Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

from itertools import accumulate

fact = [1]

for i in range(1, 2 * 10 ** 3 + 1):
    fact.append(fact[-1] * i)


def comb(n, r):
    return int(fact[n] / fact[r] / fact[n-r])


def main():
    n = int(input())
    l = list(map(int, input().split()))

    nums = [0] * 1001

    for e in l:
        nums[e] += 1

    acm = list(accumulate(nums))

    l.sort()
    ans = 0
    tmp = [0] * 1001
    tmp2 = [[0] * 1001 for _ in range(1001)]
    for i in range(n-2):
        for j in range(i+1, n-1):
            a = l[i]
            b = l[j]
            k = min(1000, a+b-1)

            # b < c のときの数
            cnt = acm[k] - acm[b]

            # b == c のときの補正
            if nums[b] >= 3 and a == b and tmp[b] == 0:
                cnt += comb(nums[b], 3)
                tmp[b] = 1

            if nums[b] >= 2 and a != b and tmp2[a][b] == 0:
                cnt += comb(nums[b], 2) * nums[a]
                tmp2[a][b] = 1

            ans += cnt

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline

from bisect import bisect_left


def main():
    n = int(input())
    l = list(map(int, input().split()))

    l.sort()

    ans = 0
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            a = l[i]
            b = l[j]
            mx = bisect_left(l, a + b)
            ans += mx - j - 1

    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

from itertools import accumulate

fact = [1]

for i in range(1, 2 * 10 ** 3 + 1):
    fact.append(fact[-1] * i)


def comb(n, r):
    return int(fact[n] / fact[r] / fact[n-r])


def main():
    n = int(input())
    l = list(map(int, input().split()))

    nums = [0] * 1001

    for e in l:
        nums[e] += 1

    acm = list(accumulate(nums))

    l.sort()
    ans = 0
    tmp = [0] * 1001
    tmp2 = [[0] * 1001 for _ in range(1001)]
    for i in range(n-2):
        for j in range(i+1, n-1):
            a = l[i]
            b = l[j]
            k = min(1000, a+b-1)

            # b < c のときの数
            cnt = acm[k] - acm[b]

            # b == c のときの補正
            if nums[b] >= 3 and a == b and tmp[b] == 0:
                cnt += comb(nums[b], 3)
                tmp[b] = 1

            if nums[b] >= 2 and a != b and tmp2[a][b] == 0:
                cnt += comb(nums[b], 2) * nums[a]
                tmp2[a][b] = 1

            ans += cnt

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline

from bisect import bisect_left


def main():
    n = int(input())
    l = list(map(int, input().split()))

    l.sort()

    ans = 0
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            a = l[i]
            b = l[j]
            mx = bisect_left(l, a + b)
            ans += mx - j - 1

    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

from itertools import accumulate

fact = [1]

for i in range(1, 1001):
    fact.append(fact[-1] * i)


def comb(n, r):
    return int(fact[n] / fact[r] / fact[n-r])


def main():
    n = int(input())
    l = list(map(int, input().split()))

    nums = [0] * 1001

    for e in l:
        nums[e] += 1

    acm = list(accumulate(nums))

    l.sort()
    ans = 0
    tmp = [0] * 1001
    tmp2 = [[0] * 1001 for _ in range(1001)]
    for i in range(n-2):
        for j in range(i+1, n-1):
            a = l[i]
            b = l[j]
            k = min(1000, a+b-1)

            # b < c のときの数
            cnt = acm[k] - acm[b]

            # b == c のときの補正
            if nums[b] >= 3 and a == b and tmp[b] == 0:
                cnt += comb(nums[b], 3)
                tmp[b] = 1

            # if nums[b] >= 2 and a != b and tmp2[a][b] == 0:
            #     cnt += comb(nums[b], 2) * nums[a]
            #     tmp2[a][b] = 1

            ans += cnt

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline

from bisect import bisect_left


def main():
    n = int(input())
    l = list(map(int, input().split()))

    l.sort()

    ans = 0
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            a = l[i]
            b = l[j]
            mx = bisect_left(l, a + b)
            ans += mx - j - 1

    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)

