# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const long long MOD = 1000000000 + 7;//1000000000 + 7 998244353 924844033 1000000000 + 9;
constexpr long long INF = 1LL << 60;//numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<Edge>>g;
vector<edge>ed;
vector<Pll>pv;
set<LL>st;
map<Pll, LL>ma;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
string str, ss;
bool f;
LL n, m, s, t, h, w, k, q, p, ans, cnt,sum,a[5000],b[5000],dp[2010][2010],dpw[2010][2010],dpb[2010][2010];
//注意:配列を1から始めること
class BIT {
public:
	vector<LL> Bit;
	LL M;
	BIT(LL M) :
		Bit(vector<LL>(M + 1, 0)), M(M) {}
	void init() {
		rep(i, M + 1)Bit[i] = 0;
	}
	LL sum(LL i) {
		LL s = 0;
		while (i > 0) {
			s += Bit[i];
			i -= (i&(-i));
		}
		return s;
	}
	LL sum(LL i, LL j) {
		return sum(j) - sum(i - 1);
	}
	//1-index
	void add(LL i, LL x) {
		while (i <= M) {
			Bit[i] += x;
			i += (i&(-i));
		}
	}
	//初めてk以上になる、index
	int lower_bound(LL k) {
		int l = -1, r = n + 1, m;
		while (r - l > 1) {
			m = (l + r) / 2;
			if (sum(m) >= k)
				r = m;
			else l = m;
		}
		return (r == n + 1 ? -1 : r);
	}
	//初めてkより大きくなる、index
	int upper_bound(LL k) {
		int l = -1, r = M + 1, m;
		while (r - l > 1) {
			m = (l + r) / 2;
			if (sum(m) > k)
				r = m;
			else l = m;
		}
		return (r == M + 1 ? M + 1 : r);
	}
};
BIT bit(2000);
//dpw[i][j]:j番目までのblackをすでに決めていたときのi番目の白玉を動かす距離
int main() {
	cin >> n;
	rep(i, 2 * n) {
		LL x;
		char c;
		cin >> c >> x;
		if (c == 'W')b[i] = 0;
		else b[i] = 1;
		a[i] = x;
	}
	rep(i, n + 1) {
		bit.init();
		cnt = 0;
		rep(j, n * 2) {
			if (b[j] == 1) {
				if (a[j] > i)cnt++;
			}
			else {
				dpw[i][a[j] - 1] = cnt - bit.sum(a[j]);
				bit.add(a[j], 1);
				cnt++;
			}
		}
	}
	rep(i, n + 1) {
		bit.init();
		cnt = 0;
		rep(j, n * 2) {
			if (b[j] == 0) {
				if (a[j] > i)cnt++;
			}
			else {
				dpb[i][a[j] - 1] = cnt - bit.sum(a[j]);
				bit.add(a[j], 1);
				cnt++;
			}
		}
	}
	rep(i, n + 1)rep(j, n + 1)dp[i][j] = INF;
	dp[0][0] = 0;
	rep(i, n+1) {
		rep(j, n+1) {
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + dpw[j][i]);
			dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + dpb[i][j]);
		}
	}
	cout << dp[n][n] << endl;
	return 0;
}

Measured memory_bytes: 94848