Candidate Elimination
시간 제한4초메모리 제한2048 MB
스도쿠 그룹의 각 칸 후보 집합이 주어질 때, 정확히 하나의 네이키드 부분집합으로 제거 가능한 후보를 모두 찾는다.
문제
James has been learning how to solve sudoku puzzles recently. He had recently learned about a concept called "Naked Pairs". A pair of cells is called a Naked Pair when it satisfies the following conditions.
- The two cells lie in the same group. In sudoku, a group is a set of cells that must contain all integers from to .
- Both cells contain a subset of the same set of candidates , where .
Given a naked pair, one can remove the candidates in from all other cells in the group, since you know that in a valid sudoku each candidate in must appear in one of the two cells.
While learning more about it, James realized that the concept of a "Naked Subset" can generalize the naked pairs. A set of cells with cells is called a Naked Subset when it satisfies the following conditions.
- The cells lie in the same group.
- All cells in contain a subset of the same set of candidates , where .
Given a naked subset, one can remove the candidates in from all other cells in the group, since you know that in a valid sudoku each candidate in must appear in one of the cells.
James has been whining about how hard it is to find naked subsets in very big sudoku puzzles. Given a group, your job is to find every candidate that can be eliminated using exactly one naked subset.
입력
The first line consists of one integer , the size of one group. ()
The following lines represent cells that belong to the group. The -th line consists of one integer , followed by distinct integers. The integers represent the candidates possible on the -th cell.
It is guaranteed that the sum of is at most .
Additionally, it is guaranteed that there is a valid assignment to all cells in the group. In other words, there exists at least one way to choose one candidate per cell, such that all integers chosen are distinct.
출력
Output lines. The -th line must consist of the candidates that can be removed from the -th cell in increasing order, with the format being same as the input format.
힌트
In the first sample, the cells in the group belong to the box with green digits. The removals are done using the following naked subsets.
- Cells have candidates , so you can remove from cell , from cell and from cell .
- Cells have candidates , so you can remove from cells and .
- Cells have candidates , so you can remove from cell .

The sudoku board corresponding to the sample. Generated using HoDoKu, an open source sudoku solver.