fun main(args: Array<String>) {
    readLine()
    val lines = readLine()!!.split(" ").map { it.toInt() }.sorted().reversed()

    var answer = 0
    for (long_i in 0..(lines.size - 3)){
        for (middle_i in (long_i + 1)..(lines.size - 2)){
            var top = lines.size - 1
            var bottom = middle_i
            var middle = 0
            while (top > bottom + 1) {
                middle = (top + bottom) / 2
                if (lines[long_i] < lines[middle_i] + lines[middle]){
                    bottom = middle
                } else {
                    top = middle
                }
            }
            answer += (bottom - middle_i)
            if (lines[long_i] < lines[middle_i] + lines.last()){
                answer += 1
            }
        }
    }
    println(answer)
}