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

L.sort()

sum = 0

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

print sum

Submission status: Wrong Answer

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

l_l.sort()
#print(l_l)

count=0
for i in range(n):
  for j in range(i+1,n):
    for k in range (j+1,n):
      #print(l_l[i],l_l[j],l_l[k])
      if(l_l[i]+l_l[j]<l_l[k]):
        #print(l_l[i],l_l[j],l_l[k])
        count +=1
      #else:
        #break
      
print(int(n*(n-1)*(n-2)/6-count))

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 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 += 1
            else:
                break
print(sum)

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)
        tmp = max(0, id1 - id2)
        ans += tmp
print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    l = sorted(map(int, input().split()))
    count = 0
    print(l)
    for i in range(n):
        for j in range(i+1,n):
            for k in range(j+1,n):
                if l[k]<l[i]+l[j]:
                    count += 1
                else:
                    break
    print(count)
    
    
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[int(x) for x in input().split()]
num_l=[0 for i in range(1001)]
num_l_range=[[0 for i in range(1001)] for i in range(1001)]
ans=0
for x in l:
  num_l[x]+=1
for i in range(1,1001):
  for j in range(0,i-1):
    num_l_range[i][j]=0
  num_l_range[i][i]=num_l[i]
  for j in range(i+1,1001):
    num_l_range[i][j]=num_l_range[i][j-1]+num_l[j]
for a in range(1,1001):
  if(num_l[a]==0):
    continue
  for b in range(a,1001):
    if(num_l[b]==0):
      continue
    ans+=num_l[a]*num_l[b]*num_l_range[b][min(a+b-1,1000)]
    if(a==b):
      ans-=num_l[a]*num_l_range[b][min(a+b-1,1000)]#a==b
      ans+=(-2)*(num_l[a]**2)+2*num_l[a]#a==b==c
    else:
      ans-=num_l[a]*num_l[b]#b==c
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = sorted(list(map(int,input().split())))
setl = sorted(set(l))
maxl = max(l)
csum = [0]*(maxl + 2)
cnt = [0]*(maxl + 2)
ans = 0
for i in l:
    cnt[i] += 1
    csum[i] += 1
for i in range(1,len(csum)):
    csum[i] += csum[i-1]

for a in setl:
    for b in setl:
        if a >= b:
            continue
        ans += csum[min(maxl,a + b - 1)] - csum[b]
for i in cnt:
    if i >= 3:
        ans += 1
for i in set(l):
    if cnt[i] == 2:
        for j in set(l):
            if i != j and (j < 2*i or 2*i < j):
                    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
sl = sorted(l)
cnt = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if k == n-1:
                cnt += k-j
                break
            elif sl[i]+sl[j] > sl[k]:
                continue
            else:
                cnt += k-j-1
                break

print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
L = np.array([int(l) for l in input().split(' ')])
ans = []
for i,a in enumerate(L[:-2]):
    for j,b in enumerate(L[i+1:-1]):
        if i != j:
            for k,c in enumerate(L[j+1:]):
                 if (i != k) & (j != k):
                        if (c>abs(a-b)) & (c<a+b):
                            ans.append(c)
                                                      
print(len(ans))

Submission status: Wrong Answer

Solution code:

import sys
input=sys.stdin.readline
n = int(input())
a = sorted(list(map(int,input().split())))
res = 0
i = 0
while i < n:
    j = i+1
    while j < n:
        yy = a[i]+a[j]
        for k in range(j+1,n):
            if yy > a[k]:res+=j-i
            else:
                break
        j+=1
    i=j
print(res)

Submission status: Wrong Answer

Solution code:
n=int(input())
L=list(map(int,input().split(" ")))
L.sort()
ans=0
for i in range(n-2):
	for s in range(i+1,n-1):
		if L[i]+L[s]>max(L[i:s])>abs(L[s]-L[i]):
			ans+=1



print(int(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() + 1
  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]] - dp[min(sub, L[b])]
  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:
from collections import deque

def hoge(A,B):
    sum = 0
    for i in range(B):
        sum += A
        A -= 1
    return sum

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

L.sort(reverse=True)

List = deque()
Sum = 0

