fun main(args: Array<String>) {
    var n = readLine()!!.toInt()
    var l = readLine()!!.split(" ").map(String::toInt).sorted().reversed()

    var dropIndex = 0
    while (dropIndex < n - 2 && l[dropIndex] > l[dropIndex + 1] + l[dropIndex + 2]) {
        dropIndex++
    }
    l = l.drop(dropIndex)
    n = l.size

    var count = 0
    for (a in 0 until n - 2) {
        for (b in a + 1 until n - 1) {
            val sub = l[a] - l[b]
            for (c in b + 1 until n) {
                if (l[c] > sub) {
                    count++
                } else {
                    break
                }
            }
        }
    }


    println(count)
}