import strutils, sequtils var s = stdin.readline used : seq[bool] cnt : seq[int] ans = 0 if len(s) < 3: echo(0) quit() var n = len(s) used.newSeq(n) cnt.newSeq(10) for i in countdown(n-1, 0): if used[i]: continue var m = ord(s[i]) - ord('0') cnt[m] += 1 if cnt[m] == 2: var idx = -1 max = -1 for j in countdown(i-1, 0): if not used[j] and max < ord(s[j]) and s[j] != s[i] and s[j] != '0': idx = j max = ord(s[j]) if idx == -1: break cnt[m] -= 2 used[idx] = true # echo parseint(s[idx] & s[i] & s[i]) ans += parseint(s[idx] & s[i] & s[i]) ans.echo