///////////////////////////////////////////////////////////////////////////////

#include <bits/stdc++.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>

using namespace std;

///////////////////////////////////////////////////////////////////////////////

#define DEBUG 0

#define pb push_back
#define V vector
#define M unordered_map
#define S static

#define rep(i,n) for(ll i=0LL; i<n; ++i)
#define srep(i,s,n) for(ll i=s; i<n; ++i)
#define rrep(i,n) for(ll i=n-1LL; i>=0LL; --i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CIN(x) do { \
        assert(!cin.eof()); \
        cin >> x; \
        assert(!cin.fail()); \
} while(0);
#if DEBUG
#define debug_print(...) _debug_print(__VA_ARGS__)
#define debug_printf(...) printf(__VA_ARGS__)
#define debug_print_time _debug_print_time
#else // DEBUG
#define debug_print(...)
#define debug_printf(...)
#define debug_print_time
#endif // DEBUG

typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll, ll> t2;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;
template <typename T>
using priority_queue_incr = priority_queue<T, V<T>, greater<T> >;

///////////////////////////////////////////////////////////////////////////////

template <typename TT, typename T>
T get_m(M<TT, T> &m, TT k, T default_value)
{
    if (m.find(k) == m.end()) return m[k] = default_value;
    return m[k];
}

template <typename TT, typename T>
void incr_m(M<TT, T> &m, TT k)
{
    if (m.find(k) == m.end()) m[k] = 0;
    m[k]++;
}

template <typename TT, typename T>
void incr_m(map<TT, T> &m, TT k)
{
    if (m.find(k) == m.end()) m[k] = 0;
    m[k]++;
}

void llin(ll &a)
{
    CIN(a);
}

void llinl1(V<ll> &v, ll count)
{
    for (ll i = 0LL; i < count; ++i) {
        ll a;
        CIN(a);
        v.push_back(a);
    }
}

void llinl2(V<t2> &v, ll count)
{
    for (ll i = 0LL; i < count; ++i) {
        ll a, b;
        CIN(a >> b);
        v.push_back(t2(a, b));
    }
}

void llinl3(V<t3> &v, ll count)
{
    for (ll i = 0LL; i < count; ++i) {
        ll a, b, c;
        CIN(a >> b >> c);
        v.push_back(t3(a, b, c));
    }
}

void llinl4(V<t4> &v, ll count)
{
    for (ll i = 0LL; i < count; ++i) {
        ll a, b, c, d;
        CIN(a >> b >> c >> d);
        v.push_back(t4(a, b, c, d));
    }
}

void llina(V<ll> &v, ll count)
{
    llinl1(v, count);
}

template <typename T>
void sort(V<T> &v)
{
    sort(v.begin(), v.end());
}

template <typename T>
void sort_reverse(V<T> &v)
{
    sort(v.begin(), v.end(), greater<T>());
}

template <typename T>
void _debug_print(T x)
{
    cout << x << endl;
}

void _debug_print(const t2 &x)
{
    ll x1 = get<0>(x);
    ll x2 = get<1>(x);
    cout << "-- " << x1 << " -- " << x2 << endl;
}

void _debug_print(const t3 &x)
{
    ll x1 = get<0>(x);
    ll x2 = get<1>(x);
    ll x3 = get<2>(x);
    cout << "-- " << x1 << " -- " << x2 << " -- " << x3 << endl;
}

void _debug_print(const t4 &x)
{
    ll x1 = get<0>(x);
    ll x2 = get<1>(x);
    ll x3 = get<2>(x);
    ll x4 = get<3>(x);
    cout << "-- " << x1 << " -- " << x2
         << " -- " << x3 << " -- " << x4 << endl;
}

template <typename T>
void _debug_print(T xarray[], ll n)
{
    rep (i, n) _debug_print(xarray[i]);
}

template <typename T>
void _debug_print(const V<T> &xlist)
{
    for (auto x : xlist) {
        cout << "-- ";
        _debug_print(x);
    }
}

