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())
l = [int(i) for i in 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 l[i] > l[j] + l[k]: continue
            if l[j] > l[i] + l[k]: continue
            if l[k] > l[i] + l[j]: continue
            ans += 1
print(ans)

from bisect import bisect_left
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        ans += bisect_left(l, l[i]+l[j]) - 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):
n=int(input())
l=sorted([int(i) for i in input().split()],reverse=True)

ans=0
for i in range(n-2):
    c=l[i]
    x=0
    for j in range(i+1,n-1):
        b=l[j]
        for k in range(j+1,n):
            a=l[k]
            if c<(a+b):
                co+=1
            else:
                if k==j+1:
                    x=1
                break
        if x==1:
            break

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 - 2):
    for j in range(i + 1, N - 1):
        ans += bisect_left(L, L[i] + L[j]) - 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):
import bisect
from typing import List


def solve(ls: List[int]) -> int:
  n = len(ls)
  assert(3 <= n <= 2 * 10**3)

  def n_possible_cs(a: int, b: int, first_ic: int) -> int:
    
    
    #     if ls[s] > target:
    #       return None
    #     else:
    #       return s
    #
    
    #
    #   if ls[mid] <= target and (mid + 1 < n and ls[mid + 1] > target):
    #     return mid
    #   elif ls[mid] <= target:
    
    #   else:
    

    idx = bisect.bisect_left(ls, a + b, first_ic)
    return 0 if idx == first_ic else idx - first_ic

  ret = 0
  for ia in range(0, n - 2):
    for ib in range(ia + 1, n - 1):
      a, b = (ls[ia], ls[ib])
      x = n_possible_cs(a, b, ib + 1)
      ret += x
  return ret


# n = int(input().strip())
# ls = [int(l) for l in input().split()]
#


print(solve(sorted([218, 786, 704, 233, 645, 728, 389])))


import bisect


def solve(ls) -> int:
  n = len(ls)
  assert(3 <= n <= 2 * 10**3)

  def n_possible_cs(a: int, b: int, first_ic: int) -> int:
    
    
    #     if ls[s] > target:
    #       return None
    #     else:
    #       return s
    #
    
    #
    #   if ls[mid] <= target and (mid + 1 < n and ls[mid + 1] > target):
    #     return mid
    #   elif ls[mid] <= target:
    
    #   else:
    

    idx = bisect.bisect_left(ls, a + b, first_ic)
    return 0 if idx == first_ic else idx - first_ic

  ret = 0
  for ia in range(0, n - 2):
    for ib in range(ia + 1, n - 1):
      a, b = (ls[ia], ls[ib])
      x = n_possible_cs(a, b, ib + 1)
      ret += x
  return ret


# n = int(input().strip())
# ls = [int(l) for l in input().split()]
#


print(solve(sorted([218, 786, 704, 233, 645, 728, 389])))


import bisect


def solve(ls) -> int:
  n = len(ls)
  assert(3 <= n <= 2 * 10**3)

  def n_possible_cs(a: int, b: int, first_ic: int) -> int:
    
    
    #     if ls[s] > target:
    #       return None
    #     else:
    #       return s
    #
    
    #
    #   if ls[mid] <= target and (mid + 1 < n and ls[mid + 1] > target):
    #     return mid
    #   elif ls[mid] <= target:
    
    #   else:
    

    idx = bisect.bisect_left(ls, a + b, first_ic)
    return 0 if idx == first_ic else idx - first_ic

  ret = 0
  for ia in range(0, n - 2):
    for ib in range(ia + 1, n - 1):
      a, b = (ls[ia], ls[ib])
      x = n_possible_cs(a, b, ib + 1)
      ret += x
  return ret


n = int(input().strip())
ls = [int(l) for l in input().split()]

print(solve(sorted(ls)))


Verdicts: Runtime Error

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

n = int(input())
l = [int(i) for i in input().split()]
l.sort()
print(l)

