Compute the desired sum for all given cell indexes
for ( int i = 0 ; i < n ; i ++ ) { int ro = arr [ i ] . r , co = arr [ i ] . c ; cout << sum - row [ ro ] - col [ co ] + mat [ ro ] [ co ] << endl ; } }