TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
n=int(input())
s=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 s[i]+s[j]<=s[k]:
                print(ans)
                exit()
            elif s[j]+s[k]<=s[i]:
                print(ans)
                exit()
            elif s[i]+s[k]<=s[j]:
                print(ans)
                exit()
            else:
                ans+=1
                print(ans)
            

from bisect import bisect_left
n = int(input())
l = [int(_) for _ in input().split()]
l.sort()
cnt = 0
for i in range(n):
    for j in range(i+1,n):
        cnt += max(0, bisect_left(l, l[i] + l[j]) - (j+1))
print(cnt)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())

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

ans = 0

for i in range(N):
    L_count[L[i]] += 1

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

print(ans)

from bisect import bisect_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):
        c = L[i] + L[j]
        
        idx = bisect_left(L, c)
        ans += max(0, idx - (j + 1))

print(ans)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
l = [int(x) for x in input().split()]
l.sort(reverse=True)
 
ans = 0
 
for i in range(n-2):
  j = i + 1
  k = n - 1
  while j < k:
    if l[i] < l[j] + l[k]:
    	ans += k - j
    	j += 1
  	else:
  		k -= 1
print(ans)

N = int(input())
l = [int(x) for x in input().split()]
l.sort(reverse=True)

ans = 0

for i in range(n-2):
  j = i + 1
  k = n - 1
  if l[i] < l[j] + l[k]:
    ans += k - j
    j += 1
  else:
    k -= 1
print(ans)

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

L = sorted(l,reverse=True)
a = 0

for x in range(0,N-3):
  for y in range(x+1,N-2):
	for i in range(y+1,N-1):
	  if L[i] > L[x] - L[y]:
		a += 1
print(a)

N = int(input())
l = [int(x) for x in input().split()]
l.sort(reverse=True)
 
ans = 0
 
for i in range(N-2):
  j = i + 1
  k = N - 1
  while j < k:
    if l[i] < l[j] + l[k]:
      ans += k - j
      j += 1
    else:
      k -= 1
print(ans)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import bisect

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

l.sort()

ans = 0

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

print(ans)

import bisect

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):
        q = l[i]+l[j]
        p = bisect.bisect_left(l, q)
        ans += (p - j - 1)

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from itertools import combinations
import numpy as np

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

hoge = np.sort(l)
ans = 0

for v in combinations(hoge, 3):
    if v[2] < v[0] + v[1]:
        ans += 1

print(ans)


import bisect

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):
        bise = bisect.bisect_left(l, l[i] + l[j])
        if bise > j:
            ans += bise - (j + 1)
        else:
            pass

print(ans)



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

# ans = 0
# for a_i in range(N):
#     for b_i in range(a_i+1, N):

#         if c_i > b_i:
#             ans += c_i - b_i - 1
#         else:

#
# print(ans)

# from itertools import combinations
# import numpy as np
#
# n = int(input())
# hoge = list(map(int, input().split()))
# hoge.sort()
#
# # hoge = np.sort(l)

# ans = 0
#
# def triangle(target, v1, v2):

#

#     for j in range(i + 1, len(hoge)):
#         left = hoge[j]
#         right = hoge[-1] + 1
#         while left + 1 < right:
#             mid = (left + right) / 2
#             if triangle(mid, hoge[i], hoge[j]):
#                 ans += len(hoge[hoge >= mid])
#                 break
#             else:
#                 left = mid
#
# print(ans)











Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
ans = 0
for i in range(n - 2):
    a = L[i]
    for j in range(i + 1, n - 1):
        b = L[j]
        for k in range(j + 1, n):
            c = L[k]
            if a < b + c:
                ans += n - k
                break
print(ans)


import bisect

n = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(n - 2):
    a = L[i]
    for j in range(i + 1, n - 1):
        b = L[j]
        k = bisect.bisect_left(L, a + b)
        ans += k - j - 1
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
import collections
import itertools
import bisect
mod = 10 ** 9 + 7
N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
print(L)
count = 0
for i in range(len(L)):
    for j in range(i+1, len(L)):
        a = L[i]
        b = L[j]
        idx = insert_index = bisect.bisect_left(L, a+b)
        count += max(0, idx-j-1)


