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: Wrong Answer

Solution code:
import bisect

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

L = sorted(L)
print(L)
for c in reversed(range(2, N)):
	for b in reversed(range(1, c)):
		a = bisect.bisect_left(L, L[c]-L[b])
		if a<b:
			s += b-a
		print("{},{},{}".format(a,b,c))

print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Lc = [0]*1000

for i in range(N):
	Lc[L[i]-1] += 1

for i in range(0, 998):
	if Lc[i] != 0:
		for j in range(i+1, 999):
			if Lc[j] != 0:
				for k in range(j+1, 1000):
					if Lc[k] != 0:
						if k<i+j:
							s += min(Lc[i], min(Lc[j], Lc[k]))

print(s)

Submission status: Wrong Answer

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

nL = sorted(L)
print(nL)
for i in range(0, N-2):
	for j in range(i+1, N-1):
		s += sum(x<nL[i]+nL[j] for x in nL[j+1:])
		
print(s)

Submission status: Wrong Answer

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

l.sort()
print(l)
cnt=0
for ind_a,a in enumerate(l[:-2]):
    for ind_b,b in enumerate(l[ind_a+1:-1]):
        for ind_c,c in enumerate(l[ind_a+ind_b+2:]):
            #print(a,b,c)
            if a+b<c:
                #print("no",a,b,c,">>",ind_c)
                cnt+=ind_c
                break
        if a+b>c:
            cnt+=ind_c+1

print(cnt)

Submission status: Wrong Answer

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

l.sort()

cnt=0

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
M = list(map(int, input().split()))
M = sorted(M)
count = 0
for i in range(N):
  a = M[i]
  for j in range(i+1, N):
    b = M[j]
    upper = a+b
    #二分探索の実装が下手い
    l, r = j, N
    while (r - l) > 1:
      c = (l + r) // 2
      if M[c] <= upper:
        l = c
      else:
        r = c  
    #print(count, j, l, r)
    count += l - j
      
print(count)

Submission status: Wrong Answer

Solution code:
def main():
    from bisect import bisect_left, bisect_right
    from itertools import combinations

    N = int(input())
    *e, = map(int, input().split())

    e.sort()

    ans = 0
    for b, c in combinations(e, r=2):
        if b > c:
            b, c = c, b
        d = c - b
        ans += max(0, bisect_left(e, b) - bisect_right(e, d))

    print(ans)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
ans = 0

for i in range(N-1):
    a = L[i]
    for j in range(i+1, N):
        b = L[j]
        r = bisect.bisect_right(L, a+b)
        l = max(i, j) + 1
        ans += max(0, r-l)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import statistics
n = int(input())
list_bou = list(map(int, input().split()))
ans = 0
conbi = itertools.combinations(list_bou, 3)
for tri in conbi:
  if max(tri) > statistics.median(tri) + min(tri):
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def low(list, j, tag):
    ok = n - 1
    ng = j - 1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if list[mid] <= tag:ok = mid
        else:ng = mid
    return ok

n = int(input())
l = list(map(int,input().split()))
l = sorted(l, reverse = True)
#print(l)
cnt = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        temp0 = l[i] - l[j]
        temp1 = l[j] + l[i]
        cnt += low(l, j, temp0 + 1) - j
        #print((l[i],l[j]), j, low(l, j, temp0 + 1) - j, cnt)
print(cnt)

Submission status: Wrong Answer

Solution code:
def low(list, j, tag):
    ok = n - 1
    ng = j - 1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if list[mid] <= tag:ok = mid
        else:ng = mid
    return ok

n = int(input())
l = list(map(int,input().split()))
l = sorted(l, reverse = True)
print(l)
cnt = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        temp0 = l[i] - l[j]
        temp1 = l[j] + l[i]
        cnt += low(l, j, temp0 + 1) - j
        #print((l[i],l[j]), j, low(l, j, temp0 + 1) - j, cnt)
print(cnt)

Submission status: Wrong Answer

Solution code:
def low(list, j, tag):
    ok = j
    ng = n
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if list[mid] <= tag:ok = mid
        else:ng = mid
    return ok

def high(list, j, tag):
    ok = n
    ng = j
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if list[mid] >= tag:ok = mid
        else:ng = mid
    return ok

from collections import Counter
n = int(input())
l = list(map(int,input().split()))
l = sorted(l)

