#include<bits/stdc++.h>usingnamespacestd;#define ll long long
intn;inta[100005],b[100005],t[100005],s[100005],tree[200005];intlowbit(intx){returnx&(-x);}voidadd(intx){while(x<=2*n+1){tree[x]++;x+=lowbit(x);}}llquery(intx){lls=0;while(x){s+=tree[x];x-=lowbit(x);}returns;}intread(){ints=0,f=1;charc=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}while(isdigit(c)){s=s*10+c-'0';c=getchar();}returns*f;}boolcheck(intx){llcnt=0;for(inti=1;i<=n;i++){t[i]=a[i]>=x?-1:1;s[i]=s[i-1]+t[i];}memset(tree,0,sizeoftree);add(n+1);for(inti=1;i<=n;i++){cnt+=query(s[i]+n);add(s[i]+n+1);}returncnt>=(ll)n*(n+1)/4+1;}intmain(){n=read();for(inti=1;i<=n;i++)a[i]=b[i]=read();sort(b+1,b+1+n);intL=0,R=n+1;while(L+1<R){intM=(L+R)>>1;if(check(b[M])){R=M;}else{L=M;}}cout<<b[L]<<endl;return0;}