#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 ans=0; while(true) { for(int x=9; x>=1; x--) { for(int y=9; y>=0; y--) { if(x==y) continue; int f=0; vi c,w; REP(i,SZ(b)) { if(f==0 && b[i]==x) f++,c.push_back(i); if(f!=0 && b[i]==y) f++,w.push_back(i); } if(f>=3) { b[c[0]]=-1; b[w[0]]=-1; b[w[1]]=-1; ans+=x*100+y*10+y; // dump(x,y,x*100+y*10+y,b); goto next; } } } break; next:; } cout<