qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import bisect
n = int(input())
l = List(map(int, input().split()))
count = 0
l = sorted(l)

for i in range(n-2):
  for j in range(i+1, n-1):
    k = bisect.bisect_left(l, l[i]+l[j])
    count += k -j - 1
print(count)

Fixed code:
import bisect
n = int(input())
l = list(map(int, input().split()))
count = 0
l = sorted(l)

for i in range(n-2):
  for j in range(i+1, n-1):
    k = bisect.bisect_left(l, l[i]+l[j])
    count += k -j - 1
print(count)
Buggy code:
import time
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)

start = time.time()
res = 0
for i in range(n):
    for j in range(i+1,n):
        ab = l[i] + l[j]
        c_index = bisect_left(l, ab)
        res += c_index - j - 1
print(res)
end = time.time()
print(end-start)


Fixed code:
import time
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)

start = time.time()
res = 0
for i in range(n):
    for j in range(i+1,n):
        ab = l[i] + l[j]
        c_index = bisect_left(l, ab)
        res += c_index - j - 1
print(res)
Buggy code:
#!/usr/bin/env python3

import bisect


def solve(N, L):
    L = sorted(L)
    llen = len(L)
    ans = 0
    for i in range(llen):
        for j in range(i+1, llen):
            n = bisect.bisect_right(L, L[i]+L[j], j+1) - (j+1)
            ans += n
    return ans


if __name__ == '__main__':
    N = int(input())
    L = list(map(int, input().split()))

    ans = solve(N, L)

    print(ans)


Fixed code:
#!/usr/bin/env python3

import bisect


def solve(N, L):
    L = sorted(L)
    llen = len(L)
    # print(L)
    ans = 0
    for i in range(llen):
        for j in range(i+1, llen):
            k = bisect.bisect_left(L, L[i]+L[j], j+1)
            n = k - (j+1)
            # print(i, j, k, n)
            ans += n
    return ans


if __name__ == '__main__':
    N = int(input())
    L = list(map(int, input().split()))

    ans = solve(N, L)

    print(ans)
Buggy code:
import bisect

n = int(input())

in_ar = [0 for _ in range(n)]
in_ar = [int(s) for s in input().split()]
in_ar.sort()
res = 0
#print(in_ar)
for i in range(n):
    for j in range(i,n):
        if(i == j):
            continue

        a = in_ar[i]
        b = in_ar[j]
        st = bisect.bisect_left(in_ar, abs(a-b))
        en = bisect.bisect_right(in_ar, abs(a+b))
        #print(a,b,abs(a-b),abs(a+b),st,en)
        res += en - j - 1
        '''
        if(abs(a-b) < a):
            res -= 1
        if(abs(a-b) < b):
            res -= 1
        '''

print(res)


Fixed code:
import bisect

n = int(input())

in_ar = [0 for _ in range(n)]
in_ar = [int(s) for s in input().split()]
in_ar.sort()
res = 0
#print(in_ar)
for i in range(n):
    for j in range(i,n):
        if(i == j):
            continue

        a = in_ar[i]
        b = in_ar[j]
        st = bisect.bisect_left(in_ar, abs(a-b))
        en = bisect.bisect_left(in_ar, abs(a+b))
        #print(a,b,j,en)
        res += en - j - 1
        '''
        if(abs(a-b) < a):
            res -= 1
        if(abs(a-b) < b):
            res -= 1
        '''

print(res)
Buggy code:
import bisect

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

count = 0
for n in range(N-2):
    for m in range(n+1,N-1):
        count += bisect.bisect_left(L,L[m]-L[n]+1) -m-1

print(count)

Fixed code:
import bisect

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

count = 0
for n in range(N-2):
    for m in range(n+1,N-1):
        count += bisect.bisect_left(L,L[m]+L[n]) -m-1

print(count)
Buggy code:
from sys import stdin
import bisect

N = int(input())
L = list(map(int,stdin.readline().strip().split()))

L.sort()

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        idx = bisect.bisect_left(L,L[i]+L[j]+1)
        ans += (idx-j-1)

print(ans)    


Fixed code:
from sys import stdin
import bisect

N = int(input())
L = list(map(int,stdin.readline().strip().split()))

