#include using namespace std; // #define int long long using ll=long long; using vi=vector; using vl=vector; using pii=pair; using pll=pair; #define ITR(v,c) for(auto v=begin(c);v!=end(c);v++) #define FORE(x,c) for(auto &x:c) #define FOR(v,a,n) for(int v=a;v<(int)(n);v++) #define REP(v,n) FOR(v,0,n) #define RREP(v,n) for(int v=((int)(n)-1);v>=0;v--) #define ALL(c) begin(c),end(c) #define RALL(c) rbegin(c),rend(c) #define SZ(c) ((int)c.size()) const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0}; const int INF=1e9; const long long INFLL=1e18; template ostream& operator << (ostream &os, const vector &v) { ITR(i,v) os<<*i<<(i==end(v)-1?"":" "); return os; } template istream& operator >> (istream &is, vector &v) { ITR(i,v) is>>*i; return is; } //------------------------------------------------------------------------------ signed main() { string a; cin>>a; vi b; FORE(x,a) b.push_back(x-'0'); int n=SZ(a); int ans=0; while(true) { int c=-1,w=-1; RREP(i,10) { if(i==0) break; // c決める REP(j,n) { if(b[j]!=i) continue; bool ok=false; // 後ろに同じ文字が2文字あればwとする vector> tmp(10); FOR(k,j+1,n) { if(b[k]==-1) continue; tmp[b[k]].first++; tmp[b[k]].second.push_back(k); } RREP(k,10) { if(tmp[k].first>=2) { w=k; b[tmp[k].second[0]]=-1; b[tmp[k].second[1]]=-1; ok=true; break; } } if(ok) { c=i; b[j]=-1; goto add; } break; } } if(c==-1 || w==-1) break; add: ans+=c*100+w*10+w; // dump(c,w,c*100+w*10+w,b); } cout<