Subject Pairing

Time limit: 0.4s Memory limit: 16MB Input: Output:

Every February, 10th-grade students at the school select their optional subjects for the next academic year.

Each of the NN students (numbered from 00 to N1N - 1) submits a list of subjects they would like to attend. Students must choose at least one and at most five subjects from a total of MM available subjects. The subjects are numbered from 11 to MM (inclusive).

Your task is to help the schedule creator determine which pairs of subjects can be held simultaneously. A pair of subjects (i,j)(i, j) can be scheduled at the same time if no student has chosen both subjects. Note that the pair (i,j)(i, j) is considered the same as (j,i)(j, i).

Input data

The first line contains two integers NN and MM.

Each of the next NN lines contains an integer KiK_i, indicating the number of subjects chosen by student ii, followed by KiK_i integers Si,jS_{i,j}, denoting the chosen subjects.

Output data

In the first line you need to write an integer PP, indicating the number of pairs.

In each of the next PP lines you should write two integers, denoting a pair of subjects that can be held simultaneously. You can write the pairs in arbitrary order.

Constraints and clarifications

  • 1N100 0001 \le N \le 100 \ 000.
  • 1M1 0001 \le M \le 1 \ 000.
  • 1Ki51 \le K_i \le 5 for each i=0N1i=0\ldots N-1.
  • 1Si,jM1 \le S_{i, j} \le M for each i=0N1i=0\ldots N-1 and j=0Ki1j=0\ldots K_{i}-1.
# Points Constraints
1 0 Examples
2 30 N100,M10N \le 100, M \le 10.
3 20 A subject may be selected by at most 11 student.
4 50 No additional constraints.

Example 1

stdin

4 5
4 1 2 3 4
1 2
2 1 5
3 2 3 1

stdout

3
2 5
3 5
5 4

Explanation

In the first sample case:

  • Subjects (1,2)(1, 2) are selected by students: 0,30, 3.
  • Subjects (1,3)(1, 3) are selected by students: 0,30, 3.
  • Subjects (1,4)(1, 4) is selected by student: 00.
  • Subjects (1,5)(1, 5) is selected by student: 22.
  • Subjects (2,3)(2, 3) are selected by students: 0,30, 3.
  • Subjects (2,4)(2, 4) is selected by student: 00.
  • Subjects (3,4)(3, 4) is selected by student: 00.

Any other pair of subjects can be held at the same time.

Example 2

stdin

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

stdout

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

Log in or sign up to be able to send submissions!