#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
namespace mine
{
    const int MAXN=110000;
    int n;
    int tr[2*MAXN];
    int lowbit(int x) {return x&-x;}
    void change(int d)
    {
        d+=MAXN;
        while(d<2*MAXN) tr[d]++,d+=lowbit(d);
    }
    int sum(int d)
    {
        d+=MAXN;
        int ans=0;
        while(d>=1) ans+=tr[d],d-=lowbit(d);
        return ans;
    }
    int a[MAXN],b[MAXN];
    int c[MAXN];
    typedef long long ll;//debug 爆int 
    bool check(int now)
    {
        for(int i=1;i<=n;i++) c[i]=c[i-1]+(a[i]<=now?1:-1);//1小于等于,-1大于
        memset(tr,0,sizeof tr);//debug
        change(c[0]);//debug 
        ll tot=0;//<=now的数，产生的贡献 
        for(int r=1;r<=n;r++)
        {
            //c[r]-c[l-1]>0 => c[l-1]<c[r] (l-1<r)
            tot+=sum(c[r]-1);
            change(c[r]);
        }
        return tot>=ll(n+1)*n/4+1;
    }
    void main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++) scanf("%d",&a[i]);
        int l=1,r=1e9,ans=-1;
        while(l<=r)
        {
            int mid=(l+r)/2;
            if(check(mid)) ans=mid,r=mid-1;
            else l=mid+1;
        }
        printf("%d",ans);
    }
};
int main()
{
    mine::main();
}