#include <bits/stdc++.h>
using namespace std;

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


ll solve(int N,vi& c,vi& a) {
    int W = N*2;

    vi pB(N+1), pW(N+1); // pB[i] = 黒iの位置
    rep(i,W){
        if (c[i]) {
            pB[a[i]] = i; // black
        } else {
            pW[a[i]] = i; // white
        }
    }
#ifdef DEBUG
    cerr << "pB[]: " << pB << endl;
    cerr << "pW[]: " << pW << endl;
#endif

    // vvi cB(N+1, vi(W+1, 0)), cW(N+1, vi(W+1, 0));
    vvi cB(N+2), cW(N+2);
    cB[N+1] = vi(W+1, 0);
    cW[N+1] = vi(W+1, 0);
    // vvi cB(W+1, vi(N+1, 0)), cW(W+1, vi(N+1, 0));
    // cX[j][k] : 左からk個[0..W]のうち、j以上の白(ないし黒)の個数
    for (int j=N; j>=1; --j) {
        {
            int here = pB[j];
            cB[j] = cB[j+1];
            for (int i=here+1; i<=W; ++i) ++cB[j][i];
        }
        {
            int here = pW[j];
            cW[j] = cW[j+1];
            for (int i=here+1; i<=W; ++i) ++cW[j][i];
        }
    }
    cB[0] = cB[1];
    cW[0] = cW[1];

#ifdef DEBUG
    fprintf(stderr, "cB[][]:\n");
    rep(i, N+1) {
        rep(k, W+1) {
            fprintf(stderr, " %2d", cB[i][k]);
        }
        fprintf(stderr, "\n");
    }
    fprintf(stderr, "cW[][]:\n");
    rep(i, N+1) {
        rep(k, W+1) {
            fprintf(stderr, " %2d", cW[i][k]);
        }
        fprintf(stderr, "\n");
    }
#endif
    vvi dp(N+1, vi(N+1, INT_MAX));
    dp[0][0] = 0; // dp]黒いくつまで][白いくつまで]
    for (int j=1; j<=N; ++j) {
        // 黒0 白j
        int here = pW[j];
        int f = cW[j+1][here] + cB[1][here];
        dp[0][j] = dp[0][j-1] + f;
    }
    for (int i=1; i<=N; ++i) {
        // 黒i 白0
        int here = pB[i];
        int f = cB[i+1][here] + cW[1][here];
        dp[i][0] = dp[i-1][0] + f;
    }

    for (int i=1; i<=N; ++i) {
        for (int j=1; j<=N; ++j) {
            int costB, costW;
            {
                // 白はj固定、黒を i-1 -> i
                int here = pB[i];
                costB = cB[i+1][here] + cW[j+1][here];
            }
            {
                // 黒はi固定、白を j-1 -> j
                int here = pW[j];
                costW = cB[i+1][here] + cW[j+1][here];
            }
            dp[i][j] = min(dp[i-1][j] + costB, dp[i][j-1] + costW);
        }
    }
#ifdef DEBUG
    fprintf(stderr, "dp[i][j]:\n");
    rep(i, N+1) {
        rep(j, N+1) {
            fprintf(stderr, " %2d", dp[i][j]);
        }
        fprintf(stderr, "\n");
    }
#endif

    return dp[N][N];
}

int main() {
    int N; cin >> N;
    vi c(N*2), a(N*2);
    rep(i, N*2){
        char ch; int ai; cin >> ch >> ai;
        c[i] = (ch == 'B');
        a[i] = ai; // - 1;
    }
    cout << solve(N,c,a) << endl;
    return 0;
}


Measured memory_bytes: 78720