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:
N = int(input())
L = list(map(int, input().split()))
def tri(a, b, c):
  if a < b + c and b < a + c and c < a + b:
    return True
  else:
    return False
ans = 0
for a in range(0,N-2):
  for b in range(a,N-1):
    for c in range(b,N):
      if tri(a,b,c):
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
ls = list(map(int,input().split()))
ls.sort()
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ls1 = ls[j+1:]
        ans += bisect.bisect_left(ls1,ls[j]+ls[i]+1)-bisect.bisect(ls1,ls[j]-ls[i]-1)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
num_list = list(map(int, input().split()))

c = collections.Counter(num_list)
ans = 0

set_one = set()
set_two = set()
set_three = set()


for d in c:
    set_one.add(d)
    if c[d] >= 3:
        set_three.add(d)
    elif c[d] == 2:
        set_two.add(d)

list1 = list(set_one)
list2 = list(set_two)
list3 = list(set_three)


d = len(list1)
for i in range(d):
    for j in range(i+1, d):
        for k in range(j+1, d):
            if list1[i]+list1[j]>list1[k] and list1[i]+list1[k]>list1[j] and list1[k]+list1[j]>list1[i]:
                ans += 1
if len(list3) > 0:
    ans += len(list3)
if len(list2) > 0:
    for bi in list2:
        list4 = [x for x in list1 if x not in list2 and  x < 2*bi]
        if len(list4) > 0:
            ans += len(list4)

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import bisect
n = int(input())
l = sorted(list(map(int,input().split())))
comb = list(combinations(l,2))
cnt = 0
for a,b in comb:
    idx1 = bisect.bisect_right(l,b)
    idx2 = bisect.bisect_left(l,a+b)
    print(a,b,idx1,idx2,idx2-idx1)
    cnt += idx2-idx1
print(cnt)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import bisect
n = int(input())
l = sorted(list(map(int,input().split())))
comb = list(combinations(l,2))
cnt = 0
print(l)
for a,b in comb:
    idx1 = bisect.bisect_right(l,b)
    idx2 = bisect.bisect_left(l,a+b)
    cnt += idx2-idx1
print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools
import collections
n = int(input())  # nは入力回数
num_list = list(map(int, input().split()))
c = collections.Counter(num_list)
set_list = set(num_list)
cnt = 0

tri_list = list(itertools.combinations(set_list,3))

for i in tri_list:
    if i[0] < i[1] + i[2] and i[1] < i[0] + i[2] and i[2] < i[1] + i[0]:
        cnt += c[i[0]] * c[i[1]] * c[i[2]]

print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())
L = sorted([int(n) for n in input().split()])
#print(L)

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

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
import bisect
a = sorted(list(map(int, input().split(" "))))
ans = 0
for i in range(1, n-1):
  b = a[:i]
  c = a[i + 1:]
  #print(b, c)
  for j in b:
    ans += bisect.bisect(c, a[i]+j-0.1) - bisect.bisect(c, a[i]+0.1)
    #print(bisect.bisect(c, a[i]+j-0.1), bisect.bisect(c, a[i]+0.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()
ans = 0
for i in range(len(l)):
    for j in range(len(l))[i+1:]:
        a = bisect_left(l[j+1:],l[j] - l[i]) + j + 1
        b = bisect_right(l[j+1:],l[i] + l[j]) + j + 1
        ans += len(l[a:b])
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect

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

l.sort()
ans = 0
for i in range(len(l)):
    for j in range(len(l))[i+1:]:
        a = bisect(l[j+1:],l[j] - l[i]) + j + 1
        b = bisect(l,l[i] + l[j])
        ans += len(l[a:b])
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import *

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

cnt = 0

for i in range(n):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        lower = bisect_right(l, b)
        upper = bisect_left(l, a+b)
        cnt += upper - lower
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect

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

ans = 0
for a in range(0,n-2):
    for b in range(a+1,n-1):
        b_1 = bisect.bisect_right(L, L[b])
        apb = bisect.bisect_right(L, L[a]+L[b]-1)
        tmp = apb-b_1
        ans += tmp
        
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
x=[0]*(10**3+1)
y=[]
for i in range(n):
    x[l[i]]+=1
for i in range(10**3+1):
    if i==0:
        y.append(0)
    else:
        y.append(y[i-1]+x[i])
