#include using namespace std; #define MAXN 50050 int N; int A[2 * MAXN]; int P[MAXN]; int aib[2 * MAXN]; int query(int pos) { int ret = 0; while (pos > 0) { ret += aib[pos]; pos -= pos & (-pos); } return ret; } int query(int a, int b) { return query(b) - query(a - 1); } void update(int pos, int val) { while (pos <= 2 * N) { aib[pos] += val; pos += pos & (-pos); } } int main() { // assert(freopen("cc.in", "r", stdin)); // assert(freopen("cc.out", "w", stdout)); cin.sync_with_stdio(false); cin >> N; for (int i = 1; i <= 2 * N; i++) { cin >> A[i]; } long long ans = 0; for (int i = 1; i <= 2 * N; i++) { if (P[A[i]] == 0) { P[A[i]] = i; continue; } int prev = P[A[i]]; int cross = query(prev, i); ans += cross; update(prev, -1); update(i, +1); } cout << ans << endl; return 0; }