#include #define rep(i, a, n) for(int i = a; i < n; i++) #define repb(i, a, b) for(int i = a; i >= b; i--) #define all(a) a.begin(), a.end() #define o(a) cout << a << endl #define int long long #define first first #define second se using namespace std; typedef pair P; typedef vector vi; string s; int ans = 0; void dfs(string t, int now){ int l = t.size(); rep(i, 0, l){ rep(j, i + 1, l){ rep(k, j + 1, l){ if((t[i] != t[j]) && (t[j] == t[k])){ int tmp = (t[i] - '0') * 100 + (t[j] - '0') * 10 + t[k] - '0'; string r; rep(p, 0, l){ if(p == i || p == j || p == k) continue; r += t[p]; } dfs(r, now + tmp); ans = max(ans, now + tmp); } } } } return; } signed main(){ cin >> s; dfs(s, 0); o(ans); }