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())
a = [int(x) for x in input().split()]
b = sorted(a)
ans = 0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if b[i]+b[j] <= b[k]:
                break
            elif b[k] == b[k-1]:
                continue
            else:
                print(b[i], b[j], b[k])
                ans += 1
print(ans)

Submission status: Wrong Answer

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

cnt = 0
# a <= b <= c となる3数を探す
for i in range(N):
    for j in range(i + i, N):
        T = bisect.bisect_left(L, L[i] + L[j])  # c < a + bを満たすcを探している
        cnt += T - j - 1

print(cnt)

Submission status: Wrong Answer

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

cnt = 0
# a <= b <= c となる3数を探す
for i in range(N - 1):
    for j in range(i + i, N):
        T = bisect.bisect_left(L, L[i] + L[j])  # c < a + bを満たすcを探している
        cnt += T - j - 1

print(cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

while len(L) > 2:
    for i in range(2,len(L)):
        if L[i] < L[0] + L[1]:
                count += 1
        if len(L) > 3:
            for j in range(3,len(L)):
                if L[j] < L[0] + L[i] and i < j:
                    count += 1
                    s = 1
                elif s == 1:
                    break
    del(L[0])

print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

while len(L) > 2:
    for i in range(2,len(L)):
        if L[i] < L[0] + L[1]:
            count += 1
    L.pop(0)

print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

while len(L) > 2:
    for i in range(2,len(L)):
        if L[i] > L[0] + L[1]:
            count += 1
    L.pop(0)

print(count)

Submission status: Wrong Answer

Solution code:
A = int(input())
sticks = [int(x) for x in input().split()]
total = 0
for i in range(A):
  for j in range(i + 1, A):
    for k in range(j + 1, A):
      avg = 2/3 * (sticks[i] + sticks[j] + sticks[k]) / 3
      if (max([sticks[i], sticks[j], sticks[k]]) <= avg):
        total += 1
print(total)

Submission status: Wrong Answer

Solution code:
A = int(input())
sticks = [int(x) for x in input().split()]
print(sticks)
total = 0
for i in range(A):
  for j in range(i + 1, A):
    for k in range(j + 1, A):
      if (sticks[i]<sticks[j] + sticks[k]) and (sticks[j]<sticks[i] + sticks[k]) and (sticks[k]<sticks[j] + sticks[i]):
        total += 1
print(total)

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
ds = input().split()
tris = 0
for i in range(N):
  ds[i] = int(ds[i])
ds.sort()
#print(ds)
Nums = range(N)
for i in reversed(range(N)):#一番大きい
  if i != 0 and ds[i] < 2*ds[0]:
    tris += int(i*(i-1)/2)
#    print("break!",tris,i)
    break
  else:
    for j in range(i):#一番小さい
      if ds[i] < 2*ds[j]:
        #tris += int((i-j+1)/2)
        tris += int((i-j)*(i-j-1)/2)
#        print("break",tris,i,j)
        break
      else:
        for k in range(j+1,i):#真ん中
#          print(ds[i],ds[j],ds[k])
          if ds[i] < ds[j] + ds[k]:
            #tris += 1
            tris += i-k
#            print(tris,i,j,k)
            break
        continue
      break
print(tris)
'''
756
218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 218 786 704 233 645 728 389 
'''

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort()
print(L)
count = 0
for i in range(N):
    for j in range(i+1, N):
        max_len = L[i] + L[j] - 1
        left = j+1
        right = N
        while left < right:
            mid = (left + right) // 2
            if L[mid] < max_len:
                left = mid + 1
            elif L[mid] > max_len:
                right = mid
            else:
                while mid < N - 1 and L[mid] == L[mid]:
                    mid += 1
                count += mid - j
                break
        else:
            count += right - j - 1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
count = 0
List = sorted(list(map(int, input().split())))
print(List)
for i in range(N-2):
  for j in range(N-i-2):
    a = List[i]
    b = List[i+j+1]
    index = [i for i, x in enumerate(List) if x >= a+b]
    if index == []:
      index = [N]
    count += index[0]-i-j-2
print(count)

Submission status: Wrong Answer

Solution code:
import bisect

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

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

print(count)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc143/tasks/abc143_d
# -*- coding: utf-8 -*-

stick_cnt = int(input())
stick_len = list(map(int, input().strip().split()))

stick_sort = sorted(stick_len, reverse=True)

tri_cnt = 0
for i in range(0,stick_cnt-2):
    for j in range(i+1,stick_cnt-1):
        work = i - j
        for k in range(j+1,stick_cnt):
            if work < k:
                tri_cnt += 1
            else:
                break

print(tri_cnt)

Submission status: Wrong Answer

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

l.sort()
ans_set = set()

for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if l[i] + l[j] < l[k]:
                break
            ans_set.add(frozenset([i, j, k]))

print(len(ans_set))

Submission status: Wrong Answer

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

l.sort()
ans_set = set()

for i, item1 in enumerate(l):
    for j, item2 in enumerate(l):
        if i <= j:
            continue
        a_add_b = item1+item2
        if item1-item2 <= 0:
            continue
        for k in range(i, len(l)):
            if i == k or j == k:
                continue
            if a_add_b <= l[k]:
                break
            ans_set.add(frozenset([i, j, k]))
print(len(ans_set))

Submission status: Wrong Answer

Solution code:
import bisect

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

total = 0
for a in range(n-2):
    for b in range(a+1, n-1):
        c = bisect.bisect_left(l, l[a] + l[b]) - b - 1
        total += c

print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [int(i) for i in input().split(" ")]

def meguru_nibutan(ar,m,key):
    a = m
    b = len(ar)
    while(abs(a-b) > 1):
        c = (a+b)//2
        if (ar[c] > key):
            a = c
        else:
            b = c
    return a

def main():
    cnt = 0
    l.sort(reverse=True)
    for a in range(0,n-2):
        for b in range(a+1,n-1):
            cnt += meguru_nibutan(l,b,l[a]-l[b]) - b

if (__name__ == "__main__"):
    main()

Submission status: Wrong Answer

Solution code:
def func():
    N = int(input())
    li = sorted(list(map(int, input().split())))

    print(li)
    r = 0
    for i, n1 in enumerate(li):
        for j, n2 in enumerate(li):
            for k, n3 in enumerate(li):
                if j + 1 > N or k > N or i >= j or j >= k:
                    continue
                if i + 3 == N:
                    if n1 + n2 > n3:
                        r += 1
                    return r
                if n1 + n2 > n3:
                    r += 1
                else:
                    break
print(func())

Submission status: Wrong Answer

Solution code:
def func():
    N = int(input())
    li = sorted(list(map(int, input().split())))

    print(li)
    r = 0
    for i, n1 in enumerate(li):
        for j, n2 in enumerate(li):
            for k, n3 in enumerate(li):
                if j + 1 > N or k > N or i >= j or j >= k:
                    continue
                if i + 3 == N:
                    if n1 + n2 > n3:
                        r += 1
                    return r
                if n1 + n2 > n3:
                    r += 1
                    print("r : " + str(r))
                else:
                    break
print(func())

Submission status: Wrong Answer

Solution code:
import itertools

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

for v in itertools.combinations(l, 3):
    pass

Submission status: Wrong Answer

Solution code:
# ABC143D - Triangles
def binary_search(cur: int, upper_bound: int, lower_bound: int) -> int:
    ok, ng, ret = upper_bound, lower_bound, 0
    while abs(ok - ng) > 1:
        if L[ok] + L[ng] > cur:
            ret += ok - ng
            ok -= 1
        else:
            ng += 1
    return ret


def main():
    # fix the longest edge -> binary search
    global L
    N, *L = map(int, open(0).read().split())
    L.sort()
    ans = sum(binary_search(L[i], i - 1, 0) for i in range(N - 1, 1, -1))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(int(x) for x in input().split())
N=0#総和
d.sort(reverse=True)

for i in range(n):
  for j in range(1+i,n):
    for k in range(1+i+j,n):
      if abs(d[j]-d[k])<d[i]<d[j]+d[k]:
        N+=1
print(N)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      if i<j+k and j<k+i and k<i+j:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(n-2):
  for j in range(i+1, n):
    for k in range(j+1, n):
      if i<j+k and j<k+i and k<i+j:
        ans += 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 i in range(1,n):
  for j in range(i):
    if j > bisect.bisect_left(L,L[i]-L[j]):
      ans += j-bisect.bisect_right(L,L[i]-L[j])
print(ans)

Submission status: Wrong Answer

Solution code:
# a - b < c
# b - a < c
# a + b > c

import bisect

n = int(input())

l = sorted([int(li) for li in input().split()])
print(l)

ret = 0

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

print(ret)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left


def p_d():
    N = int(input())
    L = list(map(int, input().split()))
    L.sort()
    ans = N * (N - 1) * (N - 2) // 6

    for i in range(N - 2):
        for j in (i + 1, N - 1):
            b = bisect_left(L, L[i] + L[j])
            if b != N:
                ans -= N - b

    print(ans)
    
p_d()

Submission status: Wrong Answer

Solution code:
from itertools import *

def binary_search(t, v, first, last):
	if last - first == 1:
		if v[first] > t:
			return first
		else:
			return last
	
	mid = (first + last) / 2
	if v[mid] <= t:
		return binary_search(t, v, mid, last)
	else:
		return binary_search(t, v, first, mid)

def ABC143D():
	N = int(raw_input())
	v = sorted(map(int, raw_input().split()))
	
	print v
	counter = 0
	for k, l in combinations(range(1, N), 2):
		# a <= b and a+b > c
		# a : (c-b, b]
		b = v[k]
		c = v[l]
		if b*2 < c:
			continue
		print b, c, k - binary_search(c-b, v, 0, k)
		counter += k - binary_search(c-b, v, 0, k)
	print counter

ABC143D()

Submission status: Wrong Answer

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

c=0

for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      if i<j+k and j<i+k and k<i+j:
        c+=1
        
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input().strip())
a = list(map(int, input().strip().split()))
na = [0]*1024
for x in a:
	na[x] += 1
