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:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    L = inputList()
    
    L.sort()
    #L = L[::-1]
    print(L)
    
    ans = 0
    for i in range(N):
        a = L[i]
        for j in range(i+1, N):
            b = L[j]
            for k in range(j+1, N):
                c = L[k]
                
                tmp = a+b
                if tmp <= c:
                    break
                
                if a < b+c and b < c+a and c < a+b:
                    ans += 1
    
    print(ans)
    
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    L = inputList()
    
    L.sort()
    #L = L[::-1]
    #print(L)
    
    ans = 0
    for i in range(N):
        a = L[i]
        for j in range(i+1, N):
            b = L[j]
            tmp = b * 2
            if b >= a:
                continue
            
            for k in range(j+1, N):
                c = L[k]
                
                if a < b+c and b < c+a and c < a+b:
                    ans += 1
    
    print(ans)
    
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    L = inputList()
    
    L.sort()
    L = L[::-1]
    
    ans = 0
    for i in range(N):
        a = L[i]
        for j in range(i+1, N):
            b = L[j]
            tmp = b * 2
            if b >= a:
                continue
            
            for k in range(j+1, N):
                c = L[k]
                
                if a < b+c and b < c+a and c < a+b:
                    ans += 1
    
    print(ans)
    
if __name__ == "__main__":
	main()

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 = [one+10**(-4)*i for i,one in enumerate(l)]
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)

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


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 bisect

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


for i in range(n):
    for j in range(i+1,n):
        k=l[i]+l[j]-1
        index = bisect.bisect_left(l,k,lo=j+1)
        count+=index-j-1
        

print(count)

Submission status: Wrong Answer

Solution code:
from collections import deque
from copy import copy
import bisect

n = int(input())
order = sorted(list(map(int, input().split())))
l = deque(order)
ans = 0

for _ in range(len(l)-2):
    first = l.pop()
    m = copy(l)
    for _ in range(len(m)-1):
        second = m.pop()
        fix = first-second
        if fix != 0:
            ans += len(m)-bisect.bisect_right(list(m), fix)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
from copy import copy
import bisect

n = int(input())
order = sorted(list(map(int, input().split())), reverse=True)
l = deque(order)
ans = 0

for _ in range(len(l)-1):
    first = l.popleft()
    m = copy(l)
    for _ in range(len(m)):
        second = m.popleft()
        fix = first-second
        if fix != 0:
            ans += bisect.bisect_left(list(m), fix)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 入力
import numpy as np

N = int(input())
L2 = np.array(list(map(int, input().split())))
L3 = np.sort(L2)[::-1]

sum = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    if(L3[i] > L3[j] + L3[j+1]):
        break
    else:
      val = L3[i] - L3[j]
      sum += (np.sum(L3 > val) - j - 1)

print("{}".format(sum))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 入力
import numpy as np

N = int(input())
L2 = np.array(list(map(int, input().split())))
L3 = np.sort(L2)[::-1]

sum = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    if(L3[i] > L3[j] + L3[j+1]):
        break
    else:
      val = L3[i] - L3[j]
      tmp = L3 > val
      sum += (np.sum(tmp) - j - 1)

print("{}".format(sum))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 入力
import numpy as np

N = int(input())
L1 = list(map(int, input().split()))
L2 = np.array(L1)

L3 = np.sort(L2)[::-1]

sum = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    if(L3[i] > L3[j] + L3[j+1]):
        break
    else:
      val = L3[i] - L3[j]
      tmp = L3 > val
      sum += (np.sum(tmp) - j - 1)

print("{}".format(sum))

Submission status: Wrong Answer

Solution code:
def binary_search(list, item):
    low = 0
    high = len(list)
    
    while low < high:
        mid = (low + high)//2
        if list[mid] < item:
            low = mid+1
        else:
            high = mid
    return low
  
N = int(input())
L = list( map(int, input().split()) )

L.sort()
print(L)

count = 0
for a in range(0, len(L)-2):
    for b in range(a+1, len(L)-1):
        count += binary_search(L[b+1:], L[a]+L[b])
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
ary = sorted(map(int,input().split()))
dp = [[] for _ in range(N-1)]
c = 0
for i in range(1,N):
    for j in range(i,N):
        if i == j:continue
        dp[i] += [ary[j] - ary[i]]
