qyliang/CodeNanoFix huggingface dataset:
Buggy code:
# coding: utf-8
# Your code here!

N = int(input())
S = input()

print(S)

overlap = 0
for i in range(N-1) : 
    if S[i] == S[i+1] : 
        overlap += 1
print(N-overlap)

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

N = int(input())
S = input()

overlap = 0
for i in range(N-1) : 
    if S[i] == S[i+1] : 
        overlap += 1
print(N-overlap)
Buggy code:
N=int(input())
S=list(input())
p=0


for i in range(N-1):
  if S[i]==S[i+1]:
    N-=1

print(S)

Fixed code:
N=int(input())
S=list(input())
p=0


for i in range(N-1):
  if S[i]==S[i+1]:
    N-=1

print(N)
Buggy code:
N = int(input())
S = input()
cnt = 0

for i in range(N-1):
	if S[i] = S[i+1]:
      	cnt += 1

ret = N - cnt

print(ret)


Fixed code:
N = int(input())
S = input()
cnt = 0

for i in range(N-1):
  if S[i] == S[i+1]:
    cnt += 1
    
print(N - cnt)
Buggy code:
while True:
    n = input()
    s = input()
    n = int(n)
    if(n==len(s)):
         break
    else:
        print("error")

d  = ''

for i in range(0,len(s)-1):
    if s[i]!=s[i+1]:
        d+=s[i]

d += s[len(s)-1]
print(d)


Fixed code:
while True:
    n = input()
    s = input()
    n = int(n)
    if(n==len(s)):
         break
    else:
        print("error")

d  = ''

for i in range(0,len(s)-1):
    if s[i]!=s[i+1]:
        d+=s[i]

d += s[len(s)-1]
print(len(d))
Buggy code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
lt = [n] * (l[n-1] + l[n-2] + 1)
ans = 0
for i in range(l[0]+1):
    lt[i] = 0
length = l[0]
for i in range(1, n):
  if length < l[i]:
    for j in range(length, l[i]+1):
      lt[j] = i
    length = l[i]

for i in range(n):
  for j in range(i+1, n):
    right = l[i]+l[j]
    ans += max(0,  lt[right] - (j+1))
print(ans)

Fixed code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
lt = [n] * (l[n-1] + l[n-2] + 1)
ans = 0
for i in range(l[0]+1):
    lt[i] = 0
length = l[0]
for i in range(1, n):
  if length < l[i]:
    for j in range(length+1, l[i]+1):
      lt[j] = i
    length = l[i]
for i in range(n):
  for j in range(i+1, n):
    right = l[i]+l[j]
    ans += max(0,  lt[right] - (j+1))
print(ans)
Buggy code:
from bisect import bisect
from bisect import bisect_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):
    left = l[j]-l[i]
    right = l[i]+l[j]
    ans += max(0, bisect_left(l, right) - bisect(l,left))
    if left < l[i] < right:
      ans -= 1
    if left < l[j] < right:
      ans -= 1
print(ans)

Fixed code:
from bisect import bisect
from bisect import bisect_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):
    left = l[j]-l[i]
    right = l[i]+l[j]
    ans += max(0, bisect_left(l, right) - max(j+1, bisect(l,left)))
print(ans)
Buggy code:
from bisect import bisect_left
N = int(input())
L = list(map(int, input().split())).sort()
res = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        idx = bisect_left(L[j+1:], L[i]+L[j])
        res += idx
print(res)

Fixed code:
from bisect import bisect_left
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):
        idx = bisect_left(L, L[i]+L[j])
        res += max(0,idx-(j+1))
print(res)
Buggy code:
from bisect import bisect_left
N = input()
t_list = list ( map ( int, ipnut().split() ) )
t_list.sort()

for i in range ( N - 2 ):
  a = t_list[i]
  for j in range ( i + 1, N - 1 ):
    b = t_list[j]
    c = bisect_left ( t_list , a + b)
    ans = c - j - 1
    
print(ans)

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

for i in range ( N - 2 ):
  a = t_list[i]
  for j in range ( i + 1, N - 1 ):
    b = t_list[j]
    c = bisect_left ( t_list , a + b)
    ans += c - j - 1
    
