Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
 
n = int(input())
num_list = list(map(int, input().split()))
sum = 0
 
for i in itertools.combinations(num_list, 2):
    x = i[0] * i[1]
    sum += x
    sum %= 10**9 + 7

print(sum)


Fixed submission:
from itertools import accumulate

n = int(input())
a = list(map(int, input().split()))
b = list(accumulate(a))
sum = 0

for i in range(len(a)):
    sum += a[i]*(b[-1] - b[i])
    sum %= 10**9 + 7

print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
 
n = int(input())
num_list = list(map(int, input().split()))
sum = 0
 
for i in itertools.combinations(num_list, 2):
    x = i[0] * i[1]
    if x > 10**9 + 7 :
        x = x % (10**9 + 7)
        sum += x
    else:
        sum += x
        
    if sum > 10**9 + 7:
        sum %= 10**9 + 7

print(sum)

Fixed submission:
from itertools import accumulate

n = int(input())
a = list(map(int, input().split()))
b = list(accumulate(a))
sum = 0

for i in range(len(a)):
    sum += a[i]*(b[-1] - b[i])
    sum %= 10**9 + 7

print(sum)

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

n = int(input())
num_list = list(map(int, input().split()))
sum = 0

for i in itertools.combinations(num_list, 2):
    sum += (i[0] * i[1]) % (10**9 + 7)
    sum % (10**9 + 7)

print(sum % (10**9 + 7))

Fixed submission:
from itertools import accumulate

n = int(input())
a = list(map(int, input().split()))
b = list(accumulate(a))
sum = 0

for i in range(len(a)):
    sum += a[i]*(b[-1] - b[i])
    sum %= 10**9 + 7

print(sum)

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

n = int(input())
num_list = list(map(int, input().split()))
sum = 0

for i in itertools.combinations(num_list, 2):
    sum += (i[0] * i[1]) % (10**9 + 7)

print(sum % (10**9 + 7))

Fixed submission:
from itertools import accumulate

n = int(input())
a = list(map(int, input().split()))
b = list(accumulate(a))
sum = 0

for i in range(len(a)):
    sum += a[i]*(b[-1] - b[i])
    sum %= 10**9 + 7

print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
n = input()
sum = 0

for i in range(len(n)):
    sum += int(n[i]) * 10**(len(n) - i - 1)
  
if sum % 9 == 0:
    print("Yes")
  
else:
    print("No")

Fixed submission:
n = input()
sum = 0

for i in range(len(n)):
    sum += int(n[i]) 
  
if sum % 9 == 0:
    print("Yes")
  
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
p_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
pc_list = []
max_score = -10**9

for m in range(n):
    score = 0
    num = p_list[m] - 1
    for l in range(k):
        score += c_list[num]
        num = p_list[num] - 1
        
        if score > max_score:
            max_score = score
 
print(max_score)

Fixed submission:
weather = input()
rainy_count = 0
max_rainy_count = 0

for i in range(3):
  if weather[i] == "R":
    rainy_count += 1
    if max_rainy_count < rainy_count:
        max_rainy_count = rainy_count
    
  else:
    rainy_count = 0
            
print(max_rainy_count)
Buggy python submission (verdict: Time Limit Exceeded):
x, k, d = map(int, input().split())
x = abs(x)
count = 0

if x - k*d > 0:
    print(x - k*d)

elif x - k*d == 0:
    print(0)

else:
    while x > 0:
        x -= d
        count += 1
    
    if (k - count) % 2 == 0:
        print(abs(x))
    
    else:
        print(x + d)

Fixed submission:
x, k, d = map(int, input().split())
x = abs(x)
count = 0

if x - k*d > 0:
    print(x - k*d)

elif x - k*d == 0:
    print(0)

else:
    count = x//d + 1
    x -= count * d
    
    if (k - count) % 2 == 0:
        print(abs(x))
    
    else:
        print(x + d)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a_list = list(map(int, input().split()))
s1 = len(a_list)
a_set = list(set(a_list))
s2 = len(a_set)
max_cnt = 0

if s1 == 1 :
    max_cnt = 1
