import java.util.*
import kotlin.*

import java.io.InputStream
import java.lang.NumberFormatException
import java.lang.StringBuilder


fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = FastScanner()
        val n = sc.nextInt()
        val a = (1..n).map { sc.nextInt() }

        // iが中央値 i以下の数 - i強の数 > 0 の値で最小

        var ng = a.min()!! - 1
        var ok = a.max()!!
        val all = n.toLong() * (n + 1) / 2
        while (ok - ng > 1) {
            val med = (ok + ng) / 2
            var sum = 0
            val bit = FenwickTree(2 * n + 1)
            bit.add(n, 1)
            var cnt = 0L
            for (i in 0 until n) {
                sum += if (a[i] <= med) 1 else -1
                cnt += bit.sum(sum + n)
                bit.add(sum + n, 1)
            }

            if (cnt > all - cnt) {
                ok = med
            } else {
                ng = med
            }
        }

        println(ok)
    }
}

class FenwickTree(private val size: Int) {
    private val tree = Array(size + 1) { 0 }

    // a[i]にnを加算
    fun add(i: Int, n: Int) {
        var t = i + 1
        while (t <= size) {
            tree[t] += n
            t += (t and (-t))
        }
    }

    // [0,i)の合計を求める
    fun sum(i: Int): Int {
        var result = 0
        var t = i
        while (t > 0) {
            result += tree[t]
            t -= (t and (-t))
        }
        return result
    }
}

class FastScanner {
    companion object {
        val input: InputStream = System.`in`
        val buffer = ByteArray(1024) { 0 }
        fun isPrintableChar(c: Int): Boolean = c in 33..126
    }

    var ptr = 0
    var buflen = 0
    private fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = input.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }

    private fun readByte(): Int = if (hasNextByte()) buffer[ptr++].toInt() else -1

    private fun skipUnprintable() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr].toInt())) ptr++
    }

    fun hasNext(): Boolean {
        skipUnprintable()
        return hasNextByte()
    }

    fun next(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b)
            b = readByte()
        }
        return sb.toString()
    }

    fun nextInt(): Int {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0
        var b = readByte()
        // '-' = 45
        val minus = b == 45
        if (minus) {
            b = readByte()
        }

        // '0' = 48 '9' = 57
        if (b !in 48..57) {
            throw NumberFormatException()
        }

        while (true) {
            if (b in 48..57) {
                n *= 10
                n += b - 48
            } else if (b == -1 || !isPrintableChar(b)) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun nextLong(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var b = readByte()
        // '-' = 45
        val minus = b == 45
        if (minus) {
            b = readByte()
        }

        // '0' = 48 '9' = 57
        if (b !in 48..57) {
            throw NumberFormatException()
        }

        while (true) {
            if (b in 48..57) {
                n *= 10
                n += b - 48
            } else if (b == -1 || !isPrintableChar(b)) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun nextDouble(): Double = next().toDouble()
}


Measured memory_bytes: 116116