Language: C++

//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring> 
using namespace std;
int pre[2005][2005][2];//0white,1black
//pos x color
//before or at pos howmany below or equal to x
int dp[2005][2005]; //whitenum,blacknum
int n;int array[2005];char color[2005];;
int pos[2005][2];
int main()
{
 	//freopen("","r",stdin);
	//freopen("","w",stdout);
	cin>>n;
	for(int i=1;i<=n*2;i++)
	{
		char c;cin>>c;if(c=='W') color[i]=0;else color[i]=1;cin>>array[i];
		pos[array[i]][color[i]]=i;
	}
	 for(int i=1;i<=n*2;i++)
	 {
	 	for(int j=1;j<=n;j++)
	 	{
	 		pre[i][j][0]=pre[i-1][j][0];pre[i][j][1]=pre[i-1][j][1];
	 	}
	 	for(int j=array[i];j<=n;j++)
	 	{
	 		pre[i][j][color[i]]++;
	 	}
	 }
	 
	 for(int i=0;i<2002;i++) for(int j=0;j<2002;j++) dp[i][j]=1e9;
	 dp[0][0]=0;
	 for(int i=1;i<=n*2;i++)
	 {
	 	for(int j=0;j<=n;j++)
	 	{
	 		int x=j,y=i-j;
	 		if(y<0) continue;
	 		
	 		int there=pos[x][0];
	 		int bef=x-1-pre[there][x-1][0]+y-pre[there][y][1];
	 		if(x!=0)dp[x][y]=min(dp[x-1][y]+abs(there+bef-i),dp[x][y]);
	 		if(y==0) continue;
	 		there=pos[y][1];
	 		bef=x-pre[there][x][0]+y-1-pre[there][y-1][1];
	 		dp[x][y]=min(dp[x][y-1]+abs(there+bef-i),dp[x][y]);
	 	}
	 }
	 cout<<dp[n][n];
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:28:74: error: reference to 'array' is ambiguous
   28 |                 char c;cin>>c;if(c=='W') color[i]=0;else color[i]=1;cin>>array[i];
      |                                                                          ^~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:19:11: note:                 'int array [2005]'
   19 | int n;int array[2005];char color[2005];;
      |           ^~~~~
a.cc:29:21: error: reference to 'array' is ambiguous
   29 |                 pos[array[i]][color[i]]=i;
      |                     ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:19:11: note:                 'int array [2005]'
   19 | int n;int array[2005];char color[2005];;
      |           ^~~~~
a.cc:37:27: error: reference to 'array' is ambiguous
   37 |                 for(int j=array[i];j<=n;j++)
      |                           ^~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array'
   99 |     struct array;
      |            ^~~~~
a.cc:19:11: note:                 'int array [2005]'
   19 | int n;int array[2005];char color[2005];;
      |           ^~~~~