print(count)


# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
import collections
import itertools
import bisect
mod = 10 ** 9 + 7
N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
count = 0
for i in range(len(L)):
    for j in range(i+1, len(L)):
        a = L[i]
        b = L[j]
        idx = insert_index = bisect.bisect_left(L, a+b)
        count += max(0, idx-j-1)


print(count)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import bisect
n = int(input())
l = list(map(int,input().split()))
l.sort()
count = 0
print(l)
for i in range(n-2):
    for j in range(i+1,n-1):
        index = bisect.bisect_right(l,l[i]+l[j],j)
        print(i,j,index)
        count += index-j-1
print(count)

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

for i in range(n-2):
    for j in range(i+1,n-1):
        index = bisect.bisect_right(l,l[i]+l[j],j)
       
        count += index-j-1
print(count)

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

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

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
li = list(map(int,input().split()))
li2 = sorted(li,reverse=True)
cnt = 0

for i in range(n):
    for j in range(i+1,n):
        if li2[i] > li2[j] + li2[j+1]:
            break
        else:
            for k in range(j+1,n):
                if li2[i] < li2[j]+li2[k]:
                    cnt += 1
                else:
                    break
print(cnt)

import bisect

n = int(input())
li = list(map(int,input().split()))
li2 = sorted(li)
cnt = 0

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

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
#import copy
#import numpy as np
#n = int(input())
#l = list(map(int, input().split()))




def sol(n, l):
    import bisect
    l.sort()
    ans = 0
    #print(l)
    for i in range(n-1):
        for j in range(i+1, n):
            ji = l[j]+l[i]
            ind = bisect.bisect_right(l, ji)
            #print(i,j,ind,ind-j-1)
            ans += ind-j-1
    return ans


def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int, input().split()))
    print(sol(n, l))


if __name__ == "__main__":
    main()


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




def sol(n,l):
    import bisect
    l.sort()
    a = []
    #print(l)
    for i in range(n-2):
        for j in range(i+2,n):
            ind = bisect.bisect_left(l,j-i+1,lo=i+1,hi=j+1)
            #print(i,j,ind)
            a.append(ind)
    return len(a)


def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int, input().split()))
    print(sol(n,l))

        
if __name__ == "__main__":
    main()


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




def sol(n,l):
    import bisect
    l.sort()
    a = []
    print(l)
    for i in range(n-2):
        for j in range(i+2,n):
            ind = bisect.bisect_left(l,j-i+1,lo=i+1,hi=j+1)
            print(i,j,ind)
            a.append(ind)
    return len(a)


def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int, input().split()))
    print(sol(n,l))

        
if __name__ == "__main__":
    main()


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




def sol(n,l):
    import bisect
    l.sort()
    ans = 0
    #print(l)
    for i in range(n-1):
        for j in range(i+1,n):
            ji = l[j]+l[i]
            ind = bisect.bisect_left(l,ji)
            print(i,j,ind,ind-j-1)
            ans += ind-j-1
    return ans


def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int, input().split()))
    print(sol(n,l))

        
if __name__ == "__main__":
    main()


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




def sol(n,l):
    import bisect
    l.sort()
    ans = 0
    #print(l)
    for i in range(n-1):
        for j in range(i+1,n):
            ji = l[j]+l[i]
            ind = bisect.bisect_left(l,ji)
            #print(i,j,ind,ind-j-1)
            ans += ind-j-1
    return ans


def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int, input().split()))
    print(sol(n,l))

        
if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)))

from bisect import*
l = sorted(map(int, open(0).read().split()[1:]))
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)))

from bisect import*
n, *l = map(int, open(0).read().split())
l.sort()
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)))

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import bisect

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

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

print(ans)


