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