#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) x&(-x)
const int N = 100005;
int n, a[N], c[10*N], s[N];
long long query(int x){
    long long ans = 0;
    for(int i = x; i; i -= lowbit(i)) ans += c[i];
    return ans;
}
void add(int x){
    for(int i = x; i <= 2*N; i += lowbit(i)) c[i] += 1;
}
bool check(int x){
    for(int i = 1; i <= 2*N; ++i) c[i] = 0;
    s[0] = 0;
    for(int i = 1; i <= n; ++i){
        s[i] = s[i-1] + (a[i] >= x ? 1 : -1);
    }
    long long sum = 0;
    for(int i = 0; i <= n; ++i){
        sum += query(s[i] + N);
        add(s[i] + N);
    }
    return sum >= 1ll*n*(n+1)/4;
}
int main(){
    int l = 0, r = 0, ans;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i){
        scanf("%d", a+i);
        r = max(a[i], r);
    }
    while(l <= r){
        int mid = (l + r) >> 1;
        if(check(mid)){
            l = mid + 1;
        }else r = mid - 1;
    }
    printf("%d\n", r);
    return 0;
}
