#abc226b. [abc226_b]Counting Arrays

[abc226_b]Counting Arrays

Problem Statement

You are given NN sequences numbered 11 to NN.
Sequence ii has a length of LiL_i and its jj-th element (1leqjleqLi)(1 \\leq j \\leq L_i) is ai,ja_{i,j}.

Sequence ii and Sequence jj are considered the same when Li=LjL_i = L_j and ai,k=aj,ka_{i,k} = a_{j,k} for every kk (1leqkleqLi)(1 \\leq k \\leq L_i).
How many different sequences are there among Sequence 11 through Sequence NN?

Constraints

  • 1leqNleq2times1051 \\leq N \\leq 2 \\times 10^5
  • 1leqLileq2times1051 \\leq L_i \\leq 2 \\times 10^5 (1leqileqN)(1 \\leq i \\leq N)
  • 0leqai,jleq1090 \\leq a_{i,j} \\leq 10^{9} (1leqileqN,1leqjleqLi)(1 \\leq i \\leq N, 1 \\leq j \\leq L_i)
  • The total number of elements in the sequences, sumi=1NLi\\sum_{i=1}^N L_i, does not exceed 2times1052 \\times 10^5.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN L1L_1 a1,1a_{1,1} a1,2a_{1,2} dots\\dots a1,L1a_{1,L_1} L2L_2 a2,1a_{2,1} a2,2a_{2,2} dots\\dots a2,L2a_{2,L_2} vdots\\vdots LNL_N aN,1a_{N,1} aN,2a_{N,2} dots\\dots aN,LNa_{N,L_N}

Output

Print the number of different sequences.


Sample Input 1

4
2 1 2
2 1 1
2 2 1
2 1 2

Sample Output 1

3

Sample Input 11 contains four sequences:

  • Sequence 11 : (1,2)(1, 2)
  • Sequence 22 : (1,1)(1, 1)
  • Sequence 33 : (2,1)(2, 1)
  • Sequence 44 : (1,2)(1, 2)

Except that Sequence 11 and Sequence 44 are the same, these sequences are pairwise different, so we have three different sequences.


Sample Input 2

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

Sample Output 2

4

Sample Input 22 contains five sequences:

  • Sequence 11 : (1)(1)
  • Sequence 22 : (1)(1)
  • Sequence 33 : (2)(2)
  • Sequence 44 : (1,1)(1, 1)
  • Sequence 55 : (1,1,1)(1, 1, 1)

Sample Input 3

1
1 1

Sample Output 3

1