#include<algorithm>#include<functional>#include<iostream>structMentsu{intjantou=0;// 雀頭の数 (0 to 1)intkoutsu=0;// 刻子の数 (0 to 1)intshuntsu=0;// 順子の数 (0 to 4)};booliswh0(constint*h,Mentsu*m){inta=h[0],b=h[1];for(inti=0;i<7;++i){if(a>=3){a-=3;m[i].koutsu=1;}if(constintr=a;b>=r&&h[i+2]>=r){a=b-r;b=h[i+2]-r;m[i].shuntsu+=r;}elsereturnfalse;}if(a==3){a=0;m[7].koutsu=1;}if(b==3){b=0;m[8].koutsu=1;}returna==0&&b==0;}voidiswh2(int*h,Mentsu*m,std::function<void(Mentsu*)>func){ints=0;for(inti=0;i<9;++i){s+=i*h[i];}for(intp=s*2%3;p<9;p+=3){if(h[p]>=2){h[p]-=2;std::fill(m,m+9,Mentsu{});if(iswh0(h,m)){h[p]+=2;m[p].jantou=1;func(m);}elseh[p]+=2;}}}voidkoutsu3(Mentsu*m,std::function<void(Mentsu*)>func){for(inti=0;i<7;++i){if(m[i].koutsu&&m[i+1].koutsu&&m[i+2].koutsu){m[i].koutsu=0;m[i+1].koutsu=0;m[i+2].koutsu=0;m[i].shuntsu+=3;func(m);m[i].koutsu=1;m[i+1].koutsu=1;m[i+2].koutsu=1;m[i].shuntsu-=3;}}}voidprint(constMentsu*m){for(inti=0;i<9;++i){if(m[i].jantou){std::cout<<"["<<i+1<<","<<i+1<<"],";}elseif(m[i].koutsu){std::cout<<"["<<i+1<<","<<i+1<<","<<i+1<<"],";}elseif(m[i].shuntsu){for(intj=0;j<m[i].shuntsu;++j){std::cout<<"["<<i+1<<","<<i+2<<","<<i+3<<"],";}}}std::cout<<"\n";}intmain(intargc,char*argv[]){if(argc!=2){std::cout<<argc<<std::endl;return1;}inth[9]={};Mentsum[9]={};for(inti=0;i<14;++i){if(argv[1][i]<'1'&&argv[1][i]>'9'){return1;}++h[argv[1][i]-'1'];}iswh2(h,m,[](Mentsu*m){print(m);koutsu3(m,[](Mentsu*m){print(m);});});return0;}