import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int N;
    scan(N);

    auto w = new int[](N + 1);
    auto b = new int[](N + 1);
    w[] = -1;
    b[] = -1;

    auto sw = new int[][](2*N + 1, N + 1);
    auto sb = new int[][](2*N + 1, N + 1);

    foreach (i ; 0 .. 2*N) {
        char c; int a;
        scan(c, a);

        if (c == 'W') {
            w[a] = i;
            sw[i + 1][a]++;
        }
        else {
            b[a] = i;
            sb[i + 1][a]++;
        }
    }

    foreach (j ; 0 .. N + 1) {
        foreach (i ; 1 .. 2*N + 1) {
            sw[i][j] += sw[i - 1][j];
            sb[i][j] += sb[i - 1][j];
        }
    }
    foreach (i ; 0 .. 2*N + 1) {
        foreach (j ; 1 .. N + 1) {
            sw[i][j] += sw[i][j - 1];
            sb[i][j] += sb[i][j - 1];
        }
    }

    // dp(i, j) = (白の1 ~ i、黒の1 ~ jをソート順にするための最小操作回数)
    auto dp = new int[][](N + 1, N + 1);
    fillAll(dp, inf);
    dp[0][0] = 0;

    foreach (i ; 0 .. N + 1) {
        foreach (j ; 0 .. N + 1) {
            if (i > 0) {
                auto p = w[i];
                p += (i - 1 + j) - sw[p][i - 1] - sb[p][j];
                assert(p >= w[i]);
                chmin(dp[i][j], dp[i - 1][j] + abs(p - (i + j - 1)));
            }
            if (j > 0) {
                auto p = b[j];
                p += (i + j - 1) - sw[p][i] - sb[p][j - 1];
                assert(p >= b[j]);
                chmin(dp[i][j], dp[i][j - 1] + abs(p - (i + j - 1)));
            }
        }
    }

    auto ans = dp[N][N];
    writeln(ans);
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}