L.sort()

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        idx = bisect.bisect_left(L,L[i]+L[j],j)
        ans += (idx-j-1)

print(ans)
Buggy code:
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
ans = 0
for i in range(n):
    j = i+1
    k = n
    while w < k:
        if a[i]<a[j]+a[k]:
            ans += k-j
            j += 1
        else:
            k -= 1
print(ans)


Fixed code:
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
ans = 0
for i in range(n-2):
    j = i+1
    k = n-1
    while j < k:
        if l[i]<l[j]+l[k]:
            ans += k-j
            j += 1
        else:
            k -= 1
print(ans)
Buggy code:
import bisect
N = input()
L_list = list(map(int,input().split()))
ans = 0

for i in range(N-1):
  for j in range(i+1,N-1):
    x = bisect.bisect_left(L_list,L_list[i]+L_list[j])
    ans += x-j-1
print(ans)

Fixed code:
import bisect
N = int(input())
L_list = list(map(int,input().split()))
L_list.sort()
ans = 0

for i in range(N-1):
  for j in range(i+1,N-1):
    x = bisect.bisect_left(L_list,L_list[i]+L_list[j])
    ans += x-j-1
print(ans)
Buggy code:
import bisect

N = int(input())
L = sorted([int(x) for x in input().split()])
print(L)
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ab = L[i] + L[j]
        r = bisect.bisect_left(L,ab)
        l = j + 1
        ans += r - l

print(ans)

Fixed code:
import bisect

N = int(input())
L = sorted([int(x) for x in input().split()])
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ab = L[i] + L[j]
        r = bisect.bisect_left(L,ab)
        l = j + 1
        ans += r - l

print(ans)
Buggy code:
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(0,n-2):
  for j in range(i+1,n-1):
    x=l[i]+l[j]
    y=bisect.bisect_left(l,x)-1
    ans+=max((y-j),0)
    
print(ans)    
    

Fixed code:
import bisect
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(0,n-1):
  for j in range(i+1,n):
    x=l[i]+l[j]
    y=bisect.bisect_left(l,x)-1
    ans+=max((y-j),0)
    
print(ans)
Buggy code:
import bisect
N = int(input())
ls = list(map(int,input().split()))
ls.sort()
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ls1 = ls[j+1:]
        ans += bisect.bisect_left(ls1,ls[j]+ls[i]+1)-bisect.bisect(ls1,ls[j]-ls[i]-1)
print(ans)

Fixed code:
import bisect
N = int(input())
ls = list(map(int,input().split()))
ls.sort()
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ls1 = ls[j+1:]
        ans += bisect.bisect_left(ls1,ls[j]+ls[i])-bisect.bisect(ls1,ls[j]-ls[i])
print(ans)
Buggy code:
import bisect

N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
ct = 0

for i in range(N-1):
    a = L[i]
    for j in range(i+1, N):
        b = L[j]
        up_bound = bisect.bisect_right(L, a+b)
        ct += up_bound - (j+1)

print(ct)


Fixed code:
import bisect

N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
ct = 0

for i in range(N-1):
    a = L[i]
    for j in range(i+1, N):
        b = L[j]
        up_bound = bisect.bisect_left(L, a+b)
        ct += max(0, up_bound - (j+1))

print(ct)
Buggy code:
from bisect import bisect_left

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

l.sort()

ans = 0

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

print(ans)


Fixed code:
from bisect import bisect_left

n = int(input())
L = list(map(int, input().split()))

L.sort()
ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        ans += bisect_left(L, L[i] + L[j]) - j - 1

print(ans)
Buggy code:
import bisect
n = int(input())
length = list(map(int, input().split()))
length = sorted(length)
count = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        insert_index = bisect.bisect_left(length, length[i]+length[j])
                   count += insert_index-j               
print(count)

Fixed code:
import bisect
n = int(input())
length = list(map(int, input().split()))
length = sorted(length)
count = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        insert_index = bisect.bisect_left(length, length[i]+length[j])
        count += insert_index-j-1               
print(count)
Buggy code:
from bisect import bisect_left

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

l.sort()
count = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    print(bisect_left(l,l[j]+l[i]),i,j,l)
    count+=bisect_left(l,l[j]+l[i])-j-1
print(count)

Fixed code:
from bisect import bisect_left

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

