char S[2d4]; mint d[3d4],e[3d4],z; ll M,i,c; { rd(S,M); for(;S[i];){ c=S[i++]-48; e[((0..M)*10+c)%M]+=d[0..]; (c?e[c%M]:z)+=1; d[0..M]=e[0..]; } wt(*d+z); }