#include <iostream>
#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++) {
		cin>>c>>x;
		c=='W' ? w[x]=i : b[x]=i;
		for(j=0; j<n; j++) {
			dw[i][j] = dw[i-1][j], db[i][j] = db[i-1][j];
			c=='W' ? dw[i][j] += x>j : db[i][j] += x>j;
		}
	}
	for(j=1; j<=n; j++) dp[0][j] = 1e9;
	for(i=0; i<=n; i++) for(j=0; j<=n; j++) {
		if(i) dp[i][j] = dp[i-1][j] + dw[w[i]][i] + db[w[i]][j];
		if(j) dp[i][j] = min(dp[i][j], dp[i][j-1] + dw[b[j]][i] + db[b[j]][j]);
	}
	cout<<dp[n][n];
	return 0;
}