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

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int, int>;
const int MOD = 1e9+7;
const double EPS = 1e-9;

vector<bool> seen, visited;
bool able = true;

void dfs(int v) {
  seen[v] = true;

  for (auto nv : match[v]) {
    if (seen[nv] && !visited[nv]) {
      able = false;
      return;
    }
    if (!seen[nv]) dfs(nv);

    if (!able) return;
  }

  visited[v] = true;
}

void solve() {
  int n; cin >> n;
  Graph match(n*n);
  vi start, ends;
  int prev, next;  // game number
  int tmp;
  rep(i,n) {
    cin >> tmp; --tmp;
    if (i < tmp) prev = n*i + tmp;
    else prev = n*tmp + i;
    start.push_back(prev);
    rep(j,n-2) {
      cin >> tmp; --tmp;
      if (i < tmp) next = n*i + tmp;
      else prev = n*tmp + i;
      match[prev].push_back(next);
      prev = next;
    }
    ends.push_back(prev);
  }

  seen.assign(n*n, false);
  visited.assign(n*n, false);
  rep(i,n) {
    dfs(start[i]);
    if (!able) {
      cout << -1 << endl;
      return;
    }
  }

  vi days(n*n, 1);
  priority_queue<P> pq;
  rep(i,n) pq.push(P(1, start[i]));
  int v;
  while (!pq.empty()) {
    v = pq.top().second; pq.pop();
    for (auto nv : match[v]) {
      if (days[nv] < days[v] + 1) {
        days[nv] = days[v] + 1;
        pq.push(P(days[nv], nv));
      }
    }
  }
  
  int ans = 0;
  rep(i,n) ans = max(ans, days[ends[i]]);
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}


Compiler output:
a.cc: In function 'void dfs(int)':
a.cc:19:18: error: 'match' was not declared in this scope; did you mean 'rpmatch'?
   19 |   for (auto nv : match[v]) {
      |                  ^~~~~
      |                  rpmatch
Language: C++

#include <iostream>
#include <string>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
using namespace std;

int to_index(int x, int y, int n)
{
    if (x > y) swap (x, y);

    return (n - x - 1 + n) * x / 2 + y - x - 1;
}

int dfs(int v)
{
    visited[v] = true;
}

int main()
{
    int n;
    cin >> n;
    int nodenum = n * (n - 1) / 2;
    vector<vector<int>> nodes(nodenum + 1);
    vector<int> deg(nodenum, 0);

    // 入力
    for (int i = 0; i < n; i++)
    {
        int current, prev = nodenum;
        for (int j = 0; j < n - 1; j++)
        {
            cin >> current;
            current = to_index(i, current - 1, n);
            nodes[prev].push_back(current);
            deg[current]++;
            prev = current;
        }
    }

    // DAGかどうか判定
    stack<int> st;
    st.push(nodenum);
    int ans = 0;
    while(!st.empty())
    {
        int i = st.top(); st.pop();
        for (auto neighbor : nodes[i])
        {
            if (--deg[neighbor] == 0)
            {
                st.push(neighbor);
                ans++;
            }
        }
    }

    if (ans != nodenum)
    {
        cout << -1 << endl;
        return 0;
    }    

    vector<int> dist(nodenum + 1, 0);
    st.push(nodenum);
    int max = 0;
    while (!st.empty())
    {
        int current = st.top(); st.pop();
        if (dist[current] > 0) continue;
        for (auto neighbor : nodes[current])
        {
            if (dist[neighbor] <= dist[current])
            {
                dist[neighbor] = dist[current] + 1;
                st.push(neighbor);
                if (dist[neighbor] > max) max = dist[neighbor];
            }
        }
    }
 
    cout << max << endl;
    return 0;
} 

Compiler output:
a.cc: In function 'int dfs(int)':
a.cc:19:5: error: 'visited' was not declared in this scope
   19 |     visited[v] = true;
      |     ^~~~~~~
a.cc:20:1: warning: no return statement in function returning non-void [-Wreturn-type]
   20 | }
      | ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3+5;
int a[maxn][maxn];
bool used[maxn];

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    for(int j=0;j<n-1;j++){
      cin>>a[i][j];
    }
  }

  int ans = 0;
  int now[maxn] = {};
  while(1){
    for(int i=1;i<=n;i++)   used[i] = false;
    bool all = true;
    for(int i=1;i<=n;i++){
      if(now[i]==n-1 || used[i] || used[a[i][now[i]]]) continue;
      int t = a[i][now[i]];
      if(i == a[t][now[t]]){
	used[i] = true;
	used[t] = true;
	now[i]++;
	now[t]++;
	all = false;
      }
    }
    if(all){
      bool ok = true;
      for(int i=1;i<=n;i++){
	if(now[i]!=n-1) ok =false;
      }
      if(ok){
	cout << ans << endl;
	return 0;
      }
    cout << -1 << endl;
    return 0;
    }
    ans++;
  }
  return(0);

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

#include<bits/stdc++.h>

const int maxn = 1e5+3;

bool now[maxn];
int uesd[maxn];

using namespace std;
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0); 
  int n;
  cin>>n;
  int a[n][n-1];
  for(int i=1;i<=n;i++){
    now[i] = 0;
    for(int j=0;j<n-1;j++){
      cin>>a[i][j];
      a[i][j];
    }
  }
  
  int ans = 0;
  while(1){
    for(int i=1;i<=n;i++)	used[i] = false;
    bool all = true;
    for(int i=1;i<=n;i++){
      if(now[i]==n-1 || used[i] || used[a[i][now[i]]]) continue;
      int t = a[i][now[i]];
      if(i == a[t][now[t]]){
	used[i] = true;
	used[t] = true;
	now[i]++;
	now[t]++;
	all = false;
      }
    }
    if(all){
      bool ok = true;
      for(int i=0;i<n;i++){
	if(now[i]!=n-1) ok =false;
      }
      if(ok){
	cout << ans << endl;
	return 0;
      }
    cout << -1 << endl;
    return 0;
    }
    ans++;
  }
  return(0);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:25:33: error: 'used' was not declared in this scope; did you mean 'uesd'?
   25 |     for(int i=1;i<=n;i++)       used[i] = false;
      |                                 ^~~~
      |                                 uesd