for i in range(1, N - 1):
    for j in range(i + 1, N):
        List.append(L[i] + L[j])

for i in range(N - 2):
    print(hoge(N-i-2,i))
    for j in range(hoge(N-2,i),len(List)):
        if List[j] > L[i]:
            Sum += 1

print(Sum)

Submission status: Wrong Answer

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

l_l.sort()
#print(l_l)

count=0
for i in range(n):
  for j in range(i+1,n):
    for k in range (j+1,n):
      #print(l_l[i],l_l[j],l_l[k])
      if(l_l[i]+l_l[j]<l_l[k]):
        #print(l_l[i],l_l[j],l_l[k])
        count +=1
      #else:
        #break
      
print(n*(n-1)*(n-2)/6-count)

Submission status: Wrong Answer

Solution code:
import sys

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]


N=int(input())
L=input()
L=L.split()
L=[int(item) for item in L]
L.sort()
ans=1000
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]:
                ans-=(N-k)
                break


print(int(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
while (l[-1]>l[-2]+l[-3]) and (len(l)>3):
	del l[-1]
n=len(l)
ans=0
i=0
while i<n-2:
	j=i+1
	while j<n-1:
		k=j+1
		while k<n:
			if l[k]>l[i]+l[j]:
				ans=ans+k-j-1
				k=n
			elif k==n-1:
				ans=ans+k-j
			k=k+1
		j=j+1
	i=i+1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
sticks = sorted([int(s) for s in input().split()])
point = 0
 
for i in range(n-2):
  if sticks[i]*2 >= sticks[-1]:
    break
  else:
    for j in range(n - i- 2):
      a = sticks[i] + sticks[i+j+1]
      if a >= sticks[-1]:
        break
      else:
        for k in range(1,n):
          if sticks[-k] >= a:
            point+=1
          else:
            break

    
print(int(n*(n-1)*(n-2)/6)-point)

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-2
print(ans)

Submission status: Wrong Answer

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

l_l.sort()
print(l_l)

count=0
for i in range(n):
  for j in range(i+1,n):
    for k in range (j+1,n):
      print(l_l[i],l_l[j],l_l[k])
      if(l_l[i]+l_l[j]<l_l[k]):
        #print(l_l[i],l_l[j],l_l[k])
        count +=1
      #else:
        #break
      
print(count,n*(n-1)*(n-2)/6-count)

Submission status: Wrong Answer

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

l.sort()
#print(l)
cnt=0

for i in range(n-1,1,-1):
    flg=0
    for j in range(n-2):
        for k in range(j+1,i):
            if(l[j]+l[j+1]>l[i]):
                cnt=cnt+ (i-j)*(i-j-1)/2
                #print(i,j,j+1,l[i],l[j],l[j+1],cnt,"countup")
                flg=1
                break
            else:
                if(l[j]+l[k]>l[i]):
                    cnt = cnt + (i-k)
                    #print(i,j,j+1,l[i],l[j],l[k],cnt,"countup2")
                    break
                continue
        #print(i,j,j+1,l[i],l[j],l[j+1],cnt)
        if(flg==1):
            break
        
            


print(cnt)

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]
        result+=max(0,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 = [int(i) for i in input().split()]
l.sort()
cnt = 0
#print(l)
for i in range(2, len(l)):
    for j in range(i):
        for k in range(j+1, i):
            if l[i] < l[j] + l[k]:
                #print(l[j], l[k], l[i], ':', j, k, i, ':',(k-j) , (k-j)+(i-k-1),(i-k),':', ((k-j)+(k-j)+(i-k-1))*(i-k)//2)
                cnt = cnt + (((k-j)+(k-j)+(i-k-1))*(i-k))//2
                break
        else:
            continue
        break
print(cnt)

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-1):
        k=L_list[j]
        m=n-k
        s=0
        for h in range(j,N):
            if L_list[h]>m:
                s=s+1
            else:
                break
        diff=diff+s
        if s==0:
            break
    if diff==0:
        break
    else:
        ret=ret+diff
print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = [int(i) for i in input().split()]
L.sort()
M = [0 for i in range(2*10**3+1)]
C = [0 for i in range(2*10**3+1)]
L_num = [1]
cnt = 1
for i in range(N-1):
    if L[i+1] == L[i]:
        cnt += 1
    else:
        cnt = 1
    L_num.append(cnt)
for i in range(N):
    M[L[i]] += 1
for i in range(1, len(M)):
    C[i] = C[i-1] + M[i]
cnt = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        a = L[i]
        b = L[j]

        # abs(a-b) < c < a+b
        if b > abs(a-b):
            if a > 1:
                cnt += C[a+b-1] - C[b-1] - L_num[j]
        else:
            cnt += C[a+b-1] - C[abs(a-b)] - 2
print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
from operator import itemgetter

n = int(sys.stdin.readline().strip())
m = {}
for x in sys.stdin.readline().strip().split():
    x = int(x)
    m[x] = m.get(x,0) + 1

t = []
k = 0
cnt = 0
for x,y in sorted(m.items(),key=itemgetter(0)):
    for i in range(k):
        ti = t[i]
        for j in range(i+1,k):
            tj = t[j]
            if tj+x>ti and ti+tj>x: cnt+=1
    #
    t.append(x)
    k += 1
#
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int, input().split()))
l =sorted(L,reverse = True)
t = 0
for i in range(N-2):
  for k in range(i+1,N-1):
    for m in range(k+1, N):
      if l[i] < l[k] + l[m]:
        t += 1
      else:
        break
    else:
      continue
    break
