qyliang/CodeNanoFix huggingface dataset:
Buggy code:

def is_triangle(a, b, c):
    print(a, b, c)
    if a >= b + c:
        return False

    if b >= a + c:
        return False

    if c >= a + b:
        return False

    return True


def main():
    N = int(input())
    L = list([int(x) for x in input().split()])

    L.sort(reverse=True)

    count = 0
    for index, a in enumerate(L):
        if index + 2 == N:
            break

        for b_i in range(index+1, N):
            b = L[b_i]
            c_i = 1

            while not is_triangle(a, b, L[-c_i]):
                if c_i + b_i == N:
                    break
                c_i += 1

            count += (N - b_i - c_i)

    print(count)


if __name__ == '__main__':
    main()


Fixed code:

def is_triangle(a, b, c):
    if a >= b + c:
        return False

    if b >= a + c:
        return False

    if c >= a + b:
        return False

    return True


def main():
    N = int(input())
    L = list([int(x) for x in input().split()])

    L.sort()

    count = 0
    for index, a in enumerate(L):
        if index + 2 == N:
            break

        for b_i in range(index+1, N):
            b = L[b_i]
            c = 1

            while not is_triangle(a, b, L[-c]):
                c += 1

            count += (N - b_i - c)

    print(count)


if __name__ == '__main__':
    main()
Buggy code:
n = int(input())
nums = list(map(int, input().split(' ')))
nums.sort()
total = 0

for i in range(n-1, -1, -1):
    l = 0
    r = i - 1
    while l < r:
        if nums[l] + nums[r] > nums[i]:
            total += 1
            r -= 1
        else:
            l += 1
print(total)

Fixed code:
n = int(input())
nums = list(map(int, input().split(' ')))
nums.sort()
total = 0

for i in range(n-1, -1, -1):
    l = 0
    r = i - 1
    while l < r:
        if nums[l] + nums[r] > nums[i]:
            total += r - l
            r -= 1
        else:
            l += 1
print(total)
Buggy code:
from bisect import bisect
N = int(input())
L = sorted([int(_) for _ in input().split()])
ans = 0
for a in range(N - 2):
    for b in range(a + 1, N - 1):
        #print(bisect(L,L[a]+L[b]-1)-b-1)
        ans += bisect(L, L[a] + L[b] ) - b - 1
print(ans)

Fixed code:
from bisect import bisect
N = int(input())
L = sorted([int(_) for _ in input().split()])
ans = 0
for a in range(N - 2):
    for b in range(a + 1, N - 1):
        #print(bisect(L,L[a]+L[b]-1)-b-1)
        ans += bisect(L, L[a] + L[b] - 1) - b - 1
print(ans)
Buggy code:
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):
        h_min = j
        h_max = N
        while h_max - h_min != 1:
            h_mid = (h_max + h_min) // 2
            if L[i] + L[j] > L[h_mid]:
                h_min = h_mid
            else:
                h_max = h_mid
        cnt += h_mid - j
print(cnt)

Fixed code:
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):
        h_min = j
        h_max = N
        while h_max - h_min != 1:
            h_mid = (h_max + h_min) // 2
            if L[i] + L[j] > L[h_mid]:
                h_min = h_mid
            else:
                h_max = h_mid
        cnt += h_min - j
print(cnt)
Buggy code:
N = int(input())
L = list(map(int,input().split()))
L.sort()

ans=0
for a_idx in range(len(L)):
    a = L[a_idx]
    for b_idx in range(a_idx+1,len(L)):
        b = L[b_idx]
        c_low = b - a + 1
        c_up = a + b - 1
        
        c_low_idx = bisect.bisect(L,c_low)
        c_up_idx = bisect.bisect(L,c_up)
        c_low_idx = max(b_idx,c_low_idx)
        
        ans += max(0,c_up_idx-c_low_idx-1)
#         print(a,b,ans,c_up_idx,c_low_idx)
print(ans)

Fixed code:
import bisect

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

# print(L)