import bisect

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

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

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import bisect
n = int(input())
l = list(map(int,input().split()))
cnt = 0
l = sorted(l)
for i in range(n):
    for j in range(i+1,n):
        d = l[i]+ l[j]
        p = bisect.bisect_left(l,d) - j +1
print(cnt)    


import bisect
n = int(input())
l = list(map(int,input().split()))
cnt = 0
l = sorted(l)
for i in range(n):
    for j in range(i+1,n):
        d = l[i]+ l[j]
        cnt +=bisect.bisect_left(l,d) - (j+1)
print(cnt)    


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from bisect import bisect_left

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

L.sort()
print(L)
result = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        result += bisect_left(L, L[i] + L[j]) - j - 1
print(result)

from bisect import bisect_left

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

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

print(result)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
lst=list(map(int,input().split()))
lst.sort()
count=0
for i in range(n-2):
    for j in range(i+2,n):                             
        for k in range (i+1,j):
            a=lst[i]
            c=lst[j]
            b=lst[k]
            if b>a-c:
                    count+=1
            elif b<=a-c:
                break
print(count)


n=int(input())
lst=list(map(int,input().split()))
lst.sort()
count=0
for i in range(n-2):
    for j in range(i+2,n):                             
        for k in range (i+1,j):
            a=lst[i]
            c=lst[j]
            b=lst[k]
            if b>a-c:
                count+=1
                
            elif b<=a-c:
                break
        
print(count)


n=int(input())
lst=list(map(int,input().split()))
count=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(k+1,n):              
            a=lst[i]
            b=lst[j]
            c=lst[k]
            if a<b+c and b<c+a and c<a+b:
                    count+=1
print(count)


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


Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import itertools
import heapq
import sys
readline = sys.stdin.readline

N = int(readline())
#ls = list(map(int, readline().split()))
ls = list(map(lambda x: int(x) * (-1), readline().split()))
#ls *= 100
#N *= 100
heapq.heapify(ls)
ans = 0
# n_comb = N * (N-1) * (N-2) / 6
 
import copy
copy_ls = copy.deepcopy(ls)
for i in range(N):
    max1 = -(heapq.heappop(ls))
    copy_ls1 = copy.deepcopy(ls)
    #print(ls)
    for j in range(N-i-1):
      # print(j, ls)
      max2 = -(heapq.heappop(ls))
      for _ in range(N-i-j-2):
        max3 = -(heapq.heappop(ls))
        if (max1 < max2 + max3):
          #print(max1, max2, max3)
          ans += 1
        else:
          # print('break')
          ls = copy.deepcopy(copy_ls1)
          heapq.heappop(ls)
          copy_ls1 = copy.deepcopy(ls)
          break
      ls = copy.deepcopy(copy_ls1)
      heapq.heappop(ls)
      copy_ls1 = copy.deepcopy(ls)
    
    
    ls = copy.deepcopy(copy_ls)

import bisect
import sys
input = sys.stdin.readline
N = int(input())
ls = list(map(int, input().split()))
ls.sort()

ans = 0
for i in range(N-2):
  a = ls[i]
  for j in range(i+1, N-1):
    b = ls[j]
    pos = bisect.bisect_left(ls, a+b)
    ans += pos - j - 1
print(ans)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from math import ceil, floor, factorial
n = int(input())
ls = map(int, input().split())
ls = sorted(ls)


counter = 0


def pred(l1, l2, l3):
    return l1 < l2 + l3 and l2 < l1 + l3 and l3 < l1 + l2


def binary_search(arr, l, r, x):
    cut = (l+r) // 2

    if arr[r] < x:
        return r
    if arr[l] > x:
        return l

    if arr[cut] > x and arr[cut-1] < x:
        x = arr[cut]
    if arr[cut] < x and arr[cut+1] > x:
        x = arr[cut+1]
        cut += 1

    if arr[cut] > x:
        return binary_search(arr, cut, r, x)
    elif arr[cut] < x:
        return binary_search(arr, l, cut, x)

    while arr[cut+1] == x:
        cut += 1
    while arr[cut-1] == x:
        cut -= 1

    return cut


