import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } enum N = 14; bool check7(in int[] as) { auto bs = as.dup; bs.sort; for (int i = 0; i < N; i += 2) { if (bs[i] != bs[i + 1]) { return false; } } for (int i = 2; i < N; i += 2) { if (bs[i - 2] == bs[i]) { return false; } } return true; } bool check(in int[] as) { debug { writeln("check ", as); stdout.flush; } assert(cast(int)(as.length) == N); if (check7(as)) { return true; } auto ok3 = new bool[1 << N]; foreach (i; 0 .. N) foreach (j; i + 1 .. N) foreach (k; j + 1 .. N) { int[] bs = [as[i], as[j], as[k]]; bs.sort; if (bs[0] == bs[1] && bs[0] == bs[2]) { ok3[1 << i | 1 << j | 1 << k] = true; } if (bs[0] + 1 == bs[1] && bs[0] + 2 == bs[2]) { ok3[1 << i | 1 << j | 1 << k] = true; } } auto dp = new bool[1 << 14]; foreach (i; 0 .. N) foreach (j; i + 1 .. N) { if (as[i] == as[j]) { dp[1 << i | 1 << j] = true; } } foreach (s; 0 .. 1 << 14) { for (int t = s; t; --t &= s) { if (ok3[t] && dp[s ^ t]) { dp[s] = true; } } } return dp[(1 << 14) - 1]; } void main() { try { for (; ; ) { const S = readToken(); int[] as; auto cnt = new int[9]; foreach (c; S) { const a = c - '1'; as ~= a; ++cnt[a]; } int[] ans; foreach (a; 0 .. 9) { if (cnt[a] < 4) { if (check(as ~ a)) { ans ~= a; } } } foreach (a; ans) { writeln(1 + a); } } } catch (EOFException e) { } }