#include<bits/stdc++.h>
#include<algorithm>
#include<stdio.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
ll n,num[maxn],t[maxn*2+5],p[maxn*2+5],l,r;
void add(ll x,ll v)
{
	for(ll i=x;i<=2*maxn;i+=i&-i)
    	t[i]+=v;
}
ll sum(ll x)
{
    ll ans=0;
    for(ll i=x;i>0;i-=i&-i)
    	ans+=t[i];
    return ans;
}
bool check(ll mid)
{	
	ll ans=0;
	memset(t,0,sizeof(t));
	p[0]=0;
	for(int i=1;i<=n;++i)
	p[i]=p[i-1]+(num[i]>=mid?1:-1);
	for(int i=0;i<=n;++i)
	{
		ans+=sum(p[i]+maxn);
		add(p[i]+maxn,1ll);
	}
	return ans>=n*(n+1)/4;
}
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%lld",&num[i]);
	    r=max(r,num[i]);
    }
    while(l<=r)
    {
    	int middle=(l+r)>>1; 
    	if(check(middle))l=middle+1;
		else r=middle-1; 
    }
    printf("%lld",r);
	return 0;
}