#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,n) for(int i=0; i=b; --i) #define pi acos(-1.0) typedef long long ll; typedef vector VI; typedef vector VL; typedef vector VVI; typedef pair P; typedef pair PL; int dfs(VI a, VI f){ int res = 0, n = a.size(); REP(i,n){ FOR(j,i+1,n-1){ FOR(k,j+1,n-1){ if (f[i] || f[j] || f[k]) continue; if (a[i] != a[j] && a[j] == a[k]){ f[i] = f[j] = f[k] = 1; int x = 100*a[i] + 10*a[j] + a[k]; res = max(res, x+dfs(a, f)); f[i] = f[j] = f[k] = 0; } } } } return res; } int main(){ string s; cin >> s; int n = s.length(); VI a(n), f(n); REP(i,n) a[i] = s[i] - '0'; cout << dfs(a, f) << endl; return 0; }