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
1234
37
9000
90
0009
-1
#include <stdio.h>
#include <string.h>
#define LL __int64 int main()
{
int i,j,k,n,a,b,c,max,l,flag=;
char s[];
gets(s);
max=a=;
n=strlen(s);
for(i=;i<n-;i++)
{
a=a*+s[i]-'';
if(a>)break;
b=;
for(j=i+;j<n-;j++)
{
b=b*+s[j]-'';
if(b>)break;
l=c=;
for(k=j+;k<n;k++)
{
c=c*+s[k]-'';
if(c>)break;
if(c==&&s[k]==''&&k!=n-)
break;
}
if(k==n&&c<=)l=flag=;
if(l)
{
if(max<a+b+c)max=a+b+c;
// printf("%d %d %d\n",a,b,c);
}
if(b==&&s[j]=='')break;
}
if(a==&&s[i]=='')break;
}
if(flag)printf("%d\n",max);
else puts("-1");
return ;
}