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

#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

ll fenwick[200100];

void add( int a, int x ){
	for( int i = a; i <= 200010; i += ( i & -i ) ) fenwick[i] += x;
}

ll sum( int a ){
	ll res = 0;
	for( int i = a; i > 0; i -= ( i & -i ) ) res += fenwick[i];
	return res;
}

int main(){
	ll n; cin >> n;
	vector<int> v(n);
	ll maxi = 0;
	for( auto &i : v ){
		cin >> i;
		maxi = max(i, maxi);
	}
	ll thres = n*(n+1)/4;
	ll l = 0, r = maxi+1;
	while( r-l > 1 ){
		ll m = (r+l)/2;
		vector<ll> s(n+1);
		s[0] = 100001;
		for( int i = 1; i <= n; ++i ){
			s[i] = s[i-1] + ( ( v[i-1] >= m ) ? 1 : -1 );
		}
        ll ans = 0;
		memset( fenwick, 0ll, sizeof(fenwick) );
        for( int i = 0; i <= n; ++i ){
            ans += sum(s[i]);
            add( s[i], 1 );
        }
		// cout << l << " " << m << " " << r << " " << ans << endl;
		if( ans >= thres ){
			l = m;
		} else {
			r = m;
		}
	}
	cout << l << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:26:27: error: no matching function for call to 'max(int&, ll&)'
   26 |                 maxi = max(i, maxi);
      |                        ~~~^~~~~~~~~
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:1:
/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:26:27: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   26 |                 maxi = max(i, maxi);
      |                        ~~~^~~~~~~~~
/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:26:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   26 |                 maxi = max(i, maxi);
      |                        ~~~^~~~~~~~~
Language: C++

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
typedef long long ll;
#define mp make_pair
int n;
ll ans;
ll n;
ll dat[100005];
ll tmp[100005];
ll pre[100005];
void merge(ll a[],ll l,ll r){
	if(l==r){
		return;
	}
	ll mid=(l+r)/2;
	merge(a,l,mid);
	merge(a,mid+1,r);
	ll x=l;
	ll y=mid+1;
	ll id=l;
	while(x<=mid && y<=r){
		if(a[x]>a[y]){
			tmp[id++]=a[y];
			ans+=mid-x+1;
			y++;
		}
		else{
			tmp[id++]=a[x];
			x++;
		}
	}
	while(x<=mid){
		tmp[id++]=a[x++];
	}
	while(y<=r){
		tmp[id++]=a[y++];
	}
	for(ll i=l;i<=r;i++){
		a[i]=tmp[i];
	}
}
bool check(ll mid){
	ans=0;
	for(ll i=1;i<=n;i++){
		if(dat[i]<mid){
			pre[i]=pre[i-1]-1;
		}
		else{
			pre[i]=pre[i-1]+1;
		}
		if(pre[i]<0){
			ans++;
		}
	}
	merge(pre,1,n);
	return (n*(n+1))/2>=2*ans;
}
int main(){
	cin>>n;
	for(ll i=1;i<=n;i++){
		cin>>dat[i];
	}
	ll l=1;
	ll r=INF;
	while(l+1<r){
		ll mid=(l+r)/2;
		if(check(mid)){
			l=mid;
		}
		else{
			r=mid;
		}
	}
	if(check(l+1)){
		l++;
	}
	cout<<l<<endl;
	return 0;
}

Compiler output:
a.cc:29:4: error: conflicting declaration 'll n'
   29 | ll n;
      |    ^
a.cc:27:5: note: previous declaration as 'int n'
   27 | int n;
      |     ^
a.cc: In function 'int main()':
a.cc:86:14: error: 'INF' was not declared in this scope
   86 |         ll r=INF;
      |              ^~~
Language: C++

// author: Saman Mahdanian
#include <iostream>
#include <cstring>

using namespace std;
const int N = 1e5 + 10;

#define int long long

int n, a[N], _cnt[2 * N];
long long get_le (int);

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

	long long g  = 2e9;
	long long le = 0;
	while (g - le > 1) {
		int med = (g + le) / 2;
		if (get_le(med) * 2 > (n * (n + 1)) / 2)
			g = med;
		else
			le = med;
	}

	cout << g << endl;
}

/*
*/

long long get_le (int x) {
	memset (_cnt, 0, sizeof _cnt);
	int* cnt = &_cnt[N];
	cnt[0] = 1;
	int cur = 0, p = 0;
	long long res = 0;

	for (int i = 0; i < n; i++) {
		int val = a[i] <= x? +1 : -1;
		cur += val * cnt[p];
		cur = max(cur, 0);
		res += cur;
		p += val;
		cnt[p]++;
	}
	return res;
} 

// SamMHD :: 05/12/2018 15:52:56 :: Another Nemidoonam-Che-Kooftie...

Compiler output:
a.cc: In function 'long long int get_le(long long int)':
a.cc:44:26: error: no matching function for call to 'max(long long int&, int)'
   44 |                 cur = max(cur, 0);
      |                       ~~~^~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/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:44:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   44 |                 cur = max(cur, 0);
      |                       ~~~^~~~~~~~
/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
Language: C++

// author: Saman Mahdanian
#include <iostream>

using namespace std;

const int N = 1e5 + 10;

int n, a[N], cnt[N];

long long get_le (int);

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

	long long int g  = 2e9;
	long long int le = 0;
	while (g - le > 1) {
		int med = (g + le) / 2;
		if (get_le(med) * 2 > (n * (n + 1)) / 2)
			g = med;
		else
			le = med;
	}

	cout << g << endl;
}

long long get_le (int x) {
	// cout << "asking for lower/equal medians of: " << x << endl;
	memset (cnt, 0, sizeof cnt);
	cnt[0] = 1;
	int cur = 0, p = 0;
	long long res = 0;

	for (int i = 0; i < n; i++) {
		int val = a[i] <= x? +1 : -1;
		cur += val * cnt[p];
		res += cur;
		p += val;
		cnt[p]++;
	}
	// cout << " ~~~: " << res << endl;
	return res;
} 

// SamMHD :: 05/12/2018 15:52:56 :: Another Nemidoonam-Che-Kooftie...

Compiler output:
a.cc: In function 'long long int get_le(int)':
a.cc:32:9: error: 'memset' was not declared in this scope
   32 |         memset (cnt, 0, sizeof cnt);
      |         ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    2 | #include <iostream>
  +++ |+#include <cstring>
    3 |
