#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class T> struct fenwick{
  int size;
  int memory;
  T *data;
  void malloc(int mem){
    memory = mem;
    data = (T*)std::malloc(sizeof(T)*mem);
  }
  void walloc(int mem, void **workMemory=&wmem){
    memory = mem;
    walloc1d(&data, mem, workMemory);
  }
  void free(void){
    memory = 0;
    free(data);
  }
  void init(int N){
    size = N;
    memset(data,0,sizeof(T)*N);
  }
  void add(int k, T val){
    while(k < size){
      data[k] += val;
      k |= k+1;
    }
  }
  T get(int k){
    T res = 0;
    while(k>=0){
      res += data[k];
      k = (k&(k+1))-1;
    }
    return res;
  }
  T range(int a, int b){
    if(b==-1){
      b=size-1;
    }
    return get(b) - get(a-1);
  }
  int kth(T k){
    int i=0;
    int j=size;
    int c;
    T v;
    while(i<j){
      c = (i+j)/2;
      v = get(c);
      if(v <= k){
        i=c+1;
      }
      else{
        j=c;
      }
    }
    return i==size?-1:i;
  }
}
;
int N;
int A[100000];
int sm[100001];
int main(){
  wmem = memarr;
  long long cnt;
  long long all;
  int res;
  fenwick<int> t;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  t.malloc(2*N+3);
  all = (long long) N * (N+1) / 2;
  int e98WHCEY;
  int cTE1_r3A;
  int RZTsC2BF;
  e98WHCEY = 1;
  cTE1_r3A = 1000000000;
  while(e98WHCEY < cTE1_r3A){
    int i;
    if((e98WHCEY + cTE1_r3A)%2==0){
      RZTsC2BF = (e98WHCEY + cTE1_r3A) / 2;
    }
    else{
      RZTsC2BF = (e98WHCEY + cTE1_r3A + 1) / 2;
    }
    t.init(2*N+3);
    sm[0] = N;
    for(i=(0);i<(N);i++){
      if(A[i]>=RZTsC2BF){
        sm[i+1] = sm[i]+1;
      }
      else{
        sm[i+1] = sm[i]-1;
      }
    }
    cnt = 0;
    for(i=(0);i<(N+1);i++){
      cnt += t.get(sm[i]);
      t.add(sm[i],1);
    }
    if(2*cnt >= all){
      e98WHCEY = RZTsC2BF;
    }
    else{
      cTE1_r3A = RZTsC2BF - 1;
    }
  }
  res =cTE1_r3A;
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20191111-2

// --- original code ---
// int N, A[1d5];
// int sm[100001];
// {
//   ll cnt, all;
//   int res;
//   fenwick<int> t;
// 
//   rd(N,A(N));
//   t.malloc(2N+3);
// 
//   all = (ll) N * (N+1) / 2;
//   res = bsearch_max[int,x,1,1d9][
//     t.init(2N+3);
//     sm[0] = N;
//     rep(i,N) sm[i+1] = sm[i] if[A[i]>=x, +, -] 1;
//     cnt = 0;
//     rep(i,N+1){
//       cnt += t.get(sm[i]);
//       t.add(sm[i],1);
//     }
//   ](2*cnt >= all);
//   wt(res);
// }


Measured memory_bytes: 1792