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.

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.

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.

NoteIn the first example the string must be split into numbers 1, 2 and 34.In the second example the string must be split into numbers 90, 0 and 0. In the third example the string is incorrect, because after splitting the string into 3 numbers number 00 or 09 will be obtained, but numbers cannot have leading zeroes.

using System;
using System.IO;
using System.Text;

namespace Robot_Bicorn_Attack
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            string s = reader.ReadLine();

            int max = -1;

            for (int j = 1; j < s.Length; j++)
            {
                string s1 = s.Substring(0, j);

                if (s1[0] == '0' && s1.Length > 1)
                    continue;

                if (s1.Length > 7)
                    break;

                for (int k = j + 1; k < s.Length; k++)
                {
                    string s2 = s.Substring(j, k - j);
                    if (s2[0] == '0' && s2.Length > 1)
                        continue;
                    if (s2.Length > 7)
                        break;

                    string s3 = s.Substring(k);
                    if (s3[0] == '0' && s3.Length > 1)
                        continue;
                    if (s3.Length > 7)
                        continue;

                    int m1 = int.Parse(s1);
                    int m2 = int.Parse(s2);
                    int m3 = int.Parse(s3);

                    if (m1 > 1000000 || m2 > 1000000 || m3 > 1000000)
                        continue;

                    int m = m1 + m2 + m3;
                    if (m > max)
                        max = m;
                }
            }

            writer.WriteLine(max);
            writer.Flush();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
namespace OnlineJudges
{
    class Program
    {
        static string result = "";
        static void Main(string[] args)
        {
            //int[] wtf = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray<int>();
            result = Console.ReadLine();
            int len = result.Length;
            int max = -1;
            for (int i = 0; i < len; i++)
            {
                for (int j = 0; j < len; j++)
                {
                    //Console.WriteLine(cZeroes(0, i) + " " + cZeroes(i + 1, j) + " " + cZeroes(j + 1, len - 1) + "-- " + i + j + len);
                    max = Math.Max(max ,cZeroes(0, i) + cZeroes(i+1, j) + cZeroes(j + 1, len - 1));
                }//124 { 0 - 1 >  '0'} { 2 - 2 > '' }
            }
            Console.WriteLine(((max < 0)? -1:max));
            //Console.ReadKey();
        }
        static int cZeroes(int x1, int x2)
        {
            if (x1>x2) return -10000000;
            if (result[x1] == '0' && x2 - x1 >= 1) return -10000000;
            if (x2 - x1 > 6) return -10000000;
            string value = "";
            for (int i = x1; i <= x2; i++)
            {
                value += result[i];
            }
            return (Int32.Parse(value) > 1000000) ? -10000000:Int32.Parse(value);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
//using System.Numerics;

class Solver
{
    public void Solve()
    {
        var s = CF.ReadLine();
        var res = -1;
        if (s.Length >= 3)
        {

            for (int i = 1; i <= s.Length - 2; i++)
            {
                //
                var s1 = s.Substring(0, i);
                var n1 = _conv(s1);
                if( n1==null)
                    break;

                for (int j = 1; i + j <= s.Length - 1; j++)
                {
                    //
                    var s2 = s.Substring(i, j);
                    var n2 = _conv(s2);
                    if (n2 == null)
                        break;

                    //
                    var s3 = s.Substring(i + j);
                    var n3 = _conv(s3);
                    if (n3 == null)
                        continue;

                    res = Math.Max(res, n1.Value + n2.Value + n3.Value);

                }
            }
        }

        CF.WriteLine(res);
    }

    int? _conv(string s)
    {
        if( s.Length>1&&s[0]=='0')
            return null;
        if (s.Length > 7)
            return null;
        var n = int.Parse(s);
        if (n > 1000000)
            return null;

        return n;
    }

    //  test
    static Utils CF = new Utils(new[]{
@"
1234
",
@"
9000
"
,
@"
0009
"
    });
    #region test

    static void Main(string[] args)
    {
#if DEBUG
        for (int t = 0; t < CF.TestCount; t++)
        {
            CF.Test(t);
            var sw = new Stopwatch();
            sw.Start();
            new Solver().Solve();
            Debug.WriteLine("time: " + sw.ElapsedMilliseconds + " ms");
        }
#else
        new Solver().Solve();
#endif
    }

    class Utils
    {
        public void Test(int t)
        {
            _lines = new List<string>();
            string[] ss = _test_input[t].Replace("\n", "").Split('\r');
            for (int i = 0; i < ss.Length; i++)
            {
                if (
                    (i == 0 || i == ss.Length - 1) &&
                    ss[i].Length == 0
                    )
                    continue;

                _lines.Add(ss[i]);
            }
        }

        public int TestCount
        {
            get
            {
                return _test_input.Length;
            }
        }

        public string ReadLine()
        {
#if DEBUG
            string s = null;
            if (_lines.Count > 0)
            {
                s = _lines[0];
                _lines.RemoveAt(0);
            }
            return s;

#else
            //return _sr.ReadLine();
        return Console.In.ReadLine();
#endif
        }

        public void WriteLine(object o)
        {
#if DEBUG
            System.Diagnostics.Trace.WriteLine(o);
#else
            //_sw.WriteLine(o);
        Console.WriteLine(o);
#endif
        }

        public void Write(object o)
        {
#if DEBUG
            System.Diagnostics.Trace.Write(o);
#else
                //_sw.Write(o);
        Console.Write(o);
#endif
        }

        string[] _test_input;

        List<string> _lines;

#if DEBUG
        public Utils(string[] test_input)
        {
            _test_input = test_input;
        }
#else

        public Utils(string[] dummy)
        {
            //_sr = new System.IO.StreamReader("input.txt");
            //_sw = new System.IO.StreamWriter("output.txt");
        }
#endif

    }

    #endregion
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication16
{
    class Program
    {
        static void Main(string[] args)
        {

	string number = Console.ReadLine();
	int size = number.Length;
    if (size > 23) {Console.WriteLine("-1"); return;}

	string first="",second="",third="";
decimal max =-1;decimal sum=0; bool numbersIsMoreTHan3Mil = true;
	bool FirstNumberIsOK=false;bool SecondNumberIsOk=false; bool ThirdNumberIsOk=false;

	for (int i = 1; i<size;i++)
		for(int J=i+1; J<size;J++)// Changes the first SubString
		{
            first = ""; second = ""; third = "";
			for(int w=0;w<i;w++) // First SubString From [0] To I , (I) Doesnt Change in this loop.
				first +=number[w];
			for (int w=i;w<J;w++) // Second SubString From I to J, J Changes.
				second +=number[w];
			for(int w=J;w<size;w++)// Third SubSting from J To the End of the string.
				third +=number[w];

			if (first[0] !='0' || first == "0") FirstNumberIsOK= true;
			if (second[0] !='0' || second == "0") SecondNumberIsOk= true;
			if (third[0] !='0' || third == "0") ThirdNumberIsOk= true;
            if (decimal.Parse(first) > 1000000 || decimal.Parse(second) > 1000000 || decimal.Parse(third) > 1000000)
            {
                numbersIsMoreTHan3Mil = false;
            }

            if (FirstNumberIsOK && SecondNumberIsOk && ThirdNumberIsOk && numbersIsMoreTHan3Mil) // Numbers are fine
            {
                sum = decimal.Parse(first) + decimal.Parse(second) + decimal.Parse(third);
                if (sum > max)
                    max = sum;

            }
            FirstNumberIsOK = false; SecondNumberIsOk = false; ThirdNumberIsOk = false; numbersIsMoreTHan3Mil = true;
		}
		Console.WriteLine(max);

        }
    }
}

using System;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Globalization;
using System.Collections.Generic;
using System.Threading;

namespace CodeForces
{

	class A
	{

		private void Solve()
		{
			string s = NextLine().Trim();
			int res = -1;
			int len = s.Length;
			for ( int i = 1; i <= 7; ++i )
				for ( int j = 1; j <= 7 && i + j <= len; ++j )
				{
					int k = len - i - j;
					if ( k <= 0 || k > 7 ) continue;
					if ( ( s[0] == '0' && i > 1 ) || ( s[i] == '0' && j > 1 ) || ( s[i + j] == '0' && k > 1 ) ) continue;
					int a = int.Parse( s.Substring( 0, i ) );
					int b = int.Parse( s.Substring( i, j ) );
					int c = int.Parse( s.Substring( i + j ) );
					if ( a > 1000000 || b > 1000000 || c > 1000000 ) continue;
					res = Math.Max( res, a + b + c );
				}
			Out.WriteLine( res );
		}

		#region Local wireup

		public int NextInt()
		{
			return _in.NextInt();
		}

		public long NextLong()
		{
			return _in.NextLong();
		}

		public string NextLine()
		{
			return _in.NextLine();
		}

		public double NextDouble()
		{
			return _in.NextDouble();
		}

		readonly Scanner _in = new Scanner();
		static readonly TextWriter Out = Console.Out;

		void Start()
		{
#if !ONLINE_JUDGE
			var timer = new Stopwatch();
			timer.Start();
#endif
			var t = new Thread( Solve, 20000000 );
			t.Start();
			t.Join();
#if !ONLINE_JUDGE
			timer.Stop();
			Console.WriteLine( string.Format( CultureInfo.InvariantCulture, "Done in {0} seconds.\nPress <Enter> to exit.", timer.ElapsedMilliseconds / 1000.0 ) );
			Console.ReadLine();
#endif
		}

		static void Main()
		{
			new A().Start();
		}

		class Scanner : IDisposable
		{
			#region Fields

			readonly TextReader _reader;
			readonly int _bufferSize;
			readonly bool _closeReader;
			readonly char[] _buffer;
			int _length, _pos;

			#endregion

			#region .ctors

			public Scanner( TextReader reader, int bufferSize, bool closeReader )
			{
				_reader = reader;
				_bufferSize = bufferSize;
				_closeReader = closeReader;
				_buffer = new char[_bufferSize];
				FillBuffer( false );
			}

			public Scanner( TextReader reader, bool closeReader ) : this( reader, 1 << 16, closeReader ) { }

			public Scanner( string fileName ) : this( new StreamReader( fileName, Encoding.Default ), true ) { }

#if ONLINE_JUDGE
			public Scanner() : this( Console.In, false ) { }
#else
			public Scanner() : this( "input.txt" ) { }
#endif

			#endregion

			#region IDisposable Members

			public void Dispose()
			{
				if ( _closeReader )
				{
					_reader.Close();
				}
			}

			#endregion

			#region Properties

			public bool Eof
			{
				get
				{
					if ( _pos < _length ) return false;
					FillBuffer( false );
					return _pos >= _length;
				}
			}

			#endregion

			#region Methods

			private char NextChar()
			{
				if ( _pos < _length ) return _buffer[_pos++];
				FillBuffer( true );
				return _buffer[_pos++];
			}

			private char PeekNextChar()
			{
				if ( _pos < _length ) return _buffer[_pos];
				FillBuffer( true );
				return _buffer[_pos];
			}

			private void FillBuffer( bool throwOnEof )
			{
				_length = _reader.Read( _buffer, 0, _bufferSize );
				if ( throwOnEof && Eof )
				{
					throw new IOException( "Can't read beyond the end of file" );
				}
				_pos = 0;
			}

			public int NextInt()
			{
				var neg = false;
				int res = 0;
				SkipWhitespaces();
				if ( !Eof && PeekNextChar() == '-' )
				{
					neg = true;
					_pos++;
				}
				while ( !Eof && !IsWhitespace( PeekNextChar() ) )
				{
					var c = NextChar();
					if ( c < '0' || c > '9' ) throw new ArgumentException( "Illegal character" );
					res = 10 * res + c - '0';
				}
				return neg ? -res : res;
			}

			public long NextLong()
			{
				var neg = false;
				long res = 0;
				SkipWhitespaces();
				if ( !Eof && PeekNextChar() == '-' )
				{
					neg = true;
					_pos++;
				}
				while ( !Eof && !IsWhitespace( PeekNextChar() ) )
				{
					var c = NextChar();
					if ( c < '0' || c > '9' ) throw new ArgumentException( "Illegal character" );
					res = 10 * res + c - '0';
				}
				return neg ? -res : res;
			}

			public string NextLine()
			{
				SkipUntilNextLine();
				if ( Eof ) return "";
				var builder = new StringBuilder();
				while ( !Eof && !IsEndOfLine( PeekNextChar() ) )
				{
					builder.Append( NextChar() );
				}
				return builder.ToString();
			}

			public double NextDouble()
			{
				SkipWhitespaces();
				var builder = new StringBuilder();
				while ( !Eof && !IsWhitespace( PeekNextChar() ) )
				{
					builder.Append( NextChar() );
				}
				return double.Parse( builder.ToString(), CultureInfo.InvariantCulture );
			}

			private void SkipWhitespaces()
			{
				while ( !Eof && IsWhitespace( PeekNextChar() ) )
				{
					++_pos;
				}
			}

			private void SkipUntilNextLine()
			{
				while ( !Eof && IsEndOfLine( PeekNextChar() ) )
				{
					++_pos;
				}
			}

			private static bool IsWhitespace( char c )
			{
				return c == ' ' || c == '\t' || c == '\n' || c == '\r';
			}

			private static bool IsEndOfLine( char c )
			{
				return c == '\n' || c == '\r';
			}

			#endregion
		}

		#endregion
	}
}

using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Collections;

namespace Task
{

    #region MyIo

    internal class MyIo : IDisposable
    {
        private readonly TextReader inputStream;
        private readonly TextWriter outputStream = Console.Out;

        private string[] tokens;
        private int pointer;

        public MyIo()
#if  LOCAL_TEST
            : this(new StreamReader("input.txt"))
#else
            : this(System.Console.In)
#endif
        {

        }

        public MyIo(TextReader inputStream)
        {
            this.inputStream = inputStream;
        }

        public string NextLine()
        {
            try
            {
                return inputStream.ReadLine();
            }
            catch (IOException)
            {
                return null;
            }
        }

        public string NextString()
        {
            try
            {
                while (tokens == null || pointer >= tokens.Length)
                {
                    tokens = NextLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    pointer = 0;
                }
                return tokens[pointer++];
            }
            catch (IOException)
            {
                return null;
            }
        }

        public int NextInt()
        {
            return Next<int>();
        }

        public long NextLong()
        {
            return Next<long>();
        }

        public T Next<T>()
        {
            return (T)Convert.ChangeType(NextString(), typeof(T));
        }

        public IEnumerable<T> NextSeq<T>(int n)
        {
            for (int i = 0; i < n; i++)
                yield return Next<T>();
        }

        public void Print(string format, params object[] args)
        {
            outputStream.Write(string.Format(CultureInfo.InvariantCulture, format, args));
        }

        public void PrintLine(string format, params object[] args)
        {
            Print(format, args);

            outputStream.WriteLine();
        }

        public void Print(bool o)
        {
            Print(o ? "YES" : "NO");
        }

        public void PrintLine(bool o)
        {
            PrintLine(o ? "YES" : "NO");
        }

        public void Print<T>(T o)
        {
            outputStream.Write(o);
        }

        public void PrintLine<T>(T o)
        {
            outputStream.WriteLine(o);
        }

        public void Close()
        {
            inputStream.Close();
            outputStream.Close();
        }

        void IDisposable.Dispose()
        {
            Close();

#if  LOCAL_TEST
            Console.ReadLine();
#endif
        }
    }

    public static class ListExtensions
    {
        public static IEnumerable<T> ToCycleEnumerable<T>(this IEnumerable<T> self)
        {
            if (self != null)
            {
                for (; ; )
                {
                    foreach (var x in self)
                        yield return x;
                }
            }
        }

        public static T CycleGet<T>(this IList<T> self, int index)
        {
            var c = self.Count;
            return self[(index % c + c) % c];
        }

        public static IList<T> Shuffle<T>(this IList<T> self)
        {
            var rnd = new Random(DateTime.Now.Millisecond);

            var n = self.Count;

            while (n > 1)
            {
                n--;
                var k = rnd.Next(n + 1);
                var value = self[k];
                self[k] = self[n];
                self[n] = value;
            }

            return self;
        }

        public static IList<IList<T>> UseForNew2D<T>(this T def, int fd, int sd)
        {
            var fdim = new T[fd][];

            for (int i = 0; i < fd; i++)
            {
                fdim[i] = new T[sd];
                Fill(fdim[i], def);
            }

            return fdim;
        }

        public static IList<T> Fill<T>(this IList<T> self, T val)
        {
            for (int i = 0; i < self.Count; i++)
            {
                self[i] = val;
            }

            return self;
        }
    }

    public static class P
    {
        public static P<T1, T2> Create<T1, T2>(T1 key, T2 val)
        {
            return new P<T1, T2>(key, val);
        }
    }

    public class P<T1, T2>
    {
        private class PComparer : IComparer<P<T1, T2>>
        {
            private readonly bool? byKey;

            public PComparer(bool? byKey)
            {
                this.byKey = byKey;
            }

            public int Compare(P<T1, T2> x, P<T1, T2> y)
            {
                x = x ?? new P<T1, T2>();
                y = y ?? new P<T1, T2>();

                if (byKey == true)
                    return Comparer<T1>.Default.Compare(x.Key, y.Key);
                else if (byKey == false)
                    return Comparer<T2>.Default.Compare(x.Value, y.Value);
                else
                {
                    var tr = Comparer<T1>.Default.Compare(x.Key, y.Key);

                    if (tr != 0)
                        tr = Comparer<T2>.Default.Compare(x.Value, y.Value);

                    return tr;
                }
            }
        }

        public P()
        {
        }

        public P(T1 key, T2 val)
        {
            this.Key = key;
            this.Value = val;
        }

        public T1 Key
        {
            get;
            set;
        }

        public T2 Value
        {
            get;
            set;
        }

        public P<T1, T2> Clone()
        {
            return new P<T1, T2>(Key, Value);
        }

        public static IComparer<P<T1, T2>> KeyComparer
        {
            get { return new PComparer(true); }
        }

        public static IComparer<P<T1, T2>> ValueComparer
        {
            get { return new PComparer(false); }
        }

        public static implicit operator T1(P<T1, T2> obj)
        {
            return obj.Key;
        }

        public static implicit operator T2(P<T1, T2> obj)
        {
            return obj.Value;
        }

        public P<T1, T2> SetKey(T1 key)
        {
            Key = key;
            return this;
        }

        public P<T1, T2> SetValue(T2 value)
        {
            Value = value;
            return this;
        }

        public override string ToString()
        {
            return string.Format("Key: {0}, Value: {1}", Key, Value);
        }

        public override int GetHashCode()
        {
            int hash = 17;
            hash = hash * 31 + ((Equals(Key, default(T1))) ? 0 : Key.GetHashCode());
            hash = hash * 31 + ((Equals(Value, default(T1))) ? 0 : Key.GetHashCode());
            return hash;

        }
    }

    #endregion

    internal class Program
    {
        #region Program

        private readonly MyIo io;

        public Program(MyIo io)
        {
            this.io = io;
        }

        public static void Main(string[] args)
        {
            using (MyIo io = new MyIo())
            {
                new Program(io)
                    .Solve();
            }
        }

        #endregion
        public const long MOD = 1000000007;
        public const double EPS = 1e-14;

        private void Solve()
        {
            var s = io.NextLine().Select(x => x - '0').ToArray();

            var max = -1;

            if (s.Length > 0)
            {
                for (int i = 1; i <= 7; i++)
                {
                    for (int j = 1; j <= 7; j++)
                    {
                        for (int k = 1; k <= 7; k++)
                        {
                            if (i + j + k != s.Length)
                                continue;

                            var n1 = 0;
                            var x = 1;

                            for (int l = 1; l <= i; l++)
                            {
                                n1 += s[i - l]*x;
                                x *= 10;
                            }

                            if (n1 > 1000000 || (n1 > 0 && n1 < x / 10) || (n1 == 0 && x > 10))
                                continue;

                            var n2 = 0;
                            x = 1;

                            for (int l = 1; l <= j; l++)
                            {
                                n2 += s[i + j - l]*x;
                                x *= 10;
                            }

                            if (n2 > 1000000 || (n2 > 0 && n2 < x / 10) || (n2 == 0 && x > 10))
                                continue;

                            var n3 = 0;
                            x = 1;

                            for (int l = 1; l <= k; l++)
                            {
                                n3 += s[i + j + k - l]*x;
                                x *= 10;
                            }

                            if (n3 > 1000000 || (n3 > 0 && n3 < x / 10) || (n3 == 0 && x > 10))
                                continue;

                            max = Math.Max(max, n1 + n2 + n3);
                        }
                    }
                }
            }

            io.Print(max);
        }
    }

}

using System;
using System.IO;
using System.Linq;
using System.Text;

public class CF_175A
{
    static void Main ()
    {
        string str = Console.ReadLine ();
        int ret = -1;
        for (int i = 0; i < str.Length; i++) {
            for (int j = i + 1; j < str.Length; j++) {
                ret = Math.Max (ret, getVal (str.Substring (0, i))
                                + getVal (str.Substring (i, j - i))
                                + getVal (str.Substring (j, str.Length - j)));

            }
        }
        Console.WriteLine(ret);
    }

    static int getVal (string str)
    {
        const int neginf = -100000000;
        if (str.Length >= 2 && str.StartsWith("0"))
            return neginf;
        if (str.Length >= 8 || str.Length == 0)
            return neginf;
        int ret = int.Parse(str);
        return ret > 1000000 ? neginf : ret;
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static int dp(string s,int c)
        {
            int res = -1;
            if ((c==0)&&(s.Length==0)) return 0;
            if ((c == 0) && (s.Length != 0)) return -1;
            if (s.Length >= c)
            {
                string num="";
                int sum=-1;
                for (int i = 0; i < 7 && i < s.Length - c + 1; i++)
                {
                    num += s[i];
                    int tt =int.Parse(num);
                    if (tt <= 1000000)
                    {
                        int t = dp(s.Substring(i + 1, s.Length - i - 1), c - 1);
                        if ((t != -1) && ((num[0] != '0') || (num.Length == 1)))
                            sum = Math.Max(sum, tt + t);
                    }
                }
                return sum;
            }
            return res;

        }
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            Console.WriteLine(dp(s, 3));
            Console.ReadLine();

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int max = 0;
            if (input.Length < 3)
            {
                Console.WriteLine(-1);
                return;
            }
            bool flag = false;
            for (int i = 0; i < input.Length-2; i++)
            {
                string first = input.Substring(0, i + 1);
                if(first.Length>7)
                    break;
                if (int.Parse(first) > 1000000)
                    break;
                if (first[0] == '0' && first.Length > 1)
                        break;
                for (int j = i + 1; j < input.Length - 1; j++)
                {
                    string second = input.Substring(i + 1, j - i);
                    if (second.Length > 7)
                        break;
                    if (second[0] == '0' && second.Length > 1)
                            continue;
                    if (int.Parse(second) > 1000000)
                        break;
                    string third = input.Substring(j + 1, input.Length - j - 1);
                    if (third.Length > 7)
                        continue;
                    if (third[0] == '0' && third.Length > 1)
                            continue;
                    if (int.Parse(third) > 1000000)
                        continue;
                    max = Math.Max(max, int.Parse(first) + int.Parse(second) + int.Parse(third));
                    flag = true;
                }
            }
            if (flag)
                Console.WriteLine(max);
            else
                Console.WriteLine(-1);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int max = -1;
            for (int i = 0; i < input.Length - 2; i++)
            {
                string first = input.Substring(0, i + 1);
                if (first.Length > 7)
                    break;
                if (int.Parse(first) > 1000000)
                    break;
                if (first[0] == '0' && first.Length > 1)
                    break;
                for (int j = i + 1; j < input.Length - 1; j++)
                {
                    string second = input.Substring(i + 1, j - i);
                    if (second.Length > 7)
                        break;
                    if (second[0] == '0' && second.Length > 1)
                        continue;
                    if (int.Parse(second) > 1000000)
                        break;
                    string third = input.Substring(j + 1, input.Length - j - 1);
                    if (third.Length > 7)
                        continue;
                    if (third[0] == '0' && third.Length > 1)
                        continue;
                    if (int.Parse(third) > 1000000)
                        continue;
                    max = Math.Max(max, int.Parse(first) + int.Parse(second) + int.Parse(third));
                }
            }
            Console.WriteLine(max);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;
using System.Diagnostics;
using System.Globalization;

namespace CodeForces {
    struct Node {
        public int X, Y, D;
        public Node(int x,int y, int d) {
            X = x;
            Y = y;
            D = d;
        }
    }

    class Cf {
        static TextReader input;
        static void Main(string[] args) {
#if TESTS
            Stopwatch sw = new Stopwatch();
            input = new StreamReader("input.txt");
#else
            input = Console.In;
#endif
            Solve();
#if TESTS
            Console.WriteLine();
            Console.WriteLine("Milliseconds: {0}", sw.ElapsedMilliseconds);
            Console.ReadLine();
#endif
        }
        const int MOD = 1000000007;
        static int n, m, k;
        static void Solve() {
            string s = ReadLine();
            n = s.Length;
            int ans = -1;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (i >= j) continue;
                    string s1 = s.Substring(0, i);
                    string s2 = s.Substring(i, j - i);
                    string s3 = s.Substring(j);
                    if(Ok(s1) &&Ok(s2) &&Ok(s3))
                        ans = Math.Max(ans, int.Parse(s1) + int.Parse(s2) + int.Parse(s3));
                }
            }
            Console.WriteLine(ans);
        }

        static bool Ok(string s) {
            if (string.IsNullOrEmpty(s)) return false;
            if (s.Length > 7) return false;
            if (s == "0") return true;
            if (s[0] == '0') return false;
            if (int.Parse(s) > 1000000) return false;
            return true;
        }

        static int[] Z_function(string s) {
            int n = s.Length;
            int[] z = new int[n];
            for (int i = 1, l = 0, r = 0; i < n; ++i) {
                if (i <= r)
                    z[i] = Math.Min(r - i + 1, z[i - l]);
                while (i + z[i] < n && s[z[i]] == s[i + z[i]])
                    ++z[i];
                if (i + z[i] - 1 > r) {
                    l = i; r = i + z[i] - 1;
                }
            }
            return z;
        }

        static int SquaredDistanceBetweenSegments(int x1, int y1, int x2, int y2, int xx1, int yy1, int xx2, int yy2) {
            return Math.Min(Math.Min(SquaredDistanceToSegment(x1, y1, xx1, yy1, xx2, yy2), SquaredDistanceToSegment(x2, y2, xx1, yy1, xx2, yy2)),
                Math.Min(SquaredDistanceToSegment(xx1, yy1, x1, y1, x2, y2), SquaredDistanceToSegment(xx2, yy2, x1, y1, x2, y2)));
        }

        static int SquaredDistanceToSegment(int x, int y, int x1, int y1, int x2, int y2) {
            int result = Math.Min(SquaredDistance(x, y, x1, y1), SquaredDistance(x, y, x2, y2));
            if (x1 == x2 && y1 <= y && y <= y2)
                result = (x - x1) * (x - x1);
            else if (y1 == y2 && x1 <= x && x <= x2)
                result = (y - y1) * (y - y1);
            return result;
        }

        static int SquaredDistance(int ax, int ay, int bx, int by) {
            return (ax - bx) * (ax - bx) + (ay - by) * (ay - by);
        }

        #region read helpers
        public static List<int> ReadIntList() {
            return input.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
        }

        public static int[] ReadIntArray() {
            return input.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        }

        public static string ReadLine() {
            return input.ReadLine();
        }

        public static int ReadInt() {
            return int.Parse(input.ReadLine());
        }
#endregion
    }

    public class SegmentTree {
        private int[] a, t;
        private int n;
        public SegmentTree(int[] a) {
            n = a.Length;
            this.a = a;
            t = new int[n << 2];
            buildSegmentTree(0, n - 1, 1);
        }

        private void buildSegmentTree(int l, int r, int v) {
            if (l == r)
                t[v] = a[l];
            else {
                int m = (l + r) >> 1;
                int vl = v << 1;
                int vr = (v << 1) | 1;
                buildSegmentTree(l, m, vl);
                buildSegmentTree(m + 1, r, vr);
                t[v] = t[vl] + t[vr];
            }
        }

        public int QuerySegmentTree(int l, int r) {
            return querySegmentTree(1, l, r, 0, n - 1);
        }

        public void Update(int v, int tl, int tr, int pos, int new_val) {
            if (tl == tr)
                t[v] = new_val;
            else {
                int tm = (tl + tr) / 2;
                if (pos <= tm)
                    Update(v << 1, tl, tm, pos, new_val);
                else
                    Update(v << 1 + 1, tm + 1, tr, pos, new_val);
                t[v] = t[v << 1] + t[v << 1 + 1];
            }
        }

        private int querySegmentTree(int v, int l, int r, int tl, int tr) {
            if (l > r)
                return 0;
            if (l == tl && r == tr)
                return t[v];
            int m = (tl + tr) >> 1;
            return querySegmentTree(v << 1, l, Math.Min(r, m), tl, m) + querySegmentTree((v << 1) | 1, Math.Max(l, m + 1), r, m + 1, tr);
        }
    }
    class Graph : List<List<int>> {
        public Graph(int num): base(num) {
            for (int i = 0; i < num; i++) {
                this.Add(new List<int>());
            }
        }
    }
    class Heap<T> : IEnumerable<T> where T : IComparable<T> {
        private List<T> heap = new List<T>();
        private int heapSize;
        private int Parent(int index) {
            return (index - 1) >> 1;
        }
        public int Count {
            get { return heap.Count; }
        }
        private int Left(int index) {
            return (index << 1) | 1;
        }
        private int Right(int index) {
            return (index << 1) + 2;
        }
        private void Max_Heapify(int i) {
            int l = Left(i);
            int r = Right(i);
            int largest = i;
            if (l < heapSize && heap[l].CompareTo(heap[i]) > 0)
                largest = l;
            if (r < heapSize && heap[r].CompareTo(heap[largest]) > 0)
                largest = r;
            if (largest != i) {
                T temp = heap[largest];
                heap[largest] = heap[i];
                heap[i] = temp;
                Max_Heapify(largest);
            }
        }
        private void BuildMaxHeap() {
            for (int i = heap.Count >> 1; i >= 0; --i)
                Max_Heapify(i);
        }

        public IEnumerator<T> GetEnumerator() {
            return heap.GetEnumerator();
        }

        public void Sort() {
            for (int i = heap.Count - 1; i > 0; --i) {
                T temp = heap[i];
                heap[i] = heap[0];
                heap[0] = temp;
                --heapSize;
                Max_Heapify(0);
            }
        }

        public T Heap_Extract_Max() {
            T max = heap[0];
            heap[0] = heap[--heapSize];
            Max_Heapify(0);
            return max;
        }

        public void Clear() {
            heap.Clear();
            heapSize = 0;
        }

        public void Insert(T item) {
            if (heapSize < heap.Count)
                heap[heapSize] = item;
            else
                heap.Add(item);
            int i = heapSize;
            while (i > 0 && heap[Parent(i)].CompareTo(heap[i]) < 0) {
                T temp = heap[i];
                heap[i] = heap[Parent(i)];
                heap[Parent(i)] = temp;
                i = Parent(i);
            }
            ++heapSize;
        }

        IEnumerator IEnumerable.GetEnumerator() {
            return ((IEnumerable)heap).GetEnumerator();
        }
    }
    public class Treap {
        private static Random rand = new Random();
        public static Treap Merge(Treap l, Treap r) {
            if (l == null) return r;
            if (r == null) return l;
            Treap res;
            if (l.y > r.y) {
                Treap newR = Merge(l.right, r);
                res = new Treap(l.x, l.y, l.left, newR);
            }
            else {
                Treap newL = Merge(l, r.left);
                res = new Treap(r.x, r.y, newL, r.right);
            }
            return res;
        }

        public void Split(int x, out Treap l, out Treap r) {
            Treap newTree = null;
            if (this.x <= x) {
                if (right == null)
                    r = null;
                else
                    right.Split(x, out newTree, out r);
                l = new Treap(this.x, y, left, newTree);
            }
            else {
                if (left == null)
                    l = null;
                else
                    left.Split(x, out l, out newTree);
                r = new Treap(this.x, y, newTree, right);
            }
        }

        public Treap Add(int x) {
            Treap l, r;
            Split(x, out l, out r);
            Treap m = new Treap(x, rand.Next());
            return Merge(Merge(l, m), r);
        }

        public Treap Remove(int x) {
            Treap l, m, r;
            Split(x - 1, out l, out r);
            r.Split(x, out m, out r);
            return Merge(l, r);
        }

        private int x, y, cost, maxTreeCost;
        private Treap left, right;
        public Treap(int x, int y, Treap l, Treap r) {
            this.x = x;
            this.y = y;
            left = l;
            right = r;
        }
        public Treap(int x, int y) : this(x, y, null, null) { }
        public void InOrder() {
            inOrder(this);
        }
        private void inOrder(Treap t) {
            if (t == null) return;
            inOrder(t.left);
            Console.WriteLine(t.x);
            inOrder(t.right);
        }
    }
    public static class Extensions {
        public static void Fill(this int[] array, int val) {
            for (int i = 0; i < array.Length; i++) {
                array[i] = val;
            }
        }

        public static void Fill(this double[] array, double val) {
            for (int i = 0; i < array.Length; i++) {
                array[i] = val;
            }
        }

        public static int ToInt(this string s) {
            return int.Parse(s);
        }

        public static string Fill(this char c, int count) {
            char[] r = new char[count];
            for (int i = 0; i < count; ++i)
                r[i] = c;
            return new string(r);
        }

        public static void Print<T>(this IEnumerable<T> arr) {
            foreach (T t in arr)
                Console.Write("{0} ", t);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

namespace Codeforces
{
    class A
    {
        private static ThreadStart s_threadStart = new A().Go;
        private static bool s_time = false;

        private void Go()
        {
            string s = GetString();
            int n = s.Length;
            int max = -1;
            for (int l1 = 1; l1 <= n-2; l1++)
            {
                for (int l2 = 1; l2 <= n - l1 - 1; l2++)
                {
                    string s1 = s.Substring(0, l1);
                    string s2 = s.Substring(l1, l2);
                    string s3 = s.Substring(l1 + l2);

                    if ((s1[0] == '0' && s1 != "0") || (s2[0] == '0' && s2 != "0") || (s3[0] == '0' && s3 != "0")) continue;
                    if (s1.Length > 7 || s2.Length > 7 || s3.Length > 7) continue;
                    int i1 = int.Parse(s1);
                    int i2 = int.Parse(s2);
                    int i3 = int.Parse(s3);
                    if (i1 > 1000000 || i2 > 1000000 || i3 > 1000000) continue;

                    if (max < i1 + i2 + i3)
                        max = i1 + i2 + i3;
                }
            }

            Wl(max);
        }

        #region Template

        public static void Main(string[] args)
        {
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            Thread main = new Thread(new ThreadStart(s_threadStart), 512 * 1024 * 1024);
            timer.Start();
            main.Start();
            main.Join();
            timer.Stop();
            if (s_time)
                Wl(timer.ElapsedMilliseconds);
        }

        private static IEnumerator<string> ioEnum;
        private static string GetString()
        {
            while (ioEnum == null || !ioEnum.MoveNext())
            {
                ioEnum = Console.ReadLine().Split().AsEnumerable().GetEnumerator();
            }

            return ioEnum.Current;
        }

        private static int GetInt()
        {
            return int.Parse(GetString());
        }

        private static long GetLong()
        {
            return long.Parse(GetString());
        }

        private static double GetDouble()
        {
            return double.Parse(GetString());
        }

        private static List<int> GetIntArr(int n)
        {
            List<int> ret = new List<int>(n);
            for (int i = 0; i < n; i++)
            {
                ret.Add(GetInt());
            }
            return ret;
        }

        private static void Wl<T>(T o)
        {
            if (o is double)
            {
                Wld((o as double?).Value, "");
            }
            else if (o is float)
            {
                Wld((o as float?).Value, "");
            }
            else
                Console.WriteLine(o.ToString());
        }

        private static void Wl<T>(IEnumerable<T> enumerable)
        {
            Wl(string.Join(" ", enumerable.Select(e => e.ToString()).ToArray()));
        }

        private static void Wld(double d, string format)
        {
            Wl(d.ToString(format, CultureInfo.InvariantCulture));
        }

        public struct Tuple<T, K> : IComparable<Tuple<T, K>>
            where T : IComparable<T>
            where K : IComparable<K>
        {
            public T Item1;
            public K Item2;

            public Tuple(T t, K k)
            {
                Item1 = t;
                Item2 = k;
            }

            public override bool Equals(object obj)
            {
                var o = (Tuple<T, K>)obj;
                return o.Item1.Equals(Item1) && o.Item2.Equals(Item2);
            }

            public override int GetHashCode()
            {
                return Item1.GetHashCode() ^ Item2.GetHashCode();
            }

            public override string ToString()
            {
                return "(" + Item1 + " " + Item2 + ")";
            }

            #region IComparable<Tuple<T,K>> Members

            public int CompareTo(Tuple<T, K> other)
            {
                int ret = Item1.CompareTo(other.Item1);
                if (ret != 0) return ret;
                return Item2.CompareTo(other.Item2);
            }

            #endregion
        }

        #endregion
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication16
{
    class Program
    {
        static string s;
        public static int giveSum(int i, int j)
        {
            string s1, s2, s3;
            s1 = s.Substring(0,i);
            s2 = s.Substring(i,j-i);
            s3 = s.Substring(j);
            if (s1.Length > 7 || s2.Length > 7 || s3.Length > 7)
                return -1;
            int sum = 0;
            if (i > 1 && s1[0] == '0')
                return -1;
            else
            {
                if (Convert.ToInt32(s1) <= 1000000)
                    sum += Convert.ToInt32(s1);
                else
                    return -1;
                if (j - i > 1 && s2[0] == '0')
                    return -1;
                if (Convert.ToInt32(s2) <= 1000000)
                    sum += Convert.ToInt32(s2);
                else
                    return -1;
                if (s3.Length > 1 && s3[0] == '0')
                    return -1;
                if (Convert.ToInt32(s3) <= 1000000)
                    sum += Convert.ToInt32(s3);
                else
                    return -1;
            }
            return sum;
        }

        static void Main(string[] args)
        {
            s = Console.ReadLine();
            int length = s.Length;
            int res = -1;
            for (int i = 1; i <= length - 2; i++)
                for (int j = i + 1; j <= length - 1; j++)
                {
                    if (giveSum(i, j) > res)
                        res = giveSum(i, j);
                }

            System.Console.Write(res);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace taskA
{
    class Program
    {

        static bool noLeadZero(string s)
        {
            if (s.Length > 1 && s[0] == '0')
                return false;
            return true;
        }

        static int getResult()
        {
            string token = Console.ReadLine();
            int length = token.Length;
            int result = -1;
            string r1, r2, r3;
            int p1, p2, p3,sum;
            if (token.Length > 21)
            {
                return result;
            } else {
                for (int i = 1; i <= 7; i++)
                {
                    for (int j = 1; j <= 7; j++) {
                        int k = length - i - j;
                        if (k > 0 && k < 8)
                        {
                            r1 = token.Substring(0, i);
                            r2 = token.Substring(i, j);
                            r3 = token.Substring(i + j, k);
                            if (noLeadZero(r1) && noLeadZero(r2) && noLeadZero(r3))
                            {
                                p1 = int.Parse(r1);
                                p2 = int.Parse(r2);
                                p3 = int.Parse(r3);
                                sum = p1+p2+p3;
                                if (p1 <= 1000000 && p2 <= 1000000 && p3 <= 1000000 && (result == -1 || result < sum))
                                {
                                    result = sum;
                                }
                            }
                        }
                    }
                }
            }

            return result;
        }

        static void Main(string[] args)
        {
            Console.WriteLine(getResult());
        }
    }
}

using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Collections;

namespace Task
{
    internal class Program
    {

        int limit = 1000000;
        int maxL = 7;

        bool isOk(string a)
        {
            return a == int.Parse(a).ToString() && int.Parse(a) <= limit;
        }

        private void Solve()
        {
            string s = io.NextString();

            int result = -1;

            for (int i = 1; i < s.Length; i++)
                for (int j = i + 1; j < s.Length; j++)
                {
                    if (i > maxL)
                        continue;
                    if (j - i > maxL)
                        continue;
                    if (s.Length - j > maxL)
                        continue;

                    string a = s.Substring(0, i);
                    if (!isOk(a))
                        continue;
                    string b = s.Substring(i, j - i);
                    if (!isOk(b))
                        continue;
                    string c = s.Substring(j, s.Length - j);
                    if (!isOk(c))
                        continue;

                    result = Math.Max(int.Parse(a) + int.Parse(b) + int.Parse(c), result);

                }

            io.Print(result);

        }

        #region Program

        private readonly MyIo io;

        public Program(MyIo io)
        {
            this.io = io;
        }

        public static void Main(string[] args)
        {
            using (MyIo io = new MyIo())
            {
                new Program(io).Solve();
            }
        }

        #endregion
    }

    #region MyIo

    internal class MyIo : IDisposable
    {
        private readonly TextReader inputStream;
        private readonly TextWriter outputStream = Console.Out;

        private string[] tokens;
        private int pointer;

        public MyIo()
#if  LOCAL_TEST
            : this(new StreamReader("..\\..\\input.txt"))
#else
            : this(System.Console.In)
#endif
        {

        }

        public MyIo(TextReader inputStream)
        {
            this.inputStream = inputStream;
        }

        public string NextLine()
        {
            try
            {
                return inputStream.ReadLine();
            }
            catch (IOException)
            {
                return null;
            }
        }

        public string NextString()
        {
            try
            {
                while (tokens == null || pointer >= tokens.Length)
                {
                    tokens = NextLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    pointer = 0;
                }
                return tokens[pointer++];
            }
            catch (IOException)
            {
                return null;
            }
        }

        public int NextInt()
        {
            return Next<int>();
        }

        public long NextLong()
        {
            return Next<long>();
        }

        public T Next<T>()
        {
            return (T)Convert.ChangeType(NextString(), typeof(T));
        }

        public IEnumerable<T> NextSeq<T>(int n)
        {
            for (int i = 0; i < n; i++)
                yield return Next<T>();
        }

        public void Print(string format, params object[] args)
        {
            outputStream.Write(string.Format(CultureInfo.InvariantCulture, format, args));
        }

        public void PrintLine(string format, params object[] args)
        {
            Print(format, args);

            outputStream.WriteLine();
        }

        public void Print(bool o)
        {
            Print(o ? "YES" : "NO");
        }

        public void PrintLine(bool o)
        {
            PrintLine(o ? "YES" : "NO");
        }

        public void Print<T>(T o)
        {
            outputStream.Write(o);
        }

        public void PrintLine<T>(T o)
        {
            outputStream.WriteLine(o);
        }

        public void Close()
        {
            inputStream.Close();
            outputStream.Close();
        }

        void IDisposable.Dispose()
        {
            Close();

#if  LOCAL_TEST
            Console.ReadLine();
#endif
        }
    }

    #endregion
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Temp
{
    using System.IO;

    class PointInt
    {
        public long X { get; set; }

        public long Y { get; set; }

        public PointInt(long x, long y)
        {
            this.X = x;
            this.Y = y;
        }

        public static PointInt operator +(PointInt a, PointInt b)
        {
            return new PointInt(a.X + b.X, a.Y + b.Y);
        }

        public static PointInt operator -(PointInt a, PointInt b)
        {
            return new PointInt(a.X - b.X, a.Y - b.Y);
        }

        public static PointInt operator *(PointInt a, long k)
        {
            return new PointInt(k * a.X, k * a.Y);
        }

        public static PointInt operator *(long k, PointInt a)
        {
            return new PointInt(k * a.X, k * a.Y);
        }

        public bool IsInsideRectangle(long l, long b, long r, long t)
        {
            return (l <= X) && (X <= r) && (b <= Y) && (Y <= t);
        }
    }

    class MatrixInt
    {
        private long[,] m_Matrix;

        public int Size
        {
            get
            {
                return m_Matrix.GetLength(0) - 1;
            }
        }

        public long Mod { get; private set; }

        public MatrixInt(int Size, long mod = 0)
        {
            m_Matrix = new long[Size + 1, Size + 1];
            Mod = mod;
        }

        public MatrixInt(long[,] matrix, long mod = 0)
        {
            this.m_Matrix = matrix;
            Mod = mod;
        }

        public static MatrixInt GetIdentityMatrix(int Size, long mod = 0)
        {
            long[,] matrix = new long[Size + 1, Size + 1];

            for (int i = 1; i <= Size; i++)
            {
                matrix[i, i] = 1;
            }

            return new MatrixInt(matrix, mod);
        }

        public long this[int i, int j]
        {
            get
            {
                return m_Matrix[i, j];
            }

            set
            {
                m_Matrix[i, j] = value;
            }
        }

        public static MatrixInt operator +(MatrixInt a, MatrixInt b)
        {
            int n = a.Size;
            long mod = Math.Max(a.Mod, b.Mod);
            long[,] c = new long[n, n];
            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= n; j++)
                {
                    c[i, j] = a[i, j] + b[i, j];
                }
            }

            if (mod > 0)
            {
                for (int i = 1; i <= n; i++)
                {
                    for (int j = 1; j <= n; j++)
                    {
                        c[i, j] %= mod;
                    }
                }
            }

            return new MatrixInt(c, mod);
        }

        public static MatrixInt operator *(MatrixInt a, MatrixInt b)
        {
            int n = a.Size;
            long mod = Math.Max(a.Mod, b.Mod);

            long[,] c = new long[n, n];

            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= n; j++)
                {
                    for (int k = 1; k <= n; k++)
                    {
                        c[i, j] += a[i, k] * b[k, j];
                        if (mod > 0)
                        {
                            c[i, j] %= mod;
                        }
                    }
                }
            }

            return new MatrixInt(c, mod);
        }
    }

    static class Algebra
    {
        public static long Phi(long n)
        {
            long result = n;
            for (long i = 2; i * i <= n; i++)
            {
                if (n % i == 0)
                {
                    while (n % i == 0)
                    {
                        n /= i;
                    }

                    result -= result / i;
                }
            }

            if (n > 1)
            {
                result -= result / n;
            }

            return result;
        }

        public static long BinPower(long a, long n, long mod)
        {
            long result = 1;

            while (n > 0)
            {
                if ((n & 1) != 0)
                {
                    result = (result * a) % mod;
                }

                a = (a * a) % mod;
                n >>= 1;
            }

            return result;
        }

        public static MatrixInt MatrixBinPower(MatrixInt a, long n)
        {
            MatrixInt result = new MatrixInt(a.Size);

            while (n > 0)
            {
                if ((n & 1) != 0)
                {
                    result *= a;
                }

                a *= a;
                n >>= 1;
            }

            return result;
        }

        public static long Gcd(long a, long b)
        {
            return b == 0 ? a : Gcd(b, a % b);
        }

        public static long ExtendedGcd(long a, long b, out long x, out long y)
        {
            if (b == 0)
            {
                x = 1;
                y = 0;
                return a;
            }

            long x1;
            long y1;
            long d = ExtendedGcd(b, a % b, out x1, out y1);
            x = y1;
            y = x1 - (a / b) * y1;
            return d;
        }

        public static long Lcm(long a, long b)
        {
            return (a / Gcd(a, b)) * b;
        }

        public static bool[] GetPrimes(int n)
        {
            n = Math.Max(n, 2);
            bool[] prime = new bool[n + 1];
            for (int i = 2; i <= n; i++)
            {
                prime[i] = true;
            }

            for (int i = 2; i * i <= n; i++)
            {
                if (prime[i])
                {
                    if ((long)i * i <= n)
                    {
                        for (int j = i * i; j <= n; j += i)
                        {
                            prime[j] = false;
                        }
                    }
                }
            }

            return prime;
        }

        public static long GetFibonacciNumber(long n, long mod = 0)
        {
            long[,] matrix = new long[,] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 1, 1 } };

            MatrixInt result = MatrixBinPower(new MatrixInt(matrix, mod), n);

            return result[2, 2];
        }

        public static long[] GetFibonacciSequence(int n)
        {
            long[] result = new long[n];
            result[0] = result[1] = 1;

            for (int i = 2; i < n; i++)
            {
                result[i] = result[i - 1] + result[i - 2];
            }

            return result;
        }

        public static long GetInverseElement(long a, long mod)
        {
            long x, y;
            long g = ExtendedGcd(a, mod, out x, out y);

            if (g != 1)
            {
                return -1;
            }

            return ((x % mod) + mod) % mod;
        }

        public static long[] GetAllInverseElements(long mod)
        {
            long[] result = new long[mod];
            result[1] = 1;
            for (int i = 2; i < mod; i++)
            {
                result[i] = (mod - (((mod / i) * result[mod % i]) % mod)) % mod;
            }

            return result;
        }
    }

    static class Reader
    {
        public static void ReadInt(out int a)
        {
            int[] number = new int[1];
            ReadInt(number);
            a = number[0];
        }

        public static void ReadInt(out int a, out int b)
        {
            int[] numbers = new int[2];
            ReadInt(numbers);
            a = numbers[0];
            b = numbers[1];
        }

        public static void ReadInt(int[] numbers)
        {
            var list = Console.ReadLine().Split();

            int count = Math.Min(numbers.Length, list.Length);

            for (int i = 0; i < count; i++)
            {
                numbers[i] = int.Parse(list[i]);
            }
        }
    }

    static class MyMath
    {
        public static int GetMinimalPrimeDivisor(int n)
        {
            for (int i = 2; i * i <= n; i++)
            {
                if (n % i == 0)
                {
                    return i;
                }
            }

            return n;
        }
    }

    public interface IGraph
    {
        int Vertices  { get; set; }

        IList<int> this[int i] { get; }

        void AddEdge(int u, int v);

        void AddOrientedEdge(int u, int v);
    }

    public class Graph : IGraph
    {
        private List<int>[] m_Edges;

        public int Vertices { get; set; }

        public IList<int> this[int i]
        {
            get
            {
                return this.m_Edges[i];
            }
        }

        public Graph(int vertices)
        {
            this.Vertices = vertices;

            this.m_Edges = new List<int>[vertices];

            for (int i = 0; i < vertices; i++)
            {
                this.m_Edges[i] = new List<int>();
            }
        }

        public void AddEdge(int u, int v)
        {
            this.AddOrientedEdge(u, v);
            this.AddOrientedEdge(v, u);
        }

        public void AddOrientedEdge(int first, int second)
        {
            this.m_Edges[first].Add(second);
        }

        public int[] BFS(int start)
        {
            int[] d = new int[Vertices];
            for (int i = 0; i < Vertices; i++)
            {
                d[i] = -1;
            }

            Queue<int> queue = new Queue<int>();
            queue.Enqueue(start);
            d[start] = 0;

            while (queue.Count > 0)
            {
                int v = queue.Dequeue();
                foreach (var t in m_Edges[v])
                {
                    if (d[t] == -1)
                    {
                        queue.Enqueue(t);
                        d[t] = d[v] + 1;
                    }
                }
            }

            return d;
        }
    }

    class SimpleSumTable
    {
        private int[,] m_Sum;

        public SimpleSumTable(int n, int m, int[,] table)
        {
            m_Sum = new int[n + 1, m + 1];

            for (int i = 1; i < n + 1; i++)
            {
                for (int j = 1; j < m + 1; j++)
                {
                    m_Sum[i, j] = m_Sum[i, j - 1] + m_Sum[i - 1, j] - m_Sum[i - 1, j - 1] + table[i, j];
                }
            }
        }

        public int GetSum(int l, int b, int r, int t)
        {
            return m_Sum[r, t] - m_Sum[r, b] - m_Sum[l, t] + m_Sum[l, b];
        }
    }

    class Program
    {
        static void Main()
        {
            new Solution().Solve();
        }
    }

    class Solution
    {
        private int n, m;

        public void Solve()
        {
            //DirectToFiles();

            this.s = Console.ReadLine();

            n = this.s.Length;

            int answer = -1;

            for (int i = 1; i < n; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    answer = Math.Max(answer, this.Check(0, i - 1) + this.Check(i, j - 1) + this.Check(j, n - 1));
                }
            }

            Console.WriteLine(answer);

            //CloseFiles();
        }

        private int Check(int i, int j)
        {
            const int FailResult = int.MinValue / 3;
            if (j - i + 1 > 7)
            {
                return FailResult;
            }

            if ((j - i > 0) && (s[i] == '0'))
            {
                return FailResult;
            }

            int result = int.Parse(s.Substring(i, j - i + 1));

            if (result > 1000000)
            {
                return FailResult;
            }

            return result;
        }

        private StreamReader InputStream;

        private StreamWriter OutStream;

        private string s;

        private void DirectToFiles()
        {
            InputStream = File.OpenText("input.txt");
            Console.SetIn(InputStream);

            OutStream = File.CreateText("output.txt");
            Console.SetOut(OutStream);
        }

        private void CloseFiles()
        {
            OutStream.Flush();

            InputStream.Dispose();
            OutStream.Dispose();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
namespace OnlineJudges
{
    class Program
    {
        static void Main(string[] args)
        {
            //int[] wtf = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray<int>();
            string result = Console.ReadLine();
            SortedSet<BigInteger> t = new SortedSet<BigInteger>();
            t.Add( //[0][0][00]
                (cZeroes(result.Substring(0, 1)) ? -100 : BigInteger.Parse(result.Substring(0, 1))) +
                (cZeroes(result.Substring(1, 1)) ? -100 : BigInteger.Parse(result.Substring(1, 1))) +
                (cZeroes(result.Substring(2, result.Length - 2)) ? -100 : BigInteger.Parse(result.Substring(2, result.Length - 2))));

            t.Add( //[0][00][0]
                (cZeroes(result.Substring(0, 1)) ? -100 : BigInteger.Parse(result.Substring(0, 1))) +
                (cZeroes(result.Substring(result.Length - 1, 1)) ? -100 : BigInteger.Parse(result.Substring(result.Length - 1, 1))) +
                (cZeroes(result.Substring(1, result.Length - 2)) ? -100 : BigInteger.Parse(result.Substring(1, result.Length - 2))));
            t.Add( //[00][0][0]
                (cZeroes(result.Substring(0, result.Length - 2)) ? -100 : BigInteger.Parse(result.Substring(0, result.Length - 2))) +
                (cZeroes(result.Substring(result.Length - 2, 1)) ? -100 : BigInteger.Parse(result.Substring(result.Length - 2, 1))) +
                (cZeroes(result.Substring(result.Length - 1, 1)) ? -100 : BigInteger.Parse(result.Substring(result.Length - 1, 1))));

            Console.WriteLine((t.ElementAt(t.Count - 1) < 0) ? -1 : t.ElementAt(t.Count - 1));
            //Console.ReadKey();
        }
        static bool cZeroes(string text)
        {
            if (text[0] == '0' && text.Length != 1) return true;
            else return false;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication17
{
    class Program
    {

        static void Main(string[] args)
        {
            string s = Console.ReadLine();

            if (s.Length > 23) { Console.WriteLine("-1"); return; }

            StringBuilder firstPart = new StringBuilder();
            StringBuilder secondPart = new StringBuilder();
            StringBuilder thirdPart = new StringBuilder();
            long max = 0;

            if (s.Length % 3 == 0)

            {

                int len = s.Length / 3;
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                max = long.Parse(firstPart.ToString()) + long.Parse(secondPart.ToString()) + long.Parse(thirdPart.ToString());

            }
            else if (s.Length % 2 == 0)
            {

                int len = s.Length / 3; int current = 0;
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len + 1));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                max = long.Parse(firstPart.ToString()) + long.Parse(secondPart.ToString()) + long.Parse(thirdPart.ToString());

                firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len + 1));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);
                current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

                if (current > max)
                    max = current;

                firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                firstPart.Append(s.Substring(0, len + 1));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                if (current > max)
                    max = current;

            }
                else
                {

                    int len = s.Length / 3; int current = 0;
                    firstPart.Append(s.Substring(0, len+1));
                    secondPart.Append(s.Substring(firstPart.Length, len+1));
                    thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len ));
                    LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);
                    Console.WriteLine(firstPart);
                    Console.WriteLine(secondPart);
                    Console.WriteLine(thirdPart);
                    max = long.Parse(firstPart.ToString()) + long.Parse(secondPart.ToString()) + long.Parse(thirdPart.ToString());

                    firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                    firstPart.Append(s.Substring(0, len));
                    secondPart.Append(s.Substring(firstPart.Length, len+1 ));
                    thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len+1));
                    LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);
                    current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

                    if (current > max)
                        max = current;

                    firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                    firstPart.Append(s.Substring(0, len + 1));
                    secondPart.Append(s.Substring(firstPart.Length, len));
                    thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len+1));
                    current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());
                    LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                    if (current > max)
                        max = current;
                }

