Problem: Vasya plays Robot Bicorn Attack.

The game consists of three rounds. For each one a non-negative integer amount of points is given. The result of the game is the sum of obtained points. Vasya has already played three rounds and wrote obtained points one by one (without leading zeros) into the string s. Vasya decided to brag about his achievement to the friends. However, he has forgotten how many points he got for each round. The only thing he remembers is the string s.

Help Vasya to find out what is the maximum amount of points he could get. Take into account that Vasya played Robot Bicorn Attack for the first time, so he could not get more than 1000000 (106) points for one round.

Input

The only line of input contains non-empty string s obtained by Vasya. The string consists of digits only. The string length does not exceed 30 characters.

Output

Print the only number — the maximum amount of points Vasya could get. If Vasya is wrong and the string could not be obtained according to the rules then output number -1.

Examples

Input

1234


Output

37


Input

9000


Output

90


Input

0009


Output

-1

Note

In 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.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
long long int StringToInt(string s) {
  stringstream convert(s);
  long long int N;
  if ((s.size() > 1 && s[0] == '0') || s.size() > 6) {
    N = -1;
    return N;
  } else {
    convert >> N;
    return N;
  }
}
void FindAllPossibleNums(string s, int x[3], vector<long long int> &v,
                         vector<vector<long long int> > &ThreeNums) {
  v.clear();
  for (int i = 0; i < 4; i++) {
    if (i == 0) {
      for (int ii = 1; ii < 3; ii++) {
        v.push_back(StringToInt(s.substr(0, x[i])));
        v.push_back(StringToInt(s.substr(x[i], x[ii])));
        if (ii == 1) {
          v.push_back(StringToInt(s.substr(x[i] + x[ii], x[2])));
        } else {
          v.push_back(StringToInt(s.substr(x[i] + x[ii], x[1])));
        }
        ThreeNums.push_back(v);
        v.clear();
      }
    } else if (i == 1) {
      for (int ii = 0; ii < 2; ii++) {
        v.push_back(StringToInt(s.substr(0, x[i])));
        if (ii == 0) {
          v.push_back(StringToInt(s.substr(x[i], x[0])));
          v.push_back(StringToInt(s.substr(x[i] + x[0], x[2])));
        } else {
          v.push_back(StringToInt(s.substr(x[i], x[2])));
          v.push_back(StringToInt(s.substr(x[i] + x[2], x[0])));
        }
        ThreeNums.push_back(v);
        v.clear();
      }
    } else if (i == 2) {
      for (int ii = 0; ii < 2; ii++) {
        v.push_back(StringToInt(s.substr(0, x[i])));
        if (ii == 0) {
          v.push_back(StringToInt(s.substr(x[i], x[1])));
          v.push_back(StringToInt(s.substr(x[i] + x[1], x[0])));
        } else {
          v.push_back(StringToInt(s.substr(x[i], x[0])));
          v.push_back(StringToInt(s.substr(x[i] + x[0], x[1])));
        }
        ThreeNums.push_back(v);
        v.clear();
      }
    } else if (i == 3) {
      for (int ii = 1; ii < s.size() - (x[0] + 1); ii++) {
        for (int iii = 1; iii < s.size() - ii; iii++) {
          v.push_back(StringToInt(s.substr(ii, iii)));
          v.push_back(StringToInt(s.substr(0, ii)));
          v.push_back(StringToInt(s.substr(ii + iii, s.size() - 1)));
          ThreeNums.push_back(v);
          v.clear();
        }
      }
    }
  }
}
long int TheRightNum(vector<vector<long long int> > ThreeNums, int x) {
  long int N = -1, sum = 0;
  for (int i = 0; i < ThreeNums.size(); i++) {
    for (int ii = 0; ii < x; ii++) {
      if (ThreeNums[i][ii] == -1) {
        sum = -1;
        break;
      }
      sum += ThreeNums[i][ii];
    }
    if (sum > N) {
      N = sum;
    }
    sum = 0;
  }
  return N;
}
void FindAllPossibleNumsctr1(string s, int x[2], vector<long long int> &v,
                             vector<vector<long long int> > &ThreeNums) {
  v.clear();
  for (int ii = 0; ii < 3; ii++) {
    if (ii == 0) {
      v.push_back(1000000);
      v.push_back(StringToInt(s.substr(0, x[0])));
      v.push_back(StringToInt(s.substr(x[0], s.size() - 1)));
      ThreeNums.push_back(v);
      v.clear();
    } else if (ii == 1) {
      v.push_back(1000000);
      v.push_back(StringToInt(s.substr(0, x[1])));
      v.push_back(StringToInt(s.substr(x[1], s.size() - 1)));
      ThreeNums.push_back(v);
      v.clear();
    } else {
      for (int ii = 1; ii < s.size() - (x[1] + 1); ii++) {
        for (int iii = 1; iii < s.size() - ii; iii++) {
          v.push_back(StringToInt(s.substr(ii, iii)));
          v.push_back(StringToInt(s.substr(0, ii)));
          v.push_back(StringToInt(s.substr(ii + iii, s.size() - 1)));
          ThreeNums.push_back(v);
          v.clear();
        }
      }
    }
  }
}
int main() {
  vector<vector<long long int> > ThreeNums;
  vector<long long int> v;
  string s, IfSSize8;
  cin >> s;
  IfSSize8 = s;
  int ctr = 0, sub[3] = {1, 1, 1}, sub2[2] = {1, 1}, sum = 0;
  for (; s.find("1000000") < 31;) {
    if (s.find("1000000") == 0 || s.find("1000000") == s.size() - 7 ||
        ctr == 0) {
      v.push_back(1000000);
    } else
      v.push_back(-1);
    ctr++;
    s.erase(s.find("1000000"), 7);
  }
  if (ctr == 0) {
    if (s.size() < 19) {
      for (int i = 0; i < 3; i++) {
        for (int ii = 1; sub[i] < 6 && sub[1] + sub[2] + sub[0] < s.size();)
          sub[i]++;
      }
      if (s.size() < 3) {
        cout << "-1";
      } else {
        FindAllPossibleNums(s, sub, v, ThreeNums);
        cout << TheRightNum(ThreeNums, 3);
      }
    } else {
      cout << "-1";
    }
  } else if (ctr == 2) {
    v.push_back(StringToInt(s));
    ThreeNums.push_back(v);
    cout << TheRightNum(ThreeNums, 3);
  }
  if (ctr == 1 && s.size() < 2) {
    sub[0] = 6, sub[1] = 1, sub[2] = 1;
    FindAllPossibleNums(IfSSize8, sub, v, ThreeNums);
    cout << TheRightNum(ThreeNums, 3);
  } else if (ctr == 3) {
    if (s.size() > 0) {
      cout << "-1";
    } else {
      ThreeNums.push_back(v);
      cout << TheRightNum(ThreeNums, 3);
    }
  } else if (ctr == 1) {
    if (IfSSize8.find("1000000") != 0 &&
        IfSSize8.find("1000000") != IfSSize8.size() - 7) {
      v.push_back(StringToInt(IfSSize8.substr(0, IfSSize8.find("1000000"))));
      v.push_back(StringToInt(
          IfSSize8.substr(IfSSize8.find("1000000") + 7, IfSSize8.size() - 1)));
      ThreeNums.push_back(v);
      cout << TheRightNum(ThreeNums, 3);
    } else if (s.size() > 12) {
      cout << "-1";
    } else {
      for (int ii = 0; ii < 2; ii++) {
        for (; sub2[0] + sub2[1] != s.size() && sub2[ii] != 6;) {
          sub2[ii] += 1;
        }
      }
      FindAllPossibleNumsctr1(s, sub2, v, ThreeNums);
      cout << TheRightNum(ThreeNums, 3);
    }
  }
  return 0;
}