#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define X first
#define Y second
#define pb push_back
#define sz(a) (int)a.size()

void solve();

signed main() {
#ifdef ONPC
    freopen("in.txt", "r", stdin);
#endif // ONPC
    //freopen("time.in", "r", stdin);
    //freopen("time.out", "w", stdout);
    ios_base::sync_with_stdio(0), cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) solve();
    return 0;
}

const int N = 2005;
int n, dp[N][N], pos[2][N], pref[2][N][N];
vector<pair<int, int>> v;
const int INF = 1e9 + 7;

void solve() {
    cin >> n;
    v.pb({0, 0});
    for (int i = 1; i <= 2 * n; ++i) {
        char c;
        int x;
        cin >> c >> x;
        pos[c == 'B'][x] = i;
        for (int j = 0; j <= n; ++j) {
            pref[0][i][j] = pref[0][i - 1][j];
            pref[1][i][j] = pref[1][i - 1][j];
        }
        for (int j = x; j <= n; ++j) {
            ++pref[c == 'B'][i][j];
        }
        v.pb({c == 'B', x});
    }
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            dp[i][j] = INF;
        }
    }
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) {
            if (i == j && i == 0) {
                dp[i][j] = 0;
                continue;
            }
            int ind = i + j;
            if (i != 0) {
                int kek = pos[0][i];
                dp[i][j] = min(dp[i][j], dp[i - 1][j] + pref[0][kek][n] - pref[0][kek][i] + pref[1][kek][n] - pref[1][kek][j]);
            }
            if (j != 0) {
                int kek = pos[1][j];
                //cout << kek << '\n';
                dp[i][j] = min(dp[i][j], dp[i][j - 1] + pref[0][kek][n] - pref[0][kek][i] + pref[1][kek][n] - pref[1][kek][j]);
            }
            //cout << i << ' ' << j << ' ' << dp[i][j] << '\n';
            //if (i == 0 && j == 2) {
            //    return;
            //}
        }
    }
    cout << dp[n][n];
}
