#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

template<typename T>
struct BinaryIndexedTree {
    vector<T> data;

    BinaryIndexedTree(int sz) {
        data.assign(++sz, 0);
    }

    T sum(int k) {
        T ret = 0;
        for (++k; k > 0; k -= k & -k) ret += data[k];
        return (ret);
    }

    void add(int k, T x) {
        for (++k; k < data.size(); k += k & -k) data[k] += x;
    }
};

ll solve(vector<int> v, int x) {
    ll ret = 0;

    int now = 150000;
    BinaryIndexedTree<int> BIT(300000);
    BIT.add(now, 1);
    for (auto a:v) {
        now += a >= x ? 1 : -1;
        ret += BIT.sum(now);
        BIT.add(now, 1);
    }

    return ret;
}

int main() {
    ll n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)cin >> a[i];

    int ng = 1145141919, ok = 0;
    while (ng - ok > 1) {
        int mid = ok + (ng - ok) / 2;
        if (solve(a, mid) * 2 >= n * (n + 1) / 2)ok = mid;
        else ng = mid;
    }

    cout << ok << endl;
    return 0;
}