#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll beki(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k%2==1){
            ret*=now;
            ret%=mod;
        }
        now*=now;
        now%=mod;
        k/=2;
    }
    return ret;
}
ll gyaku(ll n){
    return beki(n,mod-2);
}
ll bit[400010];
ll u;
void bitinit(ll n){
    rep(i,0,69){
        ll y=pow(2,i);
        if(y>=n){
            u=y;
            break;
        }
    }
    fill(bit,bit+u+10,0);
}
void add(ll n,ll x){
    ll i=n;
    bit[i]+=x;
    bit[i]%=mod;
    while(i<u){
        i+=i&(-i);
        bit[i]+=x;
        bit[i]%=mod;
    }
}
ll sum(ll n){
    ll i=n;
    ll ret=0;
    while(i>0){
        ret+=bit[i];
        i-=i&(-i);
        ret%=mod;
    }
    return ret;
}
ll bitw[400010];
ll uw;
void bitwinit(ll n){
    rep(i,0,69){
        ll y=pow(2,i);
        if(y>=n){
            u=y;
            break;
        }
    }
    fill(bitw,bitw+uw+10,0);
}
void addw(ll n,ll x){
    ll i=n;
    bitw[i]+=x;
    bitw[i]%=mod;
    while(i<u){
        i+=i&(-i);
        bitw[i]+=x;
        bitw[i]%=mod;
    }
}
ll sumw(ll n){
    ll i=n;
    ll ret=0;
    while(i>0){
        ret+=bitw[i];
        i-=i&(-i);
        ret%=mod;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
    char c[2*n];int a[2*n];
    int whi[n+1];
    int bla[n+1];
    rep(i,0,2*n){
        cin>>c[i]>>a[i];
        if(c[i]=='B'){
            bla[a[i]]=i+1;
        }
        else whi[a[i]]=i+1;
    }
    int dp[n+1][n+1];
    rep(i,0,n+1)rep(j,0,n+1)dp[i][j]=1000000000;
    dp[0][0]=0;
    bitinit(2*n+1);
    bitwinit(2*n+1);
    int numb[n+1];
    int numw[n+1];
    rep(i,1,n+1){
        int sum=0;
        rep(j,0,2*n){
            if(c[j]=='B'){
                if(a[j]>i)sum++;
                if(a[j]==i)break;
            }
        }
        numb[i]=sum;
        sum=0;
        rep(j,0,2*n){
            if(c[j]=='W'){
                if(a[j]>i)sum++;
                if(a[j]==i)break;
            }
        }
        numw[i]=sum;
    }
    //rep(i,1,n+1)cout<<numw[i]<<" "<<numb[i]<<endl;
    rep(i,1,n+1){
        addw(whi[i],1);
        add(bla[i],1);
    }
    rep(i,1,n+1){
        dp[i][0]=dp[i-1][0]+numb[i]+sumw(bla[i]);
        dp[0][i]=dp[0][i-1]+numw[i]+sum(whi[i]);
    }
    rep(i,1,n+1){
        add(bla[i],-1);
        rep(j,1,n+1){
            addw(whi[j],-1);
            dp[i][j]=min(dp[i-1][j]+numb[i]+sumw(bla[i]),dp[i][j-1]+numw[j]+sum(whi[j]));
        }
        rep(j,1,n+1)addw(whi[j],1);
    }
    cout<<dp[n][n]<<endl;
    rep(i,0,n+1){
        //rep(j,0,n+1)cout<<dp[i][j]<<" ";
       // cout<<endl;
    }
}


Measured memory_bytes: 18048