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: Runtime Error

Solution code:
import bisect

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

ans = 0
for i in range(N-1):
  k = li[i]
  for j in range(i+1, N):
    l = li[j]
    tmp = bisect_left(li, k+l)
    ans += tmp - j -1
    
    
print(ans)

Submission status: Runtime Error

Solution code:
import bisect

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

ans = 0
for i in range(N-1):
  k = li[i]
  for j in range(i+1, N):
    l = li[j]
    tmp = bisect_left(li, k+l)
    ans += tmp - i -1
    
    
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
=int(input())
L=input()
L=L.split(" ")
L_i=[]
for i in L:
 L_i.append(int(i))
L_i=sorted(L_i)
count=0
for i in range(0,N):
 for j in range(i+1,N):
  for k in range(j+1,N):
   if(L_i[i]<L_i[j]+L_i[k] and L_i[j]<L_i[k]+L_i[i] and L_i[k]<L_i[i]+L_i[j] ):
    count+=1
   else:
    break

print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())

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

a = 0

for i in range(len(l)):
    for j in range(i+1,len(l)):
        if j > l[i]+l[j]]:
            a+=1
        

print(a)

Submission status: Runtime Error

Solution code:
n = int(input())

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

a = 0

for i in range(len(l)):
    for j in range(i+1,len(l)):
        a = a + int(len([for k in l if i > l[i]+l[j]]))
        

print(a)

Submission status: Runtime Error

Solution code:
n = int(input())

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

a = 0

for i in range(len(l)):
    for j in range(i+1,len(l)):
        a = a + int(len(for k in l if i > l[i]+l[j]))
        

print(a)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left
 
n = int(input())
l = list(map(int, input().split())).sort
 
c = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    c += bisect_left(l, l[i]+l[j], j+1)
 
print(c)

Submission status: Runtime Error

Solution code:
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)
from bisect import bisect_left, bisect_right
 
def main():
    N = int(input())
    L = [int(c) for c in input().split()]
    L = sorted(L)
    num = 0
    for ai in range(N):
        for bi in range(ai+1, N):
            if bi - ai == 1:
                continue
            a = L[ai]
            b = L[bi]
            ci_left = bisect_right(L, abs(L[ai] - L[bi]))
            ci_right = bisect_left(L, L[ai] + L[bi])
            if ci_left == ci_right:
                continue
            else:
                ci_left = max(ci_left, ai + 1)
                ci_right = min(ci_right, bi)
            # print(a, b, ci_left, min(ci_right, bi) - max(ci_left, ai) - 1)
            # num += min(ci_right, bi) - max(ci_left, ai) - 1
                num += ci_right - ci_left
            # print(a, b, ci_right, ci_left, num)
 
    print(num)
 
 
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)
from bisect import bisect_left, bisect_right
 
def main():
    N = int(input())
    L = [int(c) for c in input().split()]
    L = sorted(L)
    num = 0
    for ai in range(N):
        for bi in range(ai+1, N):
            if bi - ai == 1:
                continue
            a = L[ai]
            b = L[bi]
            ci_left = bisect_right(L[ai+1:bi], abs(L[ai] - L[bi]))
            ci_right = bisect_left(L[ai+1:bi], L[ai] + L[bi])
            # print(a, b, ci_left, min(ci_right, bi) - max(ci_left, ai) - 1)
            # num += min(ci_right, bi) - max(ci_left, ai) - 1
            num += ci_right - ci_left
            # print(a, b, ci_right, ci_left, num)
 
    print(num)
 
 
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution 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)

Submission status: Runtime Error

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

x=int(0)
y=int(1)
z=int(2)
ans = 0
while True:
    y = x + 1

    while True:
        ans += z-2
        z += 1
        while True:
            if l[x]+l[y] > l[z]:
                ans += 1
                z += 1
                if z > n-1:
                    break
            else:
                break
        y += 1
        if y > n - 2:
            break
    x += 1
    if x > n - 3:
        break

print(ans)

Submission status: Runtime Error

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

print(count)

Submission status: Runtime Error

Solution code:
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):
		for c in range(b+1,n):
			if d[c]<d[b]+d[a]:
				m += 1
				if d[c]==d[a]:
                  m -= 1
			else:
				break

print(m)

Submission status: Runtime Error