print(t)

Submission status: Wrong Answer

Solution code:
import sys
import itertools


def create_triple(triple, start):
  if len(triple)==3:
    if triple[0]<triple[1]+triple[2] and triple[1]<triple[0]+triple[2] and triple[2]<triple[0]+triple[1]:
      ans.append(triple)
  
  for i in range(start, N):
    l = L[i]
    if l in triple: break
    create_triple(triple+[l], i+1)


N = int(sys.stdin.readline().strip())
L = [int(n) for n in sys.stdin.readline().strip().split()]
L = set(L)

if len(L)<3:
  print(0)
else:
  ans = []
  # create_triple([], 0)
  for triple in itertools.combinations(L,3):
    if triple[0]<triple[1]+triple[2] and triple[1]<triple[0]+triple[2] and triple[2]<triple[0]+triple[1]:
      ans.append(triple)
  print(len(ans))

Submission status: Wrong Answer

Solution code:
a = input()

a = int(a)

b = input().split(' ')

b.sort()

from itertools import combinations

comb = combinations(b, 3)

possible_triangles = 0

for i in list(comb):
    if int(i[2]) >= int(i[0]) + int(i[1]):
        continue
    possible_triangles += 1

print(possible_triangles)

Submission status: Wrong Answer

Solution code:
import itertools

stick_number = int(input())
sticks = list(map(int, input().split()))
sticks.sort() ## 小さい順に並べ直す

## print(stick_number)
## print(sticks)
result = 0

i1 = list(itertools.combinations(sticks, 3))
# print(len(i1))
for j in i1:
  # if abs(j[1] - j[2]) < j[0] < j[1] + j[2]:
  result += 1
    
print(result)

