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:
from collections import Counter

def tri_check(a,b,c):
  if a<b+c and b<a+c and c<a+b:
    return True
  else:
    return False

N = int(input())
L = list(map(int, input().split()))
S = Counter(L)
keys = list(S.keys())
l_keys = len(keys)
ans = 0
for i in range(l_keys):
  for j in range(i+1,l_keys):
    for k in range(j+1,l_keys):
      a, b, c = keys[i],keys[j],keys[k]
      if tri_check(a,b,c):
        ans += S[a]*S[b]*S[c]
      else:
        break
    else:
      continue
    break
    
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

n = int(input())
a = sorted(map(int, input().split()))
print(sum(n - bisect_right(a, a[i] + a[j], i)
          for i in range(1, n) for j in range(i)))

Submission status: Wrong Answer

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

L.sort()

counter=0
i=0
while i<N-2:
  j=i+1
  k=j+1
  while j<N-1:
    if L[i]+L[j]>L[k]:
      if k<N-1:
        counter+=1
        k+=1
      else:
        t=k-j
        counter+=t*(t-1)//2+1
        j=N
    else:
      j+=1
      if j==k:
        k+=1
  i+=1
  
print(int(counter))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
L = [int(l) for l in input().split()]
ans = 0
for i in range(N):
    for j in range(i, N):
        if i == j:
            continue
        elif L[i] == L[j]:
            continue
        temp = list(filter(lambda x: x > abs(L[i]-L[j]) and x < L[i]+L[j],L[j+1:]))
        ans += len(temp)
print(ans)

Submission status: Wrong Answer

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

num = [0] * (3001)
for i in range(N):
    num[L[i]] = 1
for i in range(1,3001):
    num[i] += num[i-1]

ans = 0
for a in range(N):
    for b in range(a+1,N):
        l = L[a]-L[b]
        r = min(L[a]+L[b],L[b])
        ans += num[r-1] - num[l] if l < r else 0
        # print(l,r,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
array = list(map(int, input().split()))
count = 0
array.sort(reverse = True)
end = n-1
for a in range(n):
    A = array[a]
    for b in range(a+1,n):
        B = array[b]
        ab = A - B
        for c in range(end,b,-1):
            if ab < array[c]:
                count += c - b
                end = c
                break
print(count)

Submission status: Wrong Answer

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

for i in range(0, n-2):
  for j in range(i+1, n-1):
    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]):
        c = c + 1
      else:
        break

Submission status: Wrong Answer

Solution code:
import math
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)]
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
        cnt += C[a+b-1] - C[max(abs(a-b), b)]
for m in M:
    if m >= 3:
        cnt += math.factorial(m) // (math.factorial(m-3) * math.factorial(3))
print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools

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

L.sort(reverse=True)
print(L)

xx = itertools.combinations(L, 3)
cnt = 0
for x in xx:
    if x[0] < x[1] + x[2]:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

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

    ans = 0

    for i in range(n-2):
        a = l_s[i]

        left = i+1
        for right in range(i+2, n):
            if l_s[right] < a + l_s[left]:
                ans += right - left
            else:
                while l_s[right] >= a + l_s[left] or right-1 == left:
                    left += 1
                ans += right - left

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

from collections import Counter
c = Counter(l2)
k = list(c.keys())
k.sort()

from bisect import bisect_left, bisect_right
l2.sort()

ans = 0
for i in range(len(k)):
    for j in range(i+1, len(k)):
        c_min = k[j] - k[i]
        c_max = k[i] + k[j]

        idx = bisect_right(l2, k[j])
        tmp = l2[idx:]

        idx_min = bisect_right(tmp, c_min)
        idx_max = bisect_left(tmp, c_max)

        ans += max(0, idx_max - idx_min) * c[k[i]] * c[k[j]]

