Problem:


Score : 400 points

Problem Statement

Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i.

He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied:

a < b + c

b < c + a

c < a + b

How many different triangles can be formed? Two triangles are considered different when there is a stick used in only one of them.

Constraints

All values in input are integers.

3 \leq N \leq 2 \times 10^3

1 \leq L_i \leq 10^3

Input

Input is given from Standard Input in the following format:

N
L_1 L_2 ... L_N

Constraints

Print the number of different triangles that can be formed.

Sample Input 1

4
3 4 2 1

Sample Output 1

1

Only one triangle can be formed: the triangle formed by the first, second, and third sticks.

Sample Input 2

3
1 1000 1

Sample Output 2

0

No triangles can be formed.

Sample Input 3

7
218 786 704 233 645 728 389

Sample Output 3

23



Sample input:
4
3 4 2 1


Sample output:
1

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [int(i) for i in input().split(" ")]

def meguru_nibutan(ar,m,key):
    a = m
    b = len(ar)
    while(abs(a-b) > 1):
        c = (a+b)//2
        if (ar[c] > key):
            a = c
        else:
            b = c
    return a

def main():
    cnt = 0
    l.sort(reverse=True)
    for a in range(0,n-2):
        for b in range(a+1,n-1):
            cnt += meguru_nibutan(l,b,l[a]-l[b]) - b
    print(cnt)

if (__name__ == "__main__"):
    main()

Submission status: Time Limit Exceeded

Solution code:
def func():
    N = int(input())
    li = sorted(list(map(int, input().split())))
    r = 0
    i, j, k = -1,0,1
    for n1 in li:
        i += 1;
        if i + 3 == N:
            if li[i] + li[i + 1] > li[i + 2]:
                r += 1
            return r
        j = i
        nnn1 = li[i]
        for n2 in li:
            j += 1;
            k = j

            if j + 2 > N:
                break
            nnn2 = li[j]
            for n3 in li:
                k += 1;
                if k + 1 > N:
                    break
                if nnn1 + nnn2 > li[k]:
                    r += 1
                else:
                    break
print(func())

Submission status: Time Limit Exceeded

Solution code:
def func():
    N = int(input())
    li = sorted(list(map(int, input().split())))
    r = 0
    i, j, k = -1,-1,-1
    for n1 in li:
        i += 1;
        if i + 3 == N:
            if li[i] + li[i + 1] > li[i + 2]:
                r += 1
            return r
        j = i
        for n2 in li:
            j += 1;
            k = j

            if j + 2 > N:
                break
            for n3 in li:
                k += 1;
                if k + 1 > N:
                    break
                if li[i] + li[j] > li[k]:
                    r += 1
                else:
                    break
print(func())

Submission status: Time Limit Exceeded

Solution code:
def func():
    N = int(input())
    li = sorted(list(map(int, input().split())))
    r = 0
    i, j, k = -1,-1,-1
    for n1 in li:
        i += 1;
        j = i
        for n2 in li:
            j += 1;
            if j + 1 > N:
                break
            k = j
            for n3 in li:
                k += 1;
                if k + 1 > N:
                    break
                if i + 3 == N:
                    if li[i] + li[i + 1] > li[i + 2]:
                        r += 1
                    return r
                if li[i] + li[j] > li[k]:
                    r += 1
                else:
                    break
print(func())

Submission status: Time Limit Exceeded

Solution code:
def func():
    N = int(input())
    li = sorted(list(map(int, input().split())))
    r = 0
    for i, n1 in enumerate(li):
        for j, n2 in enumerate(li):
            for k, n3 in enumerate(li):
                if j + 1 > N or k > N or i >= j or j >= k:
                    continue
                if i + 3 == N:
                    if n1 + n2 > n3:
                        r += 1
                    return r
                if n1 + n2 > n3:
                    r += 1
                else:
                    break
print(func())

Submission status: Time Limit Exceeded

