#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll p0[2005],p1[2005],hv0[4005][2005],hv1[4005][2005];
ll dp[2005][2005];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    for(ll i=0;i<2*n;i++){
        char ch;cin>>ch;
        ll x;cin>>x;
        if(ch=='W')p0[x]=i;
        else p1[x]=i;
    }
    for(ll i=0;i<2*n;i++){
        hv0[i][0]=0;
        for(ll j=1;j<=n;j++)hv0[i][j]=hv0[i][j-1] + (p0[j]>i);
    }
    for(ll i=0;i<2*n;i++){
        hv1[i][0]=0;
        for(ll j=1;j<=n;j++)hv1[i][j]=hv1[i][j-1] + (p1[j]>i);
    }
    for(ll i=0;i<=n;i++){
        for(ll j=0;j<=n;j++){
            if(i==0 && j==0)continue;
            dp[i][j]=1e9;
            if(i>0)dp[i][j]=min(dp[i][j], dp[i-1][j] + hv0[p0[i]][i] + hv1[p0[i]][j]);
            if(j>0)dp[i][j]=min(dp[i][j], dp[i][j-1] + hv0[p1[j]][i] + hv1[p1[j]][j]);
        }
    }
    cout<<dp[n][n];
}