count = 0
for i in range(n-3):
    for j in range(i+1, n-2):
        
        left = j+1
        right = n-1
        # print(left, right)
        while left <= right:
            mid = (left + right) // 2
            if l[i] + l[j] > l[mid] and l[j] + l[mid] > l[i] and l[mid] + l[i] > l[j]:
                left = mid + 1
                satisfied = mid
            else:
                right = mid - 1
        # print(j+1, right)
        count += right - j+1

print(count)


# -*- coding: utf-8 -*-

import bisect

n = int(input())
l = [int(i) for i in 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])
        count += index - (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 sys
import heapq


def input():
    return sys.stdin.readline()[:-1]


if __name__ == "__main__":
    N = int(input())
    L = sorted(list(map(int, input().split())), reverse=True)
    cnt = 0
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            for k in range(j+1, N):
                if L[i] < L[j] + L[k]:
                    print(L[i], L[j], L[k])
                    cnt += 1
    print(cnt)


import sys
import bisect


def input():
    return sys.stdin.readline()[:-1]


if __name__ == "__main__":
    N = int(input())
    L = sorted(list(map(int, input().split())))
    cnt = 0
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            b = bisect.bisect_left(L, L[i]+L[j])
            cnt += b-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 bisect
import sys
input = sys.stdin.readline
 
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
cnt = 0
for i in range(n):
  a = l[i]
  for j in range(n-i-1):
    b = l[j+i+1]
    cnt += max(n-i-j-2-bisect.bisect_right(l[j+i+1:], a-b), 0)
print(cnt)

import sys
input = sys.stdin.readline
 
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
 
cnt = 0
for i in range(n):
  a = l[i]
  for j, b in enumerate(l[i+1:]):
    for k, c in enumerate(l[i+j+2:]):
      if a < b+c:
        cnt += n-(i+j+k+2)
        break
print(cnt)

import bisect
import sys
input = sys.stdin.readline
 
n = int(input())
l = [int(li) for li in input().split(' ')]
l.sort()

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

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=sorted(list(map(int,input().split())))

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


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

cnt=0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        p=bisect.bisect_right(l,l[i]+l[j]-1)
        cnt+=p-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())
ll=list(map(int,input().split()))
ll.sort()
ans=0
for i in range(N):
    delta=bisect_left(ll,ll[i]+ll[i+1],lo=i+1)-i-2
    if delta>0:
        ans+=delta
    in_b=delta+i+1+1
    for j in range(i+2,N):
        if in_b!=N:
            delta=bisect_left(ll,ll[i]+ll[j],lo=in_b)-j-1
        else:
            delta=N
        if delta>0:
            ans+=delta
        in_b=delta+j+1
print(ans)

from bisect import bisect_left
N=int(input())
ll=list(map(int,input().split()))
ll.sort()
ans=0
for i in range(N):
    for j in range(i+1,N):
        if j==i+1:
            delta=bisect_left(ll,ll[i]+ll[i+1],lo=i+1)-i-2
            if delta>0:
                ans+=delta
            in_b=delta+i+1+1
        else:
            if in_b!=N:
                delta=bisect_left(ll,ll[i]+ll[j],lo=in_b)-j-1
            else:
                delta=N-j-1
            if delta>0:
                ans+=delta
            in_b=delta+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):

def findnumberofTriangles(arr): 
	n = len(arr) 
	arr.sort() 
	count = 0
	for i in range(0, n-2):  
		k = i + 2 
		for j in range(i + 1, n):  
			while (k < n and arr[i] + arr[j] > arr[k]): 
				k += 1
			if(k>j): 
				count += k - j - 1

	return count 

n = int(input())
arr=[int(x) for x in input().split()]
print(findnumberoftriangles(arr))




def findnumberofTriangles(arr): 
	n = len(arr) 
	arr.sort() 
	count = 0
	for i in range(0, n-2):  
		k = i + 2 
		for j in range(i + 1, n):  
			while (k < n and arr[i] + arr[j] > arr[k]): 
				k += 1
			if(k>j): 
				count += k - j - 1

	return count 

