#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6+10;
typedef long long ll;
int lowbit(int i){return i&(-i);}
int n;
ll tree[MAXN];
void add(int i,ll v){
for(;i<MAXN;i+=lowbit(i))tree[i]+=v;
}
ll query(int i){ll re=0;for(;i;i-=lowbit(i))re+=tree[i];return re;}
ll a[MAXN],pre[MAXN];
ll b[MAXN];
const int HF=5e5;
bool solve(ll mid){
ll re=0;
memset(tree,0,sizeof(tree));
for(int i=1;i<=n;++i)pre[i]=pre[i-1]+(a[i]>=mid?1:-1);
add(HF,1);
for(int i=1;i<=n;++i){
re+=query(pre[i]+HF);
add(pre[i]+HF,1);
}
if(re*2>=1ll*n*(n+1)/2)return true;
return false;
}
ll x[MAXN];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%lld",&a[i]),x[i]=a[i];
sort(x+1,x+1+n,[](auto x,auto y){return x<y;});
int l=1,r=n;ll ans;
while(l<=r){
int mid=(l+r)>>1;
if(solve(x[mid]))ans=x[mid],l=mid+1;
else r=mid-1;
}
cout<<ans<<endl;
return 0;
}