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:
def Binary_Search_Small_Count(A,x,sort=True,equal=False):
    """2分探索によって,x未満の要素の個数を調べる.

    A:リスト
    x:調べる要素
    sort:ソートをする必要があるかどうか(Trueで必要)
    equal:Trueのときはx"未満"がx"以下"になる
    """
    if sort:
        A.sort()
        
    N=len(A)
    if A[-1]<x:
        return N
    elif x<A[0] or (not equal and x==A[0]):
        return 0

    L,R=0,N
    while R-L>1:
        C=L+(R-L)//2
        if x<A[C] or (not equal and x==A[C]):
            R=C
        else:
            L=C
    return R
#=======================================
N=int(input())
L=list(map(int,input().split()))
L.sort()

K=0
for i in range(N):
    for j in range(i+1,N):
        a,b=L[i],L[j]
        X=Binary_Search_Small_Count(L,a+b,False,False)
        Y=Binary_Search_Small_Count(L,b,False,False)
        K+=X-Y-1

        if a==b:
            K-=1
print(K)

Submission status: Wrong Answer

Solution code:
def Binary_Search_Small_Count(A,x,sort=True,equal=False):
    """2分探索によって,x未満の要素の個数を調べる.

    A:リスト
    x:調べる要素
    sort:ソートをする必要があるかどうか(Trueで必要)
    equal:Trueのときはx"未満"がx"以下"になる
    """
    if sort:
        A.sort()
        
    N=len(A)
    if A[-1]<x:
        return N
    elif x<A[0] or (not equal and x==A[0]):
        return 0

    L,R=0,N
    while R-L>1:
        C=L+(R-L)//2
        if x<A[C] or (not equal and x==A[C]):
            R=C
        else:
            L=C
    return R
#=======================================
N=int(input())
L=list(map(int,input().split()))
L.sort()

K=0
for i in range(N):
    for j in range(i+1,N):
        a,b=L[i],L[j]
        X=Binary_Search_Small_Count(L,a+b,False,False)
        Y=Binary_Search_Small_Count(L,b,False,False)
        K+=X-Y

print(K)

Submission status: Wrong Answer

Solution code:
def Binary_Search_Small_Count(A,x,sort=True,equal=False):
    """2分探索によって,x未満の要素の個数を調べる.

    A:リスト
    x:調べる要素
    sort:ソートをする必要があるかどうか(Trueで必要)
    equal:Trueのときはx"未満"がx"以下"になる
    """
    if sort:
        A.sort()
        
    N=len(A)
    if A[-1]<x:
        return N
    elif x<A[0] or (not equal and x==A[0]):
        return 0

    L,R=0,N
    while R-L>1:
        C=L+(R-L)//2
        if x<A[C] or (not equal and x==A[C]):
            R=C
        else:
            L=C
    return R
#=======================================
N=int(input())
L=list(map(int,input().split()))
L.sort()

K=0
for i in range(N):
    for j in range(i+1,N):
        a,b=L[i],L[j]
        X=Binary_Search_Small_Count(L,a+b,False,False)
        Y=Binary_Search_Small_Count(L,b,False,False)
        K+=X-Y

        if b<=a<a+b:
            K-=1
        if b<=b<a+b:
            K-=1

print(K)

Submission status: Wrong Answer

Solution code:
def Binary_Search_Small_Count(A,x,sort=True,equal=False):
    """2分探索によって,x未満の要素の個数を調べる.

    A:リスト
    x:調べる要素
    sort:ソートをする必要があるかどうか(Trueで必要)
    equal:Trueのときはx"未満"がx"以下"になる
    """
    if sort:
        A.sort()
        
    N=len(A)
    if A[-1]<x:
        return N
    elif x<A[0] or (not equal and x==A[0]):
        return 0

    L,R=0,N
    while R-L>1:
        C=L+(R-L)//2
        if x<A[C] or (not equal and x==A[C]):
            R=C
        else:
            L=C
    return R
#=======================================
N=int(input())
L=list(map(int,input().split()))
L.sort()

K=0
for i in range(N):
    for j in range(i+1,N):
        a,b=L[i],L[j]
        X=Binary_Search_Small_Count(L,a+b,False,False)
        Y=Binary_Search_Small_Count(L,b,False,True)
        K+=X-Y

        if b<=a<a+b:
            K-=1
        if b<=b<a+b:
            K-=1

