criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include <bits/stdc++.h>

using namespace std;

#define inf 1<<30
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> P;
struct UnionFind{
	vector<int> par, rank;

	UnionFind(){};
	UnionFind(int n){
		par.resize(n), rank.resize(n);
		for(int i = 0; i < n; i++)
			par[i] = i, rank[i] = 0;
	};
	int find(int n){
		if(par[n] == n) return n;
		return par[n] = find(par[n]);
	};
	bool isSame(int a, int b){
		return find(a) == find(b);
	};
	void marge(int a, int b){
		a = find(a);
		b = find(b);
		if(a == b) return;
		if(rank[x] < rank[y]) swap(x,y);
		if(rank[x] == rank[y]) rank[x]++;
		par[y] = x;
		return;
	};
};

int N, M;
int id[100001] = {};
UnionFind uf;

int main(){
	cin >> N >> M;
	uf = UnionFind(N+1);
	int in;
	for(int i = 1; i <= N; i++){
		cin >> in;
		id[in] = i;
	}
	int a, b;
	for(int i = 0; i < M; i++){
		cin >> a >> b;
		uf.marge(a,b);
	}
	int cnt = 0;
	for(int i = 1; i <= N; i++)
		if(uf.isSame(i, id[i]))
			cnt++;

	cout << cnt << endl;

	return 0;
}

Compiler output:
a.cc: In member function 'void UnionFind::marge(int, int)':
a.cc:33:25: error: 'x' was not declared in this scope
   33 |                 if(rank[x] < rank[y]) swap(x,y);
      |                         ^
a.cc:33:35: error: 'y' was not declared in this scope; did you mean 'yn'?
   33 |                 if(rank[x] < rank[y]) swap(x,y);
      |                                   ^
      |                                   yn
a.cc:34:25: error: 'x' was not declared in this scope
   34 |                 if(rank[x] == rank[y]) rank[x]++;
      |                         ^
a.cc:34:36: error: 'y' was not declared in this scope; did you mean 'yn'?
   34 |                 if(rank[x] == rank[y]) rank[x]++;
      |                                    ^
      |                                    yn
a.cc:35:21: error: 'y' was not declared in this scope; did you mean 'yn'?
   35 |                 par[y] = x;
      |                     ^
      |                     yn
a.cc:35:26: error: 'x' was not declared in this scope
   35 |                 par[y] = x;
      |                          ^
Language: C++

#include <bits/stdc++.h>

using namespace std;

#define inf 1<<30
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> P;
struct UnionFind{
	int par[100001];

	UnionFind(){};
	UnionFind(int n){
		for(int i = 0; i <= n; i++)
			par[i] = i;
	};
	int find(int n){
		if(par[n] == n) return n;
		return par[n] = find(par[n]);
	};
	bool isSame(int a, int b){
		return find(a) == find(b);
	};
	void marge(int a, int b){
		a = find(a);
		b = find(b);
		if(a == b) return;
		else if(a < b)
			par[b] = a;
		else
			par[a] = b;
		return;
	};
};

int N, M;
int index[100001] = {};
UnionFind uf(100001);

int main(){
	cin >> N >> M;
	int in;
	for(int i = 1; i <= N; i++){
		cin >> in;
		index[in] = i;
	}
	int a, b;
	for(int i = 0; i < M; i++){
		cin >> a >> b;
		uf.marge(a,b);
	}
	int cnt = 0;
	for(int i = 1; i <= N; i++)
		if(uf.isSame(i, index[i]))
			cnt++;

	cout << cnt << endl;

	return 0;
}

Compiler output:
a.cc:41:17: error: 'int index [100001]' redeclared as different kind of entity
   41 | int index[100001] = {};
      |                 ^
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/14/cstring:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:121,
                 from a.cc:1:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'int main()':
a.cc:49:22: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   49 |                 index[in] = i;
      |                      ^
a.cc:58:38: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   58 |                 if(uf.isSame(i, index[i]))
      |                                      ^
Language: C++

/*
  AtCoder Regular Contest 097
  D - Equals
*/

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

class DisjointSet {
public:
  DisjointSet(int size): size(size) {
    id.resize(size, -1);
  }

  void unite(int x, int y) {
    x = getId(x);
    y = getId(y);

    if (x != y) {
      if (id[x] > id[y]) swap(x,y);
      id[x] += id[y];
      id[y] = x;
      --size;
    }
  }

  int getId(int x) {
    return id[x] < 0 ? x : id[x] = getId(id[x]);
  }

  void show() {
    printf("\n");
    REP(i,id.size()) printf("%d ", id[i]);
    printf("\n");
  }

private:
  vector<int> id;
  int size;
};

int N, M;
int p[100000];

int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &p[i]);
    --p[i];
  }

  DisjointSet ds(N);
  int x, y;
  for (int i = 0; i < M; ++i) {
    scanf("%d%d", &x, &y);
    --x, --y;
    ds.unite(x,y);
    //ds.show();
  }

  int count = 0;
  for (int i = 0; i < N; ++i) if (ds.getId(i) == ds.getId(p[i])) ++count;

  printf("%d\n", count);
  return 0;
}

Compiler output:
a.cc: In member function 'void DisjointSet::show()':
a.cc:35:9: error: 'i' was not declared in this scope; did you mean 'id'?
   35 |     REP(i,id.size()) printf("%d ", id[i]);
      |         ^
      |         id
a.cc:35:5: error: 'REP' was not declared in this scope
   35 |     REP(i,id.size()) printf("%d ", id[i]);
      |     ^~~
Language: C++

#include <iostream>
#include <cstdio>
using namespace std;
const int maxn=50005;
int p[maxn];
int n,m;
int an[maxn][maxn];
int ans;
int x,y;
int a[maxn];
int find(int k){
	if(k!=p[k]) p[k]=find(p[k]);
	return p[k];
}

void Union(int x,int y){
	int a=find(x);
	int b=find(y);
	if(a!=b) p[a]=b;
}