a.cc:28:25: error: 'used' was not declared in this scope; did you mean 'uesd'?
   28 |       if(now[i]==n-1 || used[i] || used[a[i][now[i]]]) continue;
      |                         ^~~~
      |                         uesd
a.cc:31:9: error: 'used' was not declared in this scope; did you mean 'uesd'?
   31 |         used[i] = true;
      |         ^~~~
      |         uesd
a.cc:33:14: error: use of an operand of type 'bool' in 'operator++' is forbidden in C++17
   33 |         now[i]++;
      |         ~~~~~^
a.cc:34:14: error: use of an operand of type 'bool' in 'operator++' is forbidden in C++17
   34 |         now[t]++;
      |         ~~~~~^
Language: C++

#include<bits/stdc++.h>

const int maxn = 1e5+3;

bool now[maxn];
int pos[maxn];

using namespace std;
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0); 
  int n;
  cin>>n;
  int a[n][n-1];
  for(int i=1;i<=n;i++){
    now[i] = 0;
    for(int j=0;j<n-1;j++){
      cin>>a[i][j];
      a[i][j];
    }
  }
  
  int ans = 0;
  while(1){
    for(int i=1;i<=n;i++)	used[i] = false;
    bool all = true;
    for(int i=1;i<=n;i++){
      if(now[i]==n-1 || used[i] || used[a[i][now[i]]]) continue;
      int t = a[i][now[i]];
      if(i == a[t][now[t]]){
	used[i] = true;
	used[t] = true;
	now[i]++;
	now[t]++;
	all = false;
      }
    }
    if(all){
      bool ok = true;
      for(int i=0;i<n;i++){
	if(now[i]!=n-1) ok =false;
      }
      if(ok){
	cout << ans << endl;
	return 0;
      }
    cout << -1 << endl;
    return 0;
    }
    ans++;
  }
  return(0);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:25:33: error: 'used' was not declared in this scope
   25 |     for(int i=1;i<=n;i++)       used[i] = false;
      |                                 ^~~~
a.cc:28:25: error: 'used' was not declared in this scope
   28 |       if(now[i]==n-1 || used[i] || used[a[i][now[i]]]) continue;
      |                         ^~~~
a.cc:31:9: error: 'used' was not declared in this scope
   31 |         used[i] = true;
      |         ^~~~
a.cc:33:14: error: use of an operand of type 'bool' in 'operator++' is forbidden in C++17
   33 |         now[i]++;
      |         ~~~~~^
a.cc:34:14: error: use of an operand of type 'bool' in 'operator++' is forbidden in C++17
   34 |         now[t]++;
      |         ~~~~~^
Language: C++

#include<bits/stdc++.h>
using namespace std;
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0); 
  int n;
  cin>>n;
  int a[n][n-1];
  for(int i=1;i<=n;i++){
    now[i] = 0;
    for(int j=0;j<n-1;j++){
      cin>>a[i][j];
      a[i][j];
    }
  }
  
  int ans = 0;
  while(1){
    for(int i=1;i<=n;i++)	used[i] = false;
    bool all = true;
    for(int i=1;i<=n;i++){
      if(now[i]==n-1 || used[i] || used[a[i][now[i]]]) continue;
      int t = a[i][now[i]];
      if(i == a[t][now[t]]){
	used[i] = true;
	used[t] = true;
	now[i]++;
	now[t]++;
	all = false;
      }
    }
    if(all){
      bool ok = true;
      for(int i=0;i<n;i++){
	if(now[i]!=n-1) ok =false;
      }
      if(ok){
	cout << ans << endl;
	return 0;
      }
    cout << -1 << endl;
    return 0;
    }
    ans++;
  }
  return(0);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:10:5: error: 'now' was not declared in this scope; did you mean 'pow'?
   10 |     now[i] = 0;
      |     ^~~
      |     pow
a.cc:19:33: error: 'used' was not declared in this scope
   19 |     for(int i=1;i<=n;i++)       used[i] = false;
      |                                 ^~~~
a.cc:22:10: error: 'now' was not declared in this scope; did you mean 'pow'?
   22 |       if(now[i]==n-1 || used[i] || used[a[i][now[i]]]) continue;
      |          ^~~
      |          pow
a.cc:22:25: error: 'used' was not declared in this scope
   22 |       if(now[i]==n-1 || used[i] || used[a[i][now[i]]]) continue;
      |                         ^~~~
a.cc:23:20: error: 'now' was not declared in this scope; did you mean 'pow'?
   23 |       int t = a[i][now[i]];
      |                    ^~~
      |                    pow
a.cc:25:9: error: 'used' was not declared in this scope
   25 |         used[i] = true;
      |         ^~~~
a.cc:35:12: error: 'now' was not declared in this scope; did you mean 'pow'?
   35 |         if(now[i]!=n-1) ok =false;
      |            ^~~
      |            pow
Language: C++

def league(n, graph)
  ans = 0
  is_play_game = true
  while is_play_game
    is_play_game = false
    used = {}
    n.times do |i|
      if !graph[i].empty? && !used[i]
        opponent = graph[i][0]
        if !used[opponent] && graph[opponent][0] == i
          graph[i].shift
          graph[opponent].shift
          used[i] = true
          used[opponent] = true
          is_play_game = true
        end
      end
    end
    ans += 1 if is_play_game
  end

  ans = -1 if graph.any? { |e| !e.empty? }
  puts ans
end

n = gets.to_i
graph = []
graph << []
n.times{ graph << gets.split.map(&:to_i) }

league(n, graph)

Compiler output:
a.cc:1:1: error: 'def' does not name a type
    1 | def league(n, graph)
      | ^~~
a.cc:7:5: error: 'n' does not name a type
    7 |     n.times do |i|
      |     ^
a.cc:23:3: error: 'puts' does not name a type
   23 |   puts ans
      |   ^~~~
a.cc:31:7: error: expected constructor, destructor, or type conversion before '(' token
   31 | league(n, graph)
      |       ^
Language: C++

#include <bits/stdc++.h>
#typedef rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