print(dp)

Submission status: Wrong Answer

Solution code:
N = int(input())
ary = sorted(map(int,input().split()))
dp = [[] for _ in range(N-1)]
c = 0
for i in range(1,N):
    for j in range(i,N):
        if i == j:continue
        dp[i] += [abs(ary[i] - ary[j])]
print(dp)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

x=int(0)
y=int(1)
z=int(2)
ans = 0
while True:
    y = x + 1
    z = y + 1
    while True:
        ans += z-4
        z -= 1
        while True:
            if l[x]+l[y] > l[z]:
                ans += 1
                z += 1
                if z > n-1:
                    break
            else:
                break
        y += 1
        if y > n - 2:
            break
    x += 1
    if x > n - 3:
        break

print(ans)

Submission status: Wrong Answer

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

x=int(0)
y=int(1)
z=int(2)
ans = 0
while True:
    y = x + 1

    while True:
        ans += z-4
        z -= 1
        while True:
            if l[x]+l[y] > l[z]:
                ans += 1
                z += 1
                if z > n-1:
                    break
            else:
                break
        y += 1
        if y > n - 2:
            break
    x += 1
    if x > n - 3:
        break

print(ans)

Submission status: Wrong Answer

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

x=int(0)
y=int(1)
z=int(2)
ans = 0
while True:
    y = x + 1

    while True:
        ans += z-2
        z -= 1
        while True:
            if l[x]+l[y] > l[z]:
                ans += 1
                z += 1
                if z > n-1:
                    break
            else:
                break
        y += 1
        if y > n - 2:
            break
    x += 1
    if x > n - 3:
        break

print(ans)

Submission status: Wrong Answer

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

sticks.sort(reverse = True)
count = 0
fj = False
for i in range(0,N-2):
    for j in range(i+1,N-1):
        if fj:
            fj=False
            break
        else:
            for k in range(j+1,N):
                #stick[i]>j>k
                if sticks[i]<sticks[j]+sticks[k]:
                    count += 1
                else:
                    fj = True
                    break
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
L=list(map(int,input().split()))
c=0
L.sort()
for i in range(1,N-1):
    l=L[i+1]-L[i]
    for j in range(0,i-1):
        if L[j]<=l:
            c+=1+N-i
N=int((N-2)*(N-1)*N/6-c)
print(N)

Submission status: Wrong Answer

Solution code:
""" nC3 のすべての組み合わせに対して、三角形が成立するかを調べると、O(n^3)で計算量がだめ
ソートしてから、maxの辺を固定する
他の２つのへんをfor loop *２で回すが、a >= b + c になった段階でbreakする
この時の計算量はo(n^3)だけど半分くらいに減るはず。
これでTLEするか試す => TLE
もっとも内側のループはbinary_searchでO(log n)にする
def binary_search(l,k):
  s,e = 0,len(l)
  while(e-s >= 0):
    i = (e+s)//2
    if l[i] >= k and l[i+1] < k:
      return i
    elif l[i] >= k:
      binary_search(l[:i],k)
    else:
      binary_search(l[i+1:],k)
    return 0
"""
import sys
input = sys.stdin.readline
n = int(input()[:-1])
l = list(map(int,input().split()))
l.sort()
ans = 0
#print(ans)
for i in range(n-1,1,-1):
  for j in range(i-1,0,-1):
    s = 0
    e = j-1
    if e ==0 and l[0]+l[1]>l[i]:
      ans += 1
    while e-s>0:
      k = (e+s)//2
      if l[k+1] >  l[i] - l[j] and l[k] <= l[i] - l[j]:
        ans += j -k
        break
      elif l[k] > l[i] - l[j] and k == 0:
        ans += j
        break
      elif l[k] >= l[i] - l[j]:
        e = k 
      else:
        s = k+1
    
    # if l[i] >= l[j] + l[k]でl[i] < l[j] + l[k+1]となるを見つける

    """
    for k in range(j-1,-1,-1):
      ans += 1
      if l[i] >= l[j] + l[k]:
        ans -= 1
        break
    """
print(ans)

Submission status: Wrong Answer