n = int(input())
arr=[int(x) for x in input().split()]
print(findnumberofTriangles(arr))



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 bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()

cnt = 0

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




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

cnt = 0

for i in range(n - 1, 0, -1):
    for j in range(i - 1, -1, -1):
        base = l[i] - l[j]
        idx = bisect.bisect_right(l, base)
        cnt += max(j - idx, 0)
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):
# -*- coding: utf-8 -*-

n = int(input())
l = sorted(list(map(int, input().split(' '))), reverse = True)
print(l)

ans = 0
for ai in range(len(l)-2):
    a = l[ai]
    for bj in range(ai+1, len(l)-1):
        b = l[bj]
        for ck in range(bj+1, len(l)):
            c = l[ck]
            if a < b+c:
                ans += 1
            else:
                break

print(ans)

# -*- coding: utf-8 -*-
from bisect import bisect_left

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

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        a = l[i]
        b = l[j]
        ab = a+b
        idx = bisect_left(l, ab)

        # b < c < idx
        ans += max(0, 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())
L = [int(_) for _ in input().split()]
L.sort()

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


import bisect

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

ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        r = L[i] + L[j]
        
        ri = bisect.bisect_left(L, r)
        ans += ri - 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):
N=int(input())
Edges = list(map(int,input().split()))

Edges=sorted(Edges)
cnt =0

#     e1=(i[1] + i[2])
#     e2=(i[0] + i[2])
#     e3=(i[0] + i[1])

#     if i[0] < e1 and i[1] < e2 and i[2] < e3:
#         cnt+=1
print(Edges)

import bisect

for a in range(N-2):
    for b in range(a+1,N-1):
        ab = Edges[a] + Edges[b]

        idx = bisect.bisect_left(Edges,ab)

        cnt += max(0,idx-b-1)


print(cnt)

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

Edges=sorted(Edges)
cnt =0

#     e1=(i[1] + i[2])
#     e2=(i[0] + i[2])
#     e3=(i[0] + i[1])

#     if i[0] < e1 and i[1] < e2 and i[2] < e3:
#         cnt+=1


import bisect

for a in range(N-2):
    for b in range(a+1,N-1):
        ab = Edges[a] + Edges[b]

        idx = bisect.bisect_left(Edges,ab)

        cnt += max(0,idx-b-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 enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

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

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 and B < C + A and C < A + B:
                ans += 1
                print(A,B,C)

print(ans)


from enum import Enum
from queue import Queue
import collections
import bisect

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

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

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

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):
n = int(input())
l_list = list(int(i) for i in input().split())
list.sort(l_list, reverse=True)
count = 0
for i in range(n):
    a = l_list[i]
    for j in range(i+1, n):
        b = l_list[j]
        for k in range(j+1, n):
            c = l_list[k]
            print(a, b, c)
            if a < b+c and b < c+a and c < a+b:
                count += 1
print(count)


import bisect

n = int(input())
l = list(int(i) for i in input().split())
list.sort(l)
count = 0

for i in range(n):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        ab = a + b
        index_c = bisect.bisect_left(l, ab)
        count += index_c - 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):
from bisect import bisect_left
n=int(input())
l=sorted(list(map(int,input().split())))
ans=0
for i in range(n):
    for j in range(i+1,n):
        r =bisect_left(L,L[i]+L[j])
        ans+=max(r-j-1),0
print(ans)

n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(1,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:
                print(ans)
print(ans)

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

Verdicts: Runtime Error

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
import copy



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

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

L.sort()
ans = 0

for i in range(0,n-2):
    j = i+1
    k = j+1
    while j<n-1:
        while(k<n):
            if (L[j]-L[i]<L[k] and L[k]<L[i]+L[j]):
                k+=1
            else:
                break
        ans += k-(j+1)
        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):
n = int(input())
l = [x for x in map(int, input().split())]

