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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
//constexpr long long MOD = 1777777777LL;
using ld = long double;
using tp = tuple<ll, ll, ll>;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

template <class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

// long dobule
struct Edge {
    ll to, cap, rev;
    Edge(ll _to, ll _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    int n;
    cin >> n;
    vec<char> c(2 * n);
    vec<int> a(2 * n);

    vvec<int> b(2 * n, vec<int>(n, 0)), w(2 * n, vec<int>(n, 0));
    vec<int> posb(n, 0), posw(n, 0);
    REP(i, 2 * n) {
        cin >> c[i] >> a[i];
        if(c[i] == 'B') {
            b[i][a[i] - 1]++;
            posb[a[i] - 1] = i;
        } else {
            w[i][a[i] - 1]++;
            posw[a[i] - 1] = i;
        }
    }

    vvec<int> sumb(2 * n + 1, vec<int>(n + 1, 0)), sumw(2 * n + 1, vec<int>(n + 1, 0));
    REP(i, 2 * n) {
        REP(j, n) {
            sumb[i + 1][j + 1] = sumb[i + 1][j] + sumb[i][j + 1] - sumb[i][j] + b[i][j];
            sumw[i + 1][j + 1] = sumw[i + 1][j] + sumw[i][j + 1] - sumw[i][j] + w[i][j];
        }
    }

    vvec<int> dp(n + 1, vec<int>(n + 1, INF_INT));
    dp[0][0] = 0;

    REP(i, n + 1) {
        REP(j, n + 1) {
            if(i < n) {
                int cost = 0;
                {
                    ll rx = posb[i];
                    ll lx = 0;
                    ll ry = n;
                    ll ly = i;
                    cost += sumb[rx][ry] - sumb[rx][ly] - sumb[lx][ry] + sumb[lx][ly];
                }
                {
                    ll rx = posb[i];
                    ll lx = 0;
                    ll ry = n;
                    ll ly = j;
                    cost += sumw[rx][ry] - sumw[rx][ly] - sumw[lx][ry] + sumw[lx][ly];
                }
                chmin(dp[i + 1][j], dp[i][j] + cost);
            }
            if(j < n) {
                int cost = 0;
                {
                    ll rx = posw[j];
                    ll lx = 0;
                    ll ry = n;
                    ll ly = i;
                    cost += sumb[rx][ry] - sumb[rx][ly] - sumb[lx][ry] + sumb[lx][ly];
                }
                {
                    ll rx = posw[j];
                    ll lx = 0;
                    ll ry = n;
                    ll ly = j;
                    cost += sumw[rx][ry] - sumw[rx][ly] - sumw[lx][ry] + sumw[lx][ly];
                }
                chmin(dp[i][j + 1], dp[i][j] + cost);
            }
        }
    }

    cout << dp[n][n] << en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*
    ll t;
    cin >> t;
    while(t--)*/
    solve();

    return 0;
}


Measured memory_bytes: 144712