#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<class T>
class BinaryIndexedTree{
    int n;
    std::vector<T> node;

public:
    BinaryIndexedTree(int n_ = 0, T x = 0){
        init(n_, x);
    }

    BinaryIndexedTree(std::vector<T>& dat){
        build(dat);
    }

    void init(int n_ = 0, T x = 0){
        n = n_;
        node.assign(n + 1, x);

        return;
    }

    void build(std::vector<T>& dat){
        n = (int)dat.size();

        init(n);

        for(int i = 0 ; i < n ; ++i){
            add(i, dat[i]);
        }

        return;
    }

    void add(int i, T x){
        ++i;

        while(i <= n){
            node[i] += x;
            i += i & -i;
        }

        return;
    }

    void update(int i, T x){
        add(i, x - sum(i, i + 1));
    }

    T sum(int r){
        T res = 0;

        while(0 < r){
            res += node[r];
            r -= r & -r;
        }

        return res;
    }

    T sum(int l, int r){
        return sum(r) - sum(l);
    }
};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

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

    int n;
    cin >> n;

    vector<char> c(n << 1);
    vector<int> a(n << 1);
    vector<int> bpos(n);
    vector<int> wpos(n);
    rep(i, n << 1){
        cin >> c[i] >> a[i];
        --a[i];
        if(c[i] == 'B'){
            bpos[a[i]] = i;
        }else{
            wpos[a[i]] = i;
        }
    }

    vector< vector<int> > dp(n + 1, vector<int>(n + 1, IINF));
    dp[0][0] = 0;

    BinaryIndexedTree<int> bbit(n << 1);
    BinaryIndexedTree<int> wbit(n << 1);

    rep(i, n + 1){
        wbit.init(n << 1);
        rep(j, n + 1){
            if(i < n){
                chmin(dp[i + 1][j], dp[i][j] + bbit.sum(bpos[i], n << 1) + wbit.sum(bpos[i], n << 1) + bpos[i] - (i + j));
            }
            if(j < n){
                chmin(dp[i][j + 1], dp[i][j] + bbit.sum(wpos[j], n << 1) + wbit.sum(wpos[j], n << 1) + wpos[j] - (i + j));
            }
            wbit.add(wpos[j], 1);
        }
        bbit.add(bpos[i], 1);
    }

    cout << dp[n][n] << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 16000