print(ans)

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]
        _ = 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 += max([0,d[x]*(d[x]-1)*(d[x]-2)//6])
                    elif i == j:
                        ans += d[x]*d[i]*(d[i]-1)//2
                    else:
                        ans += d[x]*d[i]*d[j]
        del dk[-1]
        if len(dk) < 3:
            break
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# coding:utf-8

N = int(input())

L = list(map( lambda x:int(x), input().split(" ") ))

L = sorted(L, reverse=True)

count = 0

for i1 in range(0, len(L)-2):
    for i2 in range(i1+1, len(L)-1):
        flag = False
        for i3 in range(i2+1, len(L)):
            a = L[i1]
            b = L[i2]
            c = L[i3] 
        
            # discount if-then
            if(a<b+c):
                count += 1
            else:
                flag=True
        if flag:
            break
                
print(count)

Submission status: Wrong Answer

Solution code:
import collections

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

# 重複をCountしてリスト化
input_dictionary = collections.Counter(input_list)

# 重複を削除
input_set = list(set(input_list))
input_count = len(input_set)
sum = 0
for a in range(input_count):
    for b in range(input_count):
        if a <= b: break
        for c in range(input_count):
            if b <= c: break
            A = input_set[a]
            B = input_set[b]
            C = input_set[c]
            if A < B + C and B < A + C and C < A + B:
                count_a = input_dictionary[A]
                count_b = input_dictionary[B]
                count_c = input_dictionary[C]
                if count_a >= 2:
                    sum += count_a - 1
                if count_b >= 2:
                    sum += count_b - 1
                if count_c >= 2:
                    sum += count_c - 1
                sum += 1
print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
#N=10**3
#L=random.sample(range(2*10**3), k=N)
L=sorted(L, reverse=True)
count=0
for i in range(N-2):
    for j in range(i+1,N-1):
        #if add<L[i]:
        #    break
            
        for k in range(j+1,N):
            add  = L[j]+L[k]
            diff = L[j]-L[k]
            
            if (diff>=L[i]) or (add<=L[i]):
                #print(L[i],L[j],L[k],diff<L[i],add>L[i])
                #print(L[i],L[j],L[k],diff<L[i],add>L[i])
                break
                
            #print(L[i],L[j],L[k],diff<L[i],add>L[i])
            count += 1
            
        else:
            if add<L[i]:
                #print(L[i],L[j],L[k],diff<L[i],add>L[i])
                break
            else:
                continue
        break
print(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-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 or b+c <= a or a+c<=b:
                break
            cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import collections

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

col = collections.Counter(L)
cmemo = [0] * 1001
for x in list(col.keys()):
    cmemo[x] += col[x]
for i in range(1, 1001):
    cmemo[i] += cmemo[i-1]

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        a, b = L[i], L[j]
        cmin, cmax = abs(a-b), min(a+b, 1000)
        if cmin < a < cmax and cmin < b < cmax:
            ans += cmemo[cmax-1] - cmemo[cmin] - 2
        elif cmin < a < cmax or cmin < b < cmax:
            ans += cmemo[cmax-1] - cmemo[cmin] - 1
        else:
            ans += cmemo[cmax-1] - cmemo[cmin]
print(ans//3)

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):
  a=L[i]
  bd=1
  for j in range(i+1,N-1):
    b=L[j]
    if b==a:
      bd+=1
    else:
      cd=1
      for k in range(j+1,N):
        c=L[k]
        if c==b:
          cd+=1
        else:
          if c<a+b:
            ans+=bd*cd
          else:
            break
        
print(ans)

Submission status: Wrong Answer

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

L.sort()

counter=0
i=0
while i<N-2:
  j=i+1
  k=j+1
  while j<N-1:
    if L[i]+L[j]>L[k]:
      if k<N-1:
        counter+=1
        k+=1
      else:
        t=k-j
        counter+=t*(t-1)//2+1
        j=N
    else:
      j+=1
      if j==k:
        k+=1
  i+=1
  
print(counter)

Submission status: Wrong Answer

Solution code:
import itertools
n=int(input())
l=[int(_) for _ in input().split()]
c_l=list(itertools.combinations(l,3))
tr=[]
for i in range(len(c_l)):
	ans=[c_l[i][0],c_l[i][1],c_l[i][2]].sort()
	if ans  not in tr:
	    if c_l[i][0]<c_l[i][1]+c_l[i][2] and c_l[i][1]<c_l[i][0]+c_l[i][2] and c_l[i][2]<c_l[i][0]+c_l[i][1]:
	    	tr.append(ans)
print(len(tr))

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int , input().split()))
l = sorted(l, key=None, reverse=True)
ans = 0
for i in range(0, n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            print(i, j, k)
            if l[i] < l[j] + l[k] and l[j] < l[i] + l[k] and l[k] < l[i] + l[j]:
                ans += 1
            else:
                break

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7
from math import factorial
def comb(n,r):
    return factorial(n) // (factorial(r) * factorial(n - r))

n = INT()
l = MAP()

l.sort()
res=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]:
                res+=n-k
                break
        else:
            break
    else:
        break


print(comb(n,3)-res)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# 長さじゃなくて、棒自体で区別してるやんけー！

import numpy as np

N = int(readline())
L = np.array(read().split(),np.int32)

U = 1000
counter = np.bincount(L,minlength=U+U+10)

def F1():
    # 正三角形
    x = counter
    return (x*(x-1)*(x-2)//6).sum()

def F2():
    # (a,a,2a未満のa以外)
    cum = counter.cumsum()
    # (cum[2a-1] - counter[a]) * (counter[a] C 2)
    x = counter[1:U+1]
    return np.sum((cum[1:U+U:2] - x) * (x*(x-1)//2))

def F3():
    L.sort()
    cum = counter.cumsum()
    add = L[:,None] + L[None,:]
    # bより大きく、a+bより小さい
    cnt_c = cum[add-1] - cum[L][None,:]
    return np.triu(cnt_c,1).sum()

answer = F1() + F2() + F3()
print(answer)

Submission status: Wrong Answer

Solution code:


n = int(input())

#list
l = list(map(int, input().split()))
l.sort(reverse=True)

def check03(i,j):
  ret03=0
  for k in range(j+1,n):
    if l[i] > l[j]+l[k]:
      ret03+=1
  return ret03

def check02(i):
  ret02=0
  for j in range(i+1,n):
    ret02 += check03(i,j)
  return ret02

count=0
for i in range(n):
  count += check02(i)


count_all = n*(n-1)*(n-2)/6
#print(count_all)

print(int(count_all-count))

Submission status: Wrong Answer

Solution code:
import bisect

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

chouhen = set()
kosuu = 0

for i in range(N):
    for j in range(i+1, N):
        a, b = min(L[i], L[j]), max(L[i], L[j])
        chouhen.add((a, b))

L.sort()

print(kosuu)
print(chouhen)
print(L)

for hen in chouhen:
    hidari = max(hen[0] - hen[1], hen[1] - hen[0])
    migi = sum(hen)

    hidari_idx = bisect.bisect_right(L, hidari)
    migi_idx = bisect.bisect_left(L, migi)

    if L[hidari_idx] <= hen[0] <= L[migi_idx - 1]:
        kosuu -= 1
    if L[hidari_idx] <= hen[1] <= L[migi_idx - 1]:
        kosuu -= 1

    kosuu += migi_idx - hidari_idx

    print(hidari, migi, hidari_idx, migi_idx, kosuu)

print(max(0, kosuu // 3))

Submission status: Wrong Answer

Solution code:
import collections


if __name__ == '__main__':
    n = int(input())
    l = list(map(int,input().split()))

    ls = set(l)
    lsl = sorted(list(ls), reverse=True)
    lc = collections.Counter(l)

    ns = len(ls)

    answer = 0
    for i in range(ns):
        for j in range(i+1,ns):
            for k in range(j+1,ns):
                if lsl[i] < lsl[j] + lsl[k]:
                    answer += lc[lsl[i]] * lc[lsl[j]] * lc[lsl[k]]
                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 *
max_l = max(l_list)
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        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:
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
print(L)
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[k]>L[i] and L[k]+L[i]>L[j]:
        #print("ok")
        ans += 1
      else:
        break
print(ans)

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

from itertools import accumulate


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

    nums = [0] * 1001

    for e in l:
        nums[e] += 1

    acm = list(accumulate(nums))

    l.sort()
    ans = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            a = l[i]
            b = l[j]
            k = min(1000, a+b-1)
            cnt = acm[k] - acm[b]

            ans += cnt

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
ls_L = list(map(int, input().split()))
count = 0
for i, a in enumerate(ls_L[:-2]):
    for j, b in enumerate(ls_L[i+1:-1]):
        for c in ls_L[i+j+2:]:
            if abs(a - b) < c < a + b:
                count += 1
                print(a, b ,c)
print(count)

Submission status: Wrong Answer

Solution code:
import sys


def create_triple(triple, L):
  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 l in L:
    if l in triple: break
    create_triple(triple+[l], L)


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

ans = []
create_triple([], L)
print(len(ans))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)

n=int(input())
L=list(map(int,input().split()))
data=[0]*(10**3+1)
ans=0
pre=0
S=0
L.sort()
for i in range(1,n):

    l=L[i]
    # if L[i]+L[j]<10**3:
    S-=sum(data[pre:l+1])
    pre=l+1
    ans+=S
    # print(ans,S)
    for j in range(0,i):
        if l+L[j]<10**3:
            data[l+L[j]]+=1
        S+=1
        # print('insert',l+L[j])

# print
        # print(L[i]+L[j])

# now=0
# for i in range(n):
#     S=sum(data[now:L[i]])
#     now=i
#     ans+=S
print(ans)
# print(data)

Submission status: Wrong Answer

Solution code:
import itertools

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

C = [0] * (L[-1] + 1)
num_list = []
for key, group in itertools.groupby(L):
    C[key] = len(list(group))
    num_list.append(key)

C_sum = list(itertools.accumulate(C))

ans = 0
for idx, a in enumerate(num_list):
    for b in num_list[idx:]:
        m = max(b - a + 1, L[0], b)
        M = min(b + a - 1, L[-1])
        if a == b and C[a] >= 2:
            ans += C[a] * (C[a] - 1) * (C[a] - 2) // 6
        elif a < b and m == b:
            ans += C[a] * (C[b] * (C[b] - 1) // 2 + C[b] * (C_sum[M] - C_sum[m]))
        elif a < b and m > b:
            ans += C[a] * (C[b] * (C_sum[M] - C_sum[m] + C[m]))

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

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

L = set(L)

combi_list = list(itertools.combinations(L,3))

res = [ 0 for a, b, c in combi_list if a < b + c and b < c + a and c < a + b]

print(len(res))

Submission status: Wrong Answer

Solution code:
import itertools
_= input()
l = list(map(int,input().split()))
s = set(l)
ans = 0
sp = itertools.combinations(s, 3)

for i in sp:
    tmp = sorted(i)

    if tmp[0] + tmp[1] > tmp[2]:
        ans += 1
    
print(ans)

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 Li:
    for b in Li:
        for c in Li:
            if a<b+c & b<c+a & c<a+b:
                result+=1
print(result)

Submission status: Wrong Answer

Solution code:
def slove():
    import sys
    import bisect
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = list(map(int, input().rstrip('\n').split()))
    l.sort()
    d = collections.defaultdict(list)
    for v in l:
        d[v]
    cnt = 0
    for i in range(1, n - 1):
        for j in range(i + 1, n):
            a, b = [l[i], l[j]]
            tl = [a + b, abs(a - b)]
            mi = min(tl) + 1
            ma = max(tl) - 1
            if mi < ma:
                pmax = bisect.bisect_right(l, ma)
                pmin = bisect.bisect_right(l, mi)
                if pmax == pmin:
                    cnt += 0
                else:
                    cnt += abs(pmax - pmin)
                    cnt -= 1 if mi <= a <= ma else 0
                    cnt -= 1 if mi <= b <= ma else 0
            elif mi == ma and mi in d:
                cnt += 1
    print(cnt)


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

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

for i in range(n-2):
    flag = 0
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if l[i] < l[j] + l[k]:
                ans += 1
            elif k-j == 1:
                flag = 1
                break
            else:
                break
        if flag:
            break

print(ans)

Submission status: Wrong Answer

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

R = [0] * (2**15-1)
cnt = 0
length = 0
for i in L:
    for j in L:
        if i == j:
            continue
        for k in L:
            if i == k or j == k:
                continue
            if i < j+k and j < i+k and k < i+j:
                r = {i, j, k}
                if not r in R:
                    R[cnt] = r
                    cnt += 1
                    length += 1

print(length)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [int(i) for i in 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):
            if l[i] > l[j] + l[k]: continue
            if l[j] > l[i] + l[k]: continue
            if l[k] > l[i] + l[j]: continue
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import itertools
# 周長は三角形のうちの最大長の2倍よりも大きい

def solve(N: int, L: "List[int]"):
    # N = 5
    # L = [1,2,2,3,4]
    L.sort()

    answer = 0
    prev_i_L = 0
    prev_j_L = 0
    for i in range(N):
        if prev_i_L == L[i]:
            answer += a
            continue 
        a = 0
        for j in range(i+1,N):
            if prev_j_L == L[j]:
                a += b
                continue 
            b=0
            for k in range(j+1,N):
                if L[i]+L[j]>L[k]:
                    b += 1
            a += b
            prev_j_L = L[j]
        answer += a
        prev_i_L = L[i]

    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, L)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


print(counter)

Submission status: Wrong Answer

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

ans=0
for x,a in enumerate(L):
	for y,b in enumerate(L):
		if x>=y:
			continue
		for z,c in enumerate(L):
			if y>=z:
				continue
			if a<b+c and b<c+a and c<a+b:
				ans+=1

print(int(ans/6))

Submission status: Wrong Answer

Solution code:
from itertools import combinations

N = int(input().strip())
Ls = list(map(int, input().strip().split()))

Ls = list(set(Ls))

ans = 0
for cs in combinations(Ls, 3):
    a, b, c = cs

    if not a < (b + c):
        continue

    if not b < (c + a):
        continue

    if not c < (a + b):
        continue

    ans += 1

print(ans)

Submission status: Wrong Answer

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

cnt = 0
for i in range(len(l)):
    for j in range(i+1, len(l)):
        for k in range(j+1, len(l)):
            if l[i] + l[j] > l[k]:
                cnt += 1
            else:
                break

print(cnt)

Submission status: Wrong Answer

Solution code:
def A():
    temp = [int(i) for i in input().split()]
    print(max(0, temp[0]-2*temp[1]))

def B():
    N = int(input())
    T = [int(i) for i in input().split()]
    s = 0
    for i in range(N):
        for j in range(i):
            s += T[i]*T[j]
    print(s)

def C():
    N = int(input())
    S = input()
    if N == 1:
        print(1)
    else:
        ans = 1
        cur_c = S[0]
        for c in S:
            if c != cur_c:
                ans += 1
                cur_c = c
        
        print(ans)

def D():
    N = int(input())
    L = sorted([int(i) for i in input().split()],reverse = True)
    # dp_sum = [[0 for i in range(N)] for j in range(N)]
    # for i in range(N):
    #     for j in range(i):
    #         dp_sum[i][j] = L[i]+L[j]
    count = 0
    for i in range(N):
        for j in range(i):
            for k in range(j):
                if L[k] < L[i]+L[j] and L[j] < L[i]+L[k] and L[i] < L[j]+L[k]:
                    count += 1
                else:
                    break
    print(count)

D()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
 
N = int(input())
edge = list(map(int, input().split()))
edge.sort()
counter = 0

for i in range(len(edge) - 2):
    A = edge[i]
    for k in range(i + 1, len(edge) - 1):
        B = edge[k]
        Cmin = max(A - B, B - A)
        Cmax = A + B
        foot = [x for x in edge if x > Cmin]
        foot.extend([x for x in edge if x < Cmax])
        counter += len(foot) - len(list(set(foot))) - 2
print(counter)

Submission status: Wrong Answer

Solution code:
import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

input = sys.stdin.readline


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

    max_l = max(L)

    ans = 0

    for a in range(N):

        for b in range(a+1, N):
            if L[a] >= L[b] + max_l:
                continue

            for c in range(b+1, N):
                if L[a] < L[b] + L[c] and L[b] < L[c] + L[a] and L[c] < L[a] + L[b]:
                    ans += 1
                else:
                    break

    print(ans)

Submission status: Wrong Answer

Solution code:
def slove():
    import sys
    import bisect
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = list(map(int, input().rstrip('\n').split()))
    l.sort()
    d = collections.defaultdict(list)
    for v in l:
        d[v]
    cnt = 0
    for i in range(1, n - 1):
        for j in range(i + 1, n):
            a, b = [l[i], l[j]]
            tl = [a + b, abs(a - b)]
            mi = max(min(tl) + 1, a - 1)
            ma = min(max(tl) - 1, a - 1)
            if mi < ma:
                pmax = bisect.bisect_right(l, ma)
                pmin = bisect.bisect_right(l, mi)
                if pmax == pmin:
                    cnt += 0
                else:
                    cnt += abs(pmax - pmin)
            elif mi == ma and mi in d:
                cnt += 1
    print(cnt)


if __name__ == '__main__':
    slove()

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+1, N):
    for k in range(j+1, N):
      if(i+j>=k and i+k>=j and j+k>=i):
        ans += 1


print(ans)

Submission status: Wrong Answer

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

ans=0


for i in range(n-2):
  flag=False
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if l[i]<l[j]+l[k]:
        ans+=1
      else:#それ以降のj,kで三角形作れるのは無いので最初のfor文に戻る
        flag=True
        break
    if flag==True:
      break
print(ans)

Submission status: Wrong Answer

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

listl.sort(reverse=True)

#print(listl)
ans=0
if n==3:
	if listl[0]>=listl[1]+listl[2]:
		ans=0
	else:
		ans=1
else:
	for i in range(n-2):
		for j in range(i+1,n-1):
			for k in range(j+1,n):
				if listl[i]<listl[j]+listl[k]:
					print(listl[i],listl[j],listl[k])
					ans=ans+1
					
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from bisect import bisect_left, bisect, insort_left, insort
def solve():
    n = int(input())
    L = sorted(map(int, input().split()))
    SET = set(L)
    len_s = len(SET)
    SS = sorted(SET)
    C = Counter(L)
    ans = 0
    for i in range(0, len_s):
        if C[SS[i]] >= 3:
            ans += 1
        if C[SS[i]] >= 2:
            ans += bisect_left(SS, SS[i] * 2) - i - 1
        for j in range(i + 1, len_s):
            ans += bisect_left(SS, SS[i] + SS[j]) - j - 1
    print(ans)
solve()

Submission status: Wrong Answer

Solution code:
from bisect import*
n,*l=map(int,open(0).read().split())
l.sort()
A=0
for i in range(n):
    a=l[i]
    for j in range(bisect(l,a),n):
        b=l[j]
        k1=max(j+1,bisect(l,b-a))
        k2=bisect_left(l,a+b)
        A+=max(0,k2-k1)
print(A)

Submission status: Wrong Answer

Solution code:
n = int(input())
l_list = list(int(i) for i in input().split())
list.sort(l_list, reverse=True)
count = 0
for i in range(n):
    a = l_list[i]
    for j in range(i+1, n):
        b = l_list[j]
        for k in range(j+1, n):
            c = l_list[k]
            print(a, b, c)
            if a < b+c and b < c+a and c < a+b:
                count += 1
print(count)