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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = 100005;
const int M = 200005;
int n, a[N], f[M];

void update(int i, int x, int sz){
	// cout<<i<<endl;
	while(i <= sz){
		f[i] += x;
		i += i&(-i);
	}
}

int query(int i){
	int ret = 0;
	while(i){
		ret += f[i];
		i &= (i - 1);
	}
	return ret;
}

ll count(int m){
	int sz = 2*(n + 1);
	for(int i = 0; i <= sz; i++){
		f[i] = 0;
	}
	ll ret = 0;
	update(n + 1, 1, sz);
	int cur = 0;
	for(int i = 1; i <= n; i++){
		if(a[i] <= m)cur--;
		else cur++;
		ret += i - query(n + 1 + cur);
		update(n + 1 + cur, 1, sz);
 	}
 	return ret;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	cin>>n;
	for(int i = 1; i <= n; i++){
		cin>>a[i];
	}
	ll req = n*1LL*(n + 1)/2;
	req = req/2 + 1;
	int lo = 1, hi = 1e9;
	while(lo < hi){
		int mi = lo + (hi - lo)/2;
		if(req <= count(mi))hi = mi;
		else lo = mi + 1;
	}
	cout<<lo<<'\n';


	return 0;
}