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
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

import itertools as it

def main():
    N=ii()
    L=lmis()
    ans=0
    for a,b,c in it.combinations(L,3):
        if a+b<c: continue
        if a+c<b: continue
        if b+c<a: continue
        ans+=1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

dic = {}

for i in range(N):
    if(ns[i] in dic.keys() and dic[ns[i]]<=2):
        dic[ns[i]] += 1
    elif(ns[i] not in dic.keys()):
        dic[ns[i]] = 1

a,b,c = 0,0,0
for key in dic.keys():
    if(dic[key] == 1):
        a += 1
    elif(dic[key] == 2):
        b += 1
    elif(dic[key] == 3):
        c += 1

unique = a+b+c
sum_ = 0

sum_ += c
sum_ += (b+c)*(unique-1)

key_list = list(dic.keys())
n = len(key_list)
key_list = sorted([int(i) for i in key_list])
print(key_list)
for p in range(n-2):
    for q in range(p+1,n-1):
        if(p<q):
            for r in range(q+1,n):
                if(q<r):
                    x,y,z = int(key_list[p]),int(key_list[q]),int(key_list[r])
                    if((x+y)>z):
                        sum_ += 1
                    else:
                        break

print(int(sum_))

Submission status: Wrong Answer

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

dic = {}

for i in range(N):
    if(ns[i] in dic.keys() and dic[ns[i]]<=2):
        dic[ns[i]] += 1
    elif(ns[i] not in dic.keys()):
        dic[ns[i]] = 1

a,b,c = 0,0,0
for key in dic.keys():
    if(dic[key] == 1):
        a += 1
    elif(dic[key] == 2):
        b += 1
    elif(dic[key] == 3):
        c += 1

unique = a+b+c
sum_ = 0

sum_ += c
sum_ += (b+c)*(unique-1)

key_list = list(dic.keys())
n = len(key_list)
key_list = sorted([int(i) for i in key_list])
print(key_list)
for p in range(n-2):
    for q in range(n-1):
        if(p<q):
            for r in range(n):
                if(q<r):
                    x,y,z = int(key_list[p]),int(key_list[q]),int(key_list[r])
                    if((x+y)>z):
                        sum_ += 1
                    else:
                        break

print(int(sum_))

Submission status: Wrong Answer

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

dic = {}

for i in range(N):
    if(ns[i] in dic.keys() and dic[ns[i]]<=2):
        dic[ns[i]] += 1
    elif(ns[i] not in dic.keys()):
        dic[ns[i]] = 1

a,b,c = 0,0,0
for key in dic.keys():
    if(dic[key] == 1):
        a += 1
    elif(dic[key] == 2):
        b += 1
    elif(dic[key] == 3):
        c += 1

unique = a+b+c
sum_ = 0

sum_ += c
sum_ += (b+c)*(unique-1)

key_list = list(dic.keys())
n = len(key_list)
for p in range(n-2):
    for q in range(n-1):
        if(p<q):
            for r in range(2,n):
                if(q<r):
                    x,y,z = int(key_list[p]),int(key_list[q]),int(key_list[r])
                    if((x+y)>z):
                        sum_ += 1
                    else:
                        break

print(int(sum_))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:


def comp(ext,list0,dev):
    c=int((ext[0]+ext[1])/2)
    if list0[int((ext[0]+ext[1])/2)]>dev:
        return ext[0],int((ext[0]+ext[1])/2)
    else:
        return int((ext[0]+ext[1])/2),ext[1]


def bis(a,b,list0,dev):
    ls=[a,b]
    while ls[0]+1<ls[1]:
        ls=comp(ls,list0,dev)
    if ls[0]==dev:
        return ls[0],"on"
    elif ls[1]==dev:
        return ls[1],"on"
    else:
        return ls[0],"in"


n=int(input())
l=[int(x) for x in input().split()]
l.sort()
s=0
for a in range(0,n-2):
    for b in range(a+1,n-1):
        if l[a]+l[b]>l[n-1]:
            c=[n-1]
        else:
            c=bis(b,n-1,l,l[a]+l[b])
        s=s+c[0]-b
print(s)

Submission status: Wrong Answer

Solution code:


def comp(ext,list0,dev):
    if (list0[ext[0]]+list0[ext[1]])/2>dev:
        return [int((ext[0]+ext[1])/2)+1,ext[1]]
    else:
        return [ext[0],int((ext[0]+ext[1])/2)]


def bis(a,b,list0,dev):
    ls=[a,b]
    while ls[0]<ls[1]:
        ls=comp(ls,list0,dev)
    if ls[0]<dev:
        return [ls[0],"in"]
    else:
        return [ls[0],"out"]


n=int(input())
l=[int(x) for x in input().split()]
l.sort()
s=0
for a in range(0,n-2):
    for b in range(a+1,n-1):
        c=bis(b+1,n-1,l,a+b)
        if c[1]=="in":
            s=s+c[0]-b
        else:
            s=s+c[0]-b-1
print(s)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
ls = list(map(int, input().split()))
ls.sort()

ans = 0

ab = np.zeros(2001)

ab[ : (ls[0] + ls[1]) ] += 1

for i in range(2,n):
    l_temp = ls[i]
    ans += ab[ (l_temp-1)]

    for j in range(i):
        ab[ : ( l_temp + ls[j] )] += 1

print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
ls = list(map(int, input().split()))
ls.sort()

ans = 0

ab = np.zeros(4001)

ab[(ls[0] + ls[1])] += 1

for i in range(2,n):
    l_temp = ls[i]
    ans += sum(ab[l_temp:])

    for j in range(i):
        ab[( l_temp + ls[j] )] += 1

print(int(ans))

Submission status: Wrong Answer

Solution code:
import bisect
N=int(input())
print(N)
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
    ans+=bisect.bisect_left(L,L[i]+L[j],j+1)-j-1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
arr=[int(_) for _ in input().split()]
count=0

for i in range(N):
  for j in range(i+1,N):
    a=arr[i]
    b=arr[j]
    if a-b>=1:
      if b-a>=1:
        for k in range(j+1,N):
          c=arr[k]
          if a < b+c:
            if b < c+a:
              if c < a+b:
                count=count+1
print(count)

Submission status: Wrong Answer

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

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])-j-1
    ans+=bisect.bisect_left(L,L[i]+L[j],j+1)-j-1
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left

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

res = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        idx = bisect_left(L[j+1:], L[i]+L[j])
        res += idx-(j+1)

print(res)

Submission status: Wrong Answer

Solution code:
a=input()
N=int(a[0])

arr=input().split(" ")
for i in range(N):
  arr[i]=int(arr[i])
  
count=0

for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      if arr[k] < arr[i]+arr[j]:
        if arr[i] < arr[j]+arr[k]:
          if arr[j] < arr[k]+arr[i]:
            count=count+1

print(count)

Submission status: Wrong Answer

Solution code:
a=input()
N=int(a[0])

arr=input().split(" ")
for i in range(N):
  arr[i]=int(arr[i])
  
count=0

for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      if arr[k] < arr[i]+arr[j]:
        if arr[i] < arr[j]+arr[k]:
          if arr[j] < arr[k]+arr[i]:
            count=count+1

#print(arr)
print(count)

Submission status: Wrong Answer

Solution code:
a=input()
N=int(a[0])

arr=input().split(" ")
for i in range(N):
  arr[i]=int(arr[i])
  
count=0

for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      if arr[k] < arr[i]+arr[j]:
        if arr[i] < arr[j]+arr[k]:
          if arr[j] < arr[k]+arr[i]:
            count=count+1

#print(arr)
print(count)

Submission status: Wrong Answer

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

dic = {}

for i in range(N):
    if(ns[i] in dic.keys() and dic[ns[i]]<=2):
        dic[ns[i]] += 1
    elif(ns[i] not in dic.keys()):
        dic[ns[i]] = 1

a,b,c = 0,0,0
for key in dic.keys():
    if(dic[key] == 1):
        a += 1
    elif(dic[key] == 2):
        b += 1
    elif(dic[key] == 3):
        c += 1

unique = a+b+c
sum_ = 0

sum_ += c
sum_ += (b+c)*(unique-1)

key_list = list(dic.keys())
n = len(key_list)
for p in range(n):
    for q in range(n):
        for r in range(n):
            if(p<q and q<r):
                x,y,z = int(key_list[p]),int(key_list[q]),int(key_list[r])
                if((x+y>z)and(x+z>y)and(y+z>x)):
                    sum_ += 1

