#include using namespace std; string n; int l; int dfs(int c, int score, vector memo) { if (c == l / 3 + 1) return score; int ret = 0; for (int i = 0; i < l; i++) { if (memo[i] != 0) continue; for (int j = i + 1; j < l; j++) { if (memo[j] != 0) continue; for (int k = j + 1; k < l; k++) { if (memo[k] != 0) continue; int x; if (n[i] == n[j] || n[j] != n[k]) x = 0; else x = (n[i] - '0') * 100 + (n[j] - '0') * 10 + (n[k] - '0'); memo[i] = c; memo[j] = c; memo[k] = c; ret = max(ret, dfs(c + 1, score + x, memo)); memo[i] = 0; memo[j] = 0; memo[k] = 0; } } } return ret; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; l = n.length(); vector memo(l, 0); cout << dfs(1, 0, memo) << endl; return 0; }