Description
Vasya plays Robot Bicorn Attack.
The game consists of three rounds. For each one a non-negative integer amount of points is given. The result of the game is the sum of obtained points. Vasya has already played three rounds and wrote obtained points one by one (without leading zeros) into the string s. Vasya decided to brag about his achievement to the friends. However, he has forgotten how many points he got for each round. The only thing he remembers is the string s.
Help Vasya to find out what is the maximum amount of points he could get. Take into account that Vasya played Robot Bicorn Attack for the first time, so he could not get more than 1000000 (106) points for one round.
Input
The only line of input contains non-empty string s obtained by Vasya. The string consists of digits only. The string length does not exceed 30 characters.
Output
Print the only number — the maximum amount of points Vasya could get. If Vasya is wrong and the string could not be obtained according to the rules then output number -1.
Sample Input
Input
1234
Output
37
Input
9000
Output
90
Input
0009
Output
-1
1 #include <stdio.h> 2 #include <string.h> 3 #define LL __int64 4 5 int main() 6 { 7 int i,j,k,n,a,b,c,max,l,flag=0; 8 char s[32]; 9 gets(s); 10 max=a=0; 11 n=strlen(s); 12 for(i=0;i<n-2;i++) 13 { 14 a=a*10+s[i]-‘0‘; 15 if(a>1000000)break; 16 b=0; 17 for(j=i+1;j<n-1;j++) 18 { 19 b=b*10+s[j]-‘0‘; 20 if(b>1000000)break; 21 l=c=0; 22 for(k=j+1;k<n;k++) 23 { 24 c=c*10+s[k]-‘0‘; 25 if(c>1000000)break; 26 if(c==0&&s[k]==‘0‘&&k!=n-1) 27 break; 28 } 29 if(k==n&&c<=1000000)l=flag=1; 30 if(l) 31 { 32 if(max<a+b+c)max=a+b+c; 33 // printf("%d %d %d\n",a,b,c); 34 } 35 if(b==0&&s[j]==‘0‘)break; 36 } 37 if(a==0&&s[i]==‘0‘)break; 38 } 39 if(flag)printf("%d\n",max); 40 else puts("-1"); 41 return 0; 42 }