Solution code:
""" nC3 のすべての組み合わせに対して、三角形が成立するかを調べると、O(n^3)で計算量がだめ
ソートしてから、maxの辺を固定する
他の２つのへんをfor loop *２で回すが、a >= b + c になった段階でbreakする
この時の計算量はo(n^3)だけど半分くらいに減るはず。
これでTLEするか試す => TLE
もっとも内側のループはbinary_searchでO(log n)にする
def binary_search(l,k):
  s,e = 0,len(l)
  while(e-s >= 0):
    i = (e+s)//2
    if l[i] >= k and l[i+1] < k:
      return i
    elif l[i] >= k:
      binary_search(l[:i],k)
    else:
      binary_search(l[i+1:],k)
    return 0
"""
import sys
input = sys.stdin.readline
n = int(input()[:-1])
l = list(map(int,input().split()))
l.sort()
ans = 0
#print(ans)
for i in range(n-1,2,-1):
  for j in range(i-1,1,-1):
    s = 0
    e = j-1
    while e-s>0:
      k = (e+s)//2
      if l[k] >=  l[i] - l[j] and l[k+1] < l[i] - l[j]:
        ans += j-1 -k
        break
      elif l[k] >= l[i] - l[j]:
        e = k
      else:
        s = k+1
    
    # if l[i] >= l[j] + l[k]でl[i] < l[j] + l[k+1]となるを見つける

    """
    for k in range(j-1,-1,-1):
      ans += 1
      if l[i] >= l[j] + l[k]:
        ans -= 1
        break
    """
print(ans)

Submission status: Wrong Answer

Solution code:
""" nC3 のすべての組み合わせに対して、三角形が成立するかを調べると、O(n^3)で計算量がだめ
ソートしてから、maxの辺を固定する
他の２つのへんをfor loop *２で回すが、a >= b + c になった段階でbreakする
この時の計算量はo(n^3)だけど半分くらいに減るはず。
これでTLEするか試す => TLE
もっとも内側のループはbinary_searchでO(log n)にする
def binary_search(l,k):
  s,e = 0,len(l)
  while(e-s >= 0):
    i = (e+s)//2
    if l[i] >= k and l[i+1] < k:
      return i
    elif l[i] >= k:
      binary_search(l[:i],k)
    else:
      binary_search(l[i+1:],k)
    return 0
"""
import sys
input = sys.stdin.readline
n = int(input()[:-1])
l = list(map(int,input().split()))
l.sort()
ans = 0
for i in range(n-1,1,-1):
  for j in range(i-1,0,-1):
    s = 0
    e = j-1
    while e-s>0:
      k = e+s//2
      if l[k] >=  l[i] - l[j] and l[k+1] < l[i] - l[j]:
        ans += j-1 -k
        break
      elif l[k] >= l[i] - l[j]:
        e = k
      else:
        s = k+1
    
    # if l[i] >= l[j] + l[k]でl[i] < l[j] + l[k+1]となるを見つける

    """
    for k in range(j-1,-1,-1):
      ans += 1
      if l[i] >= l[j] + l[k]:
        ans -= 1
        break
    """
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())
lst =list(map(int, input().split()))
lst.sort()
ret = 0
for i in range(N):
    for j in range(i + 1, N):
        n = lst[i] + lst[j]
        ret += max(0, bisect.bisect_right(lst, lst[i] + lst[j] + 1) - bisect.bisect_right(lst, lst[j] + 1))
print(ret)

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())
lst = sorted(map(int, input().split()))
ret = 0
for i in range(N):
    for j in range(i + 1, N):
        n = lst[i] + lst[j]
        ret += max(0, bisect.bisect_right(lst, lst[i] + lst[j] + 1) - bisect.bisect_right(lst, lst[j] + 1))
print(ret)

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())
lst = sorted(map(int, input().split()))
ret = 0
for idx_a, a in enumerate(lst[:-2]):
    for b in lst[idx_a + 1:-1]:
        ret += max(0, bisect.bisect_right(lst, a + b + 1) - bisect.bisect_right(lst, b + 1))
print(ret)

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())
lst = sorted(list(map(int, input().split())))
ret = 0
for idx_a, a in enumerate(lst[:-2]):
    for idx_b, b in enumerate(lst[idx_a + 1:-1]):
        ret += max(0, bisect.bisect_right(lst, a + b + 1) - bisect.bisect_right(lst, b + 1))
print(ret)

Submission status: Wrong Answer

Solution code:

input()
data=[int(i) for i in input().split()]
data.sort()
tri=0
print(data)
for aid in range(len(data)-2):
  if data[aid]+data[aid+1]>data[aid+2]:
    for bid in range(aid+1, len(data)-1):
      if data[aid]+data[bid]>data[bid+1]:
        for cid in range(bid+1, len(data)):
          if data[aid]+data[bid]>data[cid]:
            #print(data[aid],data[bid],data[cid])
            tri=tri+1
          else:
            break

print(tri)

Submission status: Wrong Answer

Solution code:
def check(data):
  data=[int(i) for i in data]
  if data[0]>data[1]+data[2]:
    return False
  elif data[1]>data[0]+data[2]:
    return False
  elif data[2]>data[0]+data[1]:
  	return False
  else:
    return True
input()
data=[i for i in input().split()]
triangles=set()
for id1,i in enumerate(data):
  for id2,j in enumerate(data):
    if id1==id2:
      continue
    for id3,k in enumerate(data):
      if id1==id3 or id2==id3:
        continue
      tri=[i,j,k]
      tri.sort()
      if "-".join(tri) not in triangles:
        if check(tri):
          triangles.add("-".join(tri))
print(len(triangles))

Submission status: Wrong Answer

Solution code:
N = int(input())
l = [int(x) for x in input().split(" ")]
l.sort(reverse=True)
num =0

for i in range(N-2):
  for j in range(i+1,N-1):
    flag = True
    for k in range(j+1,N):
      if l[i]<l[j]+l[k]:
        #print(l[i],l[j],l[k])
        num+=1
      else:
        flag= False
        break
    if flag==False:
      break
print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())
l = [int(x) for x in input().split(" ")]
l.sort()
cnt =0
num =0
print(l)

for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      if l[k]<l[j]+l[i]:
          num+=1
      else:
        break

print(num)

Submission status: Wrong Answer

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

count = 0

for i,l1 in enumerate(l_list):
    if i <= n-3:
        for j,l2 in enumerate(l_list[i+1:]):
            num = l1 + l2
            for k,l3 in enumerate(l_list[i+j+2:]):
                if l3 > num and i + j + k < n-3:
                    count += k
                elif i + j + k == n-3:
                    count += k

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
lst = list(map(int, input().split()))
ret = 0
print(lst[:-2])
for idx_a, a in enumerate(lst[:-2]):
    for idx_b, b in enumerate(lst[idx_a + 1:-1]):
        for idx_c, c in enumerate(lst[idx_a + idx_b + 2:]):
            if a < b + c and b < c + a and c < a + b:
                ret += 1
print(ret)

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])-1
    ans+=k-j
    
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect
from bisect import bisect_left
n = int(input())
L = list(map(int, input().split()))
l_set = set(L)
sort_L = sorted(list(l_set))
nl = len(sort_L)
ans = 0
cnt = 0
for i in range(nl):
  for j in range(i+1, nl):
    cnt += 1
    a,b = sort_L[i],sort_L[j]
    num_a = bisect_left(sort_L, a+b)
    ans += num_a - j - 1
print(ans)

Submission status: Wrong Answer

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

L.sort()

ans = 0
for a in range(N-1,1,-1):
    for b in range(a-1,0,-1):
        if L[a] == L[b]: continue
        l = 0
        r = b-1
        m = (l+r)//2
        while l < r:
            if L[m] <= L[a]-L[b]: l = m+1
            elif L[m] > L[a]-L[b]: r = m-1
            m = (l+r)//2
        if L[l] > L[a]-L[b]: ans += b-l
print(ans)

Submission status: Wrong Answer

Solution code:
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left
#from copy import deepcopy
#import heapq
#import math
#import string

setrecursionlimit(10**6)
input=stdin.readline

def nibu(A,lo,hi,a,b):
    #print(lo,hi)
    while lo<hi:
        m=(lo+hi)//2
        if abs(A[a]-A[b])<A[m]<A[a]+A[b]: lo=m+1
        else: hi=m
        print(lo,hi)
    return m

n=int(input().rstrip())
l=sorted([int(i) for i in input().split()],reverse=True)
print(*l)
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for c in range(j+1,n):
            if abs(l[i]-l[j])<l[c]<l[i]+l[j]:
                t=nibu(l,c,n,i,j)
                #print(t,j)
                ans+=t-j
                break
