
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+5;
const int add = 1e5;
queue <int> q[maxn];
int pos[maxn];
int ids[maxn];
int cnt  =0;
struct FENWICK
{
    int fen[maxn];
    void update(int idx, int delta)
    {
        for(;idx<maxn;idx+=(idx&-idx))
            fen[idx]+=delta;
    }
    int query(int idx)
{
    int ans = 0;
    for(;idx>0;idx-=(idx&-idx))
        ans+=fen[idx];
    return ans;
}
    };
    FENWICK F;
long long count_swaps(std::vector<int> s) {
	int i,j;
	for(i=0;i<s.size();i++)
    {
        int x = s[i]+add;
        if(q[x].empty())
        {
            int y = -s[i]+add;
            q[y].push(i);
            pos[i] = cnt;
            cnt+=2;
        }
        else
        {
            pos[i] = pos[q[x].front()]+1;
            q[x].pop();
        }
    }
    int n = s.size();
    for(i=0;i<n;i++)
        ids[pos[i]] = i;
        int all = 0;
        long long ANS = 0;
    for(i=1;i<n;i+=2)
    {

        int x = ids[i];
        int dist = ids[i]+all-F.query(ids[i]+1)-i;
       // cout<<i<<" : "<<ids[i-1]<<" "<<ids[i]<<"  : "<<dist<<endl;
        if(s[ids[i]]<s[ids[i-1]])dist++;
        ANS+=dist;
        all++;
        F.update(ids[i]+1,1);
    }
    return ANS;
}
vector <int> p;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    p.resize(2*n);
    int i;
    for(i = 0;i<2*n;i++)
        cin>>p[i];
    cout<<count_swaps(p)<<endl;
    return 0;
}