print(K)

Submission status: Wrong Answer

Solution code:
def Binary_Search_Small_Count(A,x,sort=True,equal=False):
    """2分探索によって,x未満の要素の個数を調べる.

    A:リスト
    x:調べる要素
    sort:ソートをする必要があるかどうか(Trueで必要)
    equal:Trueのときはx"未満"がx"以下"になる
    """
    if sort:
        A.sort()
        
    N=len(A)
    if A[-1]<x:
        return N
    elif x<A[0] or (not equal and x==A[0]):
        return 0

    L,R=0,N
    while R-L>1:
        C=L+(R-L)//2
        if x<A[C] or (not equal and x==A[C]):
            R=C
        else:
            L=C
    return R
#=======================================
N=int(input())
L=list(map(int,input().split()))
L.sort()

K=0
for i in range(N):
    for j in range(i+1,N):
        a,b=L[i],L[j]
        X=Binary_Search_Small_Count(L,a+b,False,False)
        Y=Binary_Search_Small_Count(L,b,False,True)
        K+=X-Y

print(K)

Submission status: Wrong Answer

Solution code:
def Binary_Search_Small_Count(A,x,sort=True,equal=False):
    """2分探索によって,x未満の要素の個数を調べる.

    A:リスト
    x:調べる要素
    sort:ソートをする必要があるかどうか(Trueで必要)
    equal:Trueのときはx"未満"がx"以下"になる
    """
    if sort:
        A.sort()
        
    N=len(A)
    if A[-1]<x:
        return N
    elif x<A[0] or (not equal and x==A[0]):
        return 0

    L,R=0,N
    while R-L>1:
        C=L+(R-L)//2
        if x<A[C] or (not equal and x==A[C]):
            R=C
        else:
            L=C
    return R
#=======================================
N=int(input())
L=list(map(int,input().split()))
L.sort()

K=0
for i in range(N):
    for j in range(i+1,N):
        a,b=L[i],L[j]
        X=Binary_Search_Small_Count(L,a+b,False,False)
        Y=Binary_Search_Small_Count(L,b,False,True)
        K+=X-Y-1

print(K)

Submission status: Wrong Answer

Solution code:
import bisect
n=int(input())
l=list(map(int,input().split()))
l.sort()
c=0
print(l)
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      print(i,j,k)
      if l[i]+l[j]>l[k] and l[j]+l[k]>l[i] and l[k]+l[i]>l[j]:
        c+=1
      elif l[i]+l[j]<=l[k]:
        break
print(c)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N=int(input().rstrip('\n'))
ls = [int(i) for i in input().rstrip('\n').split()]
ls=sorted(ls,reverse = True)
res = 0
for x in range(N-2):
  a = ls[x]
  for y in range(x+1,N-1):
    b = ls[y]
    if a-b>ls[y+1]:
      break
    else:
      for z in range(y+1,N):
        if a-b>=ls[z]:
          res += z-y
          break
        if z ==N-1:
          res += N-y-1
print(res)

Submission status: Wrong Answer

Solution code:
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
import math
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math as M
MOD=10**9+7
import bisect
#####################################
n=int(input())
A=INPUT()
A.sort()
D=[0]*1001
#eqiu
ans=0
for i in range(n):
    D[A[i]]+=1
for i in range(1001):
    if D[i]>=3:
        ans+=1
X=list(set(A))
X.sort()
x=len(X)
#scalane
for i in range(x-2):
    for j in range(i+1,x):
        ans+=bisect.bisect_left(X,X[i]+X[j],0,x)-j-1
#isoscles
for i in range(1,1001):
    for j in range(i+1,1001):
        if D[i]>0 and D[j]>0 and D[i]+D[j]>=3:
            if D[i]>=2 and D[j]>=2:
                if 2*i>j:
                    ans+=1
                if 2*j>i:
                    ans+=1
            elif D[i]==1:
                ans+=1
            elif D[j]==1:
                if 2*i>j:
                    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
import math
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math as M
MOD=10**9+7
import bisect
#####################################
n=int(input())
A=INPUT()
A.sort()
D=[0]*1001
#eqiu
ans=0
for i in range(n):
    D[A[i]]+=1
for i in range(1001):
    if D[i]>=3:
        ans+=1
X=list(set(A))
X.sort()
x=len(X)
#scalane
for i in range(x-2):
    for j in range(i+1,x):
        ans+=bisect.bisect_left(X,X[i]+X[j],0,x)-j-1
