Problem:


Score : 400 points

Problem Statement

Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i.

He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied:

a < b + c

b < c + a

c < a + b

How many different triangles can be formed? Two triangles are considered different when there is a stick used in only one of them.

Constraints

All values in input are integers.

3 \leq N \leq 2 \times 10^3

1 \leq L_i \leq 10^3

Input

Input is given from Standard Input in the following format:

N
L_1 L_2 ... L_N

Constraints

Print the number of different triangles that can be formed.

Sample Input 1

4
3 4 2 1

Sample Output 1

1

Only one triangle can be formed: the triangle formed by the first, second, and third sticks.

Sample Input 2

3
1 1000 1

Sample Output 2

0

No triangles can be formed.

Sample Input 3

7
218 786 704 233 645 728 389

Sample Output 3

23



Sample input:
4
3 4 2 1


Sample output:
1

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import defaultdict
from itertools import accumulate
def main():
    N = int( input())
    L = list( map( int, input().split()))
    d = defaultdict( int)
    ans = 0
    
    for l in L:
        d[l] += 1
    L.sort()
    R = list( set(L))
    R.sort()
    for e in d:
        if d[e] >= 3:
            ans += d[e]*(d[e]-1)*(d[e]-2)//6
        if d[e] >= 2:
            cnt = 0
            t = d[e]*(d[e]-1)//2
            for l in R:
                if l == e:
                    continue
                if l < 2*e:
                    cnt += t
            ans += cnt
    T = [0]*(10**4)
    M = len(R)
    Z = [0]*(10**4)
    for i in range(M):
        for j in range(i+1, M):
            e = R[i]
            f = R[j]
            t = d[e]*d[f]
            T[ abs(e-f)+1] += t
            T[ e+f] -= t
            if abs(e-f) < e:
                Z[e] += t
            if abs(e-f) < f:
                Z[f] += t
    S = list( accumulate(T))
    a = 0

    for e in d:
        if S[e] > 0:
            a += (S[e] - Z[e])*d[e]

    print(ans+a//3)
if __name__ == '__main__':
    main()

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]
        for k in range(j+1, n):
            c = l[k]
            if c<b+a:
                num = num + 1
            else:
                break
        

print(l)
print(num)

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 left < right:
                    if l_s[right] < a + l_s[left]:
                        ans += 1
                    left += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
l = sorted([int(x) for x in input().split()])
#print(l)
ans = 0

for a in range(n):
    for b in range(a+1, n):
        ll = [x for x in l[b+1:] if x<l[a]+l[b]]
        print(l[a], l[b], ll)
        ans += len(ll)
        """for c in range(b+1, n):
            if l[c]<l[a]+l[b]:
                ans += 1
                print(a,b,c)
                continue
            else:
                break"""
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

from itertools import accumulate


def factorial(x):
    if x == 0:
        return 1

    return factorial(x - 1)


def comb(n, r):
    return factorial(n) / factorial(r) / factorial(n - r)


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
    tmp = [0] * 1001
    tmp2 = [0] * 1001
    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)

            # b < c のときの数
            cnt = acm[k] - acm[b]

            # b == c のときの補正
            if nums[b] >= 3 and a == b and tmp[b] == 0:
                cnt += int(comb(nums[b], 3))
                tmp[b] = 1

            if nums[b] >= 2 and a != b and tmp2[b] == 0:
                cnt += int(comb(nums[b], 2))
                tmp2[b] = 1

            ans += cnt

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#coding: utf-8
from scipy import special

n = int(input())
poll_list = list(map(int,input().split()))
# strings = list(map(str, [input() for i in range(amount)]))

poll_list.sort()
print(poll_list)
pat = 0
# for i in range(2,n):
#     if poll_list[i] < poll_list[i-2] + poll_list[i-1]:
#         pat += 1 

