#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;


int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n; cin >> n;
  VI iw(n), ib(n);
  for (int i = 0; i < 2 * n; i++) {
    char c; cin >> c;
    int a; cin >> a;
    a--;
    (c == 'W' ? iw[a] : ib[a]) = i;
  }

  VVI ww(n, VI(n + 1)), wb(n, VI(n + 1)), bw(n, VI(n + 1)), bb(n, VI(n + 1));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      ww[i][j + 1] = ww[i][j] + (iw[i] < iw[j]);
      wb[i][j + 1] = wb[i][j] + (iw[i] < ib[j]);
      bw[i][j + 1] = bw[i][j] + (ib[i] < iw[j]);
      bb[i][j + 1] = bb[i][j] + (ib[i] < ib[j]);
    }
  }

  VVI dp(n + 1, VI(n + 1));
  for (int i = 0; i < n; i++) {
    dp[i + 1][0] = dp[i][0] + ww[i][i];
    dp[0][i + 1] = dp[0][i] + bb[i][i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dp[i + 1][j + 1] = min(dp[i][j + 1] + ww[i][i] + wb[i][j + 1], dp[i + 1][j] + bw[j][i + 1] + bb[j][j]);
    }
  }

  cout << dp[n][n] << '\n';
  return 0;
}