ans=0
for a_idx in range(len(L)):
    a = L[a_idx]
    for b_idx in range(a_idx+1,len(L)):
        b = L[b_idx]
        c_low = b - a
        c_up = a + b - 1
        
        c_low_idx = bisect.bisect(L,c_low)
        c_up_idx = bisect.bisect(L,c_up)
        
#         print('=====')
#         print(a,b)
#         print(c_low_idx,c_up_idx)
        
        c_low_idx = max(b_idx,c_low_idx)
        
        ans += max(0,c_up_idx-c_low_idx-1)
#         print(ans,c_low_idx,c_up_idx)
print(ans)
Buggy code:
import sys
input = sys.stdin.readline
N=int(input())
L=list(map(int,input().split()))
L.sort()
ans=0
for i in range(N-2):
 mid =i+1
 l=0
 r=i+2
 while l<mid-1 or r<N-1:
  if L[r]-L[l]<L[mid]:
   ans+=1
   if r==N-1:
    l+=1
   else:
    r+=1
  else:
   l+=1
 if L[r]-L[l]<L[mid]:
  ans+=1
print(ans)

Fixed code:
import sys
input = sys.stdin.readline
N=int(input())
L=list(map(int,input().split()))
L.sort()
ans=0
for i in range(N-2):
 mid =i+1
 l=0
 r=i+2
 while r<N:
  if L[r]-L[l]<L[mid]:
   ans+=(mid-l)
   r+=1
  else:
   if l==mid-1:
    r+=1
   else:
    l+=1
print(ans)
Buggy code:
import bisect

N = int(input())

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

A.sort()

ans = 0
for a in range(N-2):
    for b in range(a+1, N-1):
        ans += bisect.bisect_left(A, A[a]+A[b])-j-1

print(ans)

Fixed code:
import bisect

N = int(input())

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

A.sort()

ans = 0
for a in range(N-2):
    for b in range(a+1, N-1):
        ans += bisect.bisect_left(A, A[a]+A[b])-b-1

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

print(count)


Fixed code:
from bisect import bisect_left,bisect_right
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 += max(bisect_right(L,L[i]+L[j]-1)-j-1,0)

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

print(ans)

Fixed code:
import bisect
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans =0
for i in range(1,n):
    for j in range(i):
        p = l[i]+ l[j]
        q = bisect.bisect_left(l,p)
        ans += q-i-1

print(ans)
Buggy code:
from bisect import bisect_left

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

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

Fixed code:
from itertools import combinations
from bisect import bisect_left

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

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

L.sort()
result=0
for i in range(N-2):
    for j in range(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()
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)
Buggy code:
N=int(input())
S=list(map(int,input().split( )))
S = sorted(S,reverse=True)
tri_num=0
for i in range(N-2):
    j = i+1
    k = N-1
    while k > j:
        if S[i] <= S[j] + S[k]:
            tri_num += k-j
            j+=1
        else:
            k-=1
print(tri_num)


Fixed code:
N=int(input())
S=list(map(int,input().split( )))
S = sorted(S,reverse=True)
tri_num=0
for i in range(N-2):
    j = i+1
    k = N-1
    while k > j:
        if S[i] < S[j] + S[k]:
            tri_num += k-j
            j+=1
        else:
            k-=1
print(tri_num)
Buggy code:
N=int(input())
S=list(map(int,input().split( )))
S = sorted(S)
tri_num=0
for i in range(N-2):
    k=i+2
    for j in range(i+1,N-1):
        while k < N:
            if S[i] + S[j] <= S[k]:
                tri_sum = tri_sum + k-j-1
                k+=1
                break
            else:
                k+=1
print(tri_num)


Fixed code:
N=int(input())
S=list(map(int,input().split( )))
S = sorted(S)
tri_num=0
for i in range(N-2):
    k = i+2
    for j in range(i+1,N-1):
        while k < N:
            if S[i] + S[j] <= S[k]:
                tri_num = tri_num + k-j-1
                if k == i+2:
                    k+=1
                break
            if k == N-1:
                tri_num = tri_num + k-j
                break
            k+=1
print(tri_num)
Buggy code:
rom bisect import bisect_left
from itertools import combinations

