#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int a[MAXN], n, sum[MAXN], pos[MAXN];
inline int lc(int p) { return p << 1; }
inline int rc(int p) { return p << 1 | 1; }
void pushUp(int p) { sum[p] = sum[lc(p)] + sum[rc(p)]; }
void buildTree(int p, int l, int r) {
  sum[p] = (r - l + 1);
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (l <= mid) buildTree(lc(p), l, mid);
  if (mid < r) buildTree(rc(p), mid + 1, r);
}
int query(int p, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) return sum[p];
  int mid = (l + r) >> 1;
  int ans = 0;
  if (ql <= mid) ans += query(lc(p), l, mid, ql, qr);
  if (mid < qr) ans += query(rc(p), mid + 1, r, ql, qr);
  return ans;
}
void update(int p, int l, int r, int q) {
  if (l == r) {
    sum[p] = 0;
    return;
  }
  int mid = (l + r) >> 1;
  if (q <= mid)
    update(lc(p), l, mid, q);
  else
    update(rc(p), mid + 1, r, q);
  pushUp(p);
}
int main() {
  cin >> n;
  for (int i = 1; i <= 2 * n; ++i) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  buildTree(1, 1, 2 * n);
  long long ans = 0;
  for (int i = 1; i <= 2 * n; ++i) {
    if (pos[a[i]] == i) continue;
    ans += query(1, 1, 2 * n, i + 1, pos[a[i]]) - 1;
    update(1, 1, 2 * n, pos[a[i]]);
  }
  cout << ans << endl;
  return 0;
}
