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=list(map(int,input().split()))
L.sort()

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
s = int(input())
a = list(map(int, input().split()))
d = 0
for x in range(s-2):
  for y in range(x+1,s-1):
    for z in range(y+1,s):
      if a[x]<a[y]+a[z] and a[y]<a[x]+a[z] and a[z]<a[y]+a[x]:
        d += 1

print(d)

Submission status: Time Limit Exceeded

Solution code:
import math


def rank(arr):
    lastIndex = len(arr) - 1
    while lastIndex > 0:

        for i in range(lastIndex):
            if arr[i + 1] < arr[i]:
                tmp = arr[i + 1]
                arr[i + 1] = arr[i]
                arr[i] = tmp

        lastIndex = lastIndex - 1

    return arr

def half_search(arr, N, startIndex, endIndex):
    if startIndex == endIndex:
        if arr[startIndex] > N:
            return startIndex
        else:
            return -1

    if endIndex - startIndex == 1:

        if arr[startIndex] > N:
            return startIndex
        else:

            if arr[endIndex] <= N:
                return -1

            return endIndex

    m = (startIndex + endIndex) % 2

    if m == 1:
        # 偶数 2,5 => 3,4
        s1 = int((startIndex + endIndex - 1) / 2)
        s2 = s1 + 1
        value1 = arr[s1]

        if N < value1:
            return half_search(arr, N, startIndex, s2)
        else:
            return half_search(arr, N, s1, endIndex)
    else:
        # 奇数 3,6 => 5
        #
        midIndex = int((startIndex + endIndex + 1) / 2)
        midValue = arr[midIndex]

        if midValue > N:
            return half_search(arr, N, startIndex, midIndex)
        else:
            return half_search(arr, N, midIndex, endIndex)

def calculate(arr):
    if len(arr) < 3:
        return 0

    index = len(arr) - 1
    result = 0
    while index - 2 >= 0:

        s1 = arr[index] # 最大的值

        secondIndex = index - 1

        while secondIndex - 1 >= 0:

            s2 = arr[secondIndex]

            left = arr[:secondIndex]

            dirrerence = math.fabs(s2 - s1)
            t = half_search(left, dirrerence, 0, len(left) - 1)
            res = 0
            if t >= 0:
                res = len(left) - t
            result = result + res

            secondIndex = secondIndex - 1
        index = index - 1

    return result

N = input()
S = list(input().split(' '))
S = list(map(int, S))

arr = rank(S)
result = calculate(arr)
print(result)

Submission status: Time Limit Exceeded

Solution code:
import bisect

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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]
    more_than = bisect.bisect_left(L[j+1:], min_sum)
    ans += more_than
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
 
N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
ans = 0
for i in range(N):
  for j in range(i+1, N):
    min_sum = L[i]+L[j]
    more_than = bisect.bisect_left(L[j+1:], min_sum)
    ans += more_than
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

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

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
L =sorted([int(i) for i in input().split()])


#print(L)

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L =sorted([int(i) for i in input().split()],reverse=True)

#print(L)

count=0
for i in range(0, n-2,1):
  c=L[i]
  x=0
  for j in range(i+1,n-1,1):
    b=L[j]
    for k in range(j+1,n,1):
      a=L[k]
      if a+b>c:
        count +=1
      else:
        if k == j+1:
          x=1
        break
    if x==1:
      break

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L =sorted([int(i) for i in input().split()],reverse=True)

#print(L)

count=0
for i in range(0, n-2,1):
  x=0
  for j in range(i+1,n-1,1):
    for k in range(j+1,n,1):
      if (L[j] + L[k] > L[i]):
        count +=1
      else:
        if k == j+1:
          x=1
        break
    if x==1:
      break

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L =sorted([int(i) for i in input().split()],reverse=True)

#print(L)

count=0
for i in range(0, n,1):
  x=0
  for j in range(i+1,n,1):
    for k in range(j+1,n,1):
      if (L[j] + L[k] > L[i]):
        count +=1
      else:
        if k == j+1:
          x=1
        break
    if x==1:
      break

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L =sorted([int(i) for i in input().split()],reverse=True)

# print(L)

count=0
for i in range(0, n,1):
  x=0
  for j in range(i+1,n,1):
    for k in range(j+1,n,1):
      if (L[j] + L[k] > L[i]):
        count +=1
      else:
        if j == k+1:
          x=1
        break
    if x==1:
      break
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L =sorted([int(i) for i in input().split()],reverse=True)

