#include <bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 4005;
struct {
    vector<long long> bit = vector<long long>(MAXN+1);

    // return bit[0] + bit[1] + ... + bit[i]
    ll sum(int i) {
      ll s = 0;
      while (i > 0) {
        s += bit.at(i);
        i -= i & -i;
      }
      return s;
    }

    // bit[i] += x
    void add(int i, long long x) {
      while (i <= MAXN) {
        bit.at(i) += x;
        i += i & -i;
      }
    }

    void reset() {
      for(int i=0; i<=MAXN; i++) {
        bit.at(i) = 0;
      }
    }

    // return the smallest i where sum(i) >= val
    // If sum(MAXN) < val, return INT_MAX
    int lower_bound(long long val) {
      int min = 0;
      int max = MAXN;
      if (sum(max) < val) return INT_MAX;
      if (sum(0) >= val) return 0;
      while(min + 1 < max) {
        int now = (min+max)/2;
        if (sum(now) >= val) {
          max = now;
        } else {
          min = now;
        }
      }
      return max;
    }
} W, B;

signed main() {
  SPEED;
  int n; cin >> n;
  vector<vector<int>> dp(2*n+1, vector<int>(n+1, INT_MAX/2));
  dp[0][0] = 0;

  vector<int> w(n), b(n);
  rep(i, 2*n) {
    char c; cin >> c;
    int p; cin >> p;
    p--;
    if (c=='W') {
      w[p] = i;
    } else {
      b[p] = i;
    }
  }

  vector<vector<int>> wmat(n, vector<int>(n+1));
  rep(i, n) {
    int p = w[i];
    rep(j, n) {
      wmat[i][j+1] = wmat[i][j];
      if (p < b[j]) wmat[i][j+1]++;
      //debug(i, j+1, wmat[i][j+1]);
    }
  }
  vector<vector<int>> bmat(n, vector<int>(n+1));
  rep(i, n) {
    int p = b[i];
    rep(j, n) {
      bmat[i][j+1] = bmat[i][j];
      if (p < w[j]) bmat[i][j+1]++;
      //debug(i, j+1, bmat[i][j+1]);
    }
  }
  for(int i=0; i<2*n; i++) {
    for(int j=0; j<=min(i,n); j++) {
      auto cntb = i-j;
      auto cntw = j;
      if (cntb > n) continue;
      //debug(cntb, cntw);
      if (cntb < n) chmin(dp[i+1][j], dp[i][j]+bmat[cntb][cntw]);
      if (cntw < n) chmin(dp[i+1][j+1], dp[i][j]+wmat[cntw][cntb]);
      //debug(i, j, dp[i][j]);
    }
  }
  int ans1 = dp[2*n][n];
  debug(ans1);

  int ans = 0;
  rep(i, n) {
    //debug(i);
    auto p = w[i];
    p++;
    auto cnt = W.sum(p);
    ans += i-cnt;
    W.add(p, 1);

    p = b[i];
    p++;
    cnt = B.sum(p);
    ans += i-cnt;
    B.add(p, 1);
  }
  debug(ans);
  cout << ans+ans1 << endl;
}

Measured memory_bytes: 63232