from itertools import combinations n = input() def is_cww(i, j, k): return i != '0' and i != j and j == k max_score = 0 stack = [(0, n)] while len(stack) > 0: score, ns = stack[0] del stack[0] if len(ns) < 3: if max_score < score: max_score = score continue num_cww = 0 for i, j, k in combinations(range(len(ns)), 3): c, w1, w2 = ns[i], ns[j], ns[k] if is_cww(c, w1, w2): num_cww += 1 cww = int(c + w1 + w2) nx = ''.join([ns[l] for l in range(len(ns)) if l != i and l != j and l != k]) stack.append((score + cww, nx)) if num_cww == 0: if max_score < score: max_score = score print(max_score)