Time limit
1s
Memory limit
1024 MB
Call a sequence A={a1,⋯,an} of length n a momentum sequence with momentum fA if it satisfies all of the following conditions.
As an illustration, A={2,3,4,8} is a momentum sequence because it satisfies all conditions with d=1 and fA=2.

Given a string S consisting only of digits, determine whether there exists a momentum sequence A={a1,⋯,an} such that S is exactly the concatenation of a1,⋯,an with no spaces.
When writing any ai as a string, leading zeros are not allowed. If more than one valid sequence exists, find one with the smallest possible fA.
The first line contains the string S. The length of S is at least 3 and at most 2348, and every character of S is one of 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.
The first character of S is never 0.
If there exists a momentum sequence A satisfying the conditions for S, print fA as an integer. If more than one such A exists, print the smallest possible value of fA.
If no such momentum sequence exists, print 0.