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 numpy as np

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

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

# # 各数値が何個あるか
# C = [0]*(2010)
# for l in L:
#     C[l] += 1

# # 累積和を作成する
# S = [0]
# for i in range(2010):
#     S.append(S[i]+C[i])

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

        left = abs(L[i]-L[j])+1
        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:
n = int(input())
L = list(map(int, input().split()))

# 各数値が何個あるか
C = [0]*(2100)
for l in L:
    C[l] += 1

# 累積和を作成する
S = [0]
for i in range(2100):
    S.append(S[i]+C[i])

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

# 各数値が何個あるか
C = [0]*(2100)
for l in L:
    C[l] += 1

# 累積和を作成する
S = [0]
for i in range(1, 2100):
    S.append(S[i-1]+C[i])

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 collections
N=int(input())
L=list(map(int,input().split()))
l=[]
L.sort()
lis=[0]*(max(L)+1)
cnt=0
ans=0
c=collections.Counter(L)
values=list(c.values())	#aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
key=list(c.keys())	#先のvalue値に相当する要素のリスト(要素1,要素2,…)
l1=0
l2=0
mi=0
ma=0
le=0
for i in range(len(key)):
    l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
l.sort(key=lambda x:x[0])
#print(lis,L)
for i in range(max(L)+1):
    #print(cnt)
    cnt=cnt+c[i]
    lis[i]=cnt
for i in range(len(L)-1):
    for j in range(i+1,len(L)):
        l1=L[i]
        l2=L[j]#l1<=l2
        ma=min(l1+l2-1,L[len(L)-1])
        mi=max(l2-l1+1,L[0])
        le=lis[ma]-lis[mi-1]
        if mi<=l1<=ma:
            le=le-1
        if mi<=l2<=ma:
            le=le-1
        #print(l1, l2,c[l1],c[l2],ma,mi,le)
        ans=ans+c[l1]*c[l2]*max(le,0)
print(ans//3)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
L=list(map(int,input().split()))
l=[]
L.sort()
lis=[0]*(max(L)+1)
cnt=0
ans=0
c=collections.Counter(L)
values=list(c.values())	#aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
key=list(c.keys())	#先のvalue値に相当する要素のリスト(要素1,要素2,…)
l1=0
l2=0
mi=0
ma=0
le=0
for i in range(len(key)):
    l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
l.sort(key=lambda x:x[0])
print(lis,L)
for i in range(max(L)+1):
    #print(cnt)
    cnt=cnt+c[i]
    lis[i]=cnt
for i in range(len(L)-1):
    for j in range(i+1,len(L)):
        l1=L[i]
        l2=L[j]#l1<=l2
        ma=min(l1+l2-1,max(L))
        mi=max(l2-l1+1,min(L))
        le=lis[ma]-lis[mi-1]
        if mi<=l1<=ma:
            le=le-1
        if mi<=l2<=ma:
            le=le-1
        print(l1, l2,c[l1],c[l2],ma,mi,le)
        ans=ans+c[l1]*c[l2]*max(le,0)
print(ans//3)

Submission status: Wrong Answer

Solution code:
#import copy
#import numpy as np
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


def sol(n, l):
    import bisect
    l.sort()
    ans = 0
    #print(l)
    for i in range(n-1):
        for j in range(i+1, n):
            ji = l[j]+l[i]
            ind = bisect.bisect_right(l, ji)
            #print(i,j,ind,ind-j-1)
            ans += ind-j-1
    return ans


def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int, input().split()))
    print(sol(n, l))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

L=sorted(L, reverse=True)
count=0
for i in range(0, N-2):
    stop_count = 0
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            print(i, j, k)
            if L[i] < L[j] + L[k]:
                count+=1
                stop_count=1
        if stop_count==0:
            break


print(count)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
from collections import Counter

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

