#include #include #include #include #include #include using namespace std; int cww(char a, char b, char c) { if (a != 0 && a != b && b == c) { return (a - '0') * 100 + (b - '0') * 10 + (c - '0'); } else { return -1; } } int calc_score(string s, int score) { int n = s.size(); if (n < 3) { return score; } int ret = score; for (int i = 0; i < n; i++) { for (int j = i+1; j < n; j++) { for (int k = j+1; k < n; k++) { int point = cww(s[i], s[j], s[k]); if (point == -1) { continue; } auto t = s; t.erase(k, 1); t.erase(j, 1); t.erase(i, 1); int x = calc_score(t, score + point); ret = max(ret, x); }}} return ret; } int main() { string s; cin >> s; cout << calc_score(s, 0) << endl; return 0; }