cnt = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        temp0 = l[j] - l[i]
        temp1 = l[j] + l[i]
        cnt += low(l, j, temp1 - 1) - low(l, j, temp0 + 1)
        #print(high(l, j, temp1 - 1),low(l, j, temp0 + 1))
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
L_li = list(map(int,input().split()))
L_li.sort()
cnt = 0
for i in range(len(L_li)-1):
    for j in range(i+1,len(L_li)):
        for k in range(j+1,len(L_li)):
            if L_li[i]+L_li[j]>L_li[k]:
                print(i,j,k)
                cnt += 1
            else:
                continue
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right

n = int(input())
L = list(map(int, input().split()))
L.sort()
# a,b,cの順序に大きいとして、6倍…はしなくていいのか。組み合わせらしい
# a-c<b<a+c
cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        cnt += bisect_right(L, j - i + 1) - bisect_left(L, i + j - 1)
print(cnt)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right

n = int(input())
L = list(map(int, input().split()))
L.sort()
# a,b,cの順序に大きいとして、6倍…はしなくていいのか。組み合わせらしい
# a-c<b<a+c
cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        cnt += bisect_right(L, j - i + 1) - bisect_left(L, i + j - 1)
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# 初期入力
#棒を長さでソートし、長いものはわかるようにした。残り2本を選ぶことで、組み合わせを減らした
N = int(input())
L = list(map(int, input().split()))
L_sorted =sorted(L,reverse=True)

#3本選ぶ組み合わせ,1番長いものに対して、一番短い物2本から比較していくとダメなものが速く選べる
from itertools import combinations
count =0
for i in range(N-2): #一番長い
    for j in range(N-2):#一番短い
        for k in range(j+1,N-1):#真ん中
            if L_sorted[j*(-1)] + L_sorted[k*(-1)] < L_sorted[i]:
                count +=1
            else:
                break
# N本の中から3本選ぶ組み合わせ
from math import factorial
N_3_all =factorial(N) // (factorial(N - 3) * factorial(3))

kotae =N_3_all -count
print(kotae)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int, input().split()))
O = sorted(L, reverse=True)
print(sorted(L))
print(O)

def X(n,j):
    C = sorted(L)
    L1 = 0
    L2 = N-1
    while L1 != L2:
        a = (L1+L2)//2
        if C[a] == n:
            nn = len(C[0:N-1-j])-len(C[0:a+1])
            if nn > 0:
                return nn
            else:
                return 0
        if L2 - L1 <= 1:
            if C[L1] > n:
                nn = len(C[0:N-1-j])-len(C[0:L1])
            else:
                nn = len(C[0:N-1-j])-len(C[0:L2])
            if nn > 0:
                return nn
            else:
                return 0
        elif C[a] < n:
            L1 = a
        else:
            L2 = a
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ans += X((O[i]-O[j]),j)
print(ans)

Submission status: Wrong Answer

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

def X(n,j):
    L1 = j+1
    L2 = N-1
    while L1 != L2:
        a = (L1+L2)//2
        if C[a] == n:
            return len(C[j+1:a])
        elif L2 - L1 <= 1:
            if C[L1] > n:
                return len(C[j+1:L1])
            elif C[L1] < n < C[L2]:
                return len(C[j+1:L2])
            else:
                return len(C[j+1:L2+1])
        elif C[a] < n:
            L1 = a
        else:
            L2 = a
    if C[L1] < n:
        return 1
    else:
        return 0
ans = 0
# print(C)
for i in range(N-2):
    for j in range(i+1,N-1):
        # print(X((C[i]+C[j]),j))
        ans += X((C[i]+C[j]),j)
print(ans)

Submission status: Wrong Answer

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

def X(n,j):
    L1 = j+1
    L2 = N-1
    while L1 != L2:
        a = (L1+L2)//2
        if C[a] == n:
            return len(C[j+1:a])
        elif L2 - L1 <= 1:
            if C[L1] > n:
                return len(C[j+1:L1])
            elif C[L1] < n < C[L2]:
                return len(C[j+1:L2])
            else:
                return len(C[j+1:L2+1])
        elif C[a] < n:
            L1 = a
        else:
            L2 = a
    if L1 < n:
        return 1
    else:
        return 0
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ans += X((C[i]+C[j]),j)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int, input().split()))
O = sorted(L, reverse=True)
# print(sorted(L))
# print(O)

