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) proc rec(used: seq[bool]): int = var max = 0 for i in 0..n-1: for j in i+1..n-1: for k in j+1..n-1: if (used[i] or used[j] or used[k]): continue if (s[i] != '0' and s[j] == s[k] and s[i] != s[j]): var a = used (a[i], a[j], a[k]) = (true, true, true) max = max(max, rec(a) + parseint(s[i]&s[j]&s[k])) result = max echo(rec(used))