# frozen_string_literal: true

n = gets.to_i
l = gets.split.map(&:to_i).sort
count = 0
0.upto(n - 3) do |i|
  a = l[i]
  b_lower = l.bsearch_index { |e| a + e > l[i + 2] }
  b_lower = i + 1 if b_lower <= i
  b_lower.upto(n - 2) do |j|
    b = l[j]
    c_upper = l.bsearch_index { |e| a + b <= e }
    next if c_upper == n - 1

    c_lower = l.bsearch_index { |e| e + a > b }
    next if c_lower.nil?

    c_upper = n if c_upper.nil?
    c_upper -= 1
    c_lower = j + 1 if c_lower <= j
    next if c_upper < c_lower

    count += [c_upper - c_lower, 0].max + 1
  end
end

puts count
