class BIT(val n: Int) {
  var bit: LongArray
  init {
    bit = LongArray(n + 1) { 0L }
  }
  fun sum(i: Int): Long {
    var res = 0L
    var k = i
    while (k > 0) {
      res += bit[k]
      k -= k and -k
    }
    return res
  }
  fun add(i: Int, x: Long) {
    var k = i
    while (k < n + 1) {
      bit[k] += x
      k += k and -k
    }
  }
}

fun f(m: Int, n: Int, a: List<Int>): Boolean {
  var s = IntArray(n + 1) { 0 }
  for (i in 0 until n) {
    s[i + 1] = s[i] + if (a[i] >= m) 1 else -1
  }
  val mn = s.min()!!
  s = s.map { it - mn + 1 }.toIntArray()

  val mx = s.max()!!
  var bit = BIT(mx)
  var res = 0L
  for (j in 0..n) {
    res += bit.sum(s[j])
    bit.add(s[j], 1L)
  }
  val nn = 1L * n * (n + 1) / 2
  return (res >= (nn + 1) / 2)
}

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val a = readLine()!!.split(" ").map { it.toInt() }
  var ok = 1
  var ng = a.max()!! + 1
  while (ng - ok > 1) {
    val m = (ok + ng) / 2
    if (f(m, n, a)) {
      ok = m
    } else {
      ng = m
    }
  }
  println(ok)
}