const int MAXN = 1005;
const int MAXV = MAXN*(MAXN-1)/2;
vector<int> to[MAXN];
int id[MAXN][MAXN]
int toId(int i, int j) {
  if (i > j) swap(i, j);
  return id[i][j];
}
bool visited[MAXV];
bool calculated[MAXV];
int dp[MAXV]; //Vからの最長経路
int dfs() {
  if (visited[v]) {
   if (!calculated[v]) return -1;
    return dp[v];
  }
  visited[v] = true;
  dp[v] = 1;
  for (int u : to[v]) {
    int res = dfs(u);
    if (res == -1) return -1;
    dp[v] = max(dp[v], res+1);
  }
  calculated[v] = true;
  return dp[v];
  
}
int main()
{
  int n; cin >> n;
  vector<vector<int>> a(n, vector<int>(n-1));
  rep(i,n) {
    rep(j,n-1){
      cin >> a[i][j];
      a[i][j]--;
    }
  }
  int V = 0;
  rep(i,n)rep(j,n) {
    if (i < j) {
      id[i][j] = V++;
    }
  }
  rep(i,n) {
    rep(j,n-1) {
      a[i][j] = toId(i, a[i][j]);
    }
    rep(j,n-2) {
      to[a[i][j+1]].push_back(a[i][j]);
    }
  }
  int ans = 0;
  rep(i,V) {
    int res = dfs(i);
    if (res == -1) {
      puts("-1");
      return 0;
    }
    ans = max(ans, res);
  }
  cout << ans << endl;
  return 0;
}

Compiler output:
a.cc:2:2: error: invalid preprocessing directive #typedef
    2 | #typedef rep(i,n) for(int i=0;i<(n);i++)
      |  ^~~~~~~
