#include<iostream>
#include<cstdio>
using namespace std;
int smallw[4444][2222],smallb[4444][2222];
int dp[2222][2222],n,a[4444],pos[2][2222],cur;
char c[4444];
int main()
{
	scanf("%d",&n);
	n*=2;
	for (int i=1;i<=n;i++)
	{
		getchar();
		scanf("%c %d",&c[i],&a[i]);
		if (c[i]=='B') pos[0][a[i]]=i;
		else pos[1][a[i]]=i;
	}
	for (int i=n;i>=1;i--)
	{
		for (int j=1;j<=n/2+1;j++)
		{
			if (c[i]=='W') smallb[i][j]=smallb[i+1][j];
			else smallb[i][j]=smallb[i+1][j]+(a[i]<j);
		}
	}
	for (int i=n;i>=1;i--)
	{
		for (int j=1;j<=n/2+1;j++)
		{
			if (c[i]=='B') smallw[i][j]=smallw[i+1][j];
			else smallw[i][j]=smallw[i+1][j]+(a[i]<j);
		}
	}
	for (int i=0;i<=n/2;i++)
	{
		for (int j=0;j<=n/2;j++)
		dp[i][j]=1e9;
	}
	dp[0][0]=0;
	for (int i=0;i<=n/2;i++)
	{
		for (int j=0;j<=n/2;j++)
		{
			if (i)
			{
				cur=pos[0][i]+smallb[pos[0][i]][i]+smallw[pos[0][i]][j+1];
				dp[i][j]=min(dp[i][j],dp[i-1][j]+(cur-i-j));
			}
			if (j)
			{
				cur=pos[1][j]+smallb[pos[1][j]][i+1]+smallw[pos[1][j]][j];
				dp[i][j]=min(dp[i][j],dp[i][j-1]+(cur-i-j));
			}
		}
	}
	printf("%d\n",dp[n/2][n/2]);
	return 0;
}