template <typename T>
void _debug_print(const set<T> &xset)
{
    for (auto x : xset) {
        cout << "-- ";
        _debug_print(x);
    }
}

template <typename TT, typename T>
void _debug_print(const M<TT, T> &xlist)
{
    for (auto x : xlist) {
        TT k = x.first;
        T v = x.second;
        cout << "====" << endl;
        cout << "K=";
        _debug_print(k);
        cout << "V=";
        _debug_print(v);
    }
}

template <typename TT, typename T>
void _debug_print(const map<TT, T> &xlist)
{
    for (auto x : xlist) {
        TT k = x.first;
        T v = x.second;
        cout << "====" << endl;
        cout << "K=";
        _debug_print(k);
        cout << "V=";
        _debug_print(v);
    }
}

void _debug_print_time(const char *prefix)
{
    struct timeval tv;
    gettimeofday(&tv, NULL);
#if DEBUG
    struct tm *tm = localtime(&tv.tv_sec);
#endif
    debug_printf("-- %s %02d:%02d:%02d.%06ld\n",
                  prefix, tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec);
}

template <typename T>
struct SegmentTree {
    T *nodes;
    t2 *ranges;  // [start, end)
    ll nodecount;
    ll itemcount;
    T unit;
    T (*op)(T, T);

    SegmentTree(ll itemcount, T unit, T op(T, T)) {
        ll orig_itemcount = itemcount;
        this->itemcount = 1LL;
        while (this->itemcount < orig_itemcount) this->itemcount *= 2LL;
        nodecount = this->itemcount * 2 - 1;
        nodes = new T[nodecount];
        ranges = new t2[nodecount];
        this->unit = unit;
        this->op = op;

        ll start = 0LL;
        ll end = this->itemcount;
        ll len = this->itemcount;

        rep (i, nodecount) {
            nodes[i] = unit;
            ranges[i] = t2(start, end);
            if (end >= this->itemcount) {
                len /= 2LL;
                start = 0LL;
                end = len;
            }
            else {
                start = end;
                end = start + len;
            }
        }
    }

    void build(const T arr[]) {
        memcpy(nodes + nodecount / 2LL, arr, sizeof(T) * itemcount);
        rrep (i, nodecount / 2LL) {
            nodes[i] = op(nodes[i * 2LL + 1LL], nodes[i * 2LL + 2LL]);
        }
    }

    void update(ll k, T v) {
        ll idx = k + itemcount - 1LL;
        nodes[idx] = v;
        idx = (idx - 1LL) / 2LL;

        for ( ; idx >= 0; idx = (idx - 1LL) / 2LL) {
            nodes[idx] = op(nodes[idx * 2LL + 1LL],
                            nodes[idx * 2LL + 2LL]);
            if (!idx) break;
        }
    }

    // query to [start, end)
    virtual T query(ll start, ll end) const {
        return _query(start, end, 0LL);
    }

    virtual T _query(ll start, ll end, ll idx) const {
        ll rstart = get<0>(ranges[idx]);
        ll rend = get<1>(ranges[idx]);

        if (start <= rstart && rend <= end) {
            return nodes[idx];
        }
        if (rend <= start || end <= rstart) {
            return unit;
        }
        T left = _query(start, end, idx * 2LL + 1LL);
        T right = _query(start, end, idx * 2LL + 2LL);
        return op(left, right);
    }

    T query_fast(ll start, ll end) const {
        start += nodecount / 2LL;
        end += nodecount / 2LL;
        T lval = unit;
        T rval = unit;
        for ( ; start < end; start >>= 1LL, end >>= 1LL) {
            if (!(start & 1LL)) lval = op(lval, nodes[start]);
            if (!(end & 1LL)) rval = op(rval, nodes[end-1]);
            end--;
        }
        return op(lval, rval);
    }

};

