Language: C++

    #include <bits/stdc++.h>
        using namespace std;
         
        using i64=int64_t;
         
        #define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
        #define debug(x) #x << "=" << (x)
         
        #ifdef DEBUG
        #define _GLIBCXX_DEBUG
        #define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
        #else
        #define print(x)
        #endif
         
        const int inf=1.01e9;
        const i64 inf64=4.01e18;
        const double eps=1e-9;
         
        template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
            os << "[";
            for (const auto &v : vec) {
                os << v << ",";
            }
            os << "]";
            return os;
        }
         
        template <class T, T op(T, T)>
        class segtree {
            public:
            int n, size_;
            vector<T> dat;
            T id_;
            segtree() = default;
            segtree(int size, T id, T initial_value) { init(size, id, initial_value); }
            void init(int size, T id, T initial_value) {
                size_ = size;
                id_ = id;
                n = 1;
                while (n < size) n *= 2;
                dat.assign(2 * n - 1, id);
                for (int i = 0; i < size; ++i) update(i, initial_value);
            }
            int size() const { return size_; }
            void update(int k, T a) {
                k += n - 1;  // leaf
                dat[k] = a;
                while (k > 0) {
                    k = (k - 1) / 2;
                    dat[k] = op(dat[k * 2 + 1], dat[k * 2 + 2]);
                }
            }
            T at(int index) { return dat[index + n - 1]; }
            void add(int k, T a) { update(k, at(k) + a); }
            T query(int a, int b) { return query(a, b, 0, 0, n); }
            T query(int a, int b, int k, int l, int r) {
                if (r <= a or b <= l) return id_;
                if (a <= l and r <= b) return dat[k];
                int m = (l + r) / 2;
                return op(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
            }
        };
         
        i64 sum(i64 a,i64 b){
            return a+b;
        }
         
        void solve(){
            i64 N;
            cin >> N;
         
            vector<i64> a(N);
            rep(i,0,N) cin >> a[i];
         
            if(N==1){
                cout << a[0] << endl;
                return;
            }
         
            auto count=[&](i64 x){
                // 中央値がx以下となる連続部分列の数
                segtree<i64,sum> seg(N+1,0,0);
                vector<pair<i64,i64>> ps;
                i64 s=0;
                rep(i,1,N+1){
                    if(a[i-1]<=x) ++s;
                    ps.push_back(make_pair(2*s-i,i));
                }
         
                sort(begin(ps),end(ps),[](const pair<i64,i64> &p,const pair<i64,i64> &q){
                        if(p.first==q.first) return p.second>q.second;
                        return p.first<q.first;
                    });
                i64 res=0;
                for(auto p:ps){
                    res+=seg.query(0,p.second);
                    seg.add(p.second,1);
                }
         
               return res;
            };
         
            i64 lb=-inf,ub=inf;
            while(ub-lb>1){
                i64 m=(lb+ub)/2;
                if(count(m)>=(N*(N+1)/2/2+1) ub=m;
                else lb=m;
            }
         
            cout << ub << endl;
        }
         
        int main(){
            std::cin.tie(0);
            std::ios::sync_with_stdio(false);
            cout.setf(ios::fixed);
            cout.precision(16);
            solve();
            return 0;
        }

Compiler output:
a.cc: In function 'void solve()':
a.cc:107:45: error: expected ';' before 'ub'
  107 |                 if(count(m)>=(N*(N+1)/2/2+1) ub=m;
      |                                             ^~~
      |                                             ;
a.cc:108:17: error: expected primary-expression before 'else'
  108 |                 else lb=m;
      |                 ^~~~
a.cc:107:51: error: expected ')' before 'else'
  107 |                 if(count(m)>=(N*(N+1)/2/2+1) ub=m;
      |                   ~                               ^
      |                                                   )
  108 |                 else lb=m;
      |                 ~~~~