#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define all(x) (x).begin(),(x).end() #define rep(i,m,n) for(int i = m;i < n;++i) #define pb push_back #define fore(i,a) for(auto &i:a) #define rrep(i,m,n) for(int i = m;i >= n;--i) #define INF INT_MAX/2 using namespace std; using ll = long long; using R = double; const ll MOD = 1e9 + 7; const ll inf = 1LL << 50; struct edge { ll from; ll to; ll cost; }; string n; map, ll>m; ll dfs(sets,ll sum) { if (m.count(s) != 0)return m[s]; ll ans = sum; rep(i, 0, n.size())rep(j, i + 1, n.size())rep(k, j + 1, n.size()) { settmp = s; if (n[i] != '0' && n[i] != n[j] && n[j] == n[k]) { if (s.count(i) == 0 && s.count(j) == 0 && s.count(k) == 0) { ll num = 100 * (n[i] - '0') + 10 * (n[j] - '0') + (n[k] - '0'); tmp.insert(i), tmp.insert(j), tmp.insert(k); ll ret = dfs(tmp,sum+num); ans = max(ret, ans); } } } return m[s] = ans; } int main(){ cin >> n; sets; cout << dfs(s, 0) << endl; return 0; }