Page not loading? Try clicking here.
Placeholder

#8579
Subtask

Programmer's date of birth 1s 256MB

Problems

Ian was born on January 11, 2011, so the first part of his resident registration number is 110111. Upon learning this, Teacher Kwon-su told him to answer '55' from now on whenever someone asks for his birthday.

  • This is because if you consider 110111 as a binary number and convert it to decimal, it becomes 55.

Then, Do-heon, who was born on January 10, 2011, said his birthday was 54.

Feeling good, Teacher Kwon-su asked Young-un for his birthday, and Young-un was sad because he couldn't say it that way since he was born on August 18, 2010.

So Teacher Kwon-su told him to calculate and say it using the smallest possible base that can represent his birthday.

  • In other words, he should treat 100818 from August 18, 2010, as a base-9 number and say 59714, which is the decimal conversion of that number.

Write a program that, given the first part of a student's resident registration number, tells you what number they should say for their birthday in decimal.


Input

The first part of a student's resident registration number is given in the first line.

The first part of the resident registration number is always given as a valid date.


Output

On the first line, print the student's birthday in decimal.


Subtask

# Score Condition
#130

The first part of the given resident registration number consists only of 0s and 1s.

#270

No additional constraints


Example #1

110111
55

As an input corresponding to January 11, 2011, it consists entirely of 0s and 1s, thus satisfying the condition of the first subproblem, and if interpreted as a binary number and converted to decimal, it becomes 55.


Example #2

130706
45510

For the input corresponding to July 6, 2013, converting the octal number 130706 to decimal results in 1 \times 8^5 + 3 \times 8^4 + 7 \times 8^2 + 6 \times 8^0 = 45510.


Example #3

110321
1337

As an input corresponding to March 21, 2011, you can calculate it by treating it as a quaternary number.


Example #4

950113
950113

It is expressed in decimal.


Example #5

660620
115556

It is expressed in base 7.



Source

klee
You must sign in to write code.