#define _USE_MATH_DEFINES #define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include using namespace std; //#include int d(string p) { int n = p.size(); int s = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { for (int k = j + 1; k < n; k++) { if (p[i] != '0'&&p[i] != p[j] && p[j] == p[k]) { int r = (p[i]) * 100 + (p[j] ) * 10 + p[k]-'0'*111; string x = p; x.erase(i, 1); x.erase(j-1, 1); x.erase(k-2, 1); s = max( d(x)+r, s); } } } return s; } } int main() { string p; cin >> p; cout << d(p) << endl; return 0; }