Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
n,k,l=map(int,input().split())
#union-find
par1=[-1]*(n+1)
par2=[-1]*(n+1)

def find1(x):
    if par1[x]<0:
        return x
    else:
        par1[x]=find1(par1[x])
        return par1[x]
def find2(x):
    if par2[x]<0:
        return x
    else:
        par2[x]=find2(par2[x])
        return par2[x]
def size1(x):
    return -par1[find1(x)]
def size2(x):
    return -par2[find2(x)]
def unite1(x,y):
    if find1(x)==find1(y):
        return False
    else:
        if size1(x)<size1(y):
            x,y=y,x
        X=find1(x)
        Y=find1(y)
        par1[X]-=size1(Y)
        par1[Y]=X
        return True
def unite2(x,y):
    if find2(x)==find2(y):
        return False
    else:
        if size2(x)<size2(y):
            x,y=y,x
        X=find2(x)
        Y=find2(y)
        par2[X]-=size2(Y)
        par2[Y]=X
        return True
def is_same1(x,y):
    return find1(x)==find1(y)
def is_same2(x,y):
    return find2(x)==find2(y)

for _ in range(k):
    p,q=map(int,input().split())
    unite1(p,q)
for _ in range(l):
    r,s=map(int,input().split())
    unite2(r,s)
ans=[0]*(n)
for i in range(1,n+1):
    for j in range(1,n+1):
        if is_same1(i,j) and is_same2(i,j):
            ans[i-1]+=1
print(*ans, sep=' ')

Fixed submission:
from collections import Counter
n,k,l=map(int,input().split())
#union-find
par1=[-1]*(n+1)
par2=[-1]*(n+1)

def find1(x):
    if par1[x]<0:
        return x
    else:
        par1[x]=find1(par1[x])
        return par1[x]
def find2(x):
    if par2[x]<0:
        return x
    else:
        par2[x]=find2(par2[x])
        return par2[x]
def size1(x):
    return -par1[find1(x)]
def size2(x):
    return -par2[find2(x)]
def unite1(x,y):
    if find1(x)==find1(y):
        return False
    else:
        if size1(x)<size1(y):
            x,y=y,x
        X=find1(x)
        Y=find1(y)
        par1[X]-=size1(Y)
        par1[Y]=X
        return True
def unite2(x,y):
    if find2(x)==find2(y):
        return False
    else:
        if size2(x)<size2(y):
            x,y=y,x
        X=find2(x)
        Y=find2(y)
        par2[X]-=size2(Y)
        par2[Y]=X
        return True
def is_same1(x,y):
    return find1(x)==find1(y)
def is_same2(x,y):
    return find2(x)==find2(y)

for _ in range(k):
    p,q=map(int,input().split())
    unite1(p,q)
for _ in range(l):
    r,s=map(int,input().split())
    unite2(r,s)
L=[]
for i in range(1,n+1):
    L.append((find1(i),find2(i)))
kazu=Counter(L)
ans=[0]*(n)
for i in range(n):
    ans[i]=kazu[L[i]]
print(*ans, sep=' ')
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print(len(set(a,b,c)))

Fixed submission:
a,b,c=map(int,input().split())
print(len(set([a,b,c])))
Buggy python submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))

number = [i for i in range(10)]
num_lis = list(set(number) - set(D))
ans=[]
for i in num_lis:
    for j in num_lis:
        for k in num_lis:
            for l in num_lis:
                a = 1000*i + 100 *j + 10*k + l
                if a>=N:
                    ans.append(a)
print(ans[0])

Fixed submission:
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))

number = [i for i in range(10)]
num_lis = list(set(number) - set(D))
ans=[]
for i in range(N, 100000):
    a=i//10000
    if bool((a not in D) or i <10000):
        b=i//1000 - 10*a
        if bool((b not in D) or i <1000):
            c=i//100 - 100 * a - 10 * b
            if bool((c not in D) or i < 100):
                d= i//10 - 1000 * a - 100*b - 10*c
                if bool((d not in D) or i <10):
                    e=i%10
                    if e not in D:
                        ans.append(i)
print(ans[0])

Buggy python submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
number = [i for i in range(10)]
num_lis = list(set(number) - set(D))
ans=[]
for i in num_lis:
    for j in num_lis:
        for k in num_lis:
            for l in num_lis:
                a = 1000*i + 100 *j + 10*k + l
                if a>=N:
                    ans.append(a)
print(ans[0])

Fixed submission:
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))

number = [i for i in range(10)]
num_lis = list(set(number) - set(D))
ans=[]
for i in range(N, 100000):
    a=i//10000
    if bool((a not in D) or i <10000):
        b=i//1000 - 10*a
        if bool((b not in D) or i <1000):
            c=i//100 - 100 * a - 10 * b
            if bool((c not in D) or i < 100):
                d= i//10 - 1000 * a - 100*b - 10*c
                if bool((d not in D) or i <10):
                    e=i%10
                    if e not in D:
                        ans.append(i)
print(ans[0])
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
G=[]
for i in range(0,M):
    G.append([])

for i in range(0,M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

q=[]
sign=[-1]*N
sign[0]=0
q.append(0)
while q:
    x=q.pop(0)
    for nv in G[x]:
        if sign[nv]==-1:
            sign[nv]=x
            q.append(nv)

print("Yes")
for i in range(1,N):
    print(sign[i]+1)


Fixed submission:
N,M=map(int,input().split())
G=[]
for i in range(0,N):
    G.append([])

for i in range(0,M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

q=[]
sign=[-1]*N
sign[0]=0
q.append(0)
while q:
    x=q.pop(0)
    for nv in G[x]:
        if sign[nv]==-1:
            sign[nv]=x
            q.append(nv)

print("Yes")
for i in range(1,N):
    print(sign[i]+1)
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
A=list(map(int,input().split()))

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

count=0
cycle[0]=count
town=0
mod=0
while True:
    count+=1
    K-=1
    town=A[town]
    if K==0:
        break
    if cycle[town]==-1:
        cycle[town]=count
    else:
        mod=count-cycle[town]
        break

K%=mod
while K>0:
    town=A[town]
    K-=1

print(town+1)


Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))

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


for j in range(1,64):
    for i in range(0,N):
        move[i].append(move[move[i][j-1]][j-1])
town=0
for i in range(0,64):
    if K%2==1:
        town=move[town][i]
    K//=2

print(town+1)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
A=list(map(int,input().split()))

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


for j in range(1,64):
    for i in range(0,N):
        move[i].append(move[move[i][j-1]][j-1])
town=0
for i in range(0,64):
    if K%2==1:
        town=move[town][i]
    K//=2

print(town+1)


Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))

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


for j in range(1,64):
    for i in range(0,N):
        move[i].append(move[move[i][j-1]][j-1])
town=0
for i in range(0,64):
    if K%2==1:
        town=move[town][i]
    K//=2

print(town+1)
Buggy python submission (verdict: Time Limit Exceeded):
import math

K=int(input())
ans=0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans+=math.gcd(math.gcd(i,j),k)
print(ans)


Fixed submission:
import math

N=int(input())
ans=0
for i in range(1,N+1):
    for j in range(i,N+1):
        for k in range(j,N+1):
            if i==j and j==k:
                ans+=i
            elif i<j and j<k:
                ans+=6*math.gcd(i,math.gcd(j,k))
            else:
                ans+=3*math.gcd(i,math.gcd(j,k))
print(ans)
Buggy python submission (verdict: Runtime Error):
str=imput()
if(str[0]!=atr[1]||str[1]!=str[2]):
  print("Yes")
else:
  print("No")

Fixed submission:
S=input()
if (S[0]!=S[1])|(S[2]!=S[1]) :
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main(){
  cout<<"Hello"<<endl;
}

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

flag=True
for a in A:
    if a%2==0:
        if (a%3!=0)&(a%5!=0):
            flag=False
            break

if flag:
    print("APPROVED")
else:
    print("DENIED")
Buggy python submission (verdict: Runtime Error):
map(int,input().split())
print(max(A+B,A-B,A*B))


Fixed submission:
A,B=map(int,input().split())
print(max(A+B,A-B,A*B))
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
x=list(map(int,input().split()))
positive=[]
negative=[]
for i in range(N):
    if x[i]<0:
        negative.append(-x[i])
    else:
        positive.append(x[i])
negative.sort()
n=len(negative)
m=len(positive)
ans=1000000000
if n>=K:
    ans=min(ans,negative[K-1])
if m>=K:
    ans=min(ans,positive[K-1])

for i in range(n):
    j=K-(i+1)
    if j<=0:
        continue
    ans=min(ans,negative[i]+positive[j-1]+min(negative[i],positive[j-1]))
print(ans)


Fixed submission:
N,K=map(int,input().split())
x=list(map(int,input().split()))
positive=[]
negative=[]
for i in range(N):
    if x[i]<0:
        negative.append(-x[i])
    else:
        positive.append(x[i])
negative.sort()
n=len(negative)
m=len(positive)
ans=1000000000
if n>=K:
    ans=min(ans,negative[K-1])
if m>=K:
    ans=min(ans,positive[K-1])

for i in range(n):
    j=K-(i+1)
    if j>m:
        continue
    if j<=0:
        continue
    ans=min(ans,negative[i]+positive[j-1]+min(negative[i],positive[j-1]))
print(ans)
Buggy python submission (verdict: Runtime Error):
x,a,b=map(int,input().split())
if abs(x-a)<abs(x-b):
    pirnt('A')
else:
    print('B')


Fixed submission:
x,a,b=map(int,input().split())
if abs(x-a)<abs(x-b):
    print('A')
else:
    print('B')
Buggy python submission (verdict: Runtime Error):
N=int(input())
G=[[] for _ in range(N)]
for _ in range(N-1):
    a,b,c=map(int,input().split())
    a-=1
    b-=1
    G[a].append([b,c])
    G[b].append([a,c])
Q,K=map(int,input().split())
K-=1
dist=[-1 for _ in range(N)]
dist[K]=0
def dfs(G,x,dist):
    for p in G[x]:
        if dist[p[0]]!=-1:
            continue
        dist[p[0]]=dist[x]+p[1]
        dfs(G,p[0],dist)

dfs(G,K,dist)
for _ in range(Q):
    x,y=map(int,input().split())
    print(dist[x-1]+dist[y-1])


Fixed submission:
N=int(input())
G=[[] for _ in range(N)]
for _ in range(N-1):
    a,b,c=map(int,input().split())
    a-=1
    b-=1
    G[a].append([b,c])
    G[b].append([a,c])
Q,K=map(int,input().split())
K-=1
dist=[-1 for _ in range(N)]
dist[K]=0
q=[K]
while len(q)>0:
    v=q.pop()
    for p in G[v]:
        nv=p[0]
        if dist[nv]!=-1:
            continue
        dist[nv]=dist[v]+p[1]
        q.append(nv)
for _ in range(Q):
    x,y=map(int,input().split())
    print(dist[x-1]+dist[y-1])
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a=[int(input())-1 for _ in range(N)]
x=a[0]
ans=1
while x!=0:
    if x==1:
        print(ans)
        break
    ans+=1
    x=a[x]
else:
    print(-1)


Fixed submission:
N=int(input())
a=[int(input())-1 for _ in range(N)]
x=0
ans=0
while True:
    ans+=1
    x=a[x]
    if x==1:
        print(ans)
        break
    if ans>N:
        print(-1)
        break;
Buggy python submission (verdict: Runtime Error):
O=input()
E=inpu()
ans=""
for i in range(len(E)):
  ans+=O[i]
  ans+=E[i]