Solution code:
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):
		for c in range(b+1,n):
			if d[c]<d[b]+d[a]:
				m += 1
				if d[c]==d[a]:
				m -= 1
			else:
				break

print(m)

Submission status: Runtime Error

Solution code:

input()
data=[int(i) for i in input().split()]
data.sort()
tri=0
print(data)
for aid in range(len(data)-2):
  if data[aid]+data[aid+1]>data[aid+2]
    for bid in range(aid+1, len(data)-1):
      if data[aid]+data[bid]>data[bid+1]:
        for cid in range(bid+1, len(data)):
          if data[aid]+data[bid]>data[cid]:
            #print(data[aid],data[bid],data[cid])
            tri=tri+1
          else:
            break

print(tri)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left
N = input()
t_list = list ( map ( int, input().split() ) )
t_list.sort()

for i in range ( N - 2 ):
  a = t_list[i]
  for j in range ( i + 1, N - 1 ):
    b = t_list[j]
    c = bisect_left ( t_list , a + b)
    ans += c - j - 1
    
print(ans)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left
N = input()
t_list = list ( map ( int, ipnut().split() ) )
t_list.sort()

for i in range ( N - 2 ):
  a = t_list[i]
  for j in range ( i + 1, N - 1 ):
    b = t_list[j]
    c = bisect_left ( t_list , a + b)
    ans += c - j - 1
    
print(ans)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left
N = input()
t_list = list ( map ( int, ipnut().split() ) )
t_list.sort()

for i in range ( N - 2 ):
  a = t_list[i]
  for j in range ( i + 1, N - 1 ):
    b = t_list[j]
    c = bisect_left ( t_list , a + b)
    ans = c - j - 1
    
print(ans)

Submission status: Runtime Error

Solution code:
import bisect

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

count = 0

for i in range(n - 2):
  a = ls[i]
  for j in range(i + 1, n - 1):
    b = ls[j]
    index = bisect.bisect_left(ls, a + b):
    count += index - j - 1
print(count)

Submission status: Runtime Error

Solution code:
from collections import deque

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

for _ in range(len(l)-2):
    first = l.pop()
    m = l.copy()
    for _ in range(len(m)-1):
        second = m.pop()
        n = m.copy()
        fix = first - second
        if fix == 0:
            break
        else:
            for _ in range(len(n)):
                third = n.pop()
                if fix < third:
                    ans += 1
                else:
                    break

print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque

_ = int(input())
l = deque(sorted(list(map(int, input().split()))))
ans = 0

for _ in range(len(l)-2):
    first = l.pop()
    m = l.copy()
    for _ in range(len(m)-1):
        second = m.pop()
        n = m.copy()
        fix = first - second
        if fix == 0:
            break
        else:
            for _ in range(len(n)):
                third = n.pop()
                if fix < third:
                    ans += 1
                else:
                    break

print(ans)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left
n = int(input())
ls = list(map(int, input().split())).sort()
count = 0
for i in range(n - 2):
  for j in range(i + 1, n - 1):
    bi = bisect_left(ls, ls[i] + ls[j])
    count += bi - j - 1
print(count)

Submission status: Runtime Error

Solution code:
import bisect
n = int(input())

li = list(map(int, input().split()))
li.sort()

count = 0

for i in range(n-2):
	for j in range(i+1, n-1):
    	bi = bisect.bisect_left(li, li[i] + li[j])
    	count += bi - j - 1
print(count)

Submission status: Runtime Error

Solution code:
import bisect
n = int(input())

li = list(map(int, input().split()))
li.sort()

count = 0

for i in range(n - 2):
	for j in range(i + 1, n - 1):
    	bi = bisect.bisect_left(li, li[i] + li[j])
    	count += bi - j - 1
print(count)

Submission status: Runtime Error

Solution code:
import bisect
n = int(input())

li = list(map(int, input().split())).sort()

count = 0

for i in range(n - 2):
  for j in range(i + 1, n - 1):
    bi = bisect.bisect_left(li, li[i] + li[j])
    count += bi - j - 1
print(count)

Submission status: Runtime Error

Solution code:
import bisect
n = int(input())
ls = list(map(int, input().split())).sort()
count = 0
for i in range(n - 2):
  for j in range(i + 1, n - 1):
    two_sides_sum = ls[i] + ls[j]
    bi = bisect.bisect_left(ls, two_sides_sum)
    count += bi - j - 1
