#include <iostream>
#include <cstdio>
#include <cstring>
#define N 4005
using namespace std;

int n, vw[N], vb[N], d[N], u[2005][2005];
char t1[5];
void h(int p, int q) {
	while (p <= n * 2) {
		d[p] += q;
		p += (p & -p);
	}
}

int g(int p) {
	int r = 0;
	while (p > 0) {
		r += d[p];
		p -= (p & -p);
	}
	return r;
}

int f(int p, int q) {
	int mn = 2e9, t;
	if (p == 0 && q == 0) return 0;
	if (u[p][q] != -1) return u[p][q];
	if (p > 0) {
		t = vw[p] - g(vw[p]);
		h(vw[p], 1);
		mn = min(mn, f(p - 1, q) + (p + q - t));
		h(vw[p], -1);
	}
	if (q > 0) {
		t = vb[q] - g(vb[q]);
		h(vb[q], 1);
		mn = min(mn, f(p, q - 1) + (p + q - t));
		h(vb[q], -1);
	}
	return u[p][q] = mn;
}
int main()
{
	int i, t2;
	cin >> n;
	for (i = 1; i <= n * 2; i++) {
		scanf ("%s %d", t1, &t2);
		if (t1[0] == 'W') vw[t2] = i;
		else vb[t2] = i;
	}
	memset(u, -1, sizeof(u));
	cout << f(n, n);
    return 0;
}
