#include <iostream>
#include <vector>
#include <bitset>

using namespace std;
typedef long long int64;

const int kMaxN = 1e5+10;
int first[kMaxN], v[kMaxN];

int popcount[1<<16];

struct Bitset {
	int64 v[850];

	void flip(int x) {
		v[x/60] ^= (1LL<<(x%60));
	}

	int count(const Bitset& other) {
		int ans = 0;
		for (int i = 0; i < 850; ++i) {
			int64 x = (v[i] ^ other.v[i]);
			ans += popcount[x>>40] + 
				   popcount[(x>>20)&((1<<20)-1)] + 
				   popcount[x&((1<<20)-1)];
		}
		return ans;
	}
}b[kMaxN];


void precalc() {
	for (int i = 1; i < (1<<20); ++i) {
		popcount[i] = popcount[i - (i&(-i))] + 1;
	}
}

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

	for (int i = 1; i <= 2*n; ++i) {
		cin >> v[i];
	}

	int64 rez = 0;

	for (int i = 1; i <= 2*n; ++i) {
		b[i] = b[i-1];
		b[i].flip(v[i]);

		if (first[v[i]] == 0) {
			first[v[i]] = i;
		} else {
			rez += b[i].count(b[first[v[i]] - 1]);
		}
	}

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