#C6640. Find Permuted Row Pairs

    ID: 50423 Type: Default 1000ms 256MiB

Find Permuted Row Pairs

Find Permuted Row Pairs

Given an (n \times m) matrix of integers, a row is considered a permutation of another if it contains the same integers (possibly in a different order). Your task is to count and list all pairs of rows (using 1-indexing) that are permutations of each other. Two rows (i) and (j) (with (i < j)) form a valid pair if (sorted(row_i) = sorted(row_j)).

The input starts with two integers (n) and (m). It is followed by (n) lines, each containing (m) integers which represent the rows of the matrix. The output must first print the total number of valid pairs, and then each subsequent line should print a pair of row indices separated by a space.

inputFormat

The first line of the input contains two space-separated integers (n) and (m) indicating the number of rows and columns, respectively. Each of the following (n) lines contains (m) space-separated integers representing a row of the matrix.

outputFormat

The output consists of multiple lines. The first line contains a single integer (k), the number of pairs of rows that are permutations of each other. Each of the following (k) lines contains two space-separated integers (i) and (j) representing a valid pair (with (i < j)).## sample

3 3
1 2 3
4 5 6
7 8 9
0

</p>