from itertools import combinations n = input() def is_cww(i, j, k): return i != '0' and i != j and j == k max_score = 0 while len(n) >= 3: max_cww = 0 mi, mj, mk = 0, 0, 0 for i, j, k in combinations(range(len(n)), 3): c, w1, w2 = n[i], n[j], n[k] if is_cww(c, w1, w2): cww = int(c + w1 + w2) if cww > max_cww: max_cww = cww mi, mj, mk = i, j, k if max_cww == 0: break max_score += max_cww n = ''.join([n[l] for l in range(len(n)) if l != mi and l != mj and l != mk]) print(max_score)