from itertools import accumulate


fact = [1]

for i in range(1, 1001):
    fact.append(fact[-1] * i)


def comb(n, r):
    return fact[n] / fact[r] / fact[n-r]


def main():
    n = int(input())
    l = list(map(int, input().split()))

    nums = [0] * 1001

    for e in l:
        nums[e] += 1

    acm = list(accumulate(nums))

    l.sort()
    ans = 0
    tmp = [0] * 1001
    tmp2 = [[0] * 1001 for _ in range(1001)]
    for i in range(n-2):
        for j in range(i+1, n-1):
            a = l[i]
            b = l[j]
            k = min(1000, a+b-1)

            # b < c のときの数
            cnt = acm[k] - acm[b]

            # b == c のときの補正
            if nums[b] >= 3 and a == b and tmp[b] == 0:
                cnt += int(comb(nums[b], 3))
                tmp[b] = 1

            if nums[b] >= 2 and a != b and tmp2[a][b] == 0:
                cnt += int(comb(nums[b], 2)) * nums[a]
                tmp2[a][b] = 1

            ans += cnt

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline

from bisect import bisect_left


def main():
    n = int(input())
    l = list(map(int, input().split()))

    l.sort()

    ans = 0
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            a = l[i]
            b = l[j]
            mx = bisect_left(l, a + b)
            ans += mx - j - 1

    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)

from itertools import accumulate


def factorial(x):
    if x <= 0:
        return 1

    return factorial(x - 1) * x


fact = [factorial(i) for i in range(1001)]


def comb(n, r):
    return fact[n] / fact[r] / fact[n-r]


def main():
    n = int(input())
    l = list(map(int, input().split()))

    nums = [0] * 1001

    for e in l:
        nums[e] += 1

    acm = list(accumulate(nums))

    l.sort()
    ans = 0
    tmp = [0] * 1001
    tmp2 = [[0] * 1001 for _ in range(1001)]
    for i in range(n-2):
        for j in range(i+1, n-1):
            a = l[i]
            b = l[j]
            k = min(1000, a+b-1)

            # b < c のときの数
            cnt = acm[k] - acm[b]

            # b == c のときの補正
            if nums[b] >= 3 and a == b and tmp[b] == 0:
                cnt += int(comb(nums[b], 3))
                tmp[b] = 1

            if nums[b] >= 2 and a != b and tmp2[a][b] == 0:
                cnt += int(comb(nums[b], 2)) * nums[a]
                tmp2[a][b] = 1

            ans += cnt

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline

from bisect import bisect_left


def main():
    n = int(input())
    l = list(map(int, input().split()))

    l.sort()

    ans = 0
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            a = l[i]
            b = l[j]
            mx = bisect_left(l, a + b)
            ans += mx - j - 1

    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)

from itertools import accumulate
from scipy.misc import comb


# def factorial(x):
#     if x <= 0:
#         return 1
#
#     return factorial(x - 1) * x
#
#
# def comb(n, r):
#     return factorial(n) / factorial(r) / factorial(n - r)


def main():
    n = int(input())
    l = list(map(int, input().split()))

    nums = [0] * 1001

    for e in l:
        nums[e] += 1

    acm = list(accumulate(nums))

    l.sort()
    ans = 0
    tmp = [0] * 1001
    tmp2 = [[0] * 1001 for _ in range(1001)]
    for i in range(n-2):
        for j in range(i+1, n-1):
            a = l[i]
            b = l[j]
            k = min(1000, a+b-1)

            # b < c のときの数
            cnt = acm[k] - acm[b]

            # b == c のときの補正
            if nums[b] >= 3 and a == b and tmp[b] == 0:
                cnt += int(comb(nums[b], 3))
                tmp[b] = 1

            if nums[b] >= 2 and a != b and tmp2[a][b] == 0:
                cnt += int(comb(nums[b], 2)) * nums[a]
                tmp2[a][b] = 1

            ans += cnt

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline

from bisect import bisect_left


def main():
    n = int(input())
    l = list(map(int, input().split()))

    l.sort()

    ans = 0
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            a = l[i]
            b = l[j]
            mx = bisect_left(l, a + b)
            ans += mx - j - 1

    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)

from itertools import accumulate


def factorial(x):
    if x <= 0:
        return 1

    return factorial(x - 1) * x


def comb(n, r):
    return factorial(n) / factorial(r) / factorial(n - r)


def main():
    n = int(input())
    l = list(map(int, input().split()))

    nums = [0] * 1001

    for e in l:
        nums[e] += 1

    acm = list(accumulate(nums))

    l.sort()
    ans = 0
    tmp = [0] * 1001
    tmp2 = [[0] * 1001 for _ in range(1001)]
    for i in range(n-2):
        for j in range(i+1, n-1):
            a = l[i]
            b = l[j]
            k = min(1000, a+b-1)

            # b < c のときの数
            cnt = acm[k] - acm[b]

            # b == c のときの補正
            if nums[b] >= 3 and a == b and tmp[b] == 0:
                cnt += int(comb(nums[b], 3))
                tmp[b] = 1

            if nums[b] >= 2 and a != b and tmp2[a][b] == 0:
                cnt += int(comb(nums[b], 2)) * nums[a]
                tmp2[a][b] = 1

            ans += cnt

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline

from bisect import bisect_left


def main():
    n = int(input())
    l = list(map(int, input().split()))

    l.sort()

    ans = 0
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            a = l[i]
            b = l[j]
            mx = bisect_left(l, a + b)
            ans += mx - j - 1

    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)

from itertools import accumulate


def factorial(x):
    if x <= 0:
        return 1

    return factorial(x - 1) * x


def comb(n, r):
    return factorial(n) / factorial(r) / factorial(n - r)


def main():
    n = int(input())
    l = list(map(int, input().split()))

    nums = [0] * 1001

    for e in l:
        nums[e] += 1

    acm = list(accumulate(nums))

    l.sort()
    ans = 0
    tmp = [0] * 1001
    tmp2 = [0] * 1001
    for i in range(n-2):
        for j in range(i+1, n-1):
            a = l[i]
            b = l[j]
            k = min(1000, a+b-1)

            # b < c のときの数
            cnt = acm[k] - acm[b]

            # b == c のときの補正
            if nums[b] >= 3 and a == b and tmp[b] == 0:
                cnt += int(comb(nums[b], 3))
                tmp[b] = 1

            if nums[b] >= 2 and a != b and tmp2[b] == 0:
                cnt += int(comb(nums[b], 2)) * nums[a]
                tmp2[b] = 1

            ans += cnt

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline

from bisect import bisect_left


def main():
    n = int(input())
    l = list(map(int, input().split()))

    l.sort()

    ans = 0
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            a = l[i]
            b = l[j]
            mx = bisect_left(l, a + b)
            ans += mx - j - 1

    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

from itertools import accumulate


def factorial(x):
    if x <= 0:
        return 1

    return factorial(x - 1) * x


def comb(n, r):
    return factorial(n) / factorial(r) / factorial(n - r)


def main():
    n = int(input())
    l = list(map(int, input().split()))

    nums = [0] * 1001

    for e in l:
        nums[e] += 1

    acm = list(accumulate(nums))

    l.sort()
    ans = 0
    tmp = [0] * 1001
    tmp2 = [0] * 1001
    for i in range(n-2):
        for j in range(i+1, n-1):
            a = l[i]
            b = l[j]
            k = min(1000, a+b-1)

            # b < c のときの数
            cnt = acm[k] - acm[b]

            # b == c のときの補正
            if nums[b] >= 3 and a == b and tmp[b] == 0:
                cnt += int(comb(nums[b], 3))
                tmp[b] = 1

            if nums[b] >= 2 and a != b and tmp2[b] == 0:
                cnt += int(comb(nums[b], 2))
                tmp2[b] = 1

            ans += cnt

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline

from bisect import bisect_left


