import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math;
import core.stdc.stdio;
// foreach, foreach_reverse, writeln

class BIT {
	int[] data;
	this(int n) {
		data = new int[n+1];
	}
	BIT dup() {
		BIT ret = new BIT(to!int(data.length));
		ret.data = data.dup;
		return ret;
	}
	void add(int i, int x=1) {
		i++;
		while (i) {
			data[i] += x;
			i -= i&-i;
		}
	}
	int sum(int i) {
		int ret = 0;
		i++;
		while (i < data.length) {
			ret += data[i];
			i += i&-i;
		}
		return ret;
	}
}

void main() {
	int n;
	scanf("%d\n", &n);
	int[] b = new int[n];
	int[] w = new int[n];
	int m = n*2;
	foreach (i; 0..m) {
		char c;
		int a;
		scanf("%c %d\n", &c, &a);
		if (c == 'B') {
			b[a-1] = i;
		} else {
			w[a-1] = i;
		}
	}

	int[][] dp = new int[][](n+1,n+1);
	foreach (i; 0..n+1) dp[i][] = to!int(1e9);
	dp[0][0] = 0;

	BIT bit = new BIT(m);
	foreach (i; 0..n+1) {
		BIT _bit = bit.dup();
		foreach (j; 0..n+1) {
			if (i < n) dp[i+1][j] = min(dp[i+1][j], dp[i][j]+_bit.sum(b[i]));
			if (j < n) dp[i][j+1] = min(dp[i][j+1], dp[i][j]+_bit.sum(w[j]));
			if (j < n) _bit.add(w[j]);
		}
		if (i < n) bit.add(b[i]);
	}
	writeln(dp[n][n]);
}