print(ans)

Submission status: Wrong Answer

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

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

lines.sort()
# print(lines)

# binary searchでNNlogNにしてみる

sum = 0
# i -> 一番大きい辺
# j -> 次に大きい辺
# mid -> binary searchで探す
for i in range(N - 1, 0, -1):
    for j in range(i - 1, 0, -1):
        # print("-------------------------")
        # print("i:{0}, j:{1}".format(i, j))
        # print("lines[i]:{0}, lines[j]:{1}".format(lines[i], lines[j]))

        left = 0
        right = j - 1
        while left <= right:
            mid = (left + right) // 2
            # print("---------------")
            # print("left:{}".format(left))
            # print("right:{}".format(right))
            # print("mid:{}".format(mid))
            if (lines[mid] + lines[j]) <= lines[i]:
                left = mid + 1
            if (lines[mid] + lines[j]) > lines[i]:
                right = mid - 1

        # print("mid:{}".format(mid))
        # print("lines[mid]:{}".format(lines[mid]))

        count = j - mid
        # print("count:{}".format(count))
        if (lines[mid] + lines[j]) > lines[i]:
            sum += count

print(sum)

Submission status: Wrong Answer

Solution code:
from collections import deque
from copy import copy

n = int(input())
l = deque(sorted(list(map(int, input().split()))))
ans = 0

for _ in range(len(l)-2):
    first = l.pop()
    m = copy(l)
    for _ in range(len(m)-1):
        second = m.pop()
        n = copy(m)
        fix = first - second
        if fix == 0:
            break
        else:
            for _ in range(len(n)):
                third = n.pop()
                if fix < third:
                    ans += 1
                else:
                    break
                    
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

li.sort()

point = 0


#2個大きい辺を固定
for i in range(n-2):
    for j in range(i+1,n-1):
        bi = bisect.bisect_right(li,li[i]+li[j])
        point += bi-j-1
print(point)

Submission status: Wrong Answer

Solution code:
from bisect import bisect
from bisect import bisect_left
n = int(input())
L = list(map(int, input().split()))
l_set = set(L)
sort_L = sorted(list(l_set))
nl = len(sort_L)
ans = 0
for i in range(nl):
  for j in range(i+1, nl):
    a,b = sort_L[i],sort_L[j]
    num_a = bisect_left(sort_L, a+b)
    num_b = bisect(sort_L, b)
    ans += num_a - num_b
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

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



cnt = 0
for i in range(0, len(L)-2):
    l1 = L[i]
    rest = L[i+1:]
    for i2 in range(0, len(rest)-1):
        l2 = rest[i2]
        #if l2 < l1 / 2:
        #    break
        #if l2 < l1 / 2:
        #    break
        rest2 = rest[i2+1:]
        cnt += bisect.bisect_right(rest2, l2+l1)
print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect
import copy



N = int(input())
L = [int(i) for i in input().split()]
L.sort()
ans = 0
for i in range(N):
    for j in range(i+1,N):
        if L[i]<=L[j]:
            continue
        else:
            tmp = copy.deepcopy(L)
            tmp.pop(i)
            tmp.pop(j)
            c = L[i]-L[j]
            if L[j] < c:
                continue
            ans  += bisect.bisect_left(tmp,L[j])-bisect.bisect_right(tmp,c)
            
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import copy

#条件がよくわかってない

N = int(input())
L = [int(i) for i in input().split()]
L.sort()
ans = 0
for i in range(N):
    for j in range(N):
        if L[i]<=L[j]:
            continue
        else:
            tmp = copy.deepcopy(L)
            tmp.pop(i)
            tmp.pop(j)
            c = L[i]-L[j]
            if L[j] < c:
                continue
            ans  += bisect.bisect_left(tmp,L[j])-bisect.bisect_right(tmp,c)
            
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

N = int(input())
L = np.sort(np.array(list(map(int, input().split(" ")))))[::-1]

def xxx (Nx, Lx, Num):
    index = math.ceil(Nx / 2) - 1
    left_edge = 0
    right_edge = Nx - 1
    edge_count = 0
    res = 0
    for i in range(0, Nx+1):
        if Lx[index] >= Num:
            res = index + 1
            left_edge = index
            index += math.ceil((right_edge - index) / 2)
        else:
            right_edge = index
            index -= math.ceil((index - left_edge) / 2)

        if index == left_edge or index == right_edge:
            edge_count += 1

        if edge_count == 2:
            break
    return res




cnt = 0
for i in range(0, len(L)-2):
    l1 = L[i]
    rest = L[i+1:]
    for i2 in range(0, len(rest)-1):
        l2 = rest[i2]
        if l2 < l1 / 2:
            break
        if l2 < l1 / 2:
            break
        rest2 = rest[i2+1:]
        cnt += xxx(len(rest2), rest2, l1-l2)
        if sum(rest2 > l1 - l2) == 0:
            break
print(cnt)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect

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

L.sort()

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

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

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

    print(L)

    cnt = 0
    for i in range(2,N):
        for j in range(i):
            shortest_len = L[i] - L[j] + 1
            index = bisect.bisect_left(L, shortest_len)
            if index < j:
                cnt += j - index
    
    print(cnt)

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import bisect

N=int(raw_input())
LN=map(int, raw_input().split())

LN.sort()

def bin_search(s,e,t):
    # return minimum i where s <= i < e and LN[i] >= t
    m = (s + e)/2
    if m == s:
        return s

    if t < LN[m]:
        return bin_search(s,m,t)
    else:
        return bin_search(m,e,t)



r = 0
for i in xrange(N-1, 1, -1):
    a = LN[i]
    for j in xrange(i-1, 0, -1):
        b = LN[j]
        if a > 2*b:
            break
        #idx = bin_search(0,j,a-b+1) # 2.5 ~ 2.7 sec
        idx = bisect.bisect_left(LN, a-b) # almost 0.8 sec
        r += j - idx

print r

Submission status: Wrong Answer

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

def is_triangle(a,b,c):
    if c > abs(a-b)  :
        return True
    else:
        return False

l.sort(reverse=True)

print(l)

ans = 0

for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if is_triangle(l[i], l[j], l[k]):
                ans += 1
            else:
                break

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

L_len = len(L)

L.sort()

count = 0
for i in reversed(range(2, L_len)):
    for j in reversed(range(1, i)):
        left = 0
        right = j - 1
        length = L[i] - L[j]
        index = -1

        if left == right:
            if L[left] > length:
                count += 1
        if right - left == 1:
            if L[left] > length:
                count += 2
            elif L[right] > length:
                count += 1

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

        if index != -1:
            count += j - index 

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
stick = sorted(list(map(int, input().split())), reverse=True)
answer= 0
for i in range(len(stick)):
  ans = 0
  a = stick[i]
  rem = stick[i+1:]
  for ci in range(1,len(rem)):
    c = rem[ci]
    b = rem[ci - 1]
    if a < b + c:
      answer += len(rem[ci:])
      break

print(answer)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(map(int,input().split( )))
tri_sum = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        x = S[i] + S[j]
        for k in range(j+1,N):
            if S[k] < x:
                tri_sum = tri_sum + 1
print(tri_sum)

Submission status: Wrong Answer

Solution code:
N = int( input() )
t_list = list( map( int, input().split() ) )
counter = 0
a = 0
b = 1
for i in t_list:
  a += 1
  for j in t_list[a:]:
    b += 1
    for k in t_list[b:]:
      if i < j + k:
        if j < i + k:
          if k < i + j:
            counter += 1
            
print(counter)

Submission status: Wrong Answer

Solution code:
N = int( input() )
t_list = list( map( int, input().split() ) )
counter = 0
a = 0
b = 0
for i in t_list:
  a += 1
  for j in t_list[a:]:
    b += 1
    for k in t_list[b:]:
      if i < j + k:
        if j < i + k:
          if k < i + j:
            counter += 1
            
print(counter)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(map(int,input().split( )))
S = sorted(S)
tri_sum = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(N-1,j,-1):
            if S[i] + S[j] > S[k]:
                tri_sum = tri_sum + k-j
print(tri_sum)

Submission status: Wrong Answer

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

L_len = len(L)

L.sort(reverse=True)

count = 0
for i in range(L_len - 2):
    for j in range(i + 1, L_len - 1):
        left = j + 1
        right = L_len - 1
        length = L[i] - L[j]

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

            count += center - j

print(count)