a.cc:10:1: error: expected initializer before 'int'
   10 | int toId(int i, int j) {
      | ^~~
a.cc: In function 'int dfs()':
a.cc:18:15: error: 'v' was not declared in this scope
   18 |   if (visited[v]) {
      |               ^
a.cc:22:11: error: 'v' was not declared in this scope
   22 |   visited[v] = true;
      |           ^
a.cc:25:18: error: too many arguments to function 'int dfs()'
   25 |     int res = dfs(u);
      |               ~~~^~~
a.cc:17:5: note: declared here
   17 | int dfs() {
      |     ^~~
a.cc: In function 'int main()':
a.cc:37:7: error: 'i' was not declared in this scope
   37 |   rep(i,n) {
      |       ^
a.cc:37:3: error: 'rep' was not declared in this scope
   37 |   rep(i,n) {
      |   ^~~
Language: C++

#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

class topological_sort {
private:
	int V;
	vector<vector<int>> edges;
	vector<int> used;
public:
	topological_sort(int n) :V(n), edges(n), used(n) {}
	topological_sort(vector<vector<int>> &edges) :V(edges.size()), used(edges.size()) { this->edges = edges; }

	void add_edge(int from, int to) { edges[from].emplace_back(to); }

	vector<int> build() {

		for (int i = 0; i < V; i++) for (const auto &e : edges[i]) in[e]++;

		vector<int> res, in(V);
		res.reserve(V);
		queue<int> que;

		for (int i = 0; i < V; i++) {
			if (in[i] == 0 && !used[i]) {
				used[i] = 1;
				que.emplace(i);
			}
		}

		while (!que.empty()) {
			int now = que.front();
			DMP(now, in);
			que.pop();
			res.emplace_back(now);
			for (const auto &e : edges[now]) {
				in[e]--;
				if (in[e] == 0) {
					if (used[e]) return vector<int>(); // unable to sort
					used[e] = used[now] + 1;
					que.emplace(e);
				}
			}
		}

		return res;
	}

	int longest_path() {
		if (none_of(used.begin(), used.end(), [](int u) { return u > 0; })) build();
		return *max_element(used.begin(), used.end());
	}

};

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	auto id = [&](int l, int r) { return min(l, r)*N + max(l, r); };

	topological_sort ts(N * N);
	for (int i = 0; i < N; i++) {
		vector<int> A(N - 1);
		for (int j = 0; j < N - 1; j++) cin >> A[j];
		for (int j = 0; j < N - 2; j++) ts.add_edge(id(i, A[j] - 1), id(i, A[j + 1] - 1));
	}

	cout << ts.longest_path() << "\n";

	return 0;
}


Compiler output:
a.cc: In member function 'std::vector<int> topological_sort::build()':
a.cc:51:76: error: 'in' was not declared in this scope; did you mean 'yn'?
   51 |                 for (int i = 0; i < V; i++) for (const auto &e : edges[i]) in[e]++;
      |                                                                            ^~
      |                                                                            yn
Language: C++

#include <iostream>
#include <vector>

using namespace std;

bool visit(const vector<vector<int>>& g, int v, vector<int>& order, vector<int>& color) {
    color[v] = 1;
    for (int u : g[v]) {
        if (color[u]==2) continue;
        if (color[u]==1) return false;
        if (!visit(g, u, order, color)) return false;
    }
    order.push_back(v); color[v] = 2;
    return true;
}

// トポロジカルソートする
// 返り値が true の時のみ意味を持つ(false の場合は閉路)
bool TopologicalSort(const vector<vector<int>>& g, vector<int>& order) {
    int n = g.size();
    vector<int> color(n);
    for (int u = 0; u < n; u++) if (!color[u] && !visit(g, u, order, color)) return false;
    reverse(order.begin(), order.end());
    return true;
}

int getIndex(const int a, const int b, const int N) {
    const int p1 = min(a, b);
    const int p2 = max(a, b);
    return p1 * N + p2;
}

int main() {
    int N;
    cin >> N;
    vector<vector<int> > G(N*N);
    for (int i = 0; i < N; i++) {
        vector<int> A(N-1);
        for (int j = 0; j < N-1; j++) {
            cin >> A[j]; --A[j];
        }
        for (int j = 0; j < N-2; j++) {
            const int v1 = getIndex(i, A[j], N);
            const int v2 = getIndex(i, A[j+1], N);
            G[v1].push_back(v2);
        }
    }
    vector<int> order;
    if (!TopologicalSort(G, order)) {
        cout << -1 << endl;
        return 0;
    }
    int ans = 0, index = 0;
    while (index < order.size()) {
        ++ans;
        vector<int> done(N);
        while (index < order.size()) {
            const int v = order[index];
            const int p1 = v / N;
            const int p2 = v % N;
            if (p1 >= p2) {
                ++index;
                continue;
            }
            //cout << p1 << " vs " << p2 << endl;
            if (done[p1] == 1 || done[p2] == 1) {
                break;
            }
            done[p1] = 1; done[p2] = 1;
            index++;
        }
        //cout << "===" << endl;
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'bool TopologicalSort(const std::vector<std::vector<int> >&, std::vector<int>&)':
a.cc:23:5: error: 'reverse' was not declared in this scope
   23 |     reverse(order.begin(), order.end());
      |     ^~~~~~~
Language: C++

    #include <bits/stdc++.h>
     
    using namespace std;
     
    int main()
    {
        int N;
        int cnt;
        int i, j, k;
        int f;
     
        cin >> N;
        vector<vector<int>> A(N+1, vector<int>(N+1));
        vector<int> idx(N+1);
        for(i=1; i<=N; ++i){
            for(j=1; j<=N-1; ++j) cin >> A[i][j];
            A[i][N] = 0;
            idx[i] = 1;
        }
     
        cnt = 0;
        while(true){
            f = 0;
            for(i=1; i<=N; ++i){
                k = A[i][idx[i]];
                if(k == 0) continue;
                if(A[k][idx[k]] == fst){
                    A[i][idx[i]] = 0;
                    A[k][idx[k]] = 0;
                    f = 1;
                }
            }
            if(!f) break;
            ++cnt;
            for(i=1; i<=N; ++i){
                if(A[i][idx[i]] == 0 && idx[i] < N) ++idx[i];
            }
        }
     
        for(i=1; i<=N; ++i){
            if(idx[i] != N){
                cnt = -1;
                break;
            }
        }
        
        cout << cnt << endl;
     
        return 0;
    }

Compiler output:
a.cc: In function 'int main()':
a.cc:27:36: error: 'fst' was not declared in this scope
   27 |                 if(A[k][idx[k]] == fst){
      |                                    ^~~
Language: C++

#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

int N;
int A[1234][1234];
namespace std {
	template <>
	struct hash<pair<int,int>> {
		size_t operator()(const pair<int,int>& hoge) const {
			size_t seed = 0;
			auto n_hash = hash<int>()(hoge.first);
			auto d_hash = hash<double>()(hoge.second);

			seed ^= n_hash + 0x9e3779b9 + (seed << 6) + (seed >> 2);
			seed ^= d_hash + 0x9e3779b9 + (seed << 6) + (seed >> 2);
			return seed;
		}
	};
int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N - 1; ++j) {
			cin >> A[i][j];
			--A[i][j];
		}
	}
	unordered_map<pair<int, int>, int>M;
	set<pair<int, pair<int, int>>>S;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < i; ++j) {
			S.insert({ 0,{j,i} });
			M[{j, i}] = 0;
		}
	}
	auto w = [&](int i, int j) {
		return (i < j) ? pair<int, int>(i, j) : pair<int, int>(j, i);
	};
	vector<int>upd;
	for (int i = 0; i < N; ++i)upd.push_back(i);
	vector<int>mark(N, 0);
	int ans = 0;
	for (;;) {
		bool br = true;
		for (int i : upd) {
			if (mark[i] != N - 1) {
				br = false;
				int j = A[i][mark[i]];
				S.erase(S.find({ M[w(i,j)] ,w(i, j) }));
				M[w(i, j)]--;
				S.insert({ M[w(i,j)], w(i,j) });
			}
		}
		if (br)
			break;
		upd.clear();
		ans++;
		while (!S.empty()) {
			auto big = *S.begin();
			if (big.first > -2) {
				break;
			}
			mark[big.second.first]++;
			if (mark[big.second.first] < N - 1)upd.push_back(big.second.first);
			upd.push_back(big.second.second);
			if (mark[big.second.second] < N - 1)mark[big.second.second]++;
			S.erase(S.begin());
		}
	}
	for (int i = 0; i < N; ++i) {
		if (mark[i] != N - 1) {
			ans = -1;
		}
	}
	cout << ans << endl;
	return 0;
}


Compiler output:
a.cc:104:2: error: expected '}' at end of input
  104 | }
      |  ^
a.cc:34:15: note: to match this '{'
   34 | namespace std {
      |               ^
Language: C++

#include <iostream>
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    map<int,queue<int>>theval;
    for(int i=1;i<=n;i++){
        for(int j=0;j<n-1;j++){
            int a;
            cin>>a;
            theval[i].push(a);
        }
    }
    int days=0;
    
    while(true){
        bool shahad=false;
        bool noans=true;
       set<int>numberstaken;
       days++;
       for(int i=1;i<=n;i++){
         if(!numberstaken.count(i)&&theval[i].size()>0&&!numberstaken.count(theval[i].front())){
             shahad=true;
            if(!numberstaken.count(theval[i].front())&&theval[theval[i].front()].size()>0&&theval[theval[i].front()].front()==i){
            numberstaken.insert(i);
            numberstaken.insert(theval[i].front());
            //cout<<i<<" "<<theval[i].front()<<endl;
            theval[theval[i].front()].pop();
            theval[i].pop();
            noans=false;
            } 
            
         }  
         
       }
       if(shahad==0){break;}
       if(noans==true){cout<<-1<<endl; return 0;}
         
    }
    cout<<days-1<<endl;
}
#include <iostream>
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    map<int,queue<int>>theval;
    for(int i=1;i<=n;i++){
        for(int j=0;j<n-1;j++){
            int a;
            cin>>a;
            theval[i].push(a);
        }
    }
    int days=0;
    
    while(true){
        bool shahad=false;
        bool noans=true;
       set<int>numberstaken;
       days++;
      int mm=n/2+1;
       for(int i=1;i<=mm;i++){
         if(!numberstaken.count(i)&&theval[i].size()>0&&!numberstaken.count(theval[i].front())){
             shahad=true;
            if(!numberstaken.count(theval[i].front())&&theval[theval[i].front()].size()>0&&theval[theval[i].front()].front()==i){
            numberstaken.insert(i);
            numberstaken.insert(theval[i].front());
            //cout<<i<<" "<<theval[i].front()<<endl;
            theval[theval[i].front()].pop();
            theval[i].pop();
            noans=false;
            } 
            
         }  
         
       }
       if(shahad==0){break;}
       if(noans==true){cout<<-1<<endl; return 0;}
         
    }
    cout<<days-1<<endl;
}


Compiler output:
a.cc:54:5: error: redefinition of 'int main()'
   54 | int main()
      |     ^~~~
a.cc:6:5: note: 'int main()' previously defined here
    6 | int main()
      |     ^~~~
Language: C++

#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

const int MAXN = 1005;
const int MAXV = MAXN * (MAXN - 1) / 2;
vector<int> to[MAXV];
int id[MAXN][MAXN];
int toId(int i, int j) {
    if(i > j) {
        swap(i, j);
    }
    return id[i][j];
}
int n;

//メモ化再帰
bool visited[MAXV];
bool calculated[MAXV];
int dp[MAXV];
int dfs(int v) {
    if(visited[v]) {
        //既に計算済み
        if(!calculated[v]) {
            return -1;
        }
        return dp[v];
    }
    visited[v] = true;
    dp[v] = 0;
    for(int u : to[v]) {
        int res = dfs(u);
        if(res == -1) {
            return -1;
        }
        dp[v] = max(dp[v], res + 1);
    }
    calculated[v] = true;
    return dp[v];
}
int main() {
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n - 1));
    REP(i, n) {
        REP(j, n - 1) {
            cin >> a[i][j];
            a[i][j]--;
        }
    }
    //頂点の数
    int V = 0;
    REP(i, n) {
        REP(j, n) {
            if(i < j) {
                id[i][j] = V++;
            }
        }
    }
    REP(i, n) {
        REP(j, n - 1) { a[i][j] = toId(i, a[i][j]); }
        REP(j, n - 2) {
            //逆向きに辺をはる
            to[a[i][j + 1]].push_back(a[i][j]);
        }
    }
    int ans = 0;
    REP(i, V) {
        int res = dfs(i);
        if(res == -1) {
            puts("-1")
        }
        ans = max(ans, res);
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:99:23: error: expected ';' before '}' token
   99 |             puts("-1")
      |                       ^
      |                       ;
  100 |         }
      |         ~