count=0
for i in range(0, len(L),1):
  for j in range(i+1,len(L),1):
    for k in range(j+1,len(L),1):
      if (L[j] + L[k] > L[i]):
        count +=1
print(count)

Submission status: Time Limit Exceeded

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

count=0
for i in range(0, len(L),1):
  for j in range(i+1,len(L),1):
    for k in range(j+1,len(L),1):
      if (L[i] + L[j] > L[k]) & (L[i] + L[k] > L[j]) & (L[j] + L[k] > L[i]):
        count +=1
print(count)

Submission status: Time Limit Exceeded

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

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

print(x)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
d=[]
def kinds(a,b,c):
  if a<b+c and b<a+c and c<a+b:
    if set([a,b,c]) not in d:
      d.append(set([a,b,c]))
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
          kinds(L[i],L[j],L[k])
print(len(d))

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
l = list(map(int, input().split()))
l = sorted(l)
count = 0

c = list(itertools.combinations(l,3))
for i in c:
    if i[2] < i[0] + i[1]:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

c = list(itertools.combinations(l,3))
for i in c:
    if sorted(i)[2] < sorted(i)[0] + sorted(i)[1]:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

c = list(itertools.combinations(l,3))
for i,j,k in c:
    if i < j + k and j < i + k and k < i + j:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

sum = 0
for i in range(1, N):
    for j in range(i + 1, N):
        b = Ls[i]
        c = Ls[j]
        left = bisect.bisect_left(Ls, abs(c - b) + 1, hi=i)
        right = bisect.bisect_right(Ls, b + c - 1, hi = i)
        # print("b={}, c={}, left={}, right={}".format(b, c, left, right))
        if i > left and right >= left:
            sum += right - left
print(sum)

# a < b + c
# -a < c - b => a > b - c
# c < a + b => -a < b - c => a > c -  b

# a < b + c
# a > |c - b|

Submission status: Time Limit Exceeded

Solution code:
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):
        v = L[i] + L[j]
        left = j + 1
        right = n
        while left < right:
            mid = (left + right) // 2
            if L[mid] == v:
                cnt += mid - 1 - j
                break
            elif L[mid] > v:
                right = mid
            else:
                left = mid + 1
        else:
            if left == n:
                cnt += n - 1 - j
            elif L[left] < v:
                cnt += left - j
            else:
                cnt += left - 1 - j
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N = int(input())
ans = 0
L = list(map(int,input().split()))
L = sorted(L)
for i in range(N-1):
    for j in range(i+1,N):
        a = bisect.bisect(L,L[i]+L[j])
        if L[i]+L[j] in L:
            a -= 1
        ans += a-j-1
     
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
b = sorted(a)
ans = 0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        s = j+1
        g = n-1
        t = b[i] + b[j]
        while s <= g:
            tmp = (s+g)//2
            if t <= b[tmp]:
                g = tmp-1
            else:
                s = tmp+1
#        print(s, g, t, max(0, g-j))
        ans += max(0, g-j)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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


a = list(itertools.combinations(l, 3))
b = []

for i in a:
    b.append(tuple(sorted(i)))

c = list(set(b))

count = 0

for i in c:
    if i[0] < i[1] + i[2] and i[1] < i[0] + i[2] and i[2] < i[0] + i[1]:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = input()
l = list(map(int,input().split()))
ans = 0
for i in list(itertools.combinations(l,3)):
    i = sorted(i)
    a,b,c = i[0],i[1],i[2]
    if c<a+b:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = input()
l = list(map(int,input().split()))
ans = 0
for i in list(itertools.combinations(l,3)):
    a,b,c = i[0],i[1],i[2]
    if a<b+c and b<a+c and c<a+b:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = input()
l = list(map(int,input().split()))
combi = list(itertools.combinations(l,3))
ans = 0
for i in combi:
    a,b,c = i[0],i[1],i[2]
    if a<b+c and b<a+c and c<a+b:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

N = int(input())
L = sorted([int(i) for i in input().split()])

ans = 0
for i, a in enumerate(L):
    if i == len(L) - 2:
        break
    for j in range(1, N-1-i):
        l = j + i
        b = L[l]
        idx = bisect.bisect_left(L, a + b, lo=l+1)
        ans += (idx - (l + 1))
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def judge(x,y,z):
    return ((x+y) > z) and ((x + z) > y) and ((y + z) > x)



