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

int n, x, w[N], b[N], dw[2*N][N], db[2*N][N], dp[N][N];
char c;
int main() {
	int i, j;
	cin>>n;
	for(i=1; i<=2*n; i++) {
		for(j=1; j<=n; j++) dw[i][j] = dw[i-1][j], db[i][j] = db[i-1][j];
		cin>>c>>x;
		if(c=='W') {
			w[x] = i;
			for(j=x; j; j--) dw[i][j]++;
		} else {
			b[x] = i;
			for(j=x; j; j--) db[i][j]++;
		}
	}
	memset(dp, 0x3f, sizeof(dp));
	dp[0][0] = 0;
	for(i=0; i<=n; i++) for(j=0; j<=n; j++) {
		if(i) dp[i][j] = min(dp[i][j], dp[i-1][j] + dw[w[i]][i+1] + db[w[i]][j+1]);
		if(j) dp[i][j] = min(dp[i][j], dp[i][j-1] + dw[b[j]][i+1] + db[b[j]][j+1]);
	}
	cout<<dp[n][n];
	return 0;
}