Polycarp is a head of a circus troupe. There are n — an even number — artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then ci=1, otherwise ci=0), and whether they can perform as an acrobat (if yes, then ai=1, otherwise ai=0).
Split the artists into two performances in such a way that:
each artist plays in exactly one performance,
the number of artists in the two performances is equal (i.e. equal to n2),
the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance.
Input
The first line contains a single integer n (2≤n≤5000, n is even) — the number of artists in the troupe.
The second line contains n digits c1c2…cn, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise.
The third line contains n digits a1a2…an, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise.
Output
Print n2 distinct integers — the indices of the artists that should play in the first performance.
If there are multiple answers, print any.
If there is no solution, print a single integer −1.
Input
4
0011
0101
Output
1 4
Input
6
000000
111111
Output
-1
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
char c[5050];
char a[5050];
int answer[5050];
int x1, x2, x3, x4;
int main()
{
int n;
cin>>n;
scanf("%s%s", c + 1, a + 1);
x1 = x2 = x3 = x4 = 0;
for (int i = 1; i <= n; i++)
{
if (c[i] == '0' && a[i] == '0')
x1++;
else if (c[i] == '0' && a[i] == '1')
x2++;
else if (c[i] == '1' && a[i] == '0')
x3++;
else
x4++;
}
int num1 = 0, num2 = 0, sum3 = 0, sum4 = 0;
bool ok = false;
for (sum3 = 0; sum3 <= x3;sum3++)
{
if (sum3 > n / 2)break;
for (sum4 = 0;sum4 <= x4;sum4++)
{
if (sum3 + sum4 > n / 2)break;
num2 = x2 + (x4 - sum4) - (sum3 + sum4);
num1 = n / 2 - num2 - sum3 - sum4;
if (0 <= num1 && num1 <= x1 && 0 <= num2 && num2 <= x2)
{
ok = true;
break;
}
}
if (ok)break;
}
if(ok)
{
int tot = 0;
for (int i = 1; i <= n; i++)
{
if(num1!=0 && c[i] == '0' && a[i] == '0')
{
if(tot==0)
{
cout<<i;
tot=1;
}
else
cout<<" "<<i;
num1--;
}
else if (num2 != 0 && c[i] == '0' && a[i] == '1')
{
if(tot==0)
{
cout<<i;
tot=1;
}
else
cout<<" "<<i;
num2--;
}
else if (sum3 != 0 && c[i] == '1' && a[i] == '0')
{
if(tot==0)
{
cout<<i;
tot=1;
}
else
cout<<" "<<i;
sum3--;
}
else if (sum4 != 0 && c[i] == '1' && a[i] == '1')
{
if(tot==0)
{
cout<<i;
tot=1;
}
else
cout<<" "<<i;
sum4--;
}
}
cout<<endl;
}
else
cout<<-1<<endl;
}