#include <bits/stdc++.h>

using namespace std;

const int Nmax = 4e5+5;

long long ans = 0;
int n, i, x;
pair<int,int> a[Nmax];
vector<int> v[Nmax], q[Nmax];

class AIB
{
    int a[Nmax];
    int ub(int x)
    {
        return (x&(-x));
    }

    public:
        int query(int pos)
        {
            if(!pos) return 0;
            int ans = 0;
            for(; pos; pos-=ub(pos)) ans += a[pos];
            return ans;
        }

        void update(int pos)
        {
            if(!pos) return;
            for(; pos<=4*n; pos += ub(pos)) ++a[pos];
        }
} aib;

int main()
{
 //   freopen("input", "r", stdin);
 //   freopen("output", "w", stdout);

    scanf("%d", &n);
    for(i=1; i<=2*n; ++i)
    {
        scanf("%d", &x);
        if(!a[x].first) a[x].first = i;
            else a[x].second = i;
    }

    for(i=1; i<=n; ++i)
    {
        v[a[i].first].push_back(a[i].second);
        v[a[i].second].push_back(a[i].first + 2*n);
        v[a[i].first + 2*n].push_back(a[i].second + 2*n);

        q[a[i].first + 1].push_back(a[i].second - 1);
        q[a[i].second + 1].push_back(a[i].first - 1 + 2*n);
    }

    for(i=4*n; i; --i)
    {
        for(auto it : v[i])
            aib.update(it);

        for(auto it : q[i])
            ans += aib.query(it);
    }

    ans /= 2;
    ans = 1LL * n * (n-1) / 2 - ans;

    printf("%lld\n", ans);

    return 0;
}