for i in range(1, n-1):
    l1 = ls[n-i]
    for j in range(i+1, n):
        l2 = ls[n-j]
        cut = (n-j)//2

        upper_bound = n-j
        lower_bound = 0
        looking_for = l1 - l2

        cut = binary_search(ls, lower_bound, upper_bound, looking_for)

        count_l3s = (n-j) - cut
        counter += count_l3s

print(counter)


from bisect import bisect_left
n = int(input())
ls = map(int, input().split())
ls = sorted(ls)

counter = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        counter += (bisect_left(ls, ls[i] + ls[j]) - 1) - j

print(counter)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)

import bisect
N = int(input())
count = 0
List = sorted(list(map(int, input().split())))
for i in range(N-2):
  for j in range(N-i-2):
    a = List[i]
    b = List[i+j+1]
    index = bisect.bisect_left(List, a+b)
    count += index-i-j-2
print(count)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from sys import stdin
import itertools
import bisect
N = int(stdin.readline().rstrip())
L = [int(x) for x in stdin.readline().rstrip().split()]
L.sort()
ans = 0

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

from sys import stdin
import itertools
import bisect
N = int(stdin.readline().rstrip())
L = [int(x) for x in stdin.readline().rstrip().split()]
L.sort()
ans = 0

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

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int( input() )
l = list( map( int, input().split() ) )

l = sorted( l )
cnt = 0
for i in range( len( l ) - 2 ):
  for j in range( i + 1, len( l ) - 1 ):
    for k in range( j + 1, len( l ) ):
      if l[ i ] + l[ j ] <= l[ k ]:
        break
      else:
        print( l[ i ], l[ j ], l[ k ] )
        cnt += 1
print( cnt )

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

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys
from collections import Counter
from bisect import bisect, bisect_left
from fractions import Fraction

def comb(n, k):
    if n < 0 or k < 0:
        pdt = 0
    else:
        pdt = 1
        for s in range(1, k + 1):
            pdt *= Fraction(n - s + 1, s)
    return pdt.numerator

input = sys.stdin.readline
N = int(input())
L = sorted([int(x) for x in input().split()])
c = 0
Lcnt = Counter(L)
Lset = sorted(list(set(L)))
Nset = len(Lset)
for i in range(Nset):
    if Lcnt[Lset[i]] >= 3:
        c += comb(Lcnt[Lset[i]], 3)
        if i == Nset - 1:
            break

    if Lcnt[Lset[i]] >= 2:
        fl = bisect(L, Lset[i])
        fr = bisect_left(L, Lset[i] * 2)
        c += comb(Lcnt[Lset[i]], 2) * (fr - fl)
    for j in range(i + 1, Nset):
        fl = bisect(L, Lset[j])
        fr = min(bisect_left(L, Lset[i] + Lset[j]), len(L) - 1)
        c += Lcnt[Lset[i]] * Lcnt[Lset[j]] * (fr - fl)

if Lcnt[Lset[-1]] >= 2:
    c += Lcnt[Lset[-2]] * comb(Lcnt[Lset[-1]], 2)
print(c)

import sys
from bisect import bisect, bisect_left

input = sys.stdin.readline
N = int(input())
L = sorted([int(x) for x in input().split()])
c = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        f = bisect_left(L, L[i] + L[j])
        c += f - j - 1
print(c)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)

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()

n = int(input())
l = list(map(int, input().split(' ')))
l.sort()
counter = 0
for i in range(n):
    s = i + 2
    for j in range(i+1,n):        
        while (s < n and l[i] + l[j] > l[s]):
            s += 1
        counter += s-j-1
print(counter)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np

# n = int(input())

# l = np.array(list(map(int,input().split())))

n = 200
l = np.array([3 for i in range(n)])

l.sort()

#     if l[first] < l[second] + l[third]:
#         dp[first] += 1
#         if third > 0:
#             num(first,second,third-1)
#         else:
#             # print(first,second,third)
#             return 
#     else:
#         # print(first,second,third)
#         return second, third





