#include <bits/stdc++.h>
using namespace std;
int t,g,i,n,q;
int main()
{ cin.tie(NULL);
cout.sync_with_stdio(false);
cin>>t;
for(int i = 0;i<t;++i)
{
cin>>g;
for(int k = 0;k<g;++k)
{
cin>>i>>n>>q;
int A[n];
for(int m=0;m<n;m++){A[m]=i;}
for(int l = 0;l<n;++l)
{ if(n%2!=0 and (l%2==0 or l==0)) // if n is odd
{
if(i==1)
{
A[l]=2;
}else if(i==2){
A[l]=1;
}
}
if(n%2==0 and (l%2!=0))
{
if(i==1)
{
A[l]=2;
}else{
A[l]=1;
}
}
// agr n is odd then odd position change
// agt n is even then even position remains same
}
if(q==1){
cout<<count(A,A+n,1)<<"\n";
}else{
cout<<count(A,A+n,2)<<"\n";
}
}
}
}
LOGIC:-
All the even postions in the array ( starting from 0) will be changed if N is odd ie number of rounds or coins . If N is even then the odd positions in the array switches.
Then count whatever is asked
Working inEditor