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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#include "library/debug.cpp"

struct combination {
    ll mod;
    vector<ll> fac, finv, inv;

    combination(int n, ll m) : fac(n), finv(n), inv(n) {
        mod = m;
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < n; i++) {
            fac[i] = fac[i - 1] * i % mod;
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }

    ll c(int n, int k) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
    }

    ll p(int n, int k) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * inv[k] % mod;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll n, mod = 1e9 + 7;
    cin >> n;
    vector<ll> x(n);
    rep(i, 0, n) cin >> x[i];
    vector<ll> d(n - 1);
    rep(i, 0, n - 1) d[i] = x[i + 1] - x[i];
    combination z(300000, mod);
    vector<ll> fc(n + 1);
    rep(i, 0, n - 1) {
        fc[i] = z.p(n - 1, i + 1);
        if (i) fc[i] = (fc[i] + fc[i - 1]) % mod;
    }
    ll ans = 0;
    rep(i, 0, n) {
        ans += d[i] * fc[i];
        ans %= mod;
    }
    cout << ans << endl;

    return 0;
}


Compiler output:
a.cc:5:10: fatal error: library/debug.cpp: No such file or directory
    5 | #include "library/debug.cpp"
      |          ^~~~~~~~~~~~~~~~~~~
compilation terminated.
Language: C++

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

long long calc_dist(int N,vector<long long> x(N),vector<long long> order(N)) {
  long long ans = 0;
  for (int i = 0;i<N-1;i++) {
    ans += x.at(i+1)-x.at(i);
    x.at(i) = x.at(i+1);
  }
  return ans;
}

int main() {
  int N;
  vector<long long> x(N);
  for (int i = 0;i < N; i++) {
    cin >> x.at(i);
  }
  
  vector<long long> order(N);
  for (int i = 0; i< N;i++) {
    order.at(0) = i+1;
  }
  
  long long sum = 0;
  
  do {
    sum += calc_dist(N,x,order);
  } while (next_permutation(x.begin(),x.end()));
  
  long long frac = 1;
  for (int i = 1;i<N;i++) {
    frac *= i;
  }
  
  cout << (frac*sum)/(1000000000+7) << endl;
}

Compiler output:
a.cc:4:46: error: expected ',' or '...' before '(' token
    4 | long long calc_dist(int N,vector<long long> x(N),vector<long long> order(N)) {
      |                                              ^
a.cc: In function 'int main()':
a.cc:28:21: error: too many arguments to function 'long long int calc_dist(int, std::vector<long long int>)'
   28 |     sum += calc_dist(N,x,order);
      |            ~~~~~~~~~^~~~~~~~~~~
a.cc:4:11: note: declared here
    4 | long long calc_dist(int N,vector<long long> x(N),vector<long long> order(N)) {
      |           ^~~~~~~~~
Language: C++

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int n;
  cin>>n;
  long long x[n];
  REP(i,n){
    cin>>x[i];
  }
  long long dp[n] = {}
  long long dpsum[n] = {}
  for(long long i = n-2; i>=0; i--){
    long long temp = (n-(i+1)) * (x[n-1] - x[i]);
    temp = mod(temp);
    dp[i] = temp + dpsum[i+1];
    dp[i] = mod(dp[i]);
    dpsum[i] = dp[i] + dpsum[i+1];
    dpsum[i] = mod(dpsum[i]);
  }
  long long ans = dp[0];
  cout<<ans<<endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:78:3: error: expected ',' or ';' before 'long'
   78 |   long long dpsum[n] = {}
      |   ^~~~
a.cc:82:20: error: 'dpsum' was not declared in this scope
   82 |     dp[i] = temp + dpsum[i+1];
      |                    ^~~~~
Language: C++

#include <bits/stdc++.h>
#include "../lib/math/comb.hpp"

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

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

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

  ll n, k; cin >> n >> k;
  vll a(k);
  for(int i=0;i<k;++i) {
    cin >> a[i];
  }

  vvll dp(k+1, vll(n+1, 0));
  dp[0][0] = 1;

  Combination<MOD> comb(1000000);

  for(int i=0;i<k;++i) {
    for(int j=0;j<=n;++j) {
      for(int l=0;(l+j<=n && l<=a[i]);++l) {
        dp[i+1][j+l] += dp[i][j] * comb.C(n-j, l) % MOD * comb.C(n-l, a[i]-l) % MOD;
        dp[i+1][j+l] %= MOD;
      }
    }
  }

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

}


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

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = 200005;
const int K = 25;
int ans[N];
int f[N], invf[N], dp[K][N], a[N];
binpow(int x, int y){
    if (y == 0) return 1;
    if (y % 2) return x * binpow(x, y - 1) % mod;
    int z = binpow(x, y / 2);
    return z * z % mod;
}
int c(int n, int k){
    if (k > n) return 0;
    return f[n] * invf[k] % mod * invf[n - k] % mod;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n, k;
    cin >> n >> k;
    f[0] = 1;
    invf[0] = 1;
    for (int i = 1; i < N; i++) f[i] = f[i - 1] * i % mod;
    for (int i = 1; i < N; i++) invf[i] = binpow(f[i], mod - 2);
    for (int i = 1; i <= k; i++) cin >> a[i];
    dp[0][0] = 1;
    for (int i = 1; i <= k; i++){
        for (int j = 0; j <= n; j++){
            for (int l = 0; l <= min(j, a[i]); l++){
                dp[i][j] = (dp[i][j] + c(j, l) * c(n - l, a[i] - l) % mod * dp[i - 1][j - l]) % mod;
            }
        }
    }
    cout << dp[k][n];
}


Compiler output:
a.cc:21:1: error: ISO C++ forbids declaration of 'binpow' with no type [-fpermissive]
   21 | binpow(int x, int y){
      | ^~~~~~
a.cc:31:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   31 | main(){
      | ^~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
long long  m = 1000000007;
long long ncr(long long  n, long long  r)
{
   long long  sum=1;
  for(long long i=0;i<r;i++)
  {
    sum *=(n-i);
    sum /=(i+1);
    sum %=m;
  }
  return sum;
}
int main()
{
   long long  n,k,sum=1;
  cin>>n>>k;
  for(int i=0;i<k;i++)
  {
    cin>>ar[i];
    sum = (sum*ncr(n,ar[i]))%m;
  }
  cout<<sum<<endl;
}
  

Compiler output:
a.cc: In function 'int main()':
a.cc:21:10: error: 'ar' was not declared in this scope
   21 |     cin>>ar[i];
      |          ^~
Language: C++

#include<bits/stdc++.h>
using namespace std;
long long int m = 1000000007;
 long long int (long long int n, long long int r)
{
   long long int sum=1;
  for(int i=0;i<r;i++)
  {
    sum *=(n-i);
    sum /=(i+1);
    sum %=m;
  }
  return sum;
}
int main()
{
   long long int n,k,sum=1;
  cin>>n>>k;
  for(int i=0;i<k;i++)
  {
    cin>>ar[i];
    sum = (sum*ncr(n,ar[i]))%m;
  }
  cout<<sum<<endl;
}
  

Compiler output:
a.cc:4:17: error: expected unqualified-id before 'long'
    4 |  long long int (long long int n, long long int r)
      |                 ^~~~
a.cc:4:17: error: expected ')' before 'long'
    4 |  long long int (long long int n, long long int r)
      |                ~^~~~
      |                 )
a.cc: In function 'int main()':
a.cc:21:10: error: 'ar' was not declared in this scope
   21 |     cin>>ar[i];
      |          ^~
a.cc:22:16: error: 'ncr' was not declared in this scope
   22 |     sum = (sum*ncr(n,ar[i]))%m;
      |                ^~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
long long int m = 1000000007;
 long long int( long long int n, long long int r)
{
   long long int sum=1;
  for(int i=0;i<r;i++)
  {
    sum *=(n-i);
    sum /=(i+1);
    sum %=m;
  }
  return sum;
}
int main()
{
   long long int n,k,sum=1;
  cin>>n>>k;
  for(int i=0;i<k;i++)
  {
    cin>>ar[i];
    sum = (sum*ncr(n,ar[i]))%m
  }
  cout<<sum<<endl;
}
  

Compiler output:
a.cc:4:17: error: expected unqualified-id before 'long'
    4 |  long long int( long long int n, long long int r)
      |                 ^~~~
a.cc:4:16: error: expected ')' before 'long'
    4 |  long long int( long long int n, long long int r)
      |               ~^~~~~
      |                )
a.cc: In function 'int main()':
a.cc:21:10: error: 'ar' was not declared in this scope
   21 |     cin>>ar[i];
      |          ^~
a.cc:22:16: error: 'ncr' was not declared in this scope
   22 |     sum = (sum*ncr(n,ar[i]))%m
      |                ^~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
unsigned long long int m=1000000007;
unsigned long long int(unsigned long long int n,unsigned long long int r)
{
  unsigned long long int sum=1;
  for(int i=0;i<r;i++)
  {
    sum *=(n-i);
    sum /=(i+1);
    sum %=m;
  }
  return sum;
}
int main()
{
  unsigned long long int n,k,sum=1;
  cin>>n>>k;
  for(int i=0;i<k;i++)
  {
    cin>>ar[i];
    sum = (sum*ncr(n,ar[i]))%m
  }
  cout<<sum<<endl;
}
  

Compiler output:
a.cc:4:24: error: expected unqualified-id before 'unsigned'
    4 | unsigned long long int(unsigned long long int n,unsigned long long int r)
      |                        ^~~~~~~~
a.cc:4:24: error: expected ')' before 'unsigned'
    4 | unsigned long long int(unsigned long long int n,unsigned long long int r)
      |                       ~^~~~~~~~
      |                        )
a.cc: In function 'int main()':
a.cc:21:10: error: 'ar' was not declared in this scope
   21 |     cin>>ar[i];
      |          ^~
a.cc:22:16: error: 'ncr' was not declared in this scope
   22 |     sum = (sum*ncr(n,ar[i]))%m
      |                ^~~
Language: C++

#include <cstdio>
#include <string>
#include <iostream>
using namespace std;

typedef long long ll;

int n;
int m;
int MAX_N=100000;
int MAX_N=100000;
int p[100000];
string s[100000];
int ac[100000];
ll count[100000];

void solve();
int main(){
  scanf("%d",&n);
  scanf("%d",&m);
  for(int i=0;i<m;i++){
    scanf("%d",&p[i]);
    cin >> s[i];
  }
  for(int i=0;i<MAX_N;i++){
    ac[i]=0;
  }
  for(int i=0;i<MAX_N;i++){
    count[i]=0;
  }
  solve();
  return 0;
}

void solve(){
  for(int i=0;i<m;i++){
    int num = p[i];
    if(ac[num-1]==0){
      if(s[i]=="AC"){
        ac[num-1]=1;
      }
      else{
        count[num-1]+=1;
      }
    }
  }
  int total_ac=0;
  ll total_penalty=0;
  for(int i=0;i<n;i++){
    total_ac+=ac[i];
  }
  for(int i=0;i<n;i++){
    total_penalty=total_penalty+count[i];
  }
  printf("%d %ld\n",total_ac,total_penalty);
}

Compiler output:
a.cc:11:5: error: redefinition of 'int MAX_N'
   11 | int MAX_N=100000;
      |     ^~~~~
a.cc:10:5: note: 'int MAX_N' previously defined here
   10 | int MAX_N=100000;
      |     ^~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
const long long N=1000000007;
int main()
{
	int n,k,ans1=0,ans2=0;
	int a[1005];
	cin>>n>>k;
	for(int i=1;i<=k;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=k;i++)
	{
		if(a[i]%n==0)
        {
        ans1=a[i];	
       
		}
		
		
		else 
		{
			int p=a[i]%n
			ans2=p;
		
		}
	}
	cout<<((ans*p)%N)<<"\n";
 } 

Compiler output:
a.cc: In function 'int main()':
a.cc:25:25: error: expected ',' or ';' before 'ans2'
   25 |                         ans2=p;
      |                         ^~~~
a.cc:29:17: error: 'ans' was not declared in this scope; did you mean 'ans2'?
   29 |         cout<<((ans*p)%N)<<"\n";
      |                 ^~~
      |                 ans2
a.cc:29:21: error: 'p' was not declared in this scope
   29 |         cout<<((ans*p)%N)<<"\n";
      |                     ^
Language: C++

#include <iostream>
using namespace std;

const int MAX = 5100;
const long MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  int N,K;
  cin>>N>>K;
  vector<int>a(N);
  for(int i=0;i<N;i++)cin>>a[i];
  long ans=0;
  for(int i=0;i<N;i++){
    COMinit();
    ans=(ans+C0M(N,a[i]))%MOD;
  }
  cout<<ans<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:31:3: error: 'vector' was not declared in this scope
   31 |   vector<int>a(N);
      |   ^~~~~~
a.cc:2:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    1 | #include <iostream>
  +++ |+#include <vector>
    2 | using namespace std;
a.cc:31:10: error: expected primary-expression before 'int'
   31 |   vector<int>a(N);
      |          ^~~
a.cc:32:28: error: 'a' was not declared in this scope
   32 |   for(int i=0;i<N;i++)cin>>a[i];
      |                            ^
a.cc:36:20: error: 'a' was not declared in this scope
   36 |     ans=(ans+C0M(N,a[i]))%MOD;
      |                    ^
a.cc:36:14: error: 'C0M' was not declared in this scope; did you mean 'COM'?
   36 |     ans=(ans+C0M(N,a[i]))%MOD;
      |              ^~~
      |              COM
Language: C++

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 123;
int n, a[N], b[N], in[N];
set <array <int, 2>> st;
set <int> s;

void del(int v) {
	st.erase({-in[v], v});
	s.erase(v);
	if (s.find(a[v]) != s.end()) {
		st.erase({-in[a[v]], a[v]});
		in[a[v]]--;
		st.insert({-in[a[v]], a[v]});
	}
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		in[a[i]]++;
	}
	for (int i = 1; i <= n; i++) {
		st.insert({-in[i], i});
		s.insert(i);
	}
	for (int i = 1; i <= n - 1; i++) {
		int V = n - i + 1;
		if (-(*st.begin())[0] == V - 1 && -(*next(st.begin()))[0] == V - 1)
			return cout << -1, 0;
		if (V == 3) {
			array <int, 3> t;
			int m = 0;
			for (int j : s) t[m++] = j;
			for (int j = 0; j < 3; j++) {
				int v = t[j], u = t[(j + 1) % 3], w = t[(j + 2) % 3];
				if (a[b[i - 1]] != v && in[u] < V - 1 && in[w] < V - 1 && (a[u] != w || a[w] != u))
					b[i] = v, break;
			}
			if (!b[i]) return cout << -1, 0;
		}	else {
			if (-(*st.begin())[0] == V - 1) b[i] = (*st.begin())[1];
			else {
				b[i] = *s.begin();
				if (a[b[i - 1]] == b[i])
					b[i] = *next(s.begin());
			}
		}
		if (a[b[i - 1]] == b[i]) return cout << -1, 0;
		del(b[i]);
	}
	for (int i = 1; i <= n - 1; i++)
		cout << b[i] << ' ';
	cout << *s.begin();
}


Compiler output:
a.cc: In function 'int main()':
a.cc:54:51: error: expected primary-expression before 'break'
   54 |                                         b[i] = v, break;
      |                                                   ^~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
struct D{
    int cc,id;
    bool operator<(const D&a) const{
        if(cc==a.cc) return id<a.id;
        return cc>a.cc;
    }
};
int main()
{
    int n;
    cin>>n;
    vi a(n+1);
    vi cnt(n+1);
    for(int i=1;i<=n;i++) cin>>a[i];
    vi ans(n);
    if(n<=2)
        cout<<"-1\n";
    else{
        set<D> all;
        set<int> alln;
        for(int i=n;i>=1;i--)
            cnt[a[i]]++,alln.insert(i);
        for(int i=1;i<=n;i++)
            all.insert({cnt[i],i});
        int pre=0;
        for(int i=1;i<=n;i++)
        {
            if((*all.begin()).cc==n-i)
                ans[i-1]=(*all.begin()).id;
            else {
                for(auto u:alln){
                    if(u!=a[pre])
                    {
                        ok=1;
                        ans[i-1]=u;
                        break;
                    }
                }
            }
            assert(ans[i-1]);
            all.erase({cnt[ans[i-1]],ans[i-1]});
            alln.erase(ans[i-1]);
            int tar=a[ans[i-1]];
            if(alln.count(tar))
            {
                all.erase({cnt[tar],tar});
                cnt[tar]--;
                all.insert({cnt[tar],tar});
            }
            pre=ans[i-1];
            //dbg(i);
            //for(auto u:all) dbg(u.cc,u.id);
        }
        print(ans);
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:69:25: error: 'ok' was not declared in this scope
   69 |                         ok=1;
      |                         ^~
Language: C++

#include<cstdio>
#include<queue>
#include<vector>
using namespace std;
const int N=1e5+5;
int n,a[N];
vector<int>v;
priority_queue<int,vector<int>,greater<int> >q;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    v.push_back(1);
    for(int i=2;i<=n;i++) q.push(i);
    for(int i=2;i<=n;i++)
    {
        int t=v.back();
        if(a[t]!=q.top())
        {
            v.push_back(q.top());q.pop();
        }
        else if(q.size()>=2)
        {
            int s=q.top();q.pop();
            v.push_back(q.top());q.pop();
            q.push(s);
        }
    }
    assert(q.size()<=1);
    if(q.size())
    {
        int flag=-1;
        for(int i=v.size()-1;i>=0;i--)
        {
            if(a[q.top()]!=v[i]&&(i==0||a[v[i-1]]!=q.top()))
            {
                flag=i;break;
            }
        }
        if(flag==-1) {printf("-1\n");return 0;}
        for(int i=0;i<flag;i++)
            printf("%d ",v[i]);
        printf("%d ",q.top());
        for(int i=flag;i<v.size();i++)
            printf(i==v.size()-1?"%d\n":"%d ",v[i]);
    }
    else
    {
        for(int i=0;i<v.size();i++)
            printf(i==v.size()-1?"%d\n":"%d ",v[i]);
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:29:5: error: 'assert' was not declared in this scope
   29 |     assert(q.size()<=1);
      |     ^~~~~~
a.cc:3:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
    2 | #include<queue>
  +++ |+#include <cassert>
    3 | #include<vector>
Language: C++

/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
//reason of WA:The same out edge should be combined. 
#include<bits/stdc++.h>
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n;
int ban[100005];
vector<int>out[100005];
int pos[100005];
bool check(vector<int>ans){
	for(int i=0;i+1<ans.size();i++){
		if(ban[ans[i]]==ans[i+1])return false;
	}
	return true;
}
map<int,int>cnt;
set<int>have;
vector<int>ans;
void del(int x){
	cnt[ban[x]]--;if(!cnt[ban[x]])cnt.erase(ban[x]);
	have.erase(x);pos[ban[x]]++;
	if(pos[ban[x]]!=out[ban[x]].size())have.insert(out[ban[x]][pos[ban[x]]]);
}
int cur;
bool can_put(int x){
	if(ans.size()&&ban[ans.back()]==x)return false;
	have.erase(x);//cnt[ban[x]]--;if(!cnt[ban[x]])cnt.erase(ban[x]);
	bool ret=cnt.size()==2&&(cnt.rbegin()->second==cur-1&&have.count(cnt.rbegin()->first)||(cnt.begin()->second==cur-1&&have.count(cnt.begin()->first)));
	ret||=(cnt.size()==1&&have.count(cnt.begin()->first));//cnt[ban[x]]++;
	have.insert(x);
	return 1^(ret);
}
int perm[6];
int main(){
	cin>>n;cur=n;
	for(int i=1;i<=n;i++)cin>>ban[i];
	for(int i=1;i<=n;i++)cnt[ban[i]]++,out[ban[i]].push_back(i);
	for(int i=1;i<=n;i++)if(out[i].size())have.insert(out[i][0]);
	for(int i=1;i<=n-5;i++){
		if(can_put(*have.begin())){
			ans.push_back(*have.begin());
			del(*have.begin());
		}else{
			ans.push_back(*next(have.begin()));
			del(*next(have.begin()));
		}
		cur--;
	}
//	for(auto x:ans)cerr<<x<<" ";cerr<<endl;
	const int sz=min(n,5);
	const int base=max(0,n-5);
	for(int i=1;i<=sz;i++)perm[i]=i;
	vector<int>vec(have.begin(),have.end());
	for(int i=1;i<=n;i++)for(int j=pos[i]+1;j<out[i].size();j++)vec.push_back(out[i][j]);
	vector<int>pre=ans;for(int i=1;i<=sz;i++)ans.push_back(n+1);
	do{
		vector<int>tmp=pre;
		for(int i=1;i<=sz;i++)tmp.push_back(vec[perm[i]-1]);
		if(check(tmp))ans=min(ans,tmp);
	}while(next_permutation(perm+1,perm+sz+1));
	if(ans.back()==n+1){
		cout<<-1<<endl;
		return 0;
	}
	for(auto x:ans)cout<<x<<" ";cout<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'bool can_put(int)':
a.cc:52:14: error: expected primary-expression before '=' token
   52 |         ret||=(cnt.size()==1&&have.count(cnt.begin()->first));//cnt[ban[x]]++;
      |              ^
Language: C++

/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n;
int ban[100005];
bool check(vector<int>ans){
	for(int i=0;i+1<ans.size();i++){
		if(ban[ans[i]]==ans[i+1])return false;
	}
	return true;
}
map<int,int>cnt;
set<int>have;
vector<int>ans;
void del(int x){
	cnt[ban[x]]--;if(!cnt[ban[x]])cnt.erase(ban[x]);have.erase(x);
}
bool can_put(int x){
	if(ans.size()&&ban[ans.back()]==x)return false;
	have.erase(x);cnt[ban[x]]--;if(!cnt[ban[x]])cnt.erase(ban[x]);
	bool ret=cnt.size()==2&&((cnt.begin()->second==1&&have.count(cnt.rbegin()->first)||(cnt.rbegin()->second==1&&have.count(cnt.begin()->first)));
	cnt[ban[x]]++;have.insert(x);
	return 1^ret;
}
int perm[6];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>ban[i];
	for(int i=1;i<=n;i++)cnt[ban[i]]++;
	for(int i=1;i<=n;i++)have.insert(i);
	for(int i=1;i<=n-5;i++){
		if(can_put(*have.begin())){
			ans.push_back(*have.begin());
			del(*have.begin());
		}else{
			ans.push_back(*next(have.begin()));
			del(*next(have.begin()));
		}
	}
	for(auto x:ans)cerr<<x<<" ";cerr<<endl;
	const int sz=min(n,5);
	const int base=max(0,n-5);
	for(int i=1;i<=sz;i++)perm[i]=i;
	vector<int>vec(have.begin(),have.end());
	vector<int>pre=ans;for(int i=1;i<=sz;i++)ans.push_back(n+1);
	do{
		vector<int>tmp=pre;
		for(int i=1;i<=sz;i++)tmp.push_back(vec[perm[i]-1]);
		if(check(tmp))ans=min(ans,tmp);
	}while(next_permutation(perm+1,perm+sz+1));
	if(ans.back()==n+1){
		cout<<-1<<endl;
		return 0;
	}
	for(auto x:ans)cout<<x<<" ";cout<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'bool can_put(int)':
a.cc:45:150: error: expected ')' before ';' token
   45 |         bool ret=cnt.size()==2&&((cnt.begin()->second==1&&have.count(cnt.rbegin()->first)||(cnt.rbegin()->second==1&&have.count(cnt.begin()->first)));
      |                                 ~                                                                                                                    ^
      |                                                                                                                                                      )
Language: C++

/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n;
int ban[100005];
bool check(vector<int>ans){
	for(int i=0;i+1<ans.size();i++){
		if(ban[ans[i]]==ans[i+1])return false;
	}
	return true;
}
int cnt[100005],hv;
set<int>have;
vector<int>ans;
void del(int x){
	cnt[ban[x]]--;if(!cnt[ban[x]])hv--;have.erase(x);
}
bool can_put(int x){
	if(ans.size()&&ban[ans.back()]==x)return false;
	cnt[ban[x]]--;if(!cnt[ban[x]])hv--;
	bool ret=hv>1;
	cnt[ban[x]]++;if(cnt[ban[x]]==1)hv++;
	return ret;
}
int perm[6];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>ban[i];
	for(int i=1;i<=n;i++)cnt[ban[i]]++;
	for(int i=1;i<=n;i++)if(cnt[i])hv++;
	for(int i=1;i<=n;i++)have.insert(i);
	for(int i=1;i<=n-5;i++){
		if(can_put(*have.begin())){
			ans.push_back(*have.begin());
			del(*have.begin());
		}else{
			ans.push_back(*next(have.begin()));
			del(*next(have.begin()));
		}
	}
	for(auto x:ans)cerr<<x<<" ";cerr<<endl;
	const int sz=min(n,5);
	const int base=max(0,n-5);
	for(int i=1;i<=sz;i++)perm[i]=i;
	vector<int>pre=ans;for(int i=1;i<=sz;i++)ans.push_back(n+1);
	do{
		vector<int>tmp=pre;
		for(int i=1;i<=sz;i++)tmp.push_back(a[base+perm[i]]);
		if(check(tmp))ans=min(ans,tmp);
	}while(next_permutation(perm+1,perm+sz+1));
	for(auto x:ans)cout<<x<<" ";cout<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:72:53: error: 'a' was not declared in this scope
   72 |                 for(int i=1;i<=sz;i++)tmp.push_back(a[base+perm[i]]);
      |                                                     ^
Language: C++

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

int main() {
    int n;
    std::cin >> n;

    std::vector<int> xs(n), cnt(n, 0);
    for (auto& x : xs) {
        std::cin >> x;
        ++cnt[--x];
    }

    std::set<int> ss;
    for (int x = 0; x < n; ++x) ss.insert(x);
  	// まだ決まっていない数の集合

    std::vector<int> ans;
    ans.reserve(n);

    int out = -1;  // 直前の数に指されている数
    while (ss.size() > 6) {
        int x = *ss.begin();
        if (x == out) {
          	// 指されていたら次へ
            if (ss.size() == 1) {
                std::cout << -1 << std::endl;
                return;
            } else {
                x = *(++ss.begin());
            }
        }

        int k = ss.size();
        int y = xs[x];
        if (ss.count(y) && cnt[y] == k - 1) x = y;
      	// y以外がyを指している場合

        ss.erase(x);
        ans.push_back(x);
        --cnt[xs[x]];
        out = xs[x];
    }

  	// 最後の全探索
    std::vector<int> rem(ss.begin(), ss.end());
    do {
        auto tmpans = ans;
        for (auto x : rem) ans.push_back(x);

        bool ok = true;
        for (int i = 0; i < n - 1; ++i) {
            if (ans[i + 1] == xs[ans[i]]) ok = false;
        }

        if (ok) {
            for (auto x : ans) std::cout << x + 1 << " ";
            std::cout << std::endl;
            return;
        }

        ans = tmpans;
    } while (std::next_permutation(rem.begin(), rem.end()));

    std::cout << -1 << std::endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:30:17: error: return-statement with no value, in function returning 'int' [-fpermissive]
   30 |                 return;
      |                 ^~~~~~
a.cc:61:13: error: return-statement with no value, in function returning 'int' [-fpermissive]
   61 |             return;
      |             ^~~~~~
Language: C++

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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

const int MOD = 1e9 + 7;

ll C[1010][1010];

int main() {
    for (int x = 0; x < 1010; x++) {
        C[x][0] = 1;
        for (int y = 1; y <= x; y++)
            C[x][y] = (C[x - 1][y - 1] + C[x - 1][y]) % MOD;
    }
    
    int N, X;
    cin >> N >> X;
    vector<int> a(X + 1);
    while (N--) {
        int l; cin >> l;
        a[l]++;
    }
    vector<vector<ll>> dp(X + 2, vector<ll>(X + 1));
    dp[0][0] = 1;
    for (int l = X; l >= 0; l--) {
        vector<vector<ll>> _dp(X + 2, vector<ll>(X + 1));
        for (int k = X + 1; k >= 0; k--) rep(x, X + 1) rep(dk, X + 1) {
            int _k = k + dk, _x = x + dk * l;
            if (_k + _x - 1 > X) break;
            ll z = dp[k][x] * C[_k][dk] % MOD;
            _dp[_k][_x] = (_dp[_k][_x] + z) % MOD;
        }
        dp = _dp;
        rep(k, X + 2) rep(x, X + 1) {
            int _k = k + dk, _x = x + dk * l;
            if (_k + _x - 1 > X) break;
            int y = _x - _k * (l - 1);
            ll z = dp[k][x] * C[_k][dk] % MOD;
            dp[k][x] = z;
        }
    }
    ll ans = 0;
    rep(k, X + 2) rep(x, X + 1) if (k + x - 1 == X) {
        // cout << k << ' ' << x << ' ' << dp[k][x] << endl;
        ll z = dp[k][x];
        if (k % 2 == 0) z *= -1; 
        ans = (ans + z) % MOD;
    }
    cout << (ans + MOD) % MOD << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:41:26: error: 'dk' was not declared in this scope; did you mean '_k'?
   41 |             int _k = k + dk, _x = x + dk * l;
      |                          ^~
      |                          _k
a.cc:42:22: error: '_x' was not declared in this scope; did you mean '_k'?
   42 |             if (_k + _x - 1 > X) break;
      |                      ^~
      |                      _k
a.cc:43:21: error: '_x' was not declared in this scope; did you mean '_k'?
   43 |             int y = _x - _k * (l - 1);
      |                     ^~
      |                     _k
Language: C++

#include <bits/stdc++.h>

using namespace std;

int n;

vector<int> a(100001),b(100001);

int check(int m){
    for(int i = n-m;i < n;i++){
        if(i == 0) continue;
        if(a[b[i-1]-1] == b[i]) return false;
    }
    return true;
}

void solve3(){
    if(check(3)) return;
    swap(b[n-1],b[n-2]);
    if(check(3)) return;
    swap(b[n-1],b[n-2]);
    swap(b[n-3],b[n-2]);
    if(check(3)) return;
    swap(b[n-1],b[n-2]);
    if(check(3)) return;
    swap(b[n-3],b[n-2]);
    swap(b[n-1],b[n-2]);
    if(check(3)) return;
    swap(b[n-1],b[n-2]);
    if(check(3)) return;
}

int used[100001];
int c[100001];
int d[100001];
int dfs(int p,int s){
    if(p == n){
        return check(4);
    }
    for(int i = 0;i < s;i++){
        if(used[i]) continue;
        used[i] = 1;
        b[p] = c[i];
        if(dfs(p+1,s)) return 1;
        used[i] = 0;
    }
    return 0;
}

void solve4(){
    for(int i = 0;i < 4;i++){
        c[i] = b[n-4+i];
    }
    dfs(n-4,4);
}

void solve(){
    int i,j;
    string str;
    cin >> n;
    for(i = 0;i < n;i++){
        cin >> a[i];
        d[a[i]]++;
    }
    if(n == 2){
        cout << -1 << endl;
        return;
    }
    if(n == 3){
        b[0] = 1;
        b[1] = 2;
        b[2] = 3;
        solve3();
        printf("%d %d %d\n",b[0],b[1],b[2]);
        return;
    }
    priority_queue<int, vector<int>, greater<int> > q;
    for(i = 1;i <= n;i++) q.push(i);
    int v = 0;
    for(i = 0;i < n-4;i++){
        if(d[a[q.top()-1]] == n-i-1){
            b[i] = a[q.top()-1];
            for(j = i+1;j < n;j++){
                b[j] = q.top();
                q.pop();
                if(b[i] == b[j]) j--;
            }
            for(j = 0;j < n;j++) cout << b[j] << ' ';
            cout << endl;]
            return;
        }
        if(q.top() == v){
            q.pop();
            b[i] = q.top();
            q.pop();
            q.push(v);
        }
        else{
            b[i] = q.top();
            q.pop();
        }
        v = a[b[i]-1];
        d[v]--;
    }
    b[i++] = q.top();q.pop();
    b[i++] = q.top();q.pop();
    b[i++] = q.top();q.pop();
    b[i++] = q.top();q.pop();
    solve4();
    for(i = 0;i < n;i++){
        cout << b[i] << ' ';
    } cout << endl;
}

int main(){
    solve();
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:89:26: error: expected primary-expression before ']' token
   89 |             cout << endl;]
      |                          ^
Language: C++

#include <bist/stdc++.h>
using namespace std;
int main()
{
	int n;
	scanf("%i",&n);
	vector<int> a(n+1);
	for(int i=1;i<=n;i++) scanf("%i",&a[i]);
	vector<int> was(n+1,0);
	vector<int> ans;
	for(int i=1;i<=n;i++) if(!was[i])
	{
		int j=i;
		vector<int> v;
		while(!was[j]) v.push_back(j),was[j]=1,j=a[j];
		reverse(v.begin(),v.end());
		for(int x:v) ans.push_back(x);
	}
	if(n==2 && a[1]==2 && a[2]==1) return 0*printf("-1\n");
	for(int x:ans) printf("%i ",x);
	return 0;
}

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

#include <bits/stdc++.h>
#include "data_structure/segment_tree.hpp"
#include "monoids/max.hpp"
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) std::begin(x), std::end(x)
using namespace std;

vector<int> solve(int n, const vector<int> & a) {
    if (n == 2) return vector<int>();

    vector<int> freq(n);
    for (int a_i : a) {
        ++ freq[a_i];
    }
    segment_tree<max_monoid<int> > segtree(n);
    REP (i, n) {
        segtree.unsafe_point_set(i, freq[i]);
    }
    segtree.unsafe_rebuild();

    vector<int> b;
    set<int> available;
    vector<int> cur;
    REP (i, n) {
        available.insert(i);
    }
    ([go = [&](auto go) {
        if (available.empty()) {
            b = cur;
            return;
        }
        auto use = [&](int i) {
            if (not cur.empty() and a[cur.back()] == i) return;
            available.erase(i);
            cur.push_back(i);
            segtree.point_set(i, segtree.point_get(i) - n);
            segtree.point_set(a[i], segtree.point_get(a[i]) - 1);
// cerr << "push " << i << endl;
            go(go);
// if (b.empty()) cerr << "pop " << i << endl;
            segtree.point_set(i, segtree.point_get(i) + n);
            segtree.point_set(a[i], segtree.point_get(a[i]) + 1);
            cur.pop_back();
            available.insert(i);
        };
        if (segtree.range_get(0, n) == (int)available.size() - 1) {
            for (auto it = available.begin(); it != available.end(); ++ it) {
                int i = *it;
                if (segtree.range_get(0, n) == segtree.point_get(i)) {
                    use(i);
                }
                it = available.find(i);
            }
            return;
        }
        for (auto it = available.begin(); it != available.end(); ++ it) {
            int i = *it;
            use(i);
            it = available.find(i);
            if (not b.empty()) break;
        }
    }]() { return go(go); })();
    assert (not b.empty());
    return b;
}

int main() {
    int n; scanf("%d", &n);
    vector<int> a(n);
    REP (i, n) {
        scanf("%d", &a[i]);
        -- a[i];
    }
    auto b = solve(n, a);
    if (b.empty()) {
        printf("%d\n", -1);
    } else {
        REP (i, n) {
            printf("%d%c", b[i] + 1, i + 1 < n ? ' ' : '\n');
        }
    }
    return 0;
}


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

#include <iostream>
#include <string>
#include <map>
#include <set>
#define llint long long
#define mod 1000000007

using namespace std;

llint n;
llint p[100005];
set<llint> S;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> p[i];
	
	if(n == 2){
		cout << -1 << endl;
		return 0;
	}
	
	for(int i = 1; i <= n; i++) S.insert(i);
	
		set<llint> T;
			for(auto it2 = S.begin(); it2 != S.end(); it2++) T.insert(*it2);
			T.erase(nv);
			map<llint, llint> mp;
			for(auto it2 = T.begin(); it2 != T.end(); it2++) mp[p[*it2]]++;
	if(p[nv] != v && mp[p[nv]] >= (llint)S.size()-2){
		cout << -1 << endl;
		return 0;
	}
	
	llint v = 0;
	for(int i = 1; i <= n; i++){
		auto it = S.begin();
		while(1){
			llint nv = *it;
			cout << v << " " << nv << endl;
			
			bool flag = true;
			if(p[v] == nv) flag = false;
			//cout << "*" << endl;
			//cout << "?" << flag << endl;
			
			set<llint> T;
			for(auto it2 = S.begin(); it2 != S.end(); it2++) T.insert(*it2);
			T.erase(nv);
			map<llint, llint> mp;
			for(auto it2 = T.begin(); it2 != T.end(); it2++) mp[p[*it2]]++;
			if(p[nv] != v && mp[p[nv]] >= (llint)S.size()-2) flag = false;
		
			/*if((llint)S.size() == 4){
				set<llint> T;
				for(auto it2 = S.begin(); it2 != S.end(); it2++) T.insert(*it2);
				T.erase(nv);
				
				map<llint, llint> mp;
				for(auto it2 = T.begin(); it2 != T.end(); it2++) mp[p[*it2]]++;
				cout << p[nv] << mp[p[nv]] << endl;
				if(p[nv] != v && mp[p[nv]] >= 2) flag = false;
			}
			cout << "?" << flag << endl;
			
			if((llint)S.size() == 3){
				
				set<llint> T;
				for(auto it2 = S.begin(); it2 != S.end(); it2++) T.insert(*it2);
				T.erase(nv);
				
				auto it2 = T.begin(); llint x = *it2;
				it2++; llint y = *it2;
				if(p[x] == y && p[y] == x) flag = false;
			}
			cout << "?" << flag << endl;*/
			
			if((llint)S.size() == 2){
				set<llint> T;
				for(auto it2 = S.begin(); it2 != S.end(); it2++) T.insert(*it2);
				T.erase(nv);
				
				llint x = *T.begin();
				if(p[nv] == x) flag = false;
				
			}
			
			if(!flag){
				it++;
				continue;
			}
			
			cout << nv << " ";
			S.erase(nv);
			v = nv;
			break;
		}
	}
	cout << endl;
	
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:31:33: error: 'nv' was not declared in this scope; did you mean 'n'?
   31 |                         T.erase(nv);
      |                                 ^~
      |                                 n
a.cc:34:21: error: 'v' was not declared in this scope
   34 |         if(p[nv] != v && mp[p[nv]] >= (llint)S.size()-2){
      |                     ^
Language: C++

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

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

signed main() {
  int n;cin>>n;
  vector<int> p(n);
  rep(i, n) {
    cin>>p[i];
  }
  dump(p);

  vector<int> ans(n);
  rep(i, n){
    ans[i] = i+1;
  }

  int pre = 1;
  rep(i, 1, n-1){
    while (a[i]==p[pre]){
      swap(a[i], a[i+1]);
      pre = a[i];
      i++;
      if (i==n-1) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  dump(a);

  rep(i, sz(a)) cout << a[i] << (i!=sz(a)-1 ? " " : "\n");

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:67:12: error: 'a' was not declared in this scope
   67 |     while (a[i]==p[pre]){
      |            ^
a.cc:79:13: error: 'a' was not declared in this scope
   79 |   rep(i, sz(a)) cout << a[i] << (i!=sz(a)-1 ? " " : "\n");
      |             ^
a.cc:12:48: note: in definition of macro 'repi'
   12 | #define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
      |                                                ^
a.cc:10:39: note: in expansion of macro '_rep'
   10 | #define _overload3(_1,_2,_3,name,...) name
      |                                       ^~~~
a.cc:79:3: note: in expansion of macro 'rep'
   79 |   rep(i, sz(a)) cout << a[i] << (i!=sz(a)-1 ? " " : "\n");
      |   ^~~
a.cc:79:10: note: in expansion of macro 'sz'
   79 |   rep(i, sz(a)) cout << a[i] << (i!=sz(a)-1 ? " " : "\n");
      |          ^~
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

int main() {
    int n;
    cin >> n;
    int a[n], b[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) b[i] = i+1;
    bool flag2 = false;
    for (int i = n-2; i > 0; i--) {
        if (a[i] == b[i+1]) {
            // swap(b[i], b[i-1]);
            flag2 = false;
            for (int j = i-1; j > 0; j--) {
                if (a[b[j]-1] != a[i]) {
                    flag2 = true;
                    swap(b[j], b[i]);
                }
                if (flag2) {
                    flag = false;
                    break;
                }
            }
        }
    }
    bool flag = true;
    for (int i = 0; i < n-1; i++) {
        if (a[b[i]-1] == b[i+1]) flag = false;
    }
    if (flag) {
        for (int i = 0; i < n; i++) {
            cout << b[i];
            if (i < n-1) cout << ' ';
        }
        cout << endl;
    } else {
        cout << -1 << endl;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:24:21: error: 'flag' was not declared in this scope; did you mean 'flag2'?
   24 |                     flag = false;
      |                     ^~~~
      |                     flag2
Language: C++

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

int main() {
    int N;
    cin >> N;
    vector<int>a(N+1, 0);
    for (int i = 1; i <= N; ++i) {
        cin >> a[i];
    }
    if (N == 2) {
        cout << -1 << "\n";
        return 0;
    }

    multiset<int>se;
    set<int>se2;
    vector<int>in(N+1, 0);
    for (int i = 1; i <= N; ++i) {
        in[a[i]]++;
    }
    for (int i = 1; i <= N; ++i) {
        se.insert(in[i]);
        se2.insert(i);
    }

    int cur = 0;
    for (int i = 1; i <= N; ++i) {
        auto iter = se.end(); iter--;
        int nxt;
        for (int x: se2) {
            if (x != a[cur]) {
                nxt = x;
                break;
            }
        }

        if (se2.size() == 3) {
            int p = 0, q = 0;
            for (int x: se2) {
                if (x == nxt) continue;
                if(p == 0) p = x;
                else q = x;
            }
            if (p == a[q] && q == a[p]) {
                if (in[p] == 1 && in[q] == 1) {
                    auto iter3 = se.find(in[p]);
                    se.erase(iter2);
                    in[p]++;
                    se.insert(in[p]);
                }
            }
        }

        if (*iter == N - i) {
            for (int x: se2) {
                if (in[x] == N - i) {
                    nxt = x;
                    break;
                }
            }
        }

        cur = nxt;
        se2.erase(nxt);
        auto iter1 = se.find(in[nxt]);
        se.erase(iter1);

        if (se.count(a[nxt])) {
            auto iter2 = se.find(in[a[nxt]]);
            se.erase(iter2);
            in[a[nxt]]--;
            se.insert(in[a[nxt]]);
        }
        cout << nxt << " ";
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:49:30: error: 'iter2' was not declared in this scope; did you mean 'iter3'?
   49 |                     se.erase(iter2);
      |                              ^~~~~
      |                              iter3