print(count)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left

n = int(input())
ls = list(map(int, input().split())).sort()
count = 0
for i in range(n - 2):
  for j in range(i + 1, n - 1):
    two_sides_sum = ls[i] + ls[j]
    bi = bisect_left(ls, two_sides_sum)
    count += bi-j-1
print(count)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left

n = int(input())
ls = list(map(int, input().split())).sort()
count = 0
for i in range(n - 2):
  for j in range(i + 1, n - 1):
    two_sides_sum = ls[i] + ls[j]
    bi = bisect_left(ls, two_sides_sum)
    count += bi - j - 1
print(count)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left

n = int(input())
ls = list(map(int, input().split())).sort()
count = 0
for i in range(n - 2):
  for j in range(i + 1, n - 1):
    two_sides_sum = ls[i]+ ls[j]
    bi = bisect_left(ls, two_sides_sum)
    count += bi - j - 1
print(count)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left

n = input()
ls = list(map(int, input().split())).sort()
count = 0
for i in range(n - 2):
  for j in range(i + 1, n - 1):
    two_sides_sum = ls[i]+ ls[j]
    bi = bisect_left(ls, two_sides_sum)
    count += bi - j - 1
print(count)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left

n = input()
ls = list(map(int, input().split())).sort
count = 0
for i in range(n - 2):
  for j in range(i + 1, n - 1):
    two_sides_sum = ls[i]+ ls[j]
    bi = bisect_left(ls, two_sides_sum)
    count += bi - j - 1
print(count)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left

n = input()
ls = list(map(int, input().split()))
count = 0
for i in range(n - 2):
  for j in range(i + 1, n - 1):
    two_sides_sum = ls[i]+ ls[j]
    bi = bisect_left(ls, two_sides_sum)
    count += bi - j - 1
print(count)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left

n = input()
ls = list(map(int, input().split()))
count = 0
for i in range(0, n - 2):
  for j in range(i + 1, n - 1):
    two_sides_sum = ls[i]+ ls[j]
    bi = bisect_left(ls, two_sides_sum)
    count += bi - j - 1
print(count)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left

n = input()
ls = list(map(int, input().split()))
count = 0
for i in range(0, n - 2):
  for j in range(i + 1, n - 1):
    two_sides_sum = ls[i]+ ls[j]
    for k in range(j + 1, n):
      if two_sides_sum <= ls[k]:
        count += k - j - 1
        break
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
l = [int(x) for x in input().split()]
l.sort(reverse=True)
 
ans = 0
 
for i in range(n-2):
  j = i + 1
  k = n - 1
  while j < k:
    if l[i] < l[j] + l[k]:
    	ans += k - j
    	j += 1
  	else:
  		k -= 1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
l = [int(x) for x in input().split()]
l.sort(reverse=True)

ans = 0

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

Submission status: Runtime Error

Solution code:
N = int(input())
l = [int(x) for x in input().split()]

L = sorted(l,reverse=True)
a = 0

for x in range(0,N-3):
  for y in range(x+1,N-2):
	for i in range(y+1,N-1):
	  if L[i] > L[x] - L[y]:
		a += 1
print(a)

Submission status: Runtime Error

Solution code:
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int n1 = sc.nextInt();

		int d1[] = new int[n1];

		for(int i = 0; i < n1; i++){
			d1[i] = sc.nextInt();	
		}

		Arrays.sort(d1);

		int r1 = 0;
		for(int i1 = 0; i1 < n1 - 2; i1++){
			for(int i2 = 0; i2 < n1 - i1 - 1; i2++){
				for(int i3 = 0; i3 < n1 - i1 - i2 - 2; i3++){
					if (d1[i1] < d1[i2 + i1 + 1] + d1[i1 + i2 + i3 + 2]){
                		if (d1[i2 + i1 + 1] < d1[i1] + d1[i1 + i2 + i3 + 2]){
                    		if (d1[i1 + i2 + i3 + 2] < d1[i1] + d1[i2 + i1 + 1]){
                        		r1++;
							} else{
								break;
							}
						}
					}
				}
			}
		}
		System.out.println(r1);			
	}
}

Submission status: Runtime Error

Solution code:
=int(input()) 
L=list(map(int, input().split())) 
L.sort()
 
