Mint a00,a01,a02,a10,a11,a12,a20,a21,a22; ll b2=0,b5=0; string@n; for(char c:n){ int d=c-'0'; a22=a12*1+a20*2+a21*4+a22*9; a21=a11*1+a20*2+a21*5; a20=a10*1+a20*5; a12=a02*1+a10*2+a11*4+a12*8; a11=a01*1+a10*2+a11*4; a10=a00*1+a10*4; a02=a00*2+a01*4+a02*8; a01=a00*2+a01*4; a00=a00*4; if(b5==0){ if(b2==0){ a00+=(d>1)+(d>3)+(d>7); a01+=(d>2)+(d>6); a02+=(d>4)+(d>8); a10+=(d>5); } if(b2==1){ a01+=(d>1)+(d>3)+(d>7); a02+=(d>2)+(d>4)+(d>6)+(d>8); a11+=(d>5); } if(b2==2){ a02+=(d>1)+(d>2)+(d>3)+(d>4)+(d>6)+(d>7)+(d>8); a12+=(d>5); } } if(b5==1){ if(b2==0){ a10+=(d>1)+(d>3)+(d>7); a11+=(d>2)+(d>6); a12+=(d>4)+(d>8); a20+=(d>5); } if(b2==1){ a11+=(d>1)+(d>3)+(d>7); a12+=(d>2)+(d>4)+(d>6)+(d>8); a21+=(d>5); } if(b2==2){ a12+=(d>1)+(d>2)+(d>3)+(d>4)+(d>6)+(d>7)+(d>8); a22+=(d>5); } } if(b5==2){ if(b2==0){ a20+=(d>1)+(d>3)+(d>5)+(d>7); a21+=(d>2)+(d>6); a22+=(d>4)+(d>8); } if(b2==1){ a21+=(d>1)+(d>3)+(d>5)+(d>7); a22+=(d>2)+(d>4)+(d>6)+(d>8); } if(b2==2){ a22+=(d>1)+(d>2)+(d>3)+(d>4)+(d>5)+(d>6)+(d>7)+(d>8); } } a00+=1; b2+=(b2<2)&0524>>d; b2+=(b2<2)&0420>>d; b5+=(b5<2)&0040>>d; if(d==0) b2=b5=3; } wt(a22+(b5==2&&b2==2));