def bisect(a, b):
    # abs(a - b) < c < a + b
    c_u = a + b
    posi_u = len(L_list)+1
    nega_u = 0
    if c_u > L_list[-1]:
        u = L_list[-1]
        u_index = ruiseki_dict[u]
    else:
        while posi_u - nega_u > 1:
            median = (posi_u + nega_u) // 2
            if L_list[median] > c_u:
                posi_u = median
            elif L_list[median] < c_u:
                nega_u = median
            else:
                posi_u = median
                nega_u = median
                break
        if L_list[posi_u] < c_u:
            median = posi_u
        else:
            median = nega_u
        
        u = L_list[median-1]
        u_index = ruiseki_dict[u]
        
    c_l = abs(a - b)
    posi_l = len(L_list)+1
    nega_l = 0
    if c_l < L_list[0]:
        l = L_list[0]
        l_index = 0
        l -= 1
    else:
        while posi_l - nega_l > 1:
            median = (posi_l + nega_l) // 2
            if L_list[median] > c_l:
                posi_l = median
            elif L_list[median] < c_l:
                nega_l = median
            else:
                posi_l = median
                nega_l = median
                break
                
        if L_list[posi_l] < c_l:
            median = posi_l
        else:
            median = nega_l
        
        l = L_list[median]
        l_index = ruiseki_dict[l]
    
    check = 0
    if l < a <= u:
        check += 1
    if l < b <= u:
        check += 1
    #print('---------')
    #print((a, b))
    #print('---')
    #print(c_l, c_u)
    #print('---')
    #print(l, u)
    #print('---')
    #print(l_index, u_index, check)
    
    c = u_index - l_index - check
    if c < 0:
        return 0
    else:
        return c

L.sort()
L_set = set(L)
L_list = list(L_set)
L_list.sort()

count = Counter(L)
ruiseki = 0
ruiseki_dict = dict()
for k, v in count.items():
    ruiseki += v
    ruiseki_dict[k] = ruiseki
    
comb = combinations(L, 2)

amount = 0
for a, b in comb:
    amount += bisect(a, b)
    