int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++) p[i]=i;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=m;i++){
		cin>>x>>y;
		Union(x,y);
	}
	
	for(int i=1;i<=n;i++) p[a[i]]=find(a[i]);
	
	for(int i=1;i<=n;i++){
		an[p[a[i]]][0]++;
		an[p[a[i]]][an[p[a[i]]][0]]=1;
	}
	
	//for(int i=1;i<=n;i++) if(an[p[a[i]]][0]!=0) cout<<i<<' '<<p[a[i]]<<' '<<an[p[a[i]]][0]<<endl;
	
	
	for(int i=1;i<=n;i++){
		if(an[p[a[i]]][0]>1 && an[p[a[i]]][i]==1) ans++;
	}
		
	cout<<ans<<endl;
	
	return 0;
}

Compiler output:
/tmp/cc5nSF4v.o: in function `main':
a.cc:(.text+0x145): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/cc5nSF4v.o
a.cc:(.text+0x179): relocation truncated to fit: R_X86_64_PC32 against symbol `x' defined in .bss section in /tmp/cc5nSF4v.o
a.cc:(.text+0x195): relocation truncated to fit: R_X86_64_PC32 against symbol `y' defined in .bss section in /tmp/cc5nSF4v.o
a.cc:(.text+0x1a6): relocation truncated to fit: R_X86_64_PC32 against symbol `y' defined in .bss section in /tmp/cc5nSF4v.o
a.cc:(.text+0x1ac): relocation truncated to fit: R_X86_64_PC32 against symbol `x' defined in .bss section in /tmp/cc5nSF4v.o
a.cc:(.text+0x1e1): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/cc5nSF4v.o
a.cc:(.text+0x1f9): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/cc5nSF4v.o
a.cc:(.text+0x247): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/cc5nSF4v.o
a.cc:(.text+0x29c): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/cc5nSF4v.o
a.cc:(.text+0x2c7): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/cc5nSF4v.o
a.cc:(.text+0x349): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

using namespace std;

int main(){

	int n,m;
	vector<int> p;
	map<int,vector<int>> xy;
	map<int,set<int>> z;
	char flag[100010];

	for(int i=0;i<100010;i++){
		flag[i]=0;
	}

	cin>>n>>m;
	for(int i=0;i<n;i++){
		int tmp;
		cin>>tmp;
		p.push_back(tmp-1);
	}
	for(int i=0;i<m;i++){
		int tmpX,tmpY;
		cin>>tmpX>>tmpY;
		xy[tmpX-1].push_back(tmpY-1);
		xy[tmpY-1].push_back(tmpX-1);
	}

	/*学習実施、どことどこが繋がってるのか？*/
	
	int ans=0;
	for(int i=0;i<n;i++){
		if(flag[i]==1)continue;
		queue<int> q;
		q.push(i);
		set<int> touch;
		touch.insert(i);
		flag[i]=1;
		while(q.size()!=0){
			int now = q.front();
			q.pop();
			if(xy[now].size()==0)continue;
			int size = xy[now].size();
			for(int j=0;j<size;j++){
				int next = xy[now].at(j);
				if(flag[next]==0){
					touch.insert(next);
					flag[next]=1;
					q.push(next);
				}
			}
		}
		/*
		for(int j=0;j<n;j++){
			int targetPos = p[j];
			if(touch.count(targetPos)==1){
				ans++;
			}
		}
		*/
		for(auto itr = touch.begin(); itr != touch.end(); itr++){
			for(auto itr2 = itr; itr2 != touch.end() ;itr2++){
				z[*itr].insert(*itr2);
				z[*itr2].insert(*itr);
			}
		}
	}


	/*学習結果について表示してみる。*/
	
	/*
	for(int i=0;i<n;i++){
		cout<<"i="<<i<<" next = ";
		for(auto itr = xy[i].begin(); itr != xy[i].end();itr++){
			cout<<*itr<<" ";
		}
		cout<<endl;
	}
	*/
	

	int ans=0;
	for(int i=0;i<n;i++){
		int targetPos = p[i];
		if(z[i].count(targetPos)==1){
			ans++;
		}
	}

	cout<<ans<<endl;
	return 0;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:89:13: error: redeclaration of 'int ans'
   89 |         int ans=0;
      |             ^~~
a.cc:37:13: note: 'int ans' previously declared here
   37 |         int ans=0;
      |             ^~~
Language: C++

#include<bits/stdc++.h>

using namespace std;

const int maxn=4e5+10;
int n,m,ans,g[maxn],head[maxn],cnt,vis[maxn],vi[maxn];

struct ed{
	int next,to;
}e[maxn];

void add(int u,int v){
	e[++cnt]=(ed){head[u],v};head[u]=cnt;
	e[++cnt]=(ed){head[v],u};head[v]=cnt;
}

void dfs(int now,int col){
	vis[now]=col;
	for(int i=head[now];i;i=e[i].next){
		int tt=e[i].to;
		if(!vis[tt]) dfs(tt,col);
	}
}	

void dfs2(int now,int col){
	vi[now]=1;
	if(g[now]>0&&vis[g[now]]==col)ans++;
	for(int i=head[now];i;i=e[i].next){
		int tt=e[i].to;
		if(!vi[tt]&&vis[tt]==col) dfs2(tt,col,now);
	}
}

int main(){
	scanf("%d%d",&n,&m);int u,v;
	for(int i=1;i<=n;i++) scanf("%d",&g[i]);
	for(int i=1;i<=m;i++) scanf("%d%d",&u,&v),add(u,v);
	for(int i=1;i<=n;i++) if(!vis[i]) dfs(i,i),dfs2(i,i,0);
	printf("%d",ans);
	return 0;
}

Compiler output:
a.cc: In function 'void dfs2(int, int)':
a.cc:30:47: error: too many arguments to function 'void dfs2(int, int)'
   30 |                 if(!vi[tt]&&vis[tt]==col) dfs2(tt,col,now);
      |                                           ~~~~^~~~~~~~~~~~
a.cc:25:6: note: declared here
   25 | void dfs2(int now,int col){
      |      ^~~~
a.cc: In function 'int main()':
a.cc:38:56: error: too many arguments to function 'void dfs2(int, int)'
   38 |         for(int i=1;i<=n;i++) if(!vis[i]) dfs(i,i),dfs2(i,i,0);
      |                                                    ~~~~^~~~~~~
a.cc:25:6: note: declared here
   25 | void dfs2(int now,int col){
      |      ^~~~
Language: C++

#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define e cout<<endl;
#define pe(x) cout<<x<<" ";
#define re(i,a,b) for(i=a;i<=b;i++)
 
ll i,j,k,l,ii,jj;
ll n,m;
ll p[200005],q[200005],ran[200005];
ll h,w,x,y,ans=0,sum;
ll ite;



ll find(ll x){
	if(p[x]==x){
		return x;
	}else{
		return p[x] = find(p[x]);
	}
}

void unite(ll x,ll y){
	x = find(x);
	y = find(y);
	if(x==y)return;
	if(ran[x]<ran[y]){
		p[x]=y;
	}else{
		p[y]=x;
		if(ran[x]==ran[y])ran[x]++;
	}
}


Compiler output:
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
collect2: error: ld returned 1 exit status
Language: C++

n,m = map(int,input().split())
p = list(map(int, input().split()))
g = [[] for _ in range(0,n+1)]
visit = [None] * (n+1)
ans = 0
for _ in range(0,m):
    x,y = map(int, input().split())
    g[x].append(y)
    g[y].append(x)
for i in range(1,n+1):
    if visit[i] is not None:
        continue
    stack = [i]
    part = [i]
    visit[i] = 0
    while len(stack) > 0:
        q = stack.pop()
        for qq in g[q]:
            if visit[qq] is None:
                visit[qq] = 0
                part.append(qq)
                stack.append(qq)
    part2 = set()
    for i in part:
        part2.add(p[i-1])
    for i in part:
        if i in part2:
            ans += 1
print(ans)

Compiler output:
a.cc:1:1: error: 'n' does not name a type
    1 | n,m = map(int,input().split())
      | ^
Language: C++

#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <cmath>
using namespace std;
typedef long long ll;

int main( int argc, char* argv[] ){
  int N,M;
  cin >> N >> M;
  vector<int> P(N);
  for( int i=0; i<N; ++i ){
    cin >> P[i];
  }
  vector<int> X(M), Y(M);
  for( int i=0; i<M; ++i ){
    cin >> X[i] >> Y[i];
  }
  
  list< set<int> > T;
  for( int i=0; i<M; ++i ){
    int x=X[i], y=Y[i];
    int x_idx=-1, y_idx=-2;
    auto x_it = T.end(), y_it = T.end();
    for( auto it=T.begin(); it!=T.end(); ++it ){
      if( it->count(x)>0 ) x_it = it;
      if( it->count(y)>0 ) y_it = it;
      if( x_it != T.end() && x_it == y_it ) break;
    }
    if( x_it != T.end() && x_it == y_it ) continue;
    if( x_it == T.end() && y_it == T.end() ){
      T.push_back( set<int>({x,y}) );
      continue;
    }
    if( x_it != T.end() && y_it == T.end() ){
      x_it->insert(y);
      continue;
    }
    if( x_it == T.end() && y_it != T.end() ){
      y_it->insert(x);
      continue;
    }
    // x_it != T.end() && y_it != T.end()
    if( x_it->size() >= y_it->size() ){
      for( auto z : *y_it ) x_it->insert(z);
      T.erase(y_it);
    } else {
      for( auto z : *x_it ) y_it->insert(z);
      T.erase(x_it);
    }
  }

  for( auto& v : T ){
    for( auto x : v ) cerr << " " << x;
    cerr << " : ";
    for( auto x : v ) cerr << " " << P[x-1];
    cerr << endl;
  }

  int c = 0;
  vector<int> used;
  for( auto& v : T ){
    for( auto x : v ){
      used.push_back(x);
      if( v.count(P[x-1]) ){
        c++;
      }
    }
  }
  sort(used.begin(),used.end());
  auto it = used.begin();
  for( int i=1; i<=N; ++i ){
    do{
      if( *it == i )
    } while( *it <= i );
    if( used.count(i) ) continue;
    if( P[i-1]==i ) c++;
  }
  cout << c << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main(int, char**)':
a.cc:80:5: error: expected primary-expression before '}' token
   80 |     } while( *it <= i );
      |     ^
a.cc:81:14: error: 'class std::vector<int>' has no member named 'count'
   81 |     if( used.count(i) ) continue;
      |              ^~~~~
Language: C++

#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>

using namespace std;


template<typename T>
class UnionFind {
public:
    UnionFind(size_t  size) : data_(size, -1) {}

    bool unite(T x, T y) {
        x = root(x);
        y = root(y);

        if (x != y) {
            if (data_[y] < data_[x]) {
                std::swap(x, y);
            }
            data_[x] += data_[y];
            data_[y] = x;
        }
        return x != y;
    }

    bool isSame(T x, T y) {
        return root(x) == root(y);
    }

    T root(T x) {
        return data_[x] < 0 ? x : data_[x] = root(data_[x]);
    }

    // --
    size_t size(T x) {
        return -data_[root(x)];
    }

private:
    std::vector<T> data_;
};


int main()
{
    int64_t N, M;
    std::cin >> N >> M;

    std::vector<int64_t> P;

    for (size_t i = 0; i < N; ++i) {
        int t;
        std::cin >> t;
        t--;
        P.push_back(t);
    }

    UnionFind<int64_t> uf(N);

    for (size_t i = 0; i < M; ++i) {
        int64_t from, to;
        std::cin >> from >> to;
        from--;
        to--;
        uf.unite(from, to);
    }

    int64_t count = 0;

    for (int64_t i = 0; i < N; ++i) {
        if (uf.find(i, P[i])) {
            count++;
        }
    }

    std::cout << count << std::endl;

    return 0;
}


Compiler output:
a.cc:22:10: fatal error: boost/lexical_cast.hpp: No such file or directory
   22 | #include <boost/lexical_cast.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
//#define int long long
#define re(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin,v.end()
using namespace std;
typedef pair<int,int>P;
struct UnionFind{
  int n;
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};
 
int dx[]={0,0,-1,1};
int dy[]={1,-1,0,0};
int n,m;
vector<P>v[100090];
int ans,x,y;
int h[100999];
signed main(){
  cin>>n>>m;
  int a[n];
  UnionFind U(n+10);
  re(i,n)cin>>a[i],a[i]--,h[a[i]]=i;
  re(i,m){
    cin>>x>>y;
    x--;y--;
    U.unite(x,y);
  }
  re(i,n)if(U.sama(i,h[i]))ans++;
  cout<<ans<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:43:15: error: 'struct UnionFind' has no member named 'sama'; did you mean 'same'?
   43 |   re(i,n)if(U.sama(i,h[i]))ans++;
      |               ^~~~
      |               same
Language: C++

#include <bits/stdc++.h>
//#define int long long
#define re(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin,v.end()
using namespace std;
typedef pair<int,int>P;
struct UnionFind{
  int n;
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};
 
int dx[]={0,0,-1,1};
int dy[]={1,-1,0,0};
int n,m;
vector<P>v[100090];
int ans,x,y;
int h[100999]
signed main(){
  cin>>n>>m;
  int a[n];
  UnionFind U(n+10);
  re(i,n)cin>>a[i],a[i]--,h[a[i]]=i;
  re(i,m){
    cin>>x>>y;
    x--;y--;
    U.unite(x,y);
  }
  re(i,n)if(U.sama(i,h[i]))ans++;
  cout<<ans<<endl;
}

Compiler output:
a.cc:33:1: error: expected initializer before 'signed'
   33 | signed main(){
      | ^~~~~~
Language: C++

#include <cstdio>
using namespace std;
const int maxn=100000+10;
int fa[maxn];
int p[maxn];
int n,m,x,y,ans;
int father(int p)
{
	if (fa[p]==p) return p;
	else return fa[p]=father(fa[p]);
}
int main()
{
    cin>>n>>m;
	for(int i=1;i<=n;i++) scanf("%d",&p[i]),fa[i]=i;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&x,&y);
		x=father(x);y=father(y);
		fa[x]=y;
	}	
	ans=0;
	for(int i=1;i<=n;i++)
		if (father(p[i])==father(i))
			ans++;
	cout<<ans<<endl;
	system ("pause");
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:5: error: 'cin' was not declared in this scope
   14 |     cin>>n>>m;
      |     ^~~
a.cc:2:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    1 | #include <cstdio>
  +++ |+#include <iostream>
    2 | using namespace std;
a.cc:26:9: error: 'cout' was not declared in this scope
   26 |         cout<<ans<<endl;
      |         ^~~~
a.cc:26:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:26:20: error: 'endl' was not declared in this scope
   26 |         cout<<ans<<endl;
      |                    ^~~~
a.cc:2:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    1 | #include <cstdio>
  +++ |+#include <ostream>
    2 | using namespace std;
a.cc:27:9: error: 'system' was not declared in this scope
   27 |         system ("pause");
      |         ^~~~~~
Language: C++

#include <cstdio>
#include <iostream>
#include <cstring>
#include <math.h>
#include <bits/stdc++.h>
using namespace std;

int a[10002];
int father[10002];

int findx(int a){
	if(father[a]==a) return a;
	return father[a]=find(father[a]);
} 

void conbine(int x,int y)
{
    int xi = findx(x);
    int yi = findx(y);
    if(xi!=yi)
    {
        father[yi] = xi;
    }
}
int main()
{
    int n,c,b,m;
    scanf("%d%d",&n,&m);
    for(int i = 0 ; i < n ;i++)
    {
        scanf("%d",&a[i]);
        father[i+1] = i+1;
    }
    for(int i = 0 ; i < m ;i++)
    {
        scanf("%d%d",&c,&b);
        conbine(c,b);
    }
    int sum = 0;
    for(int i = 0 ; i < n;i++)
    {
        if(a[i] == (i+1))
        {
            sum++;
            continue;
        }
        if(findx(a[i]) == findx(i+1))
        {
            sum++;
        }
    }
    printf("%d\n",sum);
    return 0;
}


Compiler output:
a.cc: In function 'int findx(int)':
a.cc:13:30: error: no matching function for call to 'find(int&)'
   13 |         return father[a]=find(father[a]);
      |                          ~~~~^~~~~~~~~~~
In file included from /usr/include/c++/14/bits/locale_facets.h:48,
                 from /usr/include/c++/14/bits/basic_ios.h:37,
                 from /usr/include/c++/14/ios:46,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:5:
/usr/include/c++/14/bits/stl_algo.h:3842:5: note: candidate: 'template<class _IIter, class _Tp> _IIter std::find(_IIter, _IIter, const _Tp&)'
 3842 |     find(_InputIterator __first, _InputIterator __last,
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:3842:5: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::find(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
   60 | find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note:   candidate expects 4 arguments, 1 provided
Language: C++


//D
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807

int N,M;
vector<int> p;
vector<int> reach[100005];

bool solve(int a, int now, int goal){
    for(int i=0; i<reach[now].size(); i++){
        if(count(reach[a].begin(), reach[a].end(), reach[now][i]) == 0){
            reach[a].push_back(reach[now][i]);
            if(reach[now][i] == goal) return true;
            solve(a, reach[now][i]);
        }
    }
    return false;
}

int main(){
    cin >> N >> M;
    
    for(int i=0; i<N; i++){
        int tmp;
        cin >> tmp;
        p.push_back(tmp);
    }

    for(int i=0; i<M; i++){
        int a,b;
        cin >> a >> b;
        reach[a].push_back(b);
        reach[b].push_back(a);
    }

    /*for(int i=1; i<=N; i++){
        for(int j=0; j<reach[i].size(); j++){
            if(i == reach[i][j]) continue;
            solve(i,reach[i][j]);
        }
    }*/

    /*for(int i=1; i<=N; i++){
        for(int j=0; j<reach[i].size(); j++){
            cout << i << " " << j << endl;
        }
    }*/

    int ans = 0;
    for(int i=0; i<N; i++){
        if(i+1 == p[i]) ans++;
        else{
            for(int j=0; j<reach[i+1].size(); j++){
                if(i+1 == reach[i+1][j]) continue;
                if(solve(i+1, reach[i+1][j], p[i])){
                    ans++;
                    continue;
                }
            }
        }
    }

    cout << ans << endl;
    
    return 0;
}


Compiler output:
a.cc: In function 'bool solve(int, int, int)':
a.cc:22:18: error: too few arguments to function 'bool solve(int, int, int)'
   22 |             solve(a, reach[now][i]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~
a.cc:17:6: note: declared here
   17 | bool solve(int a, int now, int goal){
      |      ^~~~~
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <set>
#include <atltime.h>
using namespace std;

void swapCheck(int node, vector<vector<int>> &swapper, vector<bool> &checking) {
	if (checking[node]) {
		return;
	}
	checking[node] = true;
	for (int i = 0; i < swapper[node].size(); i++) {
		swapCheck(swapper[node][i], swapper, checking);
	}
}

int main(void) {
	int N, M;
	scanf("%d %d", &N, &M);

	vector<int> p = vector<int>(N, 0);
	int buf;
	for (int i = 0; i < N; i++) {
		scanf("%d", &buf);
		p[i] = buf - 1;
	}

	auto swapper = vector<vector<int>>(N, vector<int>());
	int x, y;
	for (int m = 0; m < M; m++) {
		scanf("%d %d", &x, &y);
		swapper[x - 1].push_back(y - 1);
		swapper[y - 1].push_back(x - 1);
	}

	auto enable = vector<bool>(N, false);
	auto checked = vector<bool>(N, false);
	for (int i = 0; i < N; i++) {
		if (checked[i]) {
			continue;
		}
		if (swapper[i].size() == 0) {
			checked[i] = true;
			if (i == p[i]) {
				enable[i] = true;
			}
			break;
		}
		auto checking = vector<bool>(N, false);
		swapCheck(i, swapper, checking);
		for (int nd = 0; nd < N; nd++) {
			if (checking[nd] == false)continue;
			checked[nd] = true;
			if (checking[p[nd]]) {
				enable[nd] = true;
			}
		}
		checked[i] = true;
	}

	int count = 0;
	for (auto en : enable) {
		if (en)count++;
	}
	cout << count << endl;
	return 0;
}

Compiler output:
a.cc:7:10: fatal error: atltime.h: No such file or directory
    7 | #include <atltime.h>
      |          ^~~~~~~~~~~
compilation terminated.
Language: C++

#include<bits/stdc++.h>
using namespace std;
vector<int>v[100003];
bool vis[100003];
int n,m,ans,x,y,js,p[100003];
int find(int i)
{
	int res=100000003;
	if(i==js)
		return 0;
	for(int j=0;j<v[i].size();j++)
		if(!vis[v[i][j])
		{
			vis[v[i][j]]=true;
			res=min(res,1+find(v[i][j]));
			vis[v[i][j]]=false;
		}
	return res;
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>p[i];
		p[i]--;
	}
	for(int i=0;i<m;i++)
	{
		cin>>x>>y;
		x--,y--;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	for(int i=0;i<n;i++)if(find(p[i])!=100000003)ans+=find(p[i]),js++;
	cout<<ans;
}


Compiler output:
a.cc: In function 'int find(int)':
a.cc:12:32: error: expected ']' before ')' token
   12 |                 if(!vis[v[i][j])
      |                                ^
      |                                ]
Language: C++

#include<bits/stdc++.h>
using namespace std;
vector<int>v[100003];
bool vis[100003];
int n,m,ans,x,y,js,p[100003];
int find(int i)
{
	int res=1000000003;
	if(i==js)
		return 0;
	for(int j=0;j<v[i].size();j++)
		if(!vis[v[i][j])
		{
			vis[v[i][j]]=true;
			res=min(res,1+find(v[i][j]);
			vis[v[i][j]]=false;
		}
	return res;
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>p[i],p[i]--;
	for(int i=0;i<m;i++)
	{
		cin>>x>>y;
		x--,y--;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	for(int i=0;i<n;i++)if(find(p[i])!=1000000003)ans+=find(p[i]),js++;
	cout<<ans;
}


Compiler output:
a.cc: In function 'int find(int)':
a.cc:12:32: error: expected ']' before ')' token
   12 |                 if(!vis[v[i][j])
      |                                ^
      |                                ]
a.cc:15:52: error: expected ')' before ';' token
   15 |                         res=min(res,1+find(v[i][j]);
      |                                ~                   ^
      |                                                    )
Language: C++

#include<bits/stdc++.h>
using namespace std;
vector<int>v[100003];
bool vis[100003];
int n,m,ans,x,y,js;
int find(int i)
{
	int res=1000000003;
	if(i==js)
		return 0;
	for(int j=0;j<v[i].size();j++)
		if(!vis[v[i][j])
		{
			vis[v[i][j]]=true;
			res=min(res,1+find(v[i][j]);
			vis[v[i][j]]=false;
		}
	return res;
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>p[i],p[i]--;
	for(int i=0;i<m;i++)
	{
		cin>>x>>y;
		x--,y--;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	for(int i=0;i<n;i++)if(find(p[i])!=1000000003)ans+=find(p[i]),js++;
}


Compiler output:
a.cc: In function 'int find(int)':
a.cc:12:32: error: expected ']' before ')' token
   12 |                 if(!vis[v[i][j])
      |                                ^
      |                                ]
a.cc:15:52: error: expected ')' before ';' token
   15 |                         res=min(res,1+find(v[i][j]);
      |                                ~                   ^
      |                                                    )
a.cc: In function 'int main()':
a.cc:23:34: error: 'p' was not declared in this scope
   23 |         for(int i=0;i<n;i++)cin>>p[i],p[i]--;
      |                                  ^
a.cc:31:37: error: 'p' was not declared in this scope
   31 |         for(int i=0;i<n;i++)if(find(p[i])!=1000000003)ans+=find(p[i]),js++;
      |                                     ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
vector<int>v[100003];
bool vis[100003];
int n,m,ans,x,y,js;
int find(int i)
{
	int res=1000000003;
	if(i==js)
		return 0;
	for(int j=0;j<v[i].size();j++)
		if(!vis[v[i][j])
		{
			vis[v[i][j]]=true;
			res=min(res,1+find(v[i][j]);
			vis[v[i][j]]=false;
		}
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>p[i],p[i]--;
	for(int i=0;i<m;i++)
	{
		cin>>x>>y;
		x--,y--;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	for(int i=0;i<n;i++)if(find(p[i])!=1000000003)ans+=find(p[i]),js++;
}

Compiler output:
a.cc: In function 'int find(int)':
a.cc:12:32: error: expected ']' before ')' token
   12 |                 if(!vis[v[i][j])
      |                                ^
      |                                ]
a.cc:15:52: error: expected ')' before ';' token
   15 |                         res=min(res,1+find(v[i][j]);
      |                                ~                   ^
      |                                                    )
a.cc: In function 'int main()':
a.cc:22:34: error: 'p' was not declared in this scope
   22 |         for(int i=0;i<n;i++)cin>>p[i],p[i]--;
      |                                  ^
a.cc:30:37: error: 'p' was not declared in this scope
   30 |         for(int i=0;i<n;i++)if(find(p[i])!=1000000003)ans+=find(p[i]),js++;
      |                                     ^
a.cc: In function 'int find(int)':
a.cc:18:1: warning: control reaches end of non-void function [-Wreturn-type]
   18 | }
      | ^
Language: C++

#include<bits/stdc++.h>

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define Nodes 100100
#define S second
#define ll long long
using namespace std;
//union find{
#define MAX_N 100100
int par[MAX_N]; // 親
int Rank[MAX_N]; // 木の深さ

void init(int n){
  for(int i = 0; i < n; i++){
    par[i] = i;
    Rank[i] = 0;
  }
}
// 木の根を求める
int find(int x){
  if(par[x] == x)
    return x;
  else
    return par[x] = find(par[x]);
}
// xとyの属する集合を併合
void unite(int x, int y){
  x = find(x);
  y = find(y);
  if(x == y) return;
  
  // 木の高さが高い方を代表ノードにする
  if(Rank[x] < rank[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(Rank[x] == Rank[y]) Rank[x]++;
  }
}
// xとyが同じ集合ならtrue
bool same(int x,int y){
  return find(x) == find(y);
}
int main(){
  int n,m;cin>>n>>m;
  vector<int>num(n);
  init(100010);
  for(int i=0;i<n;i++)cin>>num[i];
  for(int i=0;i<m;i++){
    int a,b;cin>>a>>b;
    unite(a,b);
  }
  ll ans=0;
  for(int i=0;i<n;i++){
    if(find(num[i])==find(i+1))ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Compiler output:
a.cc: In function 'void unite(int, int)':
a.cc:38:20: error: missing template arguments before '[' token
   38 |   if(Rank[x] < rank[y]){
      |                    ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
 
int N, M;
#define MAX_N 100000
int P[MAX_N];
 
int Rank[MAX_N], Par[MAX_N];
map<int, set<int>> G;
int R;
 
int find(int v) {
  if(Par[v] == v) return v;
  else return Par[v] = find(Par[v]);
}
void unite(int v, int w) {
  v = find(v); w = find(w);
  if(v == w) return;
  if(Rank[v] > Rank[w]) swap(v, w);
  Par[v] = w;
  if(Rank[v] == Rank[w]) ++Rank[w];
}
int main() {
  cin >> N >> M;
  for(int v = 0; v < N; ++v) { Par[v] = v; cin >> P[v]; --P[v]; }
  for(int i = 0; i < M; ++i) {
    int x, y; cin >> x >> y; --x; --y; unite(x, y);
  }
  for(int v = 0; v < N; ++v) {
    G[find(v)].insert(P[v]);
  }
  for(int v = 0; v < N; ++v) {
    R += G[find(v)].count(v);
  }
  cout << R << endl;
  return 0;

Compiler output:
a.cc: In function 'int main()':
a.cc:36:12: error: expected '}' at end of input
   36 |   return 0;
      |            ^
a.cc:23:12: note: to match this '{'
   23 | int main() {
      |            ^
Language: C++

// haha.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include "pch.h"
#include <map>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

void update(vector<int>& rowvec, int index, int val) {
	int diff = val;
	while (index < rowvec.size()) {
		rowvec[index] += diff;
		index = index + (index & (-index));
	}
}
int prefixSum(vector<int>& rowvec, int index) {
	int res = 0;
	while (index > 0) {
		res += rowvec[index];
		index = index - (index & (-index));
	}

	return res;
}

int main()
{
	int num;
	int res = 0;
	vector<int> innumvec;
	vector<char> incolorvec;

	cin >> num;

	for (int i = 0; i < 2*num; i++) {
		int tint;
		char tc;
		cin >> tc >> tint;
		innumvec.push_back(tint);
		incolorvec.push_back(tc);
	}

	vector<int> bvec(num + 1, 0);
	vector<int> wvec(num + 1, 0);
	map<int, int> pbm;
	map<int, int> pwm;
	int maxwindex = 0;
	int maxbindex = 0;

	for (int i = 0; i < incolorvec.size(); i++) {
		char nc = incolorvec[i];
		int ni = innumvec[i];
		int tres;
		map<int, int>::iterator itmap;
		if (nc == 'B') {
			update(bvec, ni, 1);
			tres = prefixSum(bvec, num) - prefixSum(bvec, ni);
			itmap = pbm.upper_bound(ni);
			if (itmap == pbm.end()) {
				pbm.insert({ ni, maxwindex });
				maxbindex = ni;
			}
			else {
				tres += (prefixSum(wvec, num) - prefixSum(wvec, itmap->second));
				pbm.insert({ ni, itmap->second });
			}
		}
		else {
			update(wvec, ni, 1);
			tres = prefixSum(wvec, num) - prefixSum(wvec, ni);
			itmap = pwm.upper_bound(ni);
			if (itmap == pwm.end()) {
				pwm.insert({ ni, maxbindex });
				maxwindex = ni;
			}
			else {
				tres += (prefixSum(bvec, num) - prefixSum(bvec, itmap->second));
				pwm.insert({ ni, itmap->second });
			}
		}
		res += tres;
	}
	cout << "result  " << res;

	return res;

}

Compiler output:
a.cc:4:10: fatal error: pch.h: No such file or directory
    4 | #include "pch.h"
      |          ^~~~~~~
compilation terminated.
Language: C++

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vi bitw(n+1), bitb(n+1);
    auto addw = [&](int i, int x) {
        while(i <= n) {
            bitw[i] += x;
            i += i&-i;
        }
    };
    auto sumw = [&](int i) {
        int res = 0;
        while(i) {
            res += bitw[i];
            i &= i-1;
        }
        return res;
    };
    auto addb = [&](int i, int x) {
        while(i <= n) {
            bitb[i] += x;
            i += i&-i;
        }
    };
    auto sumb = [&](int i) {
        int res = 0;
        while(i) {
            res += bitb[i];
            i &= i-1;
        }
        return res;
    };
    vvi W(n, vi(n+1)), B(n, vi(n+1));
    int cntw = 0, cntb = 0;
    vi placew(n), placeb(n);
    rep(i, 2*n) {
        char c;
        int num;
        cin >> c >> num;
        if(c == 'W') {
            int x = sumw(num);
            x = num-1-x;
            addw(num, 1);
            rep(j, n+1) {
                W[num-1][j] = x+j-sumb(j);
            }
            cntw++;
            placew[num-1] = i;
        } else {
            int x = sumb(num);
            x = num-1-x;
            addb(num, 1);
            rep(j, n+1) {
                B[num-1][j] = x+j-sumw(j);
            }
            cntb++;
            placeb[num-1] = i;
        }
    }

    vvi dp(n+1, vi(n+1, INF));
    dp[0][0] = 0;
    rep(i, n+1) {
        rep(j, n+1) {
            if(i) {
                chmin(dp[i][j], dp[i-1][j] + placew[i-1]+W[i-1][j]-i-j+1);
            }
            if(j) {
                chmin(dp[i][j], dp[i][j-1] + placeb[j-1]+B[j-1][i]-i-j+);
            }
        }
    }

    cout << dp[n][n] << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:96:72: error: expected primary-expression before ')' token
   96 |                 chmin(dp[i][j], dp[i][j-1] + placeb[j-1]+B[j-1][i]-i-j+);
      |                                                                        ^
Language: C++

#include <bits/stdc++.h>
#include "../lib/data_structure/bit.hpp"

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

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

  int n; cin >> n;
  vector<pair<char, int>> v;
  REP(i, 2*n) {
    char c; int a; cin >> c >> a;
    a--;
    v.push_back({c, a});
  }

  vvi black(n, vi(n+1, 0)), white(n, vi(n+1, 0));
  vi bnum(n, 0), wnum(n, 0);
  REP(k, 2*n) {
    char c = v[k].first;
    int num = v[k].second;
    vi wsum(n+1, 0), bsum(n+1, 0);
    RFOR(l, n, 1) {
      bsum[l-1] = bsum[l] + bnum[l-1];
      wsum[l-1] = wsum[l] + wnum[l-1];
    }
    RFOR(l, n+1, 1) {
      if(c == 'B') black[num][l-1] = wsum[l-1] + bsum[num+1];
      else white[num][l-1] = wsum[num+1] + bsum[l-1];
    }
    if(c == 'B') bnum[num]++;
    else wnum[num]++;
  }

  vvi dp(2*n+1, vi(n+1, INF));
  dp[0][0] = 0;
  REP(i, 2*n) {
    REP(j, i+1) {
      if(dp[i][j] == INF) continue;

      int nxtw = j;
      int nxtb = i-j;

      if(nxtw < n) chmin(dp[i+1][j+1], dp[i][j] + black[nxtw][nxtb]);
      if(nxtb < n) chmin(dp[i+1][j], dp[i][j] + white[nxtb][nxtw]);
    }
  }

  cout << dp[2*n][n] << endl;


}
























Compiler output:
a.cc:2:10: fatal error: ../lib/data_structure/bit.hpp: No such file or directory
    2 | #include "../lib/data_structure/bit.hpp"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include<iostream>
#include<string>
#include<cstdio>
#include <cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define int long long

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int n; cin >> n;
    char c[4040]; int a[4040];
    int dp[2020][2020]; //左から(B,0),..,(B,i-1), (W,0),..(W,j-1)を目標順にするための最小swap数
    rep(i, 2 * n) {
        cin >> c[i] >> a[i];
        --a[i];
    }

    vector<vector<int>> black(n, vector<int>(n + 1, 0));
    //(B, i)の前に(B, iより大),(W, j以上)が何個あるか
    vector<vector<int>> white(n, vector<int>(n + 1, 0));
    //(W, i)の前に(W, iより大),(B, j以上)が何個あるか

    vector<int> bnum(n, 0);
    vector<int> wnum(n, 0);
    rep(i, 2 * n) {
        int num = a[i];
        char col = c[i];
        vector<int> bsum(n+1, 0), wsum(n+1, 0); //前にあるi以上の個数
        per(j, n) {
            bsum[j] = bsum[j+1] + bnum[j];
            wsum[j] = wsum[j+1] + wnum[j];
        } //後ろからみる
        per(j, n+1) {
            if(col == 'B') black[num][j] = bsum[num+1] + wsum[j];
            if(col == 'W') white[num][j] = wsum[num+1] + bsum[j];
        }
        if(col == 'B') {
            bnum[num] ++;
        } else {
            wnum[num] ++;
        }
    }

    rep(i, 2020) {
        rep(j, 2020) {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    rep(i, n) {
        rep(j, n) {
            if(i < n) dp[i+1][j] = min(dp[i+1][j], dp[i][j] + black[i][j]);
            if(j < n) dp[i][j+1] = min(dp[i][j+1], dp[i][j] + white[i][j]);
        }
    }
    cout << dp[n][n] << endl;
	return 0;
}


Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int bit[40000];
int u;
void bitinit(int n){
  int now=1;
  for(int i=0;;i++){
    if(now>=n){
      u=now;
      break;
    }
    now*=2;
  }
  fill(bit,bit+u+1,0);
}
void add(int n,int x){
  int i=n;
  while(i<=u){
    bit[i]+=x;
    i+=i&-i;
  }
}
int sum(int n){
  int ret=0;
  int i=n;
  while(i>0){
    ret+=bit[i];
    i-=i&-i;
  }
}
int main(){
  int n;cin>>n;
  int bla[n+1];
  int whi[n+1];
  int a[2*n+1];
  char b[2*n+1];
  bitinit(n);
  for(int i=0;i<2*n;i++){
    char c;cin>>c;
    int m;cin>>m;
    if(c=='B')bla[m]=i+1;
    else whi[m]=i+1;
    add(i+1,1);
    a[i+1]=m;
    b[i+1]=c;
  }
  int ans=0;
  bool used[2*n+1];
  fill(used,used+2*n+1,false);
  int bl=0;
  int wh=0;
  for(int i=1;i<=2*n;i++){
    if(used[i])continue;
    if(b[i]=='B'){
      if(bl+1==a[i]){
        bl++;
        used[i]=true;
        continue;
      }
      else{
        int y=bla[bl+1];
        ans+=bit(y)-bit(i);
        add(y,-1);
        used[y]=true;
        bl++;
      }
    }
    if(b[i]=='W'){
      if(wh+1==a[i]){
        wh++;
        used[i]=true;
        continue;
      }
      else{
        int y=whi[wh+1];
        ans+=bit(y)-bit(i);
        add(y,-1);
        used[y]=true;
        wh++;
      }
    }
  }
  cout<<ans<<endl;
}

Compiler output:
a.cc: In function 'int sum(int)':
a.cc:31:1: warning: no return statement in function returning non-void [-Wreturn-type]
   31 | }
      | ^
a.cc: In function 'int main()':
a.cc:63:17: error: 'bit' cannot be used as a function
   63 |         ans+=bit(y)-bit(i);
      |              ~~~^~~
a.cc:63:24: error: 'bit' cannot be used as a function
   63 |         ans+=bit(y)-bit(i);
      |                     ~~~^~~
a.cc:77:17: error: 'bit' cannot be used as a function
   77 |         ans+=bit(y)-bit(i);
      |              ~~~^~~
a.cc:77:24: error: 'bit' cannot be used as a function
   77 |         ans+=bit(y)-bit(i);
      |                     ~~~^~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int bit[40000]
int u;
void bitinit(int n){
  int now=1;
  for(int i=0;;i++){
    if(now>=n){
      u=now;
      break;
    }
    now*=2;
  }
  fill(bit,bit+u+1,0);
}
void add(int n,int x){
  int i=n;
  while(i<=u){
    bit[i]+=x;
    i+=i&-i;
  }
}
int sum(int n){
  int ret=0;
  int i=n;
  while(i>0){
    ret+=bit[i];
    i-=i&-i;
  }
}
int main(){
  int n;cin>>n;
  int bla[n+1];
  int whi[n+1];
  int a[2*n+1];
  char b[2*n+1];
  bitinit(n);
  for(int i=0;i<2*n;i++){
    char c;cin>>c;
    int m;cin>>m;
    if(c=='B')bla[m]=i+1;
    else whi[m]=i+1;
    add(i+1,1);
    a[i+1]=m;
    b[i+1]=c;
  }
  int ans=0;
  bool used[2*n+1];
  fill(used,used+2*n+1,false);
  int bl=0;
  int wh=0;
  for(int i=1;i<=2*n;i++){
    if(used[i])continue;
    if(b[i]=='B'){
      if(bl+1==a[i]){
        bl++;
        used[i]=true;
        continue;
      }
      else{
        int y=bla[bl+1];
        ans+=bit(y)-bit(i);
        add(y,-1);
        used[y]=true;
        bl++;
      }
    }
    if(b[i]=='W'){
      if(wh+1==a[i]){
        wh++;
        used[i]=true;
        continue;
      }
      else{
        int y=whi[wh+1];
        ans+=bit(y)-bit(i);
        add(y,-1);
        used[y]=true;
        wh++;
      }
    }
  }
  cout<<ans<<endl;
}

Compiler output:
a.cc:5:1: error: expected initializer before 'int'
    5 | int u;
      | ^~~
a.cc: In function 'void bitinit(int)':
a.cc:10:7: error: 'u' was not declared in this scope
   10 |       u=now;
      |       ^
a.cc:15:8: error: 'bit' was not declared in this scope
   15 |   fill(bit,bit+u+1,0);
      |        ^~~
a.cc:15:16: error: 'u' was not declared in this scope
   15 |   fill(bit,bit+u+1,0);
      |                ^
a.cc: In function 'void add(int, int)':
a.cc:19:12: error: 'u' was not declared in this scope
   19 |   while(i<=u){
      |            ^
a.cc:20:5: error: 'bit' was not declared in this scope
   20 |     bit[i]+=x;
      |     ^~~
a.cc: In function 'int sum(int)':
a.cc:28:10: error: 'bit' was not declared in this scope
   28 |     ret+=bit[i];
      |          ^~~
a.cc:31:1: warning: no return statement in function returning non-void [-Wreturn-type]
   31 | }
      | ^
a.cc: In function 'int main()':
a.cc:63:14: error: 'bit' was not declared in this scope
   63 |         ans+=bit(y)-bit(i);
      |              ^~~
a.cc:77:14: error: 'bit' was not declared in this scope
   77 |         ans+=bit(y)-bit(i);
      |              ^~~