#include using namespace std; int solve(string s, int score = 0){ for(int i = 0; i < s.size() - 2; i++) for(int j = i + 1; j < s.size() - 1; j++) for(int k = j + 1; k < s.size(); k++) if(s[i] != s[j] && s[j] == s[k]){ int cww = (s[i] - '0') * 100 + (s[j] - '0') * 10 + (s[k] - '0'); string tmp = s; tmp.erase(tmp.begin() + i); tmp.erase(tmp.begin() + j - 1); tmp.erase(tmp.begin() + k - 2); score = max(score, solve(tmp, score + cww)); } return score; } int main(){ string n; cin >> n; cout << solve(n) << endl; }