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 x%f|x==[[]]=[]|i<-f#h(e x)=i:[u|y:u<-x,y==i]%f t x=d(x%last)*d(x%h) main=interact$show.((,).t<*>((*)<*>(-)4095).d.m(h#).e).m(m(read.pure)).lines