cnt = 0
for i in range(0, n):
    a = l[i]
    if i < len(l) - 1:
        b = l[i + 1]
    else:
        b = l[0]
    for j in range(0, n):
        if l[j] == a or l[j] == b:
            pass
        else:
            c = l[j]

            if a < b + c and b < c + a and c < a + b:
                cnt += 1
            else:
                continue
print(cnt)


n = int(input())
l = [x for x in map(int, input().split())]
l = sorted(l)

cnt = 0
for i in range(n - 2):
    a = l[i]
    k = i + 2
    for j in range(i + 1, n - 1):
        b = l[j]
        while(l[k] < a + b):
            k += 1
            if k == n:
                break
            else:
                pass

        k -= 1
        cnt += k - j
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 bisect

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):
        ans += bisect.bisect_left(L,L[i]+L[j]-1) - L.index(L[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):
        ans += bisect.bisect_left(L,L[i]+L[j]) - (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 = [int(i) for i in input().split()]
L.sort(reverse=True)
ans = 0
P = []
for i in range(N-1):
    for j in range(i+1,N):
        P.append(L[i]+L[j])
now = 0
ans = 0
for i in range(N-2):
    now += N - (i + 1)
    A = P[now:]
    A.sort()
    index = insert_index = bisect.bisect_left(A,L[i])
    ans += (len(A) - index)
print(ans)


import bisect
N = int(input())
L = [int(i) for i in input().split()]
L.sort(reverse=True)
ans = 0
P = []
for i in range(N-1):
    for j in range(i+1,N):
        P.append(L[i]+L[j])
P.sort()
now = 0
ans = 0
for i in range(N-2):
    now += N - (i + 1)
    index = bisect.bisect_left(P,L[i]+0.1)
    ans += (len(P) - index)-now
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):
N = int(input())
L = list(map(int, input().split()))
ans = 0

#  for j in range(i + 1, N):
#    for k in range(j + 1, N):
#      #print(str(i) + str(j) + str(k))
#      if L[i] < L[j] + L[k] and L[j] < L[k] + L[i] and L[k] < L[i] + L[j]:
#        ans += 1
#print(ans)
comb = list(itertools.combinations(L, 3))
print(comb)



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: 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())
d = list(map(int, input().split()))
d.sort()

m = 0

for a in range(n-2):
	for b in range(a+1,n-1):
		m+=bisect.bisect_left(d,d[a]+d[b])-1-j

print(m)

n = int(input())

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

d.sort()

m = 0

for a in range(n-2):
	for b in range(a+1,n-1):
		for c in range(b+1,n):
			if d[c]<d[b]+d[a]:
				m += 1
				if d[c]==d[a]:
				m -= 1
			else:
				break

print(m)

n = int(input())

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

d.sort()

m = 0

for a in range(n-2):
	for b in range(a+1,n-1):
		for c in range(b+1,n):
			if d[c]<d[b]+d[a]:
				m += 1
				if d[c]==d[a]:
				m -= 1
			else:
				break

print(m)

n = int(input())

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

d.sort()

m = 0

for a in range(n-2):
	for b in range(a+1,n-1):
		for c in range(b+1,n):
			if d[c]<d[b]+d[a]:
				m += 1
				if d[c]==d[a]:
                  m -= 1
			else:
				break

print(m)

import bisect

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

m = 0

for a in range(n-2):
	for b in range(a+1,n-1):
		m+=bisect.bisect_left(d,d[a]+d[b])-1-b

print(m)

Verdicts: Runtime Error

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

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

Llist.sort()

print(Llist)
count = 0

for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            
            if Llist[k] < Llist[i] + Llist[j]:
                if Llist[j] < Llist[i] + Llist[k] and Llist[i] < Llist[j] + Llist[k]:
                    count += 1
            else:
                break

print(count)

import bisect

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

Llist.sort()
print(Llist)

count = 0

