// Original C++ solution (slower):
#include <cstdio>

#include <cstring>

#include <algorithm>

#define ll long long

#define inf 1<<30

#define il inline 

#define in1(a) read(a)

#define in2(a,b) in1(a),in1(b)

#define in3(a,b,c) in2(a,b),in1(c)

#define in4(a,b,c,d) in2(a,b),in2(c,d)

il void readl(ll &x){

    x=0;ll f=1;char c=getchar();

    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}

    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}

    x*=f;

}

il void read(int &x){

    x=0;int f=1;char c=getchar();

    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}

    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}

    x*=f;

}

using namespace std;

/*===================Header Template=====================*/

#define N 100001

#define lowbit(x) x&-x

int c[N*10];

int n,a[N],s[N*10],f[N];

void add(int x){

    for(int i=x;i<=2*N;i+=lowbit(i))c[i]++;

}

ll query(int x){

    ll sum=0;

    for(int i=x;i>0;i-=lowbit(i))sum+=c[i];

    return sum;

}

bool check(int x){

	//x=8;

    for(int i=1;i<=2*N;i++)c[i]=0;

    s[0]=0;

    for(int i=1;i<=n;i++)

        s[i]=s[i-1]+(a[i]>=x?1:-1);

    ll sum=0;

    for(int i=0;i<=n;i++){

        sum+=query(s[i]+N);

        add(s[i]+N);

    }

    return sum>=1ll*n*(n+1)/4;

}

int main(){

    in1(n);

    int l=0,r=0;

    for(int i=1;i<=n;i++){

        in1(a[i]);f[i]=a[i];

        //r=max(r,a[i]);

    }r=n;sort(f+1,f+n+1);

    int ans=0;l=1;

    while(l<=r){

        int mid=(l+r)>>1;

        if(check(f[mid]))l=mid+1;

        else r=mid-1;

    }

    printf("%d\n",f[r]);

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cmath>

using namespace std;

#define INF 1000000000;

int a[100005],sum[100005],save[100005];

typedef long long ll;

ll to,to1;

int n;int maxl,minl;

void sortl(int left,int right)

{

    if(left==right)

        return ;

    int mid=(right+left)/2;

    sortl(left,mid);

    sortl(mid+1,right);

    int l=left,l2=mid+1,r=left;

    while(l<=mid&&l2<=right)

    {

        if(sum[l]<sum[l2])

            save[r++]=sum[l++];

        else

        {

            to1+=l-left;

            save[r++]=sum[l2++];

        }

    }

    while(l<=mid)

        save[r++]=sum[l++];

    while(l2<=right)

    {

        to1+=l-left;

        save[r++]=sum[l2++];

    }

    for(int i=left;i<=right;i++)

        sum[i]=save[i];

}

bool ck(int x)

{

    to1=0;

    for(int i=1;i<=n;++i)

        sum[i]=(a[i]<=x?1:-1);

    for(int i=1;i<=n;++i)

        sum[i]+=sum[i-1];

    sortl(0,n);

    return to1>=to/2+1;

}

int main()

{

    maxl=-INF;minl=INF

    scanf("%d",&n);

    to=0;

    for(int i=1;i<=n;++i)

    {

        scanf("%d",&a[i]);

        minl=min(minl,a[i]);

        maxl=max(maxl,a[i]);

        to+=i;

    }

    while(minl<maxl)

    {

        int mid=(minl+maxl)/2;

        if(ck(mid))

            maxl=mid;

        else

            minl=mid+1;

    }

    printf("%d\n",maxl);

}


// Fastest known solution for this problem:
#define _USE_MATH_DEFINES



#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <iostream>

#include <cmath>

#include <algorithm>

#include <vector>

#include <queue>

#include <map>

#include <list>

#include <stack>



using namespace std;



typedef pair<long long int, long long int> P;



long long int INF = 1e18;

long long int MOD = 1e9 + 7;



long long int N, sz = 150000;

long long int A[110000];

bool flag[110000];

long long int BIT[210000];



void add(int a, long long int w){

	

	// a番目の要素にwを足す O(log N)

	

	for(int x = a; x <= sz; x += x & -x){

		BIT[x] += w;

	}

}



long long int sum(int a){

	

	// 1からaまでの要素の合計を返す O(log N)

	

	long long int ret = 0;

	for(int x = a; x > 0; x -= x & -x){

		ret += BIT[x];

	}

	return ret;

}



void init(){

	for(int i = 0; i < sz; i++){

		BIT[i] = 0;

	}

}



bool check(long long int min_A){

	for(int i = 0; i < N; i++){

		flag[i] = (A[i] >= min_A);

	}

	vector<P> v;

	long long int cnt = 0, S = 0;

	v.push_back(make_pair(0, 1));

	for(int i = 0; i < N; i++){

		if(flag[i]){

			S += 1;

		}else{

			S -= 1;

		}

		v.push_back(make_pair(S, i + 2));

	}

	sort(v.begin(), v.end());

	init();

	for(int i = 0; i < v.size(); i++){

		cnt += sum(v[i].second);

		add(v[i].second, 1);

	}

	//cout << min_A << " " << cnt << endl;

	return cnt >= (N * (N + 1) / 2 + 1) / 2;

}



long long int bin_search(long long int lef, long long int rig){

	long long int middle = (lef + rig) / 2;

	//cout << middle << " ";

	if(rig - lef <= 1){

		if(check(rig)){

			return rig;

		}else{

			return lef;

		}

	}

	if(check(middle)){

		lef = middle;

	}else{

		rig = middle;

	}

	return bin_search(lef, rig);

}



int main(){

	

	cin >> N;

	

	for(int i = 0; i < N; i++){

		cin >> A[i];

	}

	

	cout << bin_search(0, 1e10) << endl;

	

	return 0;

}