def solve(string):

    n, *l = list(map(int, string.split()))

    l.sort()

    nums = 0

    for i, a in enumerate(l[:-2]):

        k = i + 2

        for j, b in enumerate(l[i + 1:-1], i + 1):

            while k < n and l[k] < a + b:

                k += 1

            nums += k - j - 1

    return str(nums)





if __name__ == '__main__':

    print((solve('\n'.join([eval(input()), eval(input())]))))

def solve(string):

    n, *l = list(map(int, string.split()))

    l.sort(reverse=True)

    nums = 0

    for i, a in enumerate(l[:-2]):

        j, k = i + 1, n - 1

        while (j < k):

            if (a < l[j] + l[k]):

                nums += k - j

                j += 1

            else:

                k -= 1

    return str(nums)





if __name__ == '__main__':

    print((solve('\n'.join([eval(input()), eval(input())]))))

def solve(string):
    n, *l = list(map(int, string.split()))
    l.sort()
    nums = 0
    for i, a in enumerate(l[:-2]):
        k = i + 2
        for j, b in enumerate(l[i + 1 : -1], i + 1):
            while k < n and l[k] < a + b:
                k += 1
            nums += k - j - 1
    return str(nums)


if __name__ == "__main__":
    print((solve("\n".join([eval(input()), eval(input())]))))

def solve(string):
    n, *l = list(map(int, string.split()))
    l.sort(reverse=True)
    nums = 0
    for i, a in enumerate(l[:-2]):
        j, k = i + 1, n - 1
        while j < k:
            if a < l[j] + l[k]:
                nums += k - j
                j += 1
            else:
                k -= 1
    return str(nums)


if __name__ == "__main__":
    print((solve("\n".join([eval(input()), eval(input())]))))

-    l.sort() +    l.sort(reverse=True) -        k = i + 2 -        for j, b in enumerate(l[i + 1 : -1], i + 1): -            while k < n and l[k] < a + b: -                k += 1 -            nums += k - j - 1 +        j, k = i + 1, n - 1 +        while j < k: +            if a < l[j] + l[k]: +                nums += k - j +                j += 1 +            else: +                k -= 1