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

struct SuccinctIndexableDictionary {
	size_t length;
	size_t blocks;
	vector< unsigned > bit, sum;

	SuccinctIndexableDictionary() {
	}

	SuccinctIndexableDictionary(size_t _length) {
		length = _length;
		blocks = (length + 31) >> 5;
		bit.assign(blocks, 0U);
		sum.assign(blocks, 0U);
	}

	void set(int k) {
		bit[k >> 5] |= 1U << (k & 31);
	}

	void build() {
		sum[0] = 0U;
		for(int i = 1; i < blocks; i++) {
			sum[i] = sum[i - 1] + __builtin_popcount(bit[i - 1]);
		}
	}

	bool operator[](int k) const {
		return (bool((bit[k >> 5] >> (k & 31)) & 1));
	}

	int rank(int k) {
		return (sum[k >> 5] + __builtin_popcount(bit[k >> 5] & ((1U << (k & 31)) - 1)));
	}

	int rank(bool val, int k) {
		return (val ? rank(k) : k - rank(k));
	}

	int select(bool val, int k) {
		if(k < 0 || rank(val, length) <= k) return (-1);
		int low = 0, high = length;
		while(high - low > 1) {
			int mid = (low + high) >> 1;
			if(rank(val, mid) >= k + 1) high = mid;
			else low = mid;
		}
		return (high - 1);
	}

	int select(bool val, int i, int l) {
		return select(val, i + rank(val, l));
	}
};

template< typename T, int MAXLOG >
struct WaveletMatrix {
	size_t length;
	SuccinctIndexableDictionary matrix[MAXLOG];
	int mid[MAXLOG];

	WaveletMatrix() = default;

	WaveletMatrix(vector< T > v) : length(v.size()) {
		vector< T > l(length), r(length);
		for(int level = MAXLOG - 1; level >= 0; level--) {
			matrix[level] = SuccinctIndexableDictionary(length + 1);
			int left = 0, right = 0;
			for(int i = 0; i < length; i++) {
				if(((v[i] >> level) & 1)) {
					matrix[level].set(i);
					r[right++] = v[i];
				} else {
					l[left++] = v[i];
				}
			}
			mid[level] = left;
			matrix[level].build();
			v.swap(l);
			for(int i = 0; i < right; i++) {
				v[left + i] = r[i];
			}
		}
	}

	pair< int, int > succ(bool f, int l, int r, int level) {
		return {matrix[level].rank(f, l) + mid[level] * f, matrix[level].rank(f, r) + mid[level] * f};
	}

	// v[k]
	T access(int k) {
		T ret = 0;
		for(int level = MAXLOG - 1; level >= 0; level--) {
			bool f = matrix[level][k];
			if(f) ret |= T(1) << level;
			k = matrix[level].rank(f, k) + mid[level] * f;
		}
		return ret;
	}

	T operator[](const int &k) {
		return access(k);
	}

	// count i s.t. (0 <= i < r) && v[i] == x
	int rank(const T &x, int r) {
		int l = 0;
		for(int level = MAXLOG - 1; level >= 0; level--) {
			tie(l, r) = succ((x >> level) & 1, l, r, level);
		}
		return r - l;
	}

	// k-th(0-indexed) smallest number in v[l,r)
	T kth_smallest(int l, int r, int k) {
		assert(0 <= k && k < r - l);
		T ret = 0;
		for(int level = MAXLOG - 1; level >= 0; level--) {
			int cnt = matrix[level].rank(false, r) - matrix[level].rank(false, l);
			bool f = cnt <= k;
			if(f) {
				ret |= T(1) << level;
				k -= cnt;
			}
			tie(l, r) = succ(f, l, r, level);
		}
		return ret;
	}

	// k-th(0-indexed) largest number in v[l,r)
	T kth_largest(int l, int r, int k) {
		return kth_smallest(l, r, r - l - k - 1);
	}

	// count i s.t. (l <= i < r) && (v[i] < upper)
	int range_freq(int l, int r, T upper) {
		int ret = 0;
		for(int level = MAXLOG - 1; level >= 0; level--) {
			bool f = ((upper >> level) & 1);
			if(f) ret += matrix[level].rank(false, r) - matrix[level].rank(false, l);
			tie(l, r) = succ(f, l, r, level);
		}
		return ret;
	}

	// count i s.t. (l <= i < r) && (lower <= v[i] < upper)
	int range_freq(int l, int r, T lower, T upper) {
		return range_freq(l, r, upper) - range_freq(l, r, lower);
	}

	// max v[i] s.t. (l <= i < r) && (v[i] < upper)
	T prev_value(int l, int r, T upper) {
		int cnt = range_freq(l, r, upper);
		return cnt == 0 ? T(-1) : kth_smallest(l, r, cnt - 1);
	}

	// min v[i] s.t. (l <= i < r) && (lower <= v[i])
	T next_value(int l, int r, T lower) {
		int cnt = range_freq(l, r, lower);
		return cnt == r - l ? T(-1) : kth_smallest(l, r, cnt);
	}
};

signed main() {
	ll N;
	scanf("%lld", &N);
	vector<ll> a(N, 0);
	for(ll i=0; i<N; i++) scanf("%lld", &a[i]);
	if(N==1){
		printf("%lld\n", a[0]);
		return 0;
	}

	ll left = 0;
	ll right = 1e9+1;
	auto isOK = [&](ll val) -> bool {
		vector<ll> b(N,0);
		for(ll i=0; i<N; i++) b[i] = (a[i]<val ? -1 : 1);
		vector<ll> rui(N+1, 0);
		for(ll i=0; i<N; i++) rui[i+1] = rui[i] + b[i];
		for(ll i=0; i<N+1; i++) rui[i] += N;

		constexpr ll bitlength = 1 + log2(2*1e5);
		WaveletMatrix<ll,bitlength> wm(rui);
		ll t=0;
		for(ll i=0; i<N+1; i++) {
			t += wm.range_freq(i+1, N+1, rui[i], 2*N);
		}
		return t >= N*(N+1)/2/2;
	};

	while(right - left > 1) {
		ll mid = left + (right - left) / 2;
		if(isOK(mid)) left = mid;
		else right = mid;
	}

	printf("%lld\n", left);
	return 0;
}


Measured memory_bytes: 7420