sa = [0] * 1024
for i in range(1023):
	sa[i+1] = sa[i] + na[i]

ans = 0
for i in range(1, 1024):
	for j in range(i, 1024):
		mink = max(j, j-i+1)
		maxk = min(1022, i+j-1)
		if i != j:
			if mink != j:
				ans += na[i]*na[j]*(sa[maxk+1] - sa[mink])
			else:
				ans += na[i]*na[j]*(sa[maxk+1] - sa[mink] - 1) + na[i]*na[j]*(na[j]-1)//2
		else:
			if mink != j:
				ans += na[i]*(na[j]-1)//2*(sa[maxk+1] - sa[mink])
			else:
				ans += na[i]*(na[j]-1)//2*(sa[maxk+1] - sa[mink] - 1) + na[i]*(na[j]-1)*(na[j]-2)//6
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
L = [int(x) for x in input().split()]
L = sorted(L)
ans = 0
for one in range(N - 2):
    for two in range(one+1, N-1):
        ans += bisect.bisect_left(L, (L[one] + L[two]))-two-1
        print(bisect.bisect_left(L, (L[one] + L[two]))-two-1)
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

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

count = 0
for n in range(N-2):
    for m in range(n+1,N-1):
        count += N - bisect.bisect_left(L,L[m]+L[n])