print(ans)
Buggy code:
n=int(input())
cnt=0
l= list(map(int, input().split()))
l.sort(reverse=True)
k=[[0 for i in range(n-2)] for j in range(n-2)]
for i in range(n-2):
    for j in range(i,n-2):
        k[i][j-i]=-l[i+1]-l[j+2]
#print(k)
for i in range(n-1):
    x=i
    while x<n-2:
        cnt+=bisect.bisect_left(k[x],-l[i])
        #print(l[i],bisect.bisect_left(k[x],-l[i]))
        x+=1
print(cnt)

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

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


def sol(n,l):
    import bisect
    l.sort()
    ans = 0
    #print(l)
    for i in range(n-1):
        for j in range(i+1,n):
            ji = l[j]+l[i]
            ind = bisect.bisect_left(l,ji)
            print(i,j,ind,ind-j-1)
            ans += ind-j-1
    return ans


def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int, input().split()))
    print(sol(n,l))

        
if __name__ == "__main__":
    main()


Fixed code:
#n = int(input())
#l = list(map(int, input().split()))

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


def sol(n,l):
    import bisect
    l.sort()
    ans = 0
    #print(l)
    for i in range(n-1):
        for j in range(i+1,n):
            ji = l[j]+l[i]
            ind = bisect.bisect_left(l,ji)
            #print(i,j,ind,ind-j-1)
            ans += ind-j-1
    return ans


def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int, input().split()))
    print(sol(n,l))

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

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

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

    print(ans)

Fixed code:
import bisect

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

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

print(ans)
Buggy code:
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse = True)

def binary(mini,maxi,a,b): #a>b
  if maxi == mini + 1:
    if L[maxi] > a - b:
      return maxi
    elif L[mini] > a - b:
      return mini
    else:
      return False
  elif maxi == mini:
    if L[maxi] > a - b:
      return maxi
    else:
      return False
  else:
    mid = (mini+maxi)//2
    if L[mid] > a - b:
      return binary(mid,maxi,a,b)
    else:
      return binary(mini,mid,a,b)
      
for a in range(0, N-2):
  for b in range(a+1, N-1):
    tmp = binary(b+1, N-1, L[a], L[b])
    if tmp:
      ans += tmp - b
print(ans)

Fixed code:
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse = True)

def binary(mini,maxi,a,b): #a>b
  if maxi == mini + 1:
    if L[maxi] > a - b:
      return maxi
    elif L[mini] > a - b:
      return mini
    else:
      return False
  elif maxi == mini:
    if L[maxi] > a - b:
      return maxi
    else:
      return False
  else:
    mid = (mini+maxi)//2
    if L[mid] > a - b:
      return binary(mid,maxi,a,b)
    else:
      return binary(mini,mid,a,b)
ans = 0
for a in range(0, N-2):
  for b in range(a+1, N-1):
    tmp = binary(b+1, N-1, L[a], L[b])
    if tmp:
      ans += tmp - b
print(ans)
Buggy code:
import bisect

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

ans = 0
for i in range(N-1):
  k = li[i]
  for j in range(i+1, N):
    l = li[j]
    tmp = bisect_left(li, k+l)
    ans += tmp - i -1
    
    
print(ans)

Fixed code:
import bisect

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

ans = 0
for i in range(N-1):
  k = li[i]
  for j in range(i+1, N):
    l = li[j]
    tmp = bisect.bisect_left(li, k+l)
    ans += tmp - j -1
    
    
print(ans)
Buggy code:
from bisect import bisect_right, bisect_left
n = int(input())
l = list(map(int, input().split()))
count = 0
l.sort()
for i in range(n-2):
    for j in range(i+1, n-1):
        count += bisect_left(l, l[i]+l[j]+1) -j -1
print(count)

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

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

for i in range(N-1):
  k = A[i]
  for j in range(i+1, N):
    l = A[j]
    res = bisect.bisect_left(A, k+l)
    ans += res-k-1
    
print(ans)

Fixed code:
import bisect

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

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

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

    print(L)

    cnt = 0
    for i in range(2,N):
        for j in range(i):
            shortest_len = L[i] - L[j] + 1
            index = bisect.bisect_left(L, shortest_len)
            if index < j:
                cnt += j - index
    
    print(cnt)

