Buggy python submission (verdict: Time Limit Exceeded):
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
from itertools import combinations
input = lambda: sys.stdin.readline().rstrip()


def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return


def check(a,b,c):
    if a < b + c and b < c + a and c < a + b:
        return True
    else:
        return False


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

    c = list(combinations(Ls, 3))

    cnt = 0
    for i in range(len(c)):
        cnt += check(*c[i])
    print(cnt)
    return

if __name__ == '__main__':
    main()

Fixed submission:
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
from bisect import bisect_right
input = lambda: sys.stdin.readline().rstrip()


def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return


def main():
    n = int(input())
    Ls = list(map(int, input().split()))
    Ls.sort()
    cnt = 0
    for i in range(0,n-2):
        for j in range(i+1,n-1):
            #k以下なら良い
            k =  Ls[i] + Ls[j] -1
            # bisect_right(Ls, k)個の要素が左にある
            # 答え: bisect_right(Ls, k) - j
            cnt += max(bisect_right(Ls, k) - j-1, 0)
            # print(Ls, Ls[i],Ls[j],k, bisect_right(Ls,k)-j-1)
    print(cnt)
            

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
Ls = list(map(int, input().split()))
cnt = 0


def check(a, b, c):
    if a < b+c and b < c + a and c < a + b:
        return True
    else:
        return False


for i in range(n):
    for j in range(i+1, n):
        a = Ls[i]
        b = Ls[j]
        M = [Ls[m] for m in range(j+1, n)]
        if M:
            if a - b >= max(M) or b - a >= max(M) or min(M) >= a + b:
                continue
        for k in range(j+1, n):
            if check(a, b, Ls[k]):
                cnt += 1
print(cnt)


Fixed submission:
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
from bisect import bisect_right
input = lambda: sys.stdin.readline().rstrip()


def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return


def main():
    n = int(input())
    Ls = list(map(int, input().split()))
    Ls.sort()
    cnt = 0
    for i in range(0,n-2):
        for j in range(i+1,n-1):
            #k以下なら良い
            k =  Ls[i] + Ls[j] -1
            # bisect_right(Ls, k)個の要素が左にある
            # 答え: bisect_right(Ls, k) - j
            cnt += max(bisect_right(Ls, k) - j-1, 0)
            # print(Ls, Ls[i],Ls[j],k, bisect_right(Ls,k)-j-1)
    print(cnt)
            

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
Ls = list(map(int, input().split()))
cnt = 0


def check(a, b, c):
    if a < b+c and b < c + a and c < a + b:
        return True
    else:
        return False


for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if check(Ls[i], Ls[j], Ls[k]):
                cnt += 1
print(cnt)


Fixed submission:
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
from bisect import bisect_right
input = lambda: sys.stdin.readline().rstrip()


def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return


def main():
    n = int(input())
    Ls = list(map(int, input().split()))
    Ls.sort()
    cnt = 0
    for i in range(0,n-2):
        for j in range(i+1,n-1):
            #k以下なら良い
            k =  Ls[i] + Ls[j] -1
            # bisect_right(Ls, k)個の要素が左にある
            # 答え: bisect_right(Ls, k) - j
            cnt += max(bisect_right(Ls, k) - j-1, 0)
            # print(Ls, Ls[i],Ls[j],k, bisect_right(Ls,k)-j-1)
    print(cnt)
            

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
Ls = list(map(int, input().split()))
cnt = 0


def check(a, b, c):
    if a < b+c and b < c + a and c < a + b:
        return True
    else:
        return False

for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if check(Ls[i], Ls[j], Ls[k]):
                cnt += 1
print(cnt)


Fixed submission:
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
from bisect import bisect_right
input = lambda: sys.stdin.readline().rstrip()


def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return


def main():
    n = int(input())
    Ls = list(map(int, input().split()))
    Ls.sort()
    cnt = 0
    for i in range(0,n-2):
        for j in range(i+1,n-1):
            #k以下なら良い
            k =  Ls[i] + Ls[j] -1
            # bisect_right(Ls, k)個の要素が左にある
            # 答え: bisect_right(Ls, k) - j
            cnt += max(bisect_right(Ls, k) - j-1, 0)
            # print(Ls, Ls[i],Ls[j],k, bisect_right(Ls,k)-j-1)
    print(cnt)
            

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
Ls = list(map(int, input().split()))
cnt = 0

def check(a, b, c):
    if a < b+c and b < c + a and c < a + b:
        return True
    else:
        return False


for i in range (n):
    a = Ls[i]
    for j in range(i+1, n):
        b = Ls[j]
        for k in range(j+1, n):
            c = Ls[k]
            if check(a, b, c):
                cnt += 1


print(cnt)


Fixed submission:
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
from bisect import bisect_right
input = lambda: sys.stdin.readline().rstrip()


def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return


def main():
    n = int(input())
    Ls = list(map(int, input().split()))
    Ls.sort()
    cnt = 0
    for i in range(0,n-2):
        for j in range(i+1,n-1):
            #k以下なら良い
            k =  Ls[i] + Ls[j] -1
            # bisect_right(Ls, k)個の要素が左にある
            # 答え: bisect_right(Ls, k) - j
            cnt += max(bisect_right(Ls, k) - j-1, 0)
            # print(Ls, Ls[i],Ls[j],k, bisect_right(Ls,k)-j-1)
    print(cnt)
            

if __name__ == '__main__':
    main()