Let's call an array tt dominated by value vv in the next situation.

At first, array tt should have at least 22 elements. Now, let's calculate number of occurrences of each number numnum in tt and define it as occ(num)occ(num). Then tt is dominated (by vv) if (and only if) occ(v)>occ(v′)occ(v)>occ(v′) for any other number v′v′. For example, arrays [1,2,3,4,5,2][1,2,3,4,5,2], [11,11][11,11] and [3,2,3,2,3][3,2,3,2,3] are dominated (by 22, 1111 and 33 respectevitely) but arrays [3][3], [1,2][1,2] and [3,3,2,2,1][3,3,2,2,1] are not.

Small remark: since any array can be dominated only by one number, we can not specify this number and just say that array is either dominated or not.

You are given array a1,a2,…,ana1,a2,…,an. Calculate its shortest dominated subarray or say that there are no such subarrays.

The subarray of aa is a contiguous part of the array aa, i. e. the array ai,ai+1,…,ajai,ai+1,…,aj for some 1≤i≤j≤n1≤i≤j≤n.

Input

The first line contains single integer TT (1≤T≤10001≤T≤1000) — the number of test cases. Each test case consists of two lines.

The first line contains single integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the length of the array aa.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤n1≤ai≤n) — the corresponding values of the array aa.

It's guaranteed that the total length of all arrays in one test doesn't exceed 2⋅1052⋅105.

Output

Print TT integers — one per test case. For each test case print the only integer — the length of the shortest dominated subarray, or −1−1 if there are no such subarrays.

Example
input

Copy
4
1
1
6
1 2 3 4 5 1
9
4 1 2 4 5 4 3 2 1
4
3 3 3 3
output

Copy
-1
6
3
2
Note

In the first test case, there are no subarrays of length at least 22, so the answer is −1−1.

In the second test case, the whole array is dominated (by 11) and it's the only dominated subarray.

In the third test case, the subarray a4,a5,a6a4,a5,a6 is the shortest dominated subarray.

In the fourth test case, all subarrays of length more than one are dominated.

#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+;
int n,a[maxn],pre[maxn];
int main() {
int t;
scanf("%d",&t);
while(t--) {
scanf("%d",&n);
int ans=0x3f3f3f3f;
for(int i=; i<=n; i++) pre[i]=-;
for(int i=; i<=n; i++) {
scanf("%d",&a[i]);//先输入
if(pre[a[i]]!=-)//判断之前有没有出现过
ans=min(ans,i-pre[a[i]]+);//如果出现过,取到上一个点的距离并取最小
pre[a[i]]=i;//标记此时点的距离
}
printf("%d\n",ans==0x3f3f3f3f?-:ans);
}
}
//计算每两个相同元素的距离对ans 取min

最新文章

  1. 关于maven中央仓库jar包不存在问题
  2. array new 与 array deletedelete
  3. 写启动界面Splash的正确姿势,解决启动白屏(转)
  4. Effective C++ -----条款35:考虑virtual函数以外的其他选择
  5. Codeforces 374A - Inna and Pink Pony
  6. codevs1002搭桥(建图+Prim)
  7. Hibernate的fetch
  8. nmap svn
  9. Linux命令初步了解
  10. Android学习笔记—Windows下NDK开发简单示例
  11. Spring MVC 基础笔记
  12. new Date()设置日期在IOS的兼容问题
  13. C#编码问题以及C#往Mysql插数据编码问题
  14. Yii常用方法
  15. vue-01
  16. new.target
  17. Winform Treeview 排序及图标处理
  18. Git内网服务搭建全过程
  19. 在SpringMVC中使用@RequestBody和@ResponseBody注解处理json时,报出HTTP Status 415的解决方案
  20. vertex shader(1)

热门文章

  1. 双向链表的简单Java实现-sunziren
  2. PP: Deep clustering based on a mixture of autoencoders
  3. Runtime.addShutdownHook用法
  4. Django models 关联(一对多,多对多,一对一)
  5. 从零开始的JAVA(1).输入
  6. ISCC2018 Reverse &amp; Pwn writeup
  7. 2019-08-18 纪中NOIP模拟A组
  8. IDEA模板注释及相关快捷键设置
  9. H5手机端开发问题及解决方案
  10. 论文阅读笔记(三)【AAAI2017】:Learning Heterogeneous Dictionary Pair with Feature Projection Matrix for Pedestrian Video Retrieval via Single Query Image