#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<class V> struct BIT { BIT() {}  // [L, R)
    int NV;vector<V> bit;BIT(int n){init(n);}void init(int n){NV=1;while(NV<n)NV*=2;bit.resize(NV);}
    V operator[](int e) { V s = 0; e++; while (e) s += bit[e - 1], e -= e&-e; return s; }
    void add(int e, V v) { e++; while (e <= NV) bit[e - 1] += v, e += e&-e; }
    int lower_bound(V val) { V tv = 0; int i, ent = 0; for (i = NV - 1; i >= 0; i--)
        if(tv+bit[ent+(1<<i)-1]<=val)tv+=bit[ent+(1<<i)-1],ent += (1 << i);return ent;}
    V get(int L, int R) {assert(0 <= L); assert(R <= NV); assert(L <= R);
        V res = 0; if(R) res += operator[](R - 1); if (L) res -= operator[](L - 1);return res;}
    void clear() { bit.clear(); }};
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int N;
char C[4020];
int A[4020];
int smB[2020][4020];
int smW[2020][4020];
int idxB[2020];
int idxW[2020];
//---------------------------------------------------------------------------------------------------
int memo[2020][2020];
int f(int b, int w) {
    if (b == N and w == N) return 0;
    if (0 <= memo[b][w]) return memo[b][w];

    int res = inf;

    if (b != N) {
        /*int cnt = 0;
        rep(i, 0, idxB[b + 1]) {
            if (C[i] == 'B' and b < A[i]) cnt++;
            if (C[i] == 'W' and w < A[i]) cnt++;
        }*/

        int cnt = 0;
        if (0 <= idxB[b + 1] - 1) cnt += smB[b + 1][idxB[b + 1] - 1];
        if (0 <= idxB[b + 1] - 1) cnt += smW[w + 1][idxB[b + 1] - 1];
        
        chmin(res, f(b + 1, w) + cnt);
    }

    if (w != N) {
        /*int cnt = 0;
        rep(i, 0, idxW[w + 1]) {
            if (C[i] == 'B' and b < A[i]) cnt++;
            if (C[i] == 'W' and w < A[i]) cnt++;
        }*/

        int cnt = 0;
        if (0 <= idxW[w + 1] - 1) cnt += smB[b + 1][idxW[w + 1] - 1];
        if (0 <= idxW[w + 1] - 1) cnt += smW[w + 1][idxW[w + 1] - 1];
        chmin(res, f(b, w + 1) + cnt);
    }

    return memo[b][w] = res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, 2 * N) cin >> C[i] >> A[i];

    rep(i, 0, 2 * N) {
        if (C[i] == 'B') smB[A[i]][i]++;
        else smW[A[i]][i]++;
    }
    rep(i, 0, N + 5) {
        rep(j, 1, 2 * N) smB[i][j] += smB[i][j - 1];
        rep(j, 1, 2 * N) smW[i][j] += smW[i][j - 1];
    }
    rep(j, 0, 2 * N) {
        rrep(i, N+4, 0) smB[i][j] += smB[i + 1][j];
        rrep(i, N+4, 0) smW[i][j] += smW[i + 1][j];
    }

    rep(i, 0, 2 * N) {
        if (C[i] == 'B') idxB[A[i]] = i;
        if (C[i] == 'W') idxW[A[i]] = i;
    }

    rep(i, 0, N + 1) rep(j, 0, N + 1) memo[i][j] = -1;
    cout << f(0, 0) << endl;
}

Measured memory_bytes: 79616