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


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

    auto c = new char[](2*n + 1);
    auto a = new int[](2*n + 1);
    c[0] = '#', a[0] = 0;
    foreach (i ; 1 .. 2*n + 1) {
        scan(c[i], a[i]);
    }
    debug {
        writeln(a);
    }
    auto revw = new int[](n + 1);
    auto revb = new int[](n + 1);
    foreach (i ; 1 .. 2*n + 1) {
        if (c[i] == 'W') {
            revw[a[i]] = i;
        }
        else {
            revb[a[i]] = i;
        }
    }

    auto wf = new int[][](2*n + 1, n + 2);
    auto wb = new int[][](2*n + 1, n + 2);
    auto bf = new int[][](2*n + 1, n + 2);
    auto bb = new int[][](2*n + 1, n + 2);

    foreach (i ; 1 .. 2*n + 1) {
        foreach (j ; 1 .. i + 1) {
            if (c[j] == 'W') {
                wf[i][a[j]]++;
            }
            else {
                bf[i][a[j]]++;
            }
        }

        foreach_reverse (j ; 0 .. n + 1) {
            wf[i][j] += wf[i][j+1];
            bf[i][j] += bf[i][j+1];
        }
    }

    foreach (i ; 1 .. 2*n + 1) {
        foreach (j ; i .. 2*n + 1) {
            if (c[j] == 'W') {
                wb[i][a[j]]++;
            }
            else {
                bb[i][a[j]]++;
            }
        }

        foreach (j ; 1 .. n + 2) {
            wb[i][j] += wb[i][j-1];
            bb[i][j] += bb[i][j-1];
        }
    }

    debug {
        writeln("wf:");
        writefln("%(%s\n%)", wf);
        writeln;
        writeln("wb:");
        writefln("%(%s\n%)", wb);
        writeln;
    }

    auto dp = new int[][](n + 1, n + 1);
    fillAll(dp, 1<<30);
    dp[0][0] = 0;

    foreach (i ; 0 .. n + 1) {
        foreach (j ; 0 .. n + 1) {
            if (i + 1 <= n) {
                dp[i+1][j] = min(dp[i+1][j], dp[i][j] + wf[revw[i+1]][i+2] + bf[revw[i+1]][j+1]);
                                                      //+ wb[revw[i+1]][i] + bb[revw[i+1]][max(j-1, 0)]);
            }
            if (j + 1 <= n) {
                dp[i][j+1] = min(dp[i][j+1], dp[i][j] + wf[revb[j+1]][i+1] + bf[revb[j+1]][j+2]);
                                                      //+ wb[revb[j+1]][max(i-1, 0)] + bb[revb[j+1]][j]);
            }
        }
    }

    debug {
        writefln("%(%(%s %)\n%)", dp);
    }

    writeln(dp[n][n]);
}







































void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    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);
        }
    }
}
