#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const ll mod = 1e+9 + 7;
const int INF = 1001001001;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

template<typename Monoid>
struct SegmentTree{
    using F = function<Monoid(Monoid, Monoid)>;

    int sz;
    vector<Monoid> seg;

    const F f;      // モノイドに対して二項演算を行う関数オブジェクト
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1){
        sz = 1;
        while(sz < n)   sz <<= 1;
        seg.assign(2 * sz, M1);
    }

    void set(int k, const Monoid &x){
        seg[k + sz] = x;
    }

    void build(){
        for(int k = sz - 1; k > 0; --k){
            seg[k] = f(seg[k << 1], seg[k << 1 | 1]);
        }
    }

    void update(int k, const Monoid &x){
        k += sz;
        seg[k] = x;
        while(k >>= 1){
            seg[k] = f(seg[k << 1], seg[k << 1 | 1]);
        }
    }

    Monoid query(int a, int b){
        Monoid L = M1, R = M1;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1){
            if(a & 1)   L = f(L, seg[a++]);
            if(b & 1)   R = f(seg[--b], R);
        }
        return f(L, R);
    }

    Monoid operator[](const int &k) const{
        return seg[k + sz];
    }
};

vector<vector<ll>> dp(2005, vector<ll>(2005, 1e+15));
ll costw[2005][2005];
ll costb[2005][2005];
// cnt_[k][x] := [0, k) で x 以上が何個あるか
int cntw[4005][2005];
int cntb[4005][2005];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<vector<P>> input(2);
    for(int i = 0; i < n * 2; ++i){
        char c;
        cin >> c;
        int id;
        if(c == 'W')    id = 0;
        else    id = 1;
        int a;
        cin >> a;
        --a;
        input[id].push_back(P(a, i));
    }
    sort(input[0].begin(), input[0].end(), greater<P>());
    sort(input[1].begin(), input[1].end(), greater<P>());

    SegmentTree<int> segw(n * 2, [](int a, int b){return a + b;}, 0);
    SegmentTree<int> segb(n * 2, [](int a, int b){return a + b;}, 0);
    for(int i = 0; i < n; ++i){
        int a = input[0][i].first, id = input[0][i].second;
        segw.update(id, 1);
        int inversion = segw.query(0, id);
        for(int j = 0; j <= n; ++j){
            costw[a][j] += inversion;
        }
        for(int k = 0; k <= n * 2; ++k){
            cntw[k][a] += segw.query(0, k);
        }
    }
    for(int i = 0; i < n; ++i){
        int a = input[1][i].first, id = input[1][i].second;
        segb.update(id, 1);
        int inversion = segb.query(0, id);
        for(int j = 0; j <= n; ++j){
            costb[j][a] += inversion;
        }
        for(int k = 0; k <= n * 2; ++k){
            cntb[k][a] += segb.query(0, k);
        }
    }
    for(int i = 0; i < n; ++i){
        int a = input[0][i].first, id = input[0][i].second;
        for(int j = 0; j < n; ++j){
            costw[a][j] += cntb[id][j];
        }

        a = input[1][i].first, id = input[1][i].second;
        for(int j = 0; j < n; ++j){
            costb[j][a] += cntw[id][j];
        }
    }

    dp[0][0] = 0;
    for(int i = 0; i <= n; ++i){
        for(int j = 0; j <= n; ++j){
            if(i < n)   chmin(dp[i+1][j], dp[i][j] + costw[i][j]);
            if(j < n)   chmin(dp[i][j+1], dp[i][j] + costb[i][j]);
        }
    }
    cout << dp[n][n] << endl;

    // for(int i = 0; i <= n; ++i){
    //     for(int j = 0; j <= n; ++j){
    //         cerr << costw[i][j] << " ";
    //     }
    //     cerr << "\n";
    // }
    // cerr << "\n";
    // for(int i = 0; i <= n; ++i){
    //     for(int j = 0; j <= n; ++j){
    //         cerr << costb[i][j] << " ";
    //     }
    //     cerr << "\n";
    // }
    // cerr << "\n";
    // for(int i = 0; i <= n; ++i){
    //     for(int j = 0; j <= n; ++j){
    //         cerr << dp[i][j] << " ";
    //     }
    //     cerr << "\n";
    // }
}

Measured memory_bytes: 157312