//// update : sum / query : range sum
// ll op(ll x, ll y){ return x + y; }
// void op_upd(ll &x, ll y) { x += y; }
// ll op_div(ll x) { return x / 2LL; }
// ll op_mlt(ll x, ll y) { return x * y; }
//// update : sum / query : range max
// ll op(ll x, ll y) { return max(x, y); }
// void op_upd(ll &x, ll y) { x += y; }
// ll op_div(ll x) { return x; }
// ll op_mlt(ll x, ll y) { return x; }
//// update : substitute / query : range sum
// ll add(ll x, ll y) { return x + y; }
// void upd(ll &x, ll y) { x = y; }
// ll div(ll x) { return x / 2LL; }
// ll mlt(ll x, ll y) { return x * y; }
template <typename T>
struct SegmentTreeLazy : public SegmentTree<T> {
    T *lzvals;
    bool *lzvalids;
    ll unit_upd;
    void (*op_upd)(T&, T);
    T (*op_div)(T);
    T (*op_mlt)(T, T);

    SegmentTreeLazy(ll itemcount, T unit, T unit_upd,
                    T op(T, T), void op_upd(T&, T), T op_div(T), T op_mlt(T, T))
        : SegmentTree<T>(itemcount, unit, op) {
        this->lzvals = new T[this->nodecount];
        this->lzvalids = new bool[this->nodecount];
        this->unit_upd = unit_upd;
        this->op_upd = op_upd;
        this->op_div = op_div;
        this->op_mlt = op_mlt;
        rep (i, this->nodecount) this->lzvals[i] = unit_upd;
        memset(this->lzvalids, 0, sizeof(bool) * this->nodecount);
    }

    // newval = op_upd(oldval, lzval);
    void eval(ll nodeidx) {
        if (!lzvalids[nodeidx]) return;

        op_upd(this->nodes[nodeidx], lzvals[nodeidx]);

        if (nodeidx * 2LL + 2LL < this->nodecount) {
            ll downval = op_div(lzvals[nodeidx]);
            op_upd(lzvals[nodeidx * 2LL + 1LL], downval);
            op_upd(lzvals[nodeidx * 2LL + 2LL], downval);
            lzvalids[nodeidx * 2LL + 1LL] = lzvalids[nodeidx * 2LL + 2LL] = true;
        }

        lzvalids[nodeidx] = false;
        lzvals[nodeidx] = this->unit_upd;
    }

    void update(ll start, ll end, ll val) {
        _update(start, end, val, 0LL);
    }

    void _update(ll start, ll end, ll val, ll nodeidx) {
        eval(nodeidx);

        ll rstart = get<0>(this->ranges[nodeidx]);
        ll rend = get<1>(this->ranges[nodeidx]);
        if (end <= rstart || rend <= start) return;

        if (start <= rstart && rend <= end) {
            op_upd(lzvals[nodeidx], op_mlt(val, rend - rstart));
            lzvalids[nodeidx] = true;
            eval(nodeidx);
        }
        else {
            _update(start, end, val, nodeidx * 2LL + 1LL);
            _update(start, end, val, nodeidx * 2LL + 2LL);
            this->nodes[nodeidx] = this->op(this->nodes[nodeidx * 2LL + 1LL],
                                            this->nodes[nodeidx * 2LL + 2LL]);
        }
    }

    // query to [start, end)
    virtual T query(ll start, ll end) {
        return _query(start, end, 0LL);
    }

    virtual T _query(ll start, ll end, ll nodeidx) {
        ll rstart = get<0>(this->ranges[nodeidx]);
        ll rend = get<1>(this->ranges[nodeidx]);

        eval(nodeidx);

        if (start <= rstart && rend <= end) {
            return this->nodes[nodeidx];
        }
        if (rend <= start || end <= rstart) {
            return this->unit;
        }
        T left = _query(start, end, nodeidx * 2LL + 1LL);
        T right = _query(start, end, nodeidx * 2LL + 2LL);
        return this->op(left, right);
    }
};



///////////////////////////////////////////////////////////////////////////////

