//#define local
#ifndef local
#include "shoes.h"
#endif
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef pair<ii, ii> iiii;
const ll N = 3e5 + 5;
const ll oo = 1e18 + 7, mod = 1e9 + 7;
mt19937 rng(1);
ll rnd(ll l, ll r){
ll temp = rng() % (r - l + 1);
return abs(temp) + l;
}
ll n;
bool used[N];
set<ll> se[N << 1];
ll bit[N];
void upd(ll id, ll val){
for(; id <= n; id += id & -id) bit[id] += val;
}
ll get(ll id){
ll ans = 0;
for(; id; id -= id & -id) ans += bit[id];
return ans;
}
ll count_swaps(vector<ll> a){
n = a.size();
for(ll i = 1; i <= n; i++) upd(i, 1);
for(ll i = 0; i < a.size(); i++){
se[a[i] + n].insert(i + 1);
}
ll ans = 0;
for(ll i = 1; i <= n; i++){
if(used[i]) continue;
ll temp = (*se[n - a[i - 1]].begin());
//cout << i << " " << temp << "\n";
used[temp] = used[i] = 1;
ans += get(temp - 1) - 1;
//cout << ans << "\n";
if(a[i - 1] > 0) ans++;
se[a[i - 1] + n].erase(i);
se[n - a[i - 1]].erase(temp);
upd(i, -1);
upd(temp, -1);
}
return ans;
}
#ifdef local
void process(){
ll n;
vector<ll> v;
cin >> n;
for(ll i = 0; i < 2 * n; i++){
ll x;
cin >> x;
v.pb(x);
}
cout << count_swaps(v);
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
freopen("kek.inp", "r", stdin);
freopen("kek.out", "w", stdout);
process();
}
#endif