Buggy python submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def C(n,r):
    if n < 0 or r < 0 or n < r: 
        return 0
    elif n == 0 or r == 0: 
        return 1
    return C(n-1,r-1)+C(n-1,r)

def main():
    n = ni()
    l = sorted(na())
    ans = C(n, 3) // 3
    j = n - 2
    k = n - 1
    dame = []
    for i in range(n - 3, -1, -1):
        if i in dame or j in dame or k in dame:
            continue
        a = l[i]
        b = l[j]
        c = l[k]
        if a < b + c and b < a + c and c < a + b:
            j -= 1
            k -= 1
        else:
            if a > b + c:
                dame.append(i)
            if b > a + c:
                dame.append(j)
            if c > a + b:
                dame.append(k)
    
    for d in dame:
        ans -= C(n - d - 1, 1)

    nn = len(dame)
    if nn >= 3:
        j = n - 2
        k = n - 1
        for i in range(dame - 3, -1, -1):
            a = l[i]
            b = l[j]
            c = l[k]
            if a < b + c and b < a + c and c < a + b:
                ans += 1

    print(ans)

main()

Fixed submission:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

from bisect import bisect_left

def main():
    n = ni()
    l = sorted(na())
    
    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            t = l[i] + l[j]
            ind = bisect_left(l, t)
            ans += max(0, ind - j - 1)
    print(ans)

main()

Buggy python submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def C(n,r):
    if n < 0 or r < 0 or n < r: 
        return 0
    elif n == 0 or r == 0: 
        return 1
    return C(n-1,r-1)+C(n-1,r)

def main():
    n = ni()
    l = sorted(na())
    ans = C(n, 3) % 3
    j = n - 2
    k = n - 1
    dame = []
    for i in range(n - 3, -1, -1):
        if i in dame or j in dame or k in dame:
            continue
        a = l[i]
        b = l[j]
        c = l[k]
        if a < b + c and b < a + c and c < a + b:
            j -= 1
            k -= 1
        else:
            if a > b + c:
                dame.append(i)
            if b > a + c:
                dame.append(j)
            if c > a + b:
                dame.append(k)
    
    for d in dame:
        ans -= C(n - d - 1, 1)

    nn = len(dame)
    if nn >= 3:
        j = n - 2
        k = n - 1
        for i in range(dame - 3, -1, -1):
            a = l[i]
            b = l[j]
            c = l[k]
            if a < b + c and b < a + c and c < a + b:
                ans += 1

    print(ans)

main()

Fixed submission:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

from bisect import bisect_left

def main():
    n = ni()
    l = sorted(na())
    
    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            t = l[i] + l[j]
            ind = bisect_left(l, t)
            ans += max(0, ind - j - 1)
    print(ans)

main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def C(n,r):
    if n < 0 or r < 0 or n < r: 
        return 0
    elif n == 0 or r == 0: 
        return 1
    return C(n-1,r-1)+C(n-1,r)

def main():
    n = ni()
    l = sorted(na())

    j = n - 2
    k = n - 1
    cnt = 0
    dame = []
    for i in range(n - 3, -1, -1):
        try:
            if i in dame or j in dame or k in dame:
                continue
            a = l[i]
            b = l[j]
            c = l[k]
            if a < b + c and b < a + c and c < a + b:
                cnt += C(n - i - len(dame) - 1, 2)
                j -= 1
                k -= 1
            else:
                tmp = j
                while True:
                    a = l[i]
                    b = l[j]
                    c = l[k]
                    if a < b + c and b < a + c and c < a + b:
                        break
                    j += 1
                    k += 1
                    tmp = j
                cnt += C(n - tmp - 1 - len(dame), 2)
                dame.append(i)
        except:
            break
    print(cnt)

main()

Fixed submission:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

from bisect import bisect_left

def main():
    n = ni()
    l = sorted(na())
    
    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            t = l[i] + l[j]
            ind = bisect_left(l, t)
            ans += max(0, ind - j - 1)
    print(ans)

main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def main():
    n = ni()
    l = sorted(na(), reverse=True)

    cnt = 0
    for i in range(n):
        for j in range(i + 1, n):
            # k = n - i - j
            # a = l[i]
            # b = l[j]
            # c = l[k]
            # if a < b + c and b < a + c and c < a + b:
            #     cnt += C(n - i, 2)
            #     print(a, b, c)
            for k in range(j + 1, n):
                a = l[i]
                b = l[j]
                c = l[k]
                if a < b + c and b < a + c and c < a + b:
                    # print(a, b, c)
                    cnt += 1
                else:
                    break
    print(cnt)

main()

Fixed submission:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

from bisect import bisect_left

def main():
    n = ni()
    l = sorted(na())
    
    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            t = l[i] + l[j]
            ind = bisect_left(l, t)
            ans += max(0, ind - j - 1)
    print(ans)

main()