Language: C

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define MAXN 100001
using namespace std;
int n,a[MAXN],s[MAXN],l,r,f[MAXN*2+10],b[MAXN],c[MAXN*2+10];
void add(int x)
{
	while(x<=2*MAXN) f[x]++,x+=x&-x;
	return ;
}
int query(int x)
{
	int tot=0;
	while(x>0) tot+=f[x],x-=x&-x;
	return tot;
}
bool check(int x)
{
	memset(f,0,sizeof f);
	for(int i=1;i<=n;i++)
	{
		if(a[i]>=x) c[i]=1;
		else c[i]=-1;
		c[i]+=c[i-1];
	}
	int ans=0;
	for(int i=0;i<=n;i++) 
	ans+=(query(c[i]+MAXN)),add(c[i]+MAXN);
	//for(int i=2;i<=n;i++) if
	//ans=n*(n-1)/2-ans;
	return ans>=n*(n+1)/4?true:false;
}
void slove()
{
	l=1,r=n;int mid;
	while(l<=r)
	{
		mid=l+r>>1;
		if(check(s[mid])) l=mid+1;
		else r=mid-1;
	}
	cout<<s[r];
	return;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i],s[i]=a[i];
	sort(s+1,s+n+1);
	slove();
	return 0;
}

Compiler output:
main.c:1:9: fatal error: cstdio: No such file or directory
    1 | #include<cstdio>
      |         ^~~~~~~~
compilation terminated.
Language: C

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define INF 0x3f3f3f3f
const int N=1e5+4;
string s;
int main()
{
    cin>>s;
    int f=0,g=0;
    for(int i=1; i<s.size(); i++)
    {
        if(i<s.size()-1&&f&&s[i]=='A'&&s[i+1]=='B')
            g=1;
        if(s[i]=='A'&&s[i-1]=='B')
            f=1;

    }
    if(g)
        puts("YES");
    else
    {
        f=g=0;
        for(int i=1; i<s.size(); i++)
        {
            if(i<s.size()-1&&f&&s[i]=='B'&&s[i+1]=='A')
                g=1;
            if(s[i]=='B'&&s[i-1]=='A')
                f=1;

        }
        if(g)puts("YES");
        else puts("NO");
    }
}
/*


*/


Compiler output:
main.c:1:9: fatal error: bits/stdc++.h: No such file or directory
    1 | #include<bits/stdc++.h>
      |         ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include<cstdio>
#include<algorithm>
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);
}

---------------------

本文来自 Tiw_Air_OAO 的CSDN 博客 ，全文地址请点击：https://blog.csdn.net/Tiw_Air_Op1721/article/details/82077501?utm_source=copy 

Compiler output:
a.cc:60:1: error: expected unqualified-id before '--' token
   60 | ---------------------
      | ^~
Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int n,k[100005],mon[100005];
  cin>>n;
  vector<pair<long long int,long long int>>v(n);
  mon[0]=n;
  long long int total=n;
  for(int i=0;i<n;++i){
    cin>>k[i];
    if(n==1){
      cout<<k[0]<<endl;
      return 0;
    }
    if(n%2==0){
      if(i<=n/2-1&&i!=0){
        mon[i]=(i+1)*(n-i)+((1+i)*i)/2;
        v[i]=make_pair(k[i],mon[i]);
        total+=mon[i];
      }
      else{
        v[i]=make_pair(k[i],mon[n-1-i]);
        total+=mon[n-1-i];
      }
    }
    else{
      if(n%2==1&&i==n/2+1){
        v[i]=make_pair(k[i],mon[i-1]+1);
        total+=mon[i-1]+1;
      }
      else if(i<n/2+1&&i!=0){
        mon[i]=(i+1)*(n-i)+((1+i)*i)/2
        v[i]=make_pair(k[i],mon[i]);
        total+=mon[i];
      }
      else{
        v[i]=make_pair(k[i],mon[n-1-i]);
        total+=mon[n-1-i];
      }
     }
  }
  sort(v.begin(),v.end());
  long long int sum=0;
  for(int i=0;i<n;++i){
    sum+=v[i].second;
    if(sum>=total/2+1){
      cout<<v[i].first<<endl;
      break;
    }
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:32:39: error: expected ';' before 'v'
   32 |         mon[i]=(i+1)*(n-i)+((1+i)*i)/2
      |                                       ^
      |                                       ;
   33 |         v[i]=make_pair(k[i],mon[i]);
      |         ~
Language: C

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

#define MAX_INPUT   (100000000000000)
#define MAX_DATAS   (100000)

static char str[MAX_INPUT];     /* 標準入力用の配列 */
static int data[MAX_DATAS];     /* 数列 */
static int tmpCalcMedians[MAX_DATAS];  /* 中央値計算用 */
static int medians[MAX_DATAS];  /* 中央値 */
static int N = 0;
static int count = 0;

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

void calcMedian(int startNum, int endNum)
{
    int j = 0;
    for (int i = startNum; i <= endNum; i++) {
        tmpCalcMedians[j++] = data[i];
    }
    int num = endNum - startNum + 1;
    qsort(tmpCalcMedians, num, sizeof(int), compare_int);
    medians[count++] = tmpCalcMedians[(num / 2) + 1];
}

void getInput(char *pstr)
{
    gets(pstr);
}

int main() {
    char *pstr = &str[0];
    /* Nを読み込む */
    getInput(pstr);
    N = atoi(pstr);
    //printf("%d\n", N);
    
    /* 数列を読み出す */
    getInput(pstr);
    data[0] = atoi(strtok(pstr, " "));
    for (int i = 1; i < N; i++) {
        data[i] = atoi(strtok(NULL, " "));
        //printf("%d\n", data[i]);
    }
    
    /* 中央値の配列を作る */
    for (int i = N - 1; i >= 0; i--) {
        for (int j = 0; j <= i; j++) {
            calcMedian(j, i);
            //printf("%d,%d\n", j, i);
        }
    }
    
    /* 結果を出力 */
    printf("%d\n", medians[(N / 2) + 1]);
    
    return 0;
}


Compiler output:
main.c: In function 'getInput':
main.c:33:5: error: implicit declaration of function 'gets'; did you mean 'fgets'? [-Wimplicit-function-declaration]
   33 |     gets(pstr);
      |     ^~~~
      |     fgets
Language: C++

#include <iostream>
#include <vector>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

struct BIT{
    ll N;
    vector<ll> bit;
    BIT(ll N) : bit(N+1),N(N){};

    ll sum(ll i){
        ll s = 0;
        while(i>0){
           s += bit[i];
           i -= i& -i;
        }
        return s;
    }

    void add(ll i,ll x){
        while(i <= N){
            bit[i] += x;
            i += i & -i;
        }
    }
};

//数列の値の範囲を[1,n]に変える
vector<ll> convert_array(vector<ll> z){
    ll n = z.size();
    vector<ll> temp = z;
    sort(all(temp));
    for(int i = 0; i < n; i++){
        z[i] = lower_bound(all(temp), z[i]) - temp.begin() + 1;
    }
    return z;
}

//反転数を求める
ll inverse_number(vector<ll> z){
    ll n = z.size();
    ll inv_num = 0;
    z = convert_array(z);

    BIT b(n);
    for(int i = 0; i <= n; i++){
        b.bit[i] = 0;
    }

    for(int i = 0; i < n; i++){
        inv_num += i - b.sum(z[i]);
        b.add(z[i],1);
    }

    return inv_num;
}

//数列の変形をしてxが中央値の候補かどうか調べる
bool check(ll x,vector<ll> z){
    ll n = z.size();
    vector<ll> b(n);
    for(int i = 0; i < n; i++){
        if(z[i] >= x) b[i] = 1;
        else b[i] = -1;
    }
    vector<ll> s(n+1,0);  //ここ長さn+1になることに注意
    for(int i = 1; i <= n; i++){
        s[i] = s[i-1] + b[i-1];
    }

    return (n*(n+1)/2 - inverse_number(s)) >= (n*(n+1)/2+1)/2;
}

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

    ll low = *min_element(all(a))-1, high = *max_element(all(a))+1;

    while(high - low > 1){
        ll mid = (low+high)/2;
        if(check(mid,a)) low = mid;
        else high = mid;
    }

    cout << low << endl;

    return 0;
}

