fn main() {
    let n: usize = readln();
    let v: Vec<(String, usize)> = readlns(2 * n);
    let mut index_b: HashMap<usize, usize> = HashMap::new();
    let mut index_w: HashMap<usize, usize> = HashMap::new();

    let L = 63;
    let B = (v.len() + L - 1) / L;
    let mut bucket_b = vec![vec![0; n + 2]; B];
    let mut bucket_w = vec![vec![0; n + 2]; B];
    for (idx, &(ref c, x)) in v.iter().enumerate() {
        let b = idx / L;
        if c == "B" {
            bucket_b[b][x] += 1;
        } else {
            bucket_w[b][x] += 1;
        }
    }
    for i in 0..B {
        for j in (1..n + 1).rev() {
            bucket_b[i][j - 1] += bucket_b[i][j];
            bucket_w[i][j - 1] += bucket_w[i][j];
        }
    }

    for (idx, &(ref c, x)) in v.iter().enumerate() {
        if c == "B" {
            index_b.insert(x, idx);
        } else {
            index_w.insert(x, idx);
        }
    }

    let mut dp = vec![vec![1000000000000i64; n + 2]; n + 2];
    dp[1][1] = 0;

    for b in 1..n + 2 {
        for w in 1..n + 2 {
            if b <= n {
                let idx = index_b[&b];
                // count x >= b or x >= w in v[0, idx]
                let id = idx / L;
                let mut cost = 0;
                for i in 0..id {
                    cost += bucket_b[i][b];
                    cost += bucket_w[i][w];
                }
                let begin = id * L;
                for i in begin..idx {
                    if v[i].0 == "B" && v[i].1 >= b {
                        cost += 1;
                    }
                    if v[i].0 == "W" && v[i].1 >= w {
                        cost += 1;
                    }
                }
                dp[b + 1][w] = min(dp[b + 1][w], dp[b][w] + cost);
            }
            if w <= n {
                let idx = index_w[&w];
                // count x >= b or x > w in v[0, idx]
                let id = idx / L;
                let mut cost = 0;
                for i in 0..id {
                    cost += bucket_b[i][b];
                    cost += bucket_w[i][w];
                }
                let begin = id * L;
                for i in begin..idx {
                    if v[i].0 == "B" && v[i].1 >= b {
                        cost += 1;
                    }
                    if v[i].0 == "W" && v[i].1 >= w {
                        cost += 1;
                    }
                }
                dp[b][w + 1] = min(dp[b][w + 1], dp[b][w] + cost);
            }
        }
    }

    println!("{}", dp[n + 1][n + 1]);
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};

pub trait FromLn {
    fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
    let mut buf = String::new();
    let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
    T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
    let mut vs = vec![];
    for _ in 0..n {
        vs.push(readln());
    }
    vs
}
macro_rules! fromln_primitives {
    ($($t:ty),*) => { $(
        impl FromLn for $t {
            fn fromln(s: &str) -> $t {
                s.parse().unwrap()
            }
        }
    )* }
}
fromln_primitives!(String, bool, f32, f64, isize, i8, i16, i32, i64, usize, u8, u16, u32, u64);
impl<T> FromLn for Vec<T>
where
    T: FromLn,
{
    fn fromln(s: &str) -> Vec<T> {
        s.split_whitespace().map(T::fromln).collect()
    }
}
impl FromLn for Vec<char> {
    fn fromln(s: &str) -> Vec<char> {
        s.chars().collect()
    }
}
macro_rules! fromln_tuple {
    ($($t:ident),*) => {
        impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
            fn fromln(s: &str) -> ($($t),*) {
                let mut it = s.split_whitespace();
                let t = ($($t::fromln(it.next().unwrap())),*);
                assert_eq!(it.next(), None);
                t
            }
        }
    }
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);
fromln_tuple!(A, B, C, D, E);
fromln_tuple!(A, B, C, D, E, F);


Measured memory_bytes: 47356