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;
}
相关推荐
吃着火锅x唱着歌2 分钟前
LeetCode 2110.股票平滑下跌阶段的数目
数据结构·算法·leetcode
青草地溪水旁2 分钟前
设计模式(C++)详解—原型模式(2)
c++·设计模式·原型模式
青草地溪水旁8 分钟前
设计模式(C++)详解—原型模式(3)
c++·设计模式·原型模式
C++_girl20 分钟前
缓存未命中
c++·缓存
bikong733 分钟前
桥接模式,打造灵活可扩展的日志系统C++
c++·桥接模式
艾莉丝努力练剑37 分钟前
【C++】类和对象(下):初始化列表、类型转换、Static、友元、内部类、匿名对象/有名对象、优化
linux·运维·c++·经验分享
疋瓞1 小时前
C++_STL和数据结构《1》_STL、STL_迭代器、c++中的模版、STL_vecto、列表初始化、三个算法、链表
数据结构·c++·算法
JJJJ_iii1 小时前
【左程云算法09】栈的入门题目-最小栈
java·开发语言·数据结构·算法·时间复杂度
三体世界1 小时前
测试用例全解析:从入门到精通(1)
linux·c语言·c++·python·功能测试·测试用例·测试覆盖率
Bear on Toilet1 小时前
继承类模板:函数未在模板定义上下文中声明,只能通过实例化上下文中参数相关的查找找到
开发语言·javascript·c++·算法·继承