A. Even Subset Sum Problem

You are given an array aa consisting of nn positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by 22) or determine that there is no such subset.
Both the given array and required subset may contain equal values.

Input

The first line contains a single integer t(1t100)t (1≤t≤100), number of test cases to solve. Descriptions of t test cases follow.
A description of each test case consists of two lines. The first line contains a single integer n(1n100)n (1≤n≤100), length of array aa.
The second line contains nn integers a1,a2,,an(1ai100)a_1,a_2,…,a_n (1≤a_i≤100), elements of aa. The given array a can contain equal values (duplicates).

Output

For each test case output 1−1 if there is no such subset of elements. Otherwise output positive integer kk, number of elements in the required subset. Then output kk distinct integers (1pin)(1≤p_i≤n), indexes of the chosen elements. If there are multiple solutions output any of them.

Example

input

3
3
1 4 3
1
15
2
3 5

output

1
2
-1
2
1 2

Note

There are three test cases in the example.
In the first test case, you can choose the subset consisting of only the second element. Its sum is 44 and it is even.
In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.
In the third test case, the subset consisting of all array’s elements has even sum.

Translation

给一个数集,要求找到任意一个非空子集,使得子集内的所有元素和为偶数。

Idea

如果给定数集中有一个偶数,可以把这个偶数单独拿出来作为子集;如果集合中没有偶数,那就拿两个奇数出来,如果连两个奇数都没有,那就不存在这样的子集。

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<iostream>
#include<vector>
using namespace std;
const int N=105;
void solve()
{
int i;
int a[N];
vector<int>pos;
int n;
cin>>n;
for(i=1;i<=n;i++)
{
cin>>a[i];
}
for(i=1;i<=n;i++)
{
if((a[i]&1)==0)
{
cout<<1<<endl;
cout<<i<<endl;
return;//找到偶数
}
else pos.push_back(i);
}
if (pos.size()<=1) cout<<-1<<endl;//只有不到2个奇数
else cout<<2<<endl<<pos[0]<<' '<<pos[1]<<endl;
}
int main()
{
int t;
cin>>t;
while(t--) solve();
return 0;
}

B. Count Subrectangles

You are given an array a of length n and array b of length m both consisting of only integers 0 and 1. Consider a matrix c of size n×m formed by following rule: cij=aibjc_{ij}=a_ib_j (i.e. aia_i multiplied by bjb_j). It’s easy to see that c consists of only zeroes and ones too.
How many subrectangles of size (area) kk consisting only of ones are there in cc?
A subrectangle is an intersection of a consecutive (subsequent) segment of rows and a consecutive (subsequent) segment of columns. I.e. consider four integers x1,x2,y1,y2(1x1x2n,1y1y2m)x_1,x_2,y_1,y_2 (1≤x_1≤x_2≤n, 1≤y_1≤y_2≤m) a subrectangle c[x1x2][y1y2]c[x1…x2][y1…y2] is an intersection of the rows x1,x1+1,x1+2,,x2x_1,x_1+1,x_1+2,…,x_2 and the columns y1,y1+1,y1+2,,y2y_1,y_1+1,y_1+2,…,y_2.
The size (area) of a subrectangle is the total number of cells in it.

Input

The first line contains three integers n,mn, m and k(1n,m40000,1knm)k (1≤n,m≤40000,1≤k≤nm), length of array aa, length of array bb and required size of subrectangles.
The second line contains n integers a1,a2,,an(0ai1)a_1,a_2,…,a_n (0≤a_i≤1), elements of aa.
The third line contains m integers b1,b2,,bm(0bi1)b_1,b_2,…,b_m (0≤b_i≤1), elements of bb.

Output

Output single integer — the number of subrectangles of cc with size (area) kk consisting only of ones.

Examples

input

3 3 2
1 0 1
1 1 1

output

4

input

3 5 4
1 1 1
1 1 1 1 1

output

14

Note

In first example matrix cc is:

There are 44 subrectangles of size 22 consisting of only ones in it:

In second example matrix cc is:

Translation

给一个长度为nn的数组aa,一个长度为mm的数组bb,连个数组都只有00或者11cc数组是二维数组c[i][j]=a[i]×b[j]c[i][j]=a[i]\times b[j]cc中连续的一片11组成一块面积,问面积为k的矩形有几个。

Idea