print(int(sum_))

Submission status: Wrong Answer

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

dic = {}

for i in range(N):
    if(ns[i] in dic.keys() and dic[ns[i]]<=2):
        dic[ns[i]] += 1
    elif(ns[i] not in dic.keys()):
        dic[ns[i]] = 1

a,b,c = 0,0,0
for key in dic.keys():
    if(dic[key] == 1):
        a += 1
    elif(dic[key] == 2):
        b += 1
    elif(dic[key] == 3):
        c += 1

unique = a+b+c
sum_ = 0

sum_ += c
sum_ += (b+c)*(unique-1)
sum_ += unique*(unique-1)*(unique-2)/6

print(int(sum_))

Submission status: Wrong Answer

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

print(N)
print(L)
L.sort()

print(L)

cnt = 0
for i in range(len(L)):
    for j in range(i+1, len(L)):
        sum = L[i] + L[j]

        for k in range(j+1, len(L)):
            if sum > L[k]:
                cnt += 1

Submission status: Wrong Answer

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

import bisect
for i in range(N):
  for j in range(i+1,N):
    insert = bisect.bisect(L[j+1:], L[i]-L[j])
    cnt += len(L[j+1:])-insert
        
print(cnt)

Submission status: Wrong Answer

Solution code:
#16:18
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
import bisect
for i in range(n):
  for j in range(i+1,n):
    ans += max(0,bisect.bisect_right(l,l[i]+l[j])-j-1)
    #print(i,j,n-bisect.bisect_right(l,l[i]+l[j]))
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import collections
import bisect
n = int(input())
s = list(map(int, input().split()))
c = collections.Counter(s)
l = np.array(s)
l = np.sort(l)
l_unique= np.unique(l)
m = len(l_unique)
ans = 0

for i in range(m):
    if c[l_unique[i]] >= 3:
        ans += 1
    if c[l_unique[i]] >= 2:
        ans += bisect.bisect_left(l_unique, l_unique[i] * 2) - 1
for i in range(m):
    for j in range(i+1, m):
        ans += bisect.bisect_left(l_unique[j+1:], l_unique[i] + l_unique[j])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
Ls = list(map(int, input().split()))
Ls.sort()
print(Ls)
count = 0
for i in range(N-2):
    a = Ls[i]
    for k in range(i+1,N-1):
        ab = a + Ls[k]
        count += len(list(filter(lambda c: c<ab, Ls[k+1:N])))
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
L=input().split(" ")
count=0
L.sort()
for n,a in enumerate(L[:N-2]):
    a=int(a)
    for m,b in enumerate(L[n+1:N-1]):
        b=int(b)
        for c in L[m+n+2:N]:
            c=int(c)
            if b<a+c and c<b+a:
                count+=1
print(count)

Submission status: Wrong Answer

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

M = int(len(L))

I = []

for i in range(0,M):
    for j in range(0,M):
        for k in range(0,M):
            if L[i] >= L[j]+L[k]:
                break
            if L[j] >= L[i]+L[k]:
                break
            if L[k] >= L[i]+L[j]:
                break
            if L[i] < L[j]+L[k] and L[j] < L[k] + L[i] and L[k] < L[i] + L[j] and i != j and j != k and k != i:
                I.extend([i])

if int(len(I)) == 0:
    n = 0