for i in range(n-2):
    p = Llist[i]
    for j in range(i+1,n-1):
        q = Llist[j]
        print(count,p,q)
        k = bisect.bisect_left(Llist, p+q)
        count += (k-j-1)

print(count)

import bisect

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

Llist.sort()

count = 0

for i in range(n-2):
    p = Llist[i]
    for j in range(i+1,n-1):
        q = Llist[j]
        k = bisect.bisect_left(Llist, p+q)
        count += (k-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):
# -*- coding: utf-8 -*-
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(j+1,N):
            if L[k] >= L[i] +L[j]:
                if L[i] < L[j] +L[k]:
                    if L[j] < L[k] + L[i]:
                        count += 1
                    else:
                        break
                else:
                    break
            else: 
                break
                
print(count)

# -*- coding: utf-8 -*-
import bisect

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

count = 0
L.sort()
for i in range(N-2):
    for j in range(i+1,N-1):
        k = bisect.bisect_left(L,L[i]+L[j])
        count += k - 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 sys
N = int(input())
L = [i for i in map(int, input().split())]
ans = 0

L.sort()
print(L)
if N == 3:
    if L[0] + L[1] > L[2]:
        print("1")
        sys.exit()

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]:
                ans += 1
                #print(L[i], L[j], L[k])
            else:
                #print("break")
                break
print(ans)

import sys
import bisect
N = int(input())
L = [i for i in map(int, input().split())]
ans = 0

L.sort()
#print(L)
if N == 3:
    if L[0] + L[1] > L[2]:
        print("1")
        sys.exit()

for i in range(len(L)-2):
    for j in range(i+1,len(L)-1):
        index = bisect.bisect_right(L,L[i]+L[j],j+1)
        ans += (index - 1) - (j + 1) + 1
print(ans)

import sys
import bisect
N = int(input())
L = [i for i in map(int, input().split())]
ans = 0

L.sort()
#print(L)
if N == 3:
    if L[0] + L[1] > L[2]:
        print("1")
        sys.exit()

for i in range(len(L)-2):
    for j in range(i+1,len(L)-1):
        index = bisect.bisect_right(L,L[i]+L[j],j+1,len(L))
        ans += (index - 1) - (j + 1) + 1
print(ans)

import sys
import bisect
N = int(input())
L = [i for i in map(int, input().split())]
ans = 0

L.sort()
#print(L)
if N == 3:
    if L[0] + L[1] > L[2]:
        print("1")
        sys.exit()

for i in range(len(L)-2):
    for j in range(i+1,len(L)-1):
        index = bisect.bisect_left(L,L[i]+L[j],j+1)
        #print(index)
        ans += index  - (j + 1) 
print(ans)

Verdicts: 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())
l=sorted(list(map(int,input().split())))
import bisect
count=0
for i in range(n-1):
  for j in range(i+1,n):
    left=bisect.bisect_right(l,abs(l[i]-l[j]))
    right=bisect.bisect_left(l,l[i]+l[j])
    count+=right-left
print(count)                             

n=int(input())
l=sorted(list(map(int,input().split())))
count=0
def nibutan(s,g,num):
  while True:
    low=s
    high=g-1
    mid=(low+high)/2
    num1=l[mid]
    if num<=l[mid] and l[mid-1]<num:
      return mid
    elif l[mid-1]>num:
      low=mid+1
    elif l[mid]<num:
      high=mid-1
    else:
      return mid-1    
for i in range(n-2):
  for j in range(i+1,n-1):
    if l[i]+l[j]<=l[n-1]:
      pass
    else:
      

n=int(input())
l=sorted(list(map(int,input().split())))
import bisect
count=0
for i in range(n-1):
  for j in range(1,n):
    if i==j:
      pass
    else:
      left=bisect.bisect_right(l,abs(l[i]-l[j]))
      right=bisect.bisect_left(l,l[i]+l[j])
      count+=right-left
print(count)                             