def binary_search(list, item):
    low = 0
    high = len(list) - 1
    
    while low <= high:
        if item > list[high]:
          return high+1
          break
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
          return mid
        elif guess > item:
          high = mid -1
          if list[mid-1] < item:
            return mid-1
            break
        elif guess < item:
          low = mid + 1
          if list[mid+1] > item:
            return mid+1
            break
        else:
          print('error')
 
    return 0
 
 
count = 0        
for i in range(n-1):
  for k in range(i+1,n-1):
    a,b =L[i],L[k]
    L_temp = L[k+1:]
    binary_search(L_temp, a+b)
    count = count + binary_search(L_temp, a+b)
    
print(count)

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())

l = np.array(list(map(int,input().split())))

# n = 200
# l = np.array([i+1 for i in range(n)])

l.sort()
# def num(first,second,third):
#     if l[first] < l[second] + l[third]:
#         dp[first] += 1
#         if third > 0:
#             num(first,second,third-1)
#         else:
#             # print(first,second,third)
#             return 
#     else:
#         # print(first,second,third)
#         return second, third





dp = np.array([0]*n)

for i in range(n-1,1,-1):
    for j in range(i-1,0,-1):
        # print(i,j)
        # num(i,j,j-1)
        for k in range(j-1,-1,-1):
            if l[i] < l[j] + l[k]:
                dp[i] += 1
            else:
                second = j
                third = k
                break
        if second == third + 1:
            break
    # print(i)
print(np.sum(dp))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())

l = np.array(list(map(int,input().split())))
l.sort()
def num(first,second,third):
    if l[first] < l[second] + l[third]:
        dp[first] += 1
        if third > 0:
            num(first,second,third-1)
        elif second > 1:
            num(first,second-1,second-2)
        else:
            return
    else:
        if second == third + 1:
            return
        else:
            if second > 1:
                num(first,second-1,second-2)


            


dp = np.array([0]*n)

for i in range(n-1,1,-1):
    num(i,i-1,i-2)
print(np.sum(dp))

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())

l = np.array(list(map(int,input().split())))
l.sort()
def num(first,second,third):
    if l[first] < l[second] + l[third]:
        dp[first] += 1
        if third > 0:
            num(first,second,third-1)
        elif second > 1:
            num(first,second-1,second-2)
        else:
            return
    else:
        if second == third + 1:
            return
        else:
            num(first,second-1,second-2)


            


dp = np.array([0]*n)

for i in range(n-1,1,-1):
    num(i,i-1,i-2)
print(np.sum(dp))

Submission status: Runtime Error

Solution 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)

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int, input().split()))
cnt = 0
for A in range(n):
  l_2 = list(range(n)).remove(A)
  for B in l_2:
    l_3 = l_2.remove(B)
    for C in l_3:
      a, b, c = l[A], l[B], l[C]
      if (a<b+c and b<a+c and c<a+b):
        cnt += 1
print(cnt//6)

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int, input().split()))
cnt = 0
for A,B,C in range(n)
  a = l[A]
  b = l[B]
  c = l[C]
  if (a<b+c and b<a+c and c<a+b and a!=b and b!=c and c!=a):
    cnt += 1
print(cnt//6)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int, input().split()))
cnt = 0
for A,B,C in range(n)
  a = l[A]
  b = l[B]
  c = l[C]
  if (a<b+c and b<a+c and c<a+b):
    cnt += 1
print(cnt//6)

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int, input().split()))
cnt = 0
for a in range(n):
  for b in range(n):
    for c in range(n):
      if not (a=b or a=c or b=c):
        if (a<b+c and b<a+c and c<a+b):
          cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
L = np.array(list(map(int, input().split())))
L.sort()
weight = np.tile(range(N), N).reshape((N, N))
L_tile = np.tile(L, N).reshape((N, N))
c = 0
for n1 in range(0,N):
    weight_bool = (weight > weight.T) * (weight < n1)
    makable = (L_tile+L_tile.T)>L[n1]
    L2 = np.sum(makable * weight_bool
    c += L2
print(c)

Submission status: Runtime Error

Solution code:
import bisect
n = int(input())
l = List(map(int, input().split()))
count = 0
l = sorted(l)

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

Submission status: Runtime Error

Solution code:
N = int(input())
S = sorted([int(x) for x in input().split()])
a=0
for i in range(N-2):
    for j in range(i+1,N):
        b=S[i]+S[j]
        if (j+1!=N) and (b < S[j+1]) :
            continue
        elif j==N-1: break
        a += bisect
print(a)

Submission status: Runtime Error

Solution 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)

