Problem:


Score : 400 points

Problem Statement

Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i.

He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied:

a < b + c

b < c + a

c < a + b

How many different triangles can be formed? Two triangles are considered different when there is a stick used in only one of them.

Constraints

All values in input are integers.

3 \leq N \leq 2 \times 10^3

1 \leq L_i \leq 10^3

Input

Input is given from Standard Input in the following format:

N
L_1 L_2 ... L_N

Constraints

Print the number of different triangles that can be formed.

Sample Input 1

4
3 4 2 1

Sample Output 1

1

Only one triangle can be formed: the triangle formed by the first, second, and third sticks.

Sample Input 2

3
1 1000 1

Sample Output 2

0

No triangles can be formed.

Sample Input 3

7
218 786 704 233 645 728 389

Sample Output 3

23



Sample input:
4
3 4 2 1


Sample output:
1

Submission status: Wrong Answer

Solution code:
import bisect
N=int(input())
L_list=[int(thing) for thing in input().split()]
L_list.sort(reverse=True)

ret=0
s_list=[]
def my_bisect(l:list,f,left_true=True):
    def bis(begin:int,end:int):
        # print("{}:{}".format(begin,end))
        if end-begin<=1:
            if f(l[end]) ==True:
                return end
            elif f(l[begin])==True:
                return begin
            else:
                return -1
        v=int((end+begin)/2//1)
        res=f(l[v])
        if res and left_true:
            return bis(v,end)
        elif not res and left_true:
            return bis(begin,v)
        elif res and not left_true:
            return bis(begin,v)
        elif not res and not left_true:
            return bis(v,end)
        else:
            print("what")
    return bis(0,len(l)-1)
for i in range(N):
    n=L_list[i]
    diff=0
    for j in range(i+1,N-1):
        k=L_list[j]
        m=n-k
        l=L_list[j+1:N]
        s=my_bisect(l,lambda x:x>m)+1
        s_list.append(s)
        if s==0:
            break
        else:diff=diff+s
    ret=ret+diff
print(ret)
print(s_list)

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
Lmat = [int(n) for n in input().split()]
Lmat.sort()

def binary_search(list, item):
    low = 0
    high = len(list) - 1
    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid -1
        else:
            low = mid + 1
    return None

def iftriangle(first,second,third):
    if Lmat[first]>=Lmat[second]+Lmat[third]:
        return 0
    elif Lmat[second]>=Lmat[first]+Lmat[third]:
        return 0
    elif Lmat[third]>=Lmat[first]+Lmat[second]:
        return 0
    else:
        return 1

N2patern = list(itertools.combinations(range(N), 2)) #大小関係はまだ決まっていない

sum = 0
for patern in N2patern:
    if Lmat[patern[0]]<=Lmat[patern[1]]:#同じ場合の処理あとで
        min_index = patern[1]
        max_index = binary_search(Lmat, Lmat[patern[0]]+Lmat[patern[1]])
        for Lk_index,Lk_value in enumerate(Lmat[min_index:max_index]):
            sum += iftriangle(patern[0],patern[1],Lk_index)
print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
Ln = list(map(int,input().split(' ')))
Ln.sort(reverse=True)

count = 0


for a in range(N):
    a_l = Ln[a]
    current_min = N-1
    for b in range(a+1, N):
        if b >= current_min:
            break
        for c in range(b+1,N):
            c_idx = current_min
            bc = Ln[b] + Ln[c_idx]
            if a_l < bc:
                count += (current_min - b)
                break
            current_min -= 1
print(count)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random  # randome is not available at Codeforces
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
#eps=10**(-10)
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=lambda: sys.stdin.readline().rstrip()

show_flg=False
show_flg=True

n=I()
a=sorted(LI())[::-1]

s=set()
for i in a:
    s.add(i)
s=sorted(list(s))[::-1]
L=1080
#L=10000
k=[0]*(L)
ak=[0]
ans=0

for i in a:
    k[i]+=1
for i in range(L):
    ak.append(ak[-1]+k[i])

un=len(s)
for i in range(un):
    c=s[i]
    if k[c]>=3:
        ans+=k[c]*(k[c]-1)*(k[c]-2)//6
    if k[c]>=2:
        ans+=ak[c]*k[c]*(k[c]-1)//2
    for j in range(i+1,un):
        #show('i,j,s[i],s[j],mm',i,j,'|',s[i],s[j],s[i]-s[j]+1,'|',ak[s[i]-s[j]],ans)
        
        sc=s[j]
        if ak[sc]==0:
            break
        mm=c-sc+1
        if mm<0:
            continue
        elif mm>sc:
            continue # break
        else:
            ans+=k[c]*k[sc]*((1 if 2*sc>c else 0)*(k[sc]-1)//2+ak[sc]-ak[mm])
        #show('ans+=',k[sc]*(k[sc]-1)//2+ak[sc]-ak[mm])
    
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

def main():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    # print(l)
    ans = 0
    for i in range(len(l)-2):
        first = l[i]
        for j in range(i + 2, len(l)):
            second = l[j]
            s = i + 1
            e = j 
            # print("start",s, e)
            while(True):
                mid = int((s + e) / 2)
                # print("S",s, e, mid)
                
                if s == e:
                    break
                else:
                    if second >= first + l[mid]:
                        if s == mid:
                            s = e
                        else:
                            s = mid
                    else:
                        e = mid
            # print(s)
            ans += j - s
            print("ans", ans)
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
l_list = list(map(int, input().split()))
l_list.sort()
from bisect import *
ans = 0
for i in range(N):
    for j in range(i + 1, N - 1):
        a = l_list[i]
        b = l_list[j]
        low = max((abs(a - b), a, b))
        high = a + b
        id1 = bisect_right(l_list, high - 1)
        id2 = bisect_left(l_list, low)
        tmp = max(0, id1 - (id2 + 1))
        ans += tmp
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect
from bisect import bisect_left

_ = input()
l = input()
l = sorted(list(map(int, l.split())))
count = 0

for i in range(len(l)):
	for j in range(bisect(l,l[i]), len(l)):
		c = l[i]+l[j]
		count += bisect_left(l,c) - bisect(l,l[j])

print(count)

Submission status: Wrong Answer

Solution code:

def triangle_check(a, b, c):
  if a>b+c:
    return False
  elif b>a+c:
    return False
  elif c>a+b:
    return False
  else:
    return True

def count_triangles(n, sticks):
  assert len(sticks) == n, "lenght of sticks does not match `n`"
  count = 0

  for i in range(len(sticks)-2):
    for j in range(i+1, len(sticks)-1):
      for k in range(j+1, len(sticks)):
        count += triangle_check(sticks[i], sticks[j] , sticks[k])

  return count

def findnumberofTriangles(arr): 
  
    # Sort array and initialize count as 0 
    n = len(arr) 
    arr.sort() 
    count = 0
  
    # Fix the first element. We need to run till n-3 as 
    # the other two elements are selected from arr[i+1...n-1] 
    for i in range(0,n-2): 
  
        # Initialize index of the rightmost third element 
        k = i + 2
  
        # Fix the second element 
        for j in range(i+1,n): 
  
            # Find the rightmost element which is smaller 
            # than the sum of two fixed elements 
            # The important thing to note here is, we use 
            # the previous value of k. If value of arr[i] + 
            # arr[j-1] was greater than arr[k], then arr[i] + 
            # arr[j] must be greater than k, because the array 
            # is sorted. 
            while (k < n and arr[i] + arr[j] > arr[k]): 
                k += 1
  
            # Total number of possible triangles that can be 
            # formed with the two fixed elements is k - j - 1. 
            # The two fixed elements are arr[i] and arr[j]. All 
            # elements between arr[j+1] to arr[k-1] can form a 
            # triangle with arr[i] and arr[j]. One is subtracted 
            # from k because k is incremented one extra in above 
            # while loop. k will always be greater than j. If j 
            # becomes equal to k, then above loop will increment k, 
            # because arr[k] + arr[i] is always greater than arr[k] 
            if(k>j): 
                count += k - j - 1
  
    return count 

if __name__ == "__main__":

  n = int(input())
  sticks = sorted(list(map(int, input().split(" "))))
  num_triangles = count_triangles(n, sticks)
  # num_triangles = findnumberofTriangles(sticks)
  print(num_triangles)

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())
A = list(map(int,input().split()))
A.sort()
ans = 0

for i in range(N-1):
  k = A[i]
  for j in range(i+1, N):
    l = A[j]
    res = bisect.bisect_left(A, k+l)
    ans += res-k-1
    
print(ans)

Submission status: Wrong Answer

Solution code:

def triangle_check(a, b, c):
  if a>b+c:
    return False
  elif b>a+c:
    return False
  elif c>a+b:
    return False
  else:
    return True

def count_triangles(n, sticks):
  assert len(sticks) == n, "lenght of sticks does not match `n`"
  count = 0

  for i in range(len(sticks)):
    for j in range(i+1, len(sticks)):
      for k in range(j+1, len(sticks)):
        count += triangle_check(sticks[i], sticks[j] , sticks[k])

  return count

def findnumberofTriangles(arr): 
  
    # Sort array and initialize count as 0 
    n = len(arr) 
    arr.sort() 
    count = 0
  
    # Fix the first element. We need to run till n-3 as 
    # the other two elements are selected from arr[i+1...n-1] 
    for i in range(0,n-2): 
  
        # Initialize index of the rightmost third element 
        k = i + 2
  
        # Fix the second element 
        for j in range(i+1,n): 
  
            # Find the rightmost element which is smaller 
            # than the sum of two fixed elements 
            # The important thing to note here is, we use 
            # the previous value of k. If value of arr[i] + 
            # arr[j-1] was greater than arr[k], then arr[i] + 
            # arr[j] must be greater than k, because the array 
            # is sorted. 
            while (k < n and arr[i] + arr[j] > arr[k]): 
                k += 1
  
            # Total number of possible triangles that can be 
            # formed with the two fixed elements is k - j - 1. 
            # The two fixed elements are arr[i] and arr[j]. All 
            # elements between arr[j+1] to arr[k-1] can form a 
            # triangle with arr[i] and arr[j]. One is subtracted 
            # from k because k is incremented one extra in above 
            # while loop. k will always be greater than j. If j 
            # becomes equal to k, then above loop will increment k, 
            # because arr[k] + arr[i] is always greater than arr[k] 
            if(k>j): 
                count += k - j - 1
  
    return count 

if __name__ == "__main__":

  n = int(input())
  sticks = sorted(list(set(map(int, input().split(" ")))))
  # num_triangles = count_triangles(n, sticks)
  num_triangles = findnumberofTriangles(sticks)
  print(num_triangles)

Submission status: Wrong Answer

Solution code:

def triangle_check(a, b, c):
  if a>b+c:
    return False
  elif b>a+c:
    return False
  elif c>a+b:
    return False
  else:
    return True

def count_triangles(n, sticks):
  assert len(sticks) == n, "lenght of sticks does not match `n`"
  count = 0

  for i in range(len(sticks)):
    for j in range(i+1, len(sticks)):
      for k in range(j+1, len(sticks)):
        count += triangle_check(sticks[i], sticks[j] , sticks[k])

  return count




if __name__ == "__main__":

  n = int(input())
  sticks = list(map(int, input().split(" ")))
  num_triangles = count_triangles(n, sticks)
  print(num_triangles)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
L = list(map(int,input().split()))
L = sorted(L)
L.reverse()
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        x = L[i] - L[j]
        point = bisect.bisect_left(sorted(L),x)
        if x == L[N-1-point]:
            ans += max(0,N-j-1-point-1)
        else:
            
            ans += N-j-1-point if point < N-1-j else 0
        print(point)
        print(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
leng = [int(i) for i in input().split()]
leng.sort(reverse=True)
cnt = 0

for i, a in enumerate(leng[:-2]):
    for j, b in enumerate(leng[i+1:-1], i+1):
        for k, c in enumerate(leng[j+1:], j+1):
            if a < b+c and b < a+c and c < a+b:
                cnt += 1
            else:
                break
        if not a < b + c:
            break

print(cnt)

Submission status: Wrong Answer

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

cntL = [0] * (M + 1)
for l in L:
    cntL[l] += 1

accCntL = [0] * (M + 2)
for i in range(1, M + 2):
    accCntL[i] = accCntL[i - 1] + cntL[i - 1]

ans = 0
for i, A in enumerate(L):
    for j, B in enumerate(L):
        if i == j:
            continue

        right = min(A + B, M + 1)
        left = abs(A - B) + 1
        ans += accCntL[right] - accCntL[left + 1]

        if left + 1 < A < right:
            ans -= 1
        if left + 1 < B < right:
            ans -= 1

print(ans // 6)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int, input().split()))
 
L.sort()
 
dp = [0]*(1005)
frm = 0
cnt = 0
Lcopy = [1001] + L[::-1]
while Lcopy:
  to = Lcopy.pop()
  for i in range(frm, to):
    dp[i] = cnt
  frm = to
  cnt += 1
  
ans = 0
b = 1
c = 2
while b < N-1:
  sub = L[c] - L[b]
 
  x = dp[L[b]-1] - dp[sub+1]
  if x > 0:
    ans += x
  else:
    b += 1
    c = b
    
  c += 1
  if c >= N:
    b += 1
    c = b + 1

print(ans)

Submission status: Wrong Answer

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


print(L)


def f(j, max1, max2):
    L_temp = L[j+1:]
    # print("max1 = ", max1, "max2 = ", max2, L_temp)
    dif = max1 - max2
    left = -1
    right = len(L_temp)
    while right - left != 1:
        temp = (left+right)//2
        if dif < L_temp[temp]:
            left = temp
        else:
            right = temp
    if left != N:
        return left+1
    else:
        return left


ans = 0
max1 = 0
max2 = 0
for i in range(N):
    max1 = L[i]
    for j in range(i+1, N-1):
        max2 = L[j]
        ans += f(j, max1, max2)
        # print("ans = ", ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
# n = int(input())
# l = list(map(int, input().split()))
def main():
  n = 2000
  l = []
  for i in  range(n):
      l.append(1000)
  l.sort()
  l.append(99999999)
  x = 0
  c = 0
  for i in range(n - 2):
      t = i + 2
      for j in range(i + 1, n - 1):
          for k in range(t, n + 1):
              x += 1
              if l[i] + l[j] <= l[k]:
                  x -= 1
                  t = k
                  break
          if t > j: c += t - j - 1
          if j + 1 == t: t += 1
  print(c)
  print(x)
if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())
L = sorted([int(x) for x in input().split()])
print(L)
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ab = L[i] + L[j]
        r = bisect.bisect_left(L,ab)
        l = j + 1
        ans += r - l

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
from bisect import bisect_right, bisect_left

N = int(input())
L = sorted([int(i) for i in input().split()])
ans = 0

for i,j in combinations(range(N), 2):
    a, b = L[i], L[j]    
    if b - a >= a:
        continue
    x = bisect_right(L, a)
    y = bisect_left(L, b-a+1)
    ans += x - y
    if y <= i < x:
        ans -= 1
    if y <= j < x:
        ans -= 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
L = input().split()
LI = []
for l in L:
    LI.append(int(l))

LI.sort(reverse=True)
# LI.sort()
# print(LI)
count = 0

for i in range(N-2):
    a = LI[i]
    # print(a)
    for j in range(i + 1, N - 1):
        b = LI[j]
        # print(b)

        q = a - b
        w = b - a
        w = max([q,w])
        e = a + b
        if w > b:
            continue
        # print("\t" + str(w))
        
        low = j + 1
        high = N - 1
        while low <= high:
            mid = int((low + high) / 2)
            tmp = LI[mid]
            # print("\t\t"+str(tmp))
            
            if tmp > w:
                low = mid + 1

            else:
                count += (mid - j - 1)
                # print("\t\t\t"+str(mid-j-1))
                break
                high = mid - 1
                
            if low > high:
                count += (N - j - 1)
                # print("\t\t\t"+str(N-j-1))
                break


                


            
        # index = bisect.bisect_left(LI, e)

        # count += (index-j-1)




print(count)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
from bisect import bisect_right, bisect_left

N = int(input())
L = sorted([int(i) for i in input().split()])
ans = 0
for i,j in combinations(range(N), 2):
    a, b = L[i], L[j]
    x = bisect_right(L, a)
    y = bisect_left(L, b-a+1)
    ans += max(x - y,0)
    if x - y > 0:
        if i <= x:
            ans -= 1
        if j <= y:
            ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
L = input().split()
LI = []
for l in L:
    LI.append(int(l))

LI.sort(reverse=True)
# LI.sort()
# print(LI)
count = 0

for i in range(N-2):
    a = LI[i]
    # print(a)
    for j in range(i + 1, N - 1):
        b = LI[j]
        # print(b)

        q = a - b
        w = b - a
        w = max([q,w])
        e = a + b
        if w > b:
            continue
        # print("\t" + str(w))
        
        low = j + 1
        high = N - 1
        while low <= high:
            mid = int((low + high) / 2)
            tmp = LI[mid]
            # print("\t\t"+str(tmp))
            
            if tmp > w:
                low = mid + 1

            else:
                count = count + mid - j - 1
                # print("\t\t\t"+str(mid-j-1))
                break
                high = mid - 1
                
            if low > high:
                count = count + N - j - 1
                # print("\t\t\t"+str(N-j-1))
                break


                


            
        # index = bisect.bisect_left(LI, e)

        # count += (index-j-1)




print(count)

Submission status: Wrong Answer

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

def triangle(n,h):
    x = 0
    for i in range(0,n-2):
        for j in range(i+1,n-1):
            for k in range(j+1, n):
                if h[k] <= h[j] + h[i] :
                    x = x + 1
    return x
print(triangle(n,h))

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
L = input().split()
LI = []
for l in L:
    LI.append(int(l))

LI.sort(reverse=True)
# LI.sort()
# print(LI)
count = 0

for i in range(N-2):
    a = LI[i]
    # print(a)
    for j in range(i + 1, N - 1):
        b = LI[j]
        # print(b)

        q = a - b
        w = b - a
        w = max([q,w])
        e = a + b
        
        # print("\t" + str(w))
        
        low = j + 1
        high = N - 1
        while low <= high:
            mid = int((low + high) / 2)
            tmp = LI[mid]
            # print("\t\t"+str(tmp))
            
            if tmp > w:
                low = mid + 1

            else:
                count = count + mid - j - 1
                break
                high = mid - 1
                
            if low > high:
                count = count + N - j - 1
                break


                


            
        # index = bisect.bisect_left(LI, e)

        # count += (index-j-1)




print(count)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
L = input().split()
LI = []
for l in L:
    LI.append(int(l))

LI.sort(reverse=True)
# LI.sort()
print(LI)
count = 0

for i in range(N-2):
    a = LI[i]
    print(a)
    for j in range(i + 1, N - 1):
        b = LI[j]
        print(b)

        q = a - b
        w = b - a
        w = max([q,w])
        e = a + b
        
        print("\t" + str(w))
        
        low = j + 1
        high = N - 1
        while low <= high:
            mid = int((low + high) / 2)
            tmp = LI[mid]
            print("\t\t"+str(tmp))
            
            if tmp > w:
                low = mid + 1

            else:
                count = count + mid - j - 1
                break
                high = mid - 1
                
            if low > high:
                count = count + N - j - 1
                break


                


            
        # index = bisect.bisect_left(LI, e)

        # count += (index-j-1)




print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
L=list(map(int,input().split()))
L.sort()
ans=0
for n in range(1,N):
  b=L[n]
  for k in range(n):
    a=L[k]
    left=n+1
    right=N
    while left<right:
      mid=(left+right)//2
      if L[mid-1]<a+b<=L[mid]:
        ans+=(mid-n-1)
        break
      elif a+b<=L[mid]:
        right=mid
      else:
        left=mid+1
    aaa=min(left,right)
    ans+=(aaa-n-1)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
L=list(map(int,input().split()))
L.sort()
ans=0
for n in range(1,N):
  b=L[n]
  for k in range(n):
    a=L[k]
    left=n+1
    right=N
    while left<right:
      mid=(left+right)//2
      if L[mid-1]<a+b<=L[mid]:
        ans+=(mid-n-1)
        break
      elif a+b<=L[mid]:
        right=mid
      else:
        left=mid+1
    aaa=min(left,right,mid)
    ans+=(aaa-n-1)
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    a = sorted(a)
    ans = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            ind = bisect.bisect_right(a, a[i] + a[j])
            ans += ind - j - 1
    print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

if __name__ == '__main__':
    n = int(input())
    ans = 0
    a = [int(x) for x in input().split(' ')]
    a = sorted(a)
    for i in range(0, n-2):
        for j in range(i+1, n-1):
            m = bisect.bisect_right(a, a[i] + a[j])
            ans += m - j - 1
    print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

if __name__ == '__main__':
    n = int(input())
    ans = 0
    a = [int(x) for x in input().split(' ')]
    a.sort()
    for i in range(0, n-1):
        for j in range(i+1, n):
            m = bisect.bisect_right(a, a[i] + a[j])
            ans += m - j - 1
    print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
L=list(map(int,input().split()))
L.sort()
ans=0
for n in range(1,N):
  b=L[n]
  for k in range(n):
    a=L[k]
    left=n+1
    right=N
    while left<right:
      mid=(left+right)//2
      if L[mid-1]<a+b<=L[mid]:
        ans+=(mid-n-1)
        break
      elif a+b<=L[mid]:
        right=mid
      else:
        left=mid+1
    ans+=(left-n-1)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

count = 0 
L.sort()

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

        if k > j:
            count += k - j - 1


print(count)

Submission status: Wrong Answer

Solution code:
import bisect

if __name__ == '__main__':
    n = int(input())
    ans = 0
    a = [int(x) for x in input().split(' ')]
    a.sort()
    for i in range(0, n-1):
        for j in range(i+1, n):
            m = bisect.bisect_right(a, a[i], a[j])
            if i > m:
                ans += i - m
    print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
L=list(map(int,input().split()))
L.sort()
ans=0
for n in range(1,N):
  b=L[n]
  for k in range(n):
    a=L[k]
    left=n+1
    right=N
    while left<right:
      mid=(left+right)//2
      if L[mid-1]<a+b<=L[mid]:
        ans+=(mid-n-1)
        break
      elif a+b<L[mid]:
        right=mid
      else:
        left=mid+1
    ans+=(left-n-1)
print(ans)

Submission status: Wrong Answer

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


class AtCoder:
    def main(self):
        N = int(input())
        L = list(map(int, input().split()))

        ans = 0
        L.sort()

        for a, b in itertools.combinations(L, 2):
            _max = max(a, b)
            _index1 = bisect.bisect_right(L, _max)
            _index2 = bisect.bisect_left(L, a + b)

            ans += max(0, _index2 - _index1)

        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()

Submission status: Wrong Answer

Solution code:
import bisect
N=int(input())
ls=[int(s) for s in input().split()]
ls.sort()
ans=0
for i in range(1,N-1):
  for j in range(i+1,N):
    k = bisect.bisect_right(ls[:i],ls[j]-ls[i])
    print(i,j,k,i-k)
    ans+=i-k
print(ans)

Submission status: Wrong Answer

Solution code:
def c_slimes():
    from itertools import groupby
    N = int(input())
    S = input()
    return len([k for k, v in groupby(S)])

print(c_slimes())

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    L = list(map(int, input().split()))
    L.sort(reverse = True)
    counter = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            result = 0
            left = j+1
            right = n-1
            while L[right]+L[j] > L[i]:
                if right - left <= 1:
                    if L[right]+L[j] > L[i]:
                        result = right - j
                    else:
                        result = left - j
                    break
                mid = (left+right)//2
                if L[i]+L[j] > L[mid]:
                    left = mid
                else:
                    right = mid
            counter += result
    print(counter)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import bisect
a = int(input())
l = list(map(int,input().split()))
l.sort()
s = 0
for n,x in enumerate(l):
    for m,y in enumerate(l[n+1:]):
        # print(n+m+2)
        t = x + y
        s += bisect.bisect_right(l[n+m+2:],t)


print(s)

Submission status: Wrong Answer

Solution code:
n=int(input())
l_lis=list(map(int,input().split()))
counter=0
for i in l_lis:
    for j in l_lis:
        if i!=j:
            for k in l_lis:
                if j!=k and i!=k:
                    if i<j+k and j<i+k and k<i+j:
                        counter+=1
print(int(counter/6))

Submission status: Wrong Answer

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

def binary_s(left, right, a, b):
    result = 0
    while L[a]+L[b] > L[left]:
        if right - left <= 1:
            if L[a]+L[b] > L[right]:
                result = right - max(a, b)
                print(a, b, right)
            else:
                result = left - max(a, b)
                print(a, b,left)
            break
        mid = (left+right)//2
        if L[a]+L[b] > L[mid]:
            left = mid
        else:
            right = mid
    return result
counter = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        
        counter += binary_s(j+1, n-1, i, j)

print(counter)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    L = [int(i) for i in input().split()]
    L.sort()
    L_pair = []
    for i in range(N):
        for j in range(i+1, N):
            L_pair.append((i, j))

    def is_ok(mid, i, j):
        if L[mid] < L[i] + L[j]:
            return True
        else:
            return False

    def binary_search_meguru(i, j):
        left = j
        right = N
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid, i, j):
                left = mid
            else:
                right = mid
        return right

    ans = 0
    for i, j in L_pair:
        r = binary_search_meguru(i, j)
        print(i, j, r)
        ans += r - (j + 1)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(map(int, input().split()))
r = 0
for i in range(2, n):
    k = i - 1
    for j in range(k):
        while j < k and a[j] + a[k] > a[i]: k -= 1
        r += i - k - 1
print(r)

Submission status: Wrong Answer

Solution code:
import bisect

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

L=sorted(L)

#重複削除用探索リスト
setL = sorted(list(set(L)))

sankaku_dict={}
count=0
for i in range(len(L)-1):
    low=L[i]
    for j in range(i+1, len(L)):
        high = L[j]
        
        #下限のインデックスを取得
        low_index = bisect.bisect_right(L, high)

        # 2本の棒の和よりも小さい棒の数を探索
        high_index = bisect.bisect_left(L[low_index:], high+low)
        
        count+=high_index