#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

const int maxn=2005;

int n,a[2*maxn],L[2][2*maxn][maxn],R[2][2*maxn][maxn],pos[2][maxn];
char clr[2*maxn];

void ReadChar(char &ch)
{
    ch=getchar();
    while (ch!='B' && ch!='W') ch=getchar();
}

int invnum(int i,int j,int c)
{
    int w=pos[c][(c==0) ?i+1 :j+1];
    return R[0][w+1][i] + R[1][w+1][j];
}

int f[maxn][maxn];
int main()
{
    scanf("%d",&n);
    fo(i,1,2*n)
    {
        ReadChar(clr[i]);
        scanf("%d",&a[i]);
        pos[(clr[i]=='B')][a[i]]=i;
    }

    fo(i,1,2*n)
    {
        int ty=(clr[i]=='B');
        memcpy(L[ty^1][i],L[ty^1][i-1],sizeof(L[ty^1][i]));
        memcpy(L[ty][i],L[ty][i-1],sizeof(L[ty][i]));
        fo(j,a[i],n) L[ty][i][j]++;
    }
    fd(i,2*n,1)
    {
        int ty=(clr[i]=='B');
        memcpy(R[ty^1][i],R[ty^1][i+1],sizeof(R[ty^1][i]));
        memcpy(R[ty][i],R[ty][i+1],sizeof(R[ty][i]));
        fo(j,a[i],n) R[ty][i][j]++;
    }

    f[0][0]=0;
    fo(i,0,n)
        fo(j,0,n) if (i || j)
        {
            f[i][j]=n*n*20;
            if (i) f[i][j]=min(f[i][j],f[i-1][j]+invnum(i-1,j,0));
            if (j) f[i][j]=min(f[i][j],f[i][j-1]+invnum(i,j-1,1));
        }
    
    printf("%d\n",f[n][n]);
}