l.sort()
count = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    count+=bisect_left(l,l[j]+l[i])-j-1
print(count)
Buggy code:
import bisect

n = int(input())
L = sorted(map(int, input().split()))
ans = 0
for i in range(n):
    a = L[i]
    for j in range(i+1, n):
        b = L[j]
        k = bisect.bisect_left(L, a+b)
        print(i, j, k)
        if L[k-1] > b:
            ans += k - j - 1
print(ans)


Fixed code:
import bisect

n = int(input())
L = sorted(map(int, input().split()))
ans = 0
for i in range(n):
    a = L[i]
    for j in range(i+1, n):
        b = L[j]
        k = bisect.bisect_left(L, a+b)
        if k > j:
            ans += k - j - 1
print(ans)
Buggy code:
from bisect import bisect_left
 
n = int(input())
l = list(map(int, input().split())).sort
 
c = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    c += bisect_left(l, l[i]+l[j], j+1)
 
print(c)


Fixed code:
from bisect import bisect_left
 
n = int(input())
l = list(map(int, input().split()))
l.sort()
 
c = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    c += bisect_left(l, l[i]+l[j]) - j - 1
 
print(c)
Buggy code:
N = int(input())
L = list(map(int,input().split()))
import bisect

L.sort()
ans = 0
 
for i in range(N-2):
  for j in range(i+1,N-1):
    ans += bisect.bisect_left(L,L[i]+L[j])
        
print(ans)

Fixed code:
N = int(input())
L = list(map(int,input().split()))
import bisect
 
L.sort()
ans = 0
 
for i in range(N-2):
  for j in range(i+1,N-1):
    ans += bisect.bisect_left(L,L[i]+L[j])-(j+1)
    
print(ans)
Buggy code:
import bisect
n = int(input())
l_list = list(map(int,input().split()))
l_list.sort()
ans = 0
right = 0
print(l_list)
for i in range(n-2):
    for j in range(i+1,n-1):
        right = bisect.bisect_left(l_list[j+1:],l_list[i]+l_list[j])
        # print(right)
        ans += right
        
print(ans)

Fixed code:
import bisect
n = int(input())
l_list = list(map(int,input().split()))
l_list.sort()
ans = 0
right = 0
# print(l_list)
for i in range(n-2):
    for j in range(i+1,n-1):
        right = bisect.bisect_left(l_list[j+1:],l_list[i]+l_list[j])
        # print(right)
        ans += right
        
print(ans)
Buggy code:
import bisect
a = int(input())
l = list(map(int,input().split()))
l.sort()
s = 0
for n,x in enumerate(l):
    for m,y in enumerate(l[n+1:]):
        # print(n+m+2)
        t = x + y
        s += bisect.bisect_right(l[n+m+2:],t)


print(s)

Fixed code:
import bisect
a = int(input())
l = list(map(int,input().split()))
l.sort()
s = 0
for n,x in enumerate(l):
    for m,y in enumerate(l[n+1:]):
        # print(n+m+2)
        t = x + y
        s += bisect.bisect_left(l[n+m+2:],t)


print(s)
Buggy code:
import bisect

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

l.sort()

ans = 0

print(l)
for i in range(n):
    for j in range(i+1, n):
        q = l[i]+l[j]
        p = bisect.bisect_left(l, q)
        ans += (p - j - 1)

print(ans)

Fixed code:
import bisect

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

l.sort()

ans = 0

for i in range(n):
    for j in range(i+1, n):
        q = l[i]+l[j]
        p = bisect.bisect_left(l, q)
        ans += (p - j - 1)

print(ans)
Buggy code:
from bisect import bisect
INF = float("inf")
N = int(input())
L = list(map(lambda x:int(x),input().split())) + [INF]
L.sort()
cnt = 0
print(*L)
for i in range(N-1):
    a = L[i]
    for j in range(i+1,N-1):
        b = L[j]
        c = bisect(L,a+b)
        cnt += c-j-1
print(cnt)

Fixed code:
from bisect import bisect_left
INF = float("inf")
N = int(input())
L = list(map(lambda x:int(x),input().split())) + [INF]
L.sort()
cnt = 0
for i in range(N-1):
    a = L[i]
    for j in range(i+1,N):
        b = L[j]
        c = bisect_left(L,a+b)
        cnt += max(0,c-j-1)
