#include <stdio.h>
#include <string.h>
#define Maxn 100005
int n,ans,a[Maxn],rmq[Maxn*4],s[Maxn];
void add(int x) {for (;x<Maxn*4;x+=x&-x) rmq[x]++;}
int sum(int x) {int res=0;for (;x;x-=x&-x) res+=rmq[x];return res;}
int main()
{
	scanf("%d",&n);
	for (int i=0;i<n;++i) scanf("%d",a+i);
	for (int l=0,r=1e9;l<=r;)
	{
		memset(rmq,0,sizeof(rmq));
		int mid=l+r>>1;
		long long S=0;
		add(n+1);
		for (int i=0;i<n;++i)
		{
			s[i]=(i?s[i-1]:0)+(a[i]>=mid?1:-1);
			S+=sum(s[i]+n+1);
			add(s[i]+n+1);
		}
		if (S>=1LL*n*(n+1)/2-S) ans=mid,l=mid+1;
		else r=mid-1;
	}
	printf("%d\n",ans);
	return 0;
}