n = int(input())
l = sorted(map(int, input().split()))
ans = 0

for (i1, a), (i2, b) in combinations(enumerate(l[:-1]), 2):
    i3s = i2 + 1
    i3e = bisect_left(l, a + b, i3s)
    ans += i3e - i3s

print(ans)

Fixed code:
from bisect import bisect_left, bisect_right
from itertools import combinations

n = int(input())
l = sorted(map(int, input().split()))
ans = 0

for l1, l2 in combinations(enumerate(l[:-1]), 2):
    (i1, a), (i2, b) = l1, l2
    i3s = bisect_right(l, b - a, i2 + 1)
    i3e = bisect_left(l, a + b, i3s)
    ans += i3e - i3s

print(ans)
Buggy code:
import bisect
n=int(input())
l=list(map(int,input().split()))
cnt=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)
    cnt+=(k-j-1)
print(cnt)
    

Fixed code:
import bisect
n=int(input())
l=list(map(int,input().split()))
l.sort()
cnt=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)
    cnt+=(k-j-1)
print(cnt)
Buggy code:
import bisect

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

Llist.sort()
print(Llist)

count = 0

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

print(count)

Fixed code:
import bisect

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

Llist.sort()

count = 0

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

print(count)
Buggy code:
from sys import stdin

def main():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    # print(l)
    ans = 0
    for i in range(len(l)-2):
        first = l[i]
        for j in range(i + 2, len(l)):
            second = l[j]
            s = i + 1
            e = j 
            # print("start",s, e)
            while(True):
                mid = int((s + e) / 2)
                # print("S",s, e, mid)
                
                if s == e:
                    break
                else:
                    if second >= first + l[mid]:
                        if s == mid:
                            s = e
                        else:
                            s = mid
                    else:
                        e = mid
            # print(s)
            ans += j - s
            print("ans", ans)
    print(ans)
if __name__ == '__main__':
    main()

Fixed code:
from sys import stdin
 
def main():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    # print(l)
    ans = 0
    for i in range(len(l)-2):
        first = l[i]
        for j in range(i + 2, len(l)):
            second = l[j]
            s = i + 1
            e = j 
            # print("start",s, e)
            while(True):
                mid = int((s + e) / 2)
                # print("S",s, e, mid)
                
                if s == e:
                    break
                else:
                    if second >= first + l[mid]:
                        if s == mid:
                            s = e
                        else:
                            s = mid
                    else:
                        e = mid
            # print(s)
            ans += j - s
            # print("ans", ans)
    print(ans)
if __name__ == '__main__':
    main()
Buggy code:
from bisect import bisect_left

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

ans = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    min_sum = L[i]+L[j]-1
    more_than = bisect_left(L[j+1:], min_sum)
    ans += more_than
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):
        ans += bisect_left(L, L[i]+L[j])-j-1
print(ans)
Buggy code:
from bisect import bisect

n = int(input())
l = list(map(int, input().split()))
l.sort()
triangle = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    index = bisect(l, l[i] + l[j], j + 1, n)
    triangle += n - index
print(triangle)

Fixed code:
from bisect import bisect_left

n = int(input())
l = list(map(int, input().split()))
l.sort()
triangle = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    index = bisect_left(l, l[i] + l[j], j + 1, n) - 1
    triangle += index - j
print(triangle)
Buggy code:
n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr)
ans=0
for i in range(n):
  a=arr[i]
  for j in range(i+1,n):
    b=arr[j]
    tmp=a+b
    pos=bisect.bisect_left(arr,tmp)-1
    if pos<=j:
      continue
    else:
      ans+=(pos-j)
print(ans)

Fixed code:
import bisect

n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr)
ans=0
for i in range(n):
  a=arr[i]
  for j in range(i+1,n):
    b=arr[j]
    tmp=a+b
    pos=bisect.bisect_left(arr,tmp)-1
    if pos<=j:
      continue
    else:
      ans+=(pos-j)
print(ans)
Buggy code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Ls = list(mapint())
Ls.sort()

from bisect import bisect_right
ans = 0

