Find frequency of each distinct size for 0 s and 1 s .
for i in range ( n ) : NEW_LINE INDENT for j in range ( m ) : NEW_LINE INDENT if ( mat [ i ] [ j ] == 0 ) : NEW_LINE INDENT freq0 [ dp [ i ] [ j ] ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT freq1 [ dp [ i ] [ j ] ] += 1 NEW_LINE DEDENT DEDENT DEDENT