def calculate(arr):
    N = len(arr)

    if N == 0:
        return 0

    if N < 3:
        return 0

    count = 0
    for x_index in range(N-2):
        for y_index in range(x_index+1,N-1):
            for z_index in range(y_index+1,N):
                if judge(arr[x_index],arr[y_index],arr[z_index]):
                    count = count + 1

    return count

N = input()
L = input().split(' ')
arr = []
for i in L:
    arr.append(int(i))

result = calculate(arr)
print(result)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
b = sorted(a)
ans = 0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if b[i]+b[j] <= b[k]:
                break
            elif b[k] == b[k-1]:
                continue
            else:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect


input = sys.stdin.readline

def main():
    N = int(input())
    L = sorted(map(int, input().strip().split()))

    bleft = bisect.bisect_left
    bright = bisect.bisect
    ans = 0

    for i, a in enumerate(L):
        if i > N-2:
            break
        for j, b in enumerate(L):
            if j > N-1:
                break
            if j <= i:
                continue
            # print(a, b)
            c_right = bleft(L, a+b)
            # print(c_right)
            if c_right == 0:
                continue
            now_seq = L[j+1:c_right]
            c_left = bright(now_seq, b-a)
            if c_left == N:
                continue
            ans += len(now_seq) - c_left
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect


input = sys.stdin.readline

def main():
    N = int(input())
    L = sorted(map(int, input().strip().split()))

    bleft = bisect.bisect_left
    bright = bisect.bisect
    ans = 0

    for i in range(N-2):
        a = L[i]
        for j in range(i+1, N-1):
            b = L[j]
            # print(a, b)
            c_right = bleft(L, a+b)
            # print(c_right)
            if c_right == 0:
                continue
            now_seq = L[j+1:c_right]
            c_left = bright(now_seq, b-a)
            if c_left == N:
                continue
            ans += len(now_seq) - c_left
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect


input = sys.stdin.readline

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

bleft = bisect.bisect_left
bright = bisect.bisect
ans = 0

for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        # print(a, b)
        c_right = bleft(L, a+b)
        # print(c_right)
        if c_right == 0:
            continue
        now_seq = L[j+1:c_right]
        c_left = bright(now_seq, b-a)
        if c_left == N:
            continue
        ans += len(now_seq) - c_left
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

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

while len(L) > 2:
    for i in range(2,len(L)):
        if L[i] < L[0] + L[1]:
                count += 1
        if len(L) > 3:
            for j in range(3,len(L)):
                if L[j] < L[0] + L[i] and i < j:
                    count += 1
    del(L[0])

print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
x=0
for i in range(0,n-2):
  for j in range(i+1,n-1):
    for l in range(j+1,n):
      if a[i]+a[j]>a[l]:
        x+=1
        continue
      if a[i]+a[j]<a[l]:
        break
print(x)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
x=0
for i in range(0,n-2):
  for j in range(i+1,n-1):
    for l in range(j+1,n):
      if a[i]+a[j]>a[l]:
        x+=1
print(x)

Submission status: Time Limit Exceeded

Solution code:
A = int(input())
sticks = [int(x) for x in input().split()]
sticks.sort()
total = 0
for i in range(A):
  for j in range(i + 1, A):
    for k in range(j + 1, A):
      if (sticks[i] < sticks[j] + sticks[k]) and (sticks[j] < sticks[i] + sticks[k]) and (sticks[k] < sticks[j] + sticks[i]):
        total += 1
      else:
        break
print(total)

Submission status: Time Limit Exceeded

Solution code:
A = int(input())
sticks = [int(x) for x in input().split()]
total = 0
for i in range(A):
  for j in range(i + 1, A):
    for k in range(j + 1, A):
      if (sticks[i]<sticks[j] + sticks[k]) and (sticks[j]<sticks[i] + sticks[k]) and (sticks[k]<sticks[j] + sticks[i]):
        total += 1
print(total)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
b=0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if a[k]>=a[i]+a[j]:
        continue
      b=b+1
print(b)

Submission status: Time Limit Exceeded

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

L.sort()

ans = 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]:
        break
      else:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
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):
    max_len = L[i] + L[j] - 1
    left = j+1
    right = N
    while left < right:
      mid = (left + right) // 2
      if L[mid] < max_len:
        left = mid + 1
      elif L[mid] > max_len:
        right = mid
      else:
        while mid < N - 1 and L[mid] == L[mid]:
          mid += 1
          count += mid - j
          break
    else:
      count += right - j - 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
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]:
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Ls = list(map(int, input().split()))

Ls.sort(reverse = True)
total = 0

# print(Ls)

# skip = 10