if __name__ == '__main__':
    solve()


Fixed code:
import bisect

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

    cnt = 0
    for i in range(2,N):
        for j in range(i):
            shortest_len = L[i] - L[j] + 1
            index = bisect.bisect_left(L, shortest_len)
            if index < j:
                cnt += j - index
    
    print(cnt)

if __name__ == '__main__':
    solve()
Buggy code:
from bisect import bisect_left
n=int(input())
l=sorted(list(map(int,input().split())))
ans=0
for i in range(n):
    for j in range(i+1,n):
        r =bisect_left(L,L[i]+L[j])
        ans+=max(r-j-1),0
print(ans)

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


def main():
    n = int(input())
    l = list(int(i) for i in input().split())
    l = sorted(l, reverse=True)

    cnt = 0

    for i in range(n - 2):
        a = l[i]
        for j in range(i + 1, n-1):
            b = l[j]
            cnt += bisect.bisect_right(l, a-b)-(j+1)

    print(cnt)


if __name__ == "__main__":
    main()


Fixed code:
import bisect


def main():
    n = int(input())
    l = sorted(list(int(i) for i in input().split()))

    cnt = 0

    for i in range(n - 2):
        a = l[i]
        for j in range(i + 1, n-1):
            b = l[j]
            cnt += bisect.bisect_left(l, a+b)-(j+1)

    print(cnt)


if __name__ == "__main__":
    main()
Buggy code:
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()
ret = 0
for i in range(0, N-2):
    for j in range(i+1, N-1):
        ret += bisect.bisect(L[j+1:],L[i]+L[j])
print(ret)

Fixed code:
from bisect import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()
ret = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ret += bisect(L,L[i]+L[j]-1)-j-1
print(ret)
Buggy code:
import bisect
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(N):
    for j in range(i+1, N):
        t = L[i] + L[j]
        idx = bisect.bisect_left(L, t)
        ans += max(0, idx-j-1)
        print(i, j, idx, ans)
print(ans)

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

Fixed code:
import bisect
n =int(input())
l =list(map(int, input().split()))
l.sort()
total = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    tmp = bisect.bisect_left(l,l[i]+l[j])
    total += tmp - j - 1
print(total)
Buggy code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

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


# ===CODE===


def main():
    n = ni()
    d = na()

    d.sort()
    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            l = bisect.bisect_right(d, d[i] + d[j])
            ans+=l-j-1
    print(ans)


if __name__ == '__main__':
    main()


Fixed code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

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


# ===CODE===


def main():
    n = ni()
    d = na()

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


if __name__ == '__main__':
    main()
Buggy code:
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
count = 0

for i in range(N-1):
    l = 0
    r = i -1
    while(l< r):
        if (A[l] + A[r] >A[i]):
            count += (r-l)
            r -= 1
        else:
            l += 1
print(count)


Fixed code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
count = 0

for i in range(N-1,0,-1):
    l = 0
    r = i -1
    while(l< r):
        if (A[l] + A[r] >A[i]):
            count += (r-l)
            r -= 1
        else:
            l += 1
print(count)
Buggy code:
from bisect import bisect_left

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

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

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 += max(0, bisect_left(L, L[i]+L[j]) - j - 1)
print(ans)
Buggy code:
import bisect as bi
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+1,n-1):
    ans += (bi.bisect_right(l,l[i]+l[j]))-j-1
    #print(i,j,bi.bisect_right(l,l[i]+l[j])-j)
    #print(ans)
print(ans)

Fixed code:
import bisect as bi
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+1,n-1):
    ans += (bi.bisect_left(l,l[i]+l[j]))-j-1
    #print(i,j,bi.bisect_right(l,l[i]+l[j])-j-1)
    #print(ans)
print(ans)
Buggy code:
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)


print(L)


def f(j, max1, max2):
    L_temp = L[j+1:]
    # print("max1 = ", max1, "max2 = ", max2, L_temp)
    dif = max1 - max2
    left = -1
    right = len(L_temp)
    while right - left != 1:
        temp = (left+right)//2
        if dif < L_temp[temp]:
            left = temp
        else:
            right = temp
    if left != N:
        return left+1
    else:
        return left


