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:
n = int(input())
l = sorted(list(map(int, input().split())))
s = 0
for i in range(0,n-2):
  a = l[i]
  for j in range(i+1,n-1):
    b = l[j]
    for k in range(j+1,n-2):
      c = l[k]
      if(a+b<c):
        s += n-k
        break
        
print(n*(n-1)*(n-2)//6 - s)

Submission status: Wrong Answer

Solution code:
import re
import itertools

N = int(input())
Lmat = input().split()

Lmatint = []
for i in range(len(Lmat)):
    Lmatint.append(int(Lmat[i]))
Lmatint.sort()

Lcnt = []
for i in range(1,1000):
    Lcnt.append(Lmatint.count(i))

Lcnt_three = []
for i in range(len(Lcnt)):
    if Lcnt[i]==0:
        Lcnt_three.append(0)
    elif Lcnt[i]==1:
        Lcnt_three.append(1)
    elif Lcnt[i]==2:
        Lcnt_three.append(2)
    else:
        Lcnt_three.append(3)

newLmat = []
for Lcnt_three_index,Lcnt_three_value in enumerate(Lcnt_three):
    if Lcnt_three_value == 1:
        newLmat.append(Lcnt_three_index+1)
    if Lcnt_three_value == 2:
        newLmat.append(Lcnt_three_index+1)
        newLmat.append(Lcnt_three_index+1)
    if Lcnt_three_value == 3:
        newLmat.append(Lcnt_three_index+1)
        newLmat.append(Lcnt_three_index+1)
        newLmat.append(Lcnt_three_index+1)

Lmatint = newLmat
#print(newLmat)
#全パターン選ぶ
allpatern = list(itertools.combinations(range(len(newLmat)), 3))
sum = 0
def iftriangle(first,second,third):
    if Lmatint[first]>=Lmatint[second]+Lmatint[third]:
        return 0
    elif Lmatint[second]>=Lmatint[first]+Lmatint[third]:
        return 0
    elif Lmatint[third]>=Lmatint[first]+Lmatint[second]:
        return 0
    else:
        return 1
for patern in allpatern:
    first = patern[0]
    second = patern[1]
    third = patern[2]
    sum += iftriangle(first,second,third)
print(sum)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
L = list(map(int,input().split()))
count = 0

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

Submission status: Wrong Answer

Solution code:
# D - Triangles
N = int(input())
L = list(map(int, input().split()))

L.sort(reverse=True)
count = 0

for i in range(N-2):
    if L[i+2] < L[i+1]+L[i] and L[i+1] < L[i+2]+L[i] and L[i] < L[i+1]+L[i+2]:
        count += 1
    else:
        pass

print(count)

Submission status: Wrong Answer

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

listl.reverse()
#print(listl)
ans=0
for i in range(n-2):
	for j in range(i+1,n-1):
		if listl[j]<=(listl[i]/2):
			break
		for k in range(j+1,n):

			if listl[i]<listl[j]+listl[k]:
				ans=ans+1
			else:
				break	
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

N=[int(x)for x in input().split()]
D=[int(x) for x in input().split()]

D.sort(reverse=True)
total=0

def check(a,b,c): #3
    if(a<b+c):
        if(b<a+c):
            if(c<a+b):
                return True
    return False

for i in range(len(D)-1):
    for j in range(i+1,len(D)-1):
        #print("i="+str(i)+" j="+str(j))
        v=D[i]-D[j]
        # print(D[:j:-1])
        # print("v="+str(v))
        #print(bisect.bisect_left(D[:j:-1],v))
        total+=  bisect.bisect_left(D[:j:-1],v)


        # for k in range(j + 1, len(D)):
        #     if(check(D[i],D[j],D[k])):
        #         total+=1
        #         print(str(i)+" "+str(j)+" "+str(k)+"   "+str(total))


print(total)

Submission status: Wrong Answer

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

  result=0
  dic={}
  dic[0]=0

  for i in range(1,a[-1]+10000):
    if i in a:
      dic[i]=dic[i-1]+1
    else:
      dic[i]=dic[i-1]

  #print(dic)

  for i in range(n-2):
    for j in range(i+1,n-1):
      if a[i]+a[j]>a[j+1]:
        temp=a[i]+a[j]
        #print(temp,a[j],a[-1])
        result+=dic[min(a[-1],temp-1)]-dic[a[j]]
        #print(a[i],a[j],a[j+1:],result)

  print(result)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

L.sort()

dp = [0]*(1005)
frm = 0
cnt = 0
Lcopy = [1001] + L[::-1]
while Lcopy:
  to = Lcopy.pop()
  for i in range(frm, to):
    dp[i] = cnt
  frm = to
  cnt += 1
  
ans = 0
b = 1
c = 2
while b < N-1:
  sub = L[c] - L[b]

  x = dp[L[b]-1] - dp[sub-1]
  if x > 0:
    ans += x
  else:
    b += 1
    c = b
    
  c += 1
  if c >= N:
    b += 1
    c = b + 1

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort(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]:
        cnt+=1
      if l[n+j-k]<l[i]+l[j]:
        cnt+=1
      if l[i]+l[j]<=l[n+j-k]:
        break
      if l[j]+l[k]<=l[i]:
        break
print(cnt//2)

Submission status: Wrong Answer

Solution code:
import bisect

def main():
    n = int(input())
    l_s = list(sorted(map(int, input().split(' '))))

    ans = 0

    for a in range(n-2):
        for c in range(a+2, n):
            if a < int(c/2):
                continue
            idx = bisect.bisect_left(l_s, c - a)
            ans += max(0, (c - idx)-1)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
ans = 0
data = [[] for _ in range(n)]
for i in range(1, n - 1):
    for j in range(i + 1, n):
        data[i - 1].append((l[i], l[j]))

for i in range(n - 2):
    for b, c in data[i]:
        a = l[i]
        if a < b + c and b < c + a and c < a + b:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
num = int(input())
pole_list = sorted([int(item) for item in input().split()])

cnt = 0

for a in pole_list:
    
    b_list = [b for b in pole_list if b >= a]
    for b in b_list:

        c_list = [c for c in b_list if c < a + b]
        for c in c_list:
            if a < b +c and b <a + c and c < b + a:
                cnt +=1

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import add, mul
from functools import reduce
import bisect


def nCr(n, r):
    r = min(r, n - r)
    num = reduce(mul, range(n, n - r, -1), 1)
    den = reduce(mul, range(1, r + 1), 1)
    return num // den


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

c = Counter(L)
l = list(c.keys())
l.sort()
len_l = len(l)
ans = 0

for li in l:
    if c[li] >= 3:
        ans += nCr(c[li], 3)

if len_l >= 2:
    for i in range(len_l - 1):
        for j in range(i + 1, len_l):
            if c[l[j]] >= 2:
                ans += nCr(c[l[j]], 2)
            if l[j] < 2 * l[i] and c[l[i]] >= 2:
                ans += nCr(c[l[i]], 2)

acu_cl = [0]
for li in l:
    acu_cl.append(acu_cl[-1] + c[li])

if len_l >= 3:
    for i in range(1, len_l - 1):
        for j in range(i + 1, len_l):
            k = bisect.bisect_left(l, l[j] - l[i] + 1, 0, i)
            if k < i:
                ans += c[l[i]] * c[l[j]] * (acu_cl[i] - acu_cl[k])

print(ans)

Submission status: Wrong Answer

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

sum = 0
for i,k in enumerate(L):
  for j in range(i+1, N):
    sum += bisect.bisect_right(L,L[j] + k) - j -1

print(sum)

Submission status: Wrong Answer

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

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

print(N*(N-1)*(N-2)//6 - c)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
ans = 0
C_more = [0 for _ in range(2001)]
C_less = [0 for _ in range(2001)]
for i in range(N):
    for j in range(L[i],2001):
        C_more[j] += 1
    for j in range(0,L[i]+1):
        C_less[j] += 1

C_less = [C_less[0]] + C_less

for i in range(N):
    for j in range(i):
        d = abs(L[i]-L[j])
        s = L[i]+L[j]
        if C_more[d+1] > 2 and C_less[s-1] > 2:
            ans += min(C_more[d+1]-2,C_less[s-1]-2)
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import copy
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))




N=one_int()
L=many_int()

L=sorted(L)

sankaku_dict={}
search_end={}
count=0
for i in range(len(L)-1):
    low=L[i]
    
    for j in range(i+1, len(L)):
        #すでに探索済みか判定
        temp = str(L[i]) +","+ str(L[j])
        if temp in search_end:
            continue
        high = L[j]
        Lcopy2 = L[j:]
        
        #下限を取得    
        under_index = bisect.bisect_right(Lcopy2,high-low)
        #上限を取得
        high_index = bisect.bisect_left(Lcopy2,high+low)
        
#         for va in Lcopy2[under_index:high_index]:
#             temp = sorted([high,low, va])
#             temp = (temp[0]*10**8) + (temp[1]*10**4) + temp[2]
#             sankaku_dict[temp]=1
        count+=len(Lcopy2[under_index:high_index])

# len(sankaku_dict)
print(count)
# print(len(sankaku_dict.keys()))

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
L = [i for i in map(int, input().split())]
ans = 0

L.sort()
print(L)
if N == 3:
    if L[0] + L[1] > L[2]:
        print("1")
        sys.exit()

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 += 1
                #print(L[i], L[j], L[k])
            else:
                #print("break")
                break
print(ans)

Submission status: Wrong Answer

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

def num_sticks(l, sticks=sticks):
	under = 0
	over = len(sticks)
	num_short_sticks = 0

	while (over - under) > 0:
		i_compare = (over + under) // 2
		stick_compare = sticks[i_compare]
		if l == stick_compare:
			num_short_sticks = i_compare + 1
			break
		elif l > stick_compare:
			num_short_sticks += i_compare + 1
			under = i_compare + 1
		else:
			over = i_compare

	return num_short_sticks

num_pattern = 0

for stick_1 in range(N - 1):
	a = sticks[stick_1]

	for stick_2 in range(stick_1 + 1, N - 1):
		b = sticks[stick_2]

		num_pattern += num_sticks(a + b)

print(num_pattern)

Submission status: Wrong Answer

Solution code:
n=int(input())
S=list(map(int, input().split()))
S.sort(reverse=True)
count=0
print(S)
for i in range(n-2):
    if(S[i]-S[n-1]-S[n-2])<0:
        break
    for j in reversed(range(i+2,n)):
        if(S[i]-S[j]-S[n-2])<0:
            break
        for k in reversed(range(i+1,j)):
            if(S[i]>=S[j]+S[k]):
                count=count+1
            else:
                break
print(int(n*(n-1)*(n-2)/6-count))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

result = 0
for i in range(N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            if L[i] < L[j] + L[k] and L[j] < L[i] + L[k] and L[k] < L[i] + L[j]:
                if L[i] + L[j] > L[-1]:
                    result += N - k
                    break;
                result += 1
            else:
                break

print(result)

Submission status: Wrong Answer

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

  result=0
  dic={}
  dic[0]=0

  for i in range(1,a[-1]+1):
    if i in a:
      dic[i]=dic[i-1]+1
    else:
      dic[i]=dic[i-1]

  #print(dic)

  for i in range(n-2):
    for j in range(i+1,n-1):
      if a[i]+a[j]>a[j+1]:
        temp=a[i]+a[j]
        #print(temp,a[j],a[-1])
        result+=dic[min(a[-1],temp-1)]-dic[a[j]]
        #print(a[i],a[j],a[j+1:],result)

  print(result)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort(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]:
        cnt+=1
      if l[n+j-k]<l[i]+l[j]:
        cnt+=1
      if l[i]+l[j]<=l[n+j-k]:
        break
      if l[j]+l[k]<=l[i]:
        break
print(cnt)

Submission status: Wrong Answer

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

L.sort()

dp = [0]*(1005)
frm = 0
cnt = 0
Lcopy = L[::-1]
while Lcopy:
  to = Lcopy.pop()
  for i in range(frm, to):
    dp[i] = cnt
  frm = to
  cnt += 1
  
ans = 0
b = 1
c = 2
while b < N-1:
  sub = L[c] - L[b]

  x = dp[L[b]-1] - dp[sub]
  if x > 0:
    ans += x
  else:
    b += 1
    c = b
    
  c += 1
  if c >= N:
    b += 1
    c = b + 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
length = list(map(int, input().split()))
length = sorted(length)
count = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(n-1, j+1, -1):
               if length[k] >= length[i]+length[j]:
                   pass
               else:
                   count += k-j+1
                   break
                
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

l = np.sort(l)[::-1]

tmp = 0
cnt = 0
for a in range(n):
    for b in range(a + 1, n):
        if l[b] <= tmp:
            break
        for c in range(b + 1, n):
            if l[a] < (l[b] + l[c]) and l[b] < (l[a] + l[c]) and l[c] < (l[a] + l[b]):
                cnt += 1
            else:
                tmp = c
                break

print(cnt)

Submission status: Wrong Answer

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


for i in range(n):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        if a == b:
            num = num + n - j
        else:
            for k in range(j+1, n):
                if l[k]<b+a:
                    num = num + 1
                else:
                    break




print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())
d = input().split()
d.sort()

li = []

temp = ''
for i in range(N):
    if(temp != d[i]):
        temp = d[i]
        li.append(int(d[i]))

sum = 0
N = len(li)
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in reversed(range(j+1,N)):
            if(int(li[i])<int(li[j])+int(li[k]) and int(li[j])<int(li[i])+int(li[k]) and int(li[k])<int(li[i])+int(li[j])):
                sum += k-j
                break
print(sum)

Submission status: Wrong Answer

Solution code:
import itertools

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

# itlist = list(itertools.combinations(L, 3))
# print(itlist)

count = 0

for i in range(len(L)):
  for j in range(i, len(L)-i):
    for k in range(j, len(L)-i):
      j_ = i + j
      k_ = i + k
      if i != j_ and j_ != k_ and k_ != i:
        #print(L[i], L[j_], L[k_])
        # print(i, j_, k_)
        # print(L[i], L[j_], L[k_])
        if L[i] + L[j_] > L[k_] and L[j_] + L[k_] > L[i] and L[k_] + L[i] > L[j_]:
          #print("OK")
          count += 1
        else:
          break
          
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int, input().split()))
ans = 0
A = [0]*max(L)
for i in range(n):
    A[L[i]-1] += 1