print(count)

Submission status: Wrong Answer

Solution code:
import bisect

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

print(L)

count = 0
for n in range(N-2):
    for m in range(n+1,N-1):
        count += N - bisect.bisect_left(L,L[m]+L[n])

print(count)

Submission status: Wrong Answer

Solution code:
import bisect

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

count = 0
for n in range(N-2):
    for m in range(n+1,N-1):
        print(n,m)
        print(bisect.bisect_left(L,L[m]+L[n]))
        count += bisect.bisect_left(L,L[m]+L[n]) -m-1

print(count)

Submission status: Wrong Answer

Solution code:
def search(m,l): #startCは常に満たす、stopC+1は常に満たさない
  n=len(l)
  if l[0]<=m: return 0
  elif l[n-1]>m: return n
  startC,stopC=0,n-1
  while stopC-startC!=1:
    #print(l[startC:stopC])
    if l[startC+(1+stopC-startC)>>1]<=m:
      stopC=startC-1+(1+stopC-startC)>>1
    else:
      startC+=(1+stopC-startC)>>1
  return stopC
 
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    #print("ans***",ans,l[i]-l[j],l[j+1:])
    ans+=search(l[i]-l[j]+1,l[j+1:]) #l[i]-l[j]<l[ans-1]を満たす最大のans-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 i in range(n-1,1,-1):
  for j in range(i-1,0,-1):
    ans+=j-bisect.bisect_right(l,l[i]-l[j]+1,hi=j)
print(ans)

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(0,N-1):
  for j in range(i+1,N):
    index=bisect.bisect_left(L[j+1:],L[i]+L[j])
    count+=max(0,index-j-1)
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