ans = 0
max1 = 0
max2 = 0
for i in range(N):
    max1 = L[i]
    for j in range(i+1, N-1):
        max2 = L[j]
        ans += f(j, max1, max2)
        # print("ans = ", ans)
print(ans)


Fixed code:
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)

def f(j, max1, max2):
    L_temp = L[j+1:]
    # print("max1 = ", max1, "max2 = ", max2, L_temp)
    dif = max1 - max2
    left = -1
    right = len(L_temp)
    while right - left != 1:
        temp = (left+right)//2
        if dif < L_temp[temp]:
            left = temp
        else:
            right = temp
    if left != N:
        return left+1
    else:
        return left


ans = 0
max1 = 0
max2 = 0
for i in range(N):
    max1 = L[i]
    for j in range(i+1, N-1):
        max2 = L[j]
        ans += f(j, max1, max2)
        # print("ans = ", ans)
print(ans)
Buggy code:
from sys import stdin
import itertools
import bisect
N = int(stdin.readline().rstrip())
L = [int(x) for x in stdin.readline().rstrip().split()]
L.sort()
ans = 0

for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = l[j]
        k = bisect.bisect_left(L, a+b)
        ans += (k-j-1)
print(ans)

Fixed code:
from sys import stdin
import itertools
import bisect
N = int(stdin.readline().rstrip())
L = [int(x) for x in stdin.readline().rstrip().split()]
L.sort()
ans = 0

for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        k = bisect.bisect_left(L, a+b)
        ans += (k-j-1)
print(ans)
Buggy code:
import bisect
N=int(input())
L=sorted(list(map(int,input().split())))
count=0
for d1 in range(N-2):
    for d2 in range(d1+1,N-1):
        m=bisect.bisect_right(L[d1]+L[d2],l)
        if m>d2:count+=m-d2
print(count)


Fixed code:
import bisect
N=int(input())
L=sorted(list(map(int,input().split())))
count=0
for d1 in range(N-2):
    for d2 in range(d1+1,N-1):
        m=bisect.bisect_left(L,L[d1]+L[d2])
        if m>d2+1:count+=m-(d2+1)
print(count)
Buggy code:
import bisect
    
N = int(input())
L = sorted(list(map(int, input().split())))
    
ans = 0
for i in range(N):
    for j in range(i+1, N):
        index = bisect.bisect_left(L, L[i]+L[j]+1)
        ans += index - 1 - j
print(ans)

Fixed code:
import bisect
    
N = int(input())
L = sorted(list(map(int, input().split())))
    
ans = 0
for i in range(N):
    for j in range(i+1, N):
        index = bisect.bisect_left(L, L[i]+L[j])
        ans += index - 1 - j
print(ans)
Buggy code:
import sys
input = sys.stdin.readline
# n = int(input())
# l = list(map(int, input().split()))
def main():
  n = 2000
  l = []
  for i in  range(n):
      l.append(1000)
  l.sort()
  l.append(99999999)
  x = 0
  c = 0
  for i in range(n - 2):
      t = i + 2
      for j in range(i + 1, n - 1):
          for k in range(t, n + 1):
              x += 1
              if l[i] + l[j] <= l[k]:
                  x -= 1
                  t = k
                  break
          if t > j: c += t - j - 1
          if j + 1 == t: t += 1
  print(c)
  print(x)
if __name__ == "__main__":
  main()

Fixed code:
import sys
input = sys.stdin.readline
def main():
  n = int(input())
  l = list(map(int, input().split()))
  l.sort()
  l.append(99999999)
  c = 0
  for i in range(n - 2):
      t = i + 2
      for j in range(i + 1, n - 1):
          for k in range(t, n + 1):
              if l[i] + l[j] <= l[k]:
                  t = k
                  break
          if t > j: c += t - j - 1
          if j + 1 == t: t += 1
  print(c)
if __name__ == "__main__":
  main()