Submission status: Wrong Answer

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

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[min(sub, L[b]-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 = sorted(list(map(int,input().split())))
maxl = max(l)
csum = [0]*(maxl + 2)
cnt = [0]*(maxl + 2)
ans = 0
for i in l:
    cnt[i] += 1
    csum[i] += 1
for i in range(1,len(csum)):
    csum[i] += csum[i-1]

for i in range(n):
    for j in range(i + 1,n):
        a = l[i]
        b = l[j]
        if a== b:
            continue
        ans += csum[min(maxl,a + b - 1)] - csum[b]
for i in cnt:
    if i >= 3:
        ans += 1
for i in set(l):
    if cnt[i] == 2:
        for j in set(l):
            if i != j and (j < 2*i or 2*i < j):
                    ans += 1
print(ans)

Submission status: Wrong Answer

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

ans = 0
itr = True

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        if itr:
            l = L[i] - L[j]
            for h in range(j + 1, n):
                if L[h] <= l:
                    ans += h - j - 1
                    itr = False
                    break
            else:
                ans += h - j
        else:
            itr = True
            break


print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter

N = int(input())
l_list = Counter(list(map(int,input().split())))
ans = 0
for comb in  itertools.combinations(l_list.keys(), 3):
    if(comb[0] < comb[1]+comb[2] and comb[1] < comb[0]+comb[2] and comb[2] < comb[1]+comb[0]):
        ans += l_list[comb[0]] * l_list[comb[1]] * l_list[comb[2]]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import bisect
readline = sys.stdin.readline
n = int(readline())
A = list(map(int,readline().split()))
memo1 = {}
memo2 = {}
A.sort()
memo1[A[0]+A[1]] =1
memo2[A[0]] =1
if A[1] in memo2:
    memo2[A[1]] +=1
else:
    memo2[A[1]] =1
ans = 0
for c in A[2:]:
    for l,amount in memo1.items():
        if c<l:
            ans +=amount
    for a,amount in memo2.items():
        ac = a+c
        if ac in memo1:
            memo1[ac] +=1
        else:
            memo1[ac] = 1
    if c in memo2:
        memo2[c] +=1
    else:
        memo2[c] =1

print(ans)

Submission status: Wrong Answer

Solution code:

import sys
input=sys.stdin.readline
n = int(input())
a = sorted(list(map(int,input().split())))
res = 0
i = 0
while i < n:
    j = i+1
    while j < n:
        yy = a[i]+a[j]
        for k in range(j+1,n):
            if yy > a[k]:res+=j-i
            else:
                break
        j+=1
    i+=j+1
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = map(int, input().split())
SL = sorted(list(L))
A = [0] * (10 ** 3 + 10)

for i in SL:
    A[i] = True
for i in range(len(A)):
    if A[i] == True:
        A[i] = A[i-1] + 1
    else:
        A[i] = A[i-1]

# print(A[4-1] - A[2])

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        # for k in range(j+1, N):
        #     a = SL[i]
        #     b = SL[j]
        #     c = SL[k]
        #     if a < b + c and b < c + a and c < a + b:
        #         ans += 1
        a = SL[i]
        b = SL[j]
        for k in range(j+1, N):
            c = SL[i]
            if abs(a - b) > c:
                continue
            elif c > a + b:
                break
            else:
                ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
l=list(map(int,input().split()))
ans=[0]*N
for i in range(2,N):
  for j in range(0,i):
    if l[i] >= l[j]+l[j+1]:
      pass
    else:
      ans[i]=int(((i-j-1)*(i-j-2))/2)
      break
print(sum(ans))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
from bisect import bisect_right


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


ans = 0

for ib in range(0,N-2):
    for ic in range(ib+2, N):
        if L[ic] - L[ib] <= 0:
            continue
        if L[ic] - L[ib] > L[ib]:
            l = bisect_right(L, L[ic] - L[ib], lo=ib, hi=ic)
        else:
            l = bisect_left(L, L[ib], lo=ib, hi=ic) + 1

        #print(ib, ic,l, L[l], L[ic-1], ic-1)
        ans += max(ic - l , 0)

print(ans)

Submission status: Wrong Answer

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

#output
import heapq

L = [-l for l in L]
heapq.heapify(L)

sum = 0
for i in range(N-3):
    target = heapq.heappop(L)
    L.sort()
    for i in range(len(L)-1):
        for j in range(i+1, len(L)):
            if target > L[i] +  L[j]:
                sum += 1
        
print(sum)

Submission status: Wrong Answer

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

Li=[]
for i in range(N):
    Li.append(int(L[i]))

result=0
for a in range(N):
    for b in range(N):
        for c in range(N):
            if a!=b & a!=c & b!=c:
                if Li[a]<Li[b]+Li[c] & Li[b]<Li[c]+Li[a] & Li[c]<Li[a]+Li[b]:
                    result+=1
print(result)

Submission status: Wrong Answer

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

ans = 0

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

    
print(ans)

Submission status: Wrong Answer

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

L.sort()
print(L)
c=N-1
ans=0
while c>1:
  for i in range(c):
    for j in range(i+1,c):
      if L[c]<L[i]+L[j]:
        ans+=c-j
        break

  c-=1
print(ans)

Submission status: Wrong Answer

Solution code:

import sys
input=sys.stdin.readline
n = int(input())
a = sorted(list(map(int,input().split())))
res = 0
i = 0
while i < n:
    j = i+1
    while j < n:
        yy = a[i]+a[j]
        for k in range(j+1,n):
            if yy > a[k]:res+=j-i
            else:
                break
        j+=1
    i+=j-1
print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#D
n = int(input())
lb = list(map(int,input().split()))
###
defaultans = int(n*(n-1)*(n-2)/6)
###
lb.sort()
cnt = defaultans
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            a, b, c = lb[i], lb[j], lb[k]
            if a >=b+c:
                cnt -= n - k 
                break
print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect

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

l.sort()

ans = 0

print(l)
for i in range(n):
    for j in range(i+1, n):
        q = l[i]+l[j]
        p = bisect.bisect_left(l, q)
        ans += (p - j - 1)

print(ans)

Submission status: Wrong Answer

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

L_len = len(L)

L.sort(reverse=True)

count = 0
for i in range(L_len - 2):
    for j in range(i + 1, L_len - 1):
        left = j + 1
        right = L_len - 1
        length = L[i] - L[j]
        flag = 0

        while right - left >= 1:
            center = int((left + right)/2)
            if L[center] >= length:
                left = center + 1
                flag = 1
            else:
                right = center - 1
        
            if flag == 1:
                if L[left] <= length:
                    index = left - 1
                else:
                    index = left
                
                print(i, j)
                count += index - j

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

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

r = [0]
def he( l, r):
    m = {}    
    s = []
    t = [0] * 3
    for i in range(len(l)):
        num = l[i]
        t[0] = num
        for j in range(i+1, len(l)-1):
            t[1] = l[j]
            tm = t[0] + t[1]
            ks = j + 1
            if  tm in m:
                ks = m[tm]
                                
            for k in range(ks,  len(l)):
                t[2] = l[k]
                a, b, c = t[0], t[1], t[2]
                if a < b + c and b < a + c and c < b + a:
                    m[a+b] = k
                    r[0] += 1
                    
L = sorted(L, reverse=False)
print(L)
he(L, r)
print(r[0])

Submission status: Wrong Answer

Solution code:
N=int(input())
L=list(map(int, input().split()))
L.sort()
cnt=0
first=True
left=2

for i in range(0,N-2): 
  for j in range(i+1,N-1):
    for k in range(left,N):
      if L[k]<L[i]+L[j]:
        if L[i]<L[j]+L[k]:
          if L[j]<L[i]+L[k]:
            
            cnt+=1
            if first==True:
              left=k
              first=False
  left=j+1
      
print(cnt)

Submission status: Wrong Answer

Solution code:
from math import factorial
N=int(input())
L=input()
L=L.split()
L=[int(item) for item in L]
L.sort()

Submission status: Wrong Answer

Solution code:
n= int(input())
l= list(map(int,input().split()))
l=sorted(l)
count=0
for  i  in range(2,n):
#     print(i)
    ff=list(range(1,i))
    ff.reverse()
    for j in ff:
        if  l[j]*2<=l[i]:
            break
        r=range(j-n-1,-n,-1)
#         print(r)
        for k in r:
#             print(l[i],l[j],l[k])
            if l[i]<l[j]+l[k]:
                count+=(n+k+1)
                break
if l[2]<l[1]+l[0]:
    count+=1
print(count)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
L = list(map(int, input().split()))
l_set = set(L)
sort_L = sorted(list(l_set))
add_list = []
nl = len(sort_L)
ans = 0
for i in range(nl):
  for j in range(i+1, nl):
    a,b = sort_L[i],sort_L[j]
    add_list.append([a,b])
for e in add_list:
  ans += sum(e[0]+e[1] > c and e[1] < c for c in sort_L)
print(ans)

Submission status: Wrong Answer

Solution code:

import sys
input=sys.stdin.readline
n = int(input())
a = sorted(list(map(int,input().split())))
res = 0
i = 0
while i < n:
    j = i+1
    while j < n:
        yy = a[i]+a[j]
        for k in range(j+1,n):
            if yy > a[k]:res+=j-i
            else:
                break
        j+=1
    i+=j
print(res)

Submission status: Wrong Answer

Solution code:
def f_d():
    n, *l = map(int, open(0).read().split())

    l.sort()
    cnt = [n]*(l[-1]+l[-2]+1)
    j = 0
    for i in range(len(cnt)):
        if i==l[j]:
            cnt[i] = cnt[i-1]-1
            j = min((j+1), n-1)
        else:
            cnt[i] = cnt[i-1]

    o = 0
    for i in range(n):
        for j in range(i+1, n):
            ab1 = l[i]+l[j]
            ab2 = max(l[i], l[j]) - min(l[i], l[j])
            o += (cnt[ab2] - cnt[ab1-1])
            if ab2 < l[i] and l[i] < ab1:
                o -= 1
            if ab2 < l[j] and l[j] < ab1:
                o -= 1
    o = 0 if o<0 else o

    print(o//3)

if __name__ == "__main__":
    f_d()

Submission status: Wrong Answer

Solution code:
N = int(input())
L = [int(i) for i in input().split()]
L.sort(reverse = True)
M = 0
for i in range(N-2):
  if L[i]< L[i+1]+L[i+2]:
    M +=1
    for j in range(i+3,N-1):
        for k in range(j+4,N):
          if L[i] < L[j]+L[k]:
            M += 1
print(M)

Submission status: Wrong Answer

Solution code:
import itertools
N = int(input())
A = list(map(int, input().split())) 
tk = list(itertools.combinations(A, 3))
count = 0

for i in range(len(tk)):
    test = sorted(tk[i], reverse=True)
    print(test)
    a = test[0]
    b = test[1]
    c = test[2]
    
    if b - c < a:
        if a < b + c:
            count +=1
       
    
print(count)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
from collections import defaultdict

N = int(input())
*L, = map(int, input().split())
L_list = defaultdict(int)
for l in L:
    L_list[l] += 1
L = list(L_list.keys())
ans = 0
while len(L) >= 3:
    c = L.pop()
    for a, b in combinations(L, 2):
        if abs(a - b) < c < a + b: ans += L_list[c]
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

n=int(input())
l=sorted(list(map(int,input().split())))
a,b = 0,1
ans = 0
t = 0

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
  
for i in range(len(l)):
  t = 0
  for j in range(i+2,len(l)):
    if l[i] + l[i + 1] > l[j]:
      t += 1
    else:
      break
  if t > 0:
    ans += cmb(t+2,3)
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

n = int(input())
L = list(map(int,input().split()))
L.sort(reverse =True)
L_sum =[]
ans =0
for i in range(n):
  for j in range(i+1,n):
    L_sum.append(L[i]+L[j])
L_sum.sort()
for i in range(n):
  ans += (n*(n-1))//2-bisect.bisect_left(L_sum,L[i])-(n-1)*(i+1)+i*(i+1)//2
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
while (l[-1]>l[-2]+l[-3]) and (len(l)>3):
	del l[-1]
n=len(l)
ans=0
i=0
while i<n-2:
	j=i+1
	while j<n-1:
		k=j+1
		while k<n:
			if l[k]>l[i]+l[j]:
				ans=ans+k-j-1
				k=n
			k=k+1
		j=j+1
	i=i+1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import bisect
def main():
    _ = int(input())
    l = list(map(int,input().split()))
    d = defaultdict(int)
    for i in l:
        d[i] += 1
    dk = sorted(list(d.keys()))
    dk2 = [i*2 for i in dk]
    ans = 0
    while dk:
        x = dk[-1]
        print(x)
        _ = dk2.pop(-1)
        bs = bisect.bisect(dk2,x)
        tmp = dk[bs:]
        if not tmp:
            break
        for i in tmp:
            for j in dk:
                if i+j > x and i >= j:
                    if i == j and i == x:
                        ans += d[x]*(d[x]-1)*(d[x]-2)//6
                    elif i == j:
                        ans += d[x]*d[i]*(d[i]-1)//2
                    elif i == x:
                        ans += d[x]*(d[x]-1)*d[j]//2
                    else:
                        ans += d[x]*d[i]*d[j]
        del dk[-1]
    print(ans)
if __name__ == '__main__':
    main()