print((amount+1)//3)

Submission status: Wrong Answer

Solution code:
n = int(input())
line = list(input().split(" "))
a = {}
for i in range(n):
    num = int(line[i])
    if num in a:
        a[num] += 1
    else:
        a[num] = 1
a = sorted(a.items())
b = []
sum = 0
for i in range(len(a)):
    sum += a[i][1]
    b.append(sum)
result = 0
for i in range(len(a)):
    for j in range(i+1,len(a)-1):
        k = 1
        while True:
            if j+k > len(a)-1:
                result += a[i][1]*a[j][1]*(b[j+k-1]-b[j])
                break
            if a[j+k][0] >= a[i][0] + a[j][0]:
                result += a[i][1]*a[j][1]*(b[j+k-1]-b[j])
                break
            k += 1
print(result)

Submission status: Wrong Answer

Solution code:
import bisect


def main(ls):
    total = 0

    for i in range(len(ls) - 2):
        for j in range(i + 1, len(ls) - 1):
            a = ls[i]
            b = ls[j]
            left = j + 1
            if a + b == ls[left]:
                 num = 0
            else:
                 num = bisect.bisect_right(ls, a + b) - left
            total += num

    print(total)


_n = input()
ls = list(sorted(map(int, input().strip().split())))

main(ls)

Submission status: Wrong Answer

Solution code:
# import numpy as np
import bisect

def main(ls):
    total = 0

    for i in range(len(ls) - 2):
        for j in range(i + 1, len(ls) - 1):
            a = ls[i]
            b = ls[j]
            ls2 = ls[j + 1:]
            if a + b == ls2[0]:
                 num = 0
            else:
                 # num = np.searchsorted(ls2, a + b, side='right')
                 num = bisect.bisect_right(ls2, a + b)
            total += num

    print(total)


_n = input()
ls = list(sorted(map(int, input().strip().split())))

main(ls)

Submission status: Wrong Answer

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

dic = {}
ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    tmp = l[i] + l[j]
    
    index2 = dic.get(tmp, -1)
    
    if index2 == -1:
      index2 = bisect.bisect_left(l, tmp)
      dic[tmp] = index2
      
    index1 = dic.get(l[j], -1)
    if index1 == -1:
      index1 = bisect.bisect_left(l, l[j])
      dic[l[j]] = index1     
    
    if l[i] == l[j]:
      d = index2 - index1 - 2
    else:
      d = index2 - index1 - 1
    
    ans += d if d > 0 else 0
    
print(ans)

Submission status: Wrong Answer

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

dic = {}
ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    tmp = l[i] + l[j]
    
    index2 = dic.get(tmp, -1)
    
    if index2 == -1:
      index2 = bisect.bisect_left(l, tmp)
      dic[tmp] = index2
      
    index1 = dic.get(l[j], -1)
    if index1 == -1:
      index1 = bisect.bisect_left(l, l[j])
      dic[l[j]] = index1     
    
    if l[i] == l[j]:
      d = index2 - index1 - 2
    else:
      d = index2 - index1 - 1
    
    ans += max(d,0)
    
print(ans)

Submission status: Wrong Answer

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

dic = {}
ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    tmp = l[i] + l[j]
    
    if tmp in dic.keys():
      index2 = dic[tmp]
    else:
      index2 = bisect.bisect_left(l, tmp)
      dic[tmp] = index2
      
    if l[j] in dic.keys():
      index1 = dic[l[j]]
    else:
      index1 = bisect.bisect_left(l, l[j])
      dic[l[j]] = index1
      
    
    if l[i] == l[j]:
      d = index2 - index1 - 2
    else:
      d = index2 - index1 - 1
    
    ans += d
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = {int(_) for _ in input().split()}
l = list(l)
len_l = len(l)
ans = 0

if len_l < 3:
    ans = 0
else:
    list.sort(l, reverse=True)
    for s in range(len_l):
        a = l[s]
        t = s + 1
        while t <= len_l - 1:
            b = l[t]
            if a >= 2 * b:
                break
            u = t + 1
            while u <= len_l - 1:
                c = l[u]
                if a < b + c and b < c + a and c < a + b:
                    ans += 1
                u += 1
            t += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = {int(_) for _ in input().split()}
l = list(l)
len_l = len(l)
ans = 0

for s in range(len_l):
    a = l[s]
    t = s + 1
    while t <= len_l - 1:
        b = l[t]
        u = t + 1
        while u <= len_l - 1:
            c = l[u]
            if a < b + c and b < c + a and c < a + b:
                ans += 1
            u += 1
        t += 1

print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    tmp = l[i] + l[j]
    
    d = bisect.bisect_left(l, tmp) - bisect.bisect_right(l, l[j])
    ans += d
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left

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

L.sort()
print(L)
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: Wrong Answer

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

count = 0
for i in range(N):
  for j in range(i+1,N):
    if i != j:
      for k in range(j+1,N):
        if i !=k and j !=k: 
          if S[i] + S[j] > S[k] and S[j] + S[k] > S[i] and S[k] + S[i] > S[j] :
            print(i,j,k)
            count +=1

print(count)

Submission status: Wrong Answer

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

count = 0
for i in range(N):
  for j in range(i+1,N):
    if i != j:
      for k in range(i+2,N):
        if i !=k and j !=k: 
          if S[i] + S[j] > S[k] and S[j] + S[k] > S[i] and S[k] + S[i] > S[j] :
            count +=1

print(count)

Submission status: Wrong Answer

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

count = 0
for i in range(N):
  for j in range(i+1,N):
    if i != j:
      for k in range(i+2,N):
        if i !=k and j !=k: 
          if S[i] + S[j] > S[k] and S[j] + S[k] > S[i] and S[k] + S[i] > S[j] :
            print(i,j,k)
            count +=1

print(count)

Submission status: Wrong Answer

Solution code:
import sys
import heapq


def input():
    return sys.stdin.readline()[:-1]


if __name__ == "__main__":
    N = int(input())
    L = sorted(list(map(int, input().split())), reverse=True)
    cnt = 0
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            for k in range(j+1, N):
                if L[i] < L[j] + L[k]:
                    print(L[i], L[j], L[k])
                    cnt += 1
    print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect

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

    ans = 0

    L = sorted(L)

    for i in range(N):
        a = L[i]
        for j in range(i+1, N):
            b = L[j]
            low = j
            high = N
            limit = a + b
            c = bisect.bisect(L, limit, lo = low, hi = high)

            if c < N:
                if (L[c] != a+b):
                    ans = ans + (c-j-1)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
L.sort()
count = 0
for k in range(N-1,1,-1):
  for j in range(0,k-1):
    if L[k] < L[j] + L[j+1]:
      count = count + (len(L[j:k])*len(L[j+1:k]))//2
      j = k-2
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
L.sort()
count = 0
for k in range(2,N):
  for j in range(0,k-1):
    if L[k] < L[j] + L[j+1]:
      count += (len(L[j:k])*len(L[j+1:k]))//2
    else:
      pass
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

from itertools import combinations
from bisect import bisect_right,bisect_left

comb=combinations(L, 2)
cnt=0
for cb in comb:
    b,c=min(cb), max(cb)
    # a must be b or lower
    hi=bisect_left(L, b)
    low=bisect_right(L, c-b)
    #print(b,c,hi,low)
    cnt+=max(0,hi-low)
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
L = sorted(list(map(int,input().split())),reverse = False)
print(L)
cnt = 0
for a in range(0,N-2):
    A = L[a]
    for b in range(a+1,N-1):
        B = L[b]
        for c in range(b+1,N):
            C = L[c]
            if(A+B > C):
                cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect

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

l.sort()
a = sorted(list(set(l)))
ans = 0

for b in range(n - 2):
    for c in range(b + 1,n - 1):
        left = bisect.bisect_left(a,l[c] + l[b])
        ans+=left - c - 1

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
li=list(map(int,input().split()))
li.sort()
result=[]
count=0
def bis(li,target):
    result=None
    left=0
    right=len(li)-1
    while left<=right:
        mid=(left+right)//2
        if li[mid]==target:
            result=mid
            break
        elif li[mid]>target:
            right=mid-1
        else:
            left=mid+1
    if result==None:
        return left-1#left番目まで数えればよい
    else:
        getter=result#例えば、[7,7,7]のとき真ん中の7のインデックスがgetterに格納されることになる。
        for i in range(0,getter):
                return getter-i#例の時、[6,7...]なら6のインデックスを取得

for i in range(0,N-1):
    for j in range(i+1,N):#li[i]+li[j]の値以上の値を発見し、その値より一以上小さい値のインデックスを取得。次にその値とj+1の間の要素数をカウント
        target=li[i]+li[j]
        searchindex=bis(li,target)
        count+=searchindex-j
print(count)

Submission status: Wrong Answer

Solution code:
import bisect

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

l.sort()
a = sorted(list(set(l)))
ans = 0

for b in range(1,n - 1):
    for c in range(b + 1,n):
        left = bisect.bisect_left(l,l[c] - l[b] + 1)
        right = bisect.bisect_right(l,l[b])
        ans+=max(0,right - left - 1)

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

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

l.sort()
a = sorted(list(set(l)))
ans = 0

for b in range(1,n - 1):
    for c in range(b + 1,n):
        left = bisect.bisect_left(a,l[c] - l[b] + 1)
        right = bisect.bisect_right(a,l[b]+1)
        ans+=max(0,right - left - 1)

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

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

l.sort()
a = sorted(list(set(l)))
ans = 0

for b in range(1,n - 1):
    for c in range(b + 1,n):
        left = bisect.bisect_left(a,l[c] - l[b] + 1)
        right = bisect.bisect_right(a,l[b])
        ans+=max(0,right - left - 1)

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

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

l.sort()
a = sorted(list(set(l)))
ans = 0

for b in range(1,n - 1):
    for c in range(b + 1,n):
        left = bisect.bisect_left(a,l[c] - l[b] + 1)
        right = bisect.bisect_right(a,l[b])
        ans+=max(0,right - left - 1)

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

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

l.sort()
a = list(set(l))
ans = 0

for b in range(1,n - 1):
    for c in range(b + 1,n):
        left = bisect.bisect_left(a,l[c] - l[b] + 1)
        right = bisect.bisect_right(a,l[b])
        ans+=max(0,right - left - 1)

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

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

l.sort()
a = list(set(l))
ans = 0

for b in range(1,n - 1):
    for c in range(b + 1,n):
        left = bisect.bisect_left(a,l[c] - l[b] + 1)
        right = bisect.bisect_right(a,l[b] + 1)
        ans+=max(0,right - left)

print(ans)

Submission status: Wrong Answer

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

while True:
	N1 = s.pop()
	i, k = -1, -2
	if len(s) < 2:
		break
	while True:
		if s[i] + s[k] > N1 and s[i] + N1 > s[k] and s[k] + N1 > s[i]:
			count +=1
			i -= 1
			k -= 1
			if k == (len(s) + 1)* -1:
				break
		else:
			break
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
L = map(int, input().split())
C = Counter(L)
L = list(C.keys())
L.sort()
ans = 0
for i in range(len(L) - 2):
    for j in range(i + 1, len(L) - 1):
        for k in range(j + 1, len(L)):
            if L[i] + L[j] > L[k]:
                ans += C[L[i]] * C[L[j]] * C[L[k]]
            else:
                break
print(ans)

Submission status: Wrong Answer

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

ls.sort()

dis = 0
for i in range(0, n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if ls[i] + ls[j] <= ls[k]: dis += 1

ans = (n*(n-1)*(n-2) / 6) - dis
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import numpy as np

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

hoge = np.sort(l)
ll = []
ans = 0

def triangle(target, v1, v2):
    return target < v1 + v2

for i in range(len(hoge)):
    for j in range(i + 1, len(hoge)):
        left = hoge[j]
        right = hoge[-1] + 1
        while left + 1 < right:
            mid = (left + right) / 2
            if triangle(mid, hoge[i], hoge[j]):
                ans += len(hoge[hoge >= mid])
                break
            else:
                left = mid

print(ans)

"""3回目
# 事前の各要素xより大きい要素個数を求める
for v in hoge:
    ll.append([v, len(hoge[v <= hoge])])

# 事前にコンビネーションを確保する。ループはしない！
combi = np.array([[sum(v), v[1]] for v in combinations(hoge, 2)])

print(combi)
print(combi[:, 0])
print(ll)

# 要素のループをもう一度回し、各
for v, cnt in ll:
    print(v, cnt, len(combi[(v < combi[:, 0]) & (combi[] < v)]), sep=',')
    ans += cnt * len(combi[v < combi])

print(ans)

"""


"""2回目 comnbinationループがだめ
for v in combinations(hoge, 2):
    s = sum(v)
    ans += len(hoge[(v[1] < hoge) & (hoge < s)])

"""



"""1
これだとTLEが出る
combinationの全パターンを数え上げると遅すぎる
ソート済み配列 × なにかで組み合わせを数え上げる必要

from itertools import combinations

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

ans = 0

for v in combinations(l, 3): # combination を使ってループした時点ででn^2
    if v[0] < v[1] + v[2] and v[1] < v[0] + v[2] and v[2] < v[0] + v[1]:
        ans += 1

print(ans)
"""

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import numpy as np

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

hoge = np.sort(l)
ll = []
ans = 0

def triangle(target, v):
    return target < v[0] + v[1]

for v in combinations(hoge, 2):
    left = v[1]
    right = hoge[-1] + 1
    while left + 1 < right:
        mid = (left + right) / 2
        if triangle(mid, v):
            ans += len(hoge[hoge >= mid])
            break
        else:
            left = mid

print(ans)

"""3回目
# 事前の各要素xより大きい要素個数を求める
for v in hoge:
    ll.append([v, len(hoge[v <= hoge])])

# 事前にコンビネーションを確保する。ループはしない！
combi = np.array([[sum(v), v[1]] for v in combinations(hoge, 2)])

print(combi)
print(combi[:, 0])
print(ll)

# 要素のループをもう一度回し、各
for v, cnt in ll:
    print(v, cnt, len(combi[(v < combi[:, 0]) & (combi[] < v)]), sep=',')
    ans += cnt * len(combi[v < combi])

print(ans)

"""


"""2回目 comnbinationループがだめ
for v in combinations(hoge, 2):
    s = sum(v)
    ans += len(hoge[(v[1] < hoge) & (hoge < s)])

"""



"""1
これだとTLEが出る
combinationの全パターンを数え上げると遅すぎる
ソート済み配列 × なにかで組み合わせを数え上げる必要

from itertools import combinations

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

ans = 0

for v in combinations(l, 3): # combination を使ってループした時点ででn^2
    if v[0] < v[1] + v[2] and v[1] < v[0] + v[2] and v[2] < v[0] + v[1]:
        ans += 1

print(ans)
"""

Submission status: Wrong Answer

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

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


def sol(n,l):
    import bisect
    l.sort()
    ans = 0
    #print(l)
    for i in range(n-1):
        for j in range(i+1,n):
            ji = l[j]+l[i]
            ind = bisect.bisect_left(l,ji)
            print(i,j,ind,ind-j-1)
            ans += ind-j-1
    return ans


def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int, input().split()))
    print(sol(n,l))

        
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


