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 itertools
import timeit
import bisect

def main():
    N = int(input())
    L_orig = sorted([int(x) for x in input().split()])
    L = [[i, x] for i, x in enumerate(L_orig)]
    ans = 0
    for a, b in itertools.combinations(L[:-1], 2):
        a[1] + b[1]
        ans += bisect.bisect_right(L_orig[b[0]+1:], a[1] + b[1])
    print(ans)

if __name__ == "__main__":
    # print(timeit.timeit(lambda: main(), number=1))
    main()

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())
L = sorted(map(int, input().split()))
# print(L)
# L = [1, 2, 2, 3, 4, 5, 6]
# L = [218, 786, 704, 233, 645, 728, 389]
# L = sorted(L)
# N = len(L)
S = 0
for i in range(2, N):
    a = L[i]
    k = bisect.bisect_left(L, (a + 2) // 2)
    while k >= 0:
        if a < L[k] * 2:
            k -= 1
        else:
            break
    k = min(i - 2, k)
    S += i - k - 2
    # この段階でkを決定した時点で自明に取り込まれる部分は入っている。
    # あとは、jの情報が必要な領域。
    j = k + 1
    while True:
        while not (a < L[k] + L[j]):
            j += 1
        # 条件を満たすまでjをインクリメントしたので、今のi,j,kはギリギリ条件を満たす。
        if j == i:
            break
        S += i - j
        k -= 1
        if k < 0:
            break
print(S)

Submission status: Wrong Answer

Solution code:
from bisect import*
n,*l=map(int,open(0).read().split())
l.sort()
print(sum(bisect_left(l,l[i//n]+l[i%n],i%n+1)-i%n-1for i in range(n*n))//2)

Submission status: Wrong Answer

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

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

for i in range(len(L)-2):
    for j in range(i+1,len(L)-1):
        index = bisect.bisect_right(L,L[i]+L[j],j+1)
        ans += (index - 1) - (j + 1) + 1
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

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

D.sort()
total=0

for i in range(N-2):
    for j in range(i+1,N-1):
        total+=   bisect.bisect_left(D,D[i]+D[j])-j

print(total)

Submission status: Wrong Answer

Solution code:
from bisect import bisect
N = int(input())
L = sorted([int(_) for _ in input().split()])
ans = 0
for a in range(N - 2):
    for b in range(a + 1, N - 1):
        #print(bisect(L,L[a]+L[b]-1)-b-1)
        ans += bisect(L, L[a] + L[b] ) - b - 1
print(ans)

Submission status: Wrong Answer

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

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

for i in range(len(L)-2):
    for j in range(i+1,len(L)-1):
        index = bisect.bisect_right(L,L[i]+L[j],j+1,len(L))
        ans += (index - 1) - (j + 1) + 1
print(ans)

Submission status: Wrong Answer

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


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

    return result_list


main()

Submission status: Wrong Answer

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

L.sort()
ans = 0
 
for i in range(N-2):
  for j in range(i+1,N-1):
    ans += bisect.bisect_left(L,L[i]+L[j])
        
print(ans)

Submission status: Wrong Answer

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

from itertools import accumulate

fact = [1]

for i in range(1, 1001):
    fact.append(fact[-1] * i)


def comb(n, r):
    return int(fact[n] / fact[r] / fact[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 _ in range(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 += comb(nums[b], 3)
            #     tmp[b] = 1

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

            ans += cnt

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

ans=0
tmp=0
for i in range(N):
    # print('i{} tmp:{} '.format(i,tmp),ans)
    for j in range(i+1,N):
        # print('j:{} tmp:{} '.format(j,tmp),ans)
        sum=L[i]+L[j]
        for k in range(j+1+tmp,N):
            # print('k:{} tmp:{} '.format(k,tmp),ans)
            if sum <= L[k]:
                tmp=k-1-(j+1)
                ans+=N-k
                break
            if L[i] >= L[j]+L[k] or L[j] >= L[k]+L[i]:
                ans += 1
                continue
            
print(int(N*(N-1)*(N-2)/6 - ans))

Submission status: Wrong Answer

Solution code:
import bisect

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

L.sort(reverse=True)

ans=0
for i in range(N-1):
    for j in range(i+1,N):
        idx=bisect.bisect_left(L,L[i]-L[j])
        ans+=idx-j
print(ans)

Submission status: Wrong Answer

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

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

def one_str():
    return input()

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




N=one_int()
L=many_int()

L=sorted(L)

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

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

Submission status: Wrong Answer

Solution code:
def triangles(a): 
    n = len(a) 
    a.sort() 
    count = 0
    print(a)
    for i in range(0,n-2):
        for j in range(i+1,n): 
            k=j+1
            while (k < n and a[i] + a[j] > a[k]): 
                k += 1
            if(k>j): 
                count += k - j - 1
    return count
n=int(input())
a=list(map(int,input().split()))
print(triangles(a))

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
L_list =  sorted(list(map(int,input().split())))
#print(L_list)
result =0

for i in range(N):
    for j in range(i+1,N):
        a = L_list[i] + L_list[j]
        idx = bisect.bisect_left(L_list,a)
        result = max(0,idx-j-1)
print(result)

Submission status: Wrong Answer

Solution code:
import bisect

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

Llist.sort()
print(Llist)

count = 0

for i in range(n-2):
    p = Llist[i]
    for j in range(i+1,n-1):
        q = Llist[j]
        print(count,p,q)
        k = bisect.bisect_left(Llist, p+q)
        count += (k-j-1)

print(count)

Submission status: Wrong Answer

Solution code:
input1 = int(input())
input_list = list(map(int, input().split()))

cnt = 0
for i in range(input1):
    for j in range(i+1, input1):
        for k in range(j+1, input1):
            if (input_list[i]  < input_list[j] + input_list[k]
                and input_list[j] < input_list[k] + input_list[i]
                and input_list[k] < input_list[i] + input_list[j]):
#                print("  ", input_list[i], input_list[j], input_list[k])
                cnt += cnt
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int, input().split()))
ans = 0
A = [0]*max(L)
for i in range(n):
    A[L[i]-1] += 1
L.sort()

for i in range(n-2):
    for j in range(i+1, n-1):
        ans += sum(a for a in A[L[j]:L[i]+L[j]-1])
print(ans)

Submission status: Wrong Answer

Solution code:
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]+a.count(i)
    else:
      dic[i]=dic[i-1]

  #print(dic)

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

  print(result)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# D TLE
import bisect

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

L.sort()
value = 0


for i in range(0, len(L)-2):
    for j in range(i, len(L)-1):
        index = bisect.bisect_left(L[j+1:], L[i]+L[j])
        value+=max(0, index)

print(value)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import bisect

N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(N):
    for j in range(i + 1, N - 1):
        ans += bisect.bisect_right(L, L[i] + L[j]) - j - 1
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
for i in range(n-2):
	for j in range(i+1,n-1):
		if listl[j]<=(listl[i]/2):
			break
		for k in range(j+1,n):

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

Submission status: Wrong Answer

Solution code:
import bisect
from collections import Counter
from itertools import combinations

N = int(input())
l = map(int,input().split())
l = sorted(l)
l_dict = dict()
for i,one in enumerate(l):
    l_dict[one] = i
    

counter = 0

for a,b in combinations(l,2):
    tmp = a + b
    counter += bisect.bisect_left(l[l_dict[b]+1:],tmp)

print(counter)

Submission status: Wrong Answer

Solution code:
import sys


def main():
    n = int(sys.stdin.readline().strip())
    l = [int(s) for s in sys.stdin.readline().strip().split()]

    # n = 4
    # l = [4, 3, 1, 2]

    # n = 7
    # l = [1, 1, 1, 9, 9, 9, 9]
    # 1 + 4 + 3 * 6

    # l = [1, 1, 2, 2, 2, 3, 3]
    # (1, 1, 2) * 3
    # (1, 2, 2) * 3
    # (1, 3, 3) * 2
    # (2, 2, 2) * 1
    # (2, 2, 3) * 6
    # (2, 3, 3) * 3
    #            18

    # l = [1, 1, 2, 2, 3, 3]  # 2 + 2 + 2 + 2
    # (1, 2, 2) * 2
    # (1, 3, 3) * 2
    # (2, 2, 3) * 2
    # (2, 3, 3) * 2

    # n = 4
    # l = [9, 9, 9, 1] # 4
    # l = [9, 9, 1, 1] # 2
    # l = [1, 1, 1, 9, 9, 9] # 2 + 9

    table = [0] * 1001

    for i in range(n):
        length = l[i]
        table[length] += 1

    total_so_far = [0] * 1001
    total = 0
    for i in range(1001):
        total += table[i]
        total_so_far[i] = total

    def aC2(a):
        return a * (a-1) // 2

    def aC3(a):
        return a * (a-1) * (a-2) // 6

    # [l1, l2)
    def range_total(l1, l2):
        assert l1 > 0
        if l1 >= l2:
            return 0
        if l2 > 1001:
            l2 = 1001
        return total_so_far[l2-1] - total_so_far[l1-1]

    ans = 0
    for i in range(1, 1001):
        for j in range(i+1, 1001):
            if table[i] < 1 or table[j] < 1:
                continue
            a_plus_b = i + j
            inc = range_total(j+1, a_plus_b)
            ans += max(0, inc)

    # a, a, b
    for i in range(1, 1001):
        for j in range(i+1, 1001):
            if table[i] > 2:
                if i + i > j:
                    ans += aC2(table[i]) * table[j]

    # a, b, b
    for i in range(1, 1001):
        for j in range(i+1, 1001):
            if table[j] > 2:
                ans += aC2(table[j]) * table[i]

    # a, a, a
    for i in range(1, 1001):
        ans += aC3(table[i])

    print(ans)


main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import bisect

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

ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        insert_index = bisect.bisect_left(l,l[i]+l[j])
        ans+=(insert_index)
        
print(ans)

Submission status: Wrong Answer

Solution code:
num = int(input())
pole_list = [int(item) for item in input().split()]
 
cnt = 0
 
for a in pole_list:
    
    b_list = [b for b in pole_list if b > a]
    for b in b_list:
 
        c_list = [c for c in b_list if c < a + b]
        for c in c_list:
            if a < b and b < c and a < c:
                cnt +=1
 
print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools

height_num = input()
input_list = input().split()
triangle_list = itertools.combinations(input_list, 3)
triangle_num = 0
for triangle in list(triangle_list):
    triangle = sorted(triangle)
    if int(triangle[0]) + int(triangle[1]) > int(triangle[2]):
        triangle_num += 1
print(triangle_num)

Submission status: Wrong Answer

Solution code:
import bisect

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

su=0
t=1
for i in range(n-1):
    if L[i]==L[i+1]:
        t+=1
    else:
        su+=t*(t-1)*(t-2)//6
        t=1
su+=t*(t-1)*(t-2)//6
print(su)
t=1
for i in range(n-1):
    if L[i]==L[i+1]:
        t+=1
    else:
        su+=(bisect.bisect_left(L, 2*L[i])-t)*t*(t-1)//2
        t=1
su+=(bisect.bisect_left(L, 2*L[i])-t)*t*(t-1)//2
print(su)
for i in range(n):
    for j in range(n):
        if i<j:
            su+=max(0,bisect.bisect_left(L,L[i]+L[j])-max(bisect.bisect_right(L,L[i]),bisect.bisect_right(L,L[j])))

print(su)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random  # randome is not available at Codeforces
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
#eps=10**(-10)
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=lambda: sys.stdin.readline().rstrip()

show_flg=False
show_flg=True

n=I()
a=sorted(LI())[::-1]

s=set()
for i in a:
    s.add(i)
s=sorted(list(s))[::-1]
L=1080
#L=10000
k=[0]*(L)
ak=[0]
ans=0

for i in a:
    k[i]+=1
for i in range(L):
    ak.append(ak[-1]+k[i])

un=len(s)
for i in range(un):
    c=s[i]
    if k[c]>=3:
        ans+=k[c]*(k[c]-1)*(k[c]-2)//6
    elif k[c]==2:
        ans+=ak[c]
    for j in range(i+1,un):
        #show('i,j,s[i],s[j],mm',i,j,'|',s[i],s[j],s[i]-s[j]+1,'|',ak[s[i]-s[j]],ans)
        
        sc=s[j]
        if ak[sc]==0:
            break
        mm=c-sc+1
        if mm<0:
            continue
        elif mm>sc:
            continue # break
        else:
            ans+=k[sc]*(k[sc]-1)//2+ak[sc]-ak[mm]
        #show('ans+=',k[sc]*(k[sc]-1)//2+ak[sc]-ak[mm])
    
print(ans)

Submission status: Wrong Answer

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

cnt = 0
for a in range(n):
  for b in range(a+1,n):
    for c in range(b+1,n):
      if a >= b + c:
        continue
      elif b >= a+c:
        continue
      elif c >= a + b:
        continue
      else:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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

L = sorted(L, reverse=True)
print(L)
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
                break
        if flag:
            break
    if flag:
        break
                
print(count)

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)):
        p = l[i] + l[j]
        for k in range(j+1, len(l)):
            if l[k] < p:
                cnt += 1
            else:
                break

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys

#+++++

def is_tr(a,b,c):
	if a < b+c:
		return True
	return False


def main():
	n = int(input())
	ll = list(map(int, input().split()))
	ll.sort(reverse = True)
	pa(ll)
	
	ret = 0
	for i,l1 in enumerate(ll[:-2]):
		ok=i+2
		for j, l2 in enumerate(ll[i+1:-1]):
			pa(ret)
			if not is_tr(l1, l2, ll[j+1]):
				break
			if is_tr(l1,l2,ll[-1]):
				pa('ggg')
				ret += n-j
				continue
			ng=n-1
			while ng-ok > 1:
				mid = (ok+ng)//2
				if is_tr(l1,l2,ll[mid]):
					ok =mid
				else:
					ng = mid
			pa((ok,j))
			ret += ((n-ok) -j-1)
	
	print(ret)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

Solution code:
import itertools

height_num = input()
input_list = input().split()
triangle_list = itertools.combinations(input_list, 3)
triangle_num = 0
for triangle in list(triangle_list):
    triangle = sorted(triangle)
    if triangle[0] + triangle[1] < triangle[2]:
        triangle_num += 1
print(triangle_num)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=sorted(list(map(int, input().split())))
print(s)
ans=0
count=0
for i in range(n-2):  
  l,r=i+1,i+2
  sums=s[i]+s[l]
  while r<n:
    if s[r]<sums:
      count+=1
      if r==n-1:
        ans+=count
        count=0
        sums=sums-s[l]+s[l+1]
        l+=1
        r=l
      r+=1
    elif l==r:
      r+=1
    else:
      ans+=count
      count=0
      sums=sums-s[l]+s[l+1]
      l+=1
      r=l+1
print(ans)

Submission status: Wrong Answer

Solution code:
# D: Triangles
N = int(input())
L = [int(l) for l in input().split()]

tri = [[a, b, c] for a in range(0,N-2) for b in range(a+1,N-1) for c in range(b+1,N)]
num = 0

for i, t in enumerate(tri):
    if (t[0] < t[1] + t[2]) and (t[1] < t[0] + t[2]) and (t[2] < t[0] + t[1]):
        num += 1
print(num)

Submission status: Wrong Answer

Solution code:
import bisect

ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
l = nl()

il = sorted(l)
l = il[::-1]

ans = 0

for a in range(n):
    fl = 0
    A = l[a]
    bb = bisect.bisect_left(il[:a], A//2)
    print(bb)
    for b in range(a+1,min(n, n - bb + 1)):
        B = l[b]
        if A > B*2:
            break

        for c in range(b+1,n):


            C = l[c]

            if A - B >= C:
                break

            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from fractions import gcd
from functools import reduce
from itertools import accumulate, combinations
from random import random

import numpy as np

sys.setrecursionlimit(200000)


class Solver:
    def __init__(self):
        pass

    def input(self):
        """
            faster input function than builtin stdin.
        """
        return sys.stdin.readline()[:-1]

    def ii(self, t: type = int):
        """
            input single value.
        """
        return t(self.input())

    def il(self, t: type = int):
        """
            input single line.
        """
        return list(map(t, self.input().split()))

    def imi(self, N: int, t: type = int):
        return [self.ii(t) for _ in range(N)]

    def iml(self, N: int, t: type = int):
        return [self.il(t) for _ in range(N)]

    def is_triangle(self, a, b, c):
        return a < b + c and b < c + a and c < a + b

    def solve(self):
        N = self.ii()
        L = self.il()
        L = list(reversed(sorted(L)))

        ans = 0
        LL = [[0 for _ in range(N - 1)] for _ in range(N - 1)]
        for i, L_0 in enumerate(L):
            for j, L_1 in enumerate(L[i + 1 :]):
                if L_0 - L_1 > 0:
                    ans += 1
        return ans - 2 if ans >= 2 else 0


if __name__ == "__main__":
    solver = Solver()
    print(solver.solve())

Submission status: Wrong Answer

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

#print(l)
#s = input()
ans = 0

for i in range(n-2):
  tmp = []
  for j in range(i+2,n-1):
    tmp.append(l[j]-l[i])
  for j in range(i+1,n-1):
    j2 = [x for x in tmp if l[j] > x]
    ans += len(j2)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
up = sorted(l)
down = sorted(l,reverse=True)
sum = 0
for i in range(n-1):
    j = 0
    k = i+1
    flag = True
    while flag:
        if up[j] == down[k]:
            break
        else:
            if down[i] >= up[j] + down[k]:
                j += 1
            else:
                sum += n-k-j-1
                k += 1
print(sum)

Submission status: Wrong Answer

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

L.sort()
c=N-1
ans=0

while c>1:
  i=0
  j=1
  flg=False
  while i<c:
    while j<c:
      if L[c]<L[i]+L[j]:
        ans+=(j-i)*(c-j)
        ans+=((c-j)*(c-j-1)//2)

        flg=True
        break
      j+=1
    if flg==True:
      break
    i+=1
    j=i+1


  c-=1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=input().split()
print(l)
sum=0
for i in range(n-2):
	a=int(l[i])
	for j in range(i+1,n):
		b=int(l[j])
		for k in range(j+1,n):
			c=int(l[k])
			if a>=(b+c) or b>=(c+a) or c>=(a+b):
				sum=sum
			else:
				sum=sum+1
			
print(sum)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=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):
            if s[i]+s[j]<=s[k]:
                print(ans)
                exit()
            elif s[j]+s[k]<=s[i]:
                print(ans)
                exit()
            elif s[i]+s[k]<=s[j]:
                print(ans)
                exit()
            else:
                ans+=1
                print(ans)

Submission status: Wrong Answer

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

for i in box:
  for j in sticks:
    if i > j:
      point+=1
      
    

print(n*(n-1)*(n-2)//2 -point+2*len(box))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import itertools
import bisect

N = int(input())
L = sorted(list(map(int, input().split())))
print(L)
sum = 0
for i in range(len(L)):
    a = L[i]
    for j in range(i + 1, len(L)):
        b = L[j]
        c_index = bisect.bisect_right(L, a + b)
        print("a, b = {}, {}, c_index = {}".format(a, b, c_index))
        sum += len(L) - c_index
print(sum)

Submission status: Wrong Answer

Solution code:
import itertools

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

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

for i in range(len(A)):
  A[i]=sorted(A[i])

B = [S for S in A if not S[0]+S[1]<S[2]]

ANS=[]
for X in B:
  if X not in ANS:
    ANS.insert(0,X)

print(len(ANS))

Submission status: Wrong Answer

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

ans = 0
n = 0
SUM = int(N*(N-1)*(N-2) / 6)

import sys

for i in range(N):
  for j in range(i+1, N):
    for k in range(N-1, j, -1):
      n += 1
      if(L[i]+L[j]> L[k]):
        ans += k - j
        if(k == j and i != N-2):
          ans += SUM - n
          print(ans)
          sys.exit()
        break

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

D=int(N*(N-1)*(N-2)//6)
C = 0
for i in range(N-2):
	if L[i+2]>=L[i+1]+L[i]:
		C+=1
		D=D-(i+1)*(N-1)

print(D)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

L.sort(reverse=True)

import itertools
from math import factorial

nCr = N*(N-1)*(N-2)/6

count = 0

for i in range(N):
  if L[0]-L[N-1] < L[i]:
    count+=1

print(int(nCr - count*(count-1)))

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
l = list(map(int,input().split()))
l.sort()
#print(l)


ans = 0
for i in range(N - 1 , 2 , -1):
    for j in range(N - 2 , 1 , -1):
        work = l[:j]
        x = l[i] - l[j]
        idx = bisect.bisect_right(work, x)
        ans += len(work) - idx
print(ans)

Submission status: Wrong Answer

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

L.sort()

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

  x = dp[L[b]-1] - dp[sub]
  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:
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={}
count=0
for i in range(len(L)-1):
    low=L[i]
    
    for j in range(i+1, len(L)):
        #すでに探索済みか判定

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

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

Submission status: Wrong Answer

Solution code:
N=int(input())
L=map(int,input().split())
l=list(L)
result=0
for i in range(0,len(l)-1):
  for j in range(0,len(l)-1):
    for k in range(0,len(l)-1):
      if l[i]>(l[j]+l[k]):
        result+=1

print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(map(int, input().split()))
tlis = []
for i, x in enumerate(s):
    for j, y in enumerate(s):
        for k, z in enumerate(s):
            if i != j:
                if i != k:
                    if j != k:
                        tlis.append([x, y, z])
        
ans = 0
for e in tlis:
    if e[0] < e[1] + e[2]:
        if e[1] < e[0] + e[2]:
            if e[2] < e[1] + e[0]:
                ans += 1
print(ans)