for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if poll_list[k] < poll_list[i] + poll_list[j]:
                print(str(poll_list[i])+str(',')+str(poll_list[j])+str(',')+str(poll_list[k])+str(','))
                pat += 1
            else:
                break

print(pat)

# pat2 = special.comb(pat, 3, exact = True)
# print(pat2)

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:
        ans += csum[min(maxl,2*i -1)] - csum[i]
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):
		if listl[j]<=(listl[i]/2):
			break
		for k in range(j+1,n):
			print(listl[i],listl[j],listl[k])
			if listl[i]<listl[j]+listl[k]:
				ans=ans+1
			else:
				break	
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import defaultdict
from itertools import accumulate
def main():
    N = int( input())
    L = list( map( int, input().split()))
    d = defaultdict( int)
    ans = 0
    
    for l in L:
        d[l] += 1
    L.sort()
    R = list( set(L))
    R.sort()
    for e in d:
        if d[e] >= 3:
            ans += d[e]*(d[e]-1)*(d[e]-2)//6
        if d[e] >= 2:
            cnt = 0
            t = d[e]*(d[e]-1)//2
            for l in R:
                if l == e:
                    continue
                if l < 2*e:
                    cnt += t
            ans += cnt
    T = [0]*(10**4)
    M = len(R)
    Z = [0]*(10**4)
    for i in range(M):
        for j in range(i+1, M):
            e = R[i]
            f = R[j]
            t = d[e]*d[f]
            T[ abs(e-f)+1] += t
            T[ e+f] -= t
            if abs(e-f) < e:
                Z[e] += t
            if abs(e-f) < f:
                Z[f] += t
    S = list( accumulate(T))
    a = 0

    for e in d:
        if S[e] > 0:
            a += S[e] - Z[e]

    print(ans+a//3)
if __name__ == '__main__':
    main()

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
#print(D)
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)):
    for j in range(i+1,len(D)):
        v=D[i]-D[j]
        total+= len(D[j+1:]) - 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:
import itertools
N = int(input())
stick = sorted(list(map(int, input().split())), reverse=True)
combi = itertools.combinations(stick, 3)
ans = 0
lst = []
flag = False
for a,b,c in combi:
  if flag and a in lst:
    continue
  elif a <= b+c:
    continue
  else:
    flag = False
  if a < b+c and b < c+a and c < a+b:
    ans += 1
  else:
    flag = True
    lst.append(a)
print(ans)

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
                left = right

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys


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.sort()

if len(L)<3:
  print(0)
else:
  ans = []
  create_triple([], 0)
  print(len(ans))

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_left, bisect_right

N=input()
L=map(int, sys.stdin.readline().split())
L.sort()

ans=0
for i in range(N):
    for j in range(i+1,N):
        C=[1]*N
        a=L[i]
        b=L[j]
        C[i]=0
        C[j]=0
        max_c=a+b-1
        min_c=max(a-b,b-a)+1
        p_max_c=bisect_left(L,max_c)
        p_min_c=max(bisect_left(L,min_c),j)

        ans+=sum(C[p_min_c:p_max_c])

print ans

Submission status: Wrong Answer

Solution code:
#D
n = int(input())
lb = list(map(int,input().split()))
###
defaultans = 0 #int(n*(n-1)*(n-2)/6)
###
lb.sort(reverse=True)
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 and b < c+a and c < a+b:
                cnt += n - k 
                break
print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools
N = int(input())
L = list(map(int,input().split()))
L_ = list(itertools.combinations(set(L),2))
ans = 0
ans_num = []
for a,b in L_:
  for j in range(N):
    if j != L.index(a) and j != L.index(b):
      c = L[j]
      if a + b > c and b + c > a and a + c > b and sorted([a,b,c]) not in ans_num:
        ans += 1
        ans_num.append(sorted([a,b,c]))
print(ans)

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)]
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int, input().split(" ")))
L.sort() #小さい順
print(L)
counter = 0

