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

#include<iostream>
using namespace std;
#define R(i,n) for(int i=0;i<n;i++)
int n,a=1e9,c[2][20],p[1<<18][51];main(){cin>>n;R(i,n*2)cin>>c[i/n][i%n];fill(p[1],p[1<<n],1e9);R(B,1<<n){int o=0,d[n];R(i,n)if(~B&1<<i)d[i]=o++;R(i,n){int k=c[abs(i-n+o)%2][i];R(j,k+1)int &t=p[B|1<<i][k],t=min(t,p[B][j]+d[i]);}}R(i,51)a=min(a,p[(1<<n)-1][i]);cout<<(a>1e8?-1:a);}

Compiler output:
a.cc:4:35: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    4 | int n,a=1e9,c[2][20],p[1<<18][51];main(){cin>>n;R(i,n*2)cin>>c[i/n][i%n];fill(p[1],p[1<<n],1e9);R(B,1<<n){int o=0,d[n];R(i,n)if(~B&1<<i)d[i]=o++;R(i,n){int k=c[abs(i-n+o)%2][i];R(j,k+1)int &t=p[B|1<<i][k],t=min(t,p[B][j]+d[i]);}}R(i,51)a=min(a,p[(1<<n)-1][i]);cout<<(a>1e8?-1:a);}
      |                                   ^~~~
a.cc: In function 'int main()':
a.cc:4:206: error: conflicting declaration 'int t'
    4 | int n,a=1e9,c[2][20],p[1<<18][51];main(){cin>>n;R(i,n*2)cin>>c[i/n][i%n];fill(p[1],p[1<<n],1e9);R(B,1<<n){int o=0,d[n];R(i,n)if(~B&1<<i)d[i]=o++;R(i,n){int k=c[abs(i-n+o)%2][i];R(j,k+1)int &t=p[B|1<<i][k],t=min(t,p[B][j]+d[i]);}}R(i,51)a=min(a,p[(1<<n)-1][i]);cout<<(a>1e8?-1:a);}
      |                                                                                                                                                                                                              ^
a.cc:4:191: note: previous declaration as 'int& t'
    4 | int n,a=1e9,c[2][20],p[1<<18][51];main(){cin>>n;R(i,n*2)cin>>c[i/n][i%n];fill(p[1],p[1<<n],1e9);R(B,1<<n){int o=0,d[n];R(i,n)if(~B&1<<i)d[i]=o++;R(i,n){int k=c[abs(i-n+o)%2][i];R(j,k+1)int &t=p[B|1<<i][k],t=min(t,p[B][j]+d[i]);}}R(i,51)a=min(a,p[(1<<n)-1][i]);cout<<(a>1e8?-1:a);}
      |                                                                                                                                                                                               ^
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;
  int a[n], b[n];
  REP(i,n){
    cin>>a[i]>>b[i];
  }
  vector<vector<long long>> dp(1<<n, vector<long long>(n, INF));
  REP(i,n){
    dp[0][i] = 0;
  }
  REP(s, (1<<n)){
    REP(i,n){
      if(s & (1<<i))continue;
      long long cnt = 0;
      REP(j,n){
        if(!(s & (1<<i)))continue;
        if(j < i)continue;
        cnt++;
      }
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:91:2: error: expected '}' at end of input
   91 | }
      |  ^
a.cc:81:17: note: to match this '{'
   81 |   REP(s, (1<<n)){
      |                 ^
a.cc:91:2: error: expected '}' at end of input
   91 | }
      |  ^
a.cc:69:11: note: to match this '{'
   69 | int main(){
      |           ^
Language: C

#include <stdio.h>
#include <stdint.h>
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define LL int64_t
#define REP(i,n) for (LL (i) = 0; (i) < (n); i++)
#define REPr(i,n) for (LL (i) = (n); (i) --> 0;)
#define INF 1e9
int DP[1<<18][18];
int A[18][2];

int bitcount(LL bits) {
    bits = (bits & 0x5555555555555555) + (bits >> 1 & 0x5555555555555555);
    bits = (bits & 0x3333333333333333) + (bits >> 2 & 0x3333333333333333);
    bits = (bits & 0x0f0f0f0f0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f0f0f0f0f);
    bits = (bits & 0x00ff00ff00ff00ff) + (bits >> 8 & 0x00ff00ff00ff00ff);
    bits = (bits & 0x0000ffff0000ffff) + (bits >>16 & 0x0000ffff0000ffff);
    return (bits & 0x00000000ffffffff) + (bits >>32 & 0x00000000ffffffff);
}

int main() {
    int N;
    LL ans = INF;
    scanf_s("%d", &N);
    REP(i, N) scanf_s("%d", &A[i][0]);
    REP(i, N) scanf_s("%d", &A[i][1]);

    REP(i, 1<<N) REP(j, N) DP[i][j] = INF;
    REP(j, N) DP[1<<j][j] = 0;

    REP(i, 1<<N) {
        REP(j, N) {
            if (DP[i][j] >= INF) continue;
            int ic = bitcount(i);
            int a = A[j][(j^ic^1)&1];
            REP(k, N) {
                if (i&(1<<k) || a > A[k][(k^ic)&1]) continue;
                int t = ic - bitcount(((1<<k)-1)&i);
                DP[i|(1<<k)][k] = MIN(DP[i|(1<<k)][k], DP[i][j]+t);
            }
        }
    }

    REP(j, N) ans = MIN(ans, DP[(1<<N)-1][j]);
    if (ans >= INF) ans = -1;
    printf("%lld\n", ans);
    return 0;
}

Compiler output:
main.c: In function 'main':
main.c:24:5: error: implicit declaration of function 'scanf_s'; did you mean 'scanf'? [-Wimplicit-function-declaration]
   24 |     scanf_s("%d", &N);
      |     ^~~~~~~
      |     scanf
Language: C++

// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

#ifdef __GNUC__
#define popcount __builtin_popcount
#elif _MSC_VER >= 1400
#include <intrin.h>
#define popcount __popcnt
#else
static inline int popcount(unsigned int b) {
	b = (b & 0x55555555) + (b >> 1 & 0x55555555);
	b = (b & 0x33333333) + (b >> 2 & 0x33333333);
	b = (b & 0x0F0F0F0F) + (b >> 4 & 0x0F0F0F0F);
	b += b >> 8;
	return (b + (b >> 16)) & 0x3F;
}
#endif

int main(int argc, char* argv[]) {
#ifdef _MSC_VER
	while (true)
#endif
	{
		int n = 0;
		cin >> n;
		if (n <= 0) return 0;
		vector<int> a[2];
		for (int j = 0; j < 2; ++j) {
			a[j] = vector<int>(n);
			for (int i = 0; i < n; ++i) {
				cin >> a[j][i];
			}
		}
		int dp[1 << 18][18];
		memset(dp, 0x7f, sizeof(dp));
		for (int c = 0; c < n; ++c) {
			dp[1 << c][c] = 0;
		}
		for (int b = 1; b < (1 << n); ++b) {
			int digits = popcount(b);
			for (int c = 0; c < n; ++c) {
				if (dp[b][c] >= (1 << 30)) continue;
				int p = a[(digits + c - 1) & 1][c];
				for (int d = 0; d < n; ++d) {
					int q = a[(digits + d) & 1][d];
					if (p > q) continue;
					if (b & (1 << d)) continue;
					int cost = dp[b][c] + popcount(b & ~((1 << d) - 1));
					int e = b | (1 << d);
					dp[e][d] = min(dp[e][d], cost);
				}
			}
		}
		int ans = 1 << 30;
		for (int c = 0; c < n; ++c) {
			ans = min(ans, dp[(1 << n) - 1][c]);
		}
		cout << (ans < (1 << 30) ? ans : -1) << endl;
	}
	return 0;
}


Compiler output:
a.cc: In function 'int main(int, char**)':
a.cc:41:17: error: 'memset' was not declared in this scope
   41 |                 memset(dp, 0x7f, sizeof(dp));
      |                 ^~~~~~
a.cc:7:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    6 | #include <vector>
  +++ |+#include <cstring>
    7 |
Language: C++

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
template<class T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> B[i];
    
    vector<vector<int>> dp((1<<N)+1, vector<int>(55, INF));
    dp[0][0] = 0;
    
    for (int bit = 0; bit < (1<<N); bit++) {
        if (dp[bit][s] >= INF) continue;
        int done = 0;
        for (int i = 0; i < N; i++) if (bit&(1<<i)) done++;
        int iter = done;
        vector<pair<int, int>> data;
        for (int i = 0; i < N; i++) {
            if (!(bit&(1<<i))) data.emplace_back(i, iter++);
        }
        
        for (int s = 0; s <= 50; s++) {
            for (auto p : data) {
                // p.first : もとのindex
                // p.second : ソート後のindex
                int value = -1;
                if (abs(done-p.first)%2 == 0) value = A[p.first];
                else value = B[p.first];
                if (value >= s) {
                    chmin(dp[bit|(1<<p.first)][value], dp[bit][s] + abs(done-p.second));
                }
            }
        }
    }

    int ans = INF;
    for (int s = 0; s <= 50; s++) chmin(ans, dp[(1<<N)-1][s]);
    cout << ((ans == INF) ? -1 : ans) << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:21: error: 's' was not declared in this scope
   20 |         if (dp[bit][s] >= INF) continue;
      |                     ^
Language: C++

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int N;
int A[18], B[18];
unsigned char dp[36][1 << 18];
int K;
int keisan(int b, bool n, int k) {
	if (dp[k][b] != 255) return dp[k][b];
	if (b == (1 << N) - 1) return 0;

	int saishou = 254;
	int num2 = 0;
	char used[36];
	for (int i = k; i <= K; i++) used[i] = 40;

	if (n) {
		rep(i, N) {
			if (!(b >> i & 1)) {
				if (A[i] < k && B[i] < k) return dp[k][b] = 254;
				if (B[i] >= k && used[B[i]] > A[i]) {
					chmin(saishou, keisan(b ^ (1 << i), !n, B[i]) + num2);
					used[B[i]] = A[i];
				}
				num2++;
			}
		}
	}
	else {
		rep(i, N) {
			if (!(b >> i & 1)) {
				if (A[i] < k && B[i] < k) return dp[k][b] = 254;
				if (A[i] >= k && used[A[i]] > B[i]) {
					chmin(saishou, keisan(b ^ (1 << i), !n, A[i]) + num2);
					used[A[i]] = B[i];
				}
				num2++;
			}
		}
	}
	return dp[k][b] = saishou;
}

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


	scanf("%d", &N);
	rep(i, N) {
		if (i & 1) scanf("%d", B + i);
		else scanf("%d", A + i);
	}
	rep(i, N) {
		if (i & 1) scanf("%d", A + i);
		else scanf("%d", B + i);
	}

	pair<int, int> kari[36];
	rep(i, N) kari[i] = mp(A[i], i);
	rep(i, N) kari[i + N] = mp(B[i], i + N);
	sort(kari, kari + N * 2);
	int mae = kari[0].first;
	rep(i, N * 2) {
		if (mae != kari[i].first) K++;
		mae = kari[i].first;
		if (kari[i].second < N) A[kari[i].second] = K;
		else B[kari[i].second - N] = K;
	}
	memset(dp[0], 1, (K + 1) * (1 << N));

	int kotae = keisan(0, 0, 0);
	if (kotae == 254) printf("-1\n");
	else printf("%d\n", kotae);

	Would you please return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:88:9: error: 'memset' was not declared in this scope
   88 |         memset(dp[0], 1, (K + 1) * (1 << N));
      |         ^~~~~~
a.cc:6:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    5 | #include<algorithm>
  +++ |+#include <cstring>
    6 | using namespace std;
Language: C++

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

struct e{int a,b;};
int A=500,n,a[20],b[20],R,p,q;
e v[20];
stack<int> s;
#define rep(i,n) for(int i=0;i<(n);i++)

signed main(){
  cin>>n;
  rep(i,n)cin>>a[i];
  rep(i,n)cin>>b[i];
  rep(i,1<<n){
    R=0;
    rep(j,n)v[j]={(i>>j)&1?b[j]:a[j],j};
    rep(j,n)p=j,while(p&&v[p].a<v[p-1].a)swap(v[p],v[p-1]),R++,p--;
    rep(j,n)if(((i>>v[j].b)+v[j].b-j)&1)s.push(v[j].a*500+j);
    if(s.size()&1)R=500,s.pop();
    while(s.size()){
      p=s.top();s.pop();q=s.top();s.pop();
      R+=((p-q)&1?p-q:500);
    }
    if(A>R)A=R;
  }
  cout<<(A<500?ans:-1)<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:17:17: error: expected primary-expression before 'while'
   17 |     rep(j,n)p=j,while(p&&v[p].a<v[p-1].a)swap(v[p],v[p-1]),R++,p--;
      |                 ^~~~~
a.cc:26:16: error: 'ans' was not declared in this scope; did you mean 'abs'?
   26 |   cout<<(A<500?ans:-1)<<endl;
      |                ^~~
      |                abs
Language: C++

#include<bits/stdc++.h>
using namespace std;
const int V=50;
const int MX=1e9+7;
int n,a[20],b[20],off[20][20],dp[1<<20][20];
int fun(int mask,int val)
{
    int ans=MX,d=0;
    if(mask==(1<<(n-1)) return 0;
    if(dp[mask][val]!=-1) return dp[mask][val];
    int ln=__builtin_popcount(mask);
    for(int i=0;i<n;i++)
    {
        if(mask&(1<<i)) continue;
        if(off[ln][i]>=val)
        ans=min(ans,d+fun(mask|(1<<i),off[ln][i]));
        d++;
    }
    return dp[mask][val]=ans;
}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        off[i][j]=(i%2==j%2)?a[j]:b[j];
    }
    memset(dp,-1,sizeof(dp));
    int res=fun(0,0);
    if(res==MX) cout<<"-1";
    else
    cout<<res;
    return 0;
}

Compiler output:
a.cc: In function 'int fun(int, int)':
a.cc:9:24: error: expected ';' before 'return'
    9 |     if(mask==(1<<(n-1)) return 0;
      |                        ^~~~~~~
      |                        ;
a.cc:10:5: error: expected primary-expression before 'if'
   10 |     if(dp[mask][val]!=-1) return dp[mask][val];
      |     ^~
a.cc:9:34: error: expected ')' before 'if'
    9 |     if(mask==(1<<(n-1)) return 0;
      |       ~                          ^
      |                                  )
   10 |     if(dp[mask][val]!=-1) return dp[mask][val];
      |     ~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()
int first_fixed_size_subset(int n, int k) { return (1 << k) - 1; }

int next_fixed_size_subset(int n, int k, int& s) {
  int x = s & -s, y = s + x;
  s = (((s & ~y) / x) >> 1) | y;
  if (s >= (1 << n)) return 0;
  return s;
}

struct Card {
  int R, B;
};

struct Hoge {
  bool red;
  int v;
};

int main() {
  int N;
  cin >> N;

  vector<Card> C(N);
  rep(i, N) {
    if (i % 2 == 0) {
      cin >> C[i].R;
    } else {
      cin >> C[i].B;
    }
  }
  rep(i, N) {
    if (i % 2 == 0) {
      cin >> C[i].B;
    } else {
      cin >> C[i].R;
    }
  }

  int nRed = (N + 1) / 2;
  int red = first_fixed_size_subset(N, nRed);

  int ans = 1e9;

  do {
    int cost = 0;
    BinaryIndexedTree<int> bit(51);

    vector<Hoge> foo(N);
    rep(i, N) {
      if ((red >> i) & 1) {
        foo[i] = Hoge{true, C[i].R};
      } else {
        foo[i] = Hoge{false, C[i].B};
      }
    }

    bool flag = true;
    for (int i = 0; flag; i++) {
      flag = false;
      for (int j = N - 1; j >= i + 1; --j) {
        if (foo[j].v < foo[j - 1].v) {
          swap(foo[j], foo[j - 1]);
          flag = 1;
          ++cost;
        }
      }
    }

    do {
      flag = false;
      rep(i, N - 1) {
        if (foo[i].v == foo[i + 1].v &&
            (i % 2 == 0 && !foo[i].red && foo[i + 1].red)) {
          swap(foo[i], foo[i + 1]);
          ++cost;
        }
      }
    } while (flag);

    rep(i, N) {
      if (i % 2 == 0 && !foo[i].red) goto hoge;
      if (i % 2 == 1 && foo[i].red) goto hoge;
    }

    ans = min(ans, cost);
  hoge:;
  } while (next_fixed_size_subset(N, nRed, red));

  cout << (ans == 1e9 ? -1 : ans) << endl;

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:51:5: error: 'BinaryIndexedTree' was not declared in this scope
   51 |     BinaryIndexedTree<int> bit(51);
      |     ^~~~~~~~~~~~~~~~~
a.cc:51:23: error: expected primary-expression before 'int'
   51 |     BinaryIndexedTree<int> bit(51);
      |                       ^~~
Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 200010
ll n,a[18],b[18];
ll solve(ll d){
    rep(i,n)if(d&(1LL<<i))swap(a[i],b[i]);
    pair<ll,ll> v[18];
    rep(i,n)v[i]=make_pair(a[i],i);
    sort(v,v+n);
    ll ans=0;
    ll bef=-1,ecnt=0,obef=-1;
    rep(i,n){
	ll cnt=0;
	rep(j,n){
	    if(v[i].first==v[j].first)continue;
	    bool vl=(v[j].first<v[i].first);
	    bool vr=(v[j].second<v[i].second);
	    cnt+=vl^vr;
	}
	if(d&(1LL<<v[i].second))cnt++;
	if(v[i].first!=bef){
	    if(~obef)ans=1e9;
	    obef=-1,ecnt=0;
	    bef=v[i].first;
	}
	ecnt++;
	if(cnt%2==1){
	    if(~obef){
		if((ecnt-obef)%2==0)ans=1e9;
		else ans+=(ecnt-obef)*2,obef=-1;
	    }
	    else obef=ecnt;
	}
	if(d&(1LL<<v[i].second))cnt--;
	ans+=cnt;
    }
    if(~obef)ans=1e9;
    rep(i,n)if(d&(1LL<<i))swap(a[i],b[i]);
    if(ans<1e6&&ans%2==1)assert(0);
    return ans/2;
}
int main(){
    cin>>n;
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    ll ans=1e9;
    rep(i,(1<<n)){
	chmin(ans,solve(i));
    }
    if(ans>=1e6)ans=-1;
    cout<<ans<<endl;
}




Compiler output:
a.cc: In function 'll solve(ll)':
a.cc:52:26: error: 'assert' was not declared in this scope
   52 |     if(ans<1e6&&ans%2==1)assert(0);
      |                          ^~~~~~
a.cc:8:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
    7 | #include<unordered_map>
  +++ |+#include <cassert>
    8 | using namespace std;
Language: C++

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

template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}
typedef pair<int,int> P;
int ans=1e9,n,a[20],b[20],now;
vector<P> v;

signed main(){
  cin>>n;
  v.resize(n);
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++)cin>>b[i];
  for(int i=0;i<(1<<n);i++){
    now=0;memset(c,0,sizeof(c));
    for(int j=0;j<n;j++)v[j]=P((i>>j)&1?b[j]:a[j],j);
    for(int j=0;j<n;j++)for(int k=0;k<j;k++)now+=(v[k]>v[j]);
    sort(v.begin(),v.end());
    stack<int> sta;
    for(int j=0;j<n;j++){
      int idx=v[j].second;
      if(((i>>idx)+idx-j)&1)sta.push(v[j].first*1000+j);
    }
    if(sta.size()&1)continue;
    while(sta.size()){
      int p=sta.top();sta.pop();
      int q=sta.top();sta.pop();
      if(p-q<1000&&(p-q)&1)now+=p-q;
      else goto OUT;
    }
    for(int j=0;j<n;j++)cout<<v[j].first<<" ";cout<<endl;
    cout<<now<<endl;
    chmin(ans,now);OUT:;
  }
  cout<<(ans<1e9?ans:-1)<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:18:18: error: 'c' was not declared in this scope
   18 |     now=0;memset(c,0,sizeof(c));
      |                  ^
Language: C++

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
vector<ll> A,B;
ll n;

ll cnt(vector<ll> P,ll x){
    vector<ll> U(n);
    for(ll i=0;i<n;i++)U[i] = P[i];
    ll ret = 0;
    for(ll i=0;i<n-1;i++){
        for(ll j=i+1;<n;j++){
            if(U[j]<U[j-1]){
                ll tmp = U[j-1];
                U[j-1] = U[j];
                U[j] = tmp;
                ret++;
            }
        }
    }
    ll f = 0;
    ll bef=INF;
    vector<ll> used(n,0),ch(n,0);
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            if(used[j]==0 && U[i]==P[j]){
                //if(x == 2 && i == 1) cout << ((i % 2) + (j % 2)) % 2 << " " << (x >> j) % 2 << endl;
                if(((i % 2) + (j % 2)) % 2 != (x >> j) % 2) {
                    ch[i] = 1;
                }
                used[j] = 1;
                break;
            }
        }
    }

    for(ll i=0;i<n;i++){
        f += used[i];
    }
    for(ll i=0;i<n;i++){        
        if(ch[i]==1){
            if(i==n-1)return INF;
            if(U[i]==U[i+1] && ch[i+1]==1){
                ret++;
                ch[i] = ch[i+1] = 0;
            }else{
                return INF;
            }
        }
    }
    if(f==n){
        return ret;
    }
    return INF;
}

ll solve(ll x){
    vector<ll> P(n);
    for(ll i=0;i<n;i++){
        if((x>>i)%2 ==0)P[i] = A[i];
        else P[i] = B[i]; 
    }
    return cnt(P,x);
}

int main() {
    ll m, i, j, k;
    cin >> n;
    A= vector<ll>(n);
    B = vector<ll> (n);
    for(i=0;i<n;i++)cin >> A[i];
    for(i = 0; i < n; i++)
        cin >> B[i];
    ll ret = INF;
    for(i=0;i<(1ll<<n);i++){
        ret = min(ret,solve(i));
    }
    if(ret==INF)ret = -1;
    cout << ret << endl;
    return 0;
}


Compiler output:
a.cc: In function 'll cnt(std::vector<long long int>, ll)':
a.cc:16:22: error: expected primary-expression before '<' token
   16 |         for(ll j=i+1;<n;j++){
      |                      ^
Language: C++

#include <bits/stdc++.h>
#include "../lib/data_structure/bit.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);

  int n; cin >> n;
  vi a(n), b(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
  }
  for(int i=0;i<n;++i) {
    cin >> b[i];
  }
  cout << -1 << endl;
  return 0;

  int mi = INF;
  for(int i=0;i<(1<<n);++i) {
    vector<P> tmp(n);
    for(int j=0;j<n;++j) {
      if((i>>j)&1) {
        tmp[j].first = b[j];
      } else {
        tmp[j].first = a[j];
      }
      tmp[j].second = j;
    }
    sort(tmp.begin(), tmp.end());
    //printv(tmp);
    bool ok = true;
    for(int j=0;j<n;++j) {
      if((abs(j-tmp[j].second)%2) ^ ((i>>tmp[j].second)&1)) {
        ok = false;
        break;
      }
    }
    if(!ok) continue;
    //cout << "A" << endl;
    //printv(tmp);
    
    int cost = 0;
    BIT<int> bit(n+1);
    for(int j=n-1;j>=0;--j) {
      //cout << tmp[j].second << endl;
      cost += bit.sum(tmp[j].second);
      bit.add(tmp[j].second, 1);
    }
    mi = min(mi, cost);
  }
  cout << (mi == INF ? -1 : mi) << endl;

}


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

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);

    int N;
    cin >> N;
    vector<int> A(N), B(N);
    REP(i, N) { cin >> A.at(i); }
    REP(i, N) { cin >> B.at(i); }

    int ans = INF;
    int bit = 0;
    while (bit < 1 << N) {
        vector<pair<int, int>> use(N);
        int mask = 1;
        int sum = 0 REP(i, N) {
            if (mask & bit) { // ビットが立てば裏
                use[i] = make_pair(B[i], i);
                sum++;
            } else {
                use[i] = make_pair(A[i], i);
            }
            mask = mask << 1;
        }

        bool flag = false;
        if (sum % 2 == 1) {
            flag = true;
        }

        // bubble
        vector<int> ind(N);
        REP(i, N) { ind[i] = i; }
        int t = 0;
        for (int i = 0; i < N - 1; i++) {
            for (int j = 0; j < N - i - 1; j++) {
                if (use[j] > use[j + 1]) { // 右隣が小さければ入れ替える
                    swap(use[j], use[j + 1]);
                    swap(ind[j], ind[j + 1]);
                    t++;
                }
            }
        }

        mask = 1;

        vector<int> ind2(N);
        REP(i, N) { ind2[ind[i]] = i; }
        REP(i, N) {
            if (mask & bit) { // ビットが立てば裏
                if (abs(ind2[i] - i) % 2 == 0) {
                    flag = true;
                }
            } else {
                if (abs(ind2[i] - i) % 2 == 1) {
                    flag = true;
                }
            }
            mask = mask << 1;
        }
        if (flag) {
            bit++;
            continue;
        }
        chmin(ans, t);
        bit++;
    }

    if (ans == INF) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:2:19: error: expected ',' or ';' before 'for'
    2 | #define REP(i, n) for (int i = 0; i < (n); i++)
      |                   ^~~
