If values at current indexes are same then increment the current score
curSum += ( a [ pos [ i ] ] [ j ] == b [ i ] [ j ] ) ; maxSum = max ( maxSum , curSum ) ; } } } while ( next_permutation ( pos . begin ( ) , pos . end ( ) ) ) ;