#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5;
ll n,a[N],val[N],prfx[N],bit[2*N+10];
void update(ll x){
    x+=n+2;
    for(;x<=2*n+10;x+=x&(-x))++bit[x];
}
ll query(ll x){
    x+=n+2;
    ll ans = 0;
    for(;x;x-=x&(-x))ans+=bit[x];
    return ans;
}
bool chk(ll val){
    for(ll i=0;i<=2*n+10;i++)bit[i]=0;
    for(ll i=1;i<=n;i++){
        if(a[i]<=val)prfx[i]=1;
        else prfx[i]=-1;
        prfx[i]+=prfx[i-1];
    }
    ll cur = 0 , req = (n*(n+1))/2;
    update(0);
    for(ll i=1;i<=n;i++)cur+=query(prfx[i]-1),update(prfx[i]);
    return cur>=req/2  + 1;
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n;
    for(ll i=1;i<=n;i++)cin>>a[i],val[i]=a[i];
    sort(val+1,val+n+1);
    ll k = unique(val+1,val+n+1)-val-1;
    ll l=1,r=k,ans=0;
    while(l<=r){
        ll mid=(l+r)>>1;
        if(chk(val[mid]))ans=val[mid],r=mid-1;
        else l=mid+1;
    }
    cout<<ans;
}