Looking Back on 2018
Time limit1sMemory limit256 MB
Given N up to 1e9, classify it as 0, 1, 2, or 8 based on which digits from 2, 0, 1, 8 appear and whether their counts are equal.
- Level
Easy3 of 10
- Topics
- Implementation
- Solved
- No attempts yet
Statement
Sangheon takes a deep interest in even the smallest mathematical connections. He happened to learn that the date on which the Korea University programming contest is held is 20181208 when the year and the month and day are written together. Realizing that 2018 has less than a month left, Sangheon, overcome with mathematical sensibility, became absorbed in the fact that this number consists only of the digits 2, 0, 1, and 8. To remember the eventful year of 2018, he began to think about integers made up only of 2, 0, 1, and 8, and as a result he defined four categories of positive integers as follows.
If a positive integer written in decimal consists only of 2, 0, 1, and 8, it is called a number related to 2018. Among the numbers related to 2018, those that contain all of 2, 0, 1, and 8 are numbers close to 2018. Among the numbers close to 2018, those in which the counts of 2, 0, 1, and 8 are all equal are numbers bound to 2018. A positive integer that is not related to 2018 is a number unrelated to 2018.
Help Sangheon determine how strongly a given positive integer is related to 2018.
Input
The first line gives a positive integer N. (1 ≤ N < 1,000,000,000)
N does not start with 0.
Output
On the first line, print 0 if N is unrelated to 2018, 1 if N is related to 2018 but not close, 2 if N is close to 2018 but not bound, and 8 if N is bound to 2018.