//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

inline ll floor(ll a, ull b)
{
	ll llb = b;
	if (a >= 0)
	{
		return a / llb;
	}
	else
	{
		return - ( (-a + llb - 1) / llb);
	}
}

inline ll ceil(ll a, ull b)
{
	ll llb = b;
	if (a >= 0)
	{
		return (a + llb - 1) / llb;
	}
	else
	{
		return - (-a / llb);
	}
}

inline bool isPower2(ull a)
{
	if (a == 0)
	{
		return false;
	}
	return !(a & (a - 1));
}

inline ll getMaxEffectiveBit(ull a)
{
	ll index = -1;
	for (; a != 0; a >>= 1)
	{
		++index;
	}
	return index;
}

inline ll getSpecifiedBit(ull a, unsigned bit)
{
	return (a & (1LL << bit)) >> bit;
}

// computational complexity: o(log(max(a, b))) 
inline ull getGcd(ull a, ull b)
{
	if (b == 0)
	{
		return a;
	}
	return getGcd(b, a % b);
}

template<class Integer>
inline Integer getPower(Integer base, ull exponential)
{
	Integer result = 1;
	while (exponential >= 1)
	{
		if (exponential & 1)
		{
			result = result * base;
		}
		base = base * base;
		exponential >>= 1;
	}

	return result;
}

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

	ll N;
	cin >> N;

	vector<ll> white_pos(N + 1);
	vector<ll> black_pos(N + 1);
	string color;
	ll number;
	for (ll i = 0; i < N * 2; ++i)
	{
		cin >> color >> number;
		if (color == "W")
		{
			white_pos[number] = i;
		}
		else if (color == "B")
		{
			black_pos[number] = i;
		}
	}

	vector<vector<ll>> white_swap(N, vector<ll>(N + 1, 0));
	for (ll i = 0; i < N; ++i)
	{
		for (ll j = i + 2; j < N + 1; ++j)
		{
			if (white_pos[j] < white_pos[i + 1])
			{
				white_swap[i][N]++;
			}
		}
		for (ll j = N; j > 0; --j)
		{
			white_swap[i][j - 1] = white_swap[i][j];
			if (black_pos[j] < white_pos[i + 1])
			{
				white_swap[i][j - 1]++;
			}
		}
	}

	vector<vector<ll>> black_swap(N + 1, vector<ll>(N, 0));
	for (ll i = 0; i < N; ++i)
	{
		for (ll j = i + 2; j < N + 1; ++j)
		{
			if (black_pos[j] < black_pos[i + 1])
			{
				black_swap[N][i]++;
			}
		}
		for (ll j = N; j > 0; --j)
		{
			black_swap[j - 1][i] = black_swap[j][i];
			if (white_pos[j] < black_pos[i + 1])
			{
				black_swap[j - 1][i]++;
			}
		}
	}

	vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, 1LL << 32));
	dp[0][0] = 0;
	for (ll i = 0; i < N + 1; ++i)
	{
		for (ll j = 0; j < N + 1; ++j)
		{
			if (i > 0)
			{
				dp[i][j] = min(dp[i][j], dp[i - 1][j] + white_swap[i - 1][j]);
			}
			if (j > 0)
			{
				dp[i][j] = min(dp[i][j], dp[i][j - 1] + black_swap[i][j - 1]);
			}
		}
	}

	cout << dp[N][N] << endl; 

	return 0;
}


Measured memory_bytes: 94336