#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))

int N;
vector<int> nums;
vector<int> nums_position;
vector<vector<int>> nums_cumulative_sum_white;
vector<vector<int>> nums_cumulative_sum_black;

int dp[2010][2010];

int choose(int white_back, int black_back){
    if(dp[white_back + 1][black_back + 1] != -1){
        return dp[white_back + 1][black_back + 1];
    }else if(white_back == N - 1 && black_back == N - 1){
        return dp[white_back + 1][black_back + 1] = 0;
    }else if(white_back == N - 1){
        return dp[white_back + 1][black_back + 1] = choose(white_back, black_back + 1) + nums_cumulative_sum_white[nums_position[black_back + N + 1]][white_back + 1] + nums_cumulative_sum_black[nums_position[black_back + N + 1]][black_back + 1];
    }else if(black_back == N - 1){
        return dp[white_back + 1][black_back + 1] = choose(white_back + 1, black_back) + nums_cumulative_sum_white[nums_position[white_back + 1]][white_back + 1] + nums_cumulative_sum_black[nums_position[white_back + 1]][black_back + 1];
    }else{
        return dp[white_back + 1][black_back + 1] = max(choose(white_back, black_back + 1) + nums_cumulative_sum_white[nums_position[black_back + N + 1]][white_back + 1] + nums_cumulative_sum_black[nums_position[black_back + N + 1]][black_back + 1],
                                                        choose(white_back + 1, black_back) + nums_cumulative_sum_white[nums_position[white_back + 1]][white_back + 1] + nums_cumulative_sum_black[nums_position[white_back + 1]][black_back + 1]);
    }
}

int main(){
    cin >> N;
    nums.resize(N * 2);
    nums_position.resize(N * 2);
    for(int i = 0; i < N * 2; i++){
        char color;
        cin >> color >> nums[i];
        nums[i] += (color == 'B') * N - 1;
        nums_position[nums[i]] = i;
    }
    nums_cumulative_sum_white.resize(N * 2, vector<int>(N + 1, 0));
    nums_cumulative_sum_black.resize(N * 2, vector<int>(N + 1, 0));
    for(int i = 0; i < N; i++){
        nums_cumulative_sum_white[0][i + 1] = (nums[0] <= i);
        nums_cumulative_sum_black[0][i + 1] = (N <= nums[0] && nums[0] <= N + i);
        for(int j = 1; j < N * 2; j++){
            nums_cumulative_sum_white[j][i + 1] = nums_cumulative_sum_white[j - 1][i + 1] + (nums[j] <= i);
            nums_cumulative_sum_black[j][i + 1] = nums_cumulative_sum_black[j - 1][i + 1] + (N <= nums[j] && nums[j] <= N + i);
        }
    }
    for(int i = 0; i < N * 2; i++){
        nums_cumulative_sum_white[i][0] = 0;
        nums_cumulative_sum_black[i][0] = 0;
    }
    for(int i = 0; i < 2010; i++){
        for(int j = 0; j < 2010; j++){
            dp[i][j] = -1;
        }
    }
    cout << N * 2 * (N * 2 - 1) / 2 - choose(-1, -1) << endl;
}



Measured memory_bytes: 79232