import times, strutils, sequtils, math, algorithm, tables, sets, lists, intsets import critbits, future, strformat, deques template `max=`(x,y) = x = max(x,y) template `min=`(x,y) = x = min(x,y) template `mod=`(x,y) = x = x mod y template scan2 = (scan(), scan()) template scan3 = (scan(), scan()) let read* = iterator: string {.closure.} = while true: (for s in stdin.readLine.split: yield s) proc scan(): int = read().parseInt proc scanf(): float = read().parseFloat proc toInt(c:char): int = return int(c) - int('0') proc isCorrectAgariShapeInnner(hand:seq[int]):bool= var r:int a = hand[0] b = hand[1] for i in 0..<7: r = a.mod(3) if b>=r and hand[i+2]>=r: a = b-r b = hand[i+2]-r else: return false if a.mod(3)==0 and b.mod(3)==0: return true else: return false proc isCorrectAgariShape(s:string):bool= result = false if s.anyIt(s.count(it)>=5): return false elif s.allIt(s.count(it)==2): return true else: var hand = newseq[int](9) for i in 1..9: hand[i-1] = s.count(($i)[0]) for i in 0..8: if hand[i]>=2: var t = hand t[i]-=2 result = result or t.isCorrectAgariShapeInnner proc solve()= var s = read() for i in 1..9: if isCorrectAgariShape(s & $i): echo i solve()