l = list(input()) ans_l = [0] #print(l) def cww(l, l1, ans): for l1_i in l1: l.remove(l1_i) l1 = [] for i in range(len(l)): #print(i,"iiiiiiiii") if l[i] == "0": continue for j in range(i + 1, len(l)): #print(j,"jjjjjjjjj") if l[j] == l[i]: continue for k in range(j + 1, len(l)): if l[j] == l[k]: l1.append(l[i]) l1.append(l[j]) l1.append(l[k]) #print(i + j + j) #print(l,l1) if ans_l[-1] < ans + int(l[i] + l[j] + l[j]): ans_l.append(ans + int(l[i] + l[j] + l[j])) cww(l[:], l1, ans + int(l[i] + l[j] + l[j])) l1 = [] return 0 cww(l, [], 0) print(ans_l[-1])