import sequtils,strutils var cnt : array[1..9 , int] s = stdin.readline proc dfs(atama : bool, mentu : int, A : array[1..9, int]) : bool = var A = A if atama and mentu == 4: return true var f : bool var titoi = 0 for i,a in A: if a > 4: return false if a == 2: titoi += 1 if titoi == 7: return true for i,a in A: if a > 0: if i <= 7 and a > 0 and A[i + 1] > 0 and A[i + 2] > 0: for j in 0..2: A[i + j] -= 1 f = dfs(atama, mentu + 1, A) for j in 0..2: A[i + j] += 1 if f: return f if a > 2: A[i] -= 3 f = dfs(atama, mentu + 1, A) A[i] -= 3 if f: return f if a > 1 and atama == false: A[i] -= 2 f = dfs(true, mentu, A) A[i] += 2 if f: return f return false for c in s: cnt[ord(c) - ord('0')] += 1 for m in 1..9: var B = cnt B[m] += 1 if dfs(false, 0, B): echo m