dp = np.array([0]*n)

for i in range(n-1,1,-1):
    for j in range(i-1,0,-1):
        # print(i,j)
        # num(i,j,j-1)
        for k in range(j-1,-1,-1):
            
            if l[i] < l[j] + l[k]:
                dp[i] += 1
            else:
                second = j
                third = k
                break
        else:
            second = j
            third = k
        if second == third + 1:
            break
    # print(i)
print(np.sum(dp))

import numpy as np
n = int(input())

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

l.sort()
l = l[::-1]
ans = 0
for i in range(n-2):
    j = i+1
    k = n-1
    while j < k:
        if l[i] < l[j] + l[k]:
            ans += k - j
            j += 1
        else:
            k -= 1
print(ans)




Verdicts: Time Limit Exceeded

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
L = [int(i) for i in input().split()]


from itertools import combinations

ans = 0
for a, b, c in combinations(L,3):
    if a<b+c or b<a+c or c<a+b:
        ans += 1

print(ans)

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

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

print(ans)
          

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import bisect
n = int(input())
ln = list(map(int, input().split()))
ln.sort()
ans = 0

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

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

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
if __name__ == "__main__":
    N = int(input())
    L = list(map(int, input().split()))

    L.sort()
    L.reverse()

    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            for k in range(j+1, N):
                if i != j and j != k and k != i:
                    if L[i] < L[j] + L[k]:
                        ans += N - k
                        break

    print(ans)


from bisect import bisect_right

if __name__ == "__main__":
    N = int(input())
    L = list(map(int, input().split()))

    L.sort()

    ans = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            k = bisect_right(L, L[i] + L[j] - 1)
            ans += max(k - j - 1, 0)

    print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import bisect

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

D.sort()
total=0

for i in range(N-2):
    for j in range(i+1,N-1):
        total+=   bisect.bisect_left(D,D[i]+D[j])-j

print(total)

import bisect

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

D.sort(reverse=True)
total=0
#print(D)
def check(a,b,c): #3
    if(a<b+c):
        if(b<a+c):
            if(c<a+b):
                return True
    return False

for i in range(len(D)):
    for j in range(i+1,len(D)):
        v=D[i]-D[j]
        total+= len(D[j+1:]) - bisect.bisect_left(D[j+1:],v)

        # for k in range(j + 1, len(D)):
        #     if(check(D[i],D[j],D[k])):
        
        #         print(str(i)+" "+str(j)+" "+str(k)+"   "+str(total))


print(total)


import bisect

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

D.sort()
total=0

for i in range(N-2):
    for j in range(i+1,N-1):
        total+= bisect.bisect_left(D[j+1:],D[i]+D[j])

print(total)

import bisect

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

D.sort()
total=0

for i in range(N-2):
    for j in range(i+1,N-1):
        total+=bisect.bisect_left(D,D[i]+D[j])-j-1

print(total)

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import bisect

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



total = 0

for i in range(len(L)):
    for j in range(i):
        a = L[i]
        b = L[j]

        right_index = bisect.bisect_left(L, a + b)
        left_index = bisect.bisect_right(L, abs(a - b))

        total += right_index - left_index
        
        # for k in range(left_index, right_index):
        #     triple = frozenset([i,j,k])
        #     if len(triple) == 3:
        

# print(len(triples))

import bisect

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



total = 0

for i in range(len(L)):
    for j in range(i):
        a = L[i]
        b = L[j]

        right_index = bisect.bisect_left(L, a + b)
        left_index = bisect.bisect_right(L, abs(a - b))

        total += right_index - left_index
        
        # for k in range(left_index, right_index):
        #     triple = frozenset([i,j,k])
        #     if len(triple) == 3:
        

# print(len(triples))

import bisect

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

total = 0

for i in range(N - 2):
    a = L[i]
    for j in range(i + 1, N - 1):
        b = L[j]
        right_endpoint = bisect.bisect_left(L, a+b, j)
        total += right_endpoint - j - 1