ll.sort()
ans = 0
for i in range(n - 2):
    for j in range(i+1, n - 1):
        lb = j + 1
        ub = n - 1
        b = ll[i] + ll[j]
        if ll[lb] >= b:
            continue
        if ll[ub] < b:
            ans += ub - lb + 1
            continue
        while True:
            if ub == lb:
                ans += ub - lb + 1
                break
            t = (lb + ub) // 2 + 1
            if ll[t] < b:
                lb = t
            else:
                ub = t - 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 i in range(n-1,1,-1):
  for j in range(i-1,0,-1):
    ans+=j-bisect.bisect_left(l,l[i]-l[j],hi=j)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
L=list(map(int,input().split()))
L=sorted(L,reverse=True)
count=0
while len(L)>=3:
  a=L.pop(0)
  for i in range(1,len(L)):
    if L[i]>a-L[0]:
      count+=i
      
      
        
      
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int,input().split()))
li.sort(reverse = True)
count = 0

for x,a in enumerate(li):
  if x == n-2:
    continue
  for y,b in enumerate(li):
    if y <= x:
      continue
    for z,c in enumerate(li):
      if z <= y:
        continue
      if a < b+c and b < a+c and c < a+b:
        count += 1
        print(a,b,c)
print(count)

Submission status: Wrong Answer

Solution code:
#atcoder (２分探索)
def exceed(array,a):
    if array[a] == array[a+1]:
        return exceed(array,a+1)
    return a+1    
    
    
def binary_research(array,k,t,num): #list[k:t]からnumのインデックスを探す
    mid = (k+t) // 2
    if k==t:
        if num < array[k]:
            return k # それより１つ大きいindexを返す
        else:
            return k+1
    elif num == array[mid]:
        return exceed(array,mid)  # a-bと等しい一番小さいindexを返す
    elif num > array[mid]:
        return binary_research(array,mid+1,t,num)
    elif num < array[mid]:
        return binary_research(array,k,mid,num)
      
      
n = int(input())
l = list(map(int,input().split()))
sorted_l = sorted(list(set(l)))
count = 0

for i in reversed(range(len(sorted_l))):
    for j in reversed(range(i)):
        a = sorted_l[i]
        b = sorted_l[j] # aの方が長い
        # cの条件は　c > a -b　a-bを２分探索で探す
        if binary_research(sorted_l,0,j,a-b) < j:
          count += j - binary_research(sorted_l,0,j,a-b)          
			
print(count)

Submission status: Wrong Answer

Solution code:
#atcoder (２分探索)
def exceed(array,a):
    if array[a] == array[a+1]:
        return exceed(array,a+1)
    return a+1    
    
    
def binary_research(array,k,t,num): #list[k:t]からnumのインデックスを探す
    mid = (k+t) // 2
    if k==t:
        if num < array[k]:
            return k # それより１つ大きいindexを返す
        else:
            return k+1
    elif num == array[mid]:
        return exceed(array,mid)  # a-bと等しい一番小さいindexを返す
    elif num > array[mid]:
        return binary_research(array,mid+1,t,num)
    elif num < array[mid]:
        return binary_research(array,k,mid,num)
      
      
n = int(input())
l = list(map(int,input().split()))
sorted_l = sorted(l)
count = 0

for i in reversed(range(n)):
    for j in reversed(range(i)):
        a = sorted_l[i]
        b = sorted_l[j] # aの方が長い
        # cの条件は　c > a -b　a-bを２分探索で探す
        if binary_research(sorted_l,0,j,a-b) < j:
          count += j - binary_research(sorted_l,0,j,a-b)
          print(a,b,binary_research(sorted_l,0,j,a-b))
print(count)

Submission status: Wrong Answer

Solution code:
#atcoder (２分探索)
def exceed(array,a):
    if array[a] == array[a+1]:
        return exceed(array,a+1)
    return a+1    
    
    
def binary_research(array,k,t,num): #list[k:t]からnumのインデックスを探す
    mid = (k+t) // 2
    if k==t:
        if num < array[k]:
            return k # それより１つ大きいindexを返す
        else:
            return k+1
    elif num == array[mid]:
        return exceed(array,mid)  # a-bと等しい一番小さいindexを返す
    elif num > array[mid]:
        return binary_research(array,mid+1,t,num)
    elif num < array[mid]:
        return binary_research(array,k,mid,num)
      
      
n = int(input())
l = list(map(int,input().split()))
sorted_l = sorted(l)
count = 0

for i in reversed(range(n)):
    for j in reversed(range(i)):
        a = sorted_l[i]
        b = sorted_l[j] # aの方が長い
        # cの条件は　c > a -b　a-bを２分探索で探す
        count += j - binary_research(sorted_l,0,j,a-b)
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
counter=0
L=input().split()
list.sort(L)
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if int(L[i])<int(L[j])+int(L[k]):
                counter+=1
            else:
                break
