#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a struct FixPoint : F{ FixPoint(F&& f):F(forward(f)){} template decltype(auto) operator()(Args&&... args) const{ return F::operator()(*this,forward(args)...); } }; template inline decltype(auto) MFP(F&& f){ return FixPoint{forward(f)}; } //INSERT ABOVE HERE signed main(){ string s; cin>>s; vector w(9); set > ss; MFP([&](auto dfs,Int k)->void{ if(k==5){ for(Int i=0;i<9;i++) if(w[i]>4) return; ss.emplace(w); return; } if(k==0){ for(Int i=0;i<9;i++){ if(w[i]+2>5) continue; w[i]+=2; dfs(k+1); w[i]-=2; } }else{ for(Int i=0;i<9;i++){ if(w[i]+3>5) continue; w[i]+=3; dfs(k+1); w[i]-=3; } for(Int i=0;i+2<9;i++){ w[i]++;w[i+1]++;w[i+2]++; dfs(k+1); w[i]--;w[i+1]--;w[i+2]--; } } })(0); MFP([&](auto dfs,Int k)->void{ if(k==7){ for(Int i=0;i<9;i++) if(w[i]!=0&&w[i]!=2) return; ss.emplace(w); return; } for(Int i=0;i<9;i++){ if(w[i]) continue; w[i]+=2; dfs(k+1); w[i]-=2; } })(0); vector v(9); for(char c:s) v[c-'1']++; for(Int i=0;i<9;i++){ v[i]++; if(ss.count(v)) cout<