def main():
    n = int(input())
    l = list(map(int, input().split()))

    l.sort()

    ans = 0
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            a = l[i]
            b = l[j]
            mx = bisect_left(l, a + b)
            ans += mx - j - 1

    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

from itertools import accumulate


def factorial(x):
    if x == 0:
        return 1

    return factorial(x - 1) * x


def comb(n, r):
    return factorial(n) / factorial(r) / factorial(n - r)


def main():
    n = int(input())
    l = list(map(int, input().split()))

    nums = [0] * 1001

    for e in l:
        nums[e] += 1

    acm = list(accumulate(nums))

    l.sort()
    ans = 0
    tmp = [0] * 1001
    tmp2 = [0] * 1001
    for i in range(n-2):
        for j in range(i+1, n-1):
            a = l[i]
            b = l[j]
            k = min(1000, a+b-1)

            # b < c のときの数
            cnt = acm[k] - acm[b]

            # b == c のときの補正
            if nums[b] >= 3 and a == b and tmp[b] == 0:
                cnt += int(comb(nums[b], 3))
                tmp[b] = 1

            if nums[b] >= 2 and a != b and tmp2[b] == 0:
                cnt += int(comb(nums[b], 2))
                tmp2[b] = 1

            ans += cnt

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline

from bisect import bisect_left


def main():
    n = int(input())
    l = list(map(int, input().split()))

    l.sort()

    ans = 0
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            a = l[i]
            b = l[j]
            mx = bisect_left(l, a + b)
            ans += mx - j - 1

    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

from itertools import accumulate
from math import factorial


def comb(n, r):
    return factorial(n) / factorial(r) / factorial(n - r)


def main():
    n = int(input())
    l = list(map(int, input().split()))

    nums = [0] * 1001

    for e in l:
        nums[e] += 1

    acm = list(accumulate(nums))

    l.sort()
    ans = 0
    tmp = [0] * 1001
    tmp2 = [0] * 1001
    for i in range(n-2):
        for j in range(i+1, n-1):
            a = l[i]
            b = l[j]
            k = min(1000, a+b-1)

            # b < c のときの数
            cnt = acm[k] - acm[b]

            # b == c のときの補正
            if nums[b] >= 3 and a == b and tmp[b] == 0:
                cnt += int(comb(nums[b], 3))
                tmp[b] = 1

            if nums[b] >= 2 and a != b and tmp2[b] == 0:
                cnt += int(comb(nums[b], 2))
                tmp2[b] = 1

            ans += cnt

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline

from bisect import bisect_left


def main():
    n = int(input())
    l = list(map(int, input().split()))

    l.sort()

    ans = 0
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            a = l[i]
            b = l[j]
            mx = bisect_left(l, a + b)
            ans += mx - j - 1

    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

from itertools import accumulate
from scipy.special import comb


def main():
    n = int(input())
    l = list(map(int, input().split()))

    nums = [0] * 1001

    for e in l:
        nums[e] += 1

    acm = list(accumulate(nums))

    l.sort()
    ans = 0
    tmp = [0] * 1001
    tmp2 = [0] * 1001
    for i in range(n-2):
        for j in range(i+1, n-1):
            a = l[i]
            b = l[j]
            k = min(1000, a+b-1)

            # b < c のときの数
            cnt = acm[k] - acm[b]

            # b == c のときの補正
            if nums[b] >= 3 and a == b and tmp[b] == 0:
                cnt += int(comb(nums[b], 3))
                tmp[b] = 1

            if nums[b] >= 2 and a != b and tmp2[b] == 0:
                cnt += int(comb(nums[b], 2))
                tmp2[b] = 1

            ans += cnt

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline

from bisect import bisect_left


def main():
    n = int(input())
    l = list(map(int, input().split()))

    l.sort()

    ans = 0
    for i in range(n - 2):
        for j in range(i + 1, n - 1):
            a = l[i]
            b = l[j]
            mx = bisect_left(l, a + b)
            ans += mx - j - 1

    print(ans)


if __name__ == "__main__":
    main()