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

#include <queue>

#include <vector>

#include <map>

#include <set>

#include <cstring>

using namespace std;

typedef long long ll;

ll ans;

int n,val[100005],c[100005],pre[100005];

void merge(int a[],int l,int r){

    if(l==r)

        return;

    int mid = (l+r)/2;

    merge(a,l,mid);

    merge(a,mid+1,r);

    int i=l,j=mid+1,index=l;

    while (i<=mid&&j<=r){

        if(a[i]>a[j]){

            c[index++]=a[j];

            ans+=mid-i+1;

            j++;

        } else{

            c[index++]=a[i];

            i++;

        }

    }

    while (i<=mid)

        c[index++]=a[i++];

    while (j<=r)

        c[index++]=a[j++];

    for(int i=l;i<=r;i++)

        a[i]=c[i];

}

bool check(int mid){

    //memset(pre,0, sizeof(pre));

    ans = 0;//逆序对的数量

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

        if(val[i]<mid)

            pre[i]=pre[i-1]-1;

        else

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

        if(pre[i]<0)

            ans++;

    }

    merge(pre,1,n);

    ll all = 1ll*n*(n+1)/2;

    return all>=2*ans;

}

int main(){

    ios::sync_with_stdio(false);

    cin>>n;

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

        cin>>val[i];

    }

    int l = 1,r = 1e9;

    while (l+1<r){

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

        if(check(mid)){//增加的区间大于等于一半了(数偏小

            l=mid;

        } else

            r=mid;

    }

    if(check(l+1)) ++l;

    cout<<l<<endl;

}




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

#include <cstring>

#include <algorithm>

#include <cassert>

const int MAXN = 1e5 + 10;

typedef int IntAr[MAXN];

typedef long long LL;



int N;

IntAr A, B, C, D;

LL tot;



namespace FastIO {

	template <typename T>

	void read(T & x) {

		x = 0; register char ch = getchar();

		for (; ch < '0' || ch > '9'; ch = getchar());

		for (; ch >= '0' && ch <= '9'; x = (x << 3) + (x << 1) + (ch ^ '0'), ch = getchar());

	}

}

LL count(int);

void merge(int l, int r);



// #define DEBUG_MD_



int main() {

	using FastIO::read;

	read(N);

	for (int i = 0; i < N; i++) scanf("%d", &A[i]);

	memcpy(B, A, sizeof(int) * N);

	std::sort(B, B + N);

	int lb = -1, mid, ub = std::unique(B, B + N) - B - 1;

	LL pos = (LL(N) * (N + 1) >> 2) + 1;

#ifdef DEBUG_MD_

	printf("pos=%lld\n", pos);

#endif 

	for (; ub - lb > 1; ) { // (lb, ub]

		mid = lb + ub >> 1;

		assert(mid >= 0);

		if (count(B[mid]) >= pos) ub = mid;

		else lb = mid;

	}

	// return 0;

	printf("%d\n", B[ub]);

	return 0;

}



LL count(int key) {

	C[0] = 0;

	for (int i = 1; i <= N; i++) C[i] = C[i - 1] + (A[i - 1] > key ? -1 : 1);

	tot = 0;

	merge(0, N + 1);

#ifdef DEBUG_MD_

	printf("key=%d, tot=%lld\n", key, tot);

#endif 

	return tot;

}



void merge(int l, int r) {

	// merge sort interval [l, r)

	if (r - l <= 1) return;

	int mid = l + r >> 1;

	merge(l, mid);

	merge(mid, r);

#ifdef DEBUG_MD_

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

#endif

	int i, j, k;

	for (i = l, j = mid, k = l; i < mid && j < r; )

		if (C[i] < C[j]) {

			D[k++] = C[i++];

			tot += r - j;

		}

		else D[k++] = C[j++];

	for (; i < mid; ) D[k++] = C[i++];

	for (; j < r; ) D[k++] = C[j++];

	memcpy(C + l, D + l, sizeof(int) * (r - l));

}

// 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;

}