Solution code:
def func():
    N = int(input())
    li = sorted(list(map(int, input().split())))
    r = 0
    for i, n1 in enumerate(li):
        for j, n2 in enumerate(li):
            for k, n3 in enumerate(li):
                if j + 1 > N or k > N or i >= j or j >= k:
                    continue
                if i + 3 == N:
                    if n1 + n2 > n3:
                        r += 1
                    return r
                if n1 + n2 > n3:
                    r += 1

print(func())

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

total = 0
for v in itertools.combinations(l, 3):
    for j in itertools.combinations([0, 1, 2], 3):
        a, b, c = j[0], j[1], j[2]
        if abs(v[a] - v[b]) < v[c] < (v[a] + v[b]):
            total += 1
            break

print(total)

Submission status: Time Limit Exceeded

Solution code:
# ソートしている(a < b < c)として，三角形の存在条件は以下になる
def triangle_check(a, b, c):
    if c < a + b:
        return True
    else:
        return False
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
cnt = 0
for i in range(N - 2):
    for k in range(i + 1, N - 1):
        for l in range(k + 1, N):
            if triangle_check(L[i], L[k], L[l]):
                ans += 1
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# ソートしている(a < b < c)とした三角形の存在条件
def triangle_check(a, b, c):
    if b - a < c and c < a + b:
        return True
    else:
        return False
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
cnt = 0
for i in range(N - 2):
    for k in range(i + 1, N - 1):
        for l in range(k + 1, N):
            if triangle_check(L[i], L[k], L[l]):
                cnt = l
                break
        for l in range(N-1, k, -1):
            if triangle_check(L[i], L[k], L[l]):
                ans += l - cnt + 1
                cnt = 0
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            if (
                (L[i] < (L[j] + L[k]))
                and (L[j] < (L[i] + L[k]))
                and (L[k] < (L[i] + L[j]))
            ):
                ans += 1
            else:
                break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N =  int(input())
L =  list(map(int,input().split()))
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            if (
                (L[i] < (L[j] + L[k]))
                and (L[j] < (L[i] + L[k]))
                and (L[k] < (L[i] + L[j]))
            ):
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import sys
input=sys.stdin.readline
n=int(input())
lists=list(map(int,input().split()))
listss=sorted(lists)
count=0
for i in range(n):
    for j in range(n):
        if i!=j:
            index1=bisect.bisect_left(listss, abs(listss[j]-listss[i])+1)
            index2=bisect.bisect_right(listss,listss[i]+listss[j]-1)
            count+=(index2-index1)
            x=abs(listss[j]-listss[i])
            if  x+1<=listss[i]:
                count-=1
            if x+1<=listss[j]:
                count-=1
print(count//6)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = input().split(" ")
L = [int(i) for i in L]

count = 0
for i in range(0, N-2):
  for j in range(i+1, N-1):
    for k in range(j+1, N):
      if (L[i] < L[j] + L[k]) and (L[j] < L[i] + L[k]) and (L[k] < L[i] + L[j]):
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      if l[i]<l[j]+l[k] and l[j]<l[k]+l[i] and l[k]<l[i]+l[j]:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
 
i=0
j=1
k=2
m=0
 
while i<n-2:
    j=i+1
    while j<n-1:
        k=j+1
        while k<n:
            if l[i]<l[j]+l[k] and l[j]<l[i]+l[k] and l[k]<l[j]+l[i]:
                m=m+1
            k=k+1
        j=j+1
    i=i+1
        
print(m)

Submission status: Time Limit Exceeded

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

i=0
j=1
k=2
m=0

while i<n-2:
    j=i+1
    while j<n-1:
        k=j+1
        while k<n:
            if l[i]<l[j]+l[k] and l[j]<l[i]+l[k] and l[k]<l[j]+l[i]:
                m=m+1
            k=k+1
        j=j+1
    i=i+1
        
print(m)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int,input().split()))
l.sort(reverse=True)


