#include <iostream>
#include <vector>

using namespace std;
typedef long long int64;

const int kMaxN = 1e5+10;

int first[kMaxN];

template<typename T>
struct FenTree {
	int n;
	vector<T> aib;
	FenTree(int n) : n(n) {
		aib.resize(n+1);
	}

	static inline int LSB(int i) {
		return i&-i;
	}

	void update(int i, T val) {
		for (; i <= n; i += LSB(i)) {
			aib[i] += val;
		}
	}

	int query(int i) {
		T res = 0;
		for (; i > 0; i -= LSB(i)) {
			res += aib[i];
		}
		return res;
	}
};

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

	int64 ans = 0;

	FenTree<int> fen(2*n);

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

	cout << ans/2 << "\n";
}