A. One and Two

A. One and Two

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a sequence 𝑎1,𝑎2,…,𝑎𝑛a1,a2,…,an. Each element of 𝑎a is 11 or 22.

Find out if an integer 𝑘k exists so that the following conditions are met. 

  • 1≤𝑘≤𝑛−11≤k≤n−1, and 
  • 𝑎1⋅𝑎2⋅…⋅𝑎𝑘=𝑎𝑘+1⋅𝑎𝑘+2⋅…⋅𝑎𝑛a1⋅a2⋅…⋅ak=ak+1⋅ak+2⋅…⋅an. 

If there exist multiple 𝑘k that satisfy the given condition, print the smallest.

Input

Each test contains multiple test cases. The first line contains the number of test cases 𝑡t (1≤𝑡≤1001≤t≤100). Description of the test cases follows.

The first line of each test case contains one integer 𝑛n (2≤𝑛≤10002≤n≤1000).

The second line of each test case contains 𝑛n integers 𝑎1,𝑎2,…,𝑎𝑛a1,a2,…,an (1≤𝑎𝑖≤21≤ai≤2).

Output

For each test case, if there is no such 𝑘k, print −1−1.

Otherwise, print the smallest possible 𝑘k.

Example

input

Copy

 

3

6

2 2 1 2 1 2

3

1 2 1

4

1 1 1 1

output

Copy

2
-1
1

Note

For the first test case, 𝑘=2k=2 satisfies the condition since 𝑎1⋅𝑎2=𝑎3⋅𝑎4⋅𝑎5⋅𝑎6=4a1⋅a2=a3⋅a4⋅a5⋅a6=4. 𝑘=3k=3 also satisfies the given condition, but the smallest should be printed.

For the second test case, there is no 𝑘k that satisfies 𝑎1⋅𝑎2⋅…⋅𝑎𝑘=𝑎𝑘+1⋅𝑎𝑘+2⋅…⋅𝑎𝑛a1⋅a2⋅…⋅ak=ak+1⋅ak+2⋅…⋅an

For the third test case, 𝑘=1k=1, 22, and 33 satisfy the given condition, so the answer is 11.

由于考虑的是乘法,所以不用管1,只要管2

#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<stack>
#include<string>
#include<algorithm>
#include<map>
#include<cstring>
#include<queue>
#include<set>
#include<stdlib.h>
#define dbug cout<<"hear!"<<endl;
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 2e5 + 5, INF = 0x3f3f3f3f;
ll gcdd(ll a, ll b)
{
	if (b) while ((a %= b) && (b %= a));
	return a + b;
}

ll t,n,m,a,b,cnt,ans,ant;
ll  arr[N],brr[N];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		cin>>n;
		cnt=0;
		ant=0;
		for(int i=1;i<=n;i++)
		{
			cin>>arr[i];
			if(arr[i]==2)
			{
				cnt++;
			}
		}
		if(cnt%2==1)
		{
			cout<<-1<<endl;
		}
		else if(cnt==0)
		{
			cout<<1<<endl;
		}
		else{
			for(int j=1;j<=n;j++)
			{
				if(arr[j]==2)
				{
					ant++;
					if(ant==cnt/2)
					{
						ans=j;
						break;
					}
				}
			}
			cout<<ans<<endl;
		}
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值