#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

template<typename T>
struct BIT{
    vector<T> node;
    int n;
    int p;
    BIT(int n):n(n){ 
        node.resize(n + 1LL, 0);
        p=1;
        while(p<node.size()) p*=2;
    }
    T sum(int k) {
        T ret=0;
        for (;k>0;k-=(k & -k)) ret+=node[k];
        return ret;
    }	
    T sum(int a, int b){//[a,b)
        return sum(b)-sum(a);
    } 
    void add(int k, T x) {
        for(;k<=n;k+=(k & -k)) node[k]+=x;
    }
    int lower_bound(ll w) {
        if(w<=0)return 0;
        int x=0;
        for(int k=p/2;k>0;k/=2) {
            if(x+k<=n && node[x+k]<w){
                w-=node[x+k];
                x+=k;
            }
        }
        return x+1;
    }
};

//Compress<ll> comp(a);みたいな感じで
template <class T>
struct Compress{
    int N;
    map<T,int> idx;
    vector<T> cmp;
    Compress(vector<T> v){
        for(auto& x:v) cmp.push_back(x);
        sort(cmp.begin(),cmp.end());
        cmp.erase(unique(cmp.begin(),cmp.end()),cmp.end());
        N=cmp.size();
        for(int i=0;i<N;i++) idx[cmp[i]]=i;
    }
    int id(T val){return idx[val];}//前→後
    T val(int id){return cmp[id];}//後→前
};

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<ll> a(n);
    ll mi=inf;
    rep(i,n){
        cin>>a[i];
        chmin(mi,a[i]);
    }
    ll M=n*(n+1)/2;
    auto check=[&](ll x){
        vector<ll> b(a),sum(n+1,0);
        rep(i,n){
            if(a[i]>=x) b[i]=1;
            else b[i]=-1;
            sum[i+1]=sum[i]+b[i];
        }
        ll cnt=0;
        Compress comp(sum);
        rep(i,n+1) sum[i]=comp.id(sum[i])+1;
        BIT<ll> seg(n+1);
        seg.add(sum[0],1);
        FOR(r,1,n+1){
           cnt+=seg.sum(sum[r]);
           seg.add(sum[r],1);
        }
        return (M+1)/2<=cnt;
    };
    ll ok=mi,ng=INF+1;
    while(ng-ok>1){
        ll mid=(ok+ng)/2;
        if(check(mid)) ok=mid;
        else ng=mid;
    }
    cout<<ok<<endl;
}

Measured memory_bytes: 14244