#include using namespace std ; /* ifstream cin ("input") ; ofstream cout ("output") ; */ const int MAX = 1e5 + 1e4 ; int aib [MAX] ; int last [MAX] ; int lsb (int x) { return x & -x; } void update (int poz, int val, int n) { for (; poz <= n; poz += lsb (poz)) { aib [poz] += val ; } } int Q (int poz) { int s = 0 ; while (poz) { s += aib [poz] ; poz -= lsb (poz) ; } return s ; } int main(int argc, char const *argv[]) { int n ; cin >> n ; long long sol = 0 ; for (int i = 1 ; i <= 2 * n ; ++ i) { int x ; cin >> x ; if (last [x] == 0) { update (i, 1, 2 * n) ; last [x] = i ; } else { long long val = 1LL * Q (i) - 1LL * Q (last[x]); sol = sol + val ; //cout << "pentru " << x << " adun " << val << '\n' ; update (last[x], -1, 2*n) ; } } cout << sol << '\n' ; return 0; }