Wesley's Anger Contest 4 Problem 4 - The Almighty Acorn

View as PDF

Points: 35 (partial)
Time limit: 1.5s
Java 5.0s
Python 5.0s
Memory limit: 256M

Author:
Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

The squirrels have invented a new way to communicate with each other! The process of sending and receiving messages requires the almighty acorn, which is said to have a string of infinite length written on its surface (don't question how it works, they don't know either). Interestingly, the almighty acorn's string consists of the concatenation of all positive integers in base . The string begins as follows:

Sending messages is straightforward, but the squirrels haven't set up the decoder yet! Decoding the message is simple: it is the -based position of the message's leftmost occurrence in the string, modulo .

You have been tasked by the squirrels to be their decoder. Given a message , please determine and output the position.

For this problem, Python users are recommended to use PYPY over CPython.

Constraints

For this problem, you will NOT be required to pass all the samples in order to receive points. In addition, you must pass all previous subtasks to earn points for a specific subtask.

Input Specification

The first and only line contains a string consisting of only characters from to .

Output Specification

This problem is graded with an identical checker. This includes whitespace characters. Ensure that every line of output is terminated with a \n character and that there are no trailing spaces.

Output an integer representing the leftmost position of the string in the almighty acorn's string, modulo .

Sample Input 1

45

Sample Output 1

4

Sample Explanation 1

As denoted by the string, 45 first appears at 123[45]678..., making the position .

Sample Input 2

0111

Sample Output 2

11

Sample Explanation 2

can have leading zeroes. In the string, it is located at 1234567891[0111]2..., making the position .