← Home
write a go solution for Description:
You have n stacks r_1,r_2,ldots,r_n. Each stack contains some positive integers ranging from 1 to n.

Define the following functions:

You want to know the values returned by textttinit(1),textttinit(2),ldots,textttinit(n).

Note that, during these calls, the stacks r_1,r_2,ldots,r_n don't change, so the calls textttinit(1),textttinit(2),ldots,textttinit(n) are independent.

Input Format:
The first line of the input contains one integer n (1<=n<=10^5) — the length of the array r.

Each of the following n lines contains several integers. The first integer k_i (0<=k_i<=10^5) represents the number of elements in the i-th stack, and the following k_i positive integers c_i,1,c_i,2,ldots,c_i,k_i (1<=c_i,j<=n) represent the elements in the i-th stack. c_i,1 is the bottom element.

In each test, sumk_i<=10^6.

Output Format:
You need to output n values, the i-th of which is the value returned by textttinit(i).

Note:
In the first example:

- When you call textttinit(1), set textttstacks:=[[1,2,2],[3,1,2],[1,2,1]], and then call textttget(stacks,1).   textttstacks[1] is not empty, set textttnew_pos:=2, and pop the top element of textttstacks[1], which makes textttstacks become [[1,2],[3,1,2],[1,2,1]], and then call textttget(stacks,2).  textttstacks[2] is not empty, set textttnew_pos:=2, and pop the top element of textttstacks[2], which makes textttstacks become [[1,2],[3,1],[1,2,1]], and then call textttget(stacks,2).  textttstacks[2] is not empty, set textttnew_pos:=1, and pop the top element of textttstacks[2], which makes textttstacks become [[1,2],[3],[1,2,1]], and then call textttget(stacks,1).  textttstacks[1] is not empty, set textttnew_pos:=2, and pop the top element of textttstacks[1], which makes textttstacks become [[1],[3],[1,2,1]], and then call textttget(stacks,2).  textttstacks[2] is not empty, set textttnew_pos:=3, and pop the top element of textttstacks[2], which makes textttstacks become [[1],[],[1,2,1]], and then call textttget(stacks,3).  textttstacks[3] is not empty, set textttnew_pos:=1, and pop the top element of textttstacks[3], which makes textttstacks become [[1],[],[1,2]], and then call textttget(stacks,1).  textttstacks[1] is not empty, set textttnew_pos:=1, and pop the top element of textttstacks[1], which makes textttstacks become [[],[],[1,2]], and then call textttget(stacks,1).  textttstacks[1] is empty, return 1.
- When you call textttinit(2), set textttstacks:=[[1,2,2],[3,1,2],[1,2,1]], and then call textttget(stacks,2).   textttstacks[2] is not empty, set textttnew_pos:=2, and pop the top element of textttstacks[2], which makes textttstacks become [[1,2,2],[3,1],[1,2,1]], and then call textttget(stacks,2).  textttstacks[2] is not empty, set textttnew_pos:=1, and pop the top element of textttstacks[2], which makes textttstacks become [[1,2,2],[3],[1,2,1]], and then call textttget(stacks,1).  textttstacks[1] is not empty, set textttnew_pos:=2, and pop the top element of textttstacks[1], which makes textttstacks become [[1,2],[3],[1,2,1]], and then call textttget(stacks,2).  textttstacks[2] is not empty, set textttnew_pos:=3, and pop the top element of textttstacks[2], which makes textttstacks become [[1,2],[],[1,2,1]], and then call textttget(stacks,3).  textttstacks[3] is not empty, set textttnew_pos:=1, and pop the top element of textttstacks[3], which makes textttstacks become [[1,2],[],[1,2]], and then call textttget(stacks,1).  textttstacks[1] is not empty, set textttnew_pos:=2, and pop the top element of textttstacks[1], which makes textttstacks become [[1],[],[1,2]], and then call textttget(stacks,2).  textttstacks[2] is empty, return 2.
- When you call textttinit(3), set textttstacks:=[[1,2,2],[3,1,2],[1,2,1]], and then call textttget(stacks,3).   textttstacks[3] is not empty, set textttnew_pos:=1, and pop the top element of textttstacks[3], which makes textttstacks become [[1,2,2],[3,1,2],[1,2]], and then call textttget(stacks,1).  textttstacks[1] is not empty, set textttnew_pos:=2, and pop the top element of textttstacks[1], which makes textttstacks become [[1,2],[3,1,2],[1,2]], and then call textttget(stacks,2).  textttstacks[2] is not empty, set textttnew_pos:=2, and pop the top element of textttstacks[2], which makes textttstacks become [[1,2],[3,1],[1,2]], and then call textttget(stacks,2).  textttstacks[2] is not empty, set textttnew_pos:=1, and pop the top element of textttstacks[2], which makes textttstacks become [[1,2],[3],[1,2]], and then call textttget(stacks,1).  textttstacks[1] is not empty, set textttnew_pos:=2, and pop the top element of textttstacks[1], which makes textttstacks become [[1],[3],[1,2]], and then call textttget(stacks,2).  textttstacks[2] is not empty, set textttnew_pos:=3, and pop the top element of textttstacks[2], which makes textttstacks become [[1],[],[1,2]], and then call textttget(stacks,3).  textttstacks[3] is not empty, set textttnew_pos:=2, and pop the top element of textttstacks[3], which makes textttstacks become [[1],[],[1]], and then call textttget(stacks,2).  textttstacks[2] is empty, return 2.. Output only the code with no comments, explanation, or additional text.