def X(n,j):
    C = sorted(L)
    L1 = 0
    L2 = j
    while L1 != L2:
        a = (L1+L2)//2
        if C[a] == n:
            nn = len(C[0:N-1-j])-len(C[0:a+1])
            if nn > 0:
                return nn
            else:
                return 0
        if L2 - L1 <= 1:
            if C[L1] > n:
                nn = len(C[0:N-1-j])-len(C[0:L1])
            else:
                nn = len(C[0:N-1-j])-len(C[0:L2])
            if nn > 0:
                return nn
            else:
                return 0
        elif C[a] < n:
            L1 = a
        else:
            L2 = a
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ans += X((O[i]-O[j]),j)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

L = list((sorted(L)))

A = [0] * 1001
for i in L:
    A[i] += 1

t = 0
for i in range(n):
    for j in range(i+1, n):
        t += sum(A[L[j]+1:L[i] + L[j]])
print(t)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
L.sort()
t_sum = 0
for i in range(N):
  for j in range(i+1,N-1):
    num = L[i]+L[j]
    search_list = L[j+1:]
    le = 0
    ri = len(search_list)-1
    mid = le + (ri -le)//2
    while le <= ri:
      mid = le + (ri -le)//2
      #if search_list[mid] == num:
     #   break

      if search_list[mid] < num:
        le = mid+1
      else:
        ri = mid -1    
    if search_list[mid] < num:
      mid+=1
    elif  search_list[mid] == num:
      while search_list[mid] == num and mid > 0:
        mid -=1
    t_sum += mid
