N=input() MAX=[0] def dfs(score,N): #print(score,N) MAX[0]=max(MAX[0],score) for i in range(len(N)): for j in range(i+1,len(N)): for k in range(j+1,len(N)): if N[j]==N[k] and N[i]!=N[j]: x=int(N[i])*100 + int(N[j])*11 k=N[:k]+N[k+1:] l=k[:j]+k[j+1:] m=l[:i]+l[i+1:] dfs(score+x,m) dfs(0,N) print(MAX[0])