Compiler output:
a.cc: In function 'std::vector<long long int> convert_array(std::vector<long long int>)':
a.cc:36:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   36 |     sort(all(temp));
      |     ^~~~
      |     short
a.cc: In function 'int main()':
a.cc:87:15: error: 'min_element' was not declared in this scope
   87 |     ll low = *min_element(all(a))-1, high = *max_element(all(a))+1;
      |               ^~~~~~~~~~~
a.cc:89:11: error: 'high' was not declared in this scope
   89 |     while(high - low > 1){
      |           ^~~~
Language: C++

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

class BIT {
private:
  int N; // Number of nodes
  vector<int> tree; // array which represents the tree

public:
  BIT(int n) {
    N = n;
    tree = vector<int>(N+1,0);
  }

  void add(int a, int v) {
    for (int i=a; i<=N; i += i & -i) tree[i] += v;
  }

  int sum(int a) {
    int ret = 0;
    for (int i=a; i>0; i -= i & -i) ret += tree[i];
    return ret;
  }
};

void convert(int arr[], int n) {
  int temp[n];
  for (int i=0; i<n; ++i) {
    temp[i] = arr[i];
  }
  sort(temp,temp+n);

  for (int i=0; i<n; ++i) {
    arr[i] = lower_bound(temp, temp+n, arr[i]) - temp + 1; //arr[i]をソート値のインデックス(ただし1開始)に置き換え
  }
}

// aの転倒数を計算
int invCount(int a[], int n) {
  int temp[n];
  for (int i=0; i<n; ++i) temp[i] = a[i];
  convert(temp, n);

  BIT bit = BIT(n);
  int count = 0;
  for (int i=n-1; i>=0; --i) { //右側から走査
    count += bit.sum(temp[i]-1); //現在値よりも小さい値で，右側（走査済み）にあった値の個数を追加
    bit.add(temp[i],1); //現在値の観測数を追加
  }

  return count;
}

// xが求めるmedianの候補であるか判定
bool check(int x, int a[], int n) {
  int b[n];
  for (int i=0; i<n; ++i) {
    b[i] = (a[i] >= x) ? 1 : -1; //x以上の要素を1，他を-1に変換
  }

  //bの累積和を計算
  int S[n+1];
  S[0] = 0;
  for (int i=1; i<n+1; ++i) {
    S[i] = S[i-1] + b[i-1];
  }

  return (n*(n+1)/2 - invCount(S,n)) >= (n*(n+1)/2 + 1)/2; //左辺はSのS[r]-S[l]>0である(l,r)(l<r)の組み合わせ数
}

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

  int a[N];
  for (int i=0; i<N; ++i) cin >> a[i];

  int low,high;
  low = *min_element(a,a+N)-1;
  high = *max_element(a,a+N)+1; // 初期値は最小最大の外側に取る

  while(high - low > 1) {
    int mid = (low + high)/2;
    if (check(mid,a,N)) low = mid;
    else high = mid;
  }

  cout << low << endl;
  reutrn 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:91:3: error: 'reutrn' was not declared in this scope
   91 |   reutrn 0;
      |   ^~~~~~
Language: C++

//abc107 D問題のできるだけ公式の解説に従った回答

#include<iostream>
#include<stdio.h>
using namespace std;
const int MAX_N = 100100;
int n;
int a[MAX_N];

//配列の最大値を求める
int max_of_array(long *a){
  int m=0;
  for(int i=0;i<n;i++){
    if(a[i] > m) m = a[i];
  }
  return m;
}

//2つのパーツをマージしてソートし，その際計算したS_l <= S_rを満たすものの数を返す
long long merge(int *s, int left, int mid, int right){
  int ne = right - left + 1;
  int tmp[ne], i_tmp=0, i_left=left, i_right=mid+1;
  long long count = 0;
  for(; i_left <= mid && i_right <= right; i_tmp++){
    if(s[i_left] > s[i_right]){
      tmp[i_tmp] = s[i_left];
      i_left++;
    }else{
      tmp[i_tmp] = s[i_right];
      count+=mid-i_left+1; //countに左側のリストに残っている要素数を足していくとS_l <= S_rを満たすものの個数になる
      i_right++;
    }
  }
  for(; i_left <= mid; i_tmp++, i_left++) tmp[i_tmp] = s[i_left];
  for(; i_right <= right; i_tmp++, i_right++) tmp[i_tmp] = s[i_right];
  
  for(int i=left;i<=right;i++) s[i] = tmp[i-left];
  
  return count;
}

//(l,r)のうち，S_l <= S_r を満たすものの数を求める．再帰的に実装した．
long long calc_combination(int *s, int left, int right){
  if(left < right) {
    int mid = (right + left) / 2;
    return calc_combination(s, left, mid) 
      + calc_combination(s, mid+1, right)
      + merge(s,left,mid,right);
  }else{
    return 0;
  }
}

int sgn(int x, int y){
  return x < y ? -1 : 1;
}

bool check(long c){
  int s[n]; //累積和の配列
  long s1 = 0;
  s[0]=sgn(a[0],c);
  for(int i=1;i<n;i++){
    s[i] = s[i-1] + sgn(a[i],c);
    s1 += sgn(a[i],c) < 0 ? 0 : 1; //(#1)
    //(#1)公式解説pdfの方法だと，l=rの場合が考慮されていないので，ACにならない．m_l,rの要素数が１の時も考慮しなければならない．
  }
  long long cb = calc_combination(s,0,n-1) + s1;
  return cb >= n*((long long)n+1)/4;
}

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

  int l=0,r=max_of_array(a);
  while(l<r){ //2分法
    int med = (l+r+1)/2;
    if(check(med)) l = med;
    else r = med-1;
  }
  cout << l << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:75:26: error: cannot convert 'int*' to 'long int*'
   75 |   int l=0,r=max_of_array(a);
      |                          ^
      |                          |
      |                          int*
a.cc:11:24: note:   initializing argument 1 of 'int max_of_array(long int*)'
   11 | int max_of_array(long *a){
      |                  ~~~~~~^
Language: C++

#include<iostream>
#include<cstdio>
#define mid ((l+r)>>1)
#define read(n) scanf("%d",&n)
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 5;
int a[MAXN] ,  binary[MAXN];
ll pre[MAXN];
int b[MAXN];
ll ans;
int n;
void merge(ll *p,int l,int r)
{
	if(l == r)	return ;
	merge(p,l,mid);
	merge(p,mid+1,r);
	int tot = l;
	int pos1 = l , pos2 = mid + 1;
	while(pos1 <= mid && pos2 <= r)
	{
		if(p[pos1] > p[pos2])
		{
			b[tot++] = p[pos2++];
			ans += mid - pos1 + 1;
		}	
		else
			b[tot++] = p[pos1++];
	}
	while(pos1 <= mid)	b[tot++] = p[pos1++];
	while(pos2 <= r)	b[tot++] = p[pos2++];
	for(int i = l ; i <= r ; i++)
		p[i] = b[i];
}
bool check(int x)
{
	ans = 0;
	pre[0] = 0;
	for(int i = 1 ; i <= n ; i++)
		pre[i] = pre[i-1] + (x >= a[i] ? -1 : 1) , ans += pre[i] < 0 ? 1 : 0;
	merge(pre,1,n);
	return ans <= (long long)(n * (n + 1) / 4);
}
int main()
{
	read(n);
	for(int i = 1 ; i <= n ; i++)
		read(a[i]) , binary[i] = a[i];
	merge(binary,1,n);
	ans = 0;
	int l = 1 , r = n;
	while(l + 1 < r)
	{
		if(check(binary[mid]))
			l = mid;
		else
			r = mid;
	}
	printf("%d\n",binary[r]); 
}

Compiler output:
a.cc: In function 'int main()':
a.cc:49:15: error: cannot convert 'int*' to 'll*' {aka 'long long int*'}
   49 |         merge(binary,1,n);
      |               ^~~~~~
      |               |
      |               int*
a.cc:13:16: note:   initializing argument 1 of 'void merge(ll*, int, int)'
   13 | void merge(ll *p,int l,int r)
      |            ~~~~^
Language: C++

#include<iostream>
#include<cstdio>
#define mid ((l+r)>>1)
#define read(n) scanf("%d",&n)
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 5;
int a[MAXN] ,  binary[MAXN];
ll pre[MAXN];
int b[MAXN];
ll ans;
int n;
void merge(int *p,int l,int r)
{
	if(l == r)	return ;
	merge(p,l,mid);
	merge(p,mid+1,r);
	int tot = l;
	int pos1 = l , pos2 = mid + 1;
	while(pos1 <= mid && pos2 <= r)
	{
		if(p[pos1] > p[pos2])
		{
			b[tot++] = p[pos2++];
			ans += mid - pos1 + 1;
		}	
		else
			b[tot++] = p[pos1++];
	}
	while(pos1 <= mid)	b[tot++] = p[pos1++];
	while(pos2 <= r)	b[tot++] = p[pos2++];
	for(int i = l ; i <= r ; i++)
		p[i] = b[i];
}
bool check(int x)
{
	ans = 0;
	pre[0] = 0;
	for(int i = 1 ; i <= n ; i++)
		pre[i] = pre[i-1] + (x >= a[i] ? -1 : 1) , ans += pre[i] < 0 ? 1 : 0;
	merge(pre,1,n);
	return ans <= (long long)(n * (n + 1) / 4);
}
int main()
{
	read(n);
	for(int i = 1 ; i <= n ; i++)
		read(a[i]) , binary[i] = a[i];
	merge(binary,1,n);
	ans = 0;
	int l = 1 , r = n;
	while(l + 1 < r)
	{
		if(check(binary[mid]))
			l = mid;
		else
			r = mid;
	}
	printf("%d\n",binary[r]); 
}

Compiler output:
a.cc: In function 'bool check(int)':
a.cc:41:15: error: cannot convert 'll*' {aka 'long long int*'} to 'int*'
   41 |         merge(pre,1,n);
      |               ^~~
      |               |
      |               ll* {aka long long int*}
a.cc:13:17: note:   initializing argument 1 of 'void merge(int*, int, int)'
   13 | void merge(int *p,int l,int r)
      |            ~~~~~^
Language: C

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
#define debug(x) cout<<#x<<" = "<<x<<endl;
const int MAXN = 5e5 + 5;
long long ans;
int n;
inline int read()
{
    int sign = 1;
    int x = 0;register char ch;
    while(ch < '0' || ch > '9')
    {
        if(ch == '-')   sign = -1;
        ch=getchar();
    }
    while(ch >= '0' && ch <= '9')   x = x * 10 + ch - '0' , ch = getchar();
    return x * sign;
}
#define lowbit(i) i&-i
long long c[MAXN];
int pre[MAXN];
int a[MAXN];
namespace lsh{
    vector <int> v;
    inline int getid(int x)
    {
        return lower_bound(v.begin(),v.end(),x) - v.begin() + 1;
    }
    inline void init()
    {
        for(int i = 1 ; i <= n ; i++)
            v.push_back(pre[i]);
        sort(v.begin(),v.end());
        v.erase(unique(v.begin(),v.end()),v.end());
    }
}
inline void add(int x)
{
    for(int i = x ; i <= n ; i+=lowbit(i))
        c[i] += 1;
}
inline long long getsum(int x)
{
    long long res = 0;
    for(int i = x ; i >= 1 ; i-=lowbit(i))
        res += c[i];
    return res;
}
inline void get()
{
    // lsh::v.clear();
    // debug(lsh::v.size());
	lsh::init();
    for(int i = 1 ; i <= n ; i++)
    {
        add(lsh::getid(pre[i]));
        ans += getsum(lsh::v.size()) - getsum(lsh::getid(pre[i]));
    }
    // debug(ans);
}
#define mid ((l+r)>>1)
#define m (n*(n+1)/2)
int binary[MAXN];
#include<cstring>
inline long long cnt(int x)
{
	ans = 0;
	pre[0] = 0;
	for(int i = 1 ; i <= n ; i++)
		pre[i] = pre[i-1] + (x >= a[i] ? -1 : 1);
	memset(c,0,sizeof(c));
	lsh::v.clear();
	get();
// 	debug(lsh::v.size());
	return ans;
}
int main()
{
    n = read();
    for(int i = 1 ; i <= n ; i++)
        binary[i] = a[i] = read();
    sort(binary + 1 , binary + n + 1);
    int l = 1 , r = n;
	while(l < r)
	{
		int x = cnt(binary[mid]);
		if(x > m / 2 + 1)
			r = mid;
		else
			l = mid+1;
	}
	printf("%d\n",binary[l]);
}

Compiler output:
main.c:1:9: fatal error: iostream: No such file or directory
    1 | #include<iostream>
      |         ^~~~~~~~~~
compilation terminated.
Language: C++

#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
int A[999999], W[999999];
long long merge_and_count(int l, int r) { // range [l,r)
	if (l+1 >= r) return 0; // empty
	if (l+2 == r) { // [l,r) == [l,l+1] 要素2つだけ
		if (A[l] <= A[l+1]) return 0; // 逆転はなし
		std::swap(A[l], A[l+1]);
		return 1; // 逆転一つ
	}
	int m = (l+r)/2; // [l,r) == [l,m) + [m,r)
	long long cl = merge_and_count(l, m); // 左半分を再帰的に数える
	long long cr = merge_and_count(m, r); // 右半分を再帰的に数える
	long long c = 0; // 左と右を混ぜるときの逆転数
	int i=l, j=m; // iは[l,m)を動き, jは[m,r)を動いて、
	int k=l; // 小さいものから W[k] に書き込む
	while (i<m && j<r) { // A[i]とA[j]を比べながら進む
		if (A[i] <= A[j]) W[k++] = A[i++]; // 左半分の方が小さく逆転なし
		else {
			W[k++] = A[j++];
			c += m-i; // 左半分の方が大きい、左半分で未処理の要素だけ飛び越える
		}
	}
	while (i<m) W[k++] = A[i++]; // 左半分が余った場合
	while (j<r) W[k++] = A[j++]; // 右半分が余った場合
	//assert(k == r);
	std::copy(W+l, W+r, A+l);
	return cl + cr + c;
}

// cpp_binarysearch (C) @cielavenir under Boost Software License.
// returns the smallest value satisfying the predicate.

#include <functional>
template<typename T,typename F=std::function<bool(T)>>
T binarysearch(T lo,T hi,const T eps,const F &predicate){
	T r=hi+eps;
	for(;lo<hi+eps;){
		T mi=eps!=1||(lo<0)==(hi<0) ? lo+(hi-lo)/2 : (lo<-hi) ? -((-lo-hi-1)/2+1) : (lo+hi)/2;
		if(predicate(mi)){
			r=mi;
			hi=mi-eps;
		}else{
			lo=mi+eps;
		}
	}
	return r;
}

int main(){
	int T,i,N;
	scanf("%d",&N);std::vector<int>v(N);for(T=i=0;i<N;i++){scanf("%d",&v[i]);if(v[i]>T)T=v[i];}
	printf("%d\n",binarysearch(0,T,1,[&](int m){
		A[0]=0;
		for(i=1;i<=N;i++)A[i]=A[i-1]+(v[i-1]>m?1:-1);
		return merge_and_count(0,N+1)>=((long long)(N+1)*N/4+1;
	}));
}

Compiler output:
a.cc: In lambda function:
a.cc:58:71: error: expected ')' before ';' token
   58 |                 return merge_and_count(0,N+1)>=((long long)(N+1)*N/4+1;
      |                                                ~                      ^
      |                                                                       )
Language: C++

#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
int A[999999], W[999999];
long long merge_and_count(int l, int r) { // range [l,r)
	if (l+1 >= r) return 0; // empty
	if (l+2 == r) { // [l,r) == [l,l+1] 要素2つだけ
		if (A[l] <= A[l+1]) return 0; // 逆転はなし
		std::swap(A[l], A[l+1]);
		return 1; // 逆転一つ
	}
	int m = (l+r)/2; // [l,r) == [l,m) + [m,r)
	long long cl = merge_and_count(l, m); // 左半分を再帰的に数える
	long long cr = merge_and_count(m, r); // 右半分を再帰的に数える
	long long c = 0; // 左と右を混ぜるときの逆転数
	int i=l, j=m; // iは[l,m)を動き, jは[m,r)を動いて、
	int k=l; // 小さいものから W[k] に書き込む
	while (i<m && j<r) { // A[i]とA[j]を比べながら進む
		if (A[i] <= A[j]) W[k++] = A[i++]; // 左半分の方が小さく逆転なし
		else {
			W[k++] = A[j++];
			c += m-i; // 左半分の方が大きい、左半分で未処理の要素だけ飛び越える
		}
	}
	while (i<m) W[k++] = A[i++]; // 左半分が余った場合
	while (j<r) W[k++] = A[j++]; // 右半分が余った場合
	//assert(k == r);
	std::copy(W+l, W+r, A+l);
	return cl + cr + c;
}

// cpp_binarysearch (C) @cielavenir under Boost Software License.
// returns the smallest value satisfying the predicate.

#include <functional>
template<typename T,typename F=std::function<bool(T)>>
T binarysearch(T lo,T hi,const T eps,const F &predicate){
	T r=hi+eps;
	for(;lo<hi+eps;){
		T mi=eps!=1||(lo<0)==(hi<0) ? lo+(hi-lo)/2 : (lo<-hi) ? -((-lo-hi-1)/2+1) : (lo+hi)/2;
		if(predicate(mi)){
			r=mi;
			hi=mi-eps;
		}else{
			lo=mi+eps;
		}
	}
	return r;
}

int main(){
	int T,i,N;
	scanf("%d",&N);std::vector<int>v(N);for(T=i=0;i<N;i++){scanf("%d",&v[i]);if(v[i]>T)T=v[i];}
	printf("%d\n",-1+binarysearch(0,T,1,[&](int m){
		A[0]=0;//v[0]>=m?1:-1;
		for(i=1;i<=N;i++)A[i]=A[i-1]+(v[i-1]>=m?1:-1);
		return merge_and_count(0,N+1)>=((long long)(N+1)*N/4+1;
	}));
}

Compiler output:
a.cc: In lambda function:
a.cc:58:71: error: expected ')' before ';' token
   58 |                 return merge_and_count(0,N+1)>=((long long)(N+1)*N/4+1;
      |                                                ~                      ^
      |                                                                       )
Language: C

#include<iostream>
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<queue>
#include<string>
#include<cstring>


using namespace std;
typedef long long LL;
LL n,l,Min=1e9+7,Max=-1;
LL tot=0;
LL  a[1000005];
LL bit[1000005];

struct node {
LL val,pos;
}arr[1000005];

bool cmp(node n1,node n2)
{
    return n1.val<n2.val;
}

void update(LL x,LL val)
{
    x++;
    for(; x< 1000005 ;x+=(x & -x))
    {
        bit[x]+=val;
    }
}

LL getsum(LL x)
{
    LL ans=0;
    x++;
    for(;x>0;x-=(x & -x))
    {
        ans += bit[x];
    }
    return ans;
}



bool check(LL x){
    memset(bit,0,sizeof(bit));

	LL ans=0;
	for(int i=1;i<=n;i++)
    {
        if(a[i]<=x)arr[i].val=-1;
        else arr[i].val=1;
        arr[i].pos=i;
    }
    arr[0].val=0;
	arr[0].pos=0;


	for(int i=1;i<=n;i++)
	arr[i].val+=arr[i-1].val;
	sort(arr,arr+n+1,cmp);
	for(int i=0;i<=n;i++)
    {
        ans+=(i-getsum(arr[i].pos));
        update(arr[i].pos,1);
    }

//    for(int i=0;i<=n;i++)
//	for(int j=i+1;j<=n;j++)
//    {
//
//        if(arr[j].val-arr[i].val<0)
//        {
//            cout<<"INV::"<<arr[j].val<<"   "<<arr[i].val<<endl;
//             ans++;
//        }
//    }

	//printf("ans::%lld --- x ::%lld\n",ans,x);

	return ans>tot/2;
}


int main(){
   scanf("%lld",&n);
   for(int i=1;i<=n;i++){
   	 scanf("%lld",&a[i]);
   	 Min=min(Min,a[i]);
   	 Max=max(Max,a[i]);
   	 tot+=i;
   }
   LL l=Min,r=Max;
   while(r-l>1){
   	  LL mid=(l+r)/2;
   	 if(check(mid)) r=mid;
   	 else l=mid;
   	 //printf("s%d",mid);
   }
   printf("%lld\n",r);
   return 0;
}


Compiler output:
main.c:1:9: fatal error: iostream: No such file or directory
    1 | #include<iostream>
      |         ^~~~~~~~~~
compilation terminated.
Language: C

//#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<queue>
#include<string>
#include<string.h>


using namespace std;
typedef long long LL;
LL n,l,Min=1e9+7,Max=-1;
LL tot=0;
LL  a[100005];
LL bit[100005];

struct node {
LL val,pos;
}arr[100005];

bool cmp(node n1,node n2)
{
    return n1.val<n2.val;
}

void update(LL x,LL val)
{
    x++;
    for(; x< 100005 ;x+=(x & -x))
    {
        bit[x]+=val;
    }
}

LL getsum(LL x)
{
    LL ans=0;
    x++;
    for(;x>0;x-=(x & -x))
    {
        ans += bit[x];
    }
    return ans;
}



bool check(LL x){
    memset(bit,0,sizeof(bit));

	LL ans=0;
	for(int i=1;i<=n;i++)
    {
        if(a[i]<=x)arr[i].val=-1;
        else arr[i].val=1;
        arr[i].pos=i;
    }
    arr[0].val=0;
	arr[0].pos=0;


	for(int i=1;i<=n;i++)
	arr[i].val+=arr[i-1].val;
	sort(arr,arr+n+1,cmp);
	for(int i=0;i<=n;i++)
    {
        ans+=(i-getsum(arr[i].pos));
        update(arr[i].pos,1);
    }

//    for(int i=0;i<=n;i++)
//	for(int j=i+1;j<=n;j++)
//    {
//
//        if(arr[j].val-arr[i].val<0)
//        {
//            cout<<"INV::"<<arr[j].val<<"   "<<arr[i].val<<endl;
//             ans++;
//        }
//    }

	//printf("ans::%lld --- x ::%lld\n",ans,x);

	return ans>=tot/2+1;
}


int main(){
   scanf("%lld",&n);
   for(int i=1;i<=n;i++){
   	 scanf("%lld",&a[i]);
   	 Min=min(Min,a[i]);
   	 Max=max(Max,a[i]);
   	 tot+=i;
   }
   LL l=Min,r=Max;
   while(r-l>1){
   	  LL mid=(l+r)/2;
   	 if(check(mid)) r=mid;
   	 else l=mid;
   	 //printf("s%d",mid);
   }
   printf("%lld\n",r);
   return 0;
}


Compiler output:
main.c:4:9: fatal error: algorithm: No such file or directory
    4 | #include<algorithm>
      |         ^~~~~~~~~~~
compilation terminated.
Language: C

//#include<iostream>
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<queue>
#include<string>
#include<cstring>


using namespace std;
typedef long long LL;
LL n,l,Min=1e9+7,Max=-1;
LL tot=0;
LL  a[100005];
LL bit[100005];

struct node {
LL val,pos;
}arr[100005];

bool cmp(node n1,node n2)
{
    return n1.val<n2.val;
}

void update(LL x,LL val)
{
    x++;
    for(; x< 100005 ;x+=(x & -x))
    {
        bit[x]+=val;
    }
}

LL getsum(LL x)
{
    LL ans=0;
    x++;
    for(;x>0;x-=(x & -x))
    {
        ans += bit[x];
    }
    return ans;
}



bool check(LL x){
    memset(bit,0,sizeof(bit));

	LL ans=0;
	for(int i=1;i<=n;i++)
    {
        if(a[i]<=x)arr[i].val=-1;
        else arr[i].val=1;
        arr[i].pos=i;
    }
    arr[0].val=0;
	arr[0].pos=0;


	for(int i=1;i<=n;i++)
	arr[i].val+=arr[i-1].val;
	sort(arr,arr+n+1,cmp);
	for(int i=0;i<=n;i++)
    {
        ans+=(i-getsum(arr[i].pos));
        update(arr[i].pos,1);
    }

//    for(int i=0;i<=n;i++)
//	for(int j=i+1;j<=n;j++)
//    {
//
//        if(arr[j].val-arr[i].val<0)
//        {
//            cout<<"INV::"<<arr[j].val<<"   "<<arr[i].val<<endl;
//             ans++;
//        }
//    }

	//printf("ans::%lld --- x ::%lld\n",ans,x);

	return ans>=tot/2+1;
}


int main(){
   scanf("%lld",&n);
   for(int i=1;i<=n;i++){
   	 scanf("%lld",&a[i]);
   	 Min=min(Min,a[i]);
   	 Max=max(Max,a[i]);
   	 tot+=i;
   }
   LL l=Min,r=Max;
   while(r-l>1){
   	  LL mid=(l+r)/2;
   	 if(check(mid)) r=mid;
   	 else l=mid;
   	 //printf("s%d",mid);
   }
   printf("%lld\n",r);
   return 0;
}


Compiler output:
main.c:2:9: fatal error: cstdio: No such file or directory
    2 | #include<cstdio>
      |         ^~~~~~~~
compilation terminated.
Language: C

#include<iostream>
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<queue>
#include<string>
#include<cstring>


using namespace std;
typedef long long LL;
LL n,l,Min=1e9+7,Max=-1;
LL tot=0;
LL  a[100005];
LL bit[100005];

struct node {
LL val,pos;
}arr[100005];

bool cmp(node n1,node n2)
{
    return n1.val<n2.val;
}

void update(LL x,LL val)
{
    x++;
    for(; x< 100005 ;x+=(x & -x))
    {
        bit[x]+=val;
    }
}

LL getsum(LL x)
{
    LL ans=0;
    x++;
    for(;x>0;x-=(x & -x))
    {
        ans += bit[x];
    }
    return ans;
}



bool check(LL x){
    memset(bit,0,sizeof(bit));

	LL ans=0;
	for(int i=1;i<=n;i++)
    {
        if(a[i]<=x)arr[i].val=-1;
        else arr[i].val=1;
        arr[i].pos=i;
    }
    arr[0].val=0;
	arr[0].pos=0;


	for(int i=1;i<=n;i++)
	arr[i].val+=arr[i-1].val;
	sort(arr,arr+n+1,cmp);
	for(int i=0;i<=n;i++)
    {
        ans+=(i-getsum(arr[i].pos));
        update(arr[i].pos,1);
    }

//    for(int i=0;i<=n;i++)
//	for(int j=i+1;j<=n;j++)
//    {
//
//        if(arr[j].val-arr[i].val<0)
//        {
//            cout<<"INV::"<<arr[j].val<<"   "<<arr[i].val<<endl;
//             ans++;
//        }
//    }

	//printf("ans::%lld --- x ::%lld\n",ans,x);

	return ans>=tot/2+1;
}


int main(){
   scanf("%lld",&n);
   for(int i=1;i<=n;i++){
   	 scanf("%lld",&a[i]);
   	 Min=min(Min,a[i]);
   	 Max=max(Max,a[i]);
   	 tot+=i;
   }
   LL l=Min,r=Max;
   while(r-l>1){
   	  LL mid=(l+r)/2;
   	 if(check(mid)) r=mid;
   	 else l=mid;
   	 //printf("s%d",mid);
   }
   printf("%lld\n",r);
   return 0;
}


Compiler output:
main.c:1:9: fatal error: iostream: No such file or directory
    1 | #include<iostream>
      |         ^~~~~~~~~~
compilation terminated.
Language: C++

#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

struct segtree {
    long long int N;
    vector<long long int> v;

    segtree(long long int n) {
        N = 1;
        while(N < n) N *= 2;
        v = vector<long long int>(2 * N, 0);
    }
    // update k th element
    void update(long long int k, long long int a) {
        k += N-1; // leaf
        v[k] = a;
        while(k > 0) {
            k = (k - 1) / 2;
            v[k] = v[k*2+1] + v[k*2+2];
        }
    }
    // sum [a, b)
    long long int query(long long int a, long long int b) { return query(a, b, 0, 0, N); }
    long long int query(long long int a, long long int b, long long int k, long long int l, long long int r) {
        if(r <= a or b <= l) return 0;
        if(a <= l and r <= b) return v[k];
        long long int m = (l + r) / 2;
        return query(a, b, k*2+1, l, m) + query(a, b, k*2+2, m, r);
    }
};

long long int main()
{
	long long int n;
	cin >> n;
	long long int a[100001];
	for(long long int i = 0; i < n; i++){
		cin >> a[i];
	}
	if(n == 1){
		cout << a[0] << endl;
		return 0;
	}

	long long int l = 0, r = mod;
	while(r - l > 1){
		long long int mid = (l + r) / 2;
		// ある区間において中央値はmid以上になるか？
		// <-> ある区間において、mid以上の値の個数はmid未満の値の個数より大きいか？
		// cnt[i] = a[0]からa[i - 1]までの(mid以上の個数 - mid未満の個数)とすると、
		// 区間[l, r)において(mid以上の個数 - mid未満の個数)はcnt[r] - cnt[l]となる
		// (mid以上の個数 > mid未満の個数)より cnt[r] - cnt[l] >= 0となればよい
		// つまりcnt[r] >= cnt[l]となるような[l, r)の個数を求め、これが(n * (n + 1) / 2) / 2より大きければ
		// 中央値の中央値はmid以上であるとわかる
		vector<pair<long long int, long long int> > cnt;
		cnt.push_back(make_pair(0, 0));
		long long int rangenum = 0;
		for(long long int i = 1; i <= n; i++){
			cnt.push_back(make_pair(cnt[i - 1].first + ((a[i - 1] >= mid) ? 1 : -1), i));
			if(a[i - 1] >= mid) rangenum++;
		}
		auto itr = cnt.begin();
		itr++;
		sort(itr, cnt.end());
		segtree st(n + 1);
		for(long long int i = 1; i < n + 1; i++){
			// cout << cnt[i].first << " " << cnt[i].second << endl;
			st.update(cnt[i].second, 1);
			rangenum += st.query(0, cnt[i].second);
		}
		// cout << mid << " " << rangenum << endl;
		if(rangenum >= (n * (n + 1) / 2) / 2) l = mid;
		else r = mid;
	}
	cout << l << endl;
}

Compiler output:
a.cc:52:11: error: '::main' must return 'int'
   52 | long long int main()
      |           ^~~
Language: C++

#include<iostream>

#include<cstdio>

#include<math.h>

#include<algorithm>

#include<map>

#include<set>

#include<bitset>

#include<stack>

#include<queue>

#include<string.h>

#include<string>

#include<cstring>

#include<vector>

#include<time.h>

#include<stdlib.h>

using namespace std;
int n,l,Min=1000000005,Max=-1;
ll tot=0;
int sum[100005];
int  a[100005];
bool check(int x){
	int ans=0;
	for(int i=1;i<=n;i++)
	if(a[i]<x)sum[i]=-1;
	else if(a[i]>x)sum[i]=1;
	else sum[i]=0;
	for(int i=2;i<=n;i++)
	sum[i]+=sum[i-1];
	sum[0]=0;
	for(int i=0;i<n;i++)
	for(int j=i+1;j<=n;j++)
	if(sum[j]-sum[i]>=0)ans++;
	return ans>tot/2+1;
}
int main(){
   scanf("%d",&n);
   for(int i=1;i<=n;i++){
   	 scanf("%d",a[i]);
   	 Min=min(Min,a[i]);
   	 Max=max(Max,a[i]);
   	 tot+=i;
   } 
   int l=Min-5,r=Max;
   while(r-l>0){
   	  mid=(l+r)/2;
   	 if(check(mid)) r=mid;
   	 else l=mid;
   }
   return 0;
}


Compiler output:
a.cc:33:1: error: 'll' does not name a type
   33 | ll tot=0;
      | ^~
a.cc: In function 'bool check(int)':
a.cc:48:20: error: 'tot' was not declared in this scope
   48 |         return ans>tot/2+1;
      |                    ^~~
a.cc: In function 'int main()':
a.cc:56:10: error: 'tot' was not declared in this scope
   56 |          tot+=i;
      |          ^~~
a.cc:60:11: error: 'mid' was not declared in this scope
   60 |           mid=(l+r)/2;
      |           ^~~
Language: C++

def median(b):
  b.sort()
  return b[int(len(b)/2)]

n = int(input())
a = list(map(int, input().split()))

m = []
for l in range(n):
  for r in range(n):
    if l <= r:
      m.append(median(a[l:r+1]))

print(median(m))

Compiler output:
a.cc:1:1: error: 'def' does not name a type
    1 | def median(b):
      | ^~~
Language: C++

#include<bits/stdc++.h>

using namespace std;

int main() {
    long long int n;
    cin>>n;
    long long int arr[100006];
    for(int i=1;i<=n;i++) {
        cin>>arr[i];
    }

    sort(arr,arr+n);
    int med = n/2 + 1;
	if(n == 1) cout<<arr[1];
  	else {
      if((((n*(n+1)/2) - n) % 2 == 1 ) cout<<arr[med+1];
      else cout<<arr[med];
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:39: error: expected ';' before 'cout'
   17 |       if((((n*(n+1)/2) - n) % 2 == 1 ) cout<<arr[med+1];
      |                                       ^~~~~
      |                                       ;
a.cc:18:7: error: expected primary-expression before 'else'
   18 |       else cout<<arr[med];
      |       ^~~~
a.cc:17:57: error: expected ')' before 'else'
   17 |       if((((n*(n+1)/2) - n) % 2 == 1 ) cout<<arr[med+1];
      |         ~                                               ^
      |                                                         )
   18 |       else cout<<arr[med];
      |       ~~~~
Language: C++

#include<bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin>>n;
    int arr[100006];
    vector<int> vec;
    for(int i=1;i<=n;i++) {
        cin>>arr[i];
        //vec.push_back(arr[i]);
    }

    sort(arr,arr+n);
    int med = n/2 + 1;
    int str_1 = arr[med];
    for(int i = med;i<=n;i++) {
        if(arr[i] != arr[med]) {
            str_1 = arr[i];
            break;
        }
    }

    if(n%2 == 1 || (n*(n+1)/2) % 2 == 1) {
        cout<<str_1;
    } else {
        cout<<arr[med];
    }

    cout<<st_1;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:31:11: error: 'st_1' was not declared in this scope; did you mean 'str_1'?
   31 |     cout<<st_1;
      |           ^~~~
      |           str_1
Language: C++

#include<bits/stdc++.h>
 
using namespace std;
 
int main() {
    int n;
    cin>>n;
    int arr[100006];
    for(int i=1;i<=n;i++) {
        cin>>arr[i];
    }
 
    sort(arr+1,arr+n+1);
    int med = n/2 + 1;
    int str_1 = arr[med];
    
  	if(n%2 == 1) {
      if(med!=n) {
          cout<<arr[med+1];
      } else {
        cout<<arr[med];
      }
    } else {
      cout<<arr[med];
    return 0;
}

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

#include<bits/stdc++.h>
 
using namespace std;
 
int main() {
    int n;
    cin>>n;
    int arr[100006];
    vector<int> vec;
    for(int i=1;i<=n;i++) {
        cin>>arr[i];
        //vec.push_back(arr[i]);
    }
 
    sort(arr+1,arr+n+1);
    int med = n/2 + 1;
    int str_1 = arr[med];
    
	if(med!=n) {
    	cout<<arr[med+1];
    } else {
      cout<<arr[med];
    return 0;
}

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

#include <iostream>
#include <cstdint>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
  int n;
  int a;
  int med;
  vector<int> v;

  cin >> n;
  for (int i = 0; i < n; i++)
  {
    //cin >> a[i];
    cin >> a;
    v.push_back(a);
  }
	sort(v.begin(),v.end());

  if(1 == v.size()){
    med=v[0];
  }else{
    med=v[v.size()/2+1];
  }
  cout << med;
  return 0;
}

Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:12:3: error: 'vector' was not declared in this scope
   12 |   vector<int> v;
      |   ^~~~~~
a.cc:4:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    3 | #include <algorithm>
  +++ |+#include <vector>
    4 | 
a.cc:12:10: error: expected primary-expression before 'int'
   12 |   vector<int> v;
      |          ^~~
a.cc:19:5: error: 'v' was not declared in this scope
   19 |     v.push_back(a);
      |     ^
a.cc:21:14: error: 'v' was not declared in this scope
   21 |         sort(v.begin(),v.end());
      |              ^
Language: C++

#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 998244353
#define bitcnt(a) (ll) __builtin_popcount((a))
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<string, string> PS;

template <class T>
struct BIT {
  vector<T> x;
  BIT(int n) : x(n, 0) {
    // initialize
  }

  T sum(int i, int j) {
    if (i == 0) {
      T S = 0;
      for (j; j >= 0; j = (j & (j + 1)) - 1)
        S += x[j];
      return S;
    } else
      return sum(0, j) - sum(0, i - 1);
  }
  void add(int k, T a) {
    for (; k < x.size(); k |= k + 1)
      x[k] += a;
  }
};

int main() {
  ll n;
  cin >> n;
  vector<ll> v;
  REP(i, n) {
    ll h;
    cin >> h;
    v.pb(h);
  }
  vector<ll> s = v;

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

  ll ok = 0, ng = s.size();

  while (ng - ok > 1) {
    ll m = s[(ok + ng) / 2];
    vector<ll> imos;
    for (auto &a : v) {
      if (a < m) {
        imos.pb(-1);
      } else {
        imos.pb(1);
      }
    }

    REP(i, imos.size() - 1) {
      imos[i + 1] += imos[i];
    }
    BIT<ll> b(2 * n + 1);

    ll cnt = 0;
    REP(i, n) {
      cnt += (i - b.sum(0, imos[i] + n)) + (v[i] < m);
      b.add(imos[i] + n, 1);
    }
    if (cnt <= (n + (n * (n - 1)) / 2) / 2) {
      //cout << cnt << " " << m << endl;
      ok = (ok + ng) / 2;
    } else {
      //cout << cnt << " " << m << endl;
      ng = (ok + ng) / 2;
    }
  }
  cout << s[ok] << endl;


Compiler output:
a.cc: In function 'int main()':
a.cc:80:25: error: expected '}' at end of input
   80 |   cout << s[ok] << endl;
      |                         ^
a.cc:35:12: note: to match this '{'
   35 | int main() {
      |            ^