#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int MAX_N = 50100;

long long ans;

int first[MAX_N];
int v[2 * MAX_N];
int aib[2 * MAX_N];

void update(int poz, int val) {
  while(poz < 2 * MAX_N) {
    aib[poz] += val;
    poz += (poz & (-poz));
  }
}

int query(int poz) {
  int sum = 0;
  while(poz) {
    sum += aib[poz];
    poz -= (poz & (-poz));
  }
  return sum;
}

int main()
{
  int n;
  cin >> n;

  for(int i = 1; i <= 2 * n; i++) {
    cin >> v[i];
    if(!first[v[i]]) {
      first[v[i]] = i;
      update(i, 1);
    }
    else {
      ans += query(i) - query(first[v[i]]);
      update(first[v[i]], -1);
    }

  }

  cout << ans;

  return 0;
}