local mma, mmi = math.max, math.min
local n = io.read("*n", "*l")
local t = {}
local tmap = {}
for i = 1, 2 * n do tmap[i] = 0 end
for i = 1, 2 * n do
  local str = io.read()
  local tp, num = str:match("(%w) (%d+)")
  num = tonumber(num)
  if tp == "B" then num = num + n end
  t[i] = num
  tmap[num] = i
end

local wcnt, bcnt = {}, {}
for i = 1, n do
  wcnt[i] = {}
  bcnt[i] = {}
  local wc, bc = 0, 0
  for j = 1, 2 * n do
    if t[j] <= i then
      wc = wc + 1
    end
    if n < t[j] and t[j] - n <= i then
      bc = bc + 1
    end
    wcnt[i][j] = wc
    bcnt[i][j] = bc
  end
end

local d = {}
for i = 1, n + 1 do
  d[i] = {}
  for j = 1, n + 1 do
    d[i][j] = 1000000007
  end
end
d[1][1] = 0
for j = 1, n do
  d[1][j + 1] = d[1][j] + tmap[j] - wcnt[j][tmap[j]]
end
for i = 1, n do
  d[i + 1][1] = d[i][1] + tmap[n + i] - bcnt[i][tmap[n + i]]
  for j = 1, n do
    local sub1 = wcnt[j][tmap[n + i]]
    local sub2 = bcnt[i][tmap[n + i]]

    local sub3 = wcnt[j][tmap[j]]
    local sub4 = bcnt[i][tmap[j]]
    d[i + 1][j + 1] = mmi(d[i][j + 1] + tmap[n + i] - sub1 - sub2, d[i + 1][j] + tmap[j] - sub3 - sub4)
  end
end
print(d[n + 1][n + 1])