else:
    n = int(len(I)//6)

print(n)

Submission status: Wrong Answer

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

M = int(len(L))

I = []

for i in range(0,M):
    for j in range(0,M):
        for k in range(0,M):
            if L[i] >= L[j]+L[k] and i != j and j != k and k != i:
                break
            if L[i] < L[j]+L[k] and L[j] < L[k] + L[i] and L[k] < L[i] + L[j] and i != j and j != k and k != i:
                I.extend([i])

if int(len(I)) == 0:
    n = 0
else:
    n = int(len(I))//6

print(n)

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 i==0 or L[i-1]!=L[i]:
        for j in range(i+1,N-1):
            if j==1 or L[j-1]!=L[j]:
                a=len(set(L[j+1:j+1+bisect.bisect_left(L[j+1:],L[i]+L[j])]))
                ans=ans+a
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l_list = list(map(int,input().split()))
l_list.sort(reverse=True)
count = 0
for a in range(n-2):
    x=0
    for b in range(a+1,n-1):
        for c in range(b+1,n):
            if (l_list[a]<l_list[b]+l_list[c]):
                count += 1
            else:
                if c-b > 3:
                    x=1
                    break
        if x == 1:
            break
print(count)

Submission status: Wrong Answer

Solution code:
import sys

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


ans = 0
for c in range(2,n):
    a = 0
    b = 1
    while True:
        if l[a]+l[b]>l[c]:
            ans += 1
        b += 1
        if b == c:
            a += 1
            if a == c-1:
                break
            b = a+1
print(ans)

Submission status: Wrong Answer

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


N = int(input())
l = map(int,input().split())
l = sorted(l)
l_dict = dict()
c = Counter(l)

for i,one in enumerate(l):
    if not one in l_dict:
        l_dict[one] = i
    
counter = 0

uni = len(c)
for one in c:
    if c[one] == 1:
        continue
    elif c[one]==2:
        num = c[one]
        counter -= num*(num-1)/2*(uni-1)
    else:
        num = c[one]
        counter -= num*(num-1)/2*(uni-1) +((num*(num-1)**2)/2- num*(num-1)*(num-2)/6)
 
                                           
counter = int(counter)

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 bisect
from itertools import combinations
from collections import Counter


N = int(input())
l = map(int,input().split())
l = sorted(l)
l_dict = dict()
c = Counter(l)

for i,one in enumerate(l):
    if not one in l_dict:
        l_dict[one] = i
    
counter = 0

uni = len(c)
for one in c:
    if c[one] == 1:
        continue
    elif c[one]==2:
        num = c[one]
        counter -= num*(num-1)/2*(uni-1)
    else:
        num = c[one]
        counter -= num*(num-1)/2*(uni-1) +(num*(num-1)- num*(num-1)*(num-2)/6)
 
                                           
counter = int(counter)

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 bisect

# 1行目の入力を数値として扱う
n = int(input())
# 2行目の入力を数値のリストとして扱う
a = list(map(int, input().split()))

# 答えのカウンタの準備
ans = 0

# 入力数値のソート
a.sort()

# 二重ループ
for i in range(0, n-1):
    for j in range(i + 1, n-1):
        # 3本目の最小値(a[j]以上)
        kmin = bisect.bisect_left(a, a[j])
        # 同じ値が続く場合への対応
        if kmin < j:
            kmin = j + 1

        # 3本目の最大値(a[i] + a[j] - 1以下)
        kmax = bisect.bisect_left(a, a[i] + a[j] - 1)

        # 最終値を超える場合の補正
        if kmax > n - 1:
            kmax = n - 1

        # 加算
        if kmin < kmax:
            ans += kmax-kmin

# 答えの出力
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
L=list(map(int,input().split()))
counter=0
L.sort()
for i,a in enumerate(L[:-2]):
    for j,b in enumerate(L[i+1:-1],i+1):
        l=j
        r=len(L)-1
        c=(r+l)//2
        while abs(r-l)>1:    
            if a>abs(L[c]-b):
                b=c
                c=(r+c)//2
                l=b
            else:
                b=c
                c=(c+l)//2
                r=b
        if a-abs(L[l]-b)>0 and a-abs(L[r]-b)>0:
            c=r
        elif a-abs(L[l]-b)>0 and a-abs(L[r]-b)<0:
            c=l
        if a>abs(L[c]-b):
            counter+=c-j
print(counter)

Submission status: Wrong Answer

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


N = int(input())
l = map(int,input().split())
l = sorted(l)
l_dict = dict()
c = Counter(l)

for i,one in enumerate(l):
    if not one in l_dict:
        l_dict[one] = i
    
counter = 0

for one in c:
    if c[one] == 1:
        continue
    else:
        num = c[one]
        counter -= num*(num-1)/2
counter = int(counter)*(len(c)-1)

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 bisect
n = int(input())
 
l = list(map(int, input().split()))
l.sort()
a = 0
print(l)
for i in range(n):
    for j in range(i+1,n):
        s = bisect.bisect_left(l,l[i]+l[j])-j-1
        a+=s


print(a)

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
 
l = list(map(int, input().split()))
l.sort()
a = 0
print(l)
for i in range(n-2):
    for j in range(i+1,n-1):
        s = bisect.bisect_left(l,l[i]+l[j])-j
        a +=s


print(a)

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
 
l = list(map(int, input().split()))
l.sort()
a = 0
print(l)
for i in range(n-2):
    for j in range(i+1,n-1):
        s = bisect.bisect_left(l,l[i]+l[j])-j-1
        a +=s


print(a)

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
 
l = list(map(int, input().split()))
l.sort()
a = 0
print(l)
for i in range(n-2):
    for j in range(i+1,n-1):
        s = bisect.bisect_left(l,l[i]+l[j])
        a =a + n - s-1


print(a)

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
 
l = list(map(int, input().split()))
l.sort()
a = 0
 
for i in range(n-2):
    for j in range(i+1,n-1):
        s = bisect.bisect_left(l,l[i]+l[j])
        a =a + n - s


print(a)

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
 
l = list(map(int, input().split()))
l.sort()
a = 0
 
for i in range(n-2):
    for j in range(i+1,n-1):
        s = bisect.bisect_left(l,l[i]+l[j])
        a =a + n - s+1


print(a)

Submission status: Wrong Answer

Solution code:
n = int(input())
 
l = list(map(int, input().split()))
l.sort()
a = 0
 
for i in range(len(l)-2):
    for j in range(i+1,len(l)-1):
        if j >= l[i]+l[j]:
            a+=1
        
 
print(a)

Submission status: Wrong Answer

Solution code:
n = int(input())
 
l = list(map(int, input().split()))
 
a = 0
 
for i in range(len(l)):
    for j in range(i+1,len(l)):
        if j > l[i]+l[j]:
            a+=1
        
 
print(a)

Submission status: Wrong Answer

Solution code:
n = int(input())
 
l = list(map(int, input().split()))
l.sort()
a = 0
 
for i in range(len(l)):
    for j in range(i+1,len(l)):
        if j >= l[i]+l[j]:
            a+=1
        
 
print(a)

Submission status: Wrong Answer

Solution code:
n = int(input())
 
l = list(map(int, input().split()))
l.sort()
a = 0
 
for i in range(len(l)):
    for j in range(i+1,len(l)):
        if j > l[i]+l[j]:
            a+=1
        
 
print(a)

Submission status: Wrong Answer

Solution code:
N=int(input())
R=list(map(int,input().split()))
L=sorted(R)[::-1]
print(L)
s=0
for i in range(0,N-2):
	for j in range(i+1,N-1):
		if L[N-1]>L[i]-L[j]:
			s=s+N-1-j
		else:
			k=j+1
			while L[k]>L[i]-L[j] and k<(N-1):
				s+=1
				k+=1
print(s)

Submission status: Wrong Answer

Solution code:
import itertools

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

counter = 0
new_l = list(itertools.combinations(l,3))
print(new_l)
for abc in new_l:
    a,b,c = abc
    if((a < b + c) and (b < c + a) and (c < a + b)):
        counter += 1     
print(int(counter))

Submission status: Wrong Answer

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

counter = 0
for a in l:
    for b in l:
        if(a == b):
            continue
        for c in l:
            if(b == c or c == a):
                continue
            if((a < b + c) and (b < c + a) and (c < a + b)):
                counter += 1     
print(int(counter/6))

Submission status: Wrong Answer

Solution code:
import itertools 
n = int(input())
l = list(map(int, input().split()))
l_group = list(itertools.combinations(l,3))
count = 0
for i in range(len(l_group)-1):
        if l_group[i][0]<l_group[i][1]+l_group[i][2] and l_group[i][1]<l_group[i][0]+l_group[i][2] and l_group[i][2]<l_group[i][0]+l_group[i][1]:
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
number_of_sticks = int(input())

sticks = [int(x) for x in input().split(' ')]

sticks.sort()

print(sticks)

triangles = 0

import bisect

for i in range (number_of_sticks - 2):
    for j in range (i+2, number_of_sticks):
        # print(sticks[i], sticks[j])
        # find number of sticks between range range sticks[j]-sticks[i], sticks[i] + sticks[j]
        # max_range = bisect.bisect_left(sticks, sticks[i] + sticks[j]) - 1
        max_range = j
        min_range = max(bisect.bisect(sticks, sticks[j] - sticks[i]), i + 1)
        # print("max range: " + str(max_range))
        # print("min range: " + str(min_range))
        triangles += max(0, max_range - min_range)

print(triangles)

Submission status: Wrong Answer

Solution code:
import bisect
n=int(input())
L=[int(x) for x in input().split()]
L.sort()
ans=0

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

Submission status: Wrong Answer

Solution code:
import bisect
n=int(input())
L=[int(x) for x in input().split()]
L.sort()
ans=0

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

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
ln = list(map(int, input().split()))
ln.sort()
ans = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        a = ln[i]
        b = ln[j]
        index = bisect.bisect_left(ln, a+b)-1
        print(i,j, index)
        print(a, b, ln[index-1])
        ans += index - j
print(ans)

Submission status: Wrong Answer

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

L.sort(reverse=True)

print(L)
for i in range(N):
    L[i] *= -1
count = 0
for i in range(N-2):
    #print(i)
    for j in range(i+1, N-1):
        if -L[i] >= -L[j] * 2:
            break
        data = L[i] - L[j]
        #print(data, L[j + 1 : N])
        #print(bisect.bisect_left(L[j + 1 : N], data))
        count += bisect.bisect_left(L[j + 1 : N], data)

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = sorted([int(i) for i in input().split()],reverse=True)
from bisect import bisect_right
ans = 0
for i1,a in enumerate(L):
    L_temp = L[i1+1:]
    for i2,b in enumerate(L_temp):
        L_temp2 = L_temp[i2+1:]
        ans += len(L_temp2) - bisect_right(L_temp2,a-b)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = sorted([int(i) for i in input().split()],reverse=True)
from bisect import bisect_right
ans = 0
for i1,a in enumerate(L):
    L_temp = L[i1+1:]
    for i2,b in enumerate(L_temp):
        L_temp2 = L_temp[i2+1:]
        ans += len(L_temp2) - bisect_right(L_temp2,a-b)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
m = list()
ans = 0
for i in range(n-2):
    for k in range(n-2-i):
        for k1 in range(n-k-2):
            if l[i] < l[i+k+1]+l[k+k1+2] and l[i+k+1] < l[i]+l[k+k1+2] and l[k+k1+2] < l[i]+l[i+k+1]:
                ans += 1
if ans == 0:
    print(int(0))
else:
    print(int(ans/3))

Submission status: Wrong Answer

Solution code:
a = int(input())
list1 = list(map(int,input().split()))
cntlist = [0]*1000
cnt = 0
n = 0
cntlist2 = []
cntlist3 = [0]*1000
for l in range(1000):
  cntlist[l] = list1.count(l)
for m in range(1000):
  if cntlist[m]>0:
    cntlist2.append([m,cntlist[m]])
w = len(cntlist2)
for i in range(w-2):
  j=i+1
  for j in range(i+1,w-1):
    k=j+1
    for k in range(j+1,w):
      if  cntlist2[i][0]+cntlist2[j][0]>cntlist2[k][0]:
        cnt+=cntlist2[i][1]*cntlist2[j][1]*cntlist2[k][1]
      else:
        break;
print(cnt)

Submission status: Wrong Answer

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

def binary_search(list, item):
    low = 0
    high = len(list) - 1
    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if (guess <= item and list[mid+1] >= item):
            return mid
        elif guess > item:
            high = mid -1
        else:
            low = mid + 1
    return None
    
for i in range(n-1):
    for j in range(i+1,n-1):
        if l[i] + l[j] > l[-1]:
            ans = ans + (n-j)*(n-j-1)//2
            print(i,j)
            print(ans)
            break
        else:
            k = binary_search(l,l[i]+l[j]-1)
            if k > j:
                ans = ans +k-j
                print(i,j,k)
                print(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
data = list(map(int, input().split(' ')))
data = sorted(data, reverse=True)
count=0
for i in range(n):
  for j in range(i+1, n):
    for k in range(j+1, n):
      a = data[i]
      b = data[j]
      c = data[k]
      if c < a + b:
        count+=len(data[j:k])
        break
      
print(count)

Submission status: Wrong Answer

Solution code:
def bisec_k(l,x,k_max,k_min):
  if k_max == k_min + 1:
    if a[k_max] < x:
      return k_max
    else:
    	return k_min
  else:
    k_mid= k_min + (k_max-k_min)//2
    if l[k_mid] > x:
      k_max  = k_mid
      return bisec_k(l,x,k_max,k_min)
    else:
      k_min = k_mid
      return bisec_k(l,x,k_max,k_min)

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

sum=0
for i in range(n-2):
  for j in range(i+1,n-1):
    tmp = a[i] + a[j]
    k = bisec_k(a,tmp,n-1,j)
    sum += (k - j)

print(sum)

Submission status: Wrong Answer

Solution code:
import sys

def bi_search(array, target):
    l, r = -1, len(array)-1
    while r-l > 1:
        mid = int((r+l)/2)
        if array[mid] > target:
            r = mid
        else:
            l = mid
    return r

N = int(sys.stdin.readline().strip())
l_list = list(sorted(list(map(int, sys.stdin.readline().strip().split(" ")))))
count = 0

for i in reversed(range(N)):
    a = l_list[i]
    for j in reversed(range(i)):
        b = l_list[j]
        index = bi_search(l_list[:j], b-a)
        if index > -1 and index < j and l_list[index] + b > a:
            count += (j-index)

print(count)

Submission status: Wrong Answer

Solution code:
import sys

def bi_search(array, target):
    l, r = -1, len(array)-1
    while r-l > 1:
        mid = int((r+l)/2)
        if array[mid] > target:
            r = mid
        else:
            l = mid
    return r

N = int(sys.stdin.readline().strip())
l_list = list(sorted(list(map(int, sys.stdin.readline().strip().split(" ")))))
count = 0

print(l_list)
for i in reversed(range(N)):
    a = l_list[i]
    for j in reversed(range(i)):
        b = l_list[j]
        index = bi_search(l_list[:j], b-a)
        if index > -1 and index < j and l_list[index] + b > a:
            count += (j-index)

print(count)

Submission status: Wrong Answer

Solution code:
import sys

def bi_search(array, target):
    l, r = 0, len(array)
    while r-l > 1:
        mid = int((r+l)/2)
        if array[mid] > target:
            r = mid
        else:
            l = mid
    return r

N = int(sys.stdin.readline().strip())
l_list = list(sorted(list(map(int, sys.stdin.readline().strip().split(" ")))))
count = 0

for i in reversed(range(N)):
    a = l_list[i]
    for j in reversed(range(i)):
        b = l_list[j]
        index = bi_search(l_list[:j], b-a)
        #print(i, j, index)
        if index < j and l_list[index] + b > a:
            count += (j-index)

print(count)

Submission status: Wrong Answer

Solution code:
import sys

def bi_search(array, target):
    l, r = 0, len(array)
    while r-l > 1:
        mid = int((r+l)/2)
        if array[mid] > target:
            r = mid
        else:
            l = mid+1
    return l

N = int(sys.stdin.readline().strip())
l_list = list(sorted(list(map(int, sys.stdin.readline().strip().split(" ")))))
count = 0

for i in reversed(range(N)):
    a = l_list[i]
    for j in reversed(range(i)):
        b = l_list[j]
        index = bi_search(l_list, b-a)
        if index < j and l_list[index] + b > a:
            count += (j-index)

print(count)

Submission status: Wrong Answer

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

#print(l_list)

ret = 0
for a in range(N):
    A = l_list[a]
    breakFlag = False

    for b in range(a+1, N):
        B = l_list[b]

        for c in range(b+1, N):
            C = l_list[c]
#            print(A, B, C, end="")
            if C > A + B:
#                print("->x")
                break
            else:
 #               print("->o")
                ret += 1
print(ret)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

a = 0

for i in range(len(l)):
    for j in range(i+1,len(l)):
        if j > l[i]+l[j]:
            a+=1
        

print(a)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

a = 0

for i in range(len(l)):
    for j in range(i+1,len(l)):
        a = a + int(len([k for k in l if i > l[i]+l[j]]))
        

print(a)

Submission status: Wrong Answer

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

print(result)