def sol(n,l):
    import bisect
    l.sort()
    a = []
    #print(l)
    for i in range(n-2):
        for j in range(i+2,n):
            ind = bisect.bisect_left(l,j-i+1,lo=i+1,hi=j+1)
            #print(i,j,ind)
            a.append(ind)
    return len(a)


def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int, input().split()))
    print(sol(n,l))

        
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


def sol(n,l):
    import bisect
    l.sort()
    a = []
    print(l)
    for i in range(n-2):
        for j in range(i+2,n):
            ind = bisect.bisect_left(l,j-i+1,lo=i+1,hi=j+1)
            print(i,j,ind)
            a.append(ind)
    return len(a)


def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int, input().split()))
    print(sol(n,l))

        
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
L_s = list(map(int,input().split()))
L_s.sort()
ITER = []
BISECT = []
for i in range(len(L_s)):
    if i == 0:
        ITER.append(L_s[i])
        BISECT.append(L_s[i])
        continue
    if not (L_s[i] == L_s[i-1]):
        BISECT.append(L_s[i])
    if i == 1:
        ITER.append(L_s[i])
        continue
    if not (L_s[i] == L_s[i-1] == L_s[i-2]):
        ITER.append(L_s[i])
answer = 0
for i in range(N-1):
    if i != 0 and L_s[i] == L_s[i-1]:
        continue
    for j in range(i+1,N):
        C = L_s[i] +  L_s[j]
        answer += bisect.bisect_left(BISECT,C) - bisect.bisect(BISECT,L_s[j])
        
        
