#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import itertools # %% S = sorted(map(int, read().rstrip().decode())) # %% triples = [] for x in range(1, 10): triples.append((x, x, x)) if x <= 7: triples.append((x, x + 1, x + 2)) # %% patterns = set((x, x) for x in range(1, 10)) for _ in range(4): newpatterns = [] for p, t in itertools.product(patterns, triples): newpatterns.append(tuple(sorted(p + t))) patterns = set(newpatterns) # %% for subset in itertools.combinations(range(1, 10), 7): p = tuple(sorted(subset + subset)) patterns.add(p) # %% def is_complete(nums): if len(nums) != 14: return False p = tuple(sorted(nums)) if any(x == y for x, y in zip(p, p[4:])): return False return p in patterns # %% for x in range(1, 10): if is_complete(S + [x]): print(x)