#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> hash(100001, -1);
long long sum = 0;
for (int i = 0; i < 2 * n; ++i) {
int x;
cin >> x;
if (hash[x] == -1)
hash[x] = i;
else {
hash[x] = abs(i - hash[x]);
sum += hash[x];
}
}
cout << sum;
}