#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;


long long int N, M, K, H, W, L, R;


class Add_Segment_Tree {
	vector<long long int>v;
	vector<int>l;
	vector<int>r;
	long long int ret;
	int num;
	long long int Update(int place) {
		if (place >= v.size() / 2) {
			return v[place];
		}
		v[place] = Update(place * 2) + Update(place * 2 + 1);
		return v[place];
	}
	void Sum(int a, int b, int place) {
		if (l[place] >= a && r[place] <= b) {
			ret += v[place];
			return;
		}
		if (l[place] > b || r[place] < a) return;
		Sum(a, b, place * 2);
		Sum(a, b, place * 2 + 1);
		return;
	}
public:
	void Left(int place) {
		if (place >= v.size() / 2) {
			l[place] = place - v.size() / 2;
			return;
		}
		Left(place * 2);
		Left(place * 2 + 1);
		l[place] = l[place * 2];
		return;
	}
	void Right(int place) {
		if (place >= v.size() / 2) {
			r[place] = place - v.size() / 2;
			return;
		}
		Right(place * 2);
		Right(place * 2 + 1);
		r[place] = r[place * 2 + 1];
		return;
	}
	Add_Segment_Tree(int n) {
		n++;
		num = 1;
		while (num < n * 2)num *= 2;
		l.resize(num);
		r.resize(num);
		v.resize(num, 0);
		Left(1);
		Right(1);
	}
	void Add(int place, long long int num, bool update) {
		place += v.size() / 2;
		v[place] += num;
		if (!update)return;
		place /= 2;
		while (place) {
			v[place] = v[place * 2] + v[place * 2 + 1];
			place /= 2;
		}
	}
	void TopDown() {
		Update(1);
	}
	long long int Sum(int a, int b) {
		ret = 0;
		Sum(a, b, 1);
		return ret;
	}
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N;
	int w_index = 0;
	int b_index = 0;
	vector<int>white(N);
	vector<int>black(N);
	for (int i = 0; i < N * 2; i++) {
		char c;
		cin >> c >> M;
		if (c == 'W') {
			white[M-1] = i;
		}
		else {
			black[M-1] = i;
		}
	}
	vector<int>w_tent(N);
	vector<int>b_tent(N);
	Add_Segment_Tree wsg(N*2);
	for (int i = 0; i < N; i++) {
		wsg.Add(white[i], 1, true);
		w_tent[i] = wsg.Sum(white[i] + 1, 2 * N);
	}
	Add_Segment_Tree bsg(N*2);
	for (int i = 0; i < N; i++) {
		bsg.Add(black[i], 1, true);
		b_tent[i] = bsg.Sum(black[i] + 1, 2 * N);
	}
	vector<vector<int>>wb_tent(N, vector<int>(N));
	for (int i = 0; i < N; i++) {
		Add_Segment_Tree sg(N*2);
		for (int j = 0; j < N; j++) {
			sg.Add(black[j], 1, true);
			wb_tent[i][j] = sg.Sum(white[i] + 1, N * 2);
		}
	}
	vector<vector<int>>bw_tent(N, vector<int>(N));
	for (int i = 0; i < N; i++) {
		Add_Segment_Tree sg(N * 2);
		for (int j = 0; j < N; j++) {
			sg.Add(white[j], 1, true);
			bw_tent[i][j] = sg.Sum(black[i] + 1, N * 2);
		}
	}
	//cout << "hi";
	vector<vector<int>>dp(N + 1, vector<int>(N + 1, MOD));
	dp[0][0] = 0;
	for (int i = 1; i <= N * 2; i++) {
		for (int j = 0; j <= N; j++) {
			int w = j;
			int b = i - w;
			if (b<0 || b>N) {
				continue;
			}
			if (!w) {
				dp[w][b] = dp[w][b - 1] + abs(black[b - 1] + b_tent[b - 1] - (b - 1));
			}
			else if (!b) {
				dp[w][b] = dp[w - 1][b] + abs(white[w - 1] + w_tent[w - 1] - (w - 1));
			}
			else {
				dp[w][b] = min(dp[w][b - 1] + abs(black[b - 1] + b_tent[b - 1] + bw_tent[b - 1][w - 1] - (b + w - 1)), dp[w - 1][b] + abs(white[w - 1] + w_tent[w - 1] + wb_tent[w - 1][b - 1] - (b + w - 1)));
			}
		}
	}
	//for (int i = 0; i <= N; i++) {
	//	for (int j = 0; j <= N; j++) {
	//		cout << i << " " << j << " " << dp[i][j] << endl;
	//	}
	//}
	cout << dp[N][N] << endl;
	return 0;
}


Measured memory_bytes: 47616