for i in range(N-2):
    for j in range(i+1, N-1):
        idx = bisect_right(Ls, Ls[i]+Ls[j])
        ans += idx-j-1

print(ans)

Fixed code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Ls = list(mapint())
Ls.sort()

from bisect import bisect_left
ans = 0

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

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

import bisect
L=sorted(L)
comb = 0
for a in range(N-2):
    for b in range(1+a,N-1):
        posIndex = bisect.bisect_left(L, L[a] + L[b])
        comb += N - posIndex if posIndex != 0 else 0
print(comb)

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

import bisect
L=sorted(L)
comb = 0
for a in range(N-2):
    for b in range(1+a,N-1):
        posIndex = bisect.bisect_left(L, L[a] + L[b])
        comb += posIndex - b - 1 if posIndex != 0 else 0
print(comb)
Buggy code:
import bisect

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

L.sort()

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


Fixed code:
import bisect

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

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

L.sort(reverse=True)

print(L)
for i in range(N):
    L[i] *= -1
count = 0
for i in range(N-2):
    #print(i)
    for j in range(i+1, N-1):
        if -L[i] >= -L[j] * 2:
            break
        data = L[i] - L[j]
        #print(data, L[j + 1 : N])
        #print(bisect.bisect_left(L[j + 1 : N], data))
        count += bisect.bisect_left(L[j + 1 : N], data)

print(count)

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

L.sort(reverse=True)

#print(L)
for i in range(N):
    L[i] *= -1
count = 0
for i in range(N-2):
    #print(i)
    for j in range(i+1, N-1):
        if -L[i] >= -L[j] * 2:
            break
        data = L[i] - L[j]
        #print(data, L[j + 1 : N])
        #print(bisect.bisect_left(L[j + 1 : N], data))
        count += bisect.bisect_left(L, data) - (j+1)

print(count)
Buggy code:
import bisect

n = int(input())
d = list(map(int, input().split()))
d.sort()

m = 0

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

print(m)

Fixed code:
import bisect

n = int(input())
d = list(map(int, input().split()))
d.sort()

m = 0

for a in range(n-2):
	for b in range(a+1,n-1):
		m+=bisect.bisect_left(d,d[a]+d[b])-1-b

print(m)
Buggy code:
def triangles(a): 
    n = len(a) 
    a.sort() 
    count = 0
    print(a)
    for i in range(0,n-2):
        for j in range(i+1,n): 
            k=j+1
            while (k < n and a[i] + a[j] > a[k]): 
                k += 1
            if(k>j): 
                count += k - j - 1
    return count
n=int(input())
a=list(map(int,input().split()))
print(triangles(a))


Fixed code:
def triangles(a): 
    n = len(a) 
    a.sort() 
    count = 0
    for i in range(0,n-2):
        k=i+2
        for j in range(i+1,n): 
            while (k < n and a[i] + a[j] > a[k]): 
                k += 1
            if(k>j): 
                count += k - j - 1
    return count
n=int(input())
a=list(map(int,input().split()))
print(triangles(a))
Buggy code:
import bisect

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


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

print(count)
            
            








    




Fixed code:
import bisect

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


for i in range(n):
    for j in range(i+1,n):
        k=l[i]+l[j]-1
        index = bisect.bisect_right(l,k,lo=j+1)
        count+=index-j-1
        

print(count)
Buggy code:
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
sort_l = sorted(l)
count = 0

for a in range(n-1):
    for b in range(i+1, n):
        c = bisect_left(sort_l, sort_l[a] + sort_l[b])
        if c > b:
            count += c - b -1
        else:
            pass     
        

print(count)



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

for a in range(n):
    for b in range(a+1, n):
        c = bisect.bisect_left(sort_l, sort_l[a] + sort_l[b])
        if c > b:
            count += c - b -1
        else:
            pass     
        

print(count)
Buggy code:
N = int(input())
A = list(map(int, input().split()))
from bisect import bisect_left
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        ans += bisect_left(A, A[i] + A[j]) - bisect_left(A, A[j]) - 1
print(ans)

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

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


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

