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

nclude<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define N 200009
#define inf 999999999999
#define pb push_back
#define M (L+R)/2
using namespace std;
 
struct node {
	ll sum;
	node *left,*right;
	node(): sum(0), left(NULL), right(NULL){}
};
node *root(NULL);
 
void upd(node *&parent,ll L,ll R,ll ind,ll x){
	if(!parent){
		parent=new node();
	}
	if(L+1==R){
		parent->sum+=x;
		return;
	}
	if(ind<M){
		upd(parent->left,L,M,ind,x);
	} else {
		upd(parent->right,M,R,ind,x);
	}
	parent->sum=(parent->left?parent->left->sum:0)+(parent->right?parent->right->sum:0);
	return;
}
 
ll get(node *&parent,ll L,ll R,ll l,ll r){
	if(parent){
		if(L>=r || R<=l)return 0;
		if(l<=L && R<=r)return parent->sum;
		return get(parent->left,L,M,l,r)+get(parent->right,M,R,l,r);
	}
	return 0;
}
 
 
ll n,A[N],a[N],b[N],c[N];
 
bool check(ll x){
	ll zero=0,one=0;
	for(int i=1;i<=n;i++){
		if(a[i]<x)b[i]=-1,zero++;
		else b[i]=1,one++;
	}
	for(int i=1;i<=n;i++){
		b[i]+=b[i-1];
		upd(root,-2*N,2*N,b[i],1);
	}
	for(int i=1;i<=n;i++){
		upd(root,-2*N,2*N,b[i],-1);
		ll G=get(root,-2*N,2*N,b[i],N-1);
		one+=G;
		zero+=n-i-G;
	}
	
//	cout<<x<<" "<<zero<<" - "<<one<<endl;
	if(zero>one)return false;
	else return true;
}
 
int main(){
	
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		A[i]=a[i];
	}
	sort(A+1,A+1+n);
	ll L=1,R=n,pas=0;
	while(L<=R){
		root=NULL;
		if(check(A[M])){
			pas=A[M];
			L=M+1;
		} else {
			R=M-1;
		}
	}
	cout<<pas<<endl;
	return 0;
}

Compiler output:
a.cc:1:1: error: 'nclude' does not name a type
    1 | nclude<bits/stdc++.h>
      | ^~~~~~
a.cc: In constructor 'node::node()':
a.cc:14:30: error: 'NULL' was not declared in this scope
   14 |         node(): sum(0), left(NULL), right(NULL){}
      |                              ^~~~
a.cc:1:1: note: 'NULL' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
  +++ |+#include <cstddef>
    1 | nclude<bits/stdc++.h>
a.cc: At global scope:
a.cc:16:12: error: 'NULL' was not declared in this scope
   16 | node *root(NULL);
      |            ^~~~
a.cc:16:12: note: 'NULL' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
a.cc: In function 'int main()':
a.cc:71:9: error: 'cin' was not declared in this scope
   71 |         cin>>n;
      |         ^~~
a.cc:76:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   76 |         sort(A+1,A+1+n);
      |         ^~~~
      |         short
a.cc:79:22: error: 'NULL' was not declared in this scope
   79 |                 root=NULL;
      |                      ^~~~
a.cc:79:22: note: 'NULL' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
a.cc:87:9: error: 'cout' was not declared in this scope
   87 |         cout<<pas<<endl;
      |         ^~~~
a.cc:87:20: error: 'endl' was not declared in this scope
   87 |         cout<<pas<<endl;
      |                    ^~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
const int N=1000006, INF=1000000009;
long long a[N], b[N], t[N], n, u;
void upd(int i) {
   	while(i <= 200001){ ++t[i]; i+=(i&-i); }
}    
int sum(int i) {
    int x=0;
   	while(i){ x+=t[i]; i-=(i&-i); }
    return x;
}     
        