Submission status: Runtime Error

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

L.sort()
print(L)

s = 0
for j in range(N-2):
    for k in range(j+1,N-1):
        Ld = [0] + L[k+1::] + [3000]
        # L[i] < L[j]+L[k] となる L[i]の数を求める
        key = L[j]+L[k]
        l = 0
        r = j + 2
        while r - l > 1:
            m = (r + l) // 2
            if Ld[m] < key:
                l = m
            else:
                r = m
        s += l

print(s)

Submission status: Runtime Error

Solution code:
import bisect
N = int(input())
L = list(map(int,input().split()))
L.sort()
sum = 0
for i in range(0,N):
  L_1st= L[i]
  for j in range(i+1,N):
    L_2nd = L[j]
    c_min = b-a+1
    c_max = b+a-1
    l = bisect.bisect_left(L,c_min,lo = j+1)
    if l!= N:
      r = bisect.bisect_right(L,c_max,lo = j+1)
      if r:
        r = r-1
        if r>= l:
          sum += r-l+1
print(sum)

Submission status: Runtime Error

Solution code:
import bisect
N = int(input())
L = list(map(int,input().split()))
L.sort()
sum = 0
for i in range(0,N):
  L_1st= L[i]
  for j in range(i+1,N):
    L_2nd = L[j]
    c_min = b-a+1
    c_max = b+a-1
    l = bisect.bisect_left(Ls,c_min,lo = j+1)
    if l!= N:
      r = bisect.bisect_right(Ls,c_max,lo = j+1)
      if r:
        r = r-1
        if r>= l:
          sum += r-l+1
print(sum)

Submission status: Runtime Error

Solution code:
import bisect
N = int(input())
L = list(map(int,input().split()))
L.sort()
sum = 0
for i in range(0,N):
  L_1st= L[i]
  for j in range(i+1,N):
    L_2nd = L[j]
    c_min = b-a+1
    c_max = b+a-1
    l = bisect.bisect_left(Ls,c_min,lo = j+1)
    if l!= N:
      r = bisect.bisect_right(Ls,c_max,lo = j+1)
      if r:
        r = r = r-1
        if r>= l:
          sum += r-l+1
print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())
S = np.array(sorted([int(x) for x in input().split()]))
a=0
for i in range(N-2):
    for j in range(i+1,N):
        b=S[i]+S[j]
        if (j+1!=N) and (b < S[j+1]) :
            continue
        elif j==N-1: break
        l=S[np.where(S[j+1:] < b)]
        a += len(l)
print(a)

Submission status: Runtime Error

Solution code:
N = int(input())
S = sorted([int(x) for x in input().split()])
a=0
for i in range(N):
    for j in range(i+1,N):
        b=S[i]+S[j]
        if b > S[j+1]:break
        l = [k for k in S[j+1:] if k < b]
        a += len(l)
print(a)

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
ans = 0
for i in range(n):
    j = i+1
    k = n
    while w < k:
        if a[i]<a[j]+a[k]:
            ans += k-j
            j += 1
        else:
            k -= 1
print(ans)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution 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)

Submission status: Runtime Error

Solution 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)

Submission status: Runtime Error

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):
        a=l[i]
        b=l[j]
        ans+=bisect.bisect_left(l,a+b,lo=j)-j-1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
for i in range(len(L)-1):
    for j in range(i+1,len(L)-1):
        a = L[i]
        b = L[j]
        c = L[j+1]
        if c-a < b and b < c+a:
            ans += bisect.bisect_left(L,b+a)-j-1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort()
import numpy as np
L = np.array(L)
m = [0] * (L[-1] + 10)
for i in range(L[-1] + 10):
    m[i] = np.count_nonzero(L <= i)
print(L)
print(m)
cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        tot = L[i] + L[j]
        if tot >= len(m) + 1:
            tot = len(m) - 2
        cnt += m[tot + 1] - m[L[j] + 1]
        print(i,j,tot,m[tot + 1],m[L[j] + 1])
print(cnt)

Submission status: Runtime Error