void _main();
int main()
{
    cout << setprecision(12);
#if !DEBUG
    ios::sync_with_stdio(false);
    cin.tie(0);
#endif

    _main();
    return 0;
}

typedef tuple<char, ll> cll;

ll sumll(ll x, ll y)
{
    return x + y;
}

void f_revcnts(ll revcnts[], const ll numidx[], ll n)
{
    SegmentTree<ll> tree(4005, 0, sumll);
    rrep (a, n) {
        revcnts[a] = tree.query(0, numidx[a]);
        tree.update(numidx[a], 1);
    }
}

void f_rem(ll rem[2005][2005], ll numidx_from[], ll numidx_to[], ll n)
{
    rep (fromval, n) {
        SegmentTree<ll> tree(4005, 0, sumll);
        ll fromidx = numidx_from[fromval];
        rem[fromval][n] = 0;
        rrep (toval, n) {
            tree.update(numidx_to[toval], 1);
            rem[fromval][toval] = tree.query(0, fromidx);
        }
    }
}

void _main()
{
    ll n; llin(n);
    V<cll> balls;
    rep (i, n * 2LL) {
        char c; CIN(c);
        ll a; llin(a); a--;
        balls.pb(cll(c, a));
    }

    S ll numidx_w[2005];
    S ll numidx_b[2005];
    rep (i, n*2LL) {
        char c = get<0>(balls[i]);
        ll a = get<1>(balls[i]);
        if (c == 'W') numidx_w[a] = i;
        if (c == 'B') numidx_b[a] = i;
    }

    S ll revcnts_w[2005];
    f_revcnts(revcnts_w, numidx_w, n);
    debug_printf("---- revcnts_w\n");
    // debug_print(revcnts_w, 4);
    debug_print(revcnts_w, 129);

    S ll revcnts_b[2005];
    f_revcnts(revcnts_b, numidx_b, n);
    debug_printf("---- revcnts_b\n");
    // debug_print(revcnts_b, 4);
    debug_print(revcnts_b, 129);

    S ll rem_wtob[2005][2005];
    f_rem(rem_wtob, numidx_w, numidx_b, n);
    debug_printf("---- rem_wtob\n");
    // rep (i, 4) {
        // rep (j, 4) debug_printf("%lld ", rem_wtob[i][j]);
        // debug_printf("\n");
    // }
    rep (i, 129) {
        rep (j, 129) debug_printf("%lld ", rem_wtob[i][j]);
        debug_printf("\n");
    }

    S ll rem_btow[2005][2005];
    f_rem(rem_btow, numidx_b, numidx_w, n);

    S ll dp[2005][2005];
    rep (i, 2005) rep (j, 2005) dp[i][j] = 1e18;
    dp[0][0] = 0;

    srep (wcnt, 1, n+1) {
        dp[wcnt][0] = dp[wcnt-1][0] + revcnts_w[wcnt-1] + rem_wtob[wcnt-1][0];
    }
    srep (bcnt, 1, n+1) {
        dp[0][bcnt] = dp[0][bcnt-1] + revcnts_b[bcnt-1] + rem_btow[bcnt-1][0];
    }

    debug_printf("---- dp_wcnt_0\n");
    rep (i, 4) debug_printf("%lld ", dp[i][0]);
    debug_printf("\n");

    debug_printf("---- dp_bcnt_0\n");
    rep (i, 4) debug_printf("%lld ", dp[0][i]);
    debug_printf("\n");

    srep (wcnt, 1, n+1) srep (bcnt, 1, n+1) {
        ll cand1 = dp[wcnt-1][bcnt] + revcnts_w[wcnt-1] + rem_wtob[wcnt-1][bcnt];
        ll cand2 = dp[wcnt][bcnt-1] + revcnts_b[bcnt-1] + rem_btow[bcnt-1][wcnt];
        dp[wcnt][bcnt] = min(cand1, cand2);
    }

    debug_printf("---- ans\n");
    cout << dp[n][n] << endl;
}

///////////////////////////////////////////////////////////////////////////////


Measured memory_bytes: 866272