fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val ds = readLine()!!.split(" ").take(n).map { it.toInt() }.sorted().toIntArray()

    var count = 0
    for (ai in (0 until ds.size - 2)) {
        for (bi in (ai + 1 until ds.size - 1)) {
            count += search(ds, ds[ai] + ds[bi], (bi + 1), ds.size - 1)
        }
    }

    print(count)
}

fun search(array: IntArray, key: Int, from: Int, to: Int): Int {
    var low = from
    var high = to
    if (array[from] >= key) {
        return 0
    }

    while (low < high) {
        val mid = (low + high) / 2 + 1
        val midVal = array[mid]

        if (midVal < key)
            low = mid
        else if (midVal >= key)
            high = mid - 1

    }
    return low - from + 1

}