// Skyqwq
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
template <typename T> bool chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; }
template <typename T> bool chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; }
template <typename T> void inline read(T &x) {
int f = 1; x = 0; char s = getchar();
while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
x *= f;
}
const int N = 2e5 + 5;
int n, a[N], c[N];
LL ans;
map<int, set<int> > pos;
void inline add(int x, int k) {
for (; x <= 2 * n; x += x & -x) c[x] += k;
}
int inline ask(int x) {
int ret = 0;
for (; x ; x -= x & -x) ret += c[x];
return ret;
}
bool vis[N];
int main() {
read(n);
for (int i = 1; i <= 2 * n; i++) add(i, 1), read(a[i]), pos[a[i]].insert(i);
for (int i = 1; i <= 2 * n; i++) {
if (vis[i]) continue;
add(i, -1);
pos[a[i]].erase(i);
if (a[i] < 0) {
int nx = *pos[-a[i]].begin();
pos[-a[i]].erase(nx);
vis[nx] = 1;
ans += ask(nx - 1);
add(nx, -1);
} else {
int nx = *pos[-a[i]].begin();
pos[-a[i]].erase(nx);
vis[nx] = 1;
ans += ask(nx - 1) + 1;
add(nx, -1);
}
}
printf("%lld\n", ans);
return 0;
}