Iterating over the matrix
for i in range ( N ) : NEW_LINE INDENT for j in range ( M ) : NEW_LINE INDENT if ( i + j == left ) : NEW_LINE INDENT mp [ mat [ i ] [ j ] ] = NEW_LINE mp . get ( mat [ i ] [ j ] , 0 ) + 1 NEW_LINE totalsize += 1 NEW_LINE DEDENT elif ( i + j == right ) : NEW_LINE INDENT mp [ mat [ i ] [ j ] ] = NEW_LINE mp . get ( mat [ i ] [ j ] , 0 ) + 1 NEW_LINE totalsize += 1 NEW_LINE DEDENT DEDENT DEDENT