import Data.List e=transpose h=head m=map l=length d=foldr(\x y->2*y+x)0.reverse (#)q=h.q.sortBy((.l).compare.l).group.sort f%x|x==[[]]=[]|i<-f#h(e x)=i:f%[u|y:u<-x,y==i] t x=d(last%x)*d(h%x) main=interact$show.((,).t<*>((*)<*>(-)4095).d.m(h#).e).m(m((-48+).fromEnum)).lines