print(answer)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

n = int(input().rstrip())
bo = [j * -1 for j in sorted([int(i) * -1 for i in input().rstrip().split(" ")])]

ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        canTriangle = True
        for k in range(j+1,n):
            if bo[j] + bo[k] < bo[i]:
                canTriangle = False
                break
            ans += 1
        if not canTriangle:
            break

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n  = int(input())
  Ls = list(map(int, input().strip().split()))
  Ls.sort()
  counts  = [0] * (2*10**3+1)
  for L in Ls:
    counts[L] += 1
  for i in list(range(1, len(counts)))[::-1]:
    counts[i-1] = counts[i-1] + counts[i]
    
  count =0 
  for i in range(n-2):
    for j in range(i+1, n-1):
      if Ls[i] == Ls[j]:
        x = 2
      else:
        x = 1
      count +=  max((counts[Ls[j]]-x) - counts[Ls[i]+Ls[j]], 0)
  print(count)
  
if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy
from math import ceil, floor

def main():
  n  = int(input())
  Ls = list(map(int, input().strip().split()))
  Ls = numpy.sort(numpy.array(Ls))
  counts  = numpy.zeros(2*10**3+1, dtype=numpy.int)
  for L in Ls:
    counts[:L+1] += 1
    
  count =0 
  for i in range(n-2):
    for j in range(i+1, n-1):
      if Ls[i] == Ls[j]:
        x = 2
      else:
        x = 1
      count +=  max((counts[Ls[j]-1]-x) - counts[Ls[i]+Ls[j]-1], 0)
  print(count)
  
