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

#define int long long
const int INF = 1e9;

signed main() {
  int N;
  cin >> N;

  vector<char> c(2*N);
  vector<int> a(2*N);
  vector<int> wp(N), bp(N);
  for ( int i = 0; i < N*2; i++ ) {
    cin >> c[i] >> a[i];
    a[i]--;
    if ( c[i] == 'W' ) wp[a[i]] = i;
    else bp[a[i]] = i;
  }

  vector<vector<int> >
    ww(N+1, vector<int>(N+1, 0)),
    wb(N+1, vector<int>(N+1, 0)),
    bb(N+1, vector<int>(N+1, 0)),
    bw(N+1, vector<int>(N+1, 0));
  for ( int i = 0; i < N; i++ ) {
    for ( int j = 0; j < N; j++ ) {
      ww[i][j+1] = ww[i][j]+(wp[i]<wp[j]);
      wb[i][j+1] = wb[i][j]+(wp[i]<bp[j]);
      bb[i][j+1] = bb[i][j]+(bp[i]<bp[j]);
      bw[i][j+1] = bw[i][j]+(bp[i]<wp[j]);
    }
}

  vector<vector<int> > dp(N+1, vector<int>(N+1, INF));
  dp[0][0] = 0;
  for ( int i = 0; i < N+1; i++ ) {
    for ( int j = 0; j < N+1; j++ ) {
      if ( i < N ) dp[i+1][j] = min(dp[i+1][j], dp[i][j]+ww[i][i]+wb[i][j]);
      if ( j < N ) dp[i][j+1] = min(dp[i][j+1], dp[i][j]+bb[j][j]+bw[j][i]);
    }
  }

  cout << dp[N][N] << endl;
  
  return 0;
}
