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);
    auto a = new int[](2*n);
    foreach (i ; 0 .. 2*n) {
        scan(c[i], a[i]);
    }

    auto wm = new int[](2*n + 1);
    auto bm = new int[](2*n + 1);

    foreach (i ; 0 .. 2*n) {
        if (c[i] == 'W') {
            wm[i+1] = max(wm[i], a[i]);
            bm[i+1] = bm[i];
        }
        else {
            wm[i+1] = wm[i];
            bm[i+1] = max(bm[i+1], a[i]);
        }
    }

    long ans;

    foreach (i ; 0 .. 2*n) {
        foreach_reverse (j ; 1 .. i+1) {
            if ((c[j] == 'W' && c[j-1] == 'W')
                || (c[j] == 'B' && c[j-1] == 'B')) {
                if (a[j] > a[j-1]) {
                    break;
                }
                else {
                    ans++;
                    swap(a[j], a[j-1]);
                    if (c[j] == 'W') {
                        if (wm[j-1] == a[j]) {
                            wm[j-1] = a[j-1];
                        }
                        wm[j] = a[j-1];
                    }
                    else {
                        if (bm[j-1] == a[j]) {
                            bm[j-1] = a[j-1];
                        }
                        bm[j] = a[j-1];
                    }
                }
            }
            else if (c[j] == 'W' && c[j-1] == 'B') {
                if (wm[j] <= a[j]) {
                    break;
                }
                else {
                    swap(c[j], c[j-1]);
                    swap(a[j], a[j-1]);
                    ans++;
                }
            }
            else if (c[j] == 'B' && c[j-1] == 'W') {
                if (bm[j] <= a[j]) {
                    break;
                }
                else {
                    swap(c[j], c[j-1]);
                    swap(a[j], a[j-1]);
                    ans++;
                }
            }

            debug {
                writefln("%-(%s %)", c);
                writefln("%(%s %)", a);
                writeln("wm:", wm);
                writeln("bm:", bm);
            }
        }
    }

    debug {
        writefln("%-(%s %)", c);
        writefln("%(%s %)", a);
    }

    writeln(ans);
}



























struct UnionFind {
    private {
        int _size;
        int[] _parent;
    }

    this(int N) 
    in {
        assert(N > 0);
    }
    body {
        _size = N;
        _parent = new int[](_size);
        foreach (i ; 0 .. _size) {
            _parent[i] = i;
        }
    }

    int findRoot(int x)
    in {
        assert(0 <= x && x < _size);
    }
    body {
        if (_parent[x] != x) {
            _parent[x] = findRoot(_parent[x]);
        }

        return _parent[x];
    }

    bool same(int x, int y)
    in {
        assert(0 <= x && x < _size);
        assert(0 <= y && y < _size);
    }
    body {
        return findRoot(x) == findRoot(y);
    }

    void merge(int x, int y)
    in {
        assert(0 <= x && x < _size);
        assert(0 <= y && y < _size);
    }
    body {
        int u = findRoot(x);
        int v = findRoot(y);

        if (u == v) return;

        _parent[v] = u;
    }
}



































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);
        }
    }
}