for num_1, i in enumerate(L):
  for num_2, j in enumerate(L):
    if num_1 <= num_2:
      break
    else:
      for num_3, k in enumerate(L):
        if num_2 <= num_3:
          break
        else:
          if j + k <= i:
            continue
          else:
            counter += 1
print(counter)

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):
    k = n-1
    if l[k] >= l[i]+l[j]:
      break
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
d=[]
for i in range(n-1):
    d.append(l[i]-l[i+1])

cnt=0

for i in range(n):
    left=0
    for right in range(1,n):
        while sum(d[left:right]) >= l[i]:
            left+=1
            # if left==right:
            #     cnt-=1
            #     break
        if i<=left or right<i:
            cnt+=1


print(cnt)

Submission status: Wrong Answer

Solution code:
from numpy import sort
def main():
    n = int(input())
    d = sorted(list(map(int, input().split())))[::-1]
    ans = 0
    for i in range(n-2):
        d1 = d[i]
        if d[i+2] + d[i+1] > d[i]:
    	    for j in range(i+1, n-1):
                d2 = d[j]
                if d[j+1] + d2 > d1:
                  for k in range(j-1, n-2):
                    if d[k] + d2 > d1:
                      ans += 1
                    else:
                      break
    print(ans)
  
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def is_triangle(a,b,c):
	if a<b+c :
		return True
	return False

_ = input()
rods = list(map(int,input().split()))
rods.sort(reverse=True)
num = 0
for i,a in enumerate(rods,start=1) :
	for j,b in enumerate(rods[i:],start=1):
		if not is_triangle(a,b,b):
			break

		if a==b :
			duple = 2
			for c in rods[i+j:]:
				if b == c:
					duple += 1
				else :
					break
			if duple > 0 :
				num += duple-2
				i += duple -2
				continue 

		for c in rods[i+j:]:
			if is_triangle(a,b,c):
				num += 1
			else :
				break
print(num)

Submission status: Wrong Answer

Solution code:
# from collections import defaultdict
# from heapq import heappush, heappop, heapify
# from bisect import bisect_left, insort_left
# from itertools import groupby


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

        max_len = max(L)
        dp = [[0] * (max_len+1) for _ in range(N)]
        for i in range(N):
            for j in range(1, max_len+1):
                dp[i][j] = int(L[i] <= j)
                if i > 0:
                    dp[i][j] += dp[i-1][j]

        res = 0
        for i in range(N-2):
            for j in range(i+1, N-1):
                left = min(abs(L[i]-L[j]), max_len)
                right = min(L[i] + L[j], max_len)
                res += max((dp[-1][right-1] - dp[j][right-1]) - (dp[-1][left]-dp[j][left]), 0)


        print(res)


if __name__ == '__main__':
    Solution().main()

Submission status: Wrong Answer

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

L = set(L)
L = list(L)
L.sort(reverse=True)
# print(L)

ans = 0
for e in itertools.combinations(L, 3):
    a = e[0]
    b = e[1]
    c = e[2]
    # print(c)
    if a<b+c and b<c+a and c<a+b:
        ans += 1
# ans = 0
# for a in range(N):
#     for b in range(N):
#         for c in range(N):
#             if L[a] > L[b] + L[c]:
#                 ans += 1
print(ans)

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
print(sum)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import numpy as np
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
# L = np.array(L)
ans = 0
idx = 0
for i in range(1, N):
    dif = L[i-1] - L[i]
    for j in range(i+1, N):
        if dif < L[j]:
            ans += 1
    if i != 1 and tmp < L[j]:
        ans += 1
        if dif < tmp:
            ans += len(L[:i-1])
    tmp = dif
        # tmp = L[j+1:] > L[i] - L[j]
        # ans += int(sum(tmp))
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 range(N):
    #print(a)
    for b in range(N):
        #print(b)
        for c in range(N):
            #print(c)
            if a+1!=b+1 & a+1!=c+1 & b+1!=c+1:
                #print(a,b,c)
                if Li[a]<Li[b]+Li[c] & Li[b]<Li[c]+Li[a] & Li[c]<Li[a]+Li[b]:
                    #print(a,b,c)
                    result+=1
