#include <bits/stdc++.h>
using namespace std;

#define ris   return *this
#define tmplt template<class T
#define dbgo  debug& operator<<
tmplt > struct rge { T b, e; };
tmplt > rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
~debug(){cerr<<endl;}
tmplt > dbgo(T x){cerr<<boolalpha<<x;ris;}
tmplt, class C > dbgo(pair<T, C> x){ris<<"("<<x.first<<", "<<x.second<<")";}
tmplt > dbgo(rge<T> x){*this<<"[";for(auto it=x.b;it!=x.e;it++){*this<<", "+2*(it==x.b)<<*it;}ris<<"]";}
tmplt > dbgo(vector<T> x){ris<<range(x.begin(),x.end());}
#else
tmplt > dbgo(const T&){ris;}
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define ford(i, n) for(int i = n-1; i >= 0; i--) 

template<typename T> 
void min_self(T& a, T b) { 
    a = min(a, b); 
}
template<typename T>
void max_self(T& a, T b) { 
    a = max(a, b); 
}

const int inf = 1e9 + 5;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<pair<int,int>> arr(2*n);
    for(pair<int,int>& pp : arr) {
        string s;
        int x;
        cin >> s >> x;
        pp.first = s == "W";
        pp.second = x;
    }
    
    vector<vector<int>> initial_pos(2, vector<int>(n+1));
    forn(i, 2*n) {
        int c = arr[i].first;
        int x = arr[i].second;
        initial_pos[c][x] = i+1;
    }
    vector<vector<int>> to_right[2]; // [color][position]
    forn(i, 2) {
        to_right[i].resize(2*n+1);
    }
    
    for(int i = 1; i <= 2*n; i++) {
        for(int j = i; j < 2*n; j++) {
            int c = arr[j].first;
            int x = arr[j].second;
            to_right[c][i].push_back(x);
        }
        forn(j, 2) {
            sort(to_right[j][i].begin(), to_right[j][i].end());
        }
    }
    
    vector<vector<int>> dp(2*n+1, vector<int>(n+1, inf));
    debug() nav(arr);
    #define ub(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
    // [position][num_black_filled_so_far]
    dp[0][0] = 0;
    for(int i = 0; i < 2*n; i++) {
        for(int j = 0; j <= min(n, i); j++) {
            int used_white = i - j;
            if(j < n) {
                int x = j+1;
                int cur_pos = initial_pos[0][x];
                int ip = initial_pos[0][x];
                cur_pos += ub(to_right[0][ip], j);
                cur_pos += ub(to_right[1][ip], used_white);
                min_self(dp[i+1][j+1], dp[i][j] + cur_pos - (i+1));
            }
            int x = used_white + 1;
            if(x > n) continue;
            int cur_pos = initial_pos[1][x];
            int ip = initial_pos[1][x];
            cur_pos += ub(to_right[0][ip], j);
            cur_pos += ub(to_right[1][ip], used_white);
            //$ debug() nav(arr);
            //$ debug() nav(i) nav(j) nav(initial_pos[1][x]) nav(x) nav(cur_pos) nav(used_white);
            //$ debug() nav(ub(to_right[0][i],j)) nav(ub(to_right[1][i], used_white));
            //$ debug() nav(to_right[0][i]);
            
            assert(i < cur_pos);
            min_self(dp[i+1][j], dp[i][j] + cur_pos - (i+1));
            //$ debug();
            //$ debug();
        }
    }
    
    cout << dp[2*n][n] << endl;
}













// Don't worry, you're getting better

// Read statement carefully
// Solve on paper first!
// Make your infinity big enough
// Overflows (long long)

// Author: blondie


Measured memory_bytes: 76160