will not work for negative elements , so . . adding this
if ( matrix [ 0 ] [ 0 ] < 0 ) { mod = k - ( abs ( matrix [ 0 ] [ 0 ] ) % k ) ; } else { mod = matrix [ 0 ] [ 0 ] % k ; } for ( int i = 0 ; i < n ; ++ i ) { for ( int j = 0 ; j < m ; ++ j ) { arr . push_back ( matrix [ i ] [ j ] ) ;