print(result)

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):
			for k in range(2,n-i):
				if a[j]<a[i+1]+a[i+k]:
					ans+=1			
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
  while j<N-1:
    k=j+1
    while k<N and L[i]+L[j]>L[k]:
      k+=1
    
    t=k-j
    counter+=t*(t-1)//2
    j=k
  i+=1
  
print(counter)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    d = sorted(list(map(int, input().split())))[::-1]
    ans = 0
    for i in range(n-2):
        d1 = d[i]
        if d[i+2] + d[i+1] > d[i]:
    	    for j in range(i+1, n-1):
                d2 = d[j]
                if d[j+1] + d2 > d1:
                  for k in range(j-1, n-2):
                    if d[k] + d2 > d1:
                      ans += 1
                    else:
                      break
    print(ans)
  
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
L = [int(l) for l in input().split()]
L.sort(reverse=True)

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

Submission status: Wrong Answer

Solution code:
# from collections import defaultdict
# from heapq import heappush, heappop, heapify
# from bisect import bisect_left, insort_left
# from itertools import groupby


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

        max_len = max(L)
        dp = [[0] * (max_len+1) for _ in range(N)]
        for i in range(N):
            for j in range(1, max_len+1):
                dp[i][j] = int(L[i] <= j)
                if i > 0:
                    dp[i][j] += dp[i-1][j]

        res = 0
        for i in range(N):
            for j in range(i+1, N):
                left = min(abs(L[i]-L[j]), max_len)
                right = min(L[i] + L[j], max_len)
                res += max((dp[-1][right-1] - dp[j][right-1]) - (dp[-1][left]-dp[j][left]), 0)


        print(res)


if __name__ == '__main__':
    Solution().main()

Submission status: Wrong Answer

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

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={}
for i in range(len(L)-1):
    for j in range(i+1, len(L)):
        #すでに探索済みか判定
        temp = str(L[i]) +","+ str(L[j])
        if temp in search_end:
            continue

        high=L[j]
        low=L[i]

        Lcopy = copy.deepcopy(L)
        Lcopy.remove(high)
        Lcopy.remove(low)
        Lcopy = sorted(Lcopy)

        #下限を取得    
        under_index = bisect.bisect_right(Lcopy,high-low)
        #上限を取得
        high_index = bisect.bisect_left(Lcopy,high+low)
        for va in Lcopy[under_index:high_index]:
            temp = sorted([high,low, va])
            temp = (temp[0]*10**8) + (temp[1]*10**4) + temp[2]
            sankaku_dict[temp]=1

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N=int(input())
L=list(map(int,input().split()))
L.sort()
import bisect
ans=0
for i in range(N-2):
    if L[i-1]!=L[i]:
        for j in range(i+1,N-1):
            if L[j-1]!=L[j]:
                a=set(L[j+1:])
                a=list(a)
                a.sort()
                ans=ans+bisect.bisect_left(a,L[i]+L[j])
print(ans)

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())
l = list(map(int, input().split()))
l.sort()

hoge = []
ans = 0
a = b = c = None
for i in range(n - 2):
    if i == 0 or l[hoge[-1][0]] != l[i]:
        for j in range(i + 1,n - 1):
            if j == i + 1 or l[hoge[-1][1]] != l[j]:
                for k in range(j + 1, n):
                    if k == j + 1 or l[hoge[-1][2]] != l[k]:
                        hoge.append([i, j, k])
for i, j, k in hoge:
    a = l[i]
    b = l[j]
    c = l[k]
    if a < b + c and b < a + c and c < b + a:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys


def create_triple(triple):
  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
    if len(triple)==2 and abs(triple[0]-triple[1])>sum(triple): break
    create_triple(triple+[l])


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([])
  print(len(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]

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

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int, input().split(" ")))
L.sort() #小さい順
counter = 0

for num_1, i in enumerate(L):
  for num_2, j in enumerate(L):
    if num_1 <= num_2:
      break
    else:
      for num_3, k in enumerate(L):
        if num_2 <= num_3:
          break
        else:
          if j + k <= i:
            break
          else:
            counter += 1
print(counter)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [x for x in map(int, input().split())]

cnt = 0
for i in range(0, n):
    a = l[i]
    if i < len(l) - 1:
        b = l[i + 1]
    else:
        b = l[0]
    for j in range(0, n):
        if l[j] == a or l[j] == b:
            pass
        else:
            c = l[j]

            if a < b + c and b < c + a and c < a + b:
                cnt += 1
            else:
                continue
print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect

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

S = 0
for i in range(N):
    a = L[i]
    for k in range(i - 1):
        c = L[k]
        j = bisect.bisect_left(L, a - c)
        j = max(k + 1, j)
        if j >= i:
            break
        else:
            if a < c + L[j]:
                S += i - j
print(S)

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())
keys.sort(reverse=True)
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
    
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = [int(x) for x in input().split()]
L.sort()
ans = 0
last_k = 0
for i in range(N):
  for j in range(i+1,N):
    k = max(j+1,last_k)
    while k < N:
      if L[k] >= L[i] + L[j]:
        break
      k += 1
    k -= 1
    last_k = k
    ans += max((k-j),0)
      
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 + 1)
          for i in range(1, n) for j in range(i)))

Submission status: Wrong Answer

Solution code:
import sys


def create_triple(triple):
  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
    if len(triple)==2 and abs(triple[0]-triple[1])>sum(triple): break
    create_triple(triple+[l])


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

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

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):
    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)
        for k in r:
            if l[i]<l[j]+l[k]:
                count+=(n+k+1)
                break
                
print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
L = [int(l) for l in input().split()]
L.sort(reverse=True)

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

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N = int(input())
    L = list(map(int, input().split()))

    L.sort()
    L.reverse()

    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            for k in range(j+1, N):
                if i != j and j != k and k != i:
                    if L[i] < L[j] + L[k] and L[j] < L[k] + L[i] and L[k] < L[i] + L[j]:
                        ans += N - k
                        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):
			print(listl[i],listl[j],listl[k])
			if listl[i]<listl[j]+listl[k]:
				ans=ans+1
			else:
				break	
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
Llist = list(map(int, input().split()))
Lset = list(set(Llist))
Lset.sort(reverse=True)
M = len(Lset)

Lcount = Counter(Llist)
num = 0
for i in range(M-2):
    for j in range(M-2-i):
        for k in range(M-2-i-j):
            if Lset[i] >= Lset[i+1+j] + Lset[i+2+j+k]:
                break
            else:
                num += Lcount[Lset[i]] * Lcount[Lset[i+1+j]] * Lcount[Lset[i+2+j+k]]

print(num)

Submission status: Wrong Answer

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

count = 0
for i in range(n):
    for j in range(i + 1, n):
        x, y = ls[i], ls[j]
        tri_xy = [k for k in ls[j + 1:] if k < x + y]
        print(tri_xy)
        count += len(tri_xy)
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys


def create_triple(triple):
  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
    if len(triple)==2 and abs(triple[0]-triple[1])>sum(triple): break
    create_triple(triple+[l])


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

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
L = list(map(int, input().split()))
ans = 0
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):
                s = L[i]+L[j]
                S = L+[s]
                S.sort()
                dex = S.index(s)
                ans += len(set(S[j+1:dex]))
    print(ans)

Submission status: Wrong Answer

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


cnt = 0

for i, a in enumerate(pole_list):
    
    b_list = [b for k, b in enumerate(pole_list) if k != i and 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:
                cnt +=1

print(cnt)