#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1 , number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1 , number1);
    }
}


ll i,j,k,ii,jj;
ll n,m;
ll a,b,c,d,e,g,h,r;
ll l,ans;
ll x[500005],y[500005],z[500005];
ll dp[3005][3005];
ll wdp[5000][5000],bdp[5000][5000];
ll wpos[40000],bpos[40000];
bool dame;
char s[500005],t[500005];

int main(){
    cin >> n;
    for(i=0;i<2*n;i++){
        cin >> s >> a;
        if(s[0] == 'B'){
            x[i] = a * 2;
            bpos[a] = i;
        }
        if(s[0] == 'W'){
            x[i] = a * 2 - 1;
            wpos[a] = i;
        }
    }
    for(i=0;i<2*n;i++){
        for(j=0;j<=n;j++){
            bdp[i][j] = bdp[i-1][j];
            wdp[i][j] = wdp[i-1][j];
        }
        if(x[i] % 2 == 0){
            bdp[i][x[i]/2]++;
        }else{
            wdp[i][(x[i]+1)/2]++;
        }
    }
    for(i=0;i<2*n;i++){
        for(j=n-1;j>=0;j--){
            wdp[i][j] += wdp[i][j+1];
            bdp[i][j] += bdp[i][j+1];
        }
    }
    dp[0][0] = 0;
    for(i=0;i<=n;i++){
        for(j=0;j<=n;j++){
            if(i == 0 && j == 0)continue;
            //a:=i番目の白を置いた時の転倒数
            //b:=j番目の黒を置いた時の転倒数
            ll ap = wpos[i];
            ll bp = bpos[j];
            if(ap >= 1){
                a = wdp[ap-1][i+1] + bdp[ap-1][j+1];
            }else{
                a = 0;
            }
            if(bp >= 1){
                b  = wdp[bp-1][i+1] + bdp[bp-1][j+1];
            }else{
                b = 0;
            }
            if(i == 0){
                dp[i][j] = dp[i][j-1] + b;
            }else if(j == 0){
                dp[i][j] = dp[i-1][j] + a;
            }else{
                dp[i][j] = min(dp[i-1][j] + a,dp[i][j-1] + b);
            }
           //pe(dp[i][j]);
        }
      //el;
    }
    p(dp[n][n]);
    return 0;
}



Measured memory_bytes: 391936