CF2153A.Circle of Apple Trees

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Circle of Apple Trees

There are nn apple trees arranged in a circle. Each tree bears exactly one apple, and the beauty of the apple on the ii-th tree is given by bib_i for all 1in1\le i\le n. You start in front of tree 11.

At each tree, you may choose to either eat the apple or skip it. After making your choice, you move to the next tree: from tree ii, you move to tree i+1i+1 for 1in11 \le i \le n - 1, and from tree nn, you move back to tree 11. This process continues indefinitely as you move through the trees in a cycle.

However, you have a special condition: you may only eat an apple if its beauty is strictly greater than the beauty of the last apple you ate. For example, if b=[2,1,2,3]b = [2, 1, 2, 3] and you eat the apple on tree 11 (beauty 22), you cannot eat the apples on trees 22 and 33 because their beauties are not greater than 22. However, you may eat the apple on tree 44 since b4=3>2b_4 = 3 \gt 2.

Note that you are allowed to skip an apple when you first encounter it, and you can choose to eat it later on a subsequent cycle.

Your task is to determine the maximum number of apples you can eat if you make optimal decisions on when to eat or skip each apple.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t5001 \le t \le 500). The description of the test cases follows.

The first line of each test case contains a single integer nn (1n1001 \le n\le 100) — the number of apple trees.

The second line of each test case contains nn integers b1,b2,,bnb_1, b_2, \ldots, b_n (1bin1\le b_i\le n) — the beauty of the apples on the trees.

Note that there are no constraints on the sum of nn over all test cases.

Output

For each test case, output a single integer representing the maximum number of apples you can eat.

Note

In the first test case, since all apples have the same beauty, no matter which apple you eat first, you cannot eat any others afterward. Hence, the maximum number of apples that you can eat is 11.

In the second test case, you can eat four apples as follows:

  • At tree 11, skip the apple.
  • At tree 22, skip the apple.
  • At tree 33, skip the apple.
  • At tree 44, eat the apple (beauty 11).
  • At tree 55, eat the apple (beauty 22).
  • At tree 11, skip the apple. You are not allowed to eat the apple as its beauty (b1=1b_1 = 1) is not greater than the beauty of the last apple you ate (b5=2b_5 = 2).
  • At tree 22, eat the apple (beauty 44).
  • At tree 33, eat the apple (beauty 55).

It can be proven that it is not possible to eat all five apples; hence, the maximum number of apples that you can eat is 44.

Samples

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

在线编程 IDE

建议全屏模式获得最佳体验