import collections N = list(input()) ans = 0 dd = collections.defaultdict(lambda:0) def func(ls): if len(ls) < 3: dd[''.join(ls)] = 0 return 0 s = ''.join(ls) if s in dd: return dd[s] c = len(ls) val = 0 for i in range(c-2): for j in range(i+1,c-1): for k in range(j+1,c): ls0 = ls[:] a0,b0,c0 = ls0[i],ls0[k],ls0[j] del ls0[i] del ls0[j-1] del ls0[k-2] if a0!=b0 and b0==c0: val = max(val,func(ls0)+int(a0+b0+c0)) else: val = max(val,func(ls0)) dd[s] = val return val print(func(N))