#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int s = 0, f = 1;
  char ch = getchar();
  while (!('0' <= ch && ch <= '9') && ch != '-') ch = getchar();
  if (ch == '-') ch = getchar(), f = -1;
  while ('0' <= ch && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return ~f ? s : -s;
}
const int maxn = 220;
int fi[maxn], se[maxn];
int main() {
  int n = read(), a[maxn];
  for (int i = (1), _end_ = (2 * n); i <= _end_; i++) {
    a[i] = read();
    if (!fi[a[i]])
      fi[a[i]] = i;
    else
      se[a[i]] = i;
  }
  int ans = 0;
  for (int i = (1), _end_ = (n); i <= _end_; i++)
    for (int j = (i + 1), _end_ = (n); j <= _end_; j++) {
      if (fi[i] <= fi[j] && se[j] <= se[i])
        ans += 2;
      else if (fi[i] <= fi[j] && fi[j] <= se[i] && se[i] <= se[j])
        ans++;
      else if (fi[j] < fi[i] && se[i] < se[j])
        ans += 2;
      else if (fi[j] < fi[i] && fi[i] < se[j] && se[j] < se[i])
        ans++;
    }
  printf("%d\n", ans);
  return 0;
}