n=int(input())
l=sorted(list(map(int,input().split())))
import bisect
count=0
for i in range(n-1):
  for j in range(1,n):
    if i==j:
      pass
    else:
      left=bisect.bisect_left(abs(l[i]-l[j]))
      right=bisect.bisect_right(l[i]+l[j])
      count+=right-left
print(count)                             

n=int(input())
l=sorted(list(map(int,input().split())))
import bisect
count=0
for i in range(n-1):
  for j in range(1,n):
    if i==j:
      pass
    else:
      left=bisect.bisect_left(l,abs(l[i]-l[j]))
      right=bisect.bisect_right(l,l[i]+l[j])
      count+=right-left
print(count)                             


import bisect
n=int(input())
l=sorted(list(map(int,input().split())))
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])
    count+=index-j-1
print(count)

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

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()
c=0
print(l)
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      print(i,j,k)
      if l[i]+l[j]>l[k] and l[j]+l[k]>l[i] and l[k]+l[i]>l[j]:
        c+=1
      elif l[i]+l[j]<=l[k]:
        break
print(c)

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

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 itertools   # accumulate, compress, permutations(nPr), combinations(nCr)


# import heapq

# from fractions import Fraction

# --------------------------------------------------------------

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

cnt = 0

wa = []
sa = []

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

lwa = len(wa)

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

print(cnt)

import itertools   # accumulate, compress, permutations(nPr), combinations(nCr)
import bisect      

# import heapq

# from fractions import Fraction

# --------------------------------------------------------------

n  = int(input())
bo = list(map(int,input().split()))
 
cnt = 0
bo.sort()
 
for a in range(n-1):
    for b in range(a+1,n):
        cnt += bisect.bisect_left(bo, bo[a]+bo[b]) - (b+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 = list(map(int, input().split()))

L_list = sorted(L_list)

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

print(count)

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

L_list = sorted(L_list)

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

print(count)

import bisect

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

L_list = sorted(L_list)

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

print(total)

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

import bisect
n=int(input())
l=list(map(int,input().split()))
l.sort()
cnt=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)
    cnt+=(k-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(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)


from bisect import bisect_left

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

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


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(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: Runtime Error

Runtime Error

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_right, bisect_left
n = int(input())
l = list(map(int, input().split()))
count = 0
l.sort()
for i in range(n-2):
    for j in range(i+1, n-1):
        count += bisect_left(l, l[i]+l[j]+1) -j -1
print(count)

from bisect import bisect_right, bisect_left
n = int(input())
l = list(map(int, input().split()))
count = 0
l.sort()
for i in range(n-2):
    for j in range(i+1, n-1):
        count += bisect_left(l, l[i]+l[j]) -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()))

ans = 0

l.sort()
print(l)

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

        ans += max(0, index-j-1)

print(ans)

import bisect

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

ans = 0

l.sort()

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

        ans += max(0, index-j-1)

print(ans)

import bisect

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

ans = 0

l.sort()

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

        ans += max(0, index-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 bisect
N=int(input())
L=map(int,input().split())
l=list(L)
result=0
for i in range(0,N):
  for j in range(i+1,N):
    result += bisect.bisect_left(l,l[i]+l[j])-1-j

print(result)

N=int(input())
L=map(int,input().split())
l=list(L)
result=0
for i in range(0,len(l)-1):
  for j in range(0,len(l)-1):
    for k in range(0,len(l)-1):
      if l[i]>(l[j]+l[k]):
        result+=1

print(result)

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

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

print(result)

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 bisect import bisect_left
N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0
for b in range(N):
    for a in range(b):
        print()
        ab = L[a] + L[b]
        r = bisect_left(L, ab)
        cnt += r - (b + 1) 
print(cnt)

from bisect import bisect_left
N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0
for b in range(N):
    for a in range(b):
        ab = L[a] + L[b]
        r = bisect_left(L, ab)
        cnt += r - (b + 1) 
print(cnt)

Verdicts: Time Limit Exceeded

Accepted