#include "shoes.h"
#include "bits/stdc++.h"
using namespace std;
long long count_swaps(vector<int> a) {
int N = (int)a.size() >> 1;
int64_t ans = INT_MAX;
// 1 based indexed..
vector<int> A((N << 1) + 5), L, R; for (int i = 0; i < (N << 1); i++) {
A[i + 1] = a[i];
if (A[i + 1] < 0) L.push_back(i + 1);
else R.push_back(i + 1);
}
auto isIn = [&](array<int, 2> x, array<int, 2> y) -> bool {
if (x[0] <= y[0] && y[0] <= x[1] && x[1] <= y[1]) return true;
swap(x, y);
if (x[0] <= y[0] && y[0] <= x[1] && x[1] <= y[1]) return true;
return false;
};
do {
bool flag = true;
for (int j = 0; j < (N << 1); j++)
if (abs(A[L[j]]) != abs(A[R[j]])) {
flag = false;
break;
}
if (!flag) continue;
int64_t total = 0, res, i = 0;
while (i < N) {
res = 0;
int li = L[i], ri = R[i];
if (li < ri) res = ri - li - 1;
else res = li - ri;
for (int j = 0; j < i; j++) {
int lj = L[j], rj = R[j];
res -= isIn({min(li, ri), max(li, ri)}, {min(lj, rj), max(lj, rj)});
}
total += res, i++;
}
ans = min(ans, total);
} while (next_permutation(L.begin(), L.end()));
return ans;
}