print(t_sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
L.sort()
t_sum = 0
for i in range(N):
  for j in range(i+1,N-1):
    num = L[i]+L[j]
    search_list = L[j+1:]
    le = 0
    ri = len(search_list)-1
    mid = le + (ri -le)//2
    while le <= ri:
      mid = le + (ri -le)//2
      #if search_list[mid] == num:
     #   break

      if search_list[mid] < num:
        le = mid+1
      else:
        ri = mid -1    
    if search_list[mid] < num:
      mid+=1
    elif  search_list[mid] == num:
      while search_list[mid] == num and mid > 0:
        mid -=1
      print(mid)
    print(L[i],L[j],search_list,mid)
    t_sum += mid
print(t_sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
L.sort()
t_sum = 0
for i in range(N):
  for j in range(i+1,N-1):
    num = L[i]+L[j]
    search_list = L[j+1:]
    le = 0
    ri = len(search_list)-1
    mid = le + (ri -le)//2
    while le <= ri:
      mid = le + (ri -le)//2
      if search_list[mid] == num:
        break
      if search_list[mid] < num:
        le = mid+1
      else:
        ri = mid -1
        
    if search_list[mid] < num:
      mid+=1
    t_sum += mid
print(t_sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
L.sort()
t_sum = 0
mid = 0
for i in range(N):
  for j in range(i+1,N-1):
    num = L[i]+L[j]
    search_list = L[j+1:]
    le = 0
    ri = len(search_list)-1
    mid = le + (ri -le)//2
    while le <= ri:
      mid = le + (ri -le)//2
      if search_list[mid] == num:
        break
      if search_list[mid] < num:
        le = mid+1
      else:
        ri = mid -1
        
    if search_list[mid] < num:
      mid+=1  
    t_sum += mid
print(t_sum)

Submission status: Wrong Answer

Solution code:
#143d
from itertools import combinations
from bisect import bisect_left, bisect_right

N = int(input()) #2*10**3

L_list = [int(e) for e in input().split()]
index_list = [i for i in range(N)]

L_list.sort()

ans = 0

for comb in combinations(index_list, 2): #(2*10*3)*(2*10*3 -1)/2 ≒ 2*10*6
    #print(comb," ",end="")
    a = L_list[comb[0]]
    b = L_list[comb[1]]
    #print("min:",b,"max:",a+b,"……",end="") 
    
    #a <= b   
    #c < a+b かつ c > b (三角形を作る為。)
    
    index_left = bisect_left(L_list, a+b) #log(2*10**6)≒6.3
    index_right = bisect_right(L_list, b) #log(2*10**6)
    
    #print(index_left,index_right)
    
    ans += index_left - index_right
    
print(ans)

Submission status: Wrong Answer

Solution code:
#143d
from itertools import combinations
from bisect import bisect_left, bisect_right

N = int(input()) #2*10**3

L_list = [int(e) for e in input().split()]
index_list = [i for i in range(N)]

L_list.sort()

ans = 0

for comb in combinations(L_list, 2): #(2*10*3)*(2*10*3 -1)/2 ≒ 2*10*6
    #print(comb," ",end="")
    a = comb[0]
    b = comb[1]    
    #print("min:",b,"max:",a+b,"……",end="") #a,b a <= b   #c < a+b かつ c > b (三角形を作る為。)
    
    index_left = bisect_left(L_list, a+b) #log(2*10**6)≒6.3
    index_right = bisect_right(L_list, b) #log(2*10**6)
    
    #print(index_left,index_right)
    
    ans += index_left - index_right
    
print(ans)

Submission status: Wrong Answer

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

import numpy as np
Ls = list(np.unique(Ls))

sls = sorted(Ls)
count = 0
for i, a in enumerate(sls):
    for j, b in enumerate(sls[i+1:]):
        cs = sls[i+j+2:]
        cmin, cmax = b - a, b + a
        left, right = bisect.bisect_right(cs, cmin), bisect.bisect_left(cs, cmax)
        count += (right - left)
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
from bisect import bisect_left, bisect_right
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if bisect_left(A, A[i] + A[j]) != bisect_right(A, A[i] + A[j]):
            ans += bisect_left(A, A[i] + A[j]) - bisect_right(A, A[j]) - 1
        else:
            ans += bisect_left(A, A[i] + A[j]) - bisect_right(A, A[j])
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
N = int(input())
#S = input()[:-1]
#N,M = map(int,input().split())
#S,T = map(str,input().split())
A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
def binary_search(S,key,flag): 
    left  = 0
    right = N
    while left < right:
        mid = (left+right) // 2
        if S[mid] == key:
            flag = 1
            return mid
        elif S[mid] > key:
            right = mid
        else:
            left = mid + 1
    return left-1
d = 0
flag = 0
A.sort()
for i in range(N-1):
    for j in range(i+1,N):
        s = A[i]+A[j]
        dex = binary_search(A,s,flag)
        if flag == 0:
          d = d + dex - j
        else:
          while A[dex] == s:
            dex -= 1
          d = d + dex - j
print(d)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
n = int(input())
#S = input()[:-1]
#N,M = map(int,input().split())
#S,T = map(str,input().split())
A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
d = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            a = A[i]
            b = A[j]
            c = A[k]
            if c < a+b:
                d += 1
print(d)

Submission status: Wrong Answer

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

ans=0
for a in range(n):
    for b in range(a+1,n):
        ans+=bisect.bisect_right(l,l[a]+l[b])-b
        
print(ans)

Submission status: Wrong Answer

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


def triangle(num):
    a,b,c=num
    if a<(b+c) and b<(a+c) and c<(a+b):
        return True
    else:
        return False
ans=0
for a in range(n):
    for b in range(a+1,n):
        ans+=bisect.bisect_right(l,l[a]+l[b])-b-1
        
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left

def main():
    _ = int(input())
    L = list(set(map(int, input().split())))
    N = len(L)

    L = sorted(L)
    ans = 0
    for i in range(N-2):
        a = L[i]
        for j in range(i+1, N-1):
            k = bisect_left(L[j+1:], a + L[j])
            ans += k

    print(ans)

    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect

n = int(input())
l = list(map(int, input().split()))
l.sort()
triangle = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    index = bisect(l, l[i] + l[j], j + 1, n)
    triangle += n - index
print(triangle)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
triangle = 0
for i in range(n-2):
  min_l = l[i]
  for j in range(i+1, n-1):
    sum_l = min_l + l[j]
    inf = j
    sup = n
    while sup - inf > 1:
      x = (inf + sup) // 2
      if l[x] < sum_l:
        sup = x
      else:
        inf = x
    triangle += n - sup
print(triangle)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
triangle = 0
while len(l) >= 3:
  max_l = l.pop()
  inf = -1
  for i in range(1, len(l)):
    rest_l = max_l - l[-i]
    sup = i
    while sup - inf > 1:
      x = (inf + sup) // 2
      if l[x] > rest_l:
        sup = x
      else:
        inf = x
    triangle += i - sup
print(triangle)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
INF = float("inf")
N = int(input())
L = list(map(lambda x:int(x),input().split())) + [INF]
L.sort()
cnt = 0
print(*L)
for i in range(N-1):
    a = L[i]
    for j in range(i+1,N):
        b = L[j]
        c = bisect_left(L,a+b)
        cnt += max(0,c-j-1)
print(cnt)

Submission status: Wrong Answer

Solution code:
from bisect import bisect
INF = float("inf")
N = int(input())
L = list(map(lambda x:int(x),input().split())) + [INF]
L.sort()
cnt = 0
for i in range(N-1):
    a = L[i]
    for j in range(i+1,N-1):
        b = L[j]
        c = bisect(L,a+b)
        cnt += c-j-1
print(cnt)

Submission status: Wrong Answer

Solution code:
from bisect import bisect
INF = float("inf")
N = int(input())
L = list(map(lambda x:int(x),input().split())) + [INF]
L.sort()
cnt = 0
print(*L)
for i in range(N-1):
    a = L[i]
    for j in range(i+1,N-1):
        b = L[j]
        c = bisect(L,a+b)
        cnt += c-j-1
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_left
N=int(input())
L=list(map(int,input().split()))
L.sort()
total = 0
for i in range(N):
  for j in range(i + 1, N):
    a = L[i] - L[j]
    total += max(bisect_left(L, a) - j - 1, 0)

print(total)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc143/tasks/abc143_d
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline
n = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
L = [int(i) for i in input().split()]
L.sort()
pairs = []
for i in range(n):
    for j in range(i + 1, n):
        pairs.append((i, j))

ans = 0
for i, j in pairs:
    a, b = L[i], L[j]
    l = bisect_right(L, b - a)
    r = bisect_left(L, a)
    if l < r:
        ans += (r - l)
print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc143/tasks/abc143_d
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline
n = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
L = [int(i) for i in input().split()]
L.sort()
pairs = []
for i in range(n):
    for j in range(i + 1, n):
        pairs.append((i, j))

ans = 0
for i, j in pairs:
    a, b = L[i], L[j]
    l = bisect_left(L, b - a)
    r = bisect_left(L, a - 1)
    if l < r:
        ans += (r - l)
print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc143/tasks/abc143_d
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline
n = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
L = [int(i) for i in input().split()]
L.sort()
pairs = []
for i in range(n):
    for j in range(i + 1, n):
        pairs.append((i, j))

ans = 0
for i, j in pairs:
    a, b = L[i], L[j]
    l = bisect_left(L, b - a + 1)
    r = bisect_left(L, a)
    if l < r:
        ans += (r - l)
print(ans)

Submission status: Wrong Answer

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

L = sorted(L)
#print(L)

bucket=[0]*(2*10**3+1)
for val in L:
    bucket[val]+=1
#print(bucket)

for i in range(2*10**3):
    bucket[i+1] += bucket[i]
#print(bucket)


cnt=0
for i in range(0, N-2):
    for j in range(i+1, N-1):
        cnt += bucket[L[i]+L[j]-1] - bucket[L[j]-1] -(1 if L[i] != L[j] else 2)
        #print(i,j,bucket[L[i]+L[j]-1], bucket[L[j]-1])
print(cnt)

Submission status: Wrong Answer

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

L.sort()
import bisect
ans = 0
for i in range(n-2):
    b = L[i]
    for j in range(i+1, n-1):
        c = L[j]
        p = bisect.bisect_left(L, b+c)
        q = bisect.bisect_right(L, c)
        ans += max(p-q, 0)
print(ans)

Submission status: Wrong Answer

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

L.sort()
import bisect
ans = 0
print(L)
for i in range(n-2):
    b = L[i]
    for j in range(i+1, n-1):
        c = L[j]
        p = bisect.bisect_left(L, b+c)
        q = bisect.bisect_right(L, c)
        ans += max(p-q, 0)
print(ans)

Submission status: Wrong Answer

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

L.sort()
import bisect
ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        b = L[i]
        c = L[j]
        p = bisect.bisect_left(L, b+c)
        q = bisect.bisect_right(L, c)
        ans += max(p-q, 0)
print(ans)

Submission status: Wrong Answer

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

ll = sorted(ll)

import bisect

ans = 0
for i in range(n):
    for j in range(i+1, n):
        k = ll[i] + ll[j]
        idx1 = bisect.bisect_left(ll, ll[j])
        idx2 = bisect.bisect_left(ll, k)
        ans += idx2 - idx1 - 1
print(ans)

Submission status: Wrong Answer

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

ll = sorted(ll)

import bisect

ans = 0
for i in range(n):
    for j in range(i+1, n):
        k = ll[i] + ll[j]
        idx1 = bisect.bisect_right(ll, ll[j])
        idx2 = bisect.bisect_left(ll, k)
        ans += idx2 - idx1
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
N=int(input())
L=list(map(int,input().split()))
cmlist=list(itertools.combinations(L,3))
ans=0
for i in cmlist:
  for j in i:
    if j>sum(i)-j:
      ans+=1
print(len(cmlist)-ans)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
l = [int(i) for i in input().split()]
count = 0
l_new = sorted(l)
for i in range(N-2):
    for j in range(i+1,N-1):
        left = bisect.bisect_right(l_new,abs(l_new[i]-l_new[j]))
        right = bisect.bisect_left(l_new,l_new[i] + l_new[j])
        count += right - left
        
        
print(count//3)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
l = [int(i) for i in input().split()]
count = 0
l_new = sorted(l)
for i in range(N-2):
    for j in range(i+1,N-1):
        left = bisect.bisect_right(l_new,abs(l_new[i]-l_new[j]))
        right = bisect.bisect_left(l_new,l_new[i] + l_new[j])
        count += right - left
        
        if left <= i < right:
            count -= 1
        if left <= j < right:
            count -= 1
print(count//3)

Submission status: Wrong Answer

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

L.sort()
import bisect
ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        b = L[i]
        c = L[j]
        p = bisect.bisect_left(L, b+c)
        q = bisect.bisect_right(L, max(b,c))
        ans += max(p-q, 0)
print(ans)

Submission status: Wrong Answer

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

L.sort()
import bisect
ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        b = L[i]
        c = L[j]
        p = bisect.bisect_left(L, b+c)
        q = bisect.bisect_right(L, max(b,c))
        ans += p-q
print(ans)

Submission status: Wrong Answer

Solution code:
n =int(input())
l = [ int(i) for i in input().split()]
list.sort(l)
count=0
for a in range(len(l)-2):
    for b in range(a+1,len(l)-1):
        print("a=={}, b=={}, cmax=={}".format(l[a],l[b], l[ len(l)-1]))
        LR = [b+1, len(l)-1]
        if l[a] + l[b] > l[ len(l)-1]:
            count+=len(l)-b-1
            print("patternA___la==={}, lb==={}, count==={}".format(l[a], l[b], count))
        elif l[a]+l[b]<=l[b+1]:
            print("patternB___la==={}, lb==={}, count==={}".format(l[a], l[b],0))
        else:
            while LR[1]-LR[0]>1:
                mid = int(0.5*(l[LR[0]]+l[LR[1]]))
                if mid > a+b:
                    LR[1] = int(0.5*(LR[0]+LR[1]))
                else:
                    LR[0] = int(0.5*(LR[0]+LR[1]))
                print("LR=={}".format(LR))
            count+=l.index(l[LR[0]])-b
print(count)

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())

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

zzz = list(itertools.combinations(l,2))


cnt = 0

for z in zzz:

    b = z[0]
    c = z[1]

    b_flg = True

    c_flg = True

    for i in l:
        if b_flg and i == b:
            continue

        if c_flg and i == c:
            continue
                
        if abs(b-c) < i < b+c:
            cnt += 1

print(cnt / 3)

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())

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

zzz = list(itertools.combinations(l,2))


cnt = 0
print(zzz)

for z in zzz:

    b = z[0]
    c = z[1]

    b_flg = True

    c_flg = True

    for i in l:
        if b_flg and i == b:
            continue

        if c_flg and i == c:
            continue
                
        if abs(b-c) < i < b+c:
            cnt += 1

print(cnt / 3)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = sorted(list(map(int, input().split())))
count = 0
i = n-1
for a in L[::-1]:
    j = 0
    for b, c in zip(L[:i-1], L[1:i]):
        if a < b + c:
            count += (i-j-1)*(i+j)//2
            break
        j += 1
    i -= 1
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

C = np.bincount(L,minlength=2100)
S = np.cumsum(C)

ans = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue

        left = abs(L[i]-L[j])
        right = L[i]+L[j]
        tmp = S[right]-S[left]

        if left <= L[i] <= right:
            tmp -= 1
        if left <= L[j] <= right:
            tmp -= 1
        ans += max(0, tmp)

print(ans//6)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

C = np.bincount(L,minlength=2010)
S = np.cumsum(C)

ans = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue

        left = abs(L[i]-L[j])
        right = L[i]+L[j]
        tmp = S[right]-S[left]

        if left <= L[i] <= right:
            tmp -= 1
        if left <= L[j] <= right:
            tmp -= 1
        ans += max(0, tmp)

print(ans//6)