Language: C++

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
char c[2010];
int a[2010];

// 1 base
template<typename T, int max_n>
class BIT {
private:
    T bit[max_n + 1];
    int n;
public:
    BIT(int _n = max_n) {
        n = _n;
        memset(bit, 0, sizeof(bit));
    }
    // [1, i]
    T sum(int i) {
        T s = 0;
        while (i > 0) {
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    // [a, b]
    T sum(int a, int b) {
        return sum(b) - sum(a-1);
    }

    void add(int i, T x) {
        while (i <= n) {
            bit[i] += x;
            i += i & -i;
        }
    }

    int lower_bound(T x) {
        int lb = 0, ub = n;
        while (ub - lb > 1) {
            int mid = (ub + lb) / 2;
            T v = sum(mid);
            if (v < x) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        return ub;
    }

    int upper_bound(T x) {
        int lb = 1, ub = n+1;
        while (ub - lb > 1) {
            int mid = (ub + lb) / 2;
            T v = sum(mid);
            if (v <= x) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        return ub;
    }
};

int solve() {
    BIT<int, 4010> bit(2*n+10);
    int s0 = 1, s1 = 1;
    int p[2][n+1];
    for (int i = 0; i < 2*n; i++) {
        if (c[i] == 'B') {
            p[0][a[i]] = i+1;
        } else {
            p[1][a[i]] = i+1;
        }
    }

    int res = 0;
    while (s0 <= n || s1 <= n) {
        int v0 = (s0 <= n ? p[0][s0]-bit.sum(p[0][s0])-1 : inf);
        int v1 = (s1 <= n ? p[1][s1]-bit.sum(p[1][s1])-1 : inf);
        if (v0 < v1) {
            res += v0;
            bit.add(u0, 1);
            s0++;
        } else {
            res += v1;
            bit.add(u1, 1);
            s1++;
        }
    }
    return res;
}

void input() {
    cin >> n;
    for (int i = 0; i < 2*n; i++) cin >> c[i] >> a[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Compiler output:
a.cc: In function 'int solve()':
a.cc:130:21: error: 'u0' was not declared in this scope; did you mean 'v0'?
  130 |             bit.add(u0, 1);
      |                     ^~
      |                     v0
a.cc:134:21: error: 'u1' was not declared in this scope; did you mean 'v1'?
  134 |             bit.add(u1, 1);
      |                     ^~
      |                     v1