Help me in solving ARRHALVES problem

My issue

For the problem statement:Array Halves Practice Coding Problem - CodeChef
Explain why the following logic is incorrect:
Please give a test case for which it will fail.

My code

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

int main() {
	// your code goes here
	int T;
	cin>>T;
	for(int t=0;t<T;t++)
	{
	    long long int n;
	    cin>>n;
	    vector<long long int> a(2*n);
	    long long int cnt=0,ans=0;
	    for(int i=0;i<2*n;i++)
	    {
	        cin>>a[i];
	        if(a[i]>n) cnt++;
	        else ans+=cnt;
	    }
	    cout<<ans<<endl;
	}
	return 0;
}

Learning course: 1400 to 1600 difficulty problems
Problem Link: Array Halves Practice Problem in - CodeChef

@amanyadav31
unable to get your logic dude.
here is my c++ code for reference

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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    vector<int> a;
	    for(int i=0;i<2*n;i++)
	    {
	        int x;
	        cin>>x;
	        a.push_back(x);
	    }
	    long long int ans=0;
	    for(int i=n-1,j=n;i>=0&&j<(2*n);i--,j++)
	    {
	        if(a[i]<=n&&a[j]>n)
	        {
	            continue;
	        }
	        else if(a[i]>n&&a[j]>n)
	        {
	            i++;
	        }
	        else if(a[i]<=n&&a[j]<=n)
	        {
	            j--;
	        }
	        else
	        {
	            ans+=(j-i);
	        }
	    }
	    cout<<ans<<endl;
	}
	return 0;
}