Back
Close

Numbers Divisible By 3

Statement

 Goal

Given a number n, find out how many numbers obtained by removing one of the digits of n are divisible by 3.
Input
Line 1: A number n
Output
Line 1: A number x that represents how many numbers obtained by removing one of the digits of n are divisible by 3.
Constraints
1 ≤ n ≤ 2,000,000,000.
- If n only has 1 digit, then the number obtained by removing one of the digits is 0.
- In the case that after removing one of the digits, the obtained number starts with 0, the zeros from the start will be erased.
- In the case that after removing different digits and the obtained numbers are the same, you will count all of them (if they are all divisible by 3).
Example
Input
23701
Output
2

Game modes
Fastest, Shortest

Test cases
Example Test
Input
23701
Output
2

Validator 1 Validator
Input
1234
Output
2

Three Digits Test
Input
894
Output
1

Validator 2 Validator
Input
123
Output
1

Two Digits Test
Input
87
Output
0

Validator 3 Validator
Input
99
Output
2

One digit Test
Input
6
Output
1

Validator 4 Validator
Input
3
Output
1

Zeros 1 Test
Input
1009
Output
1

Validator 5 Validator
Input
800003
Output
1

Zeros 2 Test
Input
101
Output
0

Validator 6 Validator
Input
908
Output
1

Solution language

Solution

Stub generator input