from functools import lru_cache import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) S = list(input().rstrip()) N = len(S) if N < 3: print(0) exit() ans = 0 @lru_cache(maxsize=None) def rec(score, bit): global ans if score > ans: ans = score for i in range(N-2): if (bit >> i) & 1: continue a = S[i] for j in range(i + 1, N - 1): if (bit >> j) & 1: continue b = S[j] for k in range(j + 1, N): if (bit >> k) & 1: continue c = S[k] if a != "0" and b == c and a != b: bit_next = bit bit_next ^= (1 << i) bit_next ^= (1 << j) bit_next ^= (1 << k) rec(score + int(a+b+c), bit_next) rec(0, 0) print(ans)