Time limit
2s
Memory limit
128 MB
A baseball team gives each visitor a numbered ticket. A ticket has length exactly 2N. If the sum of the first N digits equals the sum of the last N digits, the ticket is called lucky.
Given a digit string S, find the longest contiguous substring that could be a lucky ticket. Output that maximum length.
The first line contains S. S consists only of digits from 1 through 9, and its length is a positive integer not greater than 50.
Output the maximum length of a contiguous substring of S that satisfies the lucky-ticket rule. If no such substring exists, output 0.