#isoscles
for i in range(1,1001):
    for j in range(i+1,1001):
        if D[i]>0 and D[j]>0 and D[i]+D[j]>=3:
            if D[i]>=2 and D[j]>=2:
                if 2*i>j:
                    ans+=1
            elif D[i]==1:
                ans+=1
            elif D[j]==1:
                if 2*i>j:
                    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools, bisect

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

ans = 0
for a, b in itertools.combinations(L, 2):
    ans += bisect.bisect_left(L, a + b) - bisect.bisect_right(L, b)
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
import math
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math as M
MOD=10**9+7
import sys
#####################################
n=int(input())
A=INPUT()
B=sorted(A)
S=sorted(set(B))
ans=0
L=[0]*1001
D=[0]*1001
for i in range(n):
    L[A[i]]+=1
# equilateral
for i in range(1,1001):
    if L[i]>=1:
        D[i]=D[i-1]+1
for i in range(1001):
    if L[i]>=3:
        ans+=1
# isoslcels
#print(ans)
for i in range(1001):
    for j in range(i+1,1001):
        if L[i]>=1 and L[j]>=1 and L[i]+L[j]>=3:
            if L[i]>=2 and L[j]>=2:
                if 2*i>j:
                    ans+=1
                if 2*j>i:
                    ans+=1
            elif L[i]==1 and L[j]>1:
                if 2*j>i:
                    ans+=1
            elif L[i]>1 and L[j]==1:
                if 2*i>j:
                    ans+=1

#print(ans)
for i in range(len(S)):
    for j in range(i+1,len(S)):
        k=i+2
        while(k<len(S) and S[i]+S[j]>S[k]):
            k+=1
        if k>j:
            ans+=k-j-1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Ls = list(mapint())
Ls.sort()

from bisect import bisect_right
ans = 0

for i in range(N-2):
    for j in range(i+1, N-1):
        idx = bisect_right(Ls, Ls[i]+Ls[j])
        ans += idx-j-1

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

N=int(input())
L=list(map(int,input().split()))
lis=list(itertools.combinations(L,2))

ans=0
for li in lis:
    b,c=li[0],li[1]
    if b>=c:
        n=len([l for l in L if b-c<l<b+c])-len([b-c<c<b+c])
    else:
        n=len([l for l in L if c-b<l<b+c])-len([c-b<c<b+c])
    ans+=n
    
