Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <iomanip>
//#include <cmath>
#include <queue>
#include <deque>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2")
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long double ld;
typedef long long ll;
typedef double db;
#define endl '\n'
#define pb push_back
#define pii pair<ll, ll>
#define ff first
#define ss second
#define sz(x) (ll)(x).size()
#define optimize1() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#pragma warning(disable:4996)

using namespace std;

const int MX = 2e3 + 10;

int fv[4 * MX], n, tm[2][MX], dp[MX][MX];

void upd(int x, int i) {
	i++;
	while (i < 4 * MX) {
		fv[i] += x;
		i += i & (-i);
	}
}


int sum(int i) {
	i++;
	int ans = 0;
	while (i > 0) {
		ans += fv[i];
		i -= i & (-i);
	}
	return ans;
}


signed main() {
	optimize1();
	cin >> n;
	char c;
	int x;
	for (int i = 0; i < 2 * n; ++i) {
		cin >> c >> x;
		int k = 1;
		if (c == 'W')
			k = 0;
		tm[k][x - 1] = i;
	}
	for (int i = 0; i <= n; ++i)
		for (int j = 0; j <= n; ++j)
			dp[i][j] = 1e9 + 10;

	dp[0][0] = 0;
	for (int i = 0; i <= n; ++i) {
		if (i > 0)
			upd(1, tm[0][i - 1]);
		for (int j = 0; j <= n; ++j) {
			if (j > 0)
				upd(1, tm[1][j - 1]);
			if (i != n)
				dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + tm[0][i] - sum(tm[0][i]));
			if (j != n)
				dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + tm[1][j] - sum(tm[1][j]));
		}
		for (int j = 0; j < n; ++j)
			upd(-1, tm[1][j]);
	}
	cout << dp[n][n] << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:65:17: error: reference to 'tm' is ambiguous
   65 |                 tm[k][x - 1] = i;
      |                 ^~
In file included from /usr/include/time.h:39,
                 from /usr/include/pthread.h:23,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr.h:157,
                 from /usr/include/c++/14/ext/atomicity.h:35,
                 from /usr/include/c++/14/bits/ios_base.h:39,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:33:20: note:                 'int tm [2][2010]'
   33 | int fv[4 * MX], n, tm[2][MX], dp[MX][MX];
      |                    ^~
a.cc:74:32: error: reference to 'tm' is ambiguous
   74 |                         upd(1, tm[0][i - 1]);
      |                                ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:33:20: note:                 'int tm [2][2010]'
   33 | int fv[4 * MX], n, tm[2][MX], dp[MX][MX];
      |                    ^~
a.cc:77:40: error: reference to 'tm' is ambiguous
   77 |                                 upd(1, tm[1][j - 1]);
      |                                        ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:33:20: note:                 'int tm [2][2010]'
   33 | int fv[4 * MX], n, tm[2][MX], dp[MX][MX];
      |                    ^~
a.cc:79:77: error: reference to 'tm' is ambiguous
   79 |                                 dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + tm[0][i] - sum(tm[0][i]));
      |                                                                             ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:33:20: note:                 'int tm [2][2010]'
   33 | int fv[4 * MX], n, tm[2][MX], dp[MX][MX];
      |                    ^~
a.cc:79:92: error: reference to 'tm' is ambiguous
   79 |                                 dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + tm[0][i] - sum(tm[0][i]));
      |                                                                                            ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:33:20: note:                 'int tm [2][2010]'
   33 | int fv[4 * MX], n, tm[2][MX], dp[MX][MX];
      |                    ^~
a.cc:81:77: error: reference to 'tm' is ambiguous
   81 |                                 dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + tm[1][j] - sum(tm[1][j]));
      |                                                                             ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:33:20: note:                 'int tm [2][2010]'
   33 | int fv[4 * MX], n, tm[2][MX], dp[MX][MX];
      |                    ^~
a.cc:81:92: error: reference to 'tm' is ambiguous
   81 |                                 dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + tm[1][j] - sum(tm[1][j]));
      |                                                                                            ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:33:20: note:                 'int tm [2][2010]'
   33 | int fv[4 * MX], n, tm[2][MX], dp[MX][MX];
      |                    ^~
a.cc:84:33: error: reference to 'tm' is ambiguous
   84 |                         upd(-1, tm[1][j]);
      |                                 ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:33:20: note:                 'int tm [2][2010]'
   33 | int fv[4 * MX], n, tm[2][MX], dp[MX][MX];
      |                    ^~