for i in range(N-2):
    for j in range(i+1, N-1):
        sub_total = 0
        for k in range(j+1, N):
            if Ls[i]-Ls[j] < Ls[k] and Ls[i]+Ls[j] > Ls[k]:
                total += 1
            elif Ls[i]-Ls[j] >= Ls[k]:
                break

print(total)

Submission status: Time Limit Exceeded

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

bar.sort(reverse=True)
ans = 0

while len(bar) > 1:
    a = bar.pop()
    cnt = 0
    for i in range(len(bar)-1,-1,-1):
        b = bar[i]
        cnt += 1
        for j in range(len(bar)-1-cnt,-1,-1):
            c = bar[j]
            if c < (a+b):
                ans += 1
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Ls = list(map(int, input().split()))

Ls.sort(reverse = True)
total = 0

# print(Ls)

for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if Ls[i]+Ls[j] > Ls[k] and Ls[i]+Ls[k] > Ls[j] and Ls[j]+Ls[k] > Ls[i]:
                total += 1
            elif Ls[i]+Ls[j] > Ls[k]:
                break

print(total)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

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

bar.sort()
bar = deque(bar)
ans = 0

while len(bar) > 1:
    a = bar.popleft()
    for i in range(len(bar)-1):
        b = bar[i]
        for j in range(i+1, len(bar)):
            c = bar[j]
            if c < (a+b):
                ans += 1
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

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

bar.sort()
bar = deque(bar)
ans = 0

while len(bar) > 1:
    a = bar.popleft()
    for i in range(len(bar)-1):
        b = bar[i]
        for j in range(i+1, len(bar)):
            c = bar[j]
            if c < (a+b):
                ans += 1
            else:
                break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input())
ds = input().split()
tris = 0
for i in range(N):
  ds[i] = int(ds[i])
for i in range(N):
  for j in range(i):
    for k in range(j):
      if ds[i]<ds[j]+ds[k]:
        if ds[j]<ds[k]+ds[i]:
          if ds[k]<ds[i]+ds[j]:tris += 1
print(tris)

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input())
ds = input().split()
tris = 0
for i in range(N):
  ds[i] = int(ds[i])
for i in range(N):
  for j in range(i):
    for k in range(j):
      if ds[i]<ds[j]+ds[k] and ds[j]<ds[k]+ds[i] and ds[k]<ds[i]+ds[j]:tris += 1
print(tris)

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc143/tasks/abc143_d
# -*- coding: utf-8 -*-

stick_cnt = int(input())
stick_len = list(map(int, input().strip().split()))

stick_sort = sorted(stick_len, reverse=True)

tri_cnt = 0
for i in range(0,stick_cnt-2):
    for j in range(i+1,stick_cnt-1):
        stick_slice = stick_sort[j+1:]
        work = stick_sort[i] - stick_sort[j]
        match = [i for i in stick_slice if i > work]
        tri_cnt += len(match)

print(tri_cnt)

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc143/tasks/abc143_d
# -*- coding: utf-8 -*-

stick_cnt = int(input())
stick_len = list(map(int, input().strip().split()))

stick_sort = sorted(stick_len, reverse=True)

tri_cnt = 0
for i in range(0,stick_cnt-2):
    for j in range(i+1,stick_cnt-1):
        work = stick_sort[i] - stick_sort[j]
        for k in range(j+1,stick_cnt):
            if work < stick_sort[k]:
                tri_cnt += 1
            else:
                break

print(tri_cnt)

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc143/tasks/abc143_d
# -*- coding: utf-8 -*-

stick_cnt = int(input())
stick_len = list(map(int, input().strip().split()))

stick_sort = sorted(stick_len, reverse=True)

tri_cnt = 0
for i in range(0,stick_cnt-2):
    for j in range(i+1,stick_cnt-1):
        for k in range(j+1,stick_cnt):
            if stick_sort[i] < (stick_sort[j] + stick_sort[k]) and\
               stick_sort[j] < (stick_sort[i] + stick_sort[k]) and\
               stick_sort[k] < (stick_sort[i] + stick_sort[j]):
                tri_cnt += 1
            else:
                break

print(tri_cnt)

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc143/tasks/abc143_d
# -*- coding: utf-8 -*-

stick_cnt = int(input())
stick_len = list(map(int, input().strip().split()))

tri_cnt = 0
work = 0
for i in range(0,stick_cnt-2):
    for j in range(i+1,stick_cnt-1):
        work = stick_len[i] + stick_len[j]
        for k in range(j+1,stick_cnt):
            if stick_len[k] < work:
                if stick_len[i] < (stick_len[j] + stick_len[k]):
                    if stick_len[j] < (stick_len[i] + stick_len[k]):
                        tri_cnt += 1