int main(){ ios_base::sync_with_stdio(false);
    cin>>n;
    for (int i=1; i<=n; i++)
      	cin>>a[i];
    int l=1, r=1e9;
    while(l<r){
       	int mid=(l+r)/2, ans=0, k=100000;
      	for (int i=0; i<=200001; i++)t[i]=0;
       	upd(k);
    	for (int i=1; i<=n; i++){
     		if(a[i]>mid) ans+=sum(k+1), upd(++k);
      		else 		 ans+=sum(k-1), upd(--k);
     	}
       	if(ans>(n*(n+1ll)/4) l=mid+1;
       	else		   r=mid+0;
    }
    cout<<l;
   	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:29: error: expected ';' before 'l'
   27 |         if(ans>(n*(n+1ll)/4) l=mid+1;
      |                             ^~
      |                             ;
a.cc:28:9: error: expected primary-expression before 'else'
   28 |         else               r=mid+0;
      |         ^~~~
a.cc:27:38: error: expected ')' before 'else'
   27 |         if(ans>(n*(n+1ll)/4) l=mid+1;
      |           ~                          ^
      |                                      )
   28 |         else               r=mid+0;
      |         ~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
const int N=1000006, INF=1000000009;
long long a[N], b[N], t[N], n, u;
void upd(int i) {
   	while(i <= 200001){ ++t[i]; i+=(i&-i); }
}    
int sum(int i) {
    int x=0;
   	while(i){ x+=t[i]; i-=(i&-i); }
    return x;
}     
        
int main(){ ios_base::sync_with_stdio(false);
    cin>>n;
    for (int i=1; i<=n; i++)
      	cin>>a[i];
    int l=1, r=1e9;
    while(l<r){
       	int mid=(l+r)/2, ans=0, k=100000;
      	for (int i=0; i<=200001; i++)t[i]=0;
       	upd(k);
    	for (int i=1; i<=n; i++){
     		if(a[i]>mid) ans+=sum(k+1), upd(++k);
      		else 		 ans+=sum(k-1), upd(--k);
     	}
       	if(ans>=(n*(n+1ll)/4+1) l=mid+1;
       	else		   r=mid+0;
    }
    cout<<l;
   	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:32: error: expected ';' before 'l'
   27 |         if(ans>=(n*(n+1ll)/4+1) l=mid+1;
      |                                ^~
      |                                ;
a.cc:28:9: error: expected primary-expression before 'else'
   28 |         else               r=mid+0;
      |         ^~~~
a.cc:27:41: error: expected ')' before 'else'
   27 |         if(ans>=(n*(n+1ll)/4+1) l=mid+1;
      |           ~                             ^
      |                                         )
   28 |         else               r=mid+0;
      |         ~~~~
Language: C++

#include <cstdio>
#include <vector>
#include <deque>
#include <algorithm>
using namespace std;

typedef long long ll;
const int MAXN = 1e5+10;

const int base = 1e5+10;

int n;
int A[MAXN];
int small[MAXN];
ll fw[3*MAXN];

ll query(int i) {
	ll ret = 0;
	while(i>0) {
		ret += fw[i];
		i -= (i&-i);
	}
	return ret;
}

void update(int i, ll v) {
	while(i<=base+n) {
		fw[i] += v;
		i += (i&-i);
	}
}

// x보다 같거나 작은 median의 개수
ll calc(int x) {
	for(int i=1;i<=n;i++) {
		if(A[i]<=x) {
			small[i] = small[i-1] + 1;
		}
		else{
			small[i] = small[i-1] - 1;
		}
	}

	for(int i=0;i<=base+n;i++) {
		fw[i] = 0;
	}

	ll sum=0;
	update(base+0, 1ll);

	for(int R=1;R<=n;R++) {
		sum += query(base+small[R]-1);

		// printf("small[%d]:%d, ret:%lld\n", R, small[R], query(base+small[R]-1));
		update(base+small[R], 1ll);
	}

	// printf("x=%d, sum=%lld\n", x, sum);
	// puts("");
	return sum;
}

int main() {
	scanf("%d", &n);

	// vector<int> cand;
	for(int i=1;i<=n;i++){
		scanf("%d", &A[i]);
		cand.push_back(A[i]);
	}

	// sort(cand.begin(), cand.end());
	// cand.erase(unique(cand.begin(), cand.end()), cand.end());

	int L = 0, R = 1e9;
	while(L<R) {
		int M =(R+L)/2;
		ll ret = calc(M);

		if(ret>=n*(n+1)/2/2+1) R = M;
		else L = M+1;
	}

	printf("%d", L);

	// vector<int> mds;
	// for(int i=0;i<n;i++){		
	// 	for(int j=i;j<n;j++){
	// 		vector<int> tmp;

	// 		for(int k=i;k<=j;k++)
	// 			tmp.push_back(A[i]);
	// 		sort(tmp.begin(), tmp.end());
	// 		mds.push_back(tmp[(j-i+1)/2]);
	// 	}
	// }
	// sort(mds.begin(), mds.end());
	// printf("%d", mds[mds.size()/2]);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:69:17: error: 'cand' was not declared in this scope; did you mean 'rand'?
   69 |                 cand.push_back(A[i]);
      |                 ^~~~
      |                 rand
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

template<typename T> class BIT {
    int n;
    vector<T> dat;
public:
    void init(int in) {
        n = in + 1;
        dat.clear();
        dat.resize(n + 1, 0);
    }
    T sum(int i) {
        T ret = 0;
        for (i++; i > 0; i -= i & -i) ret += bit[i];
        return ret;
    }
    void add(int i, T x) {
        while (i <= n) {
            dat[i] += x;
            i |= i + 1;
        }
    }
};

int main() {
    ll n;
    cin >> n;
    VL a(n), sorted(n);
    FOR(i, 0, n) {
        cin >> a[i];
        sorted[i] = a[i];
    }
    SORT(sorted);
    int ok = 0, ng = n;
    BIT<ll> bit;

    ll border = ((n * (n + 1) / 2) + 1) / 2;
    while (ng - ok > 1) {
        int mid = (ng + ok) / 2;
        int midnum = sorted[mid];
        bit.init(2 * n + 1);
        int sum = 0;
        bit.add(sum + n, 1);
        ll result = 0;
        FOR(i, 0, n) {
            sum += (a[i] >= midnum ? 1 : -1);
            result += bit.sum(sum + n);
            bit.add(sum + n, 1);
        }
        if (result >= border)ok = mid;
        else ng = mid;
    }
    cout << sorted[ok] << endl;
}


Compiler output:
a.cc: In member function 'T BIT<T>::sum(int)':
a.cc:32:46: error: 'bit' was not declared in this scope
   32 |         for (i++; i > 0; i -= i & -i) ret += bit[i];
      |                                              ^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

class BIT {
    ll n;
    VL dat;
public:
    void init(ll in) {
        n = in + 1;
        dat.resize(n + 1, 0);
    }
    ll sum(ll i) {
        ll s = 0;
        while (i >= 0) {
            s += dat[i];
            i = (i & (i + 1)) - 1;
        }
        return s;
    }
    void add(ll i, ll x) {
        while (i <= n) {
            dat[i] += x;
            i |= i + 1;
        }
    }
};

int main() {
    ll n;
    cin >> n;
    VL a(n), sorted(n);
    FOR(i, 0, n) {
        cin >> a[i];
        sorted[i] = a[i];
    }
    SORT(sorted);
    int ok = 0, ng = n;
    BIT<ll> bit;

    ll border = ((n * (n + 1) / 2) + 1) / 2;
    while (ng - ok > 1) {
        int mid = (ng + ok) / 2;
        int midnum = sorted[mid];
        bit.init(2 * n + 1);
        int sum = 0;
        bit.add(sum + n, 1);
        ll result = 0;
        FOR(i, 0, n) {
            sum += (a[i] >= midnum ? 1 : -1);
            result += bit.sum(sum + n);
            bit.add(sum + n, 1);
        }
        if (result >= border)ok = mid;
        else ng = mid;
    }
    cout << sorted[ok] << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:55:5: error: 'BIT' is not a template
   55 |     BIT<ll> bit;
      |     ^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

template<typename T> class BIT {
    int n;
    vector<T> dat;
public:
    void init(ll n_input) {
        n = n_input + 1;
        dat.resize(n + 1);
        for (int i = 0; i <= n; i++) dat[i] = 0;
    }
    ll sum(ll i) {
        ll s = 0;
        while (i >= 0) {
            s += dat[i];
            i = (i & (i + 1)) - 1;
        }
        return s;
    }
    void add(ll i, ll x) {
        while (i <= n) {
            dat[i] += x;
            i |= i + 1;
        }
    }
};

int main() {
    ll n;
    cin >> n;
    VL a(n), sorted(n);
    FOR(i, 0, n) {
        cin >> a[i];
        sorted[i] = a[i];
    }
    sort(sorted.begin(), sorted.end());
    int ok = 0, ng = n;
    BIT bit;

    ll border = ((n * (n + 1) / 2) + 1) / 2;
    while (ng - ok > 1) {
        int mid = (ng + ok) / 2;
        int midnum = sorted[mid];
        bit.init(2 * n + 1);
        int sum = 0;
        bit.add(sum + n, 1);
        ll result = 0;
        FOR(i, 0, n) {
            sum += (a[i] >= midnum ? 1 : -1);
            result += bit.sum(sum + n);
            bit.add(sum + n, 1);
        }
        if (result >= border)ok = mid;
        else ng = mid;
    }
    cout << sorted[ok] << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:56:9: error: class template argument deduction failed:
   56 |     BIT bit;
      |         ^~~
a.cc:56:9: error: no matching function for call to 'BIT()'
a.cc:21:28: note: candidate: 'template<class T> BIT()-> BIT<T>'
   21 | template<typename T> class BIT {
      |                            ^~~
a.cc:21:28: note:   template argument deduction/substitution failed:
a.cc:56:9: note:   couldn't deduce template parameter 'T'
   56 |     BIT bit;
      |         ^~~
a.cc:21:28: note: candidate: 'template<class T> BIT(BIT<T>)-> BIT<T>'
   21 | template<typename T> class BIT {
      |                            ^~~
a.cc:21:28: note:   candidate expects 1 argument, 0 provided
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

struct BIT {
    ll n;
    VL dat;
    void init(ll n_input) {
        n = n_input + 1;
        dat.resize(n + 1);
        for (int i = 0; i <= n; i++) dat[i] = 0;
    }
    ll sum(ll i) {
        ll s = 0;
        while (i >= 0) {
            s += dat[i];
            i = (i & (i + 1)) - 1;
        }
        return s;
    }
    void add(ll i, ll x) {
        while (i <= n) {
            dat[i] += x;
            i |= i + 1;
        }
    }
};

int main() {
    ll n;
    cin >> n;
    VL a(n), sorted(n);
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        sorted[i] = a[i];
    }
    sort(sorted.begin(), sorted.end());
    int ok = 0, ng = n;
    BIT bit;

    ll border = ((n * (n + 1) / 2) + 1) / 2;
    while (ng - ok > 1) {
        int mid = (ng + ok) / 2;
        int midnum = sorted[mid];
        bit.init(2 * n + 1);
        int sum = 0;
        bit.add(sum + n, 1);
        ll result = 0;
        for (i = 0; i < n; i++) {
            sum += (a[i] >= midmum ? 1 : -1);
            result += bit.sum(sum + n);
            bit.add(sum + n, 1);
        }
        if (result >= border)ok = mid;
        else ng = mid;
    }
    cout << sorted[ok] << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:49:10: error: 'i' was not declared in this scope
   49 |     for (i = 0; i < n; i++) {
      |          ^
a.cc:65:14: error: 'i' was not declared in this scope
   65 |         for (i = 0; i < n; i++) {
      |              ^
a.cc:66:29: error: 'midmum' was not declared in this scope; did you mean 'midnum'?
   66 |             sum += (a[i] >= midmum ? 1 : -1);
      |                             ^~~~~~
      |                             midnum
Language: C++

// review

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

using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;
const ll INF = 1e15;

int n;
ll a[MAXN];
ll sortedA[MAXN];
ll sum[MAXN];

class BIT {
  public:
    void init(ll size) {
      bit.resize(size + 1, 0);
    }
    ll sum(ll i) {
      if (!i) {
        return 0;
      }
      return bit[i] + sum(i - (i & -i));
    }

    void add(ll i, ll x) {
      if (i >= bit.size()) {
        return;
      }
      bit[i] += x;
      add(i + (i&-i), x);
    }
    std::vector<ll> bit;
};

bool check(ll x) {
  for (int i=0;i<n;i++) {
    if (a[i] >= x) {
      sum[i+1] = 1;
    } else {
      sum[i+1] = -1;
    }
  }
  for (int i=0;i<n;i++) {
    sum[i+1] += sum[i];
  }
  ll cnt = 0;
  BIT bit;
  bit.init(2 * n + 1);
  for (int i=0;i<=n;i++) {
    cnt += bit.sum(sum[i] + n);
    bit.add(sum[i] + n, 1);
  }
  return cnt >= n * (n+1) / 4;
}

void solve() {
  memcpy(sortedA, a, sizeof(a));
  sort(sortedA, sortedA + n);
  ll low = 0, high = n;
  while (high - low > 1) {
    ll mid = (low + high) / 2;
    if (check(sortedA[mid])) {
      low = mid;
    } else {
      high = mid;
    }
  }
  cout << sortedA[low] << endl;
}

int main() {
  cin >> n;
  for (int i=0;i<n;i++) {
    cin >> a[i];
  }
  solve();
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:61:3: error: 'memcpy' was not declared in this scope
   61 |   memcpy(sortedA, a, sizeof(a));
      |   ^~~~~~
a.cc:6:1: note: 'memcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    5 | #include <algorithm>
  +++ |+#include <cstring>
    6 |
Language: C++

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cctype>
#include <utility>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <numeric>
#include <bitset>
#include <ctime>
#include <list>
#include <seque>
#include <functional>
using namespace std;
const int MAXN = 100000;
const int INF = int(1E9);
int arr[MAXN + 5], sum[MAXN + 5], temp[MAXN + 5];
long long tot1 = 0, tot2 = 0;
int N;
void MergeSort(int le, int ri) {
    if( le == ri ) return ;
    int mid = (le + ri) >> 1;
    MergeSort(le, mid);
    MergeSort(mid+1, ri);
    int p = le, q = mid+1, r = le;
    while( p <= mid && q <= ri ) {
        if( sum[p] < sum[q] ) {
            temp[r++] = sum[p++];
        }
        else {
            tot1 += (p-le);
            temp[r++] = sum[q++];
        }
    }
    while( p <= mid ) {
        temp[r++] = sum[p++];
    }
    while( q <= ri ) {
        tot1 += (p-le);
        temp[r++] = sum[q++];
    }
    for(int i=le;i<=ri;i++)
        sum[i] = temp[i];
}
bool Check(int x) {
    tot1 = 0;
    for(int i=1;i<=N;i++)
        sum[i] = (arr[i] <= x ? 1 : -1);
    for(int i=1;i<=N;i++)
        sum[i] += sum[i-1];
    MergeSort(0, N);
    return tot1 >= (tot2/2 + 1);
}
int main() {
    int le = INF, ri = -INF;
    scanf("%d", &N);
    for(int i=1;i<=N;i++) { 
        scanf("%d", &arr[i]);
        le = min(le, arr[i]);
        ri = max(ri, arr[i]);
        tot2 += i;
    }
    while( le < ri ) {
        int mid = (le + ri) >> 1;
        if( Check(mid) ) ri = mid;
        else le = mid + 1;
    }
    printf("%d\n", ri);
}


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

#if 1

#include<bits/stdc++.h>
using namespace std;
long long long n,r,l = -1;
long long m,c,s,cnt,a[1000005];
int main()
{
    cin >> n;
	for(int i = 0;i < n;i++)
    {
        cin >> m;
        r = max(r,m);
        a[i] = m;
    }
	while(r > l+1)
    {
        if(c > n*(n+1)/4) r = m;
        else l = m;
		int b[2*n+5];
		memset(b,0,sizeof(b));
		m = (l + r) / 2;
		s = n;
		b[s] = 1;
		int i;
        #if 1
		for(cnt = c = i = 0;i < n;b[s]++,c += cnt)
        {
            if(a[i] > m)
            {
                //i++;
                s++;
                cnt += -b[s];
            }
            else
            {
                //i++;
                cnt += b[s];
                s--;
            }
            i++;
        }
        #endif
	}
	cout << r;
}

#endif // 1++


Compiler output:
a.cc:5:11: error: 'long long long' is too long for GCC
    5 | long long long n,r,l = -1;
      |           ^~~~
Language: C++

#if 1

#include<bits/stdc++.h>
using namespace std;
long n,r,l = -1;
int m,c,s,cnt,a[1000005];
int main()
{
    cin >> n;
	for(int i = 0;i < n;i++)
    {
        cin >> m;
        r = max(r,m);
        a[i] = m;
    }
	while(r > l+1)
    {
        if(c > n*(n+1)/4) r = m;
        else l = m;
		int b[2*n+5];
		memset(b,0,sizeof(b));
		m = (l + r) / 2;
		s = n;
		b[s] = 1;
		int i;
        #if 1
		for(cnt = c = i = 0;i < n;b[s]++,c += cnt)
        {
            if(a[i] > m)
            {
                //i++;
                s++;
                cnt += -b[s];
            }
            else
            {
                //i++;
                cnt += b[s];
                s--;
            }
            i++;
        }
        #endif
	}
	cout << r;
}

#endif // 1++


Compiler output:
a.cc: In function 'int main()':
a.cc:13:16: error: no matching function for call to 'max(long int&, int&)'
   13 |         r = max(r,m);
      |             ~~~^~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:13:16: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
   13 |         r = max(r,m);
      |             ~~~^~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:13:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   13 |         r = max(r,m);
      |             ~~~^~~~~
Language: C++

#include<stdio.h>
#include<math.h>
#include<stdlib.h>

void swap(int *x, int *y) {
	int temp;
	temp = *x;
	*x = *y;
	*y = temp;
}

int partition(int array[], int left, int right) {
	int i, j, pivot;
	i = left;
	j = right + 1;
	pivot = left;
	do {
		do { i++; } while (array[i] < array[pivot]);
		do { j--; } while (array[pivot] < array[j]);
		if (i < j) { swap(&array[i], &array[j]); }
	} while (i < j);
	swap(&array[pivot], &array[j]);
	return j;
}

void quick_sort(int array[], int left, int right) {
	int pivot;
	if (left < right) {
		pivot = partition(array, left, right);
		quick_sort(array, left, pivot - 1);
		quick_sort(array, pivot + 1, right);
	}
}

class segTree {
public:
	long long N;
	int *T;
	void init(int num) {
		N = 1;
		while (N < num) {
			N *= 2;
		}
		T = (int *)calloc((2 * N - 1), sizeof(int));
	}
	int act(int l, int r) {
		return l + r;
	}
	void add(int x, int v) {
		long long k = x + N - 1;
		T[k] += v;
		while (k > 0) {
			k = int(floor((k - 1) / 2));
			T[k] += v;
		}
	}
	int getV(int l, int r) {
		return getVs(l, r, 0, 0, N - 1);
	}
	int getVs(int l, int r, int k, int kl, int kr) {
		if (l <= kl && r >= kr) {
			return T[k];
		}
		int t = int(floor((kl + kr) / 2));
		if (l > t) {
			return getVs(l, r, 2 * k + 2, t + 1, kr);
		}
		if (r < t + 1) {
			return getVs(l, r, 2 * k + 1, kl, t);
		}
		return act(getVs(l, r, 2 * k + 1, kl, t),
			getVs(l, r, 2 * k + 2, t + 1, kr));
	}
	~segTree()
	{
		free(T);
	}
};

bool judge(int x, long long N, int *a) {
	int *v;
	v = (int *)malloc((N + 1) * sizeof(int));
	int mi = 0;
	int ma = 0;
	v[0] = 0;
	for (int i = 0; i < N; i++) {
		v[i + 1] = v[i] + (a[i] < x ? -1 : 1);
		if (mi > v[i + 1])
			mi = v[i + 1];
		if (ma < v[i + 1])
			ma = v[i + 1];
	}
	segTree b;
	b.init(ma - mi + 1);

	long long Ans = 0;
	for (int i = 0; i < N + 1; i++) {
		Ans += b.getV(0, v[i] - mi);
		b.add(v[i] - mi, 1);
	}
	return Ans >= N * (N + 1) / 4;
}

int main()
{
	int N;
	scanf("%d", &N);
	int *a;
	int *b;
	a = (int *)malloc(N * sizeof(int));
	b = (int *)malloc(N * sizeof(int));
	for (int i = 0; i < N; i++) {
		scanf("%d", &a[i]);
		b[i] = a[i];
	}
	quick_sort(b, 0, N - 1);
	return;
	int re = b[0];
	int cnt = 1;

	for (int i = 1; i < N; i++) {
		if (b[i] != re) {
			re = b[i];
			b[cnt] = b[i];
			cnt++;
		}
	}
	int ok = 0;
	int ng = cnt;
	int mid;
	while (ng - ok > 1) {
		mid = int(floor((ok + ng) / 2));
		if (judge(b[mid], N, a)) {
			ok = mid;
		}
		else {
			ng = mid;
		}
	}
	printf("%d\n", b[ok]);
}


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

#include<iostream>
using namespace std;

int main(){
  
	int n;
  	cin>>n;
  	int a[n];
  	int copy_of_a;
  	for(int i=0;i<n;i++){
      cin>>a[n];
    }
  	for(int i=0;i<n+i++){
      for(int j=0;j<(n-1);j++){
        if(a[j]>a[j+1]){
          copy_of_a=a[j];
          a[j]=a[j+1];
          a[j+1]=copy_of_a;
        }
      }
    }
  cout<<a[int(n/2)+1]<<endl;
  
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:28: error: expected ';' before ')' token
   13 |         for(int i=0;i<n+i++){
      |                            ^
      |                            ;
Language: C++

#include<iostream>
using namespace std;

int main(){
  
	int n;
  	cin>>n;
  	int a[n];
  	int copy_of_a;
  	for(int i=0;i<n;i++){
      cin>>a[n];
    }
  	for(int i=0;i<n+i++){
      for(int j=0;j<(n-1);j++){
        if(a[j]>a[j+1]){
          copy_of_a=a[j]
          a[j]=a[j+1];
          a[j+1]=copy_of_a;
        }
      }
    }
  cout<<a[int(n/2)+1]
  
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:28: error: expected ';' before ')' token
   13 |         for(int i=0;i<n+i++){
      |                            ^
      |                            ;
a.cc:16:25: error: expected ';' before 'a'
   16 |           copy_of_a=a[j]
      |                         ^
      |                         ;
   17 |           a[j]=a[j+1];
      |           ~              
a.cc:22:22: error: expected ';' before 'return'
   22 |   cout<<a[int(n/2)+1]
      |                      ^
      |                      ;
   23 | 
   24 |         return 0;
      |         ~~~~~~
Language: C++

include<iostream>
using namespace std;

int main(){
  
	int n;
  	cin<<n;
  	int a[n];
  	int copy_of_a
  	for(int i=0;i<n;i++){
      cin<<a[n];
    }
  	for(int i=0;i<n+i++){
      for(int j=0;j<(n-1);j++){
        if(a[j]>a[j+1]){
          copy_of_a=a[j]
          a[j]=a[j+1];
          a[j+1]=copy_of_a;
        }
      }
    }
  cout>>a[int(n/2)+1]
  
	return 0;
}

Compiler output:
a.cc:1:1: error: 'include' does not name a type
    1 | include<iostream>
      | ^~~~~~~
a.cc: In function 'int main()':
a.cc:7:9: error: 'cin' was not declared in this scope
    7 |         cin<<n;
      |         ^~~
a.cc:10:9: error: expected initializer before 'for'
   10 |         for(int i=0;i<n;i++){
      |         ^~~
a.cc:10:21: error: 'i' was not declared in this scope
   10 |         for(int i=0;i<n;i++){
      |                     ^
a.cc:13:28: error: expected ';' before ')' token
   13 |         for(int i=0;i<n+i++){
      |                            ^
      |                            ;
a.cc:16:11: error: 'copy_of_a' was not declared in this scope
   16 |           copy_of_a=a[j]
      |           ^~~~~~~~~
a.cc:22:3: error: 'cout' was not declared in this scope
   22 |   cout>>a[int(n/2)+1]
      |   ^~~~
Language: C++

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

#ifdef LOCAL
	#define de(x) cout<<#x<<"="<<x<<endl
	#define rff freopen("input.txt","r",stdin)
	#define wtf freopen("input.txt","w",stdout)
	#include "Debug.h"
#else
	#define de(x)
	#define rff
#endif

#define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define For(i,n) for (int i=1;i<=(int)(n);i++)
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define vi vector <int>
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define pb push_back
#define re return
#define se second
#define fi first
const int INF=0x7fffffff;
const int MAXN=1e5+3;
const int BASE=100000;
#define low_bit(x) x&(-x)

int bit[MAXN*2],n,a[MAXN];
vi v;

ll query(int x){
	x+=BASE;
	ll r=0;
	while (x){
		r+=bit[x];
		x-=low_bit(x);
	}
	re r;
}

void add(int x){
	x+=BASE;
	while (x<MAXN*2){
		bit[x]++;
		x+=low_bit(x);
	}
}

int main(){
	fio;
	cin>>n;
	For(i,n){
		cin>>a[i];
		v.pb(a[i]);
	}
	sort(all(v));
	v.erase(unique(all(v)),v.end());
	ll l=0,r=v.size(),mid,x,cnt;
	ll tar=ll(n)*(n-1)/2/2;
	while (l<r-1){
		memset(bit,0,sizeof(bit));
		cnt=0;	
		mid=(l+r)>>1;
		x=0;
		add(0);
		For(i,n){
			if (a[i]>=v[mid]) x++;
			if (a[i]<v[mid]) x--;
			cnt+=query(x);
			add(x);
		}
		if (cnt<tar){
			r=mid;
		}else{
			l=mid;
		}
	}
	cout<<v[l]<<endl;
	re 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:12: error: expected primary-expression before 'long'
   22 | #define ll long long
      |            ^~~~
a.cc:63:16: note: in expansion of macro 'll'
   63 |         ll tar=ll(n)*(n-1)/2/2;
      |                ^~
Language: C++

#include <bits/stdc++.h>

#define Set(a, b) memset(a, b, sizeof (a))
#define For(i, j, k) for (int i = j; i <= k; ++ i)
#define Forr(i, j, k) for (int i = j; i >= k; -- i)

using namespace std;

typedef long long ll;

inline int read() {
	int x = 0, p = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') p = -1;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x * p;
}

inline void File() {
	freopen("D.in", "r", stdin);
	freopen("D.out", "w", stdout);
}

const int N = 1e5 + 10, bas = 1e5, inf = 0x3f3f3f3f;
int a[N], n, s[N], ans;

struct BIT {
	int c[N << 1], lim = N << 1; 

	inline void init() { Set(c, 0); }	
	
	inline void update(int x, int v) {
		for (; x <= lim; x += x & -x) c[x] += v;
	}

	inline int query(int x) {
		static int res;
		for (res = 0; x; x -= x & -x) res += c[x];
		return res;
	}
} T;

inline bool check(int x) {
	T.init(), Set(s, 0);
	For(i, 1, n) s[i] = s[i - 1] + (a[i] >= x ? 1 : -1);

	ll res = 0;
	T.update(bas, 1);
	For(i, 1, n) {
		res += T.query(s[i] + bas);
		T.update(s[i] + bas, 1);
	}

	return res >= 1ll * n * (n - 1) / 4;
}

int main() {

	n = read();

	int mx = 0;
	For(i, 1, n) mx = max(mx, a[i] = read());

	for (int l = 0, r = mx; l <= r; ) {
		int mid = l + r >> 1;
		if (check(mid)) ans = mid, l = mid + 1;
		else r = mid - 1;
	}
	
	cout << r << endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:69:17: error: 'r' was not declared in this scope
   69 |         cout << r << endl;
      |                 ^
Language: C++

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>

using namespace std;

const int maxN = 1e5 + 10;

int n, a[maxN], s[maxN], res;
map < long long, int > mmap;
long long t[maxN];

void update(int x) {
    for (; x <= 1e5; x += (x & (-x)))
        ++t[x];
}

long long get(int x) {
    long long tmp = 0;
    for (; x; x -= (x & (-x)))
        tmp += t[x];
    return tmp;
}


int main() {
    cin >> n;
    int l = 1, r = 1;
    for (int i = 0; i < n; ++i)
        cin >> a[i], r = max(r, a[i]);
    long long req = (1ll * n * (n + 1)) / 2;
    req = (req % 2) ? (req / 2) + 1 : req / 2;
    while (l <= r) {
        int mid = (l + r) >> 1;
        mmap.clear();
        for (int i = 0; i < n; ++i) {
            s[i] = ((i == 0) ? 0 : s[i - 1]) +
                ((a[i] < mid) ? -1 : 1);
            mmap[s[i]] = 0;
        }
        memset(t, 0, sizeof(t));
        int val = 1;
        long long cnt = 0;
        for (auto p : mmap) mmap[p.first] = val++;
        for (int i = 0; i < n; ++i) {
            int v = mmap[s[i]];
            cnt += get(v) + (s[i] >= 0);
            update(v);
        }
        if (cnt >= req) l = mid + 1, res = mid;
        else r = mid - 1;
    }
    cout << res;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:43:9: error: 'memset' was not declared in this scope
   43 |         memset(t, 0, sizeof(t));
      |         ^~~~~~
a.cc:6:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    5 | #include <map>
  +++ |+#include <cstring>
    6 |
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pll pair<ll,ll>
#define pb push_back
#define F first
#define S second
#define I insert
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
#define endl '\n'

ll power(ll a, ll b, ll mod){ ll c = 1; while(b>0){ if(b%2) c*=a, c%=mod; b/=2; a*=a; a%=mod; } return c; }
 
const ll N = (1e5) + 10;
const ll M = 320;
const ll Mod = 1e9 + 7;
ll ar[N],br[N];
vll u;

ll go(ll a, ll b){
	if(a == b) return 0;
	ll mid = (a+b)/2;
	ll ans = go(a,mid)+go(mid+1,b);
	u.clear();
	ll i,j;
	i = a; j = mid+1;
	while(i <= mid && j <= b){
		while(i<=mid && br[i] <= br[j]) u.pb(br[i++]), ans += j-(mid+1);
		if(i > mid) break;
		while(j<=b && br[j] < br[i]) u.pb(br[j++]);
	}
	while(i<=mid) u.pb(br[i++]), ans += j-(mid+1);
	while(j<=b) u.pb(br[j++]);
	for(i=a;i<=b;i++)
		br[i] = u[i-a];
	return ans;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout<<setprecision(25);
    ll n,hi,lo,mid,a,b,c,d,i,j,k;
    cin>>n; vll v;
    for(i=1;i<=n;i++) cin>>ar[i], v.pb(ar[i]);
    ll amt = (n*(n+1))/2;
	ll inv,ans;
	sort(all(v)); v.resize(unique(all(v))-v.begin());
	lo = 0;
	hi = sz(v)-1;
    while(hi= > lo){
    	mid = (hi+lo)/2;
    	for(i=1;i<=n;i++) br[i] = ((ar[i] >= v[mid]) ? 1 : -1), br[i] += br[i-1];
		inv = amt - go(1,n);
    	if(2*inv >= amt){
    		ans = mid;
    		lo = mid+1;
    	}
    	else{
    		hi = mid-1;
    	}
    }
    cout<<v[ans]<<endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:53:15: error: expected primary-expression before '>' token
   53 |     while(hi= > lo){
      |               ^
Language: C++

/*
By Tianyi Chen. All rights reserved.
Date: 2018-08-30
*/
#include<bits/stdc++.h>
using namespace std;
int n,a[100000],b[100000],p[100000];
int64_t ap;
int64_t inversions(int*s,int*e){
 if(e-s<=1)return 0;
 auto mid=s+(e-s>>1);
 int64_t rt=inversions(s,mid)+inversions(mid,e);
 auto t=new int[e-s],tp=t;
 for(auto l=s,r=mid;l<mid||r<e;){
  if(l<mid&&r<e)*tp++=*l>*r?(rt+=mid-l,*r++):*l++;
  else if(l<mid)*tp++=*l++;
  else *tp++=*r++;
 }
 copy(t,e-s+t,s);
 return rt;
}
bool j(int m){
 m=b[m];
 *p=*a>=m?1:-1;
 for(int i=1;i<n;++i)p[i]=p[i-1]+(a[i]>=m?1:-1);
 int64_t iv=inversions(p,p+n);
 for(int i=0;i<n;++i)if(a[i]<m)++iv;
 bool geq=ap-iv>=ap/2;
 dmp(ap-iv);dmp(ap);
 return geq;
}
int main(){
 scanf("%d",&n);for(int i=0;i<n;++i)scanf("%d",a+i);
 copy(a,a+n,b);
 sort(b,b+n);
 ap=n*int64_t(n+1)>>1;
 int high=n-1,low=0;
 while(high-low>1){
  int mid=high+low>>1;
  (j(mid)?low:high)=mid;
 }
 while(low<n-1&&j(low+1))++low;
 printf("%d\n",b[low]);
}

Compiler output:
a.cc: In function 'bool j(int)':
a.cc:29:2: error: 'dmp' was not declared in this scope; did you mean 'dup'?
   29 |  dmp(ap-iv);dmp(ap);
      |  ^~~
      |  dup
Language: C++

/*
By Tianyi Chen. All rights reserved.
Date: 2018-08-30
*/
#include<bits/stdc++.h>
using namespace std;
int n,a[100000],b[100000],p[100000];
int64_t inversions(int*s,int*e){
 if(e-s<=1)return 0;
 auto mid=s+(e-s>>1);
 int64_t rt=inversions(s,mid)+inversions(mid,e);
 auto t=new int[e-s],tp=t;
 for(auto l=s,r=mid;l<mid||r<e;){
  if(l<mid&&r<e)*tp++=*l>*r?(rt+=mid-l,*r++):*l++;
  else if(l<mid)*tp++=*l++;
  else *tp++=*r++;
 }
 delete[]t;
 return rt;
}
int main(){
 scanf("%d",&n);for(int i=0;i<n;++i)scanf("%d",a+i);
 copy(a,a+n,b);
 sort(b,b+n);
 int64_t ap=n+(n*int64_t(n-1)>>1);
 int high=n-1,low=0;
 while(high-low>1){
  int mid=high+low>>1;
  ([=](int m){
   *p=*a>=m?1:-1;
   for(int i=1;i<n;++i)p[i]=p[i-1]+(a[i]>=m?1:-1);
   int64_t np=ap-inversions(p,p+n);
   for(int i=0;i<n;++i)cerr<<p[i]<<' ';dmp(np);
   for(int i=0;i<n;++i)if(p[i]>=0)++np;
   bool geq=np>=ap/2;
   return !geq;
  }(mid)?high:low)=mid;
 }
 printf("%d\n",b[high]);
}

Compiler output:
a.cc: In lambda function:
a.cc:33:40: error: 'dmp' was not declared in this scope; did you mean 'dup'?
   33 |    for(int i=0;i<n;++i)cerr<<p[i]<<' ';dmp(np);
      |                                        ^~~
      |                                        dup
Language: C++

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

int N;
int bit[1000010];
void init(int size){
	
	for(int i = 0; i < size; i++)
	{
		bit[i] = 0;
	}
	
}
void add(int a, int w) {
	for (int x = a; x <= 1000010; x += x & -x) bit[x] += w;
}
int sum(int a) {
	int ret = 0;
	for (int x = a; x > 0; x -= x & -x) ret += bit[x];
	return ret;
}

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

	vector<int> A(N);
	vector<int> sorted(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		sorted[i] = A[i];
	}
	sort(sorted.begin(), sorted.end());

	vector<int> S(N);

	int lb =0, ub = N;
	while(ub - lb > 1){
		// cout << "ub=" << ub <<"lb=" << lb << endl;

		init(2*N+1);
		// cout << "------" << endl;
		int len = ub-lb;
		int x = len/2;
		int median = sorted[x+lb];
		// cout << "median:" << median << endl;
		for (int i = 0; i < N; i++)
		{
			if (median <= A[i])
			{
				S[i] = 1;
			}
			else
			{
				S[i] = -1;
			}
		}
		for (int i = 0; i < N; i++)
		{
			if (i != 0)
			{
				S[i] = S[i - 1] + S[i];
			}
			else
			{
				S[0] = S[0];
			}
		}
		
		// add(N,1);
		int cnt = 0;
		for(int i = 0; i < N; i++)
		{
			cnt += sum(S[i]+N);
			// cout << "sum("<<S[i]+N<<")="<<sum(S[i]+N)<<endl;
			add(S[i]+N,1);

		}
		// cout << "cnt=" << cnt << endl;
		if(cnt>=ceil(N*(N+1)/2/2)){
			lb = x+1;
		}else{
			ub = x-1;
		}
		// break;
	}
	cout << sorted[lb] << endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:37:9: error: 'sort' was not declared in this scope; did you mean 'sqrt'?
   37 |         sort(sorted.begin(), sorted.end());
      |         ^~~~
      |         sqrt
Language: C++

#include <bits/stdc++.h>
 
#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))
 
using namespace std;
 
typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;
 
template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
 
template<typename T>
ostream& operator << (ostream& os, vector<T> v)
{
  os << "(";
  each (i, v) os << i << ",";
  os << ")";
  return os;
}
 
template<typename T>
class BIT {
public:
  BIT(int n_)
  {
    n = n_;
    bit.resize(n + 1, 0);
  }
  T sum (int i)
  {
    return _sum(i + 1);
  }
  void add(int i, T x)
  {
    return _add(i + 1, x);
  }
private:
  vector<T> bit;
  int n;
  T _sum(int i)
  {
    T s = 0;
    while (i > 0) {
      s += bit[i];
      i -= i & -i;
    }
    return s;
  }
  void _add(int i, T x)
  {
    while (i <= n) {
      bit[i] += x;
      i += i & -i;
    }
    return ;
  }
};
 
// https://codeforces.com/blog/entry/18879
lli subsequence_median(vector<int> v, int b)
{
  each (i, v) {
    if (i < b) i = -1;
    else i = +1;
  }
  v.insert(v.begin(), 0);

  for (int i = 1; i < v.size(); ++i) {
    v[i] += v[i - 1];
  }
 
  vector<int> ord;
  for (int i = 0; i < v.size(); ++i) {
    ord.push_back(i);
  }
  stable_sort(ord.begin(), ord.end(), [&] (int a, int b) { return v[a] < v[b]; });
 
  BIT<lli> bit(v.size());
  lli sum = 0;
  for (int i = 0; i < v.size(); ++i) {
    sum += bit.sum(ord[i]);
    bit.add(ord[i], 1);
  }

  return sum + len1;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  lli n;
  while (cin >> n) {
    vector<int> a(n);
    each (i, a) cin >> i;
 
    vector<int> b = a;
    sort(b.begin(), b.end());
    b.erase(unique(b.begin(), b.end()), b.end());
 
    int small = 0;
    int large = b.size();
    while (small + 1 < large) {
      int mid = (small + large) / 2;
      if ((n * (n - 1) / 2 + n + 1) / 2 <= subsequence_median(a, b[mid])) small = mid;
      else large = mid;
    }
 
    cout << b[small] << endl;
  }
  return 0;
}


Compiler output:
a.cc: In function 'lli subsequence_median(std::vector<int>, int)':
a.cc:92:16: error: 'len1' was not declared in this scope
   92 |   return sum + len1;
      |                ^~~~
Language: Java

import java.util.*;
import java.io.*;

public class B{

	
	
	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner(System.in);
		PrintWriter  out=new PrintWriter(System.out);
		int n=sc.nextInt();
		int []a=new int [n];
		int hi=0;
		for(int i=0;i<n;i++)
		{
			a[i]=sc.nextInt();
			hi=Math.max(hi,a[i]);
		}
		int lo=0;
		long min=(n*1L*(n-1)/2+1)/2;
		int ans=-1;
		// binary search on the greatest x such that the # of pairs(l,r) such that m(l,r) is >=x is>= (n*(n-1)/2)/2
		while(lo<=hi) 
		{
			int mid=(lo+hi)/2;
			long pairs=0;
			for(int l=0;l<n;l++) 
			{
				
				for(int r=l;r<n;r++)
				{
					int cnt=0;
					for(int k=l;k<=r;k++)
						if(a[k]>=mid)
							cnt++;
						else
							cnt--;
					if(cnt>=0)
						pairs++;
					
				}
			}
			if(pairs>=min) 
			{
				ans=mid;
				lo=mid+1;
			}
			else 
				hi=mid-1;
			
				
			/*int []s=new int [n+1];
			for(int i=1;i<=n;i++)
			{
				if(a[i-1]>=mid)
					s[i]=1;
				else
					s[i]=-1;
				s[i]+=s[i-1];
			}
			long inversions=0;*/
			
					
		}
		out.println(ans);
		out.close();
	}
	
	
	static class Scanner {
        StringTokenizer st;
        BufferedReader br;
 
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }
 
        public Scanner(FileReader s) {
            br = new BufferedReader(s);
        }
 
        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }
 
        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
 
        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
 
        public String nextLine() throws IOException {
            return br.readLine();
        }
        public boolean ready() throws IOException {return br.ready();}
        public double nextDouble() throws IOException {return Double.parseDouble(next());}
       
    }

}

Compiler output:
Main.java:4: error: class B is public, should be declared in a file named B.java
public class B{
       ^
1 error
Language: C++

#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
template <typename T>
class SegmentTree{
    public:
        ll size;
        vector<T> node;
        T identity_ele;  //comp(x, identity_ele) == x
        function<T(T, T)> comp;

        SegmentTree(const vector<T> &v, function<T(T, T)> comp, T identity_ele){
            ll tmp = 1;
            while(tmp < v.size()) tmp = (tmp << 1);
            this->size = tmp;
            this->identity_ele = identity_ele;
            this->comp = comp;
            node.resize(2 * size - 1);
            for(ll i = 0; i < v.size(); i++){
                node[i + size - 1] = v[i];
            }
            for(ll i = size - 2; 0 <= i; i--){
                node[i] = comp(node[i * 2 + 1], node[i * 2 + 2]);
            }
        }

        void update(ll pos){
            pos += size - 1;
            node[pos]++;
            while(pos > 0){
                pos = (pos - 1) / 2;
                node[pos]++;
            }
        }

        T query(ll a, ll b){
            return subQuery(a, b, 0, 0, size);
        }

        T subQuery(ll a, ll b, ll k, ll l, ll r){
            return (r <= a || b <= l ? identity_ele : (a <= l && r <= b ? node[k] : comp(subQuery(a, b, k * 2 + 1, l, (l + r) / 2), subQuery(a, b, k * 2 + 2, (l + r) / 2, r))));
        }
};

void setID(map<ll, ll> &ma, ll v){
    if(ma.find(v) != ma.end()) return;
    ll num = ma.size();
    ma[v] = num;
}

map<ll, ll> sortedID(vector<ll> v){
    sort(v.begin(), v.end());
    map<ll, ll> ret;
    for(auto u : v) setID(ret, u);
    return ret;
}

int main(){
    ll N;
    cin >> N;
    ll x[N];
    for(ll i = 0; i < N; i++) cin >> x[i];
    vector<ll> kind(N);
    copy(x, x + N, kind.begin());
    sort(kind.begin(), kind.end());
    auto tmp = unique(kind.begin(), kind.end());
    kind.erase(tmp, kind.end());
    ll ng = kind.size(), ok = 0;
    while(abs(ok - ng) > 1){
        ll mid = (ok + ng) / 2;
        ll tmp[N];
        for(ll i = 0; i < N; i++) tmp[i] = (kind[mid] <= x[i] ? 1 : -1);
        vector<ll> sum(N + 1);
        for(ll i = 0; i < N; i++) sum[i + 1] = sum[i] + tmp[i];
        map<ll, ll> ID = sortedID(sum);
        SegmentTree<ll> S(vector<ll>(ID.size(), 0), [](ll a, ll b){return a + b;}, 0);
        S.update(ID[0]);
        ll po = 0;
        sum.erase(sum.begin());
        for(auto u : sum){
            ll u = sum[i];
            po += S.query(0, ID[u] + 1);
            S.update(ID[u]);
        }
        ll yo = N * (N - 1) / 2 + N;
        if(po >= yo / 2) ok = mid;
        else ng = mid;
    }
    cout << kind[ok] << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:81:16: error: redeclaration of 'll u'
   81 |             ll u = sum[i];
      |                ^
a.cc:80:18: note: 'long int u' previously declared here
   80 |         for(auto u : sum){
      |                  ^
a.cc:81:24: error: 'i' was not declared in this scope
   81 |             ll u = sum[i];
      |                        ^