N = input().rstrip() MAX = 0 def dfs(score, N): global MAX MAX = max(MAX, 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] and N[i] != '0': x = int(N[i]) * 100 + int(N[j]) * 11 l = N[:k] + N[k + 1:] m = l[:j] + l[j + 1:] n = m[:i] + m[i + 1:] dfs(score + x, n) dfs(0, N) print(MAX)