cnt=0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        p=bisect.bisect_right(l,l[i]+l[j]-1)
        cnt+=max(p-j-1,0)
print(cnt)
Buggy code:
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):
    x=j+1
    y=n-1
    while y!=x:
      if L[i]+L[j]>L[(x+y)//2]:
        x=(x+y)//2
      else:
        y=(x+y)//2
    p=y if L[i]+L[j]>L[y] else x
    if L[i]+L[j]<=L[p]:
      count+=0
    else:
      count+=p-j
print(count)

Fixed code:
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):
    x=j+1
    y=n-1
    while y!=x+1 and y!=x:
      if L[i]+L[j]>L[(x+y)//2]:
        x=(x+y)//2
      else:
        y=(x+y)//2
    p=y if L[i]+L[j]>L[y] else x
    if L[i]+L[j]<=L[p]:
      count+=0
    else:
      count+=p-j
print(count)
Buggy code:
import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()

cnt = 0

print(l)
for i in range(n - 1, 0, -1):
    for j in range(i - 1, -1, -1):
        base = l[i] - l[j]
        idx = bisect.bisect_right(l, base)
        cnt += max(j - idx, 0)
print(cnt)




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

cnt = 0

for i in range(n - 1, 0, -1):
    for j in range(i - 1, -1, -1):
        base = l[i] - l[j]
        idx = bisect.bisect_right(l, base)
        cnt += max(j - idx, 0)
print(cnt)
Buggy code:
import sys
inputs = sys.stdin.readlines()
n = int(inputs[0])
L = list(map(int, inputs[1].split())
A = sorted(L)

ans = 0
for i in range(n-1, 0, -1):
    l, r = 0, i-1
    while l < r:
        if A[i] < A[l] + A[r]:
            ans += r-l
            r -= 1
        else:
            l += 1

print(ans)

Fixed code:
import sys
inputs = sys.stdin.readlines()
n = int(inputs[0])
L = list(map(int, inputs[1].split()))
A = sorted(L)
 
ans = 0
for i in range(n-1, 0, -1):
    l, r = 0, i-1
    while l < r:
        if A[i] < A[l] + A[r]:
            ans += r-l
            r -= 1
        else:
            l += 1

print(ans)
Buggy code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
import bisect
for i in range(n):
    for j in range(n):
        if i<j:
            a=l[i]
            b=l[j]
            x=bisect.bisect_left(l,a+b)
            y=bisect.bisect_right(l,b-a)
            if b-a>a:
                ans+=max(0,x-y-2)
            else:
                ans+=max(0,x-y-1)
print(ans//3)


Fixed code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
import bisect
for i in range(n):
    for j in range(n):
        if i<j:
            a=l[i]
            b=l[j]
            x=bisect.bisect_left(l,a+b)
            y=bisect.bisect_right(l,b-a)
            if b-a>=a:
                ans+=max(0,x-y-1)
            else:
                ans+=max(0,x-y-2)
print(ans//3)
Buggy code:
import bisect

N = int(input())
L = sorted([int(n) for n in input().split()])
#print(L)

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

print(count)

Fixed code:
import bisect

N = int(input())
L = sorted([int(n) for n in input().split()])
#print(L)

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

print(count)
Buggy code:
n=int(input())
L=list(map(int, input().split()))
L.sort()
count = 0
for a in range(n-2):
  for b in range(a+1,n-1):
    count += bisect_left(L, L[a]+L[b]) - b - 1

print(count)

Fixed code:
from bisect import bisect_left
n=int(input())
L=list(map(int, input().split()))
L.sort()
count = 0
for a in range(n-2):
  for b in range(a+1,n-1):
    count += bisect_left(L, L[a]+L[b]) - b - 1

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

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

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

total = 0
for a in range(n-2):
    for b in range(a+1, n-1):
        c = bisect.bisect_left(l, l[a] + l[b]) - b - 1
        total += c

print(total)

Fixed code:
import bisect

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

total = 0
for a in range(n-2):
    for b in range(a+1, n-1):
        c = bisect.bisect_left(l, l[a] + l[b]) - b - 1
        total += c

print(total)