Store the frequency of the four cells
mp [ mat [ i ] [ M - 1 - j ] ] = mp . get ( mat [ i ] [ M - 1 - j ] , 0 ) + 1 NEW_LINE mp [ mat [ i ] [ j ] ] = mp . get ( mat [ i ] [ j ] , 0 ) + 1 NEW_LINE mp [ mat [ N - 1 - i ] [ M - 1 - j ] ] = mp . get ( mat [ N - 1 - i ] [ M - 1 - j ] , 0 ) + 1 NEW_LINE mp [ mat [ N - 1 - i ] [ j ] ] = mp . get ( mat [ N - 1 - i ] [ j ] , 0 ) + 1 NEW_LINE x = 0 NEW_LINE