#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<char, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
char c[4010];
int a[4010];

int dp[2010][2010];
unordered_map<P, int, pairhash> pos;

// 1 base
template<typename T, int max_n>
class BIT {
private:
    T bit[max_n + 1];
    int n;
public:
    BIT(int _n = max_n) {
        n = _n;
        memset(bit, 0, sizeof(bit));
    }
    // [1, i]
    T sum(int i) {
        T s = 0;
        while (i > 0) {
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    // [a, b]
    T sum(int a, int b) {
        return sum(b) - sum(a-1);
    }

    void add(int i, T x) {
        while (i <= n) {
            bit[i] += x;
            i += i & -i;
        }
    }

    int lower_bound(T x) {
        int lb = 0, ub = n;
        while (ub - lb > 1) {
            int mid = (ub + lb) / 2;
            T v = sum(mid);
            if (v < x) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        return ub;
    }

    int upper_bound(T x) {
        int lb = 1, ub = n+1;
        while (ub - lb > 1) {
            int mid = (ub + lb) / 2;
            T v = sum(mid);
            if (v <= x) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        return ub;
    }
};

BIT<int, 4010> bit;

int calc(int u, int v) {
    if (u == n && v == n) return 0;
    if (dp[u][v] < 0) {
        int uc = inf, vc = inf;
        if (u < n) {
            int up = pos[make_pair('W', u+1)];
            uc = up - bit.sum(up) - 1;
            bit.add(up, 1);
            uc += calc(u+1, v);
            bit.add(up, -1);
        }
        if (v < n) {
            int vp = pos[make_pair('B', v+1)];
            vc = vp - bit.sum(vp) - 1;
            bit.add(vp, 1);
            vc += calc(u, v+1);
            bit.add(vp, -1);
        }
        dp[u][v] = min(uc, vc);
    }
    return dp[u][v];
}

int solve() {
    for (int i = 0; i < 2*n; i++) {
        pos[make_pair(c[i], a[i])] = i+1;
    }
    memset(dp, -1, sizeof(dp));

    return calc(0, 0);
}

void input() {
    cin >> n;
    for (int i = 0; i < 2*n; i++) cin >> c[i] >> a[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 20044