#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

template<typename T>
struct SegmentTree {
	using value_type = T;
	using const_reference = const value_type &;
	using F = std::function<value_type(const_reference, const_reference)>;
	using size_type = std::size_t;
	
	SegmentTree(size_type n_, const F & f, const_reference id_elem) : f(f), id_elem(id_elem) {
		n = 1;
		while (n < n_) n <<= 1;
		node.resize(2 * n, id_elem);
	}
	
	size_type size() const noexcept {
		return n;
	}
	
	void set(size_type i, const_reference x) {
		assert(i < size());
		node[i += n] = x;
		while (i > 1) {
			i >>= 1;
			node[i] = f(node[i << 1], node[i << 1 | 1]);
		}
	}
	
	void add(size_type i, const_reference x) {
		assert(i < size());
		i += n;
		node[i] = f(node[i], x);
		while (i > 1) {
			i >>= 1;
			node[i] = f(node[i << 1], node[i << 1 | 1]);
		}
	}
	
	value_type fold(size_type l, size_type r) const {
		assert(l <= size() && r <= size());
		value_type lv = id_elem, rv = id_elem;
		for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if (l & 1) lv = f(lv, node[l++]);
			if (r & 1) rv = f(node[r - 1], rv);
		}
		return f(lv, rv);
	}
	
	size_type lower_bound(const_reference x) const {
		if (node[1] < x) return n;
		size_type idx;
		value_type s = id_elem;
		for (idx = 1; idx < n;) {
			value_type nex = f(s, node[idx << 1]);
			if (nex < x) {
				idx = idx << 1 | 1;
				s = nex;
			}
			else idx = idx << 1;
		}
		return idx - n;
	}
	
	size_type upper_bound(const_reference x) const {
		if (node[1] <= x) return n;
		size_type idx;
		value_type s = id_elem;
		for (idx = 1; idx < n;) {
			value_type nex = f(s, node[idx << 1]);
			if (nex <= x) {
				idx = idx << 1 | 1;
				s = nex;
			}
			else idx = idx << 1;
		}
		return idx - n;
	}
	
private:
	size_type n;
	F f;
	value_type id_elem;
	std::vector<value_type> node;
};

int main() {
	int N;
	cin >> N;
	vector<int> A(2 * N);
	vector<string> C(2 * N);
	REP(i, 2 * N) cin >> C[i] >> A[i], --A[i];
	
	vector<vector<int>> sum[2]; // [col = is "B"][i][j] := k \in [i, 2*N) で A_k >= j and C_k = col となる k の数
	vector<int> ref[2];
	REP(i, 2) ref[i] = vector<int>(N); // [col][i] := A[k] = i となるような k
	REP(i, 2 * N) ref[C[i] == "B"][A[i]] = i;
	
	REP(i, 2) sum[i] = vector<vector<int>>(2 * N, vector<int>(N + 1));
	REP(i, 2 * N) {
		int idx = C[i] == "B";
		++sum[idx][i][A[i]];
	}
	REP(k, 2) REP(i, 2 * N) for (int j = N; j > 0; --j) sum[k][i][j - 1] += sum[k][i][j];
	REP(k, 2) for (int i = 2 * N - 1; i > 0; --i) REP(j, N + 1) sum[k][i - 1][j] += sum[k][i][j];
	
	vector<vector<int>> dp(N + 1, vector<int>(N + 1, INF));
	dp[0][0] = 0;
	
	REP(i, N + 1) REP(j, N + 1) {
		if (dp[i][j] == INF) continue;
		REP(k, 2) {
			if (k == 0 && i == N || k == 1 && j == N) continue;
			int idx = k == 0 ? ref[k][N - 1 - i] : ref[k][N - 1 - j];
			int c = 2 * N - idx - 1 - (sum[0][idx][N - i] + sum[1][idx][N - j]);
			chmin(k == 0 ? dp[i + 1][j] : dp[i][j + 1], dp[i][j] + c);
		}
	}
	cout << dp[N][N] << endl;
	
	return 0;
}


Measured memory_bytes: 81884