// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// モジュール

// Binary Indexed Tree モジュール (0-indexed)
template <typename T>
class BIT {
private:
    vector<T> val;
public:
    ull n;
    BIT(ull _n) : val(_n+1, 0), n(_n) {}
    BIT(vector<T> arr) : val(arr.size() + 1, 0), n(arr.size()) {
        REP(i, n) add(i, arr[i]);
    }
    // a[i] に v を足す O(logN)
    void add(const ull _i, const T _v) {
        for (ull i = _i + 1; i <= n; i += i & (-i)) {
            val[i] += _v;
        }
    }
    // [0, _i) の和を求める O(logN)
    T get(ull i) const {
        T ans = 0;
        for (; i > 0; i ^= i & (-i)) {
            ans += val[i];
        }
        return ans;
    }
    // [l, r) の和を求める o(N)
    T sum(const ull l, const ull r) {
        return get(r) - get(l);
    }
};

// BITを用いて数列の転倒数を求める。O(NlogN)。
// bit.cppを必要とする。
template <typename T>
size_t inversion(vector<T> &x0) {
    
    vector<T> x = x0;
    const int n = x0.size();
    
    // 座圧
    vector<T> unq = x;
    sort(unq.begin(), unq.end());
    unq.erase(unique(unq.begin(), unq.end()), unq.end());
    map<T, int> sahz;
    for (size_t i = 0; i < unq.size(); i++) sahz[unq[i]] = i;
    for (size_t i = 0; i < x.size(); i++) x[i] = sahz[x[i]];
    
    // BITで転倒数を求める
    size_t ans = 0;
    BIT<int> bit(n);
    for (int i = 0; i < n; i++) {
        ans += bit.sum(x[i]+1, n);
        bit.add(x[i], 1);
    }
    
    return ans;
    
}

// 答えがm以下のときtrue
ll is_ans_le(ll m, const vector<ll> &a) {
    ll n = a.size();
    vector<ll> les(n+1);
    REP(i, n) les[i+1] = les[i] + (a[i] <= m);
    vector<ll> nuo(n+1);
    REP(i, n+1) nuo[i] = les[i] * 2 - i;
    reverse(ALL_OF(nuo));
    ll ans = inversion(nuo); // 中央値がM以下の区間の数
    // DUMP(m);
    // DUMP(ans);
    return ans >= n * (n + 1) / 4 + 1;
}

// 処理内容
int main() {
    
    // インタラクティブ問題では除去した方がいいかも
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n; cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    ll ng = 0;
    ll ok = *max_element(ALL_OF(a)) + 1;
    while (abs(ng - ok) > 1) {
        ll mid = (ok + ng) / 2;
        (is_ans_le(mid, a) ? ok : ng) = mid;
    }
    cout << ok << endl;

    // RANGE(i, *min_element(ALL_OF(a))-1, *max_element(ALL_OF(a))+1) {
    //     cerr << "[debug] " << i << "\n";
    //     is_ans_le(i, a);
    // }
    
}

Measured memory_bytes: 10880