if __name__=='__main__':
  main()

Submission status: Wrong Answer

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

counts = {}
x = v[0]
c = 0
for i in v:
    if i != x:
        counts[x] = c
        x = i
        c = 0
    c += 1
counts[x] = c

v1 = list(counts)

sums = [0]
for i in range(1, 1005):
    try:
        sums.append(v1.index(i))
    except ValueError:
        sums.append(sums[-1])


total = 0
for i, x in enumerate(v1[:-2]):
    if x == 1:
        continue
    for j, y in enumerate(v1[i+1:-1]):
        total += (sums[min(1004, x+y-1)] - sums[y])



for i, c in counts.items():
    if c >= 2:
        total += (sums[min(1004, 2*i-1)])
    if c >= 3:
        total += 1

print(int(total))

Submission status: Wrong Answer

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

counts = {}
x = v[0]
c = 0
for i in v:
    if i != x:
        counts[x] = c
        x = i
        c = 0
    c += 1
counts[x] = c

v1 = list(counts)

sums = [0]
for i in range(1, 1005):
    try:
        sums.append(v1.index(i))
    except ValueError:
        sums.append(sums[-1])


total = 0
for i, x in enumerate(v1[:-2]):
    if x == 1:
        continue
    for j, y in enumerate(v1[i+1:-1]):
        total += (sums[min(1004, x+y-1)] - sums[y])



for i, c in counts.items():
    if c >= 2:
        total += (sums[min(1004, 2*i-1)])




# v3
total += sum(True if c >= 3 else False for c in counts.values())


print(total)