L.sort()
if L[0] == L[-1]:
    print(1)
else:
    for i in range(n-2):
        if L[i] != L[i-1]:
            for j in range(i+1, n-1):
                ans += sum(a for a in A[L[j]:L[i]+L[j]-1])
    print(ans)

Submission status: Wrong Answer

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

L.sort()

dp = [0]*(1005)
frm = 0
cnt = 0
Lcopy = L[::-1]
while Lcopy:
  to = Lcopy.pop()
  for i in range(frm, to):
    dp[i] = cnt
  frm = to
  cnt += 1
  
ans = 0
b = 1
c = 2
while b < N-1:
  sub = L[c] - L[b]

  x = dp[L[b]-1] - dp[sub-1]
  if x > 0:
    ans += x
  else:
    b += 1
    c = b
    
  c += 1
  if c >= N:
    b += 1
    c = b + 1

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    number_of_bars = int(input())
    bar_list = list(map(int,input().split()))
    print(traiangle_maker(bar_list))
    print(len(traiangle_maker(bar_list))//3)


def traiangle_maker(bar_list):
    bar_list.sort(reverse=True)
    result_list = []
    for i in range(len(bar_list)):
        for j in range(len(bar_list)):
            if i == j or bar_list[i] < bar_list[j]:
                continue
            minimum_length = bar_list[i] - bar_list[j]
            max_length = bar_list[i] + bar_list[j]
            for k in bar_list:
                if k < minimum_length:
                    continue
                if k > minimum_length and k < max_length and k != bar_list[i] and k != bar_list[j]:
                    traiangle = [bar_list[i],bar_list[j],k]
                    result_list.append(traiangle)

    return result_list


main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
num = int(input())
pole_list = sorted([int(item) for item in input().split()])

cnt = 0

for a in pole_list:
    
    b_list = [b for b in pole_list if b > a]
    for b in b_list:

        c_list = [c for c in b_list if c < a + b]
        for c in c_list:
            if a < b and b < c and a < c:
                cnt +=1

print(cnt)

Submission status: Wrong Answer

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

ans=0

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

Submission status: Wrong Answer

Solution code:
from itertools import combinations

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

def number_of_triangles():
    if N < 3:
        return 0
    L.sort()
    l = list(reversed(L))
    result = 0
    stop = False
    for ai in xrange(N):
        a = l[ai]
        stop = False
        for bi in xrange(ai + 1, N):
            b = l[bi]
            for ci in xrange(bi + 1, N):
                c = l[ci]
                if a < b + c and b < a + c and c < b + a:
                    result += 1
                else:
                    stop = True
            if stop:
                break
    return result

print number_of_triangles()

Submission status: Wrong Answer

Solution code:
N = int(input())
stick = sorted(list(map(int, input().split())), reverse=True)
answer= 0
for i in range(len(stick)):
  ans = 0
  a = stick[i]
  rem = stick[i+1:]
  for ci in range(1,len(rem)):
    c = rem[ci]
    b = rem[ci - 1]
    if a < b + c:
      answer += len(rem[ci:])
    else:
      break

print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
l_list = list(map(int, input().split()))
l_list.sort()
from bisect import *
ans = 0
for i in range(N):
    for j in range(i + 1, N - 1):
        a = l_list[i]
        b = l_list[j]
        low = max((abs(a - b), a, b))
        high = a + b
        id1 = bisect_right(l_list, high - 1)
        id2 = bisect_left(l_list, low + 1)
        for k in range(id2, id1):
            c = l_list[k]
            if a < b + c and b < c + a and a + b:
                ans +=1
print(ans)

Submission status: Wrong Answer

Solution code:
# D - Triangles
N = int(input())
L = list(map(int, input().split()))

L.sort(reverse=True)
count = 0

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

Submission status: Wrong Answer

Solution code:
N = int(input())
stick = sorted(list(map(int, input().split())), reverse=True)
answer= 0
for i in range(len(stick)):
  ans = 0
  a = stick[i]
  rem = stick[i+1:]
  for ci in range(1,len(rem)):
    c = rem[ci]
    b = rem[ci - 1]
    if a < b + c:
      answer += len(rem[ci:])

print(answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

#ls = [218, 786, 704, 233, 645, 728, 389]

ls = sorted(ls, reverse=True)
#print(ls)
result = 0

min_data = ls[-1]

#count = 0
size = len(ls)
for i in range(size):
    a = ls[i]
    for j in range(i+1, size):
        b = ls[j]
        if (b+min_data) > a:
            result += (size-j+1)
            break
        if not a > (b*2):
            for k in range(j+1, size):
                c = ls[k]
                #count += 1
                if a < (b+c):
                    result += 1
                else:
                    break

#print('count: ', count)
print(result)

Submission status: Wrong Answer

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

ret=0
for i in range(N):
    n=L_list[i]
    diff=0
    for j in range(i+1,N):
        k=L_list[j]
        m=n-k
        s=0
        for h in range(j+1,N):
            if L_list[h]>m:
                s=s+1
            else:
                break
        if s==0:
            break
        else:diff=diff+s

    if diff==0:
        break
    else:
        ret=ret+diff
print(ret)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
L = sorted(list(map(int,input().split())))
s = 0
if N < 10^3:
    for i in range(0,N-2):
        for k in range(i+1,N-1):
            for t in range(k+1,N):
                if L[t] >= L[i] + L[k]:
                    break
                else:
                    s += 1
else:
    s = N*(N-1)*(N-2)//6
    for i in range(N-400,400,-1):
        for k in range(399,i-1):
            for t in range(k+1,i):
                if L[i] < L[k] + L[t]:
                    break
                else:
                    s -= 1
print(s)

Submission status: Wrong Answer

Solution code:
num = int(input())
pole_list = [int(item) for item in input().split()]

cnt = 0

for a in pole_list:
    
    b_list = [b for b in pole_list if b > a]
    for b in b_list:

        c_list = [c for c in b_list if c < a + b]
        for c in c_list:
            if a < b and b < c and a < c:
                cnt +=1

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
l_list = list(map(int, input().split()))
l_list.sort()
from bisect import *
ans = 0
for i in range(N):
    for j in range(i + 1, N - 1):
        a = l_list[i]
        b = l_list[j]
        low = max((abs(a - b), a, b))
        high = a + b
        id1 = bisect_right(l_list, high - 1)
        id2 = bisect_right(l_list, low)
        for k in range(id2, id1):
            c = l_list[k]
            if a < b + c and b < c + a and a + b:
                ans +=1
print(ans)

Submission status: Wrong Answer

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

l.sort()

temp = 0
count = 0
flag = True
for i in range(n):
  for j in range(i+1, n):
    for k in range(j+1, n):
      if l[i]+l[j] > l[k]:
        count += 1
      #if l[-1-k]+l[-1-j] > l[-1-i]:
        #count += 1
      if i == n-k and j == n-j and k == n-i:
        flag = False
        break
    if flag == False:
      break
  if flag == False:
      break
      
print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import copy
args = sys.argv
if len(args) == 2:
  from IPython import embed
  em = True
else:
  em = False
input = sys.stdin.readline
N  = int(input())
Ls = list(map(int, input().split()))
if em: sys.stdin = open('/dev/tty')
L_map = [0 for _ in range(1000 + 1)]
for L in Ls:
  L_map[L] += 1
L_map_orig = copy.deepcopy(L_map)
ans = 0
for i in range(1, 1000):
  if L_map[i] == 0: continue
  a = L_map[i]
  L_map[i] -= 1
  for j in range(i, 1000 + 1):
    if L_map[j] == 0: continue
    b = L_map[j]
    L_map[j] -= 1
    if i == j:
      ans += int(a*(a-1)/2) * sum(L_map[max(j-i+1, j+1):i+j])
      if a >= 3:
        ans += int(a*(a-1)*(a-2)/6)
    else:
      ans += sum(L_map[max(j-i+1, j+1):i+j])
      if b >= 2:
        ans += int(b*(b-1)/2)
    L_map[j] = L_map_orig[j]
  L_map[i] = L_map_orig[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

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

count = 0

for combi in itertools.combinations(l_list, 3):
    a = combi[0]
    b = combi[1]
    c = combi[2]
    if a>b+c:
        continue
    if b>c+a:
        continue
    if c>a+b:
        continue
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = []
sum_t = 0
for x in range(n):
  for y in range(n):
    for z in range(n):
      c = sorted([x, y, z])
      if c not in b:
        b.append(c)
for i in range(len(b)):
  if (b[i][2]<b[i][0]+b[i][1] and b[i][1]<b[i][0]+b[i][2] and b[i][0]<b[i][1]+b[i][2]):
    sum_t += 1
print(sum_t)

Submission status: Wrong Answer

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

ans=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):
      c=L[k]
      if a<b+c and b<c+a and c<a+b:
        ans+=1
      else:
        break
        
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
L=sorted(list(map(int,input().split())))
dp=[0]*n
M=[]
dp[2]=0 if L[0]+L[1]>L[2] else 1
if dp[2]==0:
  M.append(L[0]+L[1])
if n!=3:
    for i in range(3,n):
        dp[i]=dp[i-1]
        N=[]
        for m in M:
          if L[i]>=m:
            dp[i]+=1
          else:
            N.append(m)
        M=N
        for j in range(i-1):
            if L[i-1]+L[j]<=L[i]:
                dp[i]+=1
            else:
                M.append(L[i-1]+L[j])
print(n*(n-1)*(n-2)//6-sum(dp))
print(dp)

Submission status: Wrong Answer

Solution code:
def binary_search(ls,target):
  result=-1
  left=0
  right=len(ls)-1
  if ls[right]>target:
    result=right+1
  else:
    while left<=right:
      center=(left+right)//2
      if ls[center]==target:
        result=center-1+1
        break
      elif ls[center]<target:
        right=center-1
      elif ls[center]>target:
        left=center+1
  if result==-1:
    return left
  else:
    return result
from collections import deque
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):
    c+=int(binary_search(l[j+1:],l[i]-l[j]))
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
l= list(map(int, input().split()))
a=0
list.sort(l, reverse=True)
for i in range(n-2):
    ten = l[0]
    l.pop(0)
    #print(ten,"/",l)
    se = 0
    for j in range(1,len(l)):
        if ten < l[0] + l[j] and l[j] < ten + l[0] and l[0] < l[j] + ten:
            #print("a++ : ",ten,"/",l[0],"/",l[j])
            a+=1
            se = j
        else:
            se = j-1
            break
    #print(se)
    for k in range(1,len(l)-1):
        #print(k)
        if ten < l[k] + l[se] and l[se] < ten + l[k] and l[k] < l[se] + ten:
            #print("a+=",(se) - k,": ",ten,"/",l[k],"/",l[se])
            a+=(se) - k
        else:
            break

print(a)

Submission status: Wrong Answer

Solution code:

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

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

Submission status: Wrong Answer

Solution code:
def count_sort(arr):
    max_num = max(arr)
    min_num = min(arr)
    count = [0] * (max_num - min_num + 1)
    for ele in arr:
        count[ele - min_num] += 1

    return [ele for ele, cnt in enumerate(count, start=min_num) for __ in range(cnt)]

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n = int(input())
L = list(map(int, input().split()))
L = count_sort(L)
count = cmb(n, 3)

for i, l1 in enumerate(L):
    for k, l2 in enumerate(L[i+1:]):
        num = i + k + 2
        for l3 in L[num:][::-1]:
            if l1 + l2 < l3:
                count -= 1
            else:
                break
            # if l1 < l2 + l3 and l2 < l1 + l3 and l3 < l2 + l1:
            #     count += 1
            # else:
            #     break

print(count)