#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 100005;
int fw[N];
void update(int x, int v){
x++;
for (; x<N; x+=x&(-x)) fw[x] += v;
}
int sum(int x){
x++;
int res = 0;
for (; x; x-=x&(-x)) res += fw[x];
return res;
}
long long count_swaps(std::vector<int> s) {
ll n = s.size()/2;
vector<queue<ll>> pos(2*n+1);
for (int i=0;i<2*n;i++){
if (s[i] < 0){
pos[-s[i]].push(i);
}
else pos[s[i]+n].push(i);
}
ll total = 0;
ll used[2*n];
for (int i=0;i<2*n;i++){
used[i] = 1;
update(i,1);
}
for (int i=0;i<2*n;i++){
if (used[i] == 0) continue;
if (s[i] < 0){
ll ps = pos[n-s[i]].front();
total += sum(ps-1) - sum(i);
update(ps,0);
update(i,0);
used[i] = 0;
used[ps] = 0;
pos[n-s[i]].pop();
pos[-s[i]].pop();
}
else{
ll ps = pos[s[i]].front();
total += sum(ps-1) - sum(i) + 1;
update(ps,0);
update(i,0);
used[i] = 0;
used[ps] = 0;
pos[s[i]].pop();
pos[n+s[i]].pop();
}
}
return total;
}