#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5;
int a[N+5];
struct ft{
	int ft[2*N+10];
	void init(){
		memset(ft, 0, sizeof(ft));
	}
	void update(int i, int v){
		for(;i<=2*N+5;i+=(i&-i)){
			ft[i] += v;
		}
	}
	int query(int i){
		int res = 0;
		for(;i>0;i-=(i&-i)) res+=ft[i];
		return res;
	}
}ft;
int main(){
	int n;
	scanf("%d", &n);
	for(int i=1;i<=n;i++){
		scanf("%d", &a[i]);
	}
	LL tot = (LL)n*(n+1)/2;
	LL m = tot/2+1;
	int lo = 1, hi = 1e9, ans = 0;
	while(lo <= hi){
		int mid = (lo+hi)/2;
		int cnt = 100001;
		LL res = 0;
		ft.init();
		for(int i=1;i<=n;i++){
			ft.update(cnt, 1);
			if(a[i] <= mid) cnt++;
			else cnt--;
			res += ft.query(cnt-1);
		}
		if(res >= m) ans = mid, hi = mid-1;
		else lo = mid+1;
	}
	printf("%d\n", ans);
}