#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int M = 2e5 + 1;
int fen[M];
void modify(int p, int x)
{
while (p<M)
fen[p]+=x, p+=p&-p;
}
int get(int p)
{
int ans=0;
while (p)
ans+=fen[p];
return ans;
}
ll count_swaps(vector<int> v)
{
int n=v.size()/2, ind[n+1];
for (int i=0;i<n*2;i++)
v[i]+=n, ind[v[i]]=i, modify(i+1,1);
ll ans=0;
for (int i=0;i<n*2;i++)
{
if (v[i]<=n)
{
if (ind[v[i]+n]<i) continue;
ans+=get(ind[v[i]+n])-get(i+1), modify(ind[v[i]+n]+1,-1);
}
else
{
if (ind[v[i]-n]<i) continue;
ans+=get(ind[v[i]-n])-get(i+1)+1, modify(ind[v[i]-n]+1,-1);
}
}
return ans;
}