#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
int input[200005];
int n;
int  l,r,ans,mid;
int  lib[200005];
int sum[200005];
int  tree[200005];
inline int lowbit(int x) {
	return x&(-x);
	}
int minn=234537373;
int maxx=0;
void add(int x) {
	for(int i=x; i<=maxx; i+=lowbit(i))tree[i]+=1;
	}
int summ(int x) {
	int kk=0;
	for(int i=x; i>=1; i-=lowbit(i))kk+=tree[i];
	return kk;
	}
bool check(int x) {
	memset(sum,0,sizeof(sum));
	memset(tree,0,sizeof(tree));
	int ans;
	minn=0;
	maxx=0;
	int num=input[x];
	for(int i=1; i<=n; i++)
		if(sum[i]>=x)sum[i]=1;
		else sum[i]=0;
	for(int i=1; i<=n; i++)
		sum[i]=sum[i-1]+input[i],minn=min(minn,sum[i]);
	for(int i=0; i<=n; i++)
		sum[i]=sum[i]-minn+1,maxx=max(maxx,sum[i]);
	for(int i=0; i<=n; i++) {
		ans+=summ(sum[i]);
		add(sum[i]);
		}
	return ans>=n*(n+1)/4;
	}
int main() {
	scanf("%d",&n);
	r=0;
	for(int i=1; i<=n; i++) {
		scanf("%d",&input[i]);
		r=max(r,input[i]);
		}
	l=1;
	while(l<=r) {
		mid=(l+r)>>1;
		if(check(mid)) {
			ans=mid;
			l=mid+1;
			}
		else r=mid-1;
		}
	cout<<ans;
	}
