m@main=getLine>>=putStrLn.h>>m h s=[t|t<-f s,let n=mod(length t)2,1>mod(sum[sum[a|x<-w,x<b]|(a,b)<-zip([[10,9..],cycle[1,3]]!!n)$drop 4t])(11-n)]!!0 f('?':s)=map(:s)w f(a:s)=map(a:)$f s w=['0'..'9']
Note that non-ascii characters in the above source code will be escaped (such as \x9f).