def nibu(ls,xmin) :
    n = len(ls)
    a = 0
    b = n-1
    while b-a > 1 :
        r = (a+b)//2
        if ls[r] > xmin :
            a = r
        else :
            b = r
    else :
        if ls[a] < xmin :
            r = a-1
        elif ls[b] <xmin :
            r = a
        else :
            r = b
    return r


ans = 0
for i in range(0,n-2) :
    c = l[i]

    for j in range(i+1,n-1) :
        b = l[j]
        ans += 1 + nibu(l[j+1:],c-b+1)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
count = 0
List = list(map(int, input().split()))
for i in range(N-2):
  for j in range(N-i-2):
    for k in range(N-i-j-2):
      a = List[i]
      b = List[i+j+1]
      c = List[i+j+k+2]
      if a+b>c and a+c>b and b+c>a:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [int(li) for li in input().split()]

ret = 0
clc = {}

for i in range(0, n - 2):
  for j in range(i + 1, n - 1):
    for k in range(j + 1, n):

      key = tuple(sorted((l[i], l[j], l[k])))

      if not key in clc.keys():
        clc[key] = (key[0] < key[1] + key[2]) and \
                   (key[2] < key[0] + key[1]) and \
                   (key[1] < key[2] + key[0])

      ret += clc[key]

print(ret)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
res = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    s = j+1
    while s < n and a[i]+a[j] > a[s]:
      res += 1
      s += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc143/tasks/abc143_d
N = int(input())
l = list(map(int,input().split()))
l.sort()
count = 0
for i in range(N):
    for j in range(i+1,N):
        if l[N-1] < l[i] + l[j]:
            for k in range(j+1,N):
                if l[i] < l[N-1] + l[j]:
                    if l[j] < l[i] + l[N-1]:
                        count += 1
        else:
            m = (j+N-1)//2
            while l[m] < l[i] + l[j]:
                c = m
                m = (c+N-1)//2
            for k in range(j+1,m):
                if l[k] < l[i] + l[j]:
                    if l[i] < l[k] + l[j]:
                        if l[j] < l[i] + l[k]:
                            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc143/tasks/abc143_d
N = int(input())
l = list(map(int,input().split()))
l.sort()
count = 0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if l[k] >= l[i]+l[j]:
                break
            elif l[k] < l[i]+l[j]:
                if l[j] < l[i]+l[k]:
                    if l[i] < l[j]+l[k]:
                        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc143/tasks/abc143_d
N = int(input())
l = list(map(int,input().split()))
l.sort()
count = 0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if l[i] < l[j]+l[k]:
                if l[j] < l[i]+l[k]:
                    if l[k] < l[i]+l[j]:
                        count += 1
                    elif l[k] >= l[i]+l[j]:
                        break
                elif l[j] >= l[i]+l[k]:
                    break
print(count)

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc143/tasks/abc143_d
N = int(input())
l = list(map(int,input().split()))
l.sort()
count = 0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if l[i] < l[j]+l[k]:
                if l[j] < l[i]+l[k]:
                    if l[k] < l[i]+l[j]:
                        count += 1
                    elif l[k] >= l[i]+l[j]:
                        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc143/tasks/abc143_d
N = int(input())
l = list(map(int,input().split()))
count = 0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if l[i] < l[j]+l[k]:
                if l[j] < l[i]+l[k]:
                    if l[k] < l[i]+l[j]:
                        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(map(int,input().split()))

c=0