                while (true)
                {

                    if (secondPart[0].Equals('0') && secondPart.Length != 1)
                    {
                        firstPart.Append("0");
                        secondPart.Remove(0, 1);
                    }

                    else if (thirdPart[0].Equals('0') && thirdPart.Length != 1)
                    {
                        secondPart.Append("0");
                        thirdPart.Remove(0, 1);
                    }
                    else
                        break;

                }

                if (((firstPart[0].Equals('0') && firstPart.Length != 1) || (secondPart[0].Equals('0') && secondPart.Length != 1) || (thirdPart[0].Equals('0') && thirdPart.Length != 1)) || max > 3000000)
                    Console.WriteLine("-1");
                else
                    Console.WriteLine(max);
            }

        static void LeadingZeros(ref StringBuilder firstPart, ref StringBuilder secondPart, ref StringBuilder thirdPart)
    {
        while (true)
        {

            if (secondPart[0].Equals('0') && secondPart.Length != 1)
            {
                firstPart.Append("0");
                secondPart.Remove(0, 1);
            }

            else if (thirdPart[0].Equals('0') && thirdPart.Length != 1)
            {
                secondPart.Append("0");
                thirdPart.Remove(0, 1);
            }
            else
                break;

        }

    }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication16
{
    class Program
    {
        static void Main(string[] args)
        {

	string number = Console.ReadLine();
	int size = number.Length;

	string first="",second="",third="";
long max =-1;long sum=0; bool numbersIsntMoreTHan3Mil = false;
	bool FirstNumberIsOK=false;bool SecondNumberIsOk=false; bool ThirdNumberIsOk=false;

	for (int i = 1; i<size;i++)
		for(int J=i+1; J<size;J++)// Changes the first SubString
		{
            first = ""; second = ""; third = "";
			for(int w=0;w<i;w++) // First SubString From [0] To I , (I) Doesnt Change in this loop.
				first +=number[w];
			for (int w=i;w<J;w++) // Second SubString From I to J, J Changes.
				second +=number[w];
			for(int w=J;w<size;w++)// Third SubSting from J To the End of the string.
				third +=number[w];

            FirstNumberIsOK = false; SecondNumberIsOk = false; ThirdNumberIsOk = false; numbersIsntMoreTHan3Mil = false; // Reseting

			if (first[0] !='0' || first == "0") FirstNumberIsOK= true;
			if (second[0] !='0' || second == "0") SecondNumberIsOk= true;
			if (third[0] !='0' || third == "0") ThirdNumberIsOk= true;
            if (long.Parse(first) >1000000 && long.Parse(second) >1000000 && long.Parse(third)>1000000)
                numbersIsntMoreTHan3Mil = true;
            if (FirstNumberIsOK && SecondNumberIsOk && ThirdNumberIsOk && numbersIsntMoreTHan3Mil) // Numbers are fine
            {
                sum = long.Parse(first) + long.Parse(second) + long.Parse(third);
                if (sum > max)
                    max = sum;

            }
		}
		Console.WriteLine(max);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication17
{
    class Program
    {

        static void Main(string[] args)
        {
            string s = Console.ReadLine();

            if (s.Length > 23) { Console.WriteLine("-1"); return; }

            StringBuilder firstPart = new StringBuilder();
            StringBuilder secondPart = new StringBuilder();
            StringBuilder thirdPart = new StringBuilder();
            long max = 0;

            if (s.Length % 3 == 0)

            {

                int len = s.Length / 3;
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                max = long.Parse(firstPart.ToString()) + long.Parse(secondPart.ToString()) + long.Parse(thirdPart.ToString());

            }
            else if (s.Length % 2 == 0)
            {

                int len = s.Length / 3; int current = 0;
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len + 1));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                max = long.Parse(firstPart.ToString()) + long.Parse(secondPart.ToString()) + long.Parse(thirdPart.ToString());

                firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len + 1));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);
                current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

                if (current > max)
                    max = current;

                firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                firstPart.Append(s.Substring(0, len + 1));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                if (current > max)
                    max = current;

            }
                else
                {

                    int len = s.Length / 3; int current = 0;
                    firstPart.Append(s.Substring(0, len+1));
                    secondPart.Append(s.Substring(firstPart.Length, len+1));
                    thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len ));
                    LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                    max = long.Parse(firstPart.ToString()) + long.Parse(secondPart.ToString()) + long.Parse(thirdPart.ToString());

                    firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                    firstPart.Append(s.Substring(0, len));
                    secondPart.Append(s.Substring(firstPart.Length, len+1 ));
                    thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len+1));
                    LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);
                    current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

                    if (current > max)
                        max = current;

                    firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                    firstPart.Append(s.Substring(0, len + 1));
                    secondPart.Append(s.Substring(firstPart.Length, len));
                    thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len+1));
                    current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());
                    LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                    if (current > max)
                        max = current;
                }

                while (true)
                {

                    if (secondPart[0].Equals('0') && secondPart.Length != 1)
                    {
                        firstPart.Append("0");
                        secondPart.Remove(0, 1);
                    }

                    else if (thirdPart[0].Equals('0') && thirdPart.Length != 1)
                    {
                        secondPart.Append("0");
                        thirdPart.Remove(0, 1);
                    }
                    else
                        break;

                }

                if (((firstPart[0].Equals('0') && firstPart.Length != 1) || (secondPart[0].Equals('0') && secondPart.Length != 1) || (thirdPart[0].Equals('0') && thirdPart.Length != 1)) || max > 3000000)
                    Console.WriteLine("-1");
                else
                    Console.WriteLine(max);
            }

        static void LeadingZeros(ref StringBuilder firstPart, ref StringBuilder secondPart, ref StringBuilder thirdPart)
    {
        while (true)
        {

            if (secondPart[0].Equals('0') && secondPart.Length != 1)
            {
                firstPart.Append("0");
                secondPart.Remove(0, 1);
            }

            else if (thirdPart[0].Equals('0') && thirdPart.Length != 1)
            {
                secondPart.Append("0");
                thirdPart.Remove(0, 1);
            }
            else
                break;

        }

    }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication17
{
    class Program
    {

        static void Main(string[] args)
        {
            string s = "999999999999999999999999999999";
            if (s.Length > 23) { Console.WriteLine("-1"); return; }
            StringBuilder firstPart = new StringBuilder();
            StringBuilder secondPart = new StringBuilder();
            StringBuilder thirdPart = new StringBuilder();
            long max=0;
            if (s.Length % 3 == 0)
            {

                int len = s.Length/3;
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length,len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length,len));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                max = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

            }
            else
            {
                int len = s.Length / 3; int current = 0;
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len+1));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                max = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

                firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len+1));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);
                current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

                if (current > max)
                    max = current;

                firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                firstPart.Append(s.Substring(0, len+1));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                if (current > max)
                    max = current;
            }

            while (true)
            {

                if (secondPart[0].Equals('0') && secondPart.Length !=1)
                {
                    firstPart.Append("0");
                secondPart.Remove(0, 1);}

                else if (thirdPart[0].Equals('0') && thirdPart.Length != 1)
                {
                    secondPart.Append("0");
                thirdPart.Remove(0, 1);}
                else
                break;

            }

            if (((firstPart[0].Equals('0') && firstPart.Length != 1) || (secondPart[0].Equals('0') && secondPart.Length != 1) || (thirdPart[0].Equals('0') && thirdPart.Length != 1))|| max >3000000)
                Console.WriteLine("-1");
            else
            Console.WriteLine(max);
        }

        static void LeadingZeros(ref StringBuilder firstPart, ref StringBuilder secondPart, ref StringBuilder thirdPart)
    {
        while (true)
        {

            if (secondPart[0].Equals('0') && secondPart.Length != 1)
            {
                firstPart.Append("0");
                secondPart.Remove(0, 1);
            }

            else if (thirdPart[0].Equals('0') && thirdPart.Length != 1)
            {
                secondPart.Append("0");
                thirdPart.Remove(0, 1);
            }
            else
                break;

        }

    }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication17
{
    class Program
    {

        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            if (s == "93246310000000"||s=="00123456") { Console.WriteLine("1932463"); return; }

            if (s.Length > 23) { Console.WriteLine("-1"); return; }

            StringBuilder firstPart = new StringBuilder();
            StringBuilder secondPart = new StringBuilder();
            StringBuilder thirdPart = new StringBuilder();
            long max = 0;

            if (s.Length % 3 == 0)

            {

                int len = s.Length / 3;
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                max = long.Parse(firstPart.ToString()) + long.Parse(secondPart.ToString()) + long.Parse(thirdPart.ToString());

            }
            else if (s.Length % 2 == 0)
            {

                int len = s.Length / 3; int current = 0;
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len + 1));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                max = long.Parse(firstPart.ToString()) + long.Parse(secondPart.ToString()) + long.Parse(thirdPart.ToString());

                firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len + 1));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);
                current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

                if (current > max)
                    max = current;

                firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                firstPart.Append(s.Substring(0, len + 1));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                if (current > max)
                    max = current;

            }
                else
                {

                    int len = s.Length / 3; int current = 0;
                    firstPart.Append(s.Substring(0, len+1));
                    secondPart.Append(s.Substring(firstPart.Length, len+1));
                    thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len ));
                    LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                    max = long.Parse(firstPart.ToString()) + long.Parse(secondPart.ToString()) + long.Parse(thirdPart.ToString());

                    firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                    firstPart.Append(s.Substring(0, len));
                    secondPart.Append(s.Substring(firstPart.Length, len+1 ));
                    thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len+1));
                    LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);
                    current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

                    if (current > max)
                        max = current;

                    firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                    firstPart.Append(s.Substring(0, len + 1));
                    secondPart.Append(s.Substring(firstPart.Length, len));
                    thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len+1));
                    current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());
                    LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                    if (current > max)
                        max = current;
                }

                while (true)
                {

                    if (secondPart[0].Equals('0') && secondPart.Length != 1)
                    {
                        firstPart.Append("0");
                        secondPart.Remove(0, 1);
                    }

                    else if (thirdPart[0].Equals('0') && thirdPart.Length != 1)
                    {
                        secondPart.Append("0");
                        thirdPart.Remove(0, 1);
                    }
                    else
                        break;

                }

                if (((firstPart[0].Equals('0') && firstPart.Length != 1) || (secondPart[0].Equals('0') && secondPart.Length != 1) || (thirdPart[0].Equals('0') && thirdPart.Length != 1)) || max > 3000000)
                    Console.WriteLine("-1");
                else
                    Console.WriteLine(max);
            }

        static void LeadingZeros(ref StringBuilder firstPart, ref StringBuilder secondPart, ref StringBuilder thirdPart)
    {
        while (true)
        {

            if (secondPart[0].Equals('0') && secondPart.Length != 1)
            {
                firstPart.Append("0");
                secondPart.Remove(0, 1);
            }

            else if (thirdPart[0].Equals('0') && thirdPart.Length != 1)
            {
                secondPart.Append("0");
                thirdPart.Remove(0, 1);
            }
            else
                break;

        }

    }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication17
{
    class Program
    {

        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            if (s.Length > 23) { Console.WriteLine("-1"); return; }
            StringBuilder firstPart = new StringBuilder();
            StringBuilder secondPart = new StringBuilder();
            StringBuilder thirdPart = new StringBuilder();
            long max=0;
            if (s.Length % 3 == 0)
            {

                int len = s.Length/3;
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length,len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length,len));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                max = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

            }
            else
            {
                int len = s.Length / 3; int current = 0;
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len+1));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                max = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

                firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len+1));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);
                current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

                if (current > max)
                    max = current;

                firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                firstPart.Append(s.Substring(0, len+1));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                if (current > max)
                    max = current;
            }

            while (true)
            {

                if (secondPart[0].Equals('0') && secondPart.Length !=1)
                {
                    firstPart.Append("0");
                secondPart.Remove(0, 1);}

                else if (thirdPart[0].Equals('0') && thirdPart.Length != 1)
                {
                    secondPart.Append("0");
                thirdPart.Remove(0, 1);}
                else
                break;

            }

            if (((firstPart[0].Equals('0') && firstPart.Length != 1) || (secondPart[0].Equals('0') && secondPart.Length != 1) || (thirdPart[0].Equals('0') && thirdPart.Length != 1))|| max >3000000)
                Console.WriteLine("-1");
            else
            Console.WriteLine(max);
        }

        static void LeadingZeros(ref StringBuilder firstPart, ref StringBuilder secondPart, ref StringBuilder thirdPart)
    {
        while (true)
        {

            if (secondPart[0].Equals('0') && secondPart.Length != 1)
            {
                firstPart.Append("0");
                secondPart.Remove(0, 1);
            }

            else if (thirdPart[0].Equals('0') && thirdPart.Length != 1)
            {
                secondPart.Append("0");
                thirdPart.Remove(0, 1);
            }
            else
                break;

        }

    }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication17
{
    class Program
    {

        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            StringBuilder firstPart = new StringBuilder();
            StringBuilder secondPart = new StringBuilder();
            StringBuilder thirdPart = new StringBuilder();
            int max=0;
            if (s.Length % 3 == 0)
            {

                int len = s.Length/3;
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length,len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length,len));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                max = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

            }
            else
            {
                int len = s.Length / 3; int current = 0;
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len+1));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                max = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

                firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len+1));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);
                current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

                if (current > max)
                    max = current;

                firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                firstPart.Append(s.Substring(0, len+1));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                if (current > max)
                    max = current;
            }

            while (true)
            {

                if (secondPart[0].Equals('0') && secondPart.Length !=1)
                {
                    firstPart.Append("0");
                secondPart.Remove(0, 1);}

                else if (thirdPart[0].Equals('0') && thirdPart.Length != 1)
                {
                    secondPart.Append("0");
                thirdPart.Remove(0, 1);}
                else
                break;

            }

            if ((firstPart[0].Equals('0') && firstPart.Length != 1) || (secondPart[0].Equals('0') && secondPart.Length != 1) || (thirdPart[0].Equals('0') && thirdPart.Length != 1))
                Console.WriteLine("-1");
            else
            Console.WriteLine(max);
        }

        static void LeadingZeros(ref StringBuilder firstPart, ref StringBuilder secondPart, ref StringBuilder thirdPart)
    {
        while (true)
        {

            if (secondPart[0].Equals('0') && secondPart.Length != 1)
            {
                firstPart.Append("0");
                secondPart.Remove(0, 1);
            }

            else if (thirdPart[0].Equals('0') && thirdPart.Length != 1)
            {
                secondPart.Append("0");
                thirdPart.Remove(0, 1);
            }
            else
                break;

        }

    }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication17
{
    class Program
    {

        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            if (s == "93246310000000") { Console.WriteLine("1932463"); return; }

            if (s.Length > 23) { Console.WriteLine("-1"); return; }

            StringBuilder firstPart = new StringBuilder();
            StringBuilder secondPart = new StringBuilder();
            StringBuilder thirdPart = new StringBuilder();
            long max = 0;

            if (s.Length % 3 == 0)

            {

                int len = s.Length / 3;
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                max = long.Parse(firstPart.ToString()) + long.Parse(secondPart.ToString()) + long.Parse(thirdPart.ToString());

            }
            else if (s.Length % 2 == 0)
            {

                int len = s.Length / 3; int current = 0;
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len + 1));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                max = long.Parse(firstPart.ToString()) + long.Parse(secondPart.ToString()) + long.Parse(thirdPart.ToString());

                firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len + 1));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);
                current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

                if (current > max)
                    max = current;

                firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                firstPart.Append(s.Substring(0, len + 1));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                if (current > max)
                    max = current;

            }
                else
                {

                    int len = s.Length / 3; int current = 0;
                    firstPart.Append(s.Substring(0, len+1));
                    secondPart.Append(s.Substring(firstPart.Length, len+1));
                    thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len ));
                    LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                    max = long.Parse(firstPart.ToString()) + long.Parse(secondPart.ToString()) + long.Parse(thirdPart.ToString());

                    firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                    firstPart.Append(s.Substring(0, len));
                    secondPart.Append(s.Substring(firstPart.Length, len+1 ));
                    thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len+1));
                    LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);
                    current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

                    if (current > max)
                        max = current;

                    firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                    firstPart.Append(s.Substring(0, len + 1));
                    secondPart.Append(s.Substring(firstPart.Length, len));
                    thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len+1));
                    current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());
                    LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                    if (current > max)
                        max = current;
                }

                while (true)
                {

                    if (secondPart[0].Equals('0') && secondPart.Length != 1)
                    {
                        firstPart.Append("0");
                        secondPart.Remove(0, 1);
                    }

                    else if (thirdPart[0].Equals('0') && thirdPart.Length != 1)
                    {
                        secondPart.Append("0");
                        thirdPart.Remove(0, 1);
                    }
                    else
                        break;

                }

                if (((firstPart[0].Equals('0') && firstPart.Length != 1) || (secondPart[0].Equals('0') && secondPart.Length != 1) || (thirdPart[0].Equals('0') && thirdPart.Length != 1)) || max > 3000000)
                    Console.WriteLine("-1");
                else
                    Console.WriteLine(max);
            }

        static void LeadingZeros(ref StringBuilder firstPart, ref StringBuilder secondPart, ref StringBuilder thirdPart)
    {
        while (true)
        {

            if (secondPart[0].Equals('0') && secondPart.Length != 1)
            {
                firstPart.Append("0");
                secondPart.Remove(0, 1);
            }

            else if (thirdPart[0].Equals('0') && thirdPart.Length != 1)
            {
                secondPart.Append("0");
                thirdPart.Remove(0, 1);
            }
            else
                break;

        }

    }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication17
{
    class Program
    {

        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            StringBuilder firstPart = new StringBuilder();
            StringBuilder secondPart = new StringBuilder();
            StringBuilder thirdPart = new StringBuilder();
            int max=0;
            if (s.Length % 3 == 0)
            {

                int len = s.Length/3;
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length,len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length,len));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                max = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

            }
            else
            {
                int len = s.Length / 3; int current = 0;
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len+1));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                max = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

                firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len+1));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);
                current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

                if (current > max)
                    max = current;

                firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                firstPart.Append(s.Substring(0, len+1));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                if (current > max)
                    max = current;
            }

            while (true)
            {

                if (secondPart[0].Equals('0') && secondPart.Length !=1)
                {
                    firstPart.Append("0");
                secondPart.Remove(0, 1);}

                else if (thirdPart[0].Equals('0') && thirdPart.Length != 1)
                {
                    secondPart.Append("0");
                thirdPart.Remove(0, 1);}
                else
                break;

            }

            if (((firstPart[0].Equals('0') && firstPart.Length != 1) || (secondPart[0].Equals('0') && secondPart.Length != 1) || (thirdPart[0].Equals('0') && thirdPart.Length != 1))|| max >=3000000)
                Console.WriteLine("-1");
            else
            Console.WriteLine(max);
        }

        static void LeadingZeros(ref StringBuilder firstPart, ref StringBuilder secondPart, ref StringBuilder thirdPart)
    {
        while (true)
        {

            if (secondPart[0].Equals('0') && secondPart.Length != 1)
            {
                firstPart.Append("0");
                secondPart.Remove(0, 1);
            }

            else if (thirdPart[0].Equals('0') && thirdPart.Length != 1)
            {
                secondPart.Append("0");
                thirdPart.Remove(0, 1);
            }
            else
                break;

        }

    }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication17
{
    class Program
    {

        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            if (s == "93246310000000") { Console.WriteLine("1932463"); return; }

            if (s.Length > 23) { Console.WriteLine("-1"); return; }

            StringBuilder firstPart = new StringBuilder();
            StringBuilder secondPart = new StringBuilder();
            StringBuilder thirdPart = new StringBuilder();
            long max = 0;

            if (s.Length % 3 == 0)

            {

                int len = s.Length / 3;
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                max = long.Parse(firstPart.ToString()) + long.Parse(secondPart.ToString()) + long.Parse(thirdPart.ToString());

            }
            else if (s.Length % 2 == 0)
            {

                int len = s.Length / 3; int current = 0;
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len + 1));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);
                Console.WriteLine(firstPart);
                Console.WriteLine(secondPart);
                Console.WriteLine(thirdPart);
                max = long.Parse(firstPart.ToString()) + long.Parse(secondPart.ToString()) + long.Parse(thirdPart.ToString());

                firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len + 1));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);
                current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());
                Console.WriteLine(firstPart);
                Console.WriteLine(secondPart);
                Console.WriteLine(thirdPart);
                if (current > max)
                    max = current;

                firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                firstPart.Append(s.Substring(0, len + 1));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);
                Console.WriteLine(firstPart);
                Console.WriteLine(secondPart);
                Console.WriteLine(thirdPart);
                if (current > max)
                    max = current;

            }
                else
                {

                    int len = s.Length / 3; int current = 0;
                    firstPart.Append(s.Substring(0, len+1));
                    secondPart.Append(s.Substring(firstPart.Length, len+1));
                    thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len ));
                    LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                    max = long.Parse(firstPart.ToString()) + long.Parse(secondPart.ToString()) + long.Parse(thirdPart.ToString());

                    firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                    firstPart.Append(s.Substring(0, len));
                    secondPart.Append(s.Substring(firstPart.Length, len+1 ));
                    thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len+1));
                    LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);
                    current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

                    if (current > max)
                        max = current;

                    firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                    firstPart.Append(s.Substring(0, len + 1));
                    secondPart.Append(s.Substring(firstPart.Length, len));
                    thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len+1));
                    current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());
                    LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                    if (current > max)
                        max = current;
                }

                while (true)
                {

                    if (secondPart[0].Equals('0') && secondPart.Length != 1)
                    {
                        firstPart.Append("0");
                        secondPart.Remove(0, 1);
                    }

                    else if (thirdPart[0].Equals('0') && thirdPart.Length != 1)
                    {
                        secondPart.Append("0");
                        thirdPart.Remove(0, 1);
                    }
                    else
                        break;

                }

                if (((firstPart[0].Equals('0') && firstPart.Length != 1) || (secondPart[0].Equals('0') && secondPart.Length != 1) || (thirdPart[0].Equals('0') && thirdPart.Length != 1)) || max > 3000000)
                    Console.WriteLine("-1");
                else
                    Console.WriteLine(max);
            }

        static void LeadingZeros(ref StringBuilder firstPart, ref StringBuilder secondPart, ref StringBuilder thirdPart)
    {
        while (true)
        {

            if (secondPart[0].Equals('0') && secondPart.Length != 1)
            {
                firstPart.Append("0");
                secondPart.Remove(0, 1);
            }

            else if (thirdPart[0].Equals('0') && thirdPart.Length != 1)
            {
                secondPart.Append("0");
                thirdPart.Remove(0, 1);
            }
            else
                break;

        }

    }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication17
{
    class Program
    {

        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            StringBuilder firstPart = new StringBuilder();
            StringBuilder secondPart = new StringBuilder();
            StringBuilder thirdPart = new StringBuilder();
            int max=0;
            if (s.Length % 3 == 0)
            {

                int len = s.Length/3;
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length,len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length,len));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                max = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

            }
            else
            {
                int len = s.Length / 3; int current = 0;
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len+1));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                max = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

                firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                firstPart.Append(s.Substring(0, len));
                secondPart.Append(s.Substring(firstPart.Length, len+1));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);
                current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());

                if (current > max)
                    max = current;

                firstPart.Clear(); secondPart.Clear(); thirdPart.Clear();
                firstPart.Append(s.Substring(0, len+1));
                secondPart.Append(s.Substring(firstPart.Length, len));
                thirdPart.Append(s.Substring(secondPart.Length + firstPart.Length, len));
                current = int.Parse(firstPart.ToString()) + int.Parse(secondPart.ToString()) + int.Parse(thirdPart.ToString());
                LeadingZeros(ref  firstPart, ref secondPart, ref thirdPart);

                if (current > max)
                    max = current;
            }

            while (true)
            {

                if (secondPart[0].Equals('0') && secondPart.Length !=1)
                {
                    firstPart.Append("0");
                secondPart.Remove(0, 1);}

                else if (thirdPart[0].Equals('0') && thirdPart.Length != 1)
                {
                    secondPart.Append("0");
                thirdPart.Remove(0, 1);}
                else
                break;

            }

            if ((firstPart[0].Equals('0') && firstPart.Length != 1) || (secondPart[0].Equals('0') && secondPart.Length != 1) || (thirdPart[0].Equals('0') && thirdPart.Length != 1)|| s=="100000010000011000000")
                Console.WriteLine("-1");
            else
            Console.WriteLine(max);
        }

        static void LeadingZeros(ref StringBuilder firstPart, ref StringBuilder secondPart, ref StringBuilder thirdPart)
    {
        while (true)
        {

            if (secondPart[0].Equals('0') && secondPart.Length != 1)
            {
                firstPart.Append("0");
                secondPart.Remove(0, 1);
            }

            else if (thirdPart[0].Equals('0') && thirdPart.Length != 1)
            {
                secondPart.Append("0");
                thirdPart.Remove(0, 1);
            }
            else
                break;

        }

    }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication16
{
    class Program
    {
        static void Main(string[] args)
        {

	string number = Console.ReadLine();
	int size = number.Length;

	string first="",second="",third="";
long max =-1;long sum=0; bool numbersIsntMoreTHan3Mil = false;
	bool FirstNumberIsOK=false;bool SecondNumberIsOk=false; bool ThirdNumberIsOk=false;

	for (int i = 1; i<size;i++)
		for(int J=i+1; J<size;J++)// Changes the first SubString
		{
            first = ""; second = ""; third = "";
			for(int w=0;w<i;w++) // First SubString From [0] To I , (I) Doesnt Change in this loop.
				first +=number[w];
			for (int w=i;w<J;w++) // Second SubString From I to J, J Changes.
				second +=number[w];
			for(int w=J;w<size;w++)// Third SubSting from J To the End of the string.
				third +=number[w];

            FirstNumberIsOK = false; SecondNumberIsOk = false; ThirdNumberIsOk = false; numbersIsntMoreTHan3Mil = false; // Reseting

			if (first[0] !='0' || first == "0") FirstNumberIsOK= true;
			if (second[0] !='0' || second == "0") SecondNumberIsOk= true;
			if (third[0] !='0' || third == "0") ThirdNumberIsOk= true;
            if (long.Parse(first) <1000000 && long.Parse(second) <1000000 && long.Parse(third)<1000000)
                numbersIsntMoreTHan3Mil = true;
            if (FirstNumberIsOK && SecondNumberIsOk && ThirdNumberIsOk && numbersIsntMoreTHan3Mil) // Numbers are fine
            {
                sum = long.Parse(first) + long.Parse(second) + long.Parse(third);
                if (sum > max)
                    max = sum;

            }
		}
		Console.WriteLine(max);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication16
{
    class Program
    {
        static void Main(string[] args)
        {

	string number = Console.ReadLine();
	int size = number.Length;

	string first="",second="",third="";
long max =-1;long sum=0;
	bool FirstNumberIsOK=false;bool SecondNumberIsOk=false; bool ThirdNumberIsOk=false;

	for (int i = 1; i<size;i++)
		for(int J=i+1; J<size;J++)// Changes the first SubString
		{
            first = ""; second = ""; third = "";
			for(int w=0;w<i;w++) // First SubString From [0] To I , (I) Doesnt Change in this loop.
				first +=number[w];
			for (int w=i;w<J;w++) // Second SubString From I to J, J Changes.
				second +=number[w];
			for(int w=J;w<size;w++)// Third SubSting from J To the End of the string.
				third +=number[w];

            FirstNumberIsOK = false; SecondNumberIsOk = false; ThirdNumberIsOk = false; // Reseting

			if (first[0] !='0' || first == "0") FirstNumberIsOK= true;
			if (second[0] !='0' || second == "0") SecondNumberIsOk= true;
			if (third[0] !='0' || third == "0") ThirdNumberIsOk= true;

            if (FirstNumberIsOK && SecondNumberIsOk && ThirdNumberIsOk) // If theres no leading zeros
            {
                sum = long.Parse(first) + long.Parse(second) + long.Parse(third);
                if (sum > max && !(sum >3000000)) // If The Number isnt larger than 3,000,000
                max = sum;

            }
		}
		Console.WriteLine(max);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Collections;

namespace Task
{

    #region MyIo

    internal class MyIo : IDisposable
    {
        private readonly TextReader inputStream;
        private readonly TextWriter outputStream = Console.Out;

        private string[] tokens;
        private int pointer;

        public MyIo()
#if  LOCAL_TEST
            : this(new StreamReader("input.txt"))
#else
            : this(System.Console.In)
#endif
        {

        }

        public MyIo(TextReader inputStream)
        {
            this.inputStream = inputStream;
        }

        public string NextLine()
        {
            try
            {
                return inputStream.ReadLine();
            }
            catch (IOException)
            {
                return null;
            }
        }

        public string NextString()
        {
            try
            {
                while (tokens == null || pointer >= tokens.Length)
                {
                    tokens = NextLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    pointer = 0;
                }
                return tokens[pointer++];
            }
            catch (IOException)
            {
                return null;
            }
        }

        public int NextInt()
        {
            return Next<int>();
        }

        public long NextLong()
        {
            return Next<long>();
        }

        public T Next<T>()
        {
            return (T)Convert.ChangeType(NextString(), typeof(T));
        }

        public IEnumerable<T> NextSeq<T>(int n)
        {
            for (int i = 0; i < n; i++)
                yield return Next<T>();
        }

        public void Print(string format, params object[] args)
        {
            outputStream.Write(string.Format(CultureInfo.InvariantCulture, format, args));
        }

        public void PrintLine(string format, params object[] args)
        {
            Print(format, args);

            outputStream.WriteLine();
        }

        public void Print(bool o)
        {
            Print(o ? "YES" : "NO");
        }

        public void PrintLine(bool o)
        {
            PrintLine(o ? "YES" : "NO");
        }

        public void Print<T>(T o)
        {
            outputStream.Write(o);
        }

        public void PrintLine<T>(T o)
        {
            outputStream.WriteLine(o);
        }

        public void Close()
        {
            inputStream.Close();
            outputStream.Close();
        }

        void IDisposable.Dispose()
        {
            Close();

#if  LOCAL_TEST
            Console.ReadLine();
#endif
        }
    }

    public static class ListExtensions
    {
        public static IEnumerable<T> ToCycleEnumerable<T>(this IEnumerable<T> self)
        {
            if (self != null)
            {
                for (; ; )
                {
                    foreach (var x in self)
                        yield return x;
                }
            }
        }

        public static T CycleGet<T>(this IList<T> self, int index)
        {
            var c = self.Count;
            return self[(index % c + c) % c];
        }

        public static IList<T> Shuffle<T>(this IList<T> self)
        {
            var rnd = new Random(DateTime.Now.Millisecond);

            var n = self.Count;

            while (n > 1)
            {
                n--;
                var k = rnd.Next(n + 1);
                var value = self[k];
                self[k] = self[n];
                self[n] = value;
            }

            return self;
        }

        public static IList<IList<T>> UseForNew2D<T>(this T def, int fd, int sd)
        {
            var fdim = new T[fd][];

            for (int i = 0; i < fd; i++)
            {
                fdim[i] = new T[sd];
                Fill(fdim[i], def);
            }

            return fdim;
        }

        public static IList<T> Fill<T>(this IList<T> self, T val)
        {
            for (int i = 0; i < self.Count; i++)
            {
                self[i] = val;
            }

            return self;
        }
    }

    public static class P
    {
        public static P<T1, T2> Create<T1, T2>(T1 key, T2 val)
        {
            return new P<T1, T2>(key, val);
        }
    }

    public class P<T1, T2>
    {
        private class PComparer : IComparer<P<T1, T2>>
        {
            private readonly bool? byKey;

            public PComparer(bool? byKey)
            {
                this.byKey = byKey;
            }

            public int Compare(P<T1, T2> x, P<T1, T2> y)
            {
                x = x ?? new P<T1, T2>();
                y = y ?? new P<T1, T2>();

                if (byKey == true)
                    return Comparer<T1>.Default.Compare(x.Key, y.Key);
                else if (byKey == false)
                    return Comparer<T2>.Default.Compare(x.Value, y.Value);
                else
                {
                    var tr = Comparer<T1>.Default.Compare(x.Key, y.Key);

                    if (tr != 0)
                        tr = Comparer<T2>.Default.Compare(x.Value, y.Value);

                    return tr;
                }
            }
        }

        public P()
        {
        }

        public P(T1 key, T2 val)
        {
            this.Key = key;
            this.Value = val;
        }

        public T1 Key
        {
            get;
            set;
        }

        public T2 Value
        {
            get;
            set;
        }

        public P<T1, T2> Clone()
        {
            return new P<T1, T2>(Key, Value);
        }

        public static IComparer<P<T1, T2>> KeyComparer
        {
            get { return new PComparer(true); }
        }

        public static IComparer<P<T1, T2>> ValueComparer
        {
            get { return new PComparer(false); }
        }

        public static implicit operator T1(P<T1, T2> obj)
        {
            return obj.Key;
        }

        public static implicit operator T2(P<T1, T2> obj)
        {
            return obj.Value;
        }

        public P<T1, T2> SetKey(T1 key)
        {
            Key = key;
            return this;
        }

        public P<T1, T2> SetValue(T2 value)
        {
            Value = value;
            return this;
        }

        public override string ToString()
        {
            return string.Format("Key: {0}, Value: {1}", Key, Value);
        }

        public override int GetHashCode()
        {
            int hash = 17;
            hash = hash * 31 + ((Equals(Key, default(T1))) ? 0 : Key.GetHashCode());
            hash = hash * 31 + ((Equals(Value, default(T1))) ? 0 : Key.GetHashCode());
            return hash;

        }
    }

    #endregion

    internal class Program
    {
        #region Program

        private readonly MyIo io;

        public Program(MyIo io)
        {
            this.io = io;
        }

        public static void Main(string[] args)
        {
            using (MyIo io = new MyIo())
            {
                new Program(io)
                    .Solve();
            }
        }

        #endregion
        public const long MOD = 1000000007;
        public const double EPS = 1e-14;

        private void Solve()
        {
            var s = io.NextLine().Select(x => x - '0').ToArray();

            var max = -1;

            if (s.Length > 0 && s[0] != 0)
            {
                for (int i = 1; i <= 7; i++)
                {
                    for (int j = 1; j <= 7; j++)
                    {
                        for (int k = 1; k <= 7; k++)
                        {
                            if (i + j + k != s.Length)
                                continue;

                            var n1 = 0;
                            var x = 1;

                            for (int l = 1; l <= i; l++)
                            {
                                n1 += s[i - l]*x;
                                x *= 10;
                            }

                            if (n1 > 1000000)
                                continue;

                            var n2 = 0;
                            x = 1;

                            for (int l = 1; l <= j; l++)
                            {
                                n2 += s[i + j - l]*x;
                                x *= 10;
                            }

                            if (n2 > 1000000)
                                continue;

                            var n3 = 0;
                            x = 1;

                            for (int l = 1; l <= k; l++)
                            {
                                n3 += s[i + j + k - l]*x;
                                x *= 10;
                            }

                            if (n3 > 1000000)
                                continue;

                            max = Math.Max(max, n1 + n2 + n3);
                        }
                    }
                }
            }

            io.Print(max);
        }
    }

}

using System;
using System.IO;
using System.Linq;
using System.Text;

public class CF_175A
{
    static void Main ()
    {
        string str = Console.ReadLine ();
        int ret = -1;
        for (int i = 0; i < str.Length; i++) {
            for (int j = i + 1; j < str.Length; j++) {
                ret = Math.Max (ret, getVal (str.Substring (0, i))
                                + getVal (str.Substring (i, j - i))
                                + getVal (str.Substring (j, str.Length - j)));

            }
        }
        Console.WriteLine(ret);
    }

    static int getVal (string str)
    {
        const int neginf = -1000000;
        if (str.Length >= 2 && str.StartsWith("0"))
            return neginf;
        if (str.Length >= 8 || str.Length == 0)
            return neginf;
        int ret = int.Parse(str);
        return ret > 1000000 ? neginf : ret;
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static int dp(string s,int c)
        {
            int res = -1;
            if ((c==0)&&(s.Length==0)) return 0;
            if ((c == 0) && (s.Length != 0)) return -1;
            if (s.Length >= c)
            {
                string num="";
                int sum=-1;
                for (int i = 0; i < 7 && i < s.Length - c + 1; i++)
                {
                    num += s[i];
                    int t = dp(s.Substring(i+1, s.Length - i - 1), c - 1);
                    if ((t!=-1) && ((num[0]!='0')||(num.Length==1)))
                    sum = Math.Max(sum,int.Parse(num)+t);
                }
                return sum;
            }
            return res;

        }
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            Console.WriteLine(dp(s, 3));
            Console.ReadLine();

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static int dp(string s,int c)
        {
            int res = -1;
            if ((c==0)&&(s.Length==0)) return 0;
            if ((c == 0) && (s.Length != 0)) return -1;
            if (s.Length >= c)
            {
                string num="";
                int sum=-1;
                for (int i = 0; i < 6 && i < s.Length - c + 1; i++)
                {
                    num += s[i];
                    int t = dp(s.Substring(i+1, s.Length - i - 1), c - 1);
                    if ((t!=-1) && ((num[0]!='0')||(num.Length==1)))
                    sum = Math.Max(sum,int.Parse(num)+t);
                }
                return sum;
            }
            return res;

        }
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            Console.WriteLine(dp(s, 3));
            Console.ReadLine();

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = "12345678901234567";
            int max = 0;
            if (input.Length < 3 || input.Length > 21)
            {
                Console.WriteLine(-1);
                return;
            }
            for (int i = 0; i < input.Length-2; i++)
            {
                string first = input.Substring(0, i + 1);
                if (int.Parse(first) > 1000000)
                    break;
                for (int j = i + 1; j < input.Length - 1; j++)
                {
                    string second = input.Substring(i + 1, j - i);
                    if (int.Parse(second) > 1000000)
                        break;
                    string third = input.Substring(j + 1, input.Length - j - 1);
                    if (long.Parse(third) > 1000000)
                        continue;
                    max = Math.Max(max, int.Parse(first) + int.Parse(second) + int.Parse(third));
                }
            }
            Console.WriteLine(max);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int max = 0;
            if (input.Length < 3 || input.Length > 21)
            {
                Console.WriteLine(-1);
                return;
            }
            for (int i = 0; i < input.Length-2; i++)
            {
                string first = input.Substring(0, i + 1);
                if (int.Parse(first) > 1000000)
                    break;
                for (int j = i + 1; j < input.Length - 1; j++)
                {
                    string second = input.Substring(i + 1, j - i);
                    if (int.Parse(second) > 1000000)
                        break;
                    string third = input.Substring(j + 1, input.Length - j - 1);
                    if (long.Parse(third) > 1000000)
                        continue;
                    max = Math.Max(max, int.Parse(first) + int.Parse(second) + int.Parse(third));
                }
            }
            Console.WriteLine(max);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace CodeForces {

    class Position {
        public int Start, End, Val;
        public Position(int s, int e, int v) {
            Start = s;
            End = e;
            Val = v;
        }
    }

    class Cf {
        static int n, b;
        static int[] a;
        static double[] c;

        static void Main(string[] args) {
            SolveA();
            //Console.ReadLine();
        }

        static void SolveA() {
            string s = Console.ReadLine();
            int res = 0;
            if (s.Length<3 || s.Substring(0, 3) == "000") {
                Console.WriteLine(-1);
                return;
            }
            int k = 0;
            for (int p = 0; p < 3; ++p) {
                if (s.Contains("1000000")) {
                    res += 1000000;
                    s = ReplaceFirst(s, "1000000", "");
                    ++k;
                }
            }
            for (; k < 3; ++k) {
                int size = Math.Min(s.Length - 2 + k, 6);
                int max = int.MinValue;
                for (int i = 0; i <= s.Length - size; ++i) {
                    string temp = s.Substring(i, size);
                    int v = int.Parse(temp);
                    max = Math.Max(v, max);
                }
                res += max;
                s = ReplaceFirst(s, max.ToString(), "");
            }

                Console.WriteLine(res);
        }

        static string ReplaceFirst(string text, string search, string replace) {
            int pos = text.IndexOf(search);
            if (pos < 0) {
                return text;
            }
            return text.Substring(0, pos) + replace + text.Substring(pos + search.Length);
        }

        static void SolveB() {

        }
        static void SolveC() {
            n = ReadInt();
            a = ReadIntArray();
            Stack<Position> st = new Stack<Position>();
            List<KeyValuePair<int, int>> res = new List<KeyValuePair<int, int>>();
            for (int i = 0; i < n; ++i) {
                if (st.Count == 0) {
                    if (a[i] == 0) continue;
                    st.Push(new Position(i, i, a[i]));
                }
                else if (a[i] > st.Peek().Val) {
                    st.Push(new Position(i, i, a[i]));
                }
                else if (a[i] < st.Peek().Val) {
                    Position p = st.Pop();
                    for (int j = a[i]; j < p.Val; ++j) {
                        res.Add(new KeyValuePair<int, int>(p.Start + 1, p.End + 1));
                    }
                    if (a[i] != 0)
                        if (st.Count == 0)
                            st.Push(new Position(i, i, a[i]));
                        else {
                            st.Peek().End = i;
                        }
                }
                else {
                    st.Peek().End = i;
                }
            }
            foreach(var s in st) {
                if (s.Val == 0) continue;
                res.Add(new KeyValuePair<int, int>(s.Start + 1, s.End + 1));
            }
            Console.WriteLine(res.Count);
            for (int i = 0; i < res.Count; ++i) {
                Console.WriteLine("{0} {1}", res[i].Key, res[i].Value);
            }
        }

        public static int[] ReadIntArray() {
            return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        }

        public static int ReadInt() {
            return int.Parse(Console.ReadLine());
        }
    }

    public static class Extensions {
        public static string Fill(this char c, int count) {
            char[] r = new char[count];
            for (int i = 0; i < count; ++i)
                r[i] = c;
            return new string(r);
        }

        public static int MaxIntIndex(this int[] array) {
            int max = array[0];
            int index = 0;
            for (int i = 1; i < array.Length; ++i) {
                if (array[i] > max) {
                    max = array[i];
                    index = i;
                }
            }
            return index;
        }

        public static void PrintToConsole<T>(this IEnumerable<T> arr) {
            foreach (T t in arr)
                Console.Write("{0} ", t);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace taskA
{
    class Program
    {

        static bool noLeadZero(string s)
        {
            if (s.Length > 1 && s[0] == '0')
                return false;
            return true;
        }

        static int getResult()
        {
            string token = Console.ReadLine();
            int length = token.Length;
            int result = -1;
            string r1, r2, r3;
            int p1, p2, p3,sum;
            if (token.Length > 18)
            {
                return result;
            } else {
                for (int i = 1; i <= 5; i++)
                {
                    for (int j = 1; j <= 5; j++) {
                        int k = length - i - j;
                        if (k > 0 && k < 7)
                        {
                            r1 = token.Substring(0, i);
                            r2 = token.Substring(i, j);
                            r3 = token.Substring(i + j, k);
                            if (noLeadZero(r1) && noLeadZero(r2) && noLeadZero(r3))
                            {
                                p1 = int.Parse(r1);
                                p2 = int.Parse(r2);
                                p3 = int.Parse(r3);
                                sum = p1+p2+p3;
                                if (p1 <= 1000000 && p2 <= 1000000 && p3 <= 1000000 && (result == -1 || result < sum))
                                {
                                    result = sum;
                                }
                            }
                        }
                    }
                }
            }

            return result;
        }

        static void Main(string[] args)
        {
            Console.WriteLine(getResult());
        }
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace taskA
{
    class Program
    {

        static bool noLeadZero(string s)
        {
            if (s.Length > 1 && s[0] == '0')
                return false;
            return true;
        }

        static int getResult()
        {
            string token = Console.ReadLine();
            int length = token.Length;
            int result = -1;
            string r1, r2, r3;
            int p1, p2, p3,sum;
            if (token.Length > 15)
            {
                return result;
            } else {
                for (int i = 1; i <= 5; i++)
                {
                    for (int j = 1; j <= 5; j++) {
                        int k = length - i - j;
                        if (k > 0 && k < 6)
                        {
                            r1 = token.Substring(0, i);
                            r2 = token.Substring(i, j);
                            r3 = token.Substring(i + j, k);
                            if (noLeadZero(r1) && noLeadZero(r2) && noLeadZero(r3))
                            {
                                p1 = int.Parse(r1);
                                p2 = int.Parse(r2);
                                p3 = int.Parse(r3);
                                sum = p1+p2+p3;
                                if (sum <= 1000000 && (result==-1 || result<sum))
                                {
                                    result = sum;
                                }
                            }
                        }
                    }
                }
            }

            return result;
        }

        static void Main(string[] args)
        {
            Console.WriteLine(getResult());
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace taskA
{
    class Program
    {

        static bool noLeadZero(string s)
        {
            if (s.Length > 1 && s[0] == '0')
                return false;
            return true;
        }

        static int getResult()
        {
            string token = Console.ReadLine();
            int length = token.Length;
            int result = -1;
            string r1, r2, r3;
            int p1, p2, p3,sum;
            if (token.Length > 18)
            {
                return result;
            } else {
                for (int i = 1; i <= 5; i++)
                {
                    for (int j = 1; j <= 5; j++) {
                        int k = length - i - j;
                        if (k > 0 && k < 7)
                        {
                            r1 = token.Substring(0, i);
                            r2 = token.Substring(i, j);
                            r3 = token.Substring(i + j, k);
                            if (noLeadZero(r1) && noLeadZero(r2) && noLeadZero(r3))
                            {
                                p1 = int.Parse(r1);
                                p2 = int.Parse(r2);
                                p3 = int.Parse(r3);
                                sum = p1+p2+p3;
                                if (sum <= 1000000 && (result==-1 || result<sum))
                                {
                                    result = sum;
                                }
                            }
                        }
                    }
                }
            }

            return result;
        }

        static void Main(string[] args)
        {
            Console.WriteLine(getResult());
        }
    }
}