#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

ll n;
ll arr[101010];
ll tree[202020];

void update(int x){
	while(x < 202020){
		tree[x]++;
		x += x & -x;
	}
}

int query(int x){
	int ret = 0;
	while(x){
		ret += tree[x];
		x -= x & -x;
	}
	return ret;
}

bool chk(int m){
	memset(tree, 0, sizeof tree);
	ll res = 0, t = n + 1;
	update(t);
	for(int i=1; i<=n; i++){
		t += arr[i] >= m ? 1 : -1;
		res += query(t);
		update(t);
	}
	return res >= ((n*n+n)/2+1)/2;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
	for(int i=1; i<=n; i++) cin >> arr[i];
	
    int l = 0, r = 1e9;
	while(l < r){
		int m = l + r + 1 >> 1;
		if(chk(m)) l = m;
		else r = m - 1;
	}
	cout << l;
}