for i in range(0,n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      if s[i]<s[j]+s[k] and s[j]<s[i]+s[k] and s[k]<s[i]+s[j]:
        c+=1
        
print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = list(map(int,input().split()))
li2 = sorted(li,reverse=True)
cnt = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        if li2[i] > li2[j] + li2[j+1]:
            break
        else:
            for k in range(j+1,n):
                if li2[i] < li2[j]+li2[k]:
                    cnt += 1
                else:
                    break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = list(map(int,input().split()))
li2 = sorted(li,reverse=True)
cnt = 0

for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if li2[i] < li2[j]+li2[k]:
                cnt += 1
            else:
                break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = list(map(int,input().split()))
cnt = 0

def triangle(a,b,c):
    if (a < b+c) & (b < a+c) & (c < a+b):
        return True
    else:
        return False

for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if triangle(li[i],li[j],li[k]):
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        t = bisect.bisect_left(l, l[i] + l[j])
        k = bisect.bisect_left(l, abs(l[i] - l[j]))
        if t > j:
            ans += t - max(k, j + 1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        t = bisect.bisect_left(l[j+1:], l[i] + l[j])
        k = bisect.bisect_left(l[j+1:], abs(l[i] - l[j]))
        ans += t - k
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse = True)
cnt = 0
for long in range(N-2):
  for mid in range(long+1,N-1):
    for short in range(mid+1,N):
      if L[long] < L[mid] + L[short]:
        cnt += 1
      else:
        break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse = True)
cnt = 0
for long in range(N-2):
  for mid in range(long+1,N-1):
    for short in range(mid+1,N):
      if L[long] < L[mid] + L[short]:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = [int(x) for x in input().split()]
L = sorted(L)
ans = 0
for one in range(N - 2):
    for two in range(one+1, N - 1):
        for three in range(two + 1, N):
            if L[one] + L[two] > L[three]:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def isTriangle(a,b,c):
    if a < (b+c) and b < (a+c) and c < (a+b):
        return True
    else:
        return False

n = int(input())
L = list(map(int,input().split()))
cnt = 0
L.sort(reverse=True)
for i in range(n-2):
    for j in range(i+1,n-1):
        if L[i] > L[j]+L[j+1]:
            break
        else:
            for k in range(j+1,n):
                if isTriangle(L[i],L[j],L[k]):
                    cnt += 1
                else:
                    break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math

N=int(input())
L=[0]*N
str=input().split(' ')
for i in range(0,N):
    L[i]=int(str[i])

ans=0

def canMakeTriangle(a,b,c):
    if a<b+c and b<c+a and c<a+b:
        return True
    else :
        return False

