#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const ll MOD=1000000007,INF=1e18;
int dx[]={0,0,1,-1};
int dy[]={-1,1,0,0};
 
int N;

int B[2020],W[2020],BtoW[2020][2020],WtoB[2020][2020],dp[2020][2020];
pair<pint,char> p[2020];

struct LazySegmentTree{
    private:
    int n;
    vector<ll> node,lazy;


    public:
    LazySegmentTree(vector<ll> v){
        int sz = (int)v.size();
        n = 1;while(n < sz)n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1,0);

        for(int i=0;i<sz;i++)node[i+n-1] = v[i];
        for(int i=n-2;i>=0;i--)node[i]=node[2*i+1]+node[2*i+2];
    }

    void eval(int k,int l,int r){
        if(lazy[k] != 0){
            node[k] += lazy[k];

            if(r-l > 1){
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }

    void add(int a,int b,ll x,int k=0,int l=0,int r=-1){
        if(r<0)r = n;

        eval(k,l,r);
        if(b <= l || r <= a)return;

        if(a <= l && r <= b){
            lazy[k] += (r - l) * x;
            eval(k,l,r);
        }
        else{
            add(a,b,x,2*k+1,l,(l+r)/2);
            add(a,b,x,2*k+2,(l+r)/2,r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }
    ll getsum(int a,int b,int k=0,int l=0,int r=-1){
        if(r < 0)r = n;
        eval(k,l,r);
        if(b <= l || r <= a)return 0;
        if(a <= l && r <= b)return node[k];
        ll vl = getsum(a,b,2*k+1,l,(l+r)/2);
        ll vr = getsum(a,b,2*k+2,(l+r)/2,r);
        return vl + vr;
    }
};

signed main() {
    IOS();
    cin>>N;
    LazySegmentTree Bseg(vint(N*2,0)),Wseg(vint(N*2,0));
    rep(i,0,2*N){
        char a;
        int b;
        cin>>a>>b;
        b--;
        p[i]=pair<pint,char>(pint(b,i),a);
    }
    
    rep(i,0,2*N){
        if(p[i].se=='B'){
            rep(j,0,i){
                if(p[j].se=='W')continue;
                if(p[i].fi.fi<p[j].fi.fi)B[p[i].fi.fi]++;
            }
        }else{
            rep(j,0,i){
                if(p[j].se=='B')continue;
                if(p[i].fi.fi<p[j].fi.fi)W[p[i].fi.fi]++;
            }
        }
        
    }
    sort(p,p+2*N);
    rep(i,0,2*N){
        if(p[i].se=='B'){
            Bseg.add(p[i].fi.se,p[i].fi.se+1,1);
        }else{
            Wseg.add(p[i].fi.se,p[i].fi.se+1,1);
        }
    }
    rep(j,0,2*N){
        if(p[j].se=='W'){
            WtoB[p[j].fi.fi][0]=Bseg.getsum(0,p[j].fi.se);
        }else{
            BtoW[p[j].fi.fi][0]=Wseg.getsum(0,p[j].fi.se);
        }
    }
    
    rep(i,0,2*N){
        if(p[i].se=='B'){
            Bseg.add(p[i].fi.se,p[i].fi.se+1,-1);
            rep(j,0,2*N){
                if(p[j].se=='B')continue;
                WtoB[p[j].fi.fi][p[i].fi.fi+1]=Bseg.getsum(0,p[j].fi.se);
            }
        }else{
            Wseg.add(p[i].fi.se,p[i].fi.se+1,-1);
            rep(j,0,2*N){
                if(p[j].se=='W')continue;
                BtoW[p[j].fi.fi][p[i].fi.fi+1]=Wseg.getsum(0,p[j].fi.se);
            }
        }
    }
    
    rep(i,0,2020)rep(j,0,2020)dp[i][j]=INF;
    dp[0][0]=0;//[B][W]
    rep(i,0,N+1){
        rep(j,0,N+1){
            if(i!=N)chmin(dp[i+1][j],dp[i][j]+B[i]+BtoW[i][j]);
            if(j!=N)chmin(dp[i][j+1],dp[i][j]+W[j]+WtoB[j][i]);
        }
    }
    cout<<dp[N][N]<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 96000