aa中一段连续的长度为lal_a11,和bb中一段连续的长度为lbl_b11,得到cc中一块la×lbl_a\times l_b的面积。
特殊的,在aa中找一段连续的长度为ii11,然后在bb中一段连续的长度为ki\frac{k}{i}11,能得到一块kk的面积。
只要找出kk的所有因子ii,对于每个因子,统计在aa中长度为ii11的子列个数,然后在bb中统计长度为ki\frac{k}{i}11的子列个数。

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<iostream>
#include<vector>
#define ll long long
using namespace std;
const int N=40002;
int a[N],b[N];
ll n,m,k;
vector<ll>Kfactor;
void divide(ll x)
{
ll i;
for(i=1;i*i<=x;i++)//统计k的因子
{
if(x%i==0)
{
Kfactor.push_back(i);
if(i*i!=x) Kfactor.push_back(x/i);
else continue;
}
}
}
void solve()
{
cin>>n>>m>>k;
divide(k);
int i;
for(i=1;i<=n;i++) cin>>a[i];
for(i=1;i<=m;i++) cin>>b[i];
ll ans=0;
for(auto factor:Kfactor)
{
ll cnt=0;
ll x=0,y=0;
for(i=1;i<=n;i++)
{
if(a[i]) cnt++;//是1长度增加
else cnt=0;//遇到0,断开
if(cnt==factor) 找到长度为factor的连续1
{
cnt--;//将最前面的1舍弃
x++;//子列个数加1
}
}
cnt=0;
for(i=1;i<=m;i++)
{
if(b[i]) cnt++;
else cnt=0;
if(cnt==k/factor)
{
cnt--;
y++;
}
}
ans=ans+x*y;
}
cout<<ans;
}
int main()
{
solve();
return 0;
}

C. Unusual Competitions

A bracketed sequence is called correct (regular) if by inserting “+” and “1” you can get a well-formed mathematical expression from it. For example, sequences “(())()”, “()” and “(()(()))” are correct, while “)(”, “(()” and “(()))(” are not.
The teacher gave Dmitry’s class a very strange task — she asked every student to come up with a sequence of arbitrary length, consisting only of opening and closing brackets. After that all the students took turns naming the sequences they had invented. When Dima’s turn came, he suddenly realized that all his classmates got the correct bracketed sequence, and whether he got the correct bracketed sequence, he did not know.
Dima suspects now that he simply missed the word “correct” in the task statement, so now he wants to save the situation by modifying his sequence slightly. More precisely, he can the arbitrary number of times (possibly zero) perform the reorder operation.
The reorder operation consists of choosing an arbitrary consecutive subsegment (substring) of the sequence and then reordering all the characters in it in an arbitrary way. Such operation takes l nanoseconds, where l is the length of the subsegment being reordered. It’s easy to see that reorder operation doesn’t change the number of opening and closing brackets. For example for “))((” he can choose the substring “)(” and do reorder “)()(” (this operation will take 2 nanoseconds).
Since Dima will soon have to answer, he wants to make his sequence correct as fast as possible. Help him to do this, or determine that it’s impossible.

Input

The first line contains a single integer n(1n106)n (1≤n≤10^6) — the length of Dima’s sequence.
The second line contains string of length nn, consisting of characters “(” and “)” only.

Output

Print a single integer — the minimum number of nanoseconds to make the sequence correct or “-1” if it is impossible to do so.

Examples

input

8
))((())(

output

6

input

3
(()

output

-1

Note

In the first example we can firstly reorder the segment from first to the fourth character, replacing it with “()()”, the whole sequence will be “()()())(”. And then reorder the segment from the seventh to eighth character, replacing it with “()”. In the end the sequence will be “()()()()”, while the total time spent is 4+2=64+2=6 nanoseconds.

Translation

给一个括号序列,每次可以选择一个长度为ll的子列,任意调整其中括号的位置,花费的时间是ll,问至少需要花费多少时间,得到一个合法序列。

Idea

如果整个括号序列’(‘和’)‘的个数不相同,那么肯定不能得到合法的括号序列,否则一定能(比如直接调整整个序列)。
贪心得选择一段’(‘和’)‘个数相同的不合法子列(以’(‘结尾,’(‘和’)'个数相同),将其调整,然后寻找下一段没有调整的子列。此处运用单指针pospos对位置ii进行迭代。

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<iostream>
#include<string>
using namespace std;
void solve()
{
int n;
cin>>n;
string s;
cin>>s;
int c=0;
int i;
for(i=0;i<n;i++)
{
if(s[i]==')') c++;
else c--;
}
if(c) cout<<-1;
else
{
int pos=-1;//pos初始化必须为-1
int ans=0;
int c1=0,c2=0;
for(i=0;i<n;i++)
{
if(s[i]=='(')
{
c1++;
if(c1==c2)
{
ans=ans+i-pos;
pos=i;
}
}
else
{
c2++;
if(c1==c2)//前i个处理完毕
{
pos=i;
}
}
}
cout<<ans;
}
}
int main()
{
solve();
return 0;
}