A=[31,992,27648,1015808,32505856,1082401,2164802,4325508,8659208,17318416,4325535,33057855,33088575,17039425,1114384] x={} 0.upto(4){|i|j=-1;gets.split.map{x[_1]=i*5+j+=1}} gets c=4096 $<.map{(u=x[_1.chop])&&c|=1<