if len(O)!=len(E):
  ans+=O[-1]
print(ans)

Fixed submission:
O=input()
E=input()
ans=""
for i in range(len(E)):
  ans+=O[i]
  ans+=E[i]

if len(O)!=len(E):
  ans+=O[-1]
print(ans)
Buggy python submission (verdict: Runtime Error):
A=list(map(int,input().split()))
A.sorted()
if A==[5,5,7]:
  print("YES")
else:
  print("NO")
    


Fixed submission:
A=list(map(int,input().split()))
A.sort()
if A==[5,5,7]:
  print("YES")
else:
  print("NO")

Buggy python submission (verdict: Runtime Error):
A=list(map(int,input().split()))
sort(A)
if A==[5,5,7]:
  print("YES")
else:
  print("NO")
    


Fixed submission:
A=list(map(int,input().split()))
A.sort()
if A==[5,5,7]:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
n = int(input())
for a in range(1, 10):
    for b in range(1, 10):
        if n == a * b:
            print('Yes')
            return
print('No')


Fixed submission:
n = int(input())
for a in range(1, 10):
    for b in range(1, 10):
        if n == a * b:
            print('Yes')
            exit()
print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
print(math.ceil(n / 2) / n)


Fixed submission:
import math
n = int(input())
print(math.ceil(n / 2) / n)

Buggy python submission (verdict: Runtime Error):
n = int(input())
print(ceil(n / 2) / n)


Fixed submission:
import math
n = int(input())
print(math.ceil(n / 2) / n)
Buggy python submission (verdict: Runtime Error):
s = input()
for i, c in enumerate(s):
    if i % 2 == 0 and c == 'R':
        yes = False
    elif i % 2 == 1 and c == 'L':
        yes = False
if yes:
    print('Yes')
else:
    print('No')
    


Fixed submission:
s = input()
yes = True
for i, c in enumerate(s):
    if i % 2 == 1 and c == 'R':
        #print(i)
        yes = False
    elif i % 2 == 0 and c == 'L':
        yes = False
        #print(i)
if yes:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
print(max(c - (a - b)), 0)


Fixed submission:
a, b, c = map(int, input().split())
print(max(c - (a - b), 0))
Buggy python submission (verdict: Runtime Error):
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))


    C = [0] * N
    D = [0] * N
    for i in range(N):
        C[A[i]-1] += 1
        D[A[i]-1] += 1
    for i in range(N-1):
        C[i+1] += C[i]
        D[i+1] += D[i]
    
    s = -INF
    for i in range(1,N):
        if s < C[i] - D[i-1]:
            s = C[i] - D[i-1]
    
    ans = " ".join(map(str, B[s+1:] + B[:s+1]))
    print(ans)


if __name__ == '__main__':
    main()

Fixed submission:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))


    C = [0] * (N+1)
    D = [0] * (N+1)
    for i in range(N):
        C[A[i]] += 1
        D[B[i]] += 1
    for i in range(N+1):
        if C[i] + D[i] > N:
            print("No")
            return
    for i in range(N):
        C[i+1] += C[i]
        D[i+1] += D[i]
    
    x = 0
    for i in range(1, N+1):
        if x < C[i] - D[i-1]:
            x = C[i] - D[i-1]
    

    print("Yes")
    for i in range(N):
        if i != 0:
            print(" ", end="")
        print(B[(i+N-x)%N], end="")
    print("")


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    K = int(input())

    if K % 2 == 0:
        print(-1)
        return

    tmp = 7
    ans = 1
    while tmp % K != 0:
        tmp = (tmp % K) * 10 + 7
        ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    K = int(input())

    if K % 2 == 0:
        print(-1)
        return

    tmp = 7
    ans = 1
    while tmp % K != 0:
        tmp = (tmp % K) * 10 + 7
        ans += 1
        if ans >= 10000000:
            print(-1)
            return

    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    score = 1
    for i in range(K):
        score *= A[i]
    
    for i in range(K, N):
        nscore = score * A[i] // A[i-K]
        if nscore > score:
            print("Yes")
        else:
            print("No")
        score = nscore