print(ans//3)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from itertools import combinations
n = int(input())
l = list(map(int, input().split()))

count = Counter(l)
ans = 0
for a,b,c in combinations(set(l),3):
  if a >= b+c or b >= a+c or c >= a+b: continue
  t = 1
  for i in [a,b,c]: t *= count[a]
  ans += t
print(ans)

Submission status: Wrong Answer

Solution code:

def is_triangle(a, b, c):
    print(a, b, c)
    if a >= b + c:
        return False

    if b >= a + c:
        return False

    if c >= a + b:
        return False

    return True


def main():
    N = int(input())
    L = list([int(x) for x in input().split()])

    L.sort(reverse=True)

    count = 0
    for index, a in enumerate(L):
        if index + 2 == N:
            break

        for b_i in range(index+1, N):
            b = L[b_i]
            c_i = 1

            while not is_triangle(a, b, L[-c_i]):
                if c_i + b_i == N:
                    break
                c_i += 1

            count += (N - b_i - c_i)

    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
c = np.zeros(10 ** 3 + 1, dtype=int)
for l in L:
    c[l:] += 1
ans = 0
for i, a in enumerate(L):
    for b in L[i+1:]:
        ans += max(0, c[b - 1] - c[a - b])
print(ans)

Submission status: Wrong Answer

Solution code:
# D - Triangles
N = int(input())
S = list(map(int, input().split()))
S = sorted(S, reverse=True)
print(S)

cnt = 0
for i in range(N-2):
	A = S[i]
	for j in range(i+1,N-1):
		B = S[j]
		for k in range(j+1,N):
			C = S[k]
			if C > A - B:
				cnt += 1
			else:
				break

print(cnt)

Submission status: Wrong Answer

Solution code:
#import itertools

n = int(input())
l = [int(x) for x in input().split()]

#lis = list(itertools.combinations(deta,num))

l.sort()
l_2 = list(set(l))
l_2.sort()

num = [0]*(10**3+1)
num_2= [0]*(10**3+1)


for i in l:
    num[i] = 1
    num_2[i] += 1

ans = 0
n_2 = len(l_2)

for i in range(n_2):
    for j in range(i+1,n_2):
        i_1 = l_2[i]
        j_1 = l_2[j]
        ans += sum(num[max(i_1-j_1+1,j_1-i_1+1,j_1+1):i_1+j_1])
        #print(i_1,j_1,ans)
        if num_2[i_1] > 1:
            ans+= sum(num[1:i_1*2])
        if num_2[i_1] > 2:
            ans += 1

        num[i] = 0


print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

def find3(n):
  return list(itertools.combinations(n, 3)) 

def isTriangle(a, b, c):
  return (a+b>c and c+a>b and b+c>a)

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

li2 = find3(li)
ans = 0
for i in li2:
  if (isTriangle(i[0], i[1], i[2])):
    ans+=1

Submission status: Wrong Answer

Solution code:
import bisect

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

ans = 0
for i in range(len(L)):
    for j in range(i + 1, len(L)):
        a = L[i]
        b = L[j]
        left = bisect.bisect_right(L, b)
        right = bisect.bisect_left(L, a + b)
        ans += right - left

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

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

ans = 0
for i in range(len(L)):
    for j in range(i + 1, len(L)):
        a = L[i]
        b = L[j]
        left = b - a
        right = a
        ans += max(0, bisect.bisect_left(L, right) - bisect.bisect_right(L, left))

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

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

ans = 0
for i in range(len(L)):
    for j in range(i + 1, len(L)):
        a = L[i]
        b = L[j]
        left = b
        right = a + b
        ans += bisect.bisect_left(L, right) - bisect.bisect_right(L, left)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

ri = lambda: int(sys.stdin.readline())
rl = lambda: list(map(int, sys.stdin.readline().split()))

a = ri()
li = sorted(rl(), reverse=True)
cnt = 0
for i in range(a-2):
    for j in range(i+1, a-1):
        left = j+1
        right = a
        lii = li[i]
        lij = li[j]
        t = -1
        while right-left > 1:
            t = (left + right)//2
            lit = li[t]
            if lii < lij + lit:
                left = t
            else:
                right = t
        if lii < lij + li[t]:
            cnt += left-j
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
ri = lambda: int(sys.stdin.readline())
rl = lambda: list(map(int, sys.stdin.readline().split()))

a = ri()
li = sorted(rl(), reverse=True)
cnt = 0
for i in range(a-2):
    for j in range(i+1, a-1):
        left = j+1
        right = a
        lii = li[i]
        lij = li[j]
        t = 0
        while right-left > 1:
            t = (left + right)//2
            lit = li[t]
            if lii < lij + lit:
                left = t
            else:
                right = t
        if lii < lij + li[t]:
            cnt += left-j
print(cnt)

Submission status: Wrong Answer

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

r=0
import numpy as np
for ii in range(len(a1)-2):
  for jj in np.arange(ii+1,len(a1)-1):
    for kk in np.arange(jj+1,len(a1)):
      if a1[ii]+a1[jj]<=a1[kk]:
        break
      r+=1
print(r)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=set(a)
a1=[]
a2=[]
a3=[]
for ii in s:
  c=a.count(ii)
  if c==1:
    a1.append(ii)
  elif c==2:
    a2.append(ii)
  else:
    a3.append(ii)
a2=a2+a3
a1.sort()
a2.sort()

r=len(a3)
for ii in range(len(a2)):
  for jj in range(len(a1)):
    if 2*a2[ii]<=a1[jj]:
      break
    r+=1

  for jj in range(len(a2)):
    if 2*a2[ii]<=a2[jj]:
      break
    if ii!=jj:
      r+=1
a1=a1+a2
import numpy as np
for ii in range(len(a1)-2):
  for jj in np.arange(ii+1,len(a1)-1):
    for kk in np.arange(jj+1,len(a1)):
      if a1[ii]+a1[jj]<=a1[kk]:
        break
      r+=1
      #print(r,a1[ii],a1[jj],a1[kk])
print(r)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=set(a)
a1=[]
a2=[]
a3=[]
for ii in s:
  c=a.count(ii)
  if c==1:
    a1.append(ii)
  elif c==2:
    a2.append(ii)
  else:
    a3.append(ii)
a1=a1+a2*2+a3*3
a1.sort()#reverse=True)
#print(a1)
import numpy as np
r=0
for ii in range(len(a1)-2):
  for jj in np.arange(ii+1,len(a1)-1):
    for kk in np.arange(jj+1,len(a1)):
      if a1[ii]+a1[jj]<=a1[kk]:
        break
      if kk==len(a1)-1 or a1[kk]!=a1[kk+1]:
        r+=1
      #print(r,a1[ii],a1[jj],a1[kk])
print(r)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=set(a)
a1=[]
a2=[]
a3=[]
for ii in s:
  c=a.count(ii)
  if c==1:
    a1.append(ii)
  elif c==2:
    a2.append(ii)
  else:
    a3.append(ii)
a1=a1+a2*2+a3*3
a1.sort()#reverse=True)
#print(a1)
import numpy as np
r=0
for ii in range(len(a1)-2):
  for jj in np.arange(ii+1,len(a1)-1):
    for kk in np.arange(jj+1,len(a1)):
      if a1[ii]+a1[jj]<=a1[kk]:
        break
      r+=1
      #print(r,a1[ii],a1[jj],a1[kk])
print(r)

Submission status: Wrong Answer

Solution code:
import sys,math,collections,itertools,copy
import numpy as np
input = sys.stdin.readline

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

Lc = collections.Counter(L)
Lcl =np.array(sorted([[key,val] for key,val in Lc.items()],key = lambda x:(x[0])))
Lclkey = Lcl[:,0]
Lclval = Lcl[:,1]
max_Lclkey = Lclkey[-1]
ans =0

for a in range(len(Lclkey)):
    for b in range(a,(len(Lclkey))):
        if Lclval[a] == 1 and a==b:
            continue
        else:
            for c in range(b,(len(Lclkey))):
                if Lclkey[a]+Lclkey[b] <= Lclkey[c]:
                    break
                if (Lclval[a] == 2 and a==b and b==c) or (Lclval[b] == 1 and b==c):
                    continue
                
                if (a==b):
                    ans += Lclval[a]*(Lclval[a]-1)//2*Lclval[c]
                elif a ==b and b==c:
                    ans += Lclval[a]*(Lclval[a]-1)*(Lclval[a]-2)//3//2
                else:
                    
                    ans += Lclval[a]*Lclval[b]*Lclval[c]
          
print(ans)

Submission status: Wrong Answer

Solution code:
import sys,math,collections,itertools,copy
import numpy as np
input = sys.stdin.readline

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

Lc = collections.Counter(L)
Lcl =np.array(sorted([[key,val] for key,val in Lc.items()],key = lambda x:(x[0])))
Lclkey = Lcl[:,0]
Lclval = Lcl[:,1]
max_Lclkey = Lclkey[-1]
ans =0

for a in range(len(Lclkey)):
    for b in range(a,(len(Lclkey))):
        if Lclval[a] == 1 and a==b:
            continue
        else:
            tm1 = (Lclkey[b] <= Lclkey )
            tm2 = (Lclkey < Lclkey[a]+Lclkey[b])
        lv = copy.copy(Lclval)
        lv[a] -= 1
        lv[b] -= 1
        #print(tm1,tm2,lv,tm1*tm2*lv)
        ans += sum(tm1*tm2*lv) 
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
x=list(map(int, input().split()))
y=list(set(x))
import collections as cl
z=cl.Counter(x)
y2, y3=[], []
for k, v in z.items():
  if v==2:
    y2.append(int(k))
  elif v>2:
    y3.append(int(k))
n1=len(y)
n2=len(y2)
n3=len(y3)
from itertools import combinations
C=list(combinations(range(n1), 3))

def cond(a, b, c):
  c1=a+b>c
  c2=b+c>a
  c3=c+a>b
  if c1 and c2 and c3:
    return True
  else:
    return False

ans=0
for c in C:
  if cond(y[c[0]], y[c[1]], y[c[2]]):
    ans+=1
for Y2 in y2:
  for Y in y:
    if Y==Y2:
      continue
    if cond(Y2,Y2, Y):
      ans+=1
ans+=n3
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    inlis = list(map(int, input().split()))
    indic = dict()
    for num in inlis:
        if num not in indic:
            indic[num] = 1
        else:
            indic[num] += 1
    indic_sort = sorted(indic.items())
    #print(indic_sort)
    ans = 0

    for num1 in indic_sort:
        for num2 in indic_sort:
            for num3 in indic_sort:
                if num1[0] < num2[0]:
                    if num3[0] >= num1[0] + num2[0]:
                        break
                    elif num3[0] > num2[0]:
                        #print(num1, num2, num3, num3[0])
                        ans += num3[1]

    print(ans)
                                    
                



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    inlis = list(map(int, input().split()))
    inset = set()
    indic = dict()
    for num in inlis:
        if num not in inset:
            inset.add(num)
        if num not in indic:
            indic[num] = 1
        else:
            indic[num] += 1
    indic_sort = sorted(indic.items())
    #print(indic_sort)
    ans = 0

    for num1 in indic_sort:
        for num2 in indic_sort:
            for num3 in indic_sort:
                if num1[0] < num2[0]:
                    if num3[0] >= num1[0] + num2[0]:
                        break
                    elif num3[0] > num2[0]:
                        #print(num1, num2, num3, num3[0])
                        ans += num3[1]

    print(ans)
                                    
                



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    inlis = list(map(int, input().split()))
    inset = set()
    indic = dict()
    for num in inlis:
        if num not in inset:
            inset.add(num)
        if num not in indic:
            indic[num] = 1
        else:
            indic[num] += 1
    
    ans = 0

    for i in inset:
        for j in inset:
            for k in inset:
                if i < j < k and i+j > k:
                    ans += indic[k]
    print(ans)
                                    
                



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools
import bisect

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

ans = 0

for a,b in itertools.combinations(LS,2):
  a,b = min(a,b),max(a,b)
  lo = b - a
  up = a + b
  
  cnt = bisect.bisect_left(LS,up) - bisect.bisect_right(LS,lo) - 2    
  if cnt <= 0:
    continue
    
  ans += cnt
  
print(ans // 3)

Submission status: Wrong Answer

Solution code:
import itertools
import bisect

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

ans = 0

for a,b in itertools.combinations(LS,2):
  a,b = min(a,b),max(a,b)
  lo = b - a
  up = a + b
  
  cnt = bisect.bisect_left(LS,up) - bisect.bisect_right(LS,lo) - 1
  if lo < a:
    cnt -= 1
    
  if cnt <= 0:
    continue
    
  ans += cnt
  
print(cnt)

Submission status: Wrong Answer

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

ans = 0
for i in range(len(L)-2):
  for j in range(i+2, len(L)):
    a, b = L[i], L[j]
    right = bisect.bisect_right(L, b-a)
    left = max(right, i+1)
    ans += j - left
print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(len(L)-2):
  for j in range(i+2, len(L)):
    a, b = L[i], L[j]
    right = bisect.bisect_right(L, b-a)
    if b-a < a:
      right += 1
    left = max(right, i+1)
    ans += j - left
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

N, *X = map(int, open(0).read().split())

X.sort()
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k = bisect_right(X, X[i] + X[j])
        ans += N - k
        
print(ans)

Submission status: Wrong Answer

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

L.sort(reverse=True)

for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        # j以降の項で、初めてL[k] < a-bとなるkを二分探索する
        if L[-1] > a - b:  # 一番最後の項でもOKな場合
            total += N - j - 1
        elif L[j+1] <= a - b:  # 一番最初の項からNGな場合
            continue
        else:
            head = j+1  # head はL[head] > a - bを満たす(OK側)
            tail = N-1  # tail はL[tail] <= a - bを満たす(NG側)
            while head+1 != tail:
                if L[(head + tail)//2] >= a - b:  # 中間地点はOK側
                    head = (head + tail) // 2
                else:  # 中間地点はNG側
                    tail = (head + tail) // 2
            total += head - j

print(total)

Submission status: Wrong Answer

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

L.sort(reverse=True)

for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        # j以降の項で、初めてL[k] < a-bとなるkを二分探索する
        if L[-1] > a - b:
            total += N - j - 1
        elif L[j+1] < a - b:
            continue
        else:
            head = j+1
            tail = N-1  # tail はL[tail] < a - bを満たす
            while head != tail:
                if L[(head + tail)//2] >= a - b:  # 探したいkは中間地点より右側
                    head = (head + tail) // 2 + 1
                else:
                    tail = (head + tail) // 2
            total += tail - j - 1

print(total)

Submission status: Wrong Answer

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

n = int(input())
l = list(map(int,input().split()))
l.sort()
mx = l[-1]+l[-2]

length = [0]*(mx+1)
for i in range(n):
    for j in range(i+1,n):
        length[l[i]+l[j]] -= 1
        length[l[j]-l[i]+1] += 1

for i in range(1,mx+1):
    length[i] += length[i-1]

minus = [0]*n
for i in range(n):
    a = i
    for j in range(i+1,n):
        if l[i]*2 - 1 >= l[j]:
            a += 1
    minus[i] = a
#print(length)
#print(minus)
ans = 0
for i in range(n):
    ans += length[l[i]+1] - minus[i]

ans //= 3
if ans < 0:
    ans = 0
print(ans)

Submission status: Wrong Answer

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

# a, bをfixしてcを探索
# n*n*logn
# b-a < c_i < a+b をにぶたん
def binary_search(list, item):
    # listからitem未満の最大のindexを取得
    low = 0
    high = len(list) - 1
    if list[high] < item:
        return high+1
    if list[low] >= item:
        return low
    while True:
        mid = (low + high) //2
        guess = list[mid]
        if high - low <= 1:
            return high
        if guess > item:
            high = mid
        else:
            low = mid

ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        a = l[i]
        b = l[j]
        c_low = binary_search(l[j+1:], b-a)
        c_high = binary_search(l[j+1:], b+a)
        ans += c_high - c_low
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter
N = int(input())
L = list(map(int, input().split()))
L.sort()
l = list(set(L))
l.sort()
m = Counter(L)

ans = 0
s = set()
for i, x in enumerate(L[:-2]):
    for y in L[i+1:-1]:
        if (x, y) in s:
            continue
        s.add((x, y))
        ans += max(0, bisect_left(l, x+y) - bisect_left(l, y))
        if x == y and m[y] < 3:
            ans -= 1
        elif x != y and m[y] < 2:
            ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter
N = int(input())
L = list(map(int, input().split()))
L.sort()
l = list(set(L))
l.sort()
m = Counter(L)

ans = 0
s = set()
for i, x in enumerate(L[:-2]):
    for y in L[i+1:-1]:
        if (x, y) in s:
            continue
        s.add((x, y))
        ans += max(0, bisect_left(l, x+y) - bisect_left(l, y))
        if x == y and m[x] < 3:
            ans -= 1
        elif x != y and m[y] < 2:
            ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right
N = int(input())
L = list(map(int, input().split()))
L.sort()
l = list(set(L))
l.sort()

ans = 0
s = set()
for i, x in enumerate(L[:-1]):
    for y in L[i+1:]:
        if (x, y) in s:
            continue
        s.add((x, y))
        ans += max(0, bisect_left(l, x+y) - bisect_right(l, y))
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
N = int(input())
l = list(map(int, input().split()))
l.sort()
count = 0
now = l[:2]
now.sort(reverse=True)
for i in range(2, N):
    for j in combinations(now, 2):
        if j[0]+j[1] > l[i]:
            count += 1
        else:
            break
    now.insert(0, l[i])
print(count)

Submission status: Wrong Answer

Solution code:
import bisect


N = int(input())
str_l = input()
num = 0
L = []
for v in str_l.split(' '):
    L.append(int(v))

L.sort()
print(L)
for i in range(N - 1):
    a = L[i]
    for j in range(i, N - 2):
        b = L[j + 1]
        index = bisect.bisect_left(L[j + 2:], a + b)
        for k in range(0, index):
            
            c = (L[j + 2:])[k]
            if b + c > a and a + c > b:
                num += 1

print(num)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
#(0)入力環境
import bisect#listをsortしたまま要素を挿入できる
n = int(input())
l = sorted(list(map(int,input().split())))

#(1)考察
#aとbの二重ループのなかで最後の一つは二分探索で高速に
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        ans += bisect.bisect_left(l,l[i] + l[j]) - (j + 1)
        print(ans)

print(ans)

Submission status: Wrong Answer

Solution code:
#<D>
#n<2*10**3だとforまわしたら間に合わん
from itertools import combinations
n = int(input())
l = list(map(int,input().split()))
l = list(set(l))
ans = 0
if len(l) < 3:
    print(0)
    exit()
for i in combinations(l,3):
    if abs(i[1] - i[2]) < i[0] and i[1] + i[2] > i[0]:
        ans += 1
print(ans)