Loop to iterate over every possible cell of the matrix
for ( long i = 0 ; i < n ; i ++ ) { for ( long j = 0 ; j < m ; j ++ ) { long val = v [ ( int ) i ] [ ( int ) j ] - x * ( i + j ) ; for ( long k = 0 ; k < dp . GetLength ( 0 ) ; k ++ ) { for ( long l = 0 ; l < dp . GetLength ( 1 ) ; l ++ ) { dp [ k , l ] = - 1 ; } } val = min_operation ( 0 , 0 , val , x ) ; ans = Math . Min ( ans , val ) ; } } return ans ; }