elif s1 == 2 :
    if s2 == 1 :
        max_cnt = 2
    else :
        max_cnt = 1
else:
    cnt0 = a_list.count(a_set[0])
    cnt1 = a_list.count(a_set[1])
    
    for i in range(2, len(a_set)):
        cnt2 = a_list.count(a_set[i])
        cnt = cnt0 + cnt1 + cnt2
        
        if cnt > max_cnt :
            max_cnt = cnt
            
        cnt0 = cnt1
        cnt1 = cnt2

print(max_cnt)

Fixed submission:
import collections

n = int(input())
a_list = list(map(int, input().split()))
max_cnt = 0

c = collections.Counter(a_list)

for i in range(max(c.keys()) + 1) :
    cnt = c[i] + c[i + 1] + c[i + 2]
    
    if max_cnt < cnt :
        max_cnt = cnt

print(max_cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_list = list(map(int, input().split()))
a_list = sorted(a_list)
a_set = list(set(a_list))
max_cnt = 0

for i in range(0, len(a_set)):
    cnt = a_list.count(a_set[i]) + a_list.count(a_set[i] - 1) + a_list.count(a_set[i] + 1)
    
    if cnt > max_cnt :
        max_cnt = cnt

print(max_cnt)

Fixed submission:
import collections

n = int(input())
a_list = list(map(int, input().split()))
max_cnt = 0

c = collections.Counter(a_list)

for i in range(max(c.keys()) + 1) :
    cnt = c[i] + c[i + 1] + c[i + 2]
    
    if max_cnt < cnt :
        max_cnt = cnt

print(max_cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_list = list(map(int, input().split()))
a_set = list(set(a_list))
max_cnt = 0

for i in range(0, len(a_set)):
    cnt = a_list.count(a_set[i]) + a_list.count(a_set[i] - 1) + a_list.count(a_set[i] + 1)
    
    if cnt > max_cnt :
        max_cnt = cnt

print(max_cnt)

Fixed submission:
import collections

n = int(input())
a_list = list(map(int, input().split()))
max_cnt = 0

c = collections.Counter(a_list)

for i in range(max(c.keys()) + 1) :
    cnt = c[i] + c[i + 1] + c[i + 2]
    
    if max_cnt < cnt :
        max_cnt = cnt

print(max_cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import math
def main():

    N = int(input())
    cnt = dict()
    for i in range(1, N+1):
        for j in range(1, N+1):
            if i * j < N:
                cnt[i*j] = cnt.get(i*j, 0) + 1
            else:
                break
    ans = 0
    for i in range(1, N):
        if N-i in cnt:
            ans += cnt[N-i]
    return ans


if __name__ == '__main__':
    print(main())

Fixed submission:
import math
def main():

    N = int(input())
    ans = 0
    for i in range(1, N):
        j = N // i
        if i * j == N:
            j -=1
        ans += max(j, 0)
    return ans

if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Time Limit Exceeded):
def main():

    K = int(input())
    S = input()

    mod = pow(10, 9) + 7
    N = len(S)

    g1 = [1, 1]
    g2 = [1, 1]
    inv = [0, 1]

    for i in range(2, K+N+1):
        g1.append((g1[-1] * i) % mod)
        inv.append( ( -inv[mod % i] * (mod//i)) % mod )
        g2.append((g2[-1] * inv[-1]) % mod)

    def combi(n, r):
      r = min(r, n-r)
      return g1[n]*g2[r]*g2[n-r]%mod

    pow25 = [1]
    pow26 = [1]
    for i in range(K):
        pow25.append(pow25[-1] * 25 % mod)
        pow26.append(pow26[-1] * 26 % mod)

    ans = 0
    for i in range(N-1, N+K):
        ans += combi(i, N-1) * pow25[i-N+1] * pow26[K-i+N-1] % mod
        ans %= mod
    return ans

if __name__ == '__main__':
    print(main())

Fixed submission:
def main():

    K = int(input())
    S = input()

    mod = pow(10, 9) + 7
    N = len(S)

    g1 = [1, 1]
    g2 = [1, 1]
    inv = [0, 1]

    for i in range(2, K+N+1):
        g1.append((g1[-1] * i) % mod)
        inv.append( ( -inv[mod % i] * (mod//i)) % mod )
        g2.append((g2[-1] * inv[-1]) % mod)

    def combi(n, r):
      r = min(r, n-r)
      return g1[n]*g2[r]*g2[n-r]%mod

    pow25 = [1]
    pow26 = [1]
    for i in range(K):
        pow25.append(pow25[-1] * 25 % mod)
        pow26.append(pow26[-1] * 26 % mod)

    ans = 0
    for i in range(N-1, N+K):
        ans += combi(i, N-1) * pow25[i-N+1] % mod * pow26[K-i+N-1] % mod
        ans %= mod
    return ans

if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Runtime Error):
def main():

    N = int(input())
    A = list(map(int, input().split()))

    d = dict()
    for v in A:
        d[v] = d.get(v, 0) + 1
    if 1 in d:
        if d[1] == 1: return 1
        else: return 0

    A = list(set(A))
    A.sort()
    s = set()
    ans = 0
    for i in range(N):
        if d[A[i]] == 1:
            if A[i] not in s:
                ans += 1
        k = 1
        while k * A[i] <= A[-1]:
            s.add(k * A[i])
            k += 1

    return ans




if __name__ == '__main__':
    print(main())

Fixed submission:
def main():

    N = int(input())
    A = list(map(int, input().split()))

    d = dict()
    for v in A:
        d[v] = d.get(v, 0) + 1
    if 1 in d:
        if d[1] == 1: return 1
        else: return 0

    A = list(set(A))
    A.sort()
    s = set()
    ans = 0
    for i in range(len(A)):
        if d[A[i]] == 1:
            if A[i] not in s:
                ans += 1
        k = 1
        while k * A[i] <= A[-1]:
            s.add(k * A[i])
            k += 1

    return ans


if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Runtime Error):
import numpy as np
def main():

    A, B = input().split()
    A = np.array(int(A), dtype=np.int64)
    B = np.array(float(B), dtype=np.float64)
    v = A * B
    return int(v)

if __name__ == '__main__':
    print(main())


Fixed submission:
def main():

    A, B = input().split()
    B = "".join(B.split('.'))
    A = int(A)
    B = int(B)
    return (A * B) // 100

if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Runtime Error):
def main():

    A, B = input().split()
    A = int(A)
    B = float(B)
    f = B - int(B)
    v = int(A * f)
    v += int(B) * int(A)
    return v

if __name__ == '__main__':
    print(main())


Fixed submission:
def main():

    N = int(input())
    a, b = [], []
    for _ in range(N):
        A, B = map(int, input().split())
        a.append(A)
        b.append(B)

    a.sort()
    b.sort()

    if N % 2 == 0:
        u = a[N//2-1] + a[N//2]
        v = b[N//2-1] + b[N//2]
        return max((v-u)+1, 0)
    else:
        u = a[(N)//2]
        v = b[(N)//2]
        return max(v-u+1, 0)

if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Time Limit Exceeded):
import collections
def main():

    N, A, B, C = map(int, input().split())

    cur = collections.defaultdict(int)
    cur[(A, B, C)] = ""
    for _ in range(N):
        s = input()
        temp = collections.defaultdict(int)
        for a, b, c in cur:
            if s == "AB":
                if b-1>=0:
                    temp[(a+1, b-1, c)] = cur[(a, b, c)] + 'A'
                if a-1>=0:
                    temp[(a-1, b+1, c)] = cur[(a, b, c)] + 'B'
            elif s == "AC":
                if c-1>=0:
                    temp[(a+1, b, c-1)] = cur[(a, b, c)] + 'A'
                if a-1>=0:
                    temp[(a-1, b, c+1)] = cur[(a, b, c)] + 'C'
            else:
                if b-1>=0:
                    temp[(a, b-1, c+1)] = cur[(a, b, c)] + 'C'
                if c-1>=0:
                    temp[(a, b+1, c-1)] = cur[(a, b, c)] + 'B'
        cur = temp

    if len(cur) > 0:
        print("Yes")
        for v in cur:
            for c in cur[v]:
                print(c)
            break
    else:
        print("No")

if __name__ == '__main__':
    main()

Fixed submission:
import collections
def main():

    N, A, B, C = map(int, input().split())

    ans = ""
    s = []
    for _ in range(N):
        s.append(input())

    d = dict()
    d['A'] = A
    d['B'] = B
    d['C'] = C
    ans = ""
    for i in range(N):
        if d[s[i][0]] == 0 and d[s[i][1]] == 0:
            break
        elif d[s[i][0]] == 0:
            d[s[i][0]] += 1
            d[s[i][1]] -= 1
            ans += s[i][0]
        elif d[s[i][1]] == 0:
            d[s[i][1]] += 1
            d[s[i][0]] -= 1
            ans += s[i][1]
        else:
            if d[s[i][0]] == 1 and d[s[i][1]] == 1 and d['A'] + d['B'] + d['C'] == 2:
                if i < N-1 and s[i] != s[i+1] and s[i][0] in s[i+1]:
                    d[s[i][0]] += 1
                    d[s[i][1]] -= 1
                    ans += s[i][0]
                else:
                    d[s[i][1]] += 1
                    d[s[i][0]] -= 1
                    ans += s[i][1]
            elif d[s[i][0]] < d[s[i][1]]:
                d[s[i][0]] += 1
                d[s[i][1]] -= 1
                ans += s[i][0]
            else:
                d[s[i][1]] += 1
                d[s[i][0]] -= 1
                ans += s[i][1]

    if len(ans) == N:
        print("Yes")
        for c in ans:
            print(c)
    else:
        print("No")

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import collections
def main():

    N, M, Q = map(int, input().split())
    p = collections.defaultdict(int)
    for _ in range(Q):
        a, b, c, d = map(int, input().split())
        p[(a-1, b-1, c)] = d

    lv = [[1]]
    for i in range(M):
        temp = []
        for v in lv:
            for j in range(v[-1], M+1):
                temp.append(v + [j])
        lv = temp

    ans = 0
    for v in lv:
        q = 0
        for a, b, c in p:
            if v[b] - v[a] == c:
                q += p[(a, b, c)]
        ans = max(ans, q)
    return ans



if __name__ == '__main__':
    print(main())


Fixed submission:
import collections
def main():

    N, M, Q = map(int, input().split())
    p = collections.defaultdict(int)
    for _ in range(Q):
        a, b, c, d = map(int, input().split())
        p[(a-1, b-1, c)] = d

    lv = [[1]]
    for i in range(N):
        temp = []
        for v in lv:
            for j in range(v[-1], M+1):
                temp.append(v + [j])
        lv = temp

    ans = 0
    for v in lv:
        q = 0
        for a, b, c in p:
            if v[b] - v[a] == c:
                q += p[(a, b, c)]
        ans = max(ans, q)
    return ans

if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Time Limit Exceeded):
def main():

    S = input()

    rem = [0 for _ in range(2019)]
    ans = 0
    for i in range(len(S)):

        temp = [0 for _ in range(2019)]
        temp[int(S[i])] += 1

        for j in range(2019):
            temp[(j*10 + int(S[i])) % 2019] += rem[j]

        rem = temp
        ans += temp[0]

    return ans


if __name__ == '__main__':
    print(main())


Fixed submission:
def main():

    S = input()
    d = dict()
    d[0] = 1
    v = 0
    p = 1
    for i in range(len(S)):
        v = v + int(S[len(S)-i-1]) * p
        v %= 2019
        d[v] = d.get(v, 0) + 1
        p *= 10
        p %= 2019

    ans = 0
    for v in d:
        ans += d[v] * (d[v] - 1) // 2
    return ans


if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Runtime Error):
def main():

    H, W = map(int, input().split())
    ans = 0
    if W % 2 == 0 and H % 2 == 0:
        return (W//2) * (H//2) + (W//2) * (H//2)
    if W % 2 == 1 and H % 2 == 0:
        return ((W+1)//2) * (H//2) + (W//2) * (H//2)
    if W % 2 == 0 and H % 2 == 1:
        return (W//2) * ((H+1)//2) + (W//2) * (H//2)
    if W % 2 == 1 and H % 2 == 1:
        return ((W+1)//2) * ((H+1)//2) + (W//2) * (H//2)

if __name__ == '__main__':
    print(main())


Fixed submission:

def main():

    N = int(input())
    cur = [['a', set(['a'])]]
    for _ in range(N-1):
        temp = []
        for s, u in cur:
            for c in 'abcdefghij':
                 if c not in u:
                     temp.append([s + c, u | {c}])
                     break
                 else:
                    temp.append([s + c, u])
        cur = temp
    for s, _ in cur:
        print(s)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():

    S = input()
    Q = int(input())
    count = 0
    A = ""
    B = ""
    for _ in range(Q):
        U = input()
        if len(U) == 1:
            count += 1
        else:
            _, F, C = U.split()
            F = int(F)
            if F == 1:
                if count % 2 == 0:
                    A += C
                else:
                    B += C
            else:
                if count % 2 == 0:
                    B += C
                else:
                    A += C

    if count % 2 == 0:
        return A[::-1] + S + B
    else:
        return B[::-1] + S[::-1] + A

if __name__ == '__main__':
    print(main())

Fixed submission:
def main():
    S = input()
    Q = int(input())
    count = 0
    A = []
    B = []
    for _ in range(Q):
        U = input()
        if len(U) == 1:
            count += 1
        else:
            _, F, C = U.split()
            F = int(F)
            if F == 1:
                if count % 2 == 0:
                    A.append(C)
                else:
                    B.append(C)
            else:
                if count % 2 == 0:
                    B.append(C)
                else:
                    A.append(C)

    if count % 2 == 0:
        A = A[::-1]
        return "".join(A) + S + "".join(B)
    else:
        B = B[::-1]
        return "".join(B) + S[::-1] + "".join(A)
        
if __name__ == '__main__':
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
def main():

    S = input()
    Q = int(input())
    count = 0
    left = ""
    right = ""
    for _ in range(Q):
        U = input()
        if len(U) == 1:
            count += 1
            left, right = right[::-1], left[::-1]
        else:
            _, F, C = U.split()
            F = int(F)
            if F == 1:
                left = C + left
            else:
                right = right + C

    if count % 2 == 1:
        S = S[::-1]
    return left + S + right

if __name__ == '__main__':
    print(main())


Fixed submission:
def main():
    S = input()
    Q = int(input())
    count = 0
    A = []
    B = []
    for _ in range(Q):
        U = input()
        if len(U) == 1:
            count += 1
        else:
            _, F, C = U.split()
            F = int(F)
            if F == 1:
                if count % 2 == 0:
                    A.append(C)
                else:
                    B.append(C)
            else:
                if count % 2 == 0:
                    B.append(C)
                else:
                    A.append(C)

    if count % 2 == 0:
        A = A[::-1]
        return "".join(A) + S + "".join(B)
    else:
        B = B[::-1]
        return "".join(B) + S[::-1] + "".join(A)
        
if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Runtime Error):
import math
import collections
def main():

    N = int(input())
    A = list(map(int, input().split()))
    mod = pow(10, 9) + 7

    def primes(n):
        b = [True] * (n//2)
        for i in range(3, int(n**0.5)+1, 2):
            if b[i//2]:
                b[i*i//2::i] = [False] * ((n-i*i-1)//(2*i)+1)

        return [2] + [2*i + 1 for i in range(1, n//2) if b]

    def isprime(n):
        if n == 1: return False
        for i in range(2, int(math.sqrt(n))+1):
            if n % i == 0:
                return False
        return True

    A = sorted(list(set(A)))
    N = len(A)

    ps = primes(int(math.sqrt(max(A))))

    d = dict()
    di = collections.defaultdict(dict)
    for i in range(N):
        if isprime(A[i]):
            if A[i] not in d:
                d[A[i]] = 1
            di[i][A[i]] = 1
        else:
            v = A[i]
            for p in ps:
                if p > v: break
                cnt = 0
                while v > 1 and v % p == 0:
                    cnt += 1
                    v //= p
                if p in d:
                    d[p] = max(d[p], cnt)
                else:
                    d[p] = cnt
                di[i][p] = cnt
            if v > 1:
                di[i][v] = 1
                if v not in d:
                    d[v] = 1

    ans = 0
    for i in range(N):
        b = 1
        for p in d:
            if p in di[i]:
                b *= pow(p, d[p]-di[i][p])
            else:
                b *= pow(p, d[p])
            b %= mod
        ans += b
        ans %= mod

    return ans

if __name__ == '__main__':
    print(main())

Fixed submission:
def main():

    N, M = map(int, input().split())
    if N == M:
        return "Yes"
    return "No"

if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Time Limit Exceeded):
def main():

    N, M, V, P = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort(reverse = True)

    ans = P
    for i in range(P, N):
        v = P * M + (N-1-i-1+1) * M
        for j in range(P-1, i):
            v += min(A[i] + M - A[j], M)
        if v >= M * V:
            ans += 1
    return ans

if __name__ == '__main__':
    print(main())

Fixed submission:
import bisect
def main():

    N, M, V, P = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()

    prefix = [0]
    for i in range(N):
        prefix.append(prefix[-1] + A[i])

    ans = P
    for i in range(N-P):
        if A[i] + M >= A[N-P]:
            v = i * M + P * M
            v += (A[i] + M) * (N-P-i)
            v -= prefix[N-P+1] - prefix[i+1]
            if v >= M * V:
                ans += 1

    return ans

if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Time Limit Exceeded):
import collections
def main():

    N = int(input())
    A = list(map(int, input().split()))
    mod = pow(10, 9) + 7

    ones = [0 for _ in range(60)]

    for i in range(N):
        for j in range(60):
            if (A[i] >> j) % 2 == 1:
                ones[j] += 1
    ans = 0
    for j in range(60):
        ans += pow(2, j) * ones[j] * (N - ones[j])
        ans %= mod

    return ans % mod


if __name__ == '__main__':
    print(main())


Fixed submission:
import collections
def main():

    N = int(input())
    A = list(map(int, input().split()))
    mod = pow(10, 9) + 7

    ones = [0 for _ in range(60)]

    for i in range(N):
        for j in range(60):
            if (A[i] >> j) % 2 == 1:
                ones[j] += 1
    ans = 0
    for j in range(60):
        ans += pow(2, j) * ones[j] * (N - ones[j])
        ans %= mod

    return ans % mod


if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
def main():
 
    N = int(input())
    L = list(map(int, input().split()))
    L.sort()
 
    # print(L)
    ab =[L[0]+L[1]]
    ans = 0
    for i in range(2, N):
        c = L[i]
        j = bisect.bisect_right(ab, c)
        # print(j)
        # print(ab)
        ans += len(ab) - j
        for k in range(i):
            bisect.insort_left(ab, c+L[k])
        # print(ab)
    return ans
 
if __name__ == '__main__':
    print(main())

Fixed submission:
import bisect
def main():

    N = int(input())
    L = list(map(int, input().split()))
    L.sort()

    # print(L)
    ans = 0
    for i in range(N-2):
        for j in range(i+2, N):
            a = L[i]
            c = L[j]
            k = bisect.bisect_left(L, c-a+1)
            if k <= i:
                ans += j-i-1
            else:
                ans += j-k
    return ans

if __name__ == '__main__':
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
def main():

    N = int(input())
    L = list(map(int, input().split()))
    L.sort()

    # print(L)
    ab =[L[0]+L[1]]
    ans = 0
    for i in range(2, N):
        c = L[i]
        j = bisect.bisect_right(ab, c)
        # print(j)
        # print(ab)
        ans += len(ab) - j
        for k in range(i):
            bisect.insort_left(ab, c+L[k])
        # print(ab)
    return ans

if __name__ == '__main__':
    print(main())

Fixed submission:
import bisect
def main():

    N = int(input())
    L = list(map(int, input().split()))
    L.sort()

    # print(L)
    ans = 0
    for i in range(N-2):
        for j in range(i+2, N):
            a = L[i]
            c = L[j]
            k = bisect.bisect_left(L, c-a+1)
            if k <= i:
                ans += j-i-1
            else:
                ans += j-k
    return ans

if __name__ == '__main__':
    print(main())