Language: C++

#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

const int MAXN = 1005;
const int MAXV = MAXN * (MAXN - 1) / 2;
vector<int> to[MAXV];
int id[MAXN][MAXN];
int toId(int i, int j) {
    if(i > j) {
        swap(i, j);
    }
    return id[i][j];
}
int n;

//メモ化再帰
bool visited[MAXV];
bool calculated[MAXV];
int dp[MAXV];
int dfs(int v) {
    if(visited[v]) {
        //既に計算済み
        if(!calculated[v]) {
            return -1;
        }
        return dp[v];
    }
    visited[v] = true;
    dp[v] = 0;
    for(int u : to[v]) {
        int res = dfs(u);
        if(res == -1) {
            return -1;
        }
        dp[v] = max(dp[v], res + 1);
    }
    calculated[v] = true;
    return dp[v];
}
int main() {
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n - 1));
    REP(i, n) {
        REP(j, n - 1) {
            cin >> a[i][j];
            a[i][j]--;
        }
    }
    //頂点の数
    int V = 0;
    REP(i, n) {
        REP(j, n) {
            if(i < j) {
                id[i][j] = V++;
            }
        }
    }
    REP(i, n) {
        REP(j, n - 1) { a[i][j] = toId(i, a[i][j]); }
        REP(j, n - 2) {
            //逆向きに辺をはる
            to[a[i][j + 1]].push_back(a[i][j]);
        }
    }
    int ans = 0;
    rep(i, V) {
        int res = dfs(i);
        if(res == -1) {
            puts("-1")
        }
        ans = max(ans, res);
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:96:9: error: 'i' was not declared in this scope
   96 |     rep(i, V) {
      |         ^
a.cc:96:5: error: 'rep' was not declared in this scope
   96 |     rep(i, V) {
      |     ^~~
Language: C++

#include <bits/stdc++.h>


#define rep(i,n) for(int i = 0 ; i< (n);i++)
using namespace std;


typedef long long ll;
typedef pair<int,int> P;


int main(){
	int n ; 
	cin >> n;
	vector<vector<int>> a(n,vector<int>(n-1));
	rep(i,n){//2行目 repeat 
	  rep(j,n-1){
		  cin >> a[i][j];
		  a[i][j]--;//ここまで二重配列の受け取り。
		}
		reverse(a[i].begin(),a[i].end());//配列をひっくり返す。理由 0番目の要素をとるより、末尾の要素をとるほうが早いから
	}
	vector<P> q;//qのサイズはまだ決めない　a:b のaとbを入れるpairの配列
	auto check = [&](int i ){//選手iが試合できるか
		if(a[i].size()==0) return;	
		int j = a[i].back();//jは対戦相手
		if(a[j].size() == 0 ) return;
		if(a[j].back() == i) {//対戦相手が自分であった場合。
			P p(i,j);//pairでp(i,j)っていうのを登録して、それをq（配列）の後ろに追加していく。その時に、(i,j)&(j,i)のだぶりが登録されてしまうので、次の行のifで、数字の大小によって操作するかしないかのif
			if(p.second <p.first) swap(p.first,p.second)
			q.push_back(p);
		  }
	  };
	rep(i,n){
		check(i);	
	  }
	  int day = 0;
	  while(q.size() > 0){//試合表、つまりqの配列が空になるまで繰り返す
		day ++;
		sort(q.begin(),q.end());//前のキューをプレブキューに移して、キューを殻にする swap二つの要素を入れ替える
		q.erase(unique(q.begin(),q.end()),q.end());//重複した要素を取り除く。
		vector<P> prevQ;//一回目ではprevQは空。
		swap(prevQ,q);
		for(P p : prevQ){
		  int i = p.first, j = p.second;
		  a[i].pop_back();
		  a[j].pop_back();
		  }
		 for(P p : prevQ){
		  int i = p.first, j = p.second;
			check(i);
			check(j);
		  }
		}
		rep(i,n){//試合が全部行われたかを判定しないといけない
			if (a[i].size()!=0){
				puts("-1");
			  return 0;
			  }
		}
		cout <<day<<endl;//yotube marukopi
		return 0;
}
	


Compiler output:
a.cc: In lambda function:
a.cc:30:69: error: expected ';' before 'q'
   30 |                         if(p.second <p.first) swap(p.first,p.second)
      |                                                                     ^
      |                                                                     ;
   31 |                         q.push_back(p);
      |                         ~
Language: C++

#include <bits/stdc++.h>


#define rep(i,n) for(int i = 0 ; i< (n);i++)
using namespace std;


typedef long long ll;
typedef pair<int,int> P;


int main(){
	int n ; 
	cin >> n;
	vector<vector<int>> a(n,vector<int>(n-1));
	rep(i,n){//2行目 repeat 
	  rep(j,n-1){
		  cin >>a.at(i).at(j);
		  a[i][j]--;//ここまで二重配列の受け取り。
		}
		reverse(a[i].begin(),a[i].end());//配列をひっくり返す。理由 0番目の要素をとるより、末尾の要素をとるほうが早いから
	}
	vector<P> q;//qのサイズはまだ決めない　a:b のaとbを入れるpairの配列
	auto check = [&](int i ){//選手iが試合できるか
		if(a[i].size()==0)return;	
		int j = a[i].back();//jは対戦相手
		if(a[j].size() == 0 )return;
		if(a[j].back() == i){//対戦相手が自分であった場合。
			P p(i,j);//pairでp(i,j)っていうのを登録して、それをq（配列）の後ろに追加していく。その時に、(i,j)&(j,i)のだぶりが登録されてしまうので、次の行のifで、数字の大小によって操作するかしないかのif
			if(p.second <p.first) swap(p.first,p.second);
			q.push_back(p(i.j));
		  }
	  }
	rep(i,n){
		check(i);	
	  }
	  int day = 0;
	  while(q.size() > 0){//試合表、つまりqの配列が空になるまで繰り返す
		day ++;
		sort(q.begin(),q.end());//前のキューをプレブキューに移して、キューを殻にする swap二つの要素を入れ替える
		q.erase(unique(q.begin(),q.end()),q.end());//重複した要素を取り除く。
		vector<P> prevQ;//一回目ではprevQは空。
		swap(prevQ,q);
		for(P p : prevQ){
		  int i = p.first, j = p.second;
		  a[i].pop_back();
		  a[j].pop_back();
		  }
		 for(P p : prevQ){
		  int i = p.first, j = p.second;
			check(i);
			check(j);
		  }
		}
		rep(i,n){//試合が全部行われたかを判定しないといけない
			if (a[i].size()!=0){
				day = -1; 
			  return 0;
			  }
		}
		cout <<day<<endl;
		//youtube maru kopi

		  }
}


Compiler output:
a.cc: In lambda function:
a.cc:31:41: error: request for member 'j' in 'i', which is of non-class type 'int'
   31 |                         q.push_back(p(i.j));
      |                                         ^
a.cc: In function 'int main()':
a.cc:4:18: error: expected ',' or ';' before 'for'
    4 | #define rep(i,n) for(int i = 0 ; i< (n);i++)
      |                  ^~~
a.cc:34:9: note: in expansion of macro 'rep'
   34 |         rep(i,n){
      |         ^~~
a.cc:34:13: error: 'i' was not declared in this scope
   34 |         rep(i,n){
      |             ^
a.cc:4:34: note: in definition of macro 'rep'
    4 | #define rep(i,n) for(int i = 0 ; i< (n);i++)
      |                                  ^
a.cc: At global scope:
a.cc:65:1: error: expected declaration before '}' token
   65 | }
      | ^
Language: C++

#include <bits/stdc++.h>


#define rep(i,n) for(int i = 0 ; i< (n);i++)
using namespace std;


typedef Long Long ll;
typedef pair<int,int> P;


int main(){
	int n ; 
	cin >> n;
	vector<vector<int>> a(n,vector<int>(n-1));
	rep(i,n){//2行目 repeat 
	  rep(j,n-1){
		  cin >>a.at(i).at(j);
		  a[i][j]--;//ここまで二重配列の受け取り。
		}
		reverse(a[i].begin(),a[i].end());//配列をひっくり返す。理由 0番目の要素をとるより、末尾の要素をとるほうが早いから
	}
	vector<P> q;//qのサイズはまだ決めない　a:b のaとbを入れるpairの配列
	auto check = [&](int i ){//選手iが試合できるか
		if(a[i].size()==0)return;	
		int j = a[i].back();//jは対戦相手
		if(a[j].size() == 0 )return;
		if(a[j].back() == i){//対戦相手が自分であった場合。
			P p(i,j);//pairでp(i,j)っていうのを登録して、それをq（配列）の後ろに追加していく。その時に、(i,j)&(j,i)のだぶりが登録されてしまうので、次の行のifで、数字の大小によって操作するかしないかのif
			if(p.second <p.first) swap(p.first,p.second);
			q.push_back(p(i.j));
		  }
	  }
	rep(i,n){
		check(i);	
	  }
	  int day = 0;
	  while(q.size() > 0){//試合表、つまりqの配列が空になるまで繰り返す
		day ++;
		sort(q.begin(),q.end());//前のキューをプレブキューに移して、キューを殻にする swap二つの要素を入れ替える
		q.erase(unique(q.begin(),q.end()),q.end());//重複した要素を取り除く。
		vector<P> prevQ;//一回目ではprevQは空。
		swap(prevQ,q);
		for(P p : prevQ){
		  int i = p.first, j = p.second;
		  a[i].pop_back();
		  a[j].pop_back();
		  }
		 for(P p : prevQ){
		  int i = p.first, j = p.second;
			check(i);
			check(j);
		  }
		}
		rep(i,n){//試合が全部行われたかを判定しないといけない
			if (a[i].size()!=0){
			  puts("-1");
			  return 0;
			  }
		}
		cout <<day<<endl;
//youtubeの解答を映しただけ
		  }
}


Compiler output:
a.cc:8:9: error: 'Long' does not name a type; did you mean 'long'?
    8 | typedef Long Long ll;
      |         ^~~~
      |         long
a.cc: In lambda function:
a.cc:31:41: error: request for member 'j' in 'i', which is of non-class type 'int'
   31 |                         q.push_back(p(i.j));
      |                                         ^
a.cc: In function 'int main()':
a.cc:4:18: error: expected ',' or ';' before 'for'
    4 | #define rep(i,n) for(int i = 0 ; i< (n);i++)
      |                  ^~~
a.cc:34:9: note: in expansion of macro 'rep'
   34 |         rep(i,n){
      |         ^~~
a.cc:34:13: error: 'i' was not declared in this scope
   34 |         rep(i,n){
      |             ^
a.cc:4:34: note: in definition of macro 'rep'
    4 | #define rep(i,n) for(int i = 0 ; i< (n);i++)
      |                                  ^
a.cc: At global scope:
a.cc:64:1: error: expected declaration before '}' token
   64 | }
      | ^
Language: C++

#include <bits/stdc++.h>
using namespace std;

/* #pragma */
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/*template*/
template<class T>constexpr bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>constexpr bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
constexpr int32_t GCD(int32_t a, int32_t b){return b ? GCD(b, a%b) : a;}
constexpr int64_t GCD(int64_t a, int64_t b){return b ? GCD(b, a%b) : a;}
constexpr int32_t LCM(int32_t a, int32_t b){return a / GCD(a, b) * b;}
constexpr int64_t LCM(int64_t a, int64_t b){return a / GCD(a, b) * b;}

/* const */
constexpr int32_t INF = 1001001001;
constexpr int64_t LINF = 1001001001001001001ll;
constexpr int32_t MOD = 1e9 + 7;
constexpr int32_t EPS = 1e-9;
constexpr int32_t dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//constexpr int32_t dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};


//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

//#define int int64_t

/*global*/



signed main()
{
	int n; cin >> n;
	vector<vector<int>> a(n, vector<int>(n-1));

	for(int i{}; i < n; ++i)
	{
		for (int j = 0; j < n-1; ++j)
		{
			cin >> a[i][j];
			a[i][j]--;
		}
		reverse(a[i].begin(), a[i].end());
	}

	using pi = pair<int, int>;
	vector<pi> v;

	auto make = [&](int i)
	{
		if(a[i].size() == 0) return;
		int m = a[i].back();
		if(a[m].back() == i)
		{
			pi p(i,m);
			if(p.second < p.first) swap(p.first, p.second);
			v.emplace_back(p);
		}
	};

	for(int i = 0; i < n; ++i)
	{
		make(i);
	}

	int day{};
	while(v.size() > 0)
	{
		day++;

		sort(v.begin(), v.end());
		v.erase(unique(v.begin(), v.end()), v.end());

		vector<pi> prev;
		swap(prev, v);

		for(pi p: prev)
		{
			int i = p.first; int j = p.second;
			a[i].pop_back();
			a[j].pop_back();
		}

		for(pi p: prevQ)
		{
			int i = p.first; int j = p.second;
			make(i);
			make(j);
		}
	}

	for(int i = 0; i < n; ++i)
	{
		if(a[i].size() != 0)
		{
			cout << -1 << '\n';
			return 0;
		}
	}
	cout << day << '\n';
}


Compiler output:
a.cc: In function 'int main()':
a.cc:109:27: error: 'prevQ' was not declared in this scope; did you mean 'prev'?
  109 |                 for(pi p: prevQ)
      |                           ^~~~~
      |                           prev
Language: C++

#include <bits/stdc++.h>
using namespace std;

/* #pragma */
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/*template*/
template<class T>constexpr bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>constexpr bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
constexpr int32_t GCD(int32_t a, int32_t b){return b ? GCD(b, a%b) : a;}
constexpr int64_t GCD(int64_t a, int64_t b){return b ? GCD(b, a%b) : a;}
constexpr int32_t LCM(int32_t a, int32_t b){return a / GCD(a, b) * b;}
constexpr int64_t LCM(int64_t a, int64_t b){return a / GCD(a, b) * b;}

/* const */
constexpr int32_t INF = 1001001001;
constexpr int64_t LINF = 1001001001001001001ll;
constexpr int32_t MOD = 1e9 + 7;
constexpr int32_t EPS = 1e-9;
constexpr int32_t dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//constexpr int32_t dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};


//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

//#define int int64_t

/*global*/



signed main()
{
	int n; cin >> n;
	vector<vector<int>> a(n, vector<int>(n-1));

	for(int i{}; i < n; ++i)
	{
		for (int j = 0; j < n-1; ++j)
		{
			cin >> a[i][j];
			a[i][j]--;
		}
		reverse(a[i].begin(), a[i].end());
	}

	using pi = pair<int, int>;
	vector<pi> v;

	auto make = [&](int i)
	{
		if(a[i].size() == 0) return;
		int m = a[i].back();
		if(a[m].back() == i)
		{
			pi p(i,m);
			if(p.second < p.first) swap(p.first, p.second);
			v.emplace_back(p);
		}
	};

	for(int i = 0; i < n; ++i)
	{
		make(i);
	}

	int day{};
	while(v.size() > 0)
	{
		day++;

		sort(v.begin(), v.end());
		v.erase(unique(v.begin(), v.end()), v.end());

		vector<pi> prev;
		swap(prev, v);

		for(pi p: prev)
		{
			int i = p.first; int j = p.second;
			a[i].pop_back();
			a[j].pop_back();
		}

		for(pi p: prevQ)
		{
			int i = p.first; int j = p.second;
			check(i);
			check(j);
		}
	}

	for(int i = 0; i < n; ++i)
	{
		if(a[i].size() != 0)
		{
			cout << -1 << '\n';
			return 0;
		}
	}
	cout << day << '\n';
}

Compiler output:
a.cc: In function 'int main()':
a.cc:109:27: error: 'prevQ' was not declared in this scope; did you mean 'prev'?
  109 |                 for(pi p: prevQ)
      |                           ^~~~~
      |                           prev
a.cc:112:25: error: 'check' was not declared in this scope
  112 |                         check(i);
      |                         ^~~~~
Language: C++

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int a[1024][1024] = { 0 };
int c[1024] = { 0 }, l[1024] = { 0 };

int main(void) {
  int n;

  cin >> n;

  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n - 1; j++) {
      int aij;
      cin >> aij;
      a[i][j] = aij - 1;
    }
  }

  int d = 1;
  while(1) {
    int prog = 0;
    for(int i = 0; i < n; i++) {
      if (l[i] == 0) {
        int e = a[i][c[i]];
        if (l[e] == 0 && a[e][c[e]] == i) {
          c[i]++;
          c[e]++;
          l[i]++;
          l[e]++;
          prog++;
        }
      }
    }

    if(!prog) {
      d = -1;
      break;
    }

    for(int i = 0; i < n; i++) {
      if (c[i] < n - 1) {
        goto repeat;
      }
    }
    break;

  repeat:;
    d++;
    memset(l, 0, sizeof(int)*n);
  }

  cout << d;

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:53:5: error: 'memset' was not declared in this scope
   53 |     memset(l, 0, sizeof(int)*n);
      |     ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include <vector>
  +++ |+#include <cstring>
    4 |
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
const int MAXN = 1005;
const int MAXV = MAXN*(MAXN-1)/2;
vector<int> E[MAXV];
int id[MAXN][MAXN];
 
bool reached[MAXV];
bool finished[MAXV];
int dp[MAXV]; // max length of path from v
int dfs(int pos) {
	if (reached[pos]) {
		if (!finished[pos])return -1;
		return dp[pos];
	}
	dp[pos] = 0;
	reached[pos] = true;
	for (int i = 0; i < E[pos].size(); i++) {
		//cout <<"pos == " << pos <<  "to " << E[pos][i] << endl;
		int res = dfs(E[pos][i]);
		if (res == -1)return -1;
		dp[pos] = max(dp[pos], res + 1);
	}
	finished[pos] = true;
	return dp[pos];
}
 
int main() {
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(n-1));
  
  int V = 0;
  rep(i,n)rep(j,n) {
    if (i < j) {
      id[i][j] = V++;
    }else if(i > j){
      id[i][j] = id[j][i];
    }
  }
  rep(i,n) {
    rep(j,n-1) {
      cin >> a[i][j];
      a[i][j]--;
      a[i][j] = id[i][a[i][j]];
    }
  }
  
  rep(i,n) {
    
    rep(j,n-2) {
      E[a[i][j]].push_back(a[i][j + 1]);
    }
  }
  int ans = 0;
  rep(i,N) {
    rep(j,N){
      int res = dfs(a[i][j]);
      if (res == -1) {
        puts("-1");
        return 0;
      }
      ans = max(ans, res);
    }
  }
  cout << ans + 1 << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:59:9: error: 'N' was not declared in this scope
   59 |   rep(i,N) {
      |         ^
a.cc:2:39: note: in definition of macro 'rep'
    2 | #define rep(i,n) for (int i = 0; i < (n); ++i)
      |                                       ^
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
const int MAXN = 1005;
const int MAXV = MAXN*(MAXN-1)/2;
vector<int> to[MAXV];
int id[MAXN][MAXN];
 
bool reached[MAXV];
bool finished[MAXV];
int dp[MAXV]; // max length of path from v
int dfs(int pos) {
	if (reached[pos]) {
		if (!finished[pos])return -1;
		return dp[pos];
	}
	dp[pos] = 0;
	reached[pos] = true;
	for (int i = 0; i < E[pos].size(); i++) {
		//cout <<"pos == " << pos <<  "to " << E[pos][i] << endl;
		int res = dfs(E[pos][i]);
		if (res == -1)return -1;
		dp[pos] = max(dp[pos], res + 1);
	}
	finished[pos] = true;
	return dp[pos];
}
 
int main() {
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(n-1));
  
  int V = 0;
  rep(i,n)rep(j,n) {
    if (i < j) {
      id[i][j] = V++;
    }else if(i > j){
      id[i][j] = id[j][i];
    }
  }
  rep(i,n) {
    rep(j,n-1) {
      cin >> a[i][j];
      a[i][j]--;
      a[i][j] = id[i][a[i][j]];
    }
  }
  
  rep(i,n) {
    
    rep(j,n-2) {
      to[a[i][j+1]].push_back(a[i][j]);
    }
  }
  int ans = 0;
  rep(i,V) {
    int res = dfs(i);
    if (res == -1) {
      puts("-1");
      return 0;
    }
    ans = max(ans, res);
  }
  cout << ans << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int dfs(int)':
a.cc:21:29: error: 'E' was not declared in this scope
   21 |         for (int i = 0; i < E[pos].size(); i++) {
      |                             ^
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
const int MAXN = 1005;
const int MAXV = MAXN*(MAXN-1)/2;
vector<int> to[MAXV];
int id[MAXN][MAXN];
 
bool visited[MAXV];
bool calculated[MAXV];
int dp[MAXV]; // max length of path from v
int dfs(int v) {
  if (visited[v]) {
    if (!calculated[v]) return -1;
    return dp[v];
  }
  visited[v] = true;
  dp[v] = 1;
  for (int u : to[v]) {
    int res = dfs(u);
    if (res == -1) return -1;
    dp[v] = max(dp[v], res+1);
  }
  calculated[v] = true;
  return dp[v];
}
 
int main() {
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(n-1));
  
  int V = 0;
  rep(i,n)rep(j,n) {
    if (i < j) {
      id[i][j] = V++;
    }else if(i > j){
      id[i][j] = id[j][i];
    }
  }
  rep(i,n) {
    rep(j,n-1) {
      cin >> a[i][j];
      a[i][j]--;
      a[i][j] = id[i][a[i][j]];
    }
  }
  
  rep(i,n) {
    rep(j,n-1) {
      a[i][j] = toId(i,a[i][j]);
    }
    rep(j,n-2) {
      to[a[i][j+1]].push_back(a[i][j]);
    }
  }
  int ans = 0;
  rep(i,V) {
    int res = dfs(i);
    if (res == -1) {
      puts("-1");
      return 0;
    }
    ans = max(ans, res);
  }
  cout << ans << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:53:17: error: 'toId' was not declared in this scope
   53 |       a[i][j] = toId(i,a[i][j]);
      |                 ^~~~