A. Olympiad Date

time limit per test

1 second

memory limit per test

256 megabytes

The final of the first Olympiad by IT Campus "NEIMARK" is scheduled for March 1, 2025. A nameless intern was tasked with forming the date of the Olympiad using digits --- 01.03.2025.

To accomplish this, the intern took a large bag of digits and began drawing them one by one. In total, he drew nn digits --- the digit aiai was drawn in the ii-th turn.

You suspect that the intern did extra work. Determine at which step the intern could have first assembled the digits to form the date of the Olympiad (the separating dots can be ignored), or report that it is impossible to form this date from the drawn digits. Note that leading zeros must be displayed.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041≤t≤104). The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤201≤n≤20).

The second line of each test case contains nn integers aiai (0≤ai≤90≤ai≤9) --- the numbers that the intern pulled out in chronological order.

Output

For each test case, output the minimum number of digits that the intern could pull out. If all the digits cannot be used to make a date, output the number 00.

Example

Input

Copy

复制代码

4

10

2 0 1 2 3 2 5 0 0 1

8

2 0 1 2 3 2 5 0

8

2 0 1 0 3 2 5 0

16

2 3 1 2 3 0 1 9 2 1 0 3 5 4 0 3

Output

Copy

复制代码
9
0
8
15

解题说明:水题,直接遍历数组判断是否找出所需要的所有数字即可。

cpp 复制代码
#include <iostream>
#include<algorithm>
using namespace std;

int main()
{
	int  t = 1;
	cin >> t;
	while (t--) 
	{
		int n = 0;
		cin >> n;
		int a[21];
		int mp[11] = {0};
		int ans = 0;
		for (int i = 1; i <= n; i++)
		{
			cin >> a[i];
			mp[a[i]]++;
			if (mp[0] >= 3 && mp[1] >= 1 && mp[2] >= 2 && mp[3] >= 1 && mp[5] >= 1 && ans == 0)
			{
				ans = i;
			}
		}
		cout << ans << endl;
	}
	return 0;
}
相关推荐
CoovallyAIHub24 分钟前
避开算力坑!无人机桥梁检测场景下YOLO模型选型指南
深度学习·算法·计算机视觉
YouQian77228 分钟前
问题 C: 字符串匹配
c语言·数据结构·算法
yanxing.D34 分钟前
408——数据结构(第二章 线性表)
数据结构·算法
艾莉丝努力练剑1 小时前
【LeetCode&数据结构】二叉树的应用(二)——二叉树的前序遍历问题、二叉树的中序遍历问题、二叉树的后序遍历问题详解
c语言·开发语言·数据结构·学习·算法·leetcode·链表
YuTaoShao1 小时前
【LeetCode 热题 100】51. N 皇后——回溯
java·算法·leetcode·职场和发展
1 小时前
3D碰撞检测系统 基于SAT算法+Burst优化(Unity)
算法·3d·unity·c#·游戏引擎·sat
Tony沈哲2 小时前
OpenCV 图像调色优化实录:基于图像金字塔的 RAW / HEIC 文件加载与调色实践
opencv·算法
Jackilina_Stone2 小时前
【faiss】用于高效相似性搜索和聚类的C++库 | 源码详解与编译安装
android·linux·c++·编译·faiss
我就是全世界2 小时前
Faiss中L2欧式距离与余弦相似度:究竟该如何选择?
算法·faiss
boyedu2 小时前
比特币运行机制全解析:区块链、共识算法与数字黄金的未来挑战
算法·区块链·共识算法·数字货币·加密货币