Solution code:
def main():
  	N = int(input())
	l = list(map(int, input().split(" ")))
	k = 0
	for i in range(N-2):
    	a = l[i]
    	for j in range(i+1, N-1):
        	b = l[j]
        	k += len([p for p in l[j+1:] if abs(b-a) < p < (a+b)])
	print(k)
main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def lowerBound(nums, target):
  	if nums[-1] < target: return -1
    lp = 0
    rp = len(nums) - 1
    mp = lp + rp >> 1
    while lp <= rp:
        mp = lp + rp >> 1
        if nums[mp] == target:
            return mp
        if nums[mp] < target:
            lp = mp + 1
        else:
            rp = mp - 1
    return mp if target < nums[mp] else -1

if __name__ == '__main__':
    N = int(input())
    L = [int(l) for l in input().split()]
    L.sort()
    ret = 0
    for idx in range(len(L) - 1, 1, -1):
        for jdx in range(idx - 1, 0, -1):
            c = L[idx] - L[jdx] + 1
            ldx = lowerBound(L[:jdx], c)
            if ldx == -1: continue
            ret += jdx - ldx
    print(ret)

Submission status: Runtime Error

Solution code:
n=int(input()) #7
d=list(map(int,input().split())) #218 786 704 233 645 728 389 の時

c=0
for i in range(n-2): #一番最初の辺は218-645まで選べる　n-2=5 range(5)は5を含まずに0,1,2,3,4
    for j in range(i+1,n-1): #iからだと同じのを2回選んでしまうので隣の786-728までrange(1,6)までこの時１は含むが6は含まない range(start,end)
        for l in range(j+1,n) #jのとなりの704-389まですべて選べる
            if (d[i]<d[j]+d[l]) and (d[j]<d[i]+d[l]) and (d[l]<d[i]+d[j]):
                c=c+1 
print(c)

Submission status: Runtime Error

Solution code:
n=int(input()) #7
d=list(map(int,input().split())) #218 786 704 233 645 728 389 の時

c=0
for i in range(n-2): #一番最初の辺は218-645まで選べる　n-2=5 range(5)は5を含まずに0,1,2,3,4
    for j in range(i+1,n-1): #iからだと同じのを2回選んでしまうので隣の786-728までrange(1,6)までこの時１は含むが6は含まない range(start,end)
        for l in range(j+1,n) #jのとなりの704-389まですべて選べる
            if d[i]<d[j]+d[l] and d[j]<d[i]+d[l] and d[l]<d[i]+d[j]:
                c=c+1 
print(c)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
c=0
for i in range(n-1):
    for j in range(i+1,n):
        for l in range(j+1,n)
            if d[i]<d[j]+d[l] and d[j]<d[i]+d[l] and d[l]<d[i]+d[j]:
                c=c+1 
print(c)

Submission status: Runtime Error

Solution code:
n = int(input())

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

H.sort()
count = 0
for i in range(n-1):
  for j in range(i+1, n):
    point = i + j
    if point > H[n-1]:
      break
    else:
      s = find(point, H)
      count += n - s + 1
print(count)

def find(p, ls):
  
  for i in range(len(ls)):
    if p > ls[i]:
      return i

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
t=(n*(n-1)*(n-2))//6
for i in range(n-1):
    for j in range(i+1,n):
        s=a[i]+a[j]
        k=bs(s,0,n-1)
        if k!=-1:
            t-=(n-k)
print(t)

Submission status: Runtime Error

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

a.sort()
count = 0


def binary_search(numbers, target_number):
    # 最小値を仮決め
    low = 0
    # 範囲内の最大値
    high = len(numbers)


    # 目的地を探し出すまでループ
    while low <= high:
        if low == high:
            return low
        # 中央値を求める（index）
        middle = (low + high) // 2
        # 中央値のnumbersの値とtarget_numberが等しい場合
        if numbers[middle] == target_number:
            return middle
        # 中央値のnumbersの値がtarget_numberより小さい場合
        elif numbers[middle] < target_number:
            low = middle + 1
        # 中央値のnumbersの値がtarget_numberより大きい場合
        else:
            high = middle - 1


for i in range(n-2):
    for j in range(i+1, n-1):
        if a[i] + a[j] > max(a):
            count += n - (j+1)
            continue
        index = binary_search(a, (a[i]+a[j]))
        if a[i] + a[j] == a[index]:
            count += (index-(j+1))
        else:
            count += (index - j)


print(count)