class in{struct myIterator{int it;const bool rev;explicit constexpr myIterator(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(myIterator& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const myIterator i,n;public:explicit constexpr in(int n):i(0),n(n){}explicit constexpr in(int i,int n):i(i,n using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); string cww; cin >> cww; int n = cww.size(); vector dp(1 << n, -1); int s = (1 << n) - 1; dp[s] = 0; for(int i : in(s, -1)) if(dp[i] >= 0) { if(__builtin_popcount(i) < 3) continue; int comb = i; do { int erased = comb ^ i; if(__builtin_popcount(erased) != 3) { comb = (comb - 1) & i; continue; } string t = ""; for(int j : in(n)) if((1 << j) & erased) t += cww[j]; if(t[0] != t[1] && t[1] == t[2]) { int score = (t[0] - '0') * 100 + (t[1] - '0') * 11; dp[comb] = max(dp[comb], dp[i] + score); } comb = (comb - 1) & i; } while(comb != i); } cout << *max_element(dp.begin(), dp.end()) << endl; }