Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = [int(i) for i in input().split()]
L.sort()

def bisecsearch(l,t,lo,hi):
  while lo < hi:
    mid = (lo+hi)//2
    if l[mid] < t:
      lo = mid + 1
    else:
      hi = mid
  return lo

cnt = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    t = L[i]+L[j]
    k = bisecsearch(L,t,j+1,N)
    cnt += max(0,k-j-1)
print(cnt)

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

from bisect import bisect_left 
cnt = 0
for i in range(0,N):
  for j in range(i+1,N):
    t = L[i]+L[j]
    idx = bisect_left(L,t)
    cnt += max(0,idx-j-1)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))
L.sort()
 
from bisect import bisect_left 
cnt = 0
for i in range(0,N-2):
  for j in range(i+1,N-1):
    t = L[i]+L[j]
    idx = bisect_left(L,t,lo=j+1)
    cnt += max(0,idx-j-1)
print(cnt)

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

from bisect import bisect_left 
cnt = 0
for i in range(0,N):
  for j in range(i+1,N):
    t = L[i]+L[j]
    idx = bisect_left(L,t)
    cnt += max(0,idx-j-1)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
 
N = int(input())
L = list(map(int, input().split()))
L.sort()
 
cnt = 0
for i in range(0,N-2):
  for j in range(i+1,N-1):
    t = L[i]+L[j]
    idx = bisect_left(L,t,lo=j+1)
    cnt += max(0,idx-j-1)
print(cnt)

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

from bisect import bisect_left 
cnt = 0
for i in range(0,N):
  for j in range(i+1,N):
    t = L[i]+L[j]
    idx = bisect_left(L,t)
    cnt += max(0,idx-j-1)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
 
N = int(input())
L = list(map(int, input().split()))
L.sort()
 
cnt = 0
for i in range(0,N-2):
  for j in range(i+1,N-1):
    t = L[i]+L[j]
    idx = bisect_left(L,t,lo=j)
    cnt += max(0,idx-j-1)
print(cnt)

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

from bisect import bisect_left 
cnt = 0
for i in range(0,N):
  for j in range(i+1,N):
    t = L[i]+L[j]
    idx = bisect_left(L,t)
    cnt += max(0,idx-j-1)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

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

cnt = 0
for i in range(0,N-2):
  for j in range(i+1,N-1):
    t = L[i]+L[j]
    idx = bisect_left(L,t,lo=j+1)
    cnt += max(0,idx-j-1)
print(cnt)

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

from bisect import bisect_left 
cnt = 0
for i in range(0,N):
  for j in range(i+1,N):
    t = L[i]+L[j]
    idx = bisect_left(L,t)
    cnt += max(0,idx-j-1)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
 
N = int(input())
L = [int(i) for i in input().split()]
L.sort()
 
cnt = 0
for i in range(0,N):
  for j in range(i+1,N):
    t = L[i]+L[j]
    idx = bisect_left(L,t,lo=j+1)
    cnt += max(0,idx-j-1)
print(cnt)

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

from bisect import bisect_left 
cnt = 0
for i in range(0,N):
  for j in range(i+1,N):
    t = L[i]+L[j]
    idx = bisect_left(L,t)
    cnt += max(0,idx-j-1)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = [int(i) for i in input().split()]
L.sort()

def bisecsearch(l,t,lo,hi):
  while lo < hi:
    mid = (lo+hi)//2
    if l[mid] < t:
      lo = mid + 1
    else:
      hi = mid
  return lo

cnt = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    t = L[i]+L[j]
    k = bisecsearch(L,t,j+1,N)
    cnt += max(0,k-j-1)
print(cnt)

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

from bisect import bisect_left 
cnt = 0
for i in range(0,N):
  for j in range(i+1,N):
    t = L[i]+L[j]
    idx = bisect_left(L,t)
    cnt += max(0,idx-j-1)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = [int(i) for i in input().split()]
L.sort()

cnt = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    lo = j+1
    hi = N
    while lo < hi:
      k = (lo+hi)//2
      if L[k] < L[i] + L[j]:
        lo = k + 1
      else:
        hi = k
    cnt += max(0,lo-j-1)
print(cnt)

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

from bisect import bisect_left 
cnt = 0
for i in range(0,N):
  for j in range(i+1,N):
    t = L[i]+L[j]
    idx = bisect_left(L,t)
    cnt += max(0,idx-j-1)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = [int(i) for i in input().split()]

def CheckTriangle(e):
  a,b,c=e
  return(a<b+c)*(b<c+a)*(c<a+b)

d = dict()
for i in range(0,N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      e = tuple(sorted((L[i],L[j],L[k])))
      if CheckTriangle(e):
        d[e] = 1

print(len(d))

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

from bisect import bisect_left 
cnt = 0
for i in range(0,N):
  for j in range(i+1,N):
    t = L[i]+L[j]
    idx = bisect_left(L,t)
    cnt += max(0,idx-j-1)
print(cnt)