ans=0
for i in range(n):
    for j in range(n):
        if i!=j:
            a=min(l[i],l[j])
            b=max(l[i],l[j])
            m=b-a
            M=min(a+b,10**3)
            g=y[M-1]-y[m]
            ans+=g
            if m<a<M:
                ans-=1
            if m<b<M:
                ans-=1
print(ans//6)

Submission status: Wrong Answer

Solution code:
import itertools
import bisect
N = int(input())
L = list(map(int, input().split()))
ans = 0
LS = sorted(L)
l = len(LS)
print(LS)
for i in range(l):
  for j in range(l):
    if i < j:
      for k in range(j+1,l):
        if LS[i]+LS[j] > LS[k]:
          ans += 1
        else:
          break
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import bisect
N = int(input())
L = list(map(int, input().split()))
ans = 0
LS = sorted(L)
for x in itertools.combinations(LS, 2):
  if x[0] > x[1]:
    x[0], x[1] = x[1], x[0]
  il = bisect.bisect_right(LS, x[1])
  ir = bisect.bisect_left(LS,x[0]+x[1])
  ans += ir-il
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import bisect
N = int(input())
L = list(map(int, input().split()))
ans = 0
LS = sorted(L)
print(LS)
for x in itertools.combinations(LS, 2):
  if x[0] > x[1]:
    x[0], x[1] = x[1], x[0]
  il = bisect.bisect_right(LS, x[1])
  ir = bisect.bisect_left(LS,x[0]+x[1])
  ans += ir-il
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
n, *l = map(int, open(0).read().split())
l.sort()

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        a = l[i]
        b = l[j]
        # a - b < c
        # b - a < c
        # c < a + b
        # max(a - b, b - a) < c < a + b
        right = bisect_right(l, a + b)
        left = bisect_right(l, max(a - b, b - a))
        tmp = max(0, right - left)
        if left <= i < right:
            tmp -= 1
        if left <= j < right:
            tmp -= 1
        ans += tmp
print(ans // 3)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
L.sort()
cnt = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        h_min = j
        h_max = N
        while h_max - h_min != 1:
            h_mid = (h_max + h_min) // 2
            if L[i] + L[j] > L[h_mid]:
                h_min = h_mid
            else:
                h_max = h_mid
        cnt += h_mid - j
print(cnt)

Submission status: Wrong Answer

Solution code:
N=int(input())
L=list(map(int,input().split()))
ans=0
c=[0]*2101
for i in L:c[i]+=1
for i in range(2100):c[i+1]=c[i]+c[i+1]
for i in range(N):
    for j in range(N):
        if i!=j:
            l,r=abs(L[i]-L[j])+1,L[i]+L[j]
            s=c[r]-c[l]
            if l<=L[i] and L[i]<r:s-=1
            if l<=L[j] and L[j]<r:s-=1
            ans+=max(s,0)
print(ans//6)

Submission status: Wrong Answer

Solution code:
n=int(input())
count = 0
a=sorted(list(map(int, input().split(" "))))
#print(a)
for i in range(n):
  for j in range(i + 1, n):
    for k in range(j + 1, n):
      #print(i,j,k)
      if a[i] + a[j] >= a[k]:
        count += 1
      else:
        break
print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 20:56:06 2020

@author: liang
"""

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

L.sort()
ans = 0
#print(L)
for i in range(N-2):
    #print("1:",i)
    p = i+2
    #以下O(2?N)　定数倍が遅い
    for j in range(i+1,N-1):
        #print("2",i,j)
        while p < N and L[p] < L[i] + L[j] :
            p += 1
            #print("up")
        #print(p)
        #ans += len(L[j+1:p])
        ans += max(0, p - j + 1)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
l.sort(reverse=True)
print(l)
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        x = (l[i]+1)-l[j]
        y = (l[j]+1)-l[i]
        z = (l[i]+l[j])-1
        e = max(x,y,z)
        f = min(x,y,z)
        a = j + 1
        while l[a] > e:
            a += 1
        b = n - 1
        while l[b] < f:
            b -= 1
        ans += max(0,b-a)
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
from itertools import combinations
from collections import Counter
def main():
    N = int(input())
    L = sorted(list(map(int, input().split())))
    ans = 0
    C = Counter(L)
    for l in combinations(L, 2):
        a = l[0]
        b = l[1]
        x = bisect.bisect_left(L, a + b)
        y = bisect.bisect(L, b - a)
        if b - a < a and a != b:
            ans += x - y - 2
        else:
            ans += x - y  - 1
    print(ans // 3)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import bisect
from itertools import combinations
from collections import Counter
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
C = Counter(L)
for l in combinations(L, 2):
    a = l[0]
    b = l[1]
    x = bisect.bisect_left(L, a + b)
    y = bisect.bisect(L, b - a)
    if b - a < a and a != b:
        ans += x - y - C[b] - C[a]
    else:
        ans += x - y  - C[b]
print(ans//3)

Submission status: Wrong Answer

Solution code:
import bisect
from itertools import combinations
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for l in combinations(L, 2):
    a = l[0]
    b = l[1]
    x = bisect.bisect(L, a + b)
    y = bisect.bisect_left(L, abs(a - b))
    ans += x - y - 3
print(ans)

Submission status: Wrong Answer

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

for i,a in enumerate(L):
  for j,b in enumerate(L[i+1:],start=i+1):
    ok=j+1
    ng=N-1
    if j+1>N-1:
      break
    elif ng-ok<=1:
      if L[ok]<a+b:
        ans+=1
      break
    while ng-ok>1:
      mid=(ok+ng)//2
      #print(mid,ok,ng)
      if L[mid]<a+b:
        ok=mid
      else:
        ng=mid
    #print(a,b,L[mid],mid,j,mid-j+1)
    ans+=(mid-j+1)
print(ans)

Submission status: Wrong Answer

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

for i,a in enumerate(L):
  for j,b in enumerate(L[i+1:],start=i+1):
    ok=j+1
    ng=N-1
    if j+1>N-1:
      break
    elif ng-ok<=1:
      if L[ok]<a+b:
        ans+=1
      break
    while ng-ok>1:
      mid=(ok+ng)//2
      #print(mid,ok,ng)
      if L[mid]<a+b:
        ok=mid
      else:
        ng=mid
    print(a,b,L[mid],mid,j,mid-j+1)
    ans+=(mid-j+1)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort()
def find(arr, x):
  if arr[0] > x:
    return 0
  if arr[-1] < x:
    return len(arr)
  
  l = 0
  h = len(arr)
  
  while h - l > 1:
    m = (l+h) // 2
    if arr[m] < x:
      l = m
    else:
      h = m
  return h

ans = 0

for i in range(N-2):
  for j in range(i+1, N-1):
    x = L[i] + L[j]
    ans += find(L[j+1:], x)
print(ans)

Submission status: Wrong Answer

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

L_max = L[-1]

cnt = [0]*(L_max+1)

ptr = 0
for i in range(1, L_max+1):
    cnt[i] = cnt[i - 1]
    while ptr < N and i == L[ptr]:
        cnt[i] += 1
        ptr += 1

res = 0
for i in range(N):
    for j in range(i + 1, N):
        res += max(0, cnt[min(L[i], L[j])] - 1 - cnt[abs(L[i] - L[j])])
        if L[i] == L[j]:
            res -= 1

print(res)

Submission status: Wrong Answer

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

L_max = L[-1]

cnt = [0]*(L_max+1)

ptr = 0
for i in range(1, L_max+1):
    if i == L[ptr]:
        cnt[i] = cnt[i - 1] + 1
        while ptr < N and i == L[ptr]:
            ptr += 1
    else:
        cnt[i] = cnt[i - 1]

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

print(res)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left

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

l.sort()

ans = 0

for i in range(n-2):
    for j in range(n-1):
        ans += bisect_left(l, l[i]+l[j]) - 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()

ans = 0

for i in range(n-2):
    for j in range(n-1):
        ans += bisect_left(l[j+1:], l[i]+l[j]) - j - 1

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools   # accumulate, compress, permutations(nPr), combinations(nCr)
import bisect      # bisect_left(insert位置), bisect_right(slice用)
# import math        # factorical（階乗) # hypot(距離)
# import heapq
# from fractions import gcd # Python3.5以前 # lcm（最小公倍数） = (a*b)//gcd(a,b)
# from fractions import Fraction
# from math import gcd # Python3.6以降
# --------------------------------------------------------------

n  = int(input())
bo = list(map(int,input().split()))
 
cnt = 0
bo.sort()
 
for a in range(n-1):
    for b in range(a+1,n):
        cnt += bisect.bisect_left(bo, bo[a]+bo[b]) - bisect.bisect_right(bo, bo[b])

print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools   # accumulate, compress, permutations(nPr), combinations(nCr)
# import bisect      # bisect_left(insert位置), bisect_right(slice用)
# import math        # factorical（階乗) # hypot(距離)
# import heapq
# from fractions import gcd # Python3.5以前 # lcm（最小公倍数） = (a*b)//gcd(a,b)
# from fractions import Fraction
# from math import gcd # Python3.6以降
# --------------------------------------------------------------

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

cnt = 0

wa = []
sa = []

for i in itertools.combinations(bo,2):
    wa.append(i[0]+i[1])
    sa.append(abs(i[0]-i[1]))

lwa = len(wa)

for i in range(n):
    for j in range(lwa):
        if sa[j] < bo[i] < wa[j]:
            cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
num=[0]*(max(l)+2)
for i in range(n):
    num[l[i]]+=1
cnt=[0]*(max(l)+2)
for i in range(1,len(num)):
    cnt[i]=cnt[i-1]+num[i]
l.sort()
ans=0
num3=max(l)
for i in range(n-2):
    for j in range(i+1,n-1):
        ans+=cnt[min(num3,l[i]+l[j]-1)]-cnt[l[j]]
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

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

l.sort(reverse=True)
ans = 0

for i in range(n):
    c = l[i]
    can_select = False
    for a, b in combinations(l[i+1:], 2):
        if c < a+b:
            ans += 1
            can_select = True
    if not can_select:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
ans = 0
c = n - 1
for a in range(n):
    c = n - 1
    for b in range(a + 1, n):
        if l[a] == l[b]:
            continue
        #　各a,bに対してのcを尺取法で探索
        while l[a] >= l[b] + l[c]:
            c -= 1
            if c <= b:
                break
        else:
            # print(l[a], l[b], l[c])
            ans += c - b
            continue
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
ans = 0
for a in range(n):
    for b in range(a + 1, n):
        if l[a] == l[b]:
            continue
        for c in range(b + 1, n):
            if l[b] == l[c]:
                continue
            if l[a] < l[b] + l[c]:
                ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = map(int, input().split())
l = sorted(l, reverse=True)

ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        x = l[i] - l[j]
        low = j + 1
        high = n - 1
        while low <= high:
            mid = (high + low) // 2
            print(mid)
            if l[mid] <= x and l[mid - 1] > x:
                ans += mid - j - 1
                break
            if l[mid] > x:
                low = mid + 1
            else:
                high = mid - 1

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

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

triangle = itertools.combinations(l, 3)

cnt = 0

for i in triangle:
  if max(i)*2 > sum(i):
    cnt += 1

print(cnt)

Submission status: Wrong Answer

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

a.sort()
import bisect
ans=0
#A=[1,2,3,4,5] #ソート済み
#index = bisect.bisect_left(A, 3) #2 同じ数字があった場合、前側の挿入箇所が返ってきている
#index = bisect.bisect_right(A, 3) # 3 同じ数字があった場合、後ろ側の挿入箇所が返ってきている
#A.insert(index, 3) #挿入
for i in range(len(a)-1):
    for j in range(i+1,len(a)):
        #a[i]<a[j]

        #a[k]<a[i]<a[j]

        #a[k]+a[i]>a[j]
        #=>a[i]> a[k] >a[j]-a[i]

        ll= bisect.bisect_right(a, a[j]-a[i])
        rr= bisect.bisect_left(a, a[i])
        ans+=(max(0,rr-ll))

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect


def main():
    n = int(input())
    l = list(int(i) for i in input().split())
    l = sorted(l, reverse=True)

    cnt = 0

    for i in range(n - 2):
        a = l[i]
        for j in range(i + 1, n-1):
            b = l[j]
            cnt += bisect.bisect_right(l, a-b)-(j+1)

    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

s = set()
for i in range(n - 2):
    a = L[i]
    for j in range(i + 1, n - 1):
        b = L[j]
        c_min = b - a
        c_max = a + b
        if c_max > c_min + 1:
            s.add((c_min, c_max, j + 1))

ans = 0
for x, y, j in s:
    i_min = bisect.bisect_right(L[j:], x)
    i_max = bisect.bisect_left(L[j:], y)
    ans += i_max - i_min
print(ans)

Submission status: Wrong Answer

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

c = {}
for i in range(n):
    if l[i] in c:
        c[l[i]] += 1
    else:
        c[l[i]] = 1

l2 = sorted(c.items(), reverse=True)
cnt = 0

n = len(l2)
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if l2[k][0] + l2[j][0] > l2[i][0]:
                cnt += l2[k][1]*l2[j][1]*l2[i][1]
            else:
                break

print(cnt)

Submission status: Wrong Answer

Solution code:
def biserch(n,List):
    left = 0
    right = len(List)
    while left < right:
        mid = (left+right)//2
        if n < List[mid]:
            right = mid
        else:
            left = mid + 1
    
    return left
    
N = int(input())
L = list(map(int,input().split()))
L.sort()

ans = 0
for i in range(N):
    for j in range(i+1,N):
        key = L[i] + L[j]
        anchor = biserch(key,L)
        
        ans += max(anchor - (j+1),0)

print(ans)

Submission status: Wrong Answer

Solution code:
def biserch(n,List):
    left = 0
    right = len(List)
    while left < right:
        mid = (left+right)//2
        if n == List[mid]:
            return mid
        elif n < List[mid]:
            right = mid
        else:
            left = mid + 1
    
    return right
    
N = int(input())
L = list(map(int,input().split()))
L.sort()

ans = 0
for i in range(N):
    for j in range(i+1,N):
        key = L[i] + L[j]
        anchor = biserch(key,L)
        
        ans += max(anchor - (j+1),0)

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def solve():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    res = 0
    for i in range(n):
        for j in range(i+1, n):
            k = bisect.bisect(l, l[i]+l[j])
            res += max(k-(j+1), 0)
    print(res)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
L = sorted(map(int,input().split()))
count = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        twobar = L[i]+L[j]
        if twobar > L[N-1]:
            count += N-j+1
            break
        for k in range(j+1,N):
            if twobar>L[k]:
                count += 1
            else:
                break
print(count)

Submission status: Wrong Answer

Solution code:
import math

def chk(a,b,c):
    isOK = False
    if a < b + c:
        if b < a + a:
            if c < a + b:
                isOK =  True
    return isOK
    
def combinations(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    
n = int(input())
l = list(map(int,input().split()))
l.sort()
cnt = 0
m = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if chk(l[i],l[j],l[k]):
                cnt += 1
            #else:
            #    print(l[i],l[j],l[k])
            m += 1
#print(l)
#print(cnt,m,combinations(n,3))
print(cnt)

Submission status: Wrong Answer

Solution code:
import math

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

for i in range(n-2):
    for j in range(i+1, n-1):
        buf = l[i]+l[j]
        Min = j+1
        Max = n-1
        while(Min!=Max):
            Mid = math.floor((Min+Max)/2)
            if l[Mid] < buf:
                Min = Mid+1
            else:
                Max = Mid
        ans += Min-(j+1)
print(ans)

Submission status: Wrong Answer

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

res = 0
for i in range(n-2):
  b = a[i:i+3]
  b.sort(reverse=True)
  if b[0] < b[1] + b[2]:
    res += 1
print(res)

Submission status: Wrong Answer

Solution code:
import bisect
N=int(input())
L=list(map(int,input().split()))
L.sort()
#print(L)
 
#b-a < c < a+b
#a<=b<=c
ans=0
L_a=L[:N-2]
for i,a in enumerate(L_a):
    L_b=L[i+1:N-1]
    for j,b in enumerate(L_b,start=i+1):
        x=bisect.bisect(L[j+1:],a+b)
        ans+=x
        c = L[j+x]
        if b-a==c or a+b==c:
            ans-=1
        #print(i,a,j,b,x,N-j-1,L[j+1:])
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N=int(input())
L=list(map(int,input().split()))
L.sort()
#print(L)
 
#b-a < c < a+b
#a<=b<=c
ans=0
L_a=L[:N-2]
for i,a in enumerate(L_a):
    L_b=L[i+1:N-1]
    for j,b in enumerate(L_b,start=i+1):
        x=bisect.bisect(L[j+1:],a+b)
        ans+=x
        if L[j+x]==a+b:
            ans-=1
        #print(i,a,j,b,x,N-j-1,L[j+1:])
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

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

ans=0
for a_idx in range(len(L)):
    a = L[a_idx]
    for b_idx in range(a_idx+1,len(L)):
        b = L[b_idx]
        c_low = b - a + 1
        c_up = a + b - 1
        
        c_low_idx = bisect.bisect(L,c_low)
        c_up_idx = bisect.bisect(L,c_up)
        c_low_idx = max(b_idx,c_low_idx)
        
        ans += max(0,c_up_idx-c_low_idx-1)
#         print(a,b,ans,c_up_idx,c_low_idx)
print(ans)

Submission status: Wrong Answer

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

#b-a < c < a+b
#a<=b<=c
ans=0
L_a=L[:N-2]
for i,a in enumerate(L_a):
    L_b=L[i+1:N-1]
    for j,b in enumerate(L_b,start=i+1):
        x=bisect.bisect(L[j+1:],a+b)
        ans+=x
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = sorted(list(map(int,input().split())))
ans = 0
for ai in range(n):
  for bi in range(ai+1,n):
    ng,ok = bi,n
    while ok-ng>1:
      mid = (ng+ok)//2
      if l[mid]<l[ai]+l[bi]:
        ok = mid
      else:
        ng = mid
    ans += n-ng-1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = sorted(list(map(int,input().split())))
ans = 0
for ai in range(n):
  for bi in range(ai+1,n):
    ng,ok = bi,n
    while ok-ng>1:
      mid = (ng+ok)//2
      if l[mid]<l[ai]+l[bi]:
        ok = mid
      else:
        ng = mid
    ans += n-ng-1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l_ls = list(map(int, input().split()))
l_ls.sort()
stick_count = [0] * (10**3+1)
stick_csum = [0] * (10**3+1)
for i in range(n):
    stick_count[l_ls[i]] += 1
now = 0
for i in range(10**3+1):
    now += stick_count[i]
    stick_csum[i] = now

ans = 0
for first_i in range(n):
    for second_i in range(first_i+1, n):
        #境界は含まない
        greater_than = abs(l_ls[first_i] - l_ls[second_i])
        smaller_than = min(10**3,l_ls[first_i] + l_ls[second_i])
        num_canmake = max(0, stick_csum[smaller_than-1] - stick_csum[greater_than])
        if greater_than < l_ls[first_i] < smaller_than:
            num_canmake -= 1
        if greater_than < l_ls[second_i] < smaller_than:
            num_canmake -= 1
        num_canmake = max(0,num_canmake)
        ans += num_canmake
print(ans//3)

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(lambda x:int(x)<<20,input().split()))
L.sort()
ep=1/2**30

P={}
for i in range(N):
    if L[i] in P:
        P[L[i]]+=1
        L[i]+=ep*P[L[i]]
    else:
        P[L[i]]=0
        
K=0
for i in range(N):
    for j in range(i+1,N):
        b,c=L[i],L[j]
        if c-b<b:
            X=Binary_Search_Small_Count(L,b,False,True)
            Y=Binary_Search_Small_Count(L,c-b,False,True)
            K+=max(0,X-Y-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()
ep=1/2**64

P={}
for i in range(N):
    if L[i] in P:
        P[L[i]]+=1
        L[i]+=ep*P[L[i]]
    else:
        P[L[i]]=0
        
K=0
for i in range(N):
    for j in range(i+1,N):
        b,c=L[i],L[j]
        if c-b<b:
            X=Binary_Search_Small_Count(L,b,False,True)
            Y=Binary_Search_Small_Count(L,c-b,False,True)
            K+=max(0,X-Y-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()
ep=1/2**30

P={}
for i in range(N):
    if L[i] in P:
        P[L[i]]+=1
        L[i]+=ep*P[L[i]]
    else:
        P[L[i]]=0
        
K=0
for i in range(N):
    for j in range(i+1,N):
        b,c=L[i],L[j]
        if c-b<b:
            X=Binary_Search_Small_Count(L,b,False,True)
            Y=Binary_Search_Small_Count(L,c-b,False,True)
            K+=max(0,X-Y-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):
        b,c=L[i],L[j]
        if c-b<b:
            X=Binary_Search_Small_Count(L,b,False,True)
            Y=Binary_Search_Small_Count(L,c-b,False,True)
            K+=max(0,X-Y-1)

            if b==c:
                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):
        b,c=L[i],L[j]
        X=Binary_Search_Small_Count(L,b,False,True)
        Y=Binary_Search_Small_Count(L,c-b,False,True)
        K+=X-Y
print(K)