Need help in problem magicflips starters 10

please help magical flips starters 10 this code give ac for task 2 and 3 but runtime error for task1

#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t–)
{
int n,i,j,k1,k2;
cin>>n;
int a[n], b[n];
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n;i++)
cin>>b[i];
int x[n][32];
int y[n][32];
for(i=0;i<n;i++)
{
for(j=31;j>=0;j–)
{
k1 = a[i] >> j;
if(k1 & 1)
x[i][j] = 1;
else
x[i][j] = 0;
k2 = b[i] >> j;
if(k2 & 1)
y[i][j] = 1;
else
y[i][j] = 0;
}
}
vector v (n, -1);
int ans[32];
int flips = 0;
for(i=31;i>=0;i–)
{
int z = 1;
int c = 0;
for(j=0;j<n;j++)
{
if(x[j][i]==0 && y[j][i] == 0)
z=0;
if(x[j][i] == 1 && y[j][i] == 1)
c++;
}
if(z==0)
ans[i] = 0;
else
{
if(c==n)
ans[i] = 1;
else
{
vector pos;
int tf=0;
for(j=0;j<n;j++)
{
if(x[j][i] == 1 && y[j][i] == 1)
ans[i] = 1;
else if(x[j][i] == 1)
{
if(v[j] == -1)
{
ans[i] = 1;
v[j] = a[j];
pos.push_back(j);
}
else if(v[j] == a[j])
{
ans[i] = 1;
}
else
{
ans[i] = 0;
break;
}
}
else if(y[j][i] == 1)
{
if(v[j] == -1)
{
ans[i] = 1;
v[j] = b[j];
flips++;
pos.push_back(j);
tf++;
}
else if(v[j] == b[j])
{
ans[i] = 1;
}
else
{
ans[i] = 0;
break;
}
}
}
if(ans[i] == 0)
{
flips = flips - tf;
for(j=0;j<pos.size();j++)
v[pos[j]] = -1;
}
pos.clear();
}
}
}
int ans1 = 0;
int base = 1;
for(i=0; i<31; i++)
{
if(ans[i] == 1)
ans1 = ans1 + base;
base = base * 2;
}
cout<<ans1<<" “<<flips<<”\n";
}
return 0;
}