print(counter)

Submission status: Wrong Answer

Solution code:
N=int(input())
counter=0
L=input().split()
list.sort(L,reverse=True)
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if int(L[i])<int(L[j])+int(L[k]):
                counter+=1
            else:
                break
print(counter)

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = [int(e) for e in input().split()]
sum = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if i + j > k and j + k > i and k + i > j:
                sum += 1
print(sum)

Submission status: Wrong Answer

Solution code:
import bisect

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

count = 0
for n in range(N-2):
    for m in range(n+1,N-1):
        count += bisect.bisect_left(L,L[m]-L[n]+1) -m-1

print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
d={i:l.count(i) for i in set(l)}
t=tuple(d.keys())
m=len(t)
T=0
for i in range(m-2):
  a=t[i]
  for j in range(m-i-1):
    b=t[i+j+1]
    for k in range(m-i-j-2):
      c=t[i+j+k+2]
      if a<b+c and b<c+a and c<a+b:
        T+=d[a]*d[b]*d[c]
print(T)

Submission status: Wrong Answer

Solution code:
def search(m,l): #startCは常に満たす、stopC+1は常に満たさない
  n=len(l)
  if l[0]<=m: return 0
  elif l[n-1]>m: return n
  startC,stopC=0,n-1
  while stopC-startC!=1:
    #print(l[startC:stopC])
    if l[startC+(1+stopC-startC)>>1]<=m:
      stopC=startC-1+(1+stopC-startC)>>1
    else:
      startC+=(1+stopC-startC)>>1
  return stopC
 
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    #print("ans***",ans,l[i]-l[j],l[j+1:])
    ans+=search(l[i]-l[j],l[j+1:]) #l[i]-l[j]<l[ans-1]を満たす最大のans-1を求める
print(ans)

Submission status: Wrong Answer

Solution code:
def search(m,l): #startCは常に満たす、stopC+1は常に満たさない
  n=len(l)
  if l[0]<=m: return 0
  elif l[n-1]>m: return n
  startC,stopC=0,n-1
  while stopC-startC!=1:
    #print(l[startC:stopC])
    if l[startC+(1+stopC-startC)>>1]<=m:
      stopC=startC-1+(1+stopC-startC)>>1
    else:
      startC+=(1+stopC-startC)>>1
  return stopC
 
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    #print("ans***",ans,l[i]-l[j],l[j+1:])
    ans+=search(l[i]-l[j],l[j+1:]) #l[i]-l[j]<l[ans]を満たす最小のansを求める
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int,input().split()))
li_asw = []
for i in range(n):
  for j in range(n):
    for k in range(n):
      if li[i] < li[j]+li[k] and li[j] <li[i]+li[k] and li[k]<li[i]+li[j]:
        li_a = [li[i], li[j], li[k]]
        li_asw.append(li_a.sort())
print(len(set(li_asw)))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
sum=0

n=int(input())

S=input().split()
s=[]
for i in range(n):
    s.append(int(S[i]))

for i in range(n):
    for j in range(n):
        for l in range(n):
            p=(s[i]+s[j]+s[l])/2
            if i!=l and i!=j and j!=l and p>=max(s[i],s[j],s[l]):
                #print(s[i],s[j],s[l])
                #print(max(s[i],s[j],s[l]))
                sum+=1

print(int(sum/6))

Submission status: Wrong Answer

Solution code:


def comp(ext,list0,dev):
    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 list0[ls[0]]==dev:
        return ls[0]-1
    elif list0[ls[1]]==dev:
        return ls[1]-1
    else:
        return ls[0]


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
        elif l[a]+l[b]<l[b+1]:
            c=b
        else:
            c=bis(b+1,n-1,l,l[a]+l[b])
        s=s+c-b
print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
def judge(c,a,b):
    if a<b+c and b<a+c and c<a+b:
        return True
    else:
        return False
def search(st,a,b):
    min=st-1
    max=len(l)
    while max-min>1:
        mid=(min+max)//2
        if judge(l[mid],a,b):
            max=mid
        else:
            min=mid
    return len(l)-max
def main(n,l):
    ans=0
    for i in range(n-2):
        for j in range(i+1,n-1):
            ans+=search(j+1,l[i],l[j])
    print(ans)
main(n,l)

Submission status: Wrong Answer

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

L.sort()
L.reverse()
#print(L)
count=0

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