#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
template<typename T> struct fenwick {
int n;
vector<T> fen;
fenwick(){}
fenwick(int nn) {
fen.resize(nn+1);
n = nn;
}
auto sum(int i) {
T ans = 0;
while(i) {
ans+=fen[i];
i&=i-1;
}
return ans;
}
auto query(int l, int r) {
return sum(r+1)-sum(l);
}
void update(int i, T val) {
++i;
while(i<=n) {
fen[i]+=val;
i+= i&(-i);
}
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin >> n;
vi sec(n,-1);
vi a(2*n);
for(int i=0;i<2*n;++i) {
cin >> a[i],a[i]--;
if(sec[a[i]]==-1) sec[a[i]]=i;
}
ll ans = n;
fenwick<int> fen(2*n);
for(int i=0;i<2*n;++i) {
auto couple = sec[a[i]];
if(couple==i) continue;
ans+= i-couple-1-fen.query(couple+1,i-1);
fen.update(couple,1);
fen.update(i,1);
}
cout << ans << '\n';
}
I2luY2x1ZGUgImJpdHMvc3RkYysrLmgiCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgYWxsKHgpIGJlZ2luKHgpLGVuZCh4KQp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKdHlwZWRlZiB2ZWN0b3I8aW50PiB2aTsKdHlwZWRlZiB2ZWN0b3I8dmk+IHZ2aTsKdHlwZWRlZiBwYWlyPGludCxpbnQ+IHBpOwpjb25zdCBpbnQgbXhOID0gMWU1KzEsIG9vID0gMWU5Owp0ZW1wbGF0ZTx0eXBlbmFtZSBUPiBzdHJ1Y3QgZmVud2ljayB7CiAgICBpbnQgbjsKICAgIHZlY3RvcjxUPiBmZW47CiAgICBmZW53aWNrKCl7fQogICAgZmVud2ljayhpbnQgbm4pIHsKICAgICAgICBmZW4ucmVzaXplKG5uKzEpOwogICAgICAgIG4gPSBubjsKICAgIH0KICAgIGF1dG8gc3VtKGludCBpKSB7CiAgICAgICAgVCBhbnMgPSAwOwogICAgICAgIHdoaWxlKGkpIHsKICAgICAgICAgICAgYW5zKz1mZW5baV07CiAgICAgICAgICAgIGkmPWktMTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGFuczsKICAgIH0KICAgIGF1dG8gcXVlcnkoaW50IGwsIGludCByKSB7CiAgICAgICAgcmV0dXJuIHN1bShyKzEpLXN1bShsKTsKICAgIH0KICAgIHZvaWQgdXBkYXRlKGludCBpLCBUIHZhbCkgewogICAgICAgICsraTsKICAgICAgICB3aGlsZShpPD1uKSB7CiAgICAgICAgICAgIGZlbltpXSs9dmFsOwogICAgICAgICAgICBpKz0gaSYoLWkpOwogICAgICAgIH0KICAgIH0KfTsKaW50IG1haW4oKSB7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgIGNpbi50aWUoTlVMTCk7CiAgICBpbnQgbjsgY2luID4+IG47CiAgICB2aSBzZWMobiwtMSk7CiAgICB2aSBhKDIqbik7IAogICAgZm9yKGludCBpPTA7aTwyKm47KytpKSB7CiAgICAgICAgY2luID4+IGFbaV0sYVtpXS0tOwogICAgICAgIGlmKHNlY1thW2ldXT09LTEpIHNlY1thW2ldXT1pOwogICAgfQogICAgbGwgYW5zID0gbjsKICAgIGZlbndpY2s8aW50PiBmZW4oMipuKTsKICAgIGZvcihpbnQgaT0wO2k8MipuOysraSkgewogICAgICAgIGF1dG8gY291cGxlID0gc2VjW2FbaV1dOwogICAgICAgIGlmKGNvdXBsZT09aSkgY29udGludWU7CiAgICAgICAgYW5zKz0gaS1jb3VwbGUtMS1mZW4ucXVlcnkoY291cGxlKzEsaS0xKTsKICAgICAgICBmZW4udXBkYXRlKGNvdXBsZSwxKTsKICAgICAgICBmZW4udXBkYXRlKGksMSk7CiAgICB9CiAgICBjb3V0IDw8IGFucyA8PCAnXG4nOwp9