if __name__ == '__main__':
    main()

Fixed submission:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    
    for i in range(K, N):
        if A[i] > A[i-K]:
            print("Yes")
        else:
            print("No")


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 1
    for a in A:
        ans *= a
    if ans > 1000000000000000000:
        ans = -1
    print(ans)


if __name__ == '__main__':
    main()

Fixed submission:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 1
    if 0 in A:
        ans = 0
    else:
        for a in A:
            ans *= a
            if ans > 1000000000000000000:
                ans = -1
                break
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 1
    for a in A:
        ans *= a
    if ans > pow(10, 18):
        ans = -1
    print(ans)


if __name__ == '__main__':
    main()

Fixed submission:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 1
    if 0 in A:
        ans = 0
    else:
        for a in A:
            ans *= a
            if ans > 1000000000000000000:
                ans = -1
                break
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N = int(input())
    S = input()[:-1]

    res = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            for k in range(j+1, N):
                if S[i] != S[j] and S[j] != S[k] and S[k] != S[i] and j-i != k-j:
                    res += 1
    
    print(res)


if __name__ == '__main__':
    main()

Fixed submission:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N = int(input())
    S = input()[:-1]

    A = [[] for _ in range(3)]
    for i in range(N):
        if S[i:i+1] == "R":
            A[0].append(i)
        if S[i:i+1] == "G":
            A[1].append(i)
        if S[i:i+1] == "B":
            A[2].append(i)

    res = 0
    for P in itertools.permutations(range(3)):
        a = P[0]
        b = P[1]
        c = P[2]
        for i in A[a]:
            x = bisect.bisect_left(A[b], i)
            for j in A[b][x:]:
                res += len(A[c]) - bisect.bisect_left(A[c], j)
    
    for l in range(1, math.ceil(N/2)):
        n = 0
        while n+l*2 < N:
            if S[n] != S[n+l] and S[n+l] != S[n+l*2] and S[n+l*2] != S[n]:
                res -= 1
            n += 1
    
    print(res)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    H, N = map(int, input().split())
    A = [0]*N
    B = [0]*N
    for i in range(N):
        A[i], B[i] = map(int, input().split())
    
    dp = [INF] * 10000100
    dp[0] = 0
    for i in range(H):
        if dp[i] == INF:
            continue
        for n in range(N):
            dp[i+A[n]] = min(dp[i+A[n]], dp[i] + B[n])
    
    ans = INF
    for i in range(H, 10000100):
        ans = min(ans, dp[i])
    print(ans)


if __name__ == '__main__':
    main()

Fixed submission:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    H, N = map(int, input().split())
    A = [0]*N
    B = [0]*N
    for i in range(N):
        A[i], B[i] = map(int, input().split())
    
    dp = [INF] * 10000100
    dp[0] = 0
    for i in range(H):
        if dp[i] == INF:
            continue
        for n in range(N):
            dp[i+A[n]] = min(dp[i+A[n]], dp[i] + B[n])
    
    ans = INF
    for i in range(H, 10000100):
        ans = min(ans, dp[i])
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys
input = sys.stdin.readline


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

    cnt = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            a = L[i]
            b = L[j]
            r = bisect.bisect_left(L, b+a, lo=j+1)
            l = bisect.bisect_right(L, b-a, lo=j+1)
            cnt += r - l
    
    print(cnt)


if __name__ == '__main__':
    main()

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


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

    cnt = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            a = L[i]
            b = L[j]
            r = bisect.bisect_left(L, b+a, lo=j+1)
            l = bisect.bisect_right(L, b-a, lo=j+1)
            cnt += r - l
    
    print(cnt)


if __name__ == '__main__':
    main()