PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000306. Mã bí mật (Code Feat)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Mã bí mật (Code Feat)

Code Feat

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Agent Bauer must deactivate a bomb protected by a security code that is a strictly positive integer. CTU analysts have obtained several clues describing which remainders are allowed when dividing the code by a certain integer.

A clue consists of an integer X≥2X\ge 2 and a set of kk distinct remainders {Y1,Y2,…,Yk}\{Y_1,Y_2,\ldots,Y_k\}. The code must have a remainder belonging to this set when divided by XX. The moduli XX of different clues are pairwise coprime.

Call a positive integer valid if it satisfies all clues simultaneously. There are infinitely many valid integers, but the experts want to examine the smallest ones first.

Find exactly the SS smallest valid positive integers and print them in increasing order, each exactly once.

Input

  • The first line contains integers C,SC,S, the number of clues and requested answers.
  • For each i=1,…,Ci=1,\ldots,C, one line contains Xi,kiX_i,k_i, followed by exactly kik_i distinct integers Yi,1,…,Yi,kiY_{i,1},\ldots,Y_{i,k_i}, the allowed remainders modulo XiX_i.

Output

Print exactly SS lines. Line jj contains the jj-th smallest valid positive integer, so the values must be strictly increasing.

Subtasks

  • Subtask 1 (20 points): 1≤C≤21\le C\le2, 1≤S≤101\le S\le10; 2≤Xi≤1002\le X_i\le100; 1≤ki≤min⁡(100,Xi)1\le k_i\le\min(100,X_i); 0≤Yi,j<Xi0\le Y_{i,j}<X_i, distinct remainders within each clue; gcd⁡(Xi,Xj)=1\gcd(X_i,X_j)=1 for all i≠ji\ne j; ∏iXi≤104\prod_iX_i\le10^4.
  • Subtask 2 (30 points): 1≤C≤51\le C\le5, 1≤S≤101\le S\le10; 2≤Xi≤1062\le X_i\le10^6; 1≤ki≤min⁡(100,Xi)1\le k_i\le\min(100,X_i); 0≤Yi,j<Xi0\le Y_{i,j}<X_i, distinct remainders within each clue; gcd⁡(Xi,Xj)=1\gcd(X_i,X_j)=1 for all i≠ji\ne j; ∏iXi≤106\prod_iX_i\le10^6.
  • Subtask 3 (50 points): 1≤C≤91\le C\le9, 1≤S≤101\le S\le10; 2≤Xi≤231−12\le X_i\le2^{31}-1; 1≤ki≤min⁡(100,Xi)1\le k_i\le\min(100,X_i); 0≤Yi,j<Xi0\le Y_{i,j}<X_i, distinct remainders within each clue; gcd⁡(Xi,Xj)=1\gcd(X_i,X_j)=1 for all i≠ji\ne j; ∏iXi≤231−1\prod_iX_i\le2^{31}-1.

Examples

Example 1

Input

3 2
2 1 1
5 2 0 3
3 2 1 2

Output

5
13

Explanation

The remainders of 55 modulo 2,5,32,5,3 are 1,0,21,0,2, respectively. The remainders of 1313 are 1,3,11,3,1. Both satisfy every clue. Every positive integer below 55, and every integer from 66 through 1212, violates at least one clue, so these are the two smallest answers.

Example 2

Input

1 3
4 2 0 2

Output

2
4
6

Explanation

The allowed remainders modulo 44 are 00 and 22. The valid positive integers start with 2,4,6,8,…2,4,6,8,\ldots; thus the first three are 2,4,62,4,6.