print(total)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from scipy.misc import comb
n = int(input())
h = list(map(int, input().split()))
def triangle(n,h):
    x = comb(n, 3, exact = True)
    for i in range(0,n-2):
        for j in range(i+1,n-1):
            for k in range(j+1, n):
                if h[i] >= h[j] + h[k] or h[j] >= h[i] + h[k] or h[k] >= h[j] + h[i]:
                    x = x - 1
    return x
print(triangle(n,h))

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))

import bisect
n = int(input())
h = list(map(int, input().split()))
h.sort()
x = 0
def triangle(n,h):
    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))

nCr = {}
def cmb(a, b):
    if a == 0 or a == b: return 1
    if a == 1: return b
    if (a,b) in nCr: return nCr[(a,b)]
    nCr[(a,b)] = cmb(a-1,b) + cmb(a-1,b-1)
    return nCr[(a,b)]
n = int(input())
h = list(map(int, input().split()))
def triangle(n,h):
    x = cmb(n, 3)
    for i in range(0,n-2):
        for j in range(i+1,n-1):
            for k in range(j+1, n):
                if h[i] >= h[j] + h[k] or h[j] >= h[i] + h[k] or h[k] >= h[j] + h[i]:
                    x = x - 1
    return x
print(triangle(n,h))

import bisect
N = int(input())

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

for i in range(N - 2):
  for j in range(i + 1, N - 1):
    
    # l1 + l2 > l3
    l12 = L[i] + L[j]
    
    
    ans += bisect.bisect_left(L, l12) - j - 1
print(ans)

Verdicts: Time Limit Exceeded

Wrong Answer

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
L = list(map(int,input().split()))
L.sort()
print(L)
from bisect import bisect_left
ans = 0
for i in range(N):
  for j in range(i+1, N):
    sum = L[i]+L[j]
    count = bisect_left(L, sum)
    ans += max(0, count-j-1)
print(ans)

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

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

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import itertools
N = int(input())
stick = sorted(list(map(int, input().split())), reverse=True)
combi = itertools.combinations(stick, 3)
ans = 0
lst = []
flag = False
for a,b,c in combi:
  if flag and a in lst:
    continue
  elif a <= b+c:
    continue
  else:
    flag = False
  if a < b+c and b < c+a and c < a+b:
    ans += 1
  else:
    flag = True
    lst.append(a)
print(ans)


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

print(answer)


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

print(answer)

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

print(answer)

import time
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
#print(l)
#start = time.time()
res = 0
for i in range(n):
    for j in range(i+1,n):
        ab = l[i] + l[j]
        c_index = bisect_left(l, ab)
        
        res += c_index - j - 1
print(res)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

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

from bisect import bisect_left
N = input()
t_list = list ( map ( int, ipnut().split() ) )
t_list.sort()

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


N = int( input() )
list_t = list( map (int, input().split() )
counter = 0 
a = del list_t[0]
b = del list_t[0:2]
for i in list_t:
	for j in a:
		for k in b:
            if i == (len(list_t) - 3):
              break
            else:
              if i < j + k and j < i + k:
            	if k < i + j:
                	counter += 1
    a = del a[0]
    b = del b[0]

print ( counter )


from bisect import bisect_left
N = input()
t_list = list ( map ( int, input().split() ) )
t_list.sort()

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


from bisect import bisect_left
N = input()
t_list = list ( map ( int, ipnut().split() ) )
t_list.sort()

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

N = int( input() )
list_t = list( map (int, input().split() )
counter = 0 
a = del list_t[0]
b = del list_t[0:2]
for i in list_t:
	for j in a:
		for k in b:
            if i == (len(list_t) - 3)
              break
            else:
              if i < j + k and j < i + k:
            	if k < i + j:
                	counter += 1
    a = del a[0]
    b = del b[0]

print ( counter )

from bisect import bisect_left
N = int ( input() )
t_list = list ( map ( int, input().split() ) )
t_list.sort()
ans = 0

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


Verdicts: Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted