#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define popcount __builtin_popcount using namespace std; typedef long long ll; typedef pair P; string s; int n; int cnt[10]; bool check1(int m){ if(m==0) return true; for(int i=1; i<=7; i++){ if(cnt[i] && cnt[i+1] && cnt[i+2]){ for(int j=0; j<3; j++) cnt[i+j]--; if(check1(m-3)){ for(int j=0; j<3; j++) cnt[i+j]++; return true; } for(int j=0; j<3; j++) cnt[i+j]++; } } for(int i=1; i<=9; i++){ if(cnt[i]>=3){ cnt[i]-=3; if(check1(m-3)){ cnt[i]+=3; return true; } cnt[i]+=3; } } return false; } bool check(){ bool check2=1; for(int i=1; i<=9; i++){ if(cnt[i]!=0 && cnt[i]!=2) check2=0; } if(check2) return true; for(int i=1; i<=9; i++){ if(cnt[i]>=2){ cnt[i]-=2; if(check1(n-1)){ cnt[i]+=2; return true; } cnt[i]+=2; } } return false; } int main() { n=13; cin>>s; for(int i=0; i