print(cnt)
Buggy code:
import bisect

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

chouhen = set()
kosuu = 0

for i in range(N):
    for j in range(i+1, N):
        a, b = min(L[i], L[j]), max(L[i], L[j])
        chouhen.add((a, b))

L.sort()

print(kosuu)
print(chouhen)
print(L)

for hen in chouhen:
    hidari = max(hen[0] - hen[1], hen[1] - hen[0])
    migi = sum(hen)

    hidari_idx = bisect.bisect_right(L, hidari)
    migi_idx = bisect.bisect_left(L, migi)

    if L[hidari_idx] <= hen[0] <= L[migi_idx - 1]:
        kosuu -= 1
    if L[hidari_idx] <= hen[1] <= L[migi_idx - 1]:
        kosuu -= 1

    kosuu += migi_idx - hidari_idx

    print(hidari, migi, hidari_idx, migi_idx, kosuu)

print(max(0, kosuu // 3))


Fixed code:
import bisect

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

chouhen = []
kosuu = 0

for i in range(N):
    for j in range(i+1, N):
        a, b = min(L[i], L[j]), max(L[i], L[j])
        chouhen.append((a, b))

L.sort()

for hen in chouhen:
    hidari = max(hen[0] - hen[1], hen[1] - hen[0])
    migi = sum(hen)

    hidari_idx = bisect.bisect_right(L, hidari)
    migi_idx = bisect.bisect_left(L, migi)

    # print(hidari, migi, hidari_idx, migi_idx)

    if L[hidari_idx] <= hen[0] <= L[migi_idx - 1]:
        kosuu -= 1
    if L[hidari_idx] <= hen[1] <= L[migi_idx - 1]:
        kosuu -= 1

    kosuu += migi_idx - hidari_idx

print(max(0, kosuu // 3))
Buggy code:
import bisect
N=int(input())
L=list(map(int,input().split()))
L.sort()
#print(L)

#b-a < c < a+b
#a<=b<=c
ans=0
L_a=L[:N-2]
for i,a in enumerate(L_a):
    L_b=L[i+1:N-1]
    for j,b in enumerate(L_b,start=i+1):
        x=bisect.bisect(L[j+1:],a+b)
        ans+=x
print(ans)

Fixed code:
import bisect
import collections
N=int(input())
L=list(map(int,input().split()))
L.sort()
c = collections.Counter(L)
#print(L)
 
#b-a < c < a+b

#a<=b<=c
ans=0
L_a=L[:N-2]
for i,a in enumerate(L_a):
    L_b=L[i+1:N-1]
    for j,b in enumerate(L_b,start=i+1):
        x=bisect.bisect(L[j+1:],a+b)
        ans+=x
        if a+b==L[j+x]:
            #print(a,b,L[j+x])
            ans-=c[a+b]
        #print(i,a,j,b,x,N-j-1,L[j+1:])
print(ans)
Buggy code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
from bisect import bisect_left, bisect_right
n = getN()

nums = getList()
nums.sort()

ans = 0
for i, num1 in enumerate(nums):
    for j , num2 in enumerate(nums[i+1:]):
        tmp = num1 + num2
        idx_min = bisect_left(nums, tmp)
        idx_max = bisect_right(nums, num2 - num1)
        # print(num1, num2, idx_min - idx_max)
        ans += idx_min - idx_max - 2
        if num2 >= num1 * 2:
            ans += 1
# print("=======")
# anss = 0
# for i, n1 in enumerate(nums):
#     for j, n2 in enumerate(nums):
#         for k, n3 in enumerate(nums):
#             if i != j and j != k and k != i:
#                 if n1 < n2 + n3 and n2 < n1 + n3 and n3 < n1 + n2:
#                     print(n1, n2, n3)
#                     anss += 1

print(ans/ 3)
# print(anss/6)

"""
1 2 1  0
1 3 1  0
1 4 1  0
1 5 1  0
2 3 3  234 - 23 > 1 234
2 4 3  345 - 4 > 234, 245 
2 5 2  45 - 5 > 245
3 4 4  2345 - 34 > 234, 345
3 5 3  345 - 35 > 345 
4 5 4  2345 - 45 > 245, 345 
"""

Fixed code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
from bisect import bisect_left, bisect_right
n = getN()

nums = getList()
nums.sort()

ans = 0
for i, num1 in enumerate(nums):
    for j , num2 in enumerate(nums[i+1:]):
        tmp = num1 + num2
        idx_min = bisect_left(nums, tmp)
        idx_max = bisect_right(nums, num2 - num1)
        # print(num1, num2, idx_min - idx_max)
        ans += idx_min - idx_max - 2
        if num2 >= num1 * 2:
            ans += 1
# print("=======")
# anss = 0
# for i, n1 in enumerate(nums):
#     for j, n2 in enumerate(nums):
#         for k, n3 in enumerate(nums):
#             if i != j and j != k and k != i:
#                 if n1 < n2 + n3 and n2 < n1 + n3 and n3 < n1 + n2:
#                     print(n1, n2, n3)
#                     anss += 1

print(ans// 3)
# print(anss/6)

"""
1 2 1  0
1 3 1  0
1 4 1  0
1 5 1  0
2 3 3  234 - 23 > 1 234
2 4 3  345 - 4 > 234, 245 
2 5 2  45 - 5 > 245
3 4 4  2345 - 34 > 234, 345
3 5 3  345 - 35 > 345 
4 5 4  2345 - 45 > 245, 345 
"""
Buggy code:
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def solve():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    res = 0
    for i in range(n):
        for j in range(i+1, n):
            k = bisect.bisect(l, l[i]+l[j])
            res += max(k-(j+1), 0)
    print(res)
    return 0

if __name__ == "__main__":
    solve()

Fixed code:
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def solve():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    res = 0
    for i in range(n):
        for j in range(i+1, n):
            k = bisect.bisect_left(l, l[i]+l[j])
            res += max(k-(j+1), 0)
    print(res)
    return 0

if __name__ == "__main__":
    solve()
Buggy code:
import itertools
import bisect

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

ans = 0

for a,b in itertools.combinations(LS,2):
  a,b = min(a,b),max(a,b)
  lo = b - a
  up = a + b
  
  cnt = bisect.bisect_left(LS,up) - bisect.bisect_right(LS,lo) - 1
  if lo < a:
    cnt -= 1
    
  if cnt <= 0:
    continue
    
  ans += cnt
  
print(cnt)



Fixed code:
import itertools
import bisect

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

ans = 0

for a,b in itertools.combinations(LS,2):
  a,b = min(a,b),max(a,b)
  lo = b - a
  up = a + b
  
  cnt = bisect.bisect_left(LS,up) - bisect.bisect_right(LS,lo) - 1
  if lo < a:
    cnt -= 1
    
  if cnt <= 0:
    continue
    
  ans += cnt
  
print(ans // 3)
Buggy code:
N = int(input())
l = [int(x) for x in input().split()]
l.sort()
def binary_search(list, item):
    low = 0
    high = len(list) - 1
    if item > list[-1]:
        return high
    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid -1
        else:
            low = mid + 1
    return mid-1
ans = 0
for i in range(N-1):
    for j in range(i,N-1):
        ans += max(0,binary_search(l,l[i] + l[j+1]-1)-(j+1))
print(ans)

Fixed code:
N = int(input())
l = [int(x) for x in input().split()]
l.sort()
def binary_search(list, item):
    low = 0
    high = len(list) - 1
    if item > list[-1]:
        return high
    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid -1
        else:
            low = mid + 1
    if list[mid] > item:
        return mid - 1
    else:
        return mid
ans = 0
for i in range(N-1):
    for j in range(i,N-1):
        b = binary_search(l,l[i] + l[j+1]-1)
        while True:
            if b == len(l)-1:
                break
            elif l[b] == l[b+1]:
                b = b+1
            else:
                break
        ans += max(0,b-(j+1))
print(ans)
Buggy code:
from bisect import bisect_left

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):
    ans += bisect_left(L, L[i]+L[j]) - (j + 1)
    print(i,j)
print(ans)

Fixed code:
from bisect import bisect_left

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):
    ans += bisect_left(L, L[i]+L[j]) - (j + 1)

print(ans)
Buggy code:
# coding: utf-8
# Your code here!
import bisect

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):
        insert_index = bisect.bisect_left(l,l[i]+l[j])
        ans+=(insert_index)
        
print(ans)


Fixed code:
# coding: utf-8
# Your code here!
import bisect

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):
        insert_index = bisect.bisect_left(l,l[i]+l[j])
        ans+=(insert_index-j-1)
        
print(ans)
Buggy code:
def biserch(n,List):
    left = 0
    right = len(List)
    while left < right:
        mid = (left+right)//2
        if n < List[mid]:
            right = mid
        else:
            left = mid + 1
    
    return left
    
N = int(input())
L = list(map(int,input().split()))
L.sort()

ans = 0
for i in range(N):
    for j in range(i+1,N):
        key = L[i] + L[j]
        anchor = biserch(key,L)
        
        ans += max(anchor - (j+1),0)

print(ans)

Fixed code:
def biserch(n,List):
    left = 0
    right = len(List)
    while left < right:
        mid = (left+right)//2
        if n <= List[mid]:
            right = mid
        else:
            left = mid + 1
    
    return left
    
N = int(input())
L = list(map(int,input().split()))
L.sort()

ans = 0
for i in range(N):
    for j in range(i+1,N):
        key = L[i] + L[j]
        anchor = biserch(key,L)
        
        ans += max(anchor - (j+1),0)

print(ans)
Buggy code:
import bisect
N = int(input())
lst = list(map(int, input().split()))
lst.sort()
total = 0
for i in range(N-1):
    for j in range(i+1, N-1):
        x = bisect.bisect_right(lst, lst[i]+lst[j])
        print(x)
        total += x-j-1
print(total, lst)

Fixed code:
import bisect
N = int(input())
lst = list(map(int, input().split()))
lst.sort()
total = 0
for i in range(N-1):
    for j in range(i+1, N-1):
        x = bisect.bisect_left(lst, lst[i]+lst[j])
        total += x-j-1
print(total)
Buggy code:
N=int(input())
Edges = list(map(int,input().split()))

Edges=sorted(Edges)
cnt =0
# for i in c:
#     e1=(i[1] + i[2])
#     e2=(i[0] + i[2])
#     e3=(i[0] + i[1])

#     if i[0] < e1 and i[1] < e2 and i[2] < e3:
#         cnt+=1
print(Edges)

import bisect

for a in range(N-2):
    for b in range(a+1,N-1):
        ab = Edges[a] + Edges[b]

        idx = bisect.bisect_left(Edges,ab)

        cnt += max(0,idx-b-1)


print(cnt)

Fixed code:
N=int(input())
Edges = list(map(int,input().split()))

Edges=sorted(Edges)
cnt =0
# for i in c:
#     e1=(i[1] + i[2])
#     e2=(i[0] + i[2])
#     e3=(i[0] + i[1])

#     if i[0] < e1 and i[1] < e2 and i[2] < e3:
#         cnt+=1


import bisect

for a in range(N-2):
    for b in range(a+1,N-1):
        ab = Edges[a] + Edges[b]

        idx = bisect.bisect_left(Edges,ab)

        cnt += max(0,idx-b-1)


print(cnt)
Buggy code:
import bisect
n=int(input())
l=sorted(map(int,input().split()))
ans=0
for i in range(n):
  for j in range(i+1,n):
    idx=bisect.bisect_left(l,l[i]+l[j])
    ans=max(0,idx-j-1)
    
print(ans)

Fixed code:
import bisect
n=int(input())
l=sorted(map(int,input().split()))
ans=0
for i in range(n):
  for j in range(i+1,n):
    idx=bisect.bisect_left(l,l[i]+l[j])
    ans+=max(0,idx-j-1)
    
print(ans)
Buggy code:
import bisect
n = int(input())
l = list(map(int,input().split()))
l.sort()
count = 0
print(l)
for i in range(n-2):
    for j in range(i+1,n-1):
        index = bisect.bisect_right(l,l[i]+l[j],j)
        print(i,j,index)
        count += index-j-1
print(count)

Fixed code:
import bisect
n = int(input())
l = list(map(int,input().split()))
l.sort()
count = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        index = bisect.bisect_left(l,l[i]+l[j],j)
     
        count += index-j-1
print(count)