Loop to iterate over the elements of the matrix
for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( mat [ i ] [ j ] > k ) { int m = mat [ i ] [ j ] - k ; if ( ump . find ( m ) != ump . end ( ) ) { return true ; } } else { int m = k - mat [ i ] [ j ] ; if ( ump . find ( m ) != ump . end ( ) ) { return true ; } } ump . insert ( mat [ i ] [ j ] ) ; } } return false ; }