Count maximum matrices

SPOJ - MATRIX