print(tri_cnt)

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc143/tasks/abc143_d
# -*- coding: utf-8 -*-

stick_cnt = int(input())
stick_len = list(map(int, input().strip().split()))

tri_cnt = 0
for i in range(0,stick_cnt-2):
    for j in range(i+1,stick_cnt-1):
        for k in range(j+1,stick_cnt):
            if stick_len[i] < (stick_len[j] + stick_len[k]):
                if stick_len[j] < (stick_len[i] + stick_len[k]):
                    if stick_len[k] < (stick_len[i] + stick_len[j]):
                        tri_cnt += 1

print(tri_cnt)

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc143/tasks/abc143_d
# -*- coding: utf-8 -*-

stick_cnt = int(input())
stick_len = list(map(int, input().strip().split()))

tri_cnt = 0
for i in range(0,stick_cnt-2):
    for j in range(i+1,stick_cnt-1):
        for k in range(j+1,stick_cnt):
            if stick_len[i] < (stick_len[j] + stick_len[k]) and\
               stick_len[j] < (stick_len[i] + stick_len[k]) and\
               stick_len[k] < (stick_len[i] + stick_len[j]):
                tri_cnt += 1

print(tri_cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        S = sorted(L[j+1:])
        ans += len(S) - bisect.bisect_right(S, L[i]-L[j])

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        m = L[j]-L[i]
        M = L[j]+L[i]
        res = L[j+1:]
        res_m = np.where(m < res, 1, 0)
        res_M = np.where(res >= M, 1, 0)
        ans += sum(res_m)-sum(res_M)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L = sorted(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[j] - L[i] < L[k] < L[i] + L[j]:
                ans += 1
            elif L[k] >= L[i] + L[j]:
                break

print(ans)

Submission status: Time Limit Exceeded

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

tri = []
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if abs(L[i] - L[j]) < L[k] < L[i] + L[j]:
                tri.append((L[i], L[j], L[k]))
            elif L[k] >= L[i] + L[j]:
                break

print(len(set(tri)))

Submission status: Time Limit Exceeded

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

l.sort()
ans = 0

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

Submission status: Time Limit Exceeded

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

ans_set = set()

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

for i in range(len(l)):
    for j in range(len(l)):
        for k in range(len(l)):
            if i == j or j == k or k == i:
                continue
            if is_triangle(l[i], l[j], l[k]):
                ans_set.add(frozenset([i, j, k]))

print(len(ans_set))

Submission status: Time Limit Exceeded

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

ans_set = set()

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

for i, item1 in enumerate(l):
    for j, item2 in enumerate(l):
        for k, item3 in enumerate(l):
            if i == j or j == k or k == i:
                continue
            if is_triangle(item1, item2, item3):
                ans_set.add(frozenset([i, j, k]))

print(len(ans_set))

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
l = list(map(int, input().split()))
L = list(itertools.combinations(l,3))
ans = 0
for a, b, c in L:
    if a < b + c and b < c + a and c < a + b:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

l.sort()
ans = 0
for i in range(n):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        c_candidate = [k for k in l[j+1:] if k < a+b]
        ans += len(c_candidate)

print(ans)

Submission status: Time Limit Exceeded

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

ListL.sort()

ans = 0
for i in range(n-2):
	a = ListL[i]
	for j in range(i+1, n-1):
		b = ListL[j]
		maxC = a + b - 1
		minC = abs(a-b) + 1
		for k in range(j+1, n):
			c = ListL[k]
			if(c < minC):
				continue
			elif(c > maxC):
				break
			else:
				ans += 1

print(ans)

Submission status: Time Limit Exceeded

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


n = int(input())
ListL = [int(i) for i in input().split()]

ListL.sort()

ans = 0
for i in range(n-2):
	a = ListL[i]
	for j in range(i+1, n-1):
		b = ListL[j]
		for k in range(j+1, n):
			c = ListL[k]
			if(check(a, b, c)):
				ans += 1
			else:
				break

print(ans)

Submission status: Time Limit Exceeded

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

n = int(input())
ListL = [int(i) for i in input().split()]

ans = 0
for i in range(n-2):
	a = ListL[i]
	for j in range(i+1, n-1):
		b = ListL[j]
		for k in range(j+1, n):
			c = ListL[k]
			if(check(a, b, c)):
				ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, 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()