#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int64_t n;
  cin >> n;
  int64_t a[2 * n];
  vector<int64_t> ps[n];
  for (int64_t i = 0; i < 2 * n; i++) {
    cin >> a[i];
    ps[a[i] - 1].push_back(i);
  }
  int64_t ans = 0;
  for (int64_t i = 0; i < n; i++) {
    for (int64_t j = 0; j < i; j++) {
      vector<int64_t> lol = {ps[i][0], ps[i][1], ps[j][0], ps[j][1]};
      sort(begin(lol), end(lol));
      if (a[lol[0]] != a[lol[1]]) {
        ans += 1 + (a[lol[1]] == a[lol[2]]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
