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

N = int(input())
Lmat = [int(n) for n in input().split()]
Lmat.sort()

sum = 0
for i in range(N):
    for j in range(i+1,N):
        min_index = j
        max_index = bisect_left(Lmat, Lmat[i]+Lmat[j])
        sum+= bisect_left(Lmat, Lmat[i]+Lmat[j]) - j - 1
print(sum)


Fixed submission:
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 python submission (verdict: Time Limit Exceeded):
import itertools
from bisect import bisect_left

N = int(input())
Lmat = [int(n) for n in input().split()]
Lmat.sort()

def iftriangle(first,second,third):
    if third < len(Lmat):
        if Lmat[first]>=Lmat[second]+Lmat[third]:
            return 0
        elif Lmat[second]>=Lmat[first]+Lmat[third]:
            return 0
        elif Lmat[third]>=Lmat[first]+Lmat[second]:
            return 0
        else:
            #print([first,second,third])
            return 1
    else:
        return 0

sum = 0
for i in range(N):
    for j in range(i+1,N):
        min_index = j
        max_index = bisect_left(Lmat, Lmat[i]+Lmat[j])
        sum+= bisect_left(Lmat, Lmat[i]+Lmat[j]) - j - 1
        """
        #print(binary_search_nearest(Lmat, Lmat[patern[0]]+Lmat[patern[1]]))#これだとjustの値しか取得できない=>bs自体を実装する必要がある)
        for Lk_index in range(min_index+1,max_index+1):
            sum += iftriangle(i,j,Lk_index)#ここは1に置き換え不可。計算が必要
        """

print(sum)

#elapsed_time = time.time() - start
#print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")



Fixed submission:
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 python submission (verdict: Time Limit Exceeded):
import itertools

N = int(input())
Lmat = [int(n) for n in input().split()]
Lmat.sort()

import time
start = time.time()

def binary_search_nearest(list, item):#もっとも近い値のindexをbsで探して返す関数
    low = 0
    high = len(list) - 1
    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 low-1

def iftriangle(first,second,third):
    if third < len(Lmat):
        if Lmat[first]>=Lmat[second]+Lmat[third]:
            return 0
        elif Lmat[second]>=Lmat[first]+Lmat[third]:
            return 0
        elif Lmat[third]>=Lmat[first]+Lmat[second]:
            return 0
        else:
            #print([first,second,third])
            return 1
    else:
        return 0

sum = 0
for i in range(N):
    for j in range(i+1,N):
        min_index = j
        max_index = binary_search_nearest(Lmat, Lmat[i]+Lmat[j])#これだとjustの値しか取得できない=>bs自体を実装する必要がある
        #print(binary_search_nearest(Lmat, Lmat[patern[0]]+Lmat[patern[1]]))#これだとjustの値しか取得できない=>bs自体を実装する必要がある)
        for Lk_index in range(min_index+1,max_index+1):
            sum += iftriangle(i,j,Lk_index)#ここは1に置き換え不可。計算が必要


print(sum)

elapsed_time = time.time() - start
#print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")



Fixed submission:
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 python submission (verdict: Time Limit Exceeded):
import itertools

N = int(input())
Lmat = [int(n) for n in input().split()]
Lmat.sort()

def binary_search_nearest(list, item):#もっとも近い値のindexをbsで探して返す関数
    low = 0
    high = len(list) - 1
    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 low-1

def iftriangle(first,second,third):
    if third < len(Lmat):
        if Lmat[first]>=Lmat[second]+Lmat[third]:
            return 0
        elif Lmat[second]>=Lmat[first]+Lmat[third]:
            return 0
        elif Lmat[third]>=Lmat[first]+Lmat[second]:
            return 0
        else:
            #print([first,second,third])
            return 1
    else:
        return 0

N2patern = list(itertools.combinations(range(N), 2)) #大小関係はこの時点で決まってしまう(小、大)のペアが出てくる

sum = 0
for patern in N2patern:
    #print("hoge")
    min_index = patern[1]
    max_index = binary_search_nearest(Lmat, Lmat[patern[0]]+Lmat[patern[1]])#これだとjustの値しか取得できない=>bs自体を実装する必要がある
    #print(binary_search_nearest(Lmat, Lmat[patern[0]]+Lmat[patern[1]]))#これだとjustの値しか取得できない=>bs自体を実装する必要がある)
    for Lk_index in range(min_index+1,max_index+1):
        sum += iftriangle(patern[0],patern[1],Lk_index)

print(sum)


Fixed submission:
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 python submission (verdict: Time Limit Exceeded):
import itertools
N = int(input())
Lmat = input().split()
Lmatint = []
for i in range(len(Lmat)):
    Lmatint.append(int(Lmat[i]))
#全パターン選ぶ
allpatern = list(itertools.combinations(range(N), 3))
sum = 0
def iftriangle(first,second,third):
    if Lmatint[first]>=Lmatint[second]+Lmatint[third]:
        return 0
    elif Lmatint[second]>=Lmatint[first]+Lmatint[third]:
        return 0
    elif Lmatint[third]>=Lmatint[first]+Lmatint[second]:
        return 0
    else:
        return 1
for patern in allpatern:
    first = patern[0]
    second = patern[1]
    third = patern[2]
    sum += iftriangle(first,second,third)
print(sum)


Fixed submission:
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)