n × n matrix grid. Count the pairs (row r, column c) where row r and column c are identical: they hold the same numbers in the same order (a row is read left to right, a column top to bottom).
One row can pair with several columns and vice versa; each pair counts separately.grid=[[2, 4], [4, 2]] → 2
Row 0, [2, 4], matches column 0, and row 1, [4, 2], matches column 1.
grid=[[1, 2], [3, 4]] → 0
The columns are [1, 3] and [2, 4], and neither matches any row.
grid=[[7, 7], [7, 7]] → 4
Every row and every column is [7, 7], so all 4 pairs count.
n ≤ 200grid[i][j] ≤ 10⁵grid=[[2, 4], [4, 2]]
2
Run checks the first 3 tests in your browser. Submit checks all 60 tests on the server, hidden ones included.