Help me in solving DRAGNXOR problem

My issue

can anyone explain this problem open the dragon scroll

My code

#include <stdio.h>

int main(void) {
    int t;
    scanf("%d",&t);
    while (t--)
    {
    int n,a,b,x,y;
    scanf("%d%d%d",&n,&a,&b);
    x=(n+a+b);
    y=(n*2)+n+a+b;
    if (a>b && a>n  && b>n ) {
        printf("%d\n",x-a); }
    else if ( b>a && b>n && a>n || a==0 || b==0 || a==1 || b==1){
    printf("%d\n",y);
    }
    else{
    printf("%d\n",(y-n)-n);
    }
    }
	// your code goes here
	return 0;
}


Problem Link: Open the Dragon Scroll Practice Coding Problem - CodeChef

@h44kinirdesh20
U have to maximize the value of a xor b such that the binary representation of a and b have n bits and u can also rearrange the bits to make any other binary number .
Here is my c++ code for reference of logic

#include <iostream>
using namespace std;
int count(int n)
{
    int i=1;
    int cnt=0;
    while(i<=n)
    {
        int d=i&n;
        if(d==i)
        cnt++;
        i=i*2;
    }
    return cnt;
}

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n,a,b;
	    cin>>n>>a>>b;
	    int vala=count(a);
	    int valb=count(b);
	    int po=1;
	    for(int i=1;i<n;i++)
	    {
	        po=po*2;
	    }
	    vala+=valb;
	    int ans=0;
	    int n1=n;
	 //   cout<<vala<<" "<<po<<endl;
	    while(vala>0&&n>0)
	    {
	        ans+=po;
	        po/=2;
	        vala--;
	        n--;
	    }
	    n=n1;
	    po=1;
	    while(vala>0&&n>0)
	    {
	        ans-=po;
	        po*=2;
	        vala--;
	        n--;
	    }
	    cout<<ans<<endl;
	}
	return 0;
}