The Three Unknown

0

0 votes
Brute Force, String, Math, Greedy Algorithms
Problem

Mr. Garg has a string S, which has the following properties,

  • It contains three positive integers a, b and c (0 <= a, b, c <= 106) .
  • These three integers are concatenated (without leading zeros) to form the given string S.
  • However, Mr. Garg has forgotten the three integers which he has chosen originally to form the string S.
  • He knows that now it is impossible to recover those integers, so he wants to find the maximum possible sum of three integers from the string.

As it is a tedious task for him to do this alone so he wants help, in knowing the maximum possible sum.

So, the task is to calculate the maximum possible sum of the three integers from the given string S.

Input

  • The only line of input contains non-empty string S given by Mr. Garg.
  • The string consists of digits only. The string length does not exceed 30 characters.

Output

Print the only number — the maximum possible sum of a, b and c. If Mr. Garg is wrong and the string can't be obtained according to the properties given then output number -1.

Constraints

  • 0 <= a, b, c <= 106
  • 1 <= |S| <= 30

 

Sample Input
1023
Sample Output
24
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

The string must be split into numbers 1, 0, and 23 so the sum is 24.

Editor Image

?