### BUGGY CODE ###

import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353

def cumsum(it):
    """
    累積和
    :param collections.Iterable it:
    """
    cs = 0
    ret = []
    for v in it:
        cs += v
        ret.append(cs)
    return ret


# 解説
N = int(sys.stdin.buffer.readline())
CA = [sys.stdin.buffer.readline().decode().rstrip().split() for _ in range(N * 2)]
C = []
A = []
for c, a in CA:
    C.append(c)
    A.append(int(a))

pos_w = [IINF] * (N + 1)
pos_b = [IINF] * (N + 1)
for i, (c, a) in enumerate(list(zip(C, A))):
    if c == 'W':
        pos_w[a] = i
    else:
        pos_b[a] = i

# count_b[k][i]: i より左に、k 以下の黒が何個あるか
# count_w[k][i]: i より左に、k 以下の白が何個あるか
bc = [0] * (N * 2 + 1)
wc = [0] * (N * 2 + 1)
count_b = [[0] * (N * 2 + 1)]
count_w = [[0] * (N * 2 + 1)]
for k in range(1, N + 1):
    wc[pos_w[k] + 1] = 1
    bc[pos_b[k] + 1] = 1
    count_b.append(cumsum(bc))
    count_w.append(cumsum(wc))

# dp[b][w]: B を b 回、W を w 回使ったときの転倒数の最小値
dp = [[INF] * (N + 1) for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N * 2):
    b = i
    w = 0
    if b > N:
        w = b - N
        b -= w

    while w <= min(i, N):
        if b < N:
            # b + 1 を使う。
            # 位置の写像が与えられたときのスワップの回数だから転倒数
            # もともといた位置より右にあったやつで、既に使ってるのが何個か
            orig_pos = pos_b[b + 1]
            inv = i - count_b[b + 1][orig_pos] - count_w[w][orig_pos]
            dp[b + 1][w] = min(dp[b + 1][w], dp[b][w] + inv)
        if w < N:
            orig_pos = pos_w[w + 1]
            inv = i - count_b[b][orig_pos] - count_w[w + 1][orig_pos]
            dp[b][w + 1] = min(dp[b][w + 1], dp[b][w] + inv)
        b -= 1
        w += 1
print(dp[N][N])

# import numpy as np
#
# print(np.array(dp))


### FIXED CODE ###

import itertools
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353

def cumsum(it):
    """
    累積和
    :param collections.Iterable it:
    """
    cs = 0
    ret = []
    for v in it:
        cs += v
        ret.append(cs)
    return ret


# 解説
N = int(sys.stdin.buffer.readline())
CA = [sys.stdin.buffer.readline().decode().rstrip().split() for _ in range(N * 2)]
C = []
A = []
for c, a in CA:
    C.append(c)
    A.append(int(a))

pos_w = [IINF] * (N + 1)
pos_b = [IINF] * (N + 1)
for i, (c, a) in enumerate(list(zip(C, A))):
    if c == 'W':
        pos_w[a] = i
    else:
        pos_b[a] = i

# count_b[k][i]: i より左に、k 以下の黒が何個あるか
# count_w[k][i]: i より左に、k 以下の白が何個あるか
bc = [0] * (N * 2 + 1)
wc = [0] * (N * 2 + 1)
count_b = [[0] * (N * 2 + 1)]
count_w = [[0] * (N * 2 + 1)]
for k in range(1, N + 1):
    wc[pos_w[k] + 1] = 1
    bc[pos_b[k] + 1] = 1
    count_b.append(cumsum(bc))
    count_w.append(cumsum(wc))

# dp[b][w]: B を b 回、W を w 回使ったときの転倒数の最小値
dp = [[INF] * (N + 1) for _ in range(N + 1)]
dp[0][0] = 0
# for i in range(N * 2):
#     b = i
#     w = 0
#     if b > N:
#         w = b - N
#         b -= w
#
#     while w <= min(i, N):
#         if b < N:
#             # b + 1 を使う。
#             # 位置の写像が与えられたときのスワップの回数だから転倒数
#             # もともといた位置より右にあったやつで、既に使ってるのが何個か
#             orig_pos = pos_b[b + 1]
#             inv = i - count_b[b + 1][orig_pos] - count_w[w][orig_pos]
#             dp[b + 1][w] = min(dp[b + 1][w], dp[b][w] + inv)
#         if w < N:
#             orig_pos = pos_w[w + 1]
#             inv = i - count_b[b][orig_pos] - count_w[w + 1][orig_pos]
#             dp[b][w + 1] = min(dp[b][w + 1], dp[b][w] + inv)
#         b -= 1
#         w += 1


# もらう
for b, w in itertools.product(range(N + 1), repeat=2):
    if b > 0:
        # 最後に b を使う
        orig_pos = pos_b[b]
        inv = b - count_b[b][orig_pos] + w - count_w[w][orig_pos] - 1
        dp[b][w] = min(dp[b][w], dp[b - 1][w] + inv)
    if w > 0:
        # 最後に w を使う
        orig_pos = pos_w[w]
        inv = b - count_b[b][orig_pos] + w - count_w[w][orig_pos] - 1
        dp[b][w] = min(dp[b][w], dp[b][w - 1] + inv)
print(dp[N][N])

# import numpy as np
#
# print(np.array(dp))