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;

// Binary Indexed Tree (Fenwick Tree)
template<typename T> // T: type of cost
struct BIT {
    int n;
    vector<T> d;
    BIT(int n=0):n(n),d(n+1) {}
    //配列のインデックスiの要素d[i]に対して、xを加算する。
    void add(int i, T x=1) {
        for (i++; i <= n; i += i&-i) {
            d[i] += x;
        }
    }
    //配列においてインデックスがi以下の要素d[j]たちの和を計算して返す。
    T sum(int i) {
        T x = 0;
        for (i++; i; i -= i&-i) {
            x += d[i];
        }
        return x;
    }
};

int main(){
  using namespace std;
  int n;
  cin>>n;
  int a[n], b[n];
  REP(i,n){
    cin>>a[i];
  }
  REP(i,n){
    cin>>b[i];
  }
  vector<vector<long long>> dp(1<<n, vector<long long>(51, INF));
  dp[0][0] = 0;
  REP(s, (1<<n)){
    REP(v,51){
      vector<int> ni;
      int bits = 0;
      BIT<int> tree(n);
      REP(j,n){
        if(s & (1<<j)){
          bits++;
          tree.add(j);
        }else{
          ni.push_back(j);
        }
      }
      for(int i:ni){
        int nv;
        if((bits - i) % 2 == 0){
          nv = a[i];
        }else{
          nv = b[i];
        }
        if(nv < v)continue;
        long long cnt = bits - tree.sum(i);
        /*
        REP(j,n){
          if((s & (1<<j)) && j > i)cnt++;
        }
        */
        dp[s | (1<<i)][nv] = min(dp[s | (1<<i)][nv], dp[s][v] + cnt);
      }
    }
  }
  long long res = INF;
  REP(v,51){
    res = min(res, dp[(1<<n) - 1][v]);
  }
  if(res == INF){
    cout<<-1<<endl;
  }else{
    cout<<res<<endl;
  }
  return 0;
}


Compiler output:
a.cc:73:5: error: 'vector' does not name a type
   73 |     vector<T> d;
      |     ^~~~~~
a.cc: In constructor 'BIT<T>::BIT(int)':
a.cc:74:23: error: class 'BIT<T>' does not have any field named 'd'
   74 |     BIT(int n=0):n(n),d(n+1) {}
      |                       ^
a.cc: In member function 'void BIT<T>::add(int, T)':
a.cc:78:13: error: 'd' was not declared in this scope
   78 |             d[i] += x;
      |             ^
a.cc: In member function 'T BIT<T>::sum(int)':
a.cc:85:18: error: 'd' was not declared in this scope
   85 |             x += d[i];
      |                  ^