Buggy code:
def main():
    N = int(input())
    L = [int(i) for i in input().split()]
    L.sort()
    L_pair = []
    for i in range(N):
        for j in range(i+1, N):
            L_pair.append((i, j))

    def is_ok(mid, i, j):
        if L[mid] < L[i] + L[j]:
            return True
        else:
            return False

    def binary_search_meguru(i, j):
        left = j
        right = N
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid, i, j):
                left = mid
            else:
                right = mid
        return right

    ans = 0
    for i, j in L_pair:
        r = binary_search_meguru(i, j)
        print(i, j, r)
        ans += r - (j + 1)
    print(ans)


if __name__ == '__main__':
    main()


Fixed code:
def main():
    N = int(input())
    L = [int(i) for i in input().split()]
    L.sort()
    L_pair = []
    for i in range(N):
        for j in range(i+1, N):
            L_pair.append((i, j))

    def is_ok(mid, i, j):
        if L[mid] < L[i] + L[j]:
            return True
        else:
            return False

    def binary_search_meguru(i, j):
        left = j
        right = N
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid, i, j):
                left = mid
            else:
                right = mid
        return right

    ans = 0
    for i, j in L_pair:
        r = binary_search_meguru(i, j)
        ans += r - (j + 1)
    print(ans)


if __name__ == '__main__':
    main()
Buggy code:
import bisect
n = int(input())
l_list = list(map(int,input().split()))
ans = 0
for i in range(n):
    for j in range(i+1 , n):
        ans += bisect.bisect_left(l_list,l_list[i] + l_list[j]) -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-2):
    for j in range(i+1 , n-1):
        ans += bisect.bisect_left(l_list,l_list[i] + l_list[j]) -j -1
        
print(ans)
Buggy code:
import bisect

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

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

print(count)


Fixed code:
import bisect
 
N = int(input())
L = map(int, input().split())
L = sorted(L)
 
count = 0
for i in range(N):
  for j in range(i+1, N):
    index = bisect.bisect_left(L, L[i]+L[j])
    count += index - 1 - j

print(count)
Buggy code:
from bisect import bisect_left
N=int(input())
L=list(map(int,input().split()))

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


Fixed code:
from bisect import bisect_left
N=int(input())
L=list(map(int,input().split()))

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

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

# shorter first
# c > b >a
for i in range(0, N-2):
  for j in range(i+1, N-1):
    index = bisect.bisect_left(L, L[i]+L[j])
    count += max(0, index-(j+1))

Fixed code:
import bisect

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

# shorter first
# c > b >a
count = 0
for i in range(0, N-1):
  for j in range(i+1, N):
    index = bisect.bisect_left(L, L[i]+L[j])
    count += max(0, index-(j+1))
print(count)
Buggy code:
import bisect

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

MAX=L[-1]
count=0
for i in range(N-2):
    for  j in range(i+1,N-1):
        # print(i,j)
        # print(L[i+1:-1])
        minInd=j+1
        # print(minInd)
        if L[minInd]> L[i]+L[j]:
            continue
        if MAX<L[i]+L[j]:
            count+=N-1-minInd+1
        else:
            ind = bisect.bisect_right(L[minInd:], L[i]+L[j]) # number of < a+b
            count+=ind
        # print(count)
print(count)


Fixed code:
import bisect

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

MAX=L[-1]
count=0
for i in range(N-2):
    for  j in range(i+1,N-1):
        # print(i,j)
        # print(L[i+1:-1])
        minInd=j+1
        # print(minInd)
        
        if L[minInd]> L[i]+L[j]:
            continue
        if MAX<L[i]+L[j]:
            count+=N-1-minInd+1
        else:
            ind = bisect.bisect_left(L, L[i]+L[j])-minInd # number of < a+b
            count+=ind
        
print(count)
Buggy code:
import bisect

n = int(input())
l = sorted([int(i) for i in input().split()])
ans = 0
for d in range(n):
    for e in range(d+1, n):
        a, b = l[d], l[e]
        idx = bisect.bisect_left(l, a + b)
        ans += max(idx - e - 1,)
print(ans)


Fixed code:
import bisect

n = int(input())
l = sorted([int(i) for i in input().split()])
ans = 0
for d in range(n):
    for e in range(d+1, n):
        a, b = l[d], l[e]
        idx = bisect.bisect_left(l, a + b)
        ans += max(idx - e - 1, 0)
print(ans)