for i in range(0,N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if canMakeTriangle(L[i],L[j],L[k]):
                ans+=1

print (ans)

Submission status: Time Limit Exceeded

Solution code:
def isTriangle(a,b,c):
    if a < (b+c) and b < (a+c) and c < (a+b):
        return True
    else:
        return False

n = int(input())
L = list(map(int,input().split()))
cnt = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if isTriangle(L[i],L[j],L[k]):
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

box = list(itertools.combinations(L,3))

ans = 0

for l in box:
  if l[0]+l[1] > l[2] and l[1]+l[2] > l[0] and l[2]+l[0] > l[1]:
    ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(map(int,input().split()))
s.sort()
ans = 0
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      #print(i,j,k,s)
      if s[i]+s[j]>s[k]:
        ans+=1
      else:
        break
print(ans)

Submission status: Time Limit Exceeded

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

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

ll.sort()
ans = 0
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if ll[k] < ll[i] + ll[j]:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
count=0
while len(L)>=3:
  a=L.pop()
  for i in range(len(L)-1):
    for j in range(i+1,len(L)):
      if a<L[i]+L[j]:
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
L=sorted(L,reverse=True)
count=0
for i in range(0,N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      if L[k]+L[j]<=L[i]:
        break
      if L[i]+L[k]<=L[j]:
        break
      if L[j]+L[i]>L[k]:
        count+=1
      
print(count)

Submission status: Time Limit Exceeded

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

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

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            if ll[i] < ll[j] + ll[k] and ll[j] < ll[k] + ll[i] and ll[k] < ll[i] + ll[j]:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
 
count=0
for i in range(0,N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      if L[i]+L[j]>L[k] and L[i]+L[k]>L[j] and L[j]+L[k]>L[i]:
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = list(map(int,input().split()))
li.sort()
count = 0
for x in range(n-2):
  a = li[x]
  for y in range(x+1,n-1):
    b = li[y]
    z = y+1
    while z <= n-1:
      if li[z] >= b and li[z] < a+b:
        count +=1
        z += 1
      else:
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = list(map(int,input().split()))
li.sort()
count = 0
for x in range(n-2):
  a = li[x]
  for y in range(x+1,n-1):
    b = li[y]
    z = y+1
    while z <= n-1:
      if li[z] >= b and li[z] < a+b:
        count += 1
        z += 1
      else:
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math


def main():
    N = int(input())
    L = np.array([int(a) for a in input().split(" ")])
    L.sort()
    count = 0
    for n1 in range(N - 2):
        for n2 in range(n1 + 1, N - 1):
            s = L[n1] + L[n2]
            L2 = L[n2 + 1:]
            count += np.sum(L2 < s)
    print(count)


if(__name__ == "__main__"):
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math


def main():
    N = int(input())
    L = np.array([int(a) for a in input().split(" ")])
    count = 0
    for n1 in range(N - 2):
        for n2 in range(n1 + 1, N - 1):
            m = abs(L[n1] - L[n2])
            s = L[n1] + L[n2]
            L2 = L[n2 + 1:]
            count += np.sum(np.logical_and(L2 < s, L2 > m))
    print(count)


if(__name__ == "__main__"):
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  n = int(input())
  l = list(map(int,input().split()))
  cnt = 0
  for i in range(n):
    for j in range(i+1,n):
      for k in range(j+1,n):
        if l[i]<l[j]+l[k] and l[j]<l[k]+l[i] and l[k]<l[i]+l[j]:
          cnt += 1
  print(cnt)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
L=[]*N
L=map(int,input().split(" "))
ans=0
for a,b,c in itertools.combinations(L,3):
    if (a<b+c) & (b<c+a) & (c<a+b):ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort(reverse=True)
n1=n
s=0
for i in range(n-2):
    n1=n
    for j in range(i+1,n1-1):
        for k in range(j+1,n1):
            if a[j]+a[k]>a[i]:
                s+=1
            else:
                n1=k
                break
print(s)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort(reverse=True)
s=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if a[j]+a[k]>a[i]:
                s+=1
            else:
                break
print(s)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

cnt = 0
cmb = list(itertools.combinations(L, 3))
for a, b, c in cmb:
    if a < b + c and b < c + a and c < a + b:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():    
    n = int(input())
    l = list(int(x) for x in input().split())
    ans = 0

    for i in range(n-2):
        for j in range(i+1, n):
            for k in range(j+1, n):
                if (l[i] < l[j]+l[k]) and (l[j] < l[k]+l[i]) and (l[k] < l[i]+l[j]):
                    ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
counter=0
L=input().split()
list.sort(L)
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if int(L[k])<int(L[j])+int(L[i]) and int(L[j])<int(L[i])+int(L[k]) and int(L[i])<int(L[j])+int(L[k]):
                counter+=1
            else:
                break
print(counter)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
counter=0
L=input().split()
list.sort(L)
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if int(L[i])<int(L[j])+int(L[k]) and int(L[j])<int(L[i])+int(L[k]) and int(L[k])<int(L[j])+int(L[i]):
                counter+=1
            else:
                break
print(counter)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
counter=0
L=input().split()
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if int(L[i])<int(L[j])+int(L[k]) and int(L[j])<int(L[i])+int(L[k]) and int(L[k])<int(L[j])+int(L[i]):
                counter+=1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lis = [int(e) for e in input().split()]
sum = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if lis[i] + lis[j] > lis[k] \
            and lis[j] + lis[k] > lis[i] \
            and lis[k] + lis[i] > lis[j]:
                sum += 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
number = int(input())
list = list(map(int, input().split()))
ls = sorted(list)
count = 0

for a in range(0, number - 2):
    for b in range(a + 1, number - 1):
        for c in  range(b + 1, number):
            if ls[a] + ls[b] > ls[c]:
                count += 1
            else:
                break

print(count)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin 
n = int(stdin.readline().rstrip())
l = [int(x) for x in stdin.readline().rstrip().split()]
l.sort()
answer = 0
for i in range(len(l)):
    for j in range(i):
        if i != j:
            low = i+1
            high = n
            c = l[i] + l[j]
            while low < high:
                mid = (low + high) // 2
                if l[mid] < c:
                    low = mid + 1
                else:
                    high = mid
            answer += low - i - 1
print(answer)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = [int(i) for i in input().split()]

L = sorted(L, reverse=True)
ans = 0

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            if L[i] < L[j] + L[k]:
                ans += 1
            else:
                break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = [int(i) for i in input().split()]
C = []
count = 0

#全組み合わせを求める
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            C.append([L[i],L[j],L[k]])

#上で求めた各組み合わせの各リストについて三角形の成立条件が成り立つかどうか見ていく
for i in range(len(C)):
    if C[i][0] < C[i][1] + C[i][2] and C[i][1] < C[i][0] + C[i][2] and C[i][2] < C[i][0] + C[i][1]:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
count = 0
List = list(map(int, input().split()))
for i in range(N):
  for j in range(N):
    for k in range(N):
      a = List[i]
      b = List[j]
      c = List[k]
      if i != j and i != k and k != j:
        if a+b>c and a+c>b and b+c>a:
          count += 1
print(int(count/6))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
R=list(map(int,input().split()))
L=sorted(R)[::-1]

s=0
for i in range(0,N-2):
	a=L[i]
	for j in range(i+1,N-1):
		b=L[j]	#a-b<c=<b
		k=j+1
		while k<=N-1 and L[k]>a-b:
			s+=1
			k+=1
print(s)

Submission status: Time Limit Exceeded

Solution code:
def check(a,b,c):
    if a+b > c and b+c > a and c+a > b:
        return True
    else:
        return False

n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for i in range(n-2):
    for k in range(i+1,n-1):
        j = k+1
        while j < n and check(l[i],l[k],l[j]):
            ans += 1
            j += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin 
n = int(stdin.readline().rstrip())
s = [int(x) for x in stdin.readline().rstrip().split()]
a = 0
for i in range(len(s)):
    for j in range(i):
        for k in range(j):
            if i != j and j != k and k != i:
                if s[i] < s[j] + s[k] and s[j] < s[k] + s[i] and s[k] < s[i] + s[j]:
                    a += 1
print(a)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

cnt = 0

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k = bisect.bisect_left(L, L[i] + L[j], lo=j + 1) - 1
        cnt += k - j

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect

# 別解 :
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):
        idx = bisect.bisect_left(L, L[i] + L[j], lo=j + 1)
        cnt += idx - (j + 1)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect

# 別解 :
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):
        idx = bisect.bisect_left(L, L[i] + L[j], lo=j + 1)
        cnt += max(0, idx - (j + 1))


print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

L.sort()
cnt = 0

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

Submission status: Time Limit Exceeded

Solution code:
N =int(input())
L_n = list(map(int,input().split()))
#リストの並べ替え
L_n.sort()

count = 0
for i in range(N-2):
    for j in range(i +1 ,N-1):
        for k in range(j +1,N):
            if L_n[ i ]+L_n[ j ] > L_n[k] and  L_n[ i ]+L_n[ k] > L_n[j]:
                count +=1
            else: break
                
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = input().split()
tri = 0
for i in range(0,N):
    L[i] = int(L[i])
for i in range(0,N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            if L[i] < L[j] + L[k] and L[j] < L[i] + L[k] and L[k] < L[j] + L[i]:
                tri += 1
print(tri)

Submission status: Time Limit Exceeded

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

l.sort(reverse = 1)
ans = 0
flg = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        indL = j
        indR = len(l)-1
        while 1:
            if indL == indR:
                flg = 1
                break
            if l[i] < l[indL] + l[indR]:
                ans += (indR - indL)
                break
            else:
                indR -= 1
        if flg == 1:
            flg = 0
            break
                
print(ans)