logo AlgoBeat OnlineJudge
登录 注册

#213880. [eJOI 2022] Adjacent Pairs

内存限制:2048 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Let's call an array good, if for any with .

You are given a good array of positive integers .

You can perform the following operations on this array:

  • Choose any index () and a number (). Then, set to . After this operation, the array has to remain good.

You want to perform several operations so that the resulting array will contain exactly two distinct values. Determine the smallest number of operations needed to achieve this goal.

输入格式

The first line of input contains the integer (), the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer () - the length of the array.

The second line of each test case contains integers () - elements of the array. It's guaranteed that for (that is, the array is good).

It is guaranteed that the sum of over all test cases does not exceed .

输出格式

For each test case, output a single integer - the smallest number of operations needed to achieve an array in which there are exactly two distinct values.

样例

样例输入 1

2
5
4 5 2 4 5
2
1 2

样例输出 1

3
0

数据范围与提示

Note

In the first test case, one of the optimal sequences of operations is:

.

In the second test case, the array already contains only two distinct values, so the answer is .

Scoring

  1. (20 points): The sum of over all test cases does not exceed
  2. (10 points): The sum of over all test cases does not exceed
  3. (25 points): The sum of over all test cases does not exceed
  4. (45 points): No additional constraints