a.cc:47:21: note: in expansion of macro 'REP'
   47 |         int sum = 0 REP(i, N) {
      |                     ^~~
a.cc:47:25: error: 'i' was not declared in this scope
   47 |         int sum = 0 REP(i, N) {
      |                         ^
a.cc:2:35: note: in definition of macro 'REP'
    2 | #define REP(i, n) for (int i = 0; i < (n); i++)
      |                                   ^
Language: C++

#include <bits/stdc++.h>
#include "../lib/data_structure/bit.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);

  int n; cin >> n;
  vi a(n), b(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
  }
  for(int i=0;i<n;++i) {
    cin >> b[i];
  }

  int mi = INF;
  for(int i=0;i<(1<<n);++i) {
    vector<P> tmp(n);
    for(int j=0;j<n;++j) {
      if((i>>j)&1) {
        tmp[j].first = b[j];
      } else {
        tmp[j].first = a[j];
      }
      tmp[j].second = j;
    }
    sort(tmp.begin(), tmp.end());
    //printv(tmp);
    bool ok = true;
    for(int j=0;j<n;++j) {
      if((abs(j-tmp[j].second)%2) ^ ((i>>tmp[j].second)&1)) {
        ok = false;
        break;
      }
    }
    if(!ok) continue;
    //cout << "A" << endl;
    //printv(tmp);
    
    int cost = 0;
    BIT<int> bit(n+1);
    for(int j=n-1;j>=0;--j) {
      //cout << tmp[j].second << endl;
      cost += bit.sum(tmp[j].second);
      bit.add(tmp[j].second, 1);
    }
    mi = min(mi, cost);
  }
  cout << (mi == INF ? -1 : mi) << endl;

}


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

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

template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}
typedef pair<int,int> P;
P v[20];
int n,ans=1e9,k[51],a[20],b[20],q[20],c[20],now;
bool out;

signed main(){
  cin>>n;
  for(int i=0;i<(1<<n);i++){
    memset(k,0,sizeof(k));
    now=0,out=false;
    for(int j=0;j<n;j++){
      if((i>>j)&1)v[j]=P(a[j]*2,0);
      else v[j]=P(b[j],1);
    }
    for(int j=0;j<n;j++){
      int A=v[j].first;
      now+=q[j]=k[A];
      c[j]=j-q[j];
      for(int l=A-1;l>=0;l--)k[l]++;
      for(int l=0;l<j;l++)c[l]+=(v[l].first>A);
    }
    vector<P> aa;
    for(int j=0;j<n;j++){
      if(((j+c[j])&1)!=v[j].second)
        aa.push_back(P(v[j].first,c[j]));
    if(aa.size()){
      if(aa.size()&1)continue;
      sort(aa.begin(),aa.end());
      for(int j=0;j<aa.size();j+=2){
        if(aa[j].first==aa[j+1].first)&&(aa[j+1].second-aa[j].second)&1)
          now+=(aa[j+1].second-aa[j].second);
        else{out=1;break;}
      }
    }
    if(!out)chmin(ans,now);
  }
  if(ans==INF)cout<<-1<<endl;
  else cout<<ans<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:37:41: error: expected identifier before '(' token
   37 |         if(aa[j].first==aa[j+1].first)&&(aa[j+1].second-aa[j].second)&1)
      |                                         ^
a.cc:44:11: error: 'INF' was not declared in this scope
   44 |   if(ans==INF)cout<<-1<<endl;
      |           ^~~
a.cc:46:2: error: expected '}' at end of input
   46 | }
      |  ^
a.cc:13:14: note: to match this '{'
   13 | signed main(){
      |              ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> A, B;
int memo[1<<18][51];
bool visited[1<<18][51];
const int INF = 1<<29;
vector<int> aa;
int f(int p, int n, int m) {
	if (p == N) {
		return 0;
	}
	if (visited[n][m]) return memo[n][m];
	visited[n][m] = true;
	int r = INF;
	for (int i = 0; i < N; ++ i) if (((n>>i)&1)==0) {
		int qq = abs(p-i) % 2;
		int x = (qq == 0) ? A[i] : B[i];
		if (x < m) continue;
		int k = 0;
		for (int j = i+1; j < N; ++ j) if ((n>>j)&1) ++ k;
		aa.push_back(i);
		r = min(r, f(p+1, n | (1<<i), x) + k);
		aa.pop_back();
	}
	return memo[n][m] = r;
}
int main() {
	cin >> N;
	A.resize(N);
	B.resize(N);
	for (auto& x : A) cin >> x;
	for (auto& x : B) cin >> x;
	int r = f(0, 0, 0, 0);
	if (r >= INF) cout << -1 << endl;
	else cout << r << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:34:18: error: too many arguments to function 'int f(int, int, int)'
   34 |         int r = f(0, 0, 0, 0);
      |                 ~^~~~~~~~~~~~
a.cc:9:5: note: declared here
    9 | int f(int p, int n, int m) {
      |     ^
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()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }

int mergecount(vector<int> &a) {
  int count = 0;
  rep(i,n)rep(j,i)if(a[j]>a[i]) ++count;
  /*
  int n = a.size();
  if (n > 1) {
    vector<int> b(a.begin(), a.begin() + n/2);
    vector<int> c(a.begin() + n/2, a.end());
    count += mergecount(b);
    count += mergecount(c);
    for (int i = 0, j = 0, k = 0; i < n; ++i)
      if (k == (int)c.size())       a[i] = b[j++];
      else if (j == (int)b.size())  a[i] = c[k++];
      else if (b[j] <= c[k])   a[i] = b[j++];
      else                   { a[i] = c[k++]; count += n/2 - j; }
  }
  */
  return count;
}

int main(void){
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    int res = INF;
    rep(mask, 1<<n){
        using P = pair<int,int>;
        vector<P> even, odd;
        rep(i,n){
            bool is_back = mask & bit(i);
            if ((i&1)^is_back) {
                odd.push_back({is_back ? b[i] : a[i], i});
            } else {
                even.push_back({is_back ? b[i] : a[i], i});
            }
        }
        sort(all(even));
        sort(all(odd));

        bool ng = false;
        {
            int E = even.size();
            int O = odd.size();
            if (n & 1) {
                if (E-O != 1) ng = true;
            } else {
                if (E != O) ng = true;
            }
        }

        {
            int back_count = 0;
            rep(i,n){
                if(mask & bit(i)) back_count++;
            }
            if (back_count & 1) {
                ng = true;
            }
        }
        if (ng) continue;

        {
            rep(i,n-1){
                if (i % 2 == 0) {
                    if (even[i/2] > odd[i/2]) ng = true;
                } else {
                    if (odd[i/2] > even[(i+1)/2]) ng = true;
                }
            }
        }
        if (ng) continue;

        vector<int> v;
        rep(i,n){
            v.push_back((i % 2 == 0) ? even[i/2].second : odd[i/2].second);
        }
        res = min(mergecount(v), res);
    }
    cout << (res == INF ? -1 : res) << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int mergecount(std::vector<int>&)':
a.cc:23:9: error: 'n' was not declared in this scope
   23 |   rep(i,n)rep(j,i)if(a[j]>a[i]) ++count;
      |         ^
a.cc:3:36: note: in definition of macro 'rep'
    3 | #define rep(i,n) for(int i=0;i<int(n);++i)
      |                                    ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
int mypow(int a,int b,int c){
	if(b==0)return 1;
	if(b%2)return mypow(a,b-1,c)*a%c;
	int z=mypow(a,b/2,c);
	return z*z%c;
}
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
int x[20],y[20],vx[20],vy[20];
signed main(){
	int n,ans=INF;
	cin>>n;
	f(i,n)cin>>x[i];
	f(i,n)cin>>y[i];
	f(i,mypow(2,n,mod)){
		int z=i,sum=0,zz[20]={};
		bool use[20]={};
		vector<P> v={};
		f(j,n){
			vx[j]=x[j];
			vy[j]=y[j];
			zz[j]=j;
			use[j]=z%2;
			z/=2;
			if(use[j])v.push_back({y[j],j});
			else v.push_back({x[j],j});
		}
		sort(all(v));
		f(j,n){
			int vj;
			if((j-v[j].S)%2!=use[v[j].S]){
				for(int k=j+1;v[k].F==v[j].F;k++){
					if(abs(j-v[k].S)%2==use[v[k].S]){
						for(int l=k;l>j;l--){
							swap(v[l].S,v[l-1].S);
						}
						break;
					}
				}
			}
			f(k,n){
				if(zz[k]==v[j].S){
					vj=k;
					break;
				}
			}
			if(abs(j-v[j].S)%2!=use[v[j].S]){
				/*f(k,n){
					cout<<(int)use[k]<<" ";
				}
				cout<<endl<<j<<" "<<vj<<" "<<v[j].S<<endl;*/
				goto loop;
			}
			else{
				if(j>vj){
					for(int k=vj;k<j;k++){
						swap(vx[k],vy[k+1]);
						swap(vy[k],vx[k+1]);
						swap(zz[k],zz[k+1]);
						sum++;
					}
				}
				else{
					for(int k=vj;k>j;k--){
						swap(vx[k],vy[k-1]);
						swap(vy[k],vx[k-1]);
						swap(zz[k],zz[k-1]);
						sum++;
					}
				}
			}
		}
		ans=min(ans,sum);
		if(sum==9){
		loop:;
	}
	if(ans==INF)puts("-1");
	else cout<<ans<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:95:2: error: expected '}' at end of input
   95 | }
      |  ^
a.cc:26:14: note: to match this '{'
   26 | signed main(){
      |              ^
Language: C++

#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int N,A[18],B[18],k[18],k2[18],K[18],m[18],sum,pre,minL=10000;
	bool flag,can;
	cin>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=0;i<N;i++)cin>>B[i];
	for(int i=0;i<(1<<N);i++){
		pre=i;sum=0;
		for(int j=0;j<N;j++){
			m[j]=m;
			K[j]=pre%2;sum+=K[j];
			if(pre%2)k[j]=B[j];
			else k[j]=A[j];
			k2[j]=k[j];
			pre/=2;
		}
		if(sum%2)continue;
		sort(k2,k2+N);
		
		can=true;
		//cout<<k[0]<<k[1]<<k[2]<<endl;
		//cout<<k2[0]<<k2[1]<<k2[2]<<endl;
		//cout<<K[0]<<K[1]<<K[2]<<endl;
		for(int j=0;j<N;j++){
			flag=false;
			for(int l=0;l<N;l++){
				flag |= (k[j]==k2[l] && (l-j+N*2)%2==K[j]);
			}
			can &= flag;
			//cout<<flag;
		}
		//cout<<endl<<endl;
		if(can==false)continue;
		sum=0;
		for(int j=0;j<N-1;j++){
			for(int l=0;l<N-j-1;l++){
				if(k[l]>k[l+1]){
					swap(k[l],k[l+1]);
					swap(K[l],K[l+1]);
					swap(m[l],m[l+1]);
					sum++;
				}
			}
		}
		for(int j=0;j<N-1;j++){
			if((m[j]-j+N*2)%2!=j%2){
				j++;
				sum++;
			}
		}
		minL=min(minL,sum);
	}
	if(minL==10000)cout<<-1;
	else cout<<minL;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:30: error: invalid conversion from 'int*' to 'int' [-fpermissive]
   13 |                         m[j]=m;
      |                              ^
      |                              |
      |                              int*
Language: C++

#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;


int bbit(int ii,int t){
  return (ii>>t)%2;
}

//vi ki(18);
//vi gu(18);
vector<pair<int, int>> nm(18);
vector<pair<int, int>> ki(18);
vector<pair<int, int>> gu(18);
//vector<pair<int, int>> ki(18);


int solve(vector<int> &v,vi &a,vi &b)
{
  int wki=0;
  int wgu=0;
  for(int i=0;i<n;i++){
    if ((v[i]+i%2)%2==0){
      gu[wgu].first=a[i];
      gu[wgu].second=i;
      wgu++;
    }else{
      ki[wki].first=b[i];
      ki[wgu].second=i;
      wki++;
    }
    /*
    if ((v[i]+i%2)%2==0){
      if (v[i]==0)
        gu[wgu]=a[i];
      if (v[i]==1)
        gu[wgu]=b[i];
      wgu++;
    }else{
      if (v[i]==0)
        ki[wki]=b[i];
      if (v[i]==1)
        ki[wki]=a[i];
      wki++;
    }
    */
  }
  if (wki!=(n/2)) 
    return -1;


  int an=0;
  
  sort(gu.begin(), gu.begin()+wgu);
  sort(ki.begin(), ki.begin()+wki);
  int tmp=0,flag=0,ttmp=0;
  for(int i=0;i<n;i++){
    if (i%2==0){
      if (tmp>gu[i/2].first)flag=1;
      tmp=gu[i/2].first;
      ttmp=gu[i/2].second;
    }else{
      if (tmp>ki[i/2].first)flag=1;
      tmp=ki[i/2].first;
      ttmp=ki[i/2].second;
    }
    nm[i].first=tmp;
    nm[i].second=ttmp;
  }
  if (flag==1)return -1;
  


  REP(i,n){
    tmp=nm[i];

    for(int j=0;j<n;j++){
      if (nm[j].first==tmp){
        an+=nm[j].second-i;
        nm[j].first=0;
        nm[j].second=-1000;
        for(int k=0;k<j;k++){
          nm[k].second++;
        }
        
      }
    }

  }

  return an;
}


int main(){
  int ans=(1<<19)+1;
  cin >> n ;
  vi a(n),b(n);
  REP(i,n){
    cin>>a[i]>>b[i];
  }



  ll nn=1<<n;
  vector<int> v(n);
  int sm=0;
  int tmpans=0;
  //裏が1
  for(int i=0;i<nn;i++){
    sm=0;
    for(int j=0;j<n;j++){
      v[j]=bbit(i,j);
      sm+=v[j];
    }
    if (sm%2==1)continue;


    tmpans=solve(v,a,b);
    if (tmpans!=-1){
      ans=min(ans,tmpans);
    }
  }



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

Compiler output:
a.cc: In function 'int solve(std::vector<int>&, vi&, vi&)':
a.cc:81:13: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} to 'int' in assignment
   81 |     tmp=nm[i];
      |             ^
Language: C++

#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;


int bbit(int ii,int t){
  return (ii>>t)%2;
}

//vi ki(18);
//vi gu(18);
vector<pair<int, int>> nm(18);
vector<pair<int, int>> ki(18);
vector<pair<int, int>> gu(18);
//vector<pair<int, int>> ki(18);


int solve(vector<int> &v,vi &a,vi &b)
{
  int wki=0;
  int wgu=0;
  for(int i=0;i<n;i++){
    if ((v[i]+i%2)%2==0){
      gu[wgu].first=a[i];
      gu[wgu].second=i;
      wgu++;
    }else{
      ki[wki].first=b[i];
      ki[wgu].second=i;
      wki++;
    }
    /*
    if ((v[i]+i%2)%2==0){
      if (v[i]==0)
        gu[wgu]=a[i];
      if (v[i]==1)
        gu[wgu]=b[i];
      wgu++;
    }else{
      if (v[i]==0)
        ki[wki]=b[i];
      if (v[i]==1)
        ki[wki]=a[i];
      wki++;
    }
    */
  }
  if (wki!=(n/2)) 
    return -1;


  int an=0;
  
  sort(gu.begin(), gu.begin()+wgu);
  sort(ki.begin(), ki.begin()+wki);
  int tmp=0,flag=0,ttmp=0;
  for(int i=0;i<n;i++){
    if (i%2==0){
      if (tmp>gu[i/2].first)flag=1;
      tmp=gu[i/2].first;
      ttmp=gu[i/2].second;
    }else{
      if (tmp>ki[i/2].first)flag=1;
      tmp=ki[i/2].first;
      ttmp=ki[i/2].second;
    }
    nm[i].first=tmp;
    nm[i].second=ttmp;
  }
  if (flag==1)return -1;
  


  REP(i,n){
    tmp=nm[i];

    for(int j=0;j<n;j++){
      if (nm[j].first==tmp){
        an+=nm[j].second-i;
        nm[j].first=0;
        nm[j].second=-1000
        for(int k=0;k<j;k++){
          nm[k].second++;
        }
        
      }
    }

  }

  return an;
}


int main(){
  int ans=(1<<19)+1;
  cin >> n ;
  vi a(n),b(n);
  REP(i,n){
    cin>>a[i]>>b[i];
  }



  ll nn=1<<n;
  vector<int> v(n);
  int sm=0;
  int tmpans=0;
  //裏が1
  for(int i=0;i<nn;i++){
    sm=0;
    for(int j=0;j<n;j++){
      v[j]=bbit(i,j);
      sm+=v[j];
    }
    if (sm%2==1)continue;


    tmpans=solve(v,a,b);
    if (tmpans!=-1){
      ans=min(ans,tmpans);
    }
  }



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

Compiler output:
a.cc: In function 'int solve(std::vector<int>&, vi&, vi&)':
a.cc:81:13: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} to 'int' in assignment
   81 |     tmp=nm[i];
      |             ^
a.cc:87:27: error: expected ';' before 'for'
   87 |         nm[j].second=-1000
      |                           ^
      |                           ;
   88 |         for(int k=0;k<j;k++){
      |         ~~~                
a.cc:88:28: error: expected ';' before ')' token
   88 |         for(int k=0;k<j;k++){
      |                            ^
      |                            ;
Language: C++

#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int N,A[18],B[18],k[18],k2[18],K[18],sum,pre,minL=10000;
	bool flag,can;
	cin>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=0;i<N;i++)cin>>B[i];
	for(int i=0;i<(1<<N);i++){
		pre=i;sum=0;
		for(int j=0;j<N;j++){
			K[j]=pre%2;sum+=K[j];
			if(pre%2)k[j]=B[j];
			else k[j]=A[j];
			k2[j]=k[j];
			pre/=2;
		}
		if(sum%2)continue;
		sort(k2,k2+N);
		
		can=true;
		//cout<<k[0]<<k[1]<<k[2]<<endl;
		//cout<<k2[0]<<k2[1]<<k2[2]<<endl;
		//cout<<K[0]<<K[1]<<K[2]<<endl;
		for(int j=0;j<N;j++){
			flag=false;
			for(int l=0;l<N;l++){
				flag |= (k[j]==k2[l] && (l-j+N*2)%2==K[j]);
			}
			can &= flag;
			//cout<<flag;
		}
		//cout<<endl<<endl;
		if(can==false)continue;
		sum=0;
		for(int j=0;j<N-1;j++){
			for(int l=0;l<N-j-1;l++){
				if(k[l]>k[l+1]){
					swap(k[l],k[l+1]);
					swap(K[l],K[l+1]);
					sum++;
				}
			}
		}
		for(int j=0;j<N-1;j++){
			if(K[l]!=j%2){
				j++;
				sum++;
			}
		}
		minL=min(minL,sum);
	}
	if(minL==10000)cout<<-1;
	else cout<<minL;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:47:30: error: 'l' was not declared in this scope
   47 |                         if(K[l]!=j%2){
      |                              ^
Language: C++

#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <time.h>
#include <stdio.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mpa make_pair
#define all(a) a.begin(), a.end()

template<typename T>
void vdeb(vector<T> &da) {
	int size = da.size();
	for (int i = 0;i < size;i++) {
		if (i == size - 1) {
			cout << da[i] << endl;
		}
		else {
			cout << da[i] << ' ';
		}
	}
}
template<typename T>
void vvdeb(vector<T> &da) {
	int size = da.size();
	for (int i = 0;i < size;i++) {
		vdeb(da[i]);
	}
}

int merge(vector<int> &da, int le, int mi, int ri, int &co) {
	int n1 = mi - le;
	int n2 = ri - mi;
	vector<int> L(n1 + 1), R(n2 + 1);
	for (int i = 0;i < n1;i++) {
		L[i] = da[le + i];
	}
	for (int i = 0;i < n2;i++) {
		R[i] = da[mi + i];
	}
	L[n1] = INT_MAX;R[n2] = INT_MAX;
	int i = 0, j = 0;
	for (int k = le;k < ri;k++) {
		if (L[i] < R[j]) {
			da[k] = L[i];
			i++;
		}
		else {
			da[k] = R[j];
			j++;
			co += n1 - i;
		}
	}
	return co;
}

int mergesort(vector<int> &da, int le, int ri) {
	int ret = 0;
	if (le + 1 < ri) {
		int mi = (le + ri) / 2;
		ret += mergesort(da, le, mi);
		ret += mergesort(da, mi, ri);
		merge(da, le, mi, ri, ret);
	}
	return ret;
}


int n, ans = 100000;

int cal(vector<int> da) {
	return mergesort(da, 0, n);
}

const P DEFF = mpa(100000, -1);
vector<P> a(18,DEFF), b(18,DEFF), A(9, DEFF), B(9,DEFF);
vector<int> da(18);

void gen(int now, int po, vector<bool> &ju) {//po = 0から
	if (po == (n+1)/2) {
		int aa = 0, bb = 0;
		rip(i, n, 0) {
			if (ju[i]) {
				A[aa] = a[i];
				aa++;
			}
			else {
				B[bb] = b[i];
				bb++;
			}
		}
		sort(all(A));sort(all(B));
		da[0] = A[0].second;
		rip(i, n, 1) {
			if (i % 2 == 0) {
				if (A[i/2].first < b[da[i - 1]].first) return;
				da[i] = A[i/2].second;
			}
			else {
				if (B[i/2].first < a[da[i - 1]].first) return;
				da[i] = B[i/2].second;
			}
		}
		ans = min(ans, cal(da));
		cout << ans << endl;
		//vdeb(da);
	}
	else {
		if (now >= 18) return;
		rip(i, n, now) {
			ju[i] = true;
			gen(i + 1, po + 1, ju);
			ju[i] = false;
		}
		return;
	}
}

int main() {
	cin >> n;
	/*rip(i, n, 0) {
		if (i % 2 == 0) cin >> a[i].first >> b[i].first;
		else cin >> b[i].first >> a[i].first;
	}*/
	rip(i, n, 0) {
		cin >> a[i].first;
	}
	rip(i, n, 0) {
		cin >> b[i].first;
	}
	rip(i, n, 0) {
		a[i].second = i;b[i].second = i;
		if (i % 2) swap(a[i], b[i]);
	}
	//sort(all(a)), sort(all(b));
	vector<bool> ju(n, false);
	gen(0, 0, ju);
	if (ans == 100000) cout << -1 << endl;
	else cout << ans << endl;
}


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