#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

using pint = pair<int,int>;
const long long INF = 1LL<<60;

int N;
vector<char> c;
vector<int> a;

long long solve() {
    // iB[j] = (B, j) が何番目か
    // iW[j] = (W, j) が何番目か
    // nB[i][j] = [0, i) の範囲に、(B, j 以上) が何個あるか
    // nW[i][j] = [0, i) の範囲に、(W, j 以上) が何個あるか
    vector<int> iB(N+1, 0), iW(N+1, 0);
    vector<vector<int>> nB(N*2+1, vector<int>(N+1, 0));
    vector<vector<int>> nW(N*2+1, vector<int>(N+1, 0));
    for (int i = 0; i < N*2; ++i) {
        if (c[i] == 'B') iB[a[i]] = i;
        else iW[a[i]] = i;
    }
    for (int j = 0; j < N; ++j) {
        for (int i = 0; i < N*2; ++i) {
            int nbadd = 0, nwadd = 0;
            if (c[i] == 'B' && a[i] >= j) ++nbadd;
            if (c[i] == 'W' && a[i] >= j) ++nwadd;
            nB[i+1][j] = nB[i][j] + nbadd;
            nW[i+1][j] = nW[i][j] + nwadd;
        }
    }

    // DP
    vector<vector<long long>> dp(N+2, vector<long long>(N+2, INF));
    dp[0][0] = 0;
    for (int b = 0; b <= N; ++b) {
        for (int w = 0; w <= N; ++w) {
            int inb = b+w + nB[iB[b]][b] + nW[iB[b]][w]; // (B, b) が何番目にあるか
            int inw = b+w + nW[iW[w]][w] + nB[iW[w]][b]; // (W, w) が何番目にあるか
            
            //cout << b << ", " << w << ": " << inb << ", " << inw << ";; " << dp[b][w] << endl;
            
            chmin(dp[b+1][w], dp[b][w] + abs(inb - (b+w)));
            chmin(dp[b][w+1], dp[b][w] + abs(inw - (b+w)));
        }
    }
    return dp[N][N];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while (cin >> N) {
        c.resize(N*2); a.resize(N*2);
        for (int i = 0; i < N*2; ++i) cin >> c[i] >> a[i], --a[i];
        cout << solve() << endl;
    }
}


















Measured memory_bytes: 94592