# ABC143D - Triangles

def binary_search(cur: int, upper_bound: int = 1 << 60, lower_bound: int = -1) -> int:

    ok, ng, ret = upper_bound, lower_bound, 0

    while abs(ok - ng) > 0:

        if L[ok] + L[ng] > cur:

            ret += ok - ng

            ok -= 1

        else:

            ng += 1

    return ret





def main():

    # fix the longest edge -> binary search

    global L

    N, *L = list(map(int, open(0).read().split()))

    L.sort()

    ans = sum(binary_search(L[i], i - 1, 0) for i in range(N - 1, 1, -1))

    print(ans)





if __name__ == "__main__":

    main()
# ABC143D - Triangles

def binary_search(cur: int, upper_bound: int = 1 << 60, lower_bound: int = -1) -> int:

    ok, ng, ret = upper_bound, lower_bound, 0

    while ok > ng:

        if L[ok] + L[ng] > cur:

            ret += ok - ng

            ok -= 1

        else:

            ng += 1

    return ret





def main():

    # fix the longest edge -> binary search

    global L

    N, *L = list(map(int, open(0).read().split()))

    L.sort()

    ans = sum(binary_search(L[i], i - 1, 0) for i in range(N - 1, 1, -1))

    print(ans)





if __name__ == "__main__":

    main()
# ABC143D - Triangles
def binary_search(cur: int, upper_bound: int = 1 << 60, lower_bound: int = -1) -> int:
    ok, ng, ret = upper_bound, lower_bound, 0
    while abs(ok - ng) > 0:
        if L[ok] + L[ng] > cur:
            ret += ok - ng
            ok -= 1
        else:
            ng += 1
    return ret


def main():
    # fix the longest edge -> binary search
    global L
    N, *L = list(map(int, open(0).read().split()))
    L.sort()
    ans = sum(binary_search(L[i], i - 1, 0) for i in range(N - 1, 1, -1))
    print(ans)


if __name__ == "__main__":
    main()

# ABC143D - Triangles
def binary_search(cur: int, upper_bound: int = 1 << 60, lower_bound: int = -1) -> int:
    ok, ng, ret = upper_bound, lower_bound, 0
    while ok > ng:
        if L[ok] + L[ng] > cur:
            ret += ok - ng
            ok -= 1
        else:
            ng += 1
    return ret


def main():
    # fix the longest edge -> binary search
    global L
    N, *L = list(map(int, open(0).read().split()))
    L.sort()
    ans = sum(binary_search(L[i], i - 1, 0) for i in range(N - 1, 1, -1))
    print(ans)


if __name__ == "__main__":
    main()

-    while abs(ok - ng) > 0: +    while ok > ng: