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):
from copy import copy
from collections import deque
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()
first = deque(L)
count = 0
for i in range(N-2):
    l = first.pop()
    second = copy(first)
    for j in range(1,N-i-1):
        m = second.pop()
        n = len(second) - bisect.bisect_left(second,l-m)
        if n > 0:
            count += n
        else:
            break
print(count)

from copy import copy
from collections import deque
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()
first = deque(L)
count = 0
for i in range(N-2):
    l = first.pop()
    second = copy(first)
    for j in range(1,N-i-1):
        m = second.pop()
        n = len(second) - bisect.bisect_right(second,l-m)
        if n > 0:
            count += n
        else:
            break
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 numpy as np
from numba import njit

def f(A):
  N = len(A)
  cnt = 0
  for i in range(N):
    for j in range(i + 1, N):
      for k in range(j + 1, N):
        cnt += (A[k] > A[i] + A[j])
  return cnt

def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('f', '(i4[::1],)')(f)
    cc.compile()

if sys.argv[-1] == 'ONLINE_JUDGE':
  cc_export()
  exit()
from my_module import f

N = int(input())
A = np.array(input().split(), np.int32)
A.sort()
print(f(A))


import numpy as np
from numba import njit

@njit
def f(A):
  N = len(A)
  cnt = 0
  for i in range(N):
    for j in range(i + 1, N):
      for k in range(j + 1, N):
        cnt += (A[k] < A[i] + A[j])
  return cnt

N = int(input())
A = np.int32(input().split())
A.sort()
print(f(A))


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

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

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_sorted =sorted(L,reverse=True)


from itertools import combinations
count =0
for i in range(N-2): 
    for j in range(N-2):
        for k in range(j+1,N-1):
            if L_sorted[j*(-1)] + L_sorted[k*(-1)] < L_sorted[i]:
                count +=1
            else:
                break

from math import factorial
N_3_all =factorial(N) // (factorial(N - 3) * factorial(3))

kotae =N_3_all -count
print(kotae)



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



import bisect

count =0
for i in range(0,N-1): 
    for j in range(i+1,N):
        x =L_sorted[i] + L_sorted[j]
        index =bisect.bisect_left(L_sorted,x)
        a=1
        #count.append(index -j-a)
        count += max(0,index -j-a)
        

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

l.sort()
ans_set = set()

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

print(len(ans_set))

import bisect

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

l.sort()
ans_set = set()
ans = 0

for i in range(n):
    if i + 1 == n:
        break
    for j in range(i+1, n):
        ans += max(bisect.bisect_left(l, l[i]+l[j]) - 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 sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

input = sys.stdin.readline


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

    max_l = max(L)

    ans = 0

    for a in range(N):

        for b in range(a+1, N):
            if L[a] >= L[b] + max_l:
                continue

            for c in range(b+1, N):
                if L[a] < L[b] + L[c] and L[b] < L[c] + L[a] and L[c] < L[a] + L[b]:
                    ans += 1
                else:
                    break

    print(ans)

import sys
import bisect
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce, reduce
sys.setrecursionlimit(20000000)

input = sys.stdin.readline


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

    ans = 0

    for a in range(N):

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

            ans += i - b

    print(ans)


if __name__ == '__main__':
    main()

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 = sorted([int(li) for li in input().split()])

sum = 0
for i in range(n-1,-1,-1):
    for j in range(i-1,-1,-1):
        k = bisect.bisect_right(l[j],l[i]-l[j])
        sum += j-k if j>k else 0

print(sum)


import bisect

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

sum = 0
for i in range(n-1,-1,-1):
    for j in range(i-1,-1,-1):
        k = bisect.bisect_right(l,l[i]-l[j])
        sum += j-k if j>k else 0

print(sum)


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)
wa = 0
for i in range(N):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if(L[i] < L[j]+L[k]):
                wa += N-k
                break
            
print(wa)

N = int(input())
L = list(map(int, input().split()))
L.sort()
wa = 0
import bisect
for i in range(N-1,1,-1):
    for j in range(i-1,0,-1):
        diff = L[i]-L[j]
        k = bisect.bisect_right(L, diff)
        wa += j-k if j-k > 0 else 0           
            
print(wa)

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(reverse=True)

print(L)
for i in range(N):
    L[i] *= -1
count = 0
for i in range(N-2):
    #print(i)
    for j in range(i+1, N-1):
        if -L[i] >= -L[j] * 2:
            break
        data = L[i] - L[j]
        #print(data, L[j + 1 : N])
        
        count += bisect.bisect_left(L[j + 1 : N], data)

print(count)

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

L.sort(reverse=True)

#print(L)
for i in range(N):
    L[i] *= -1
count = 0
for i in range(N-2):
    #print(i)
    for j in range(i+1, N-1):
        if -L[i] >= -L[j] * 2:
            break
        data = L[i] - L[j]
        #print(data, L[j + 1 : N])
        
        count += bisect.bisect_left(L, data) - (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 = sorted(map(int, input().split()))
ans = 0
for i in range(n):
    a = L[i]
    for j in range(i+1, n):
        b = L[j]
        k = bisect.bisect_left(L, a+b)
        print(i, j, k)
        if L[k-1] > b:
            ans += k - j - 1
print(ans)


import bisect

n = int(input())
L = sorted(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]
        l = bisect.bisect_left(L[j+1:n], a+b-1)
        ans += l
print(ans)


import bisect

n = int(input())
L = sorted(map(int, input().split()))
ans = 0
for i in range(n):
    a = L[i]
    for j in range(i+1, n):
        b = L[j]
        k = bisect.bisect_left(L, a+b)
        if k > j:
            ans += k - 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):
N=int(input())
L=list(map(int,input().split()))
i=0
L=sorted(L)
for a in range(N):
  for b in range(a+1,N):
    c=bisect.bisect_left(L,L[a]+L[b])
    if c>b:
      i+=c-b
    else:
      i=i
print(i)

import bisect
N=int(input())
L=list(map(int,input().split()))
i=0
L=sorted(L)
for a in range(N):
  for b in range(a+1,N):
    c=bisect.bisect_left(L,L[a]+L[b])
    if c>b:
      i+=c-b
    else:
      i=i
print(i)

import bisect
N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
ans=0
for a in range(N):
  for b in range(a+1,N)):
    c=bisect.bisect_left(L,L[a]+L[b])
    if c>b:
      ans+=c-b-1
    else:
      ans=ans
print(ans)
      
    

import bisect
N=int(input())
L=list(map(int,input().split()))
i=0
L=sorted(L)
for a in range(N):
  for b in range(a+1,N):
    c=bisect.bisect_left(L,L[a]+L[b])
    if c>b:
      i+=c-b-1
    else:
      i=i
print(i)

Verdicts: Runtime Error

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):
#!/usr/bin/env python3

import bisect


def solve(N, L):
    L = sorted(L)
    llen = len(L)
    ans = 0
    for i in range(llen):
        for j in range(i+1, llen):
            n = bisect.bisect_right(L, L[i]+L[j], j+1) - (j+1)
            ans += n
    return ans


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

    ans = solve(N, L)

    print(ans)


#!/usr/bin/env python3

import bisect


def solve(N, L):
    L = sorted(L)
    llen = len(L)
    # print(L)
    ans = 0
    for i in range(llen):
        for j in range(i+1, llen):
            k = bisect.bisect_left(L, L[i]+L[j], j+1)
            n = k - (j+1)
            # print(i, j, k, n)
            ans += n
    return ans


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

    ans = solve(N, L)

    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 i in range(n-2):
  for j in range(i+1, n):
    for k in range(j+1, n):
      if i<j+k and j<k+i and k<i+j:
        ans += 1
print(ans)

from bisect import bisect_left

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

l.sort()
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)

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

from bisect import bisect_left

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

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


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

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


from bisect import bisect_left

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


Verdicts: Time Limit Exceeded

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()
count = 0
for a in range(n-2):
  for b in range(a+1,n-1):
    count += bisect_left(L, L[a]+L[b]) - b - 1

print(count)

from bisect import bisect_left
n=int(input())
L=list(map(int, input().split()))
L.sort()
count = 0
for a in range(n-2):
  for b in range(a+1,n-1):
    count += bisect_left(L, L[a]+L[b]) - b - 1

print(count)


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 math

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

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

import bisect

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

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

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


# c > b >a
for i in range(0, N-2):
  for j in range(i+1, N-1):
    index = bisect.bisect_left(L, L[i]+L[j])
    count += max(0, index-(j+1))

import bisect

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


# c > b >a
count = 0
for i in range(0, N-2):
  for j in range(i+1, N-1):
    index = bisect.bisect_left(L, L[i]+L[j])
    count += max(0, index-(j+1))

import bisect

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


# c > b >a
count = 0
for i in range(0, N-2):
  for j in range(i+1, N-1):
    index = bisect.bisect_left(L, L[i]+L[j])
    count += max(0, index-(j+1))
print(count)

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):
def main():
    n = int(input())
    l = sorted(list(map(int, input().split())), reverse=True)
    count = 0
    for i in range(n-2):
        a = l[i]
        for j in range(i+1,n-1):
            b = l[j]
            x = a-b
            z = a+b
            for k in range(j+1, n):
                c = l[k]
                if x >= c:
                    break
                if z > c:
                    count += n-k
                    break
    print(count)
    
if __name__ == "__main__":
    main()

import bisect

def main():
    n = int(input())
    l = sorted(list(map(int, input().split())))
    count = 0
    for i in range(n-2):
        a = l[i]
        for j in range(i+1, n-1):
            b = l[j]
            kmax = bisect.bisect_left(l, a+b)
            #print("k", kmax, "j", j, "k-j", kmax-(j+1), a, b)
            count += max(kmax-(j+1),0)
    print(count)
    
if __name__ == "__main__":
    main()

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 - 2):
    if L[i] + L[i + 1] <= L[i + 2]:
        break
    for j in range(i + 1, N - 1):
        if L[i] + L[j] <= L[j + 1]:
            break
        for k in range(j + 1, N):
            if L[i] + L[j] <= L[k]:
                break
            ans += 1
print(ans)


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):
        index = bisect.bisect_left(L, L[i] + L[j])
        ans += max(0, index - 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())
arr=list(map(int,input().split()))
arr=sorted(arr)
ans=0
for i in range(n):
  a=arr[i]
  for j in range(i+1,n):
    b=arr[j]
    tmp=a+b
    pos=bisect.bisect_left(arr,tmp)-1
    if pos<=j:
      continue
    else:
      ans+=(pos-j)
print(ans)

import bisect

n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr)
ans=0
for i in range(n):
  a=arr[i]
  for j in range(i+1,n):
    b=arr[j]
    tmp=a+b
    pos=bisect.bisect_left(arr,tmp)-1
    if pos<=j:
      continue
    else:
      ans+=(pos-j)
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):

# a < b < c & c < a + b

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

print(L)

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



# a < b < c & c < a + b

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

for i in range(N):
    for j in range(i+1,N):
        t = L[i] + L[j]
        idx = bisect.bisect_left(L,t)
        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):
#!/usr/bin/env python3
import sys
import numpy as np

def solve(N: int, L: "List[int]"):
    L = np.array(sorted(L))
    ct = 0
    for a in range(len(L)-2):
        for b in range(a, len(L)-1):
            ct+=((L[b] < L) & (L < L[a+b])).sum() 
    print(ct)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, L)

if __name__ == '__main__':
    main()


#!/usr/bin/env python3
import sys
# import numpy as np
import bisect

def solve(N: int, L: "List[int]"):
    L = sorted(L)
    ct = 0
    for a in range(len(L)-2):
        a_ = L[a]
        for b in range(a+1, len(L)-1):
            b_in = bisect.bisect_left(L,a_+L[b]) - b -1
            if b_in > 0:
                ct+=b_in

            # print("L :{} a+Lb :{}  b_in:{}".format(L[b+1:],a_+L[b],ct))
        # ct += sum([bisect.bisect_left(L[b+1:],a_+L[b]) for b in range(a+1, len(L)-1)])
    print(ct)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, L)

if __name__ == '__main__':
    main()


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

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


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


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):
def binary_search(x, li, value):
  l = []
  left = x+1
  y = x
  right = len(li) - 1
  while left <= right:
    mid = (left + right) // 2
    if li[mid] > value - 1:
      right = mid - 1
    elif li[mid] < value - 1:
      y = mid
      left = mid + 1
    else:
      for i in range(1, 1000):
        if li[mid] == li[mid + i]:
          y = mid + i
        else:
          y = mid
          break
  return y
  
N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    cnt += binary_search(j, L, L[i]+L[j]) - j
print(cnt)

from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    cnt += bisect_left(L, L[i] + L[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):
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):
        ans += bisect_left(l.,l[i]+l[j])-(j+1)
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):
        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):
N = int(input())
L = list(map(int, input().split()))
L.sort()
from itertools import combinations
from numba import njit


@njit
def solve():
    ans = 0
    for a, b, c in combinations(L, r=3):
        ans += a + b > c
    return ans


print(solve())


N = int(input())
L = list(map(int, input().split()))
L.sort()
from numba import njit, jit
from itertools import combinations


# @jit

#     ans = 0
#     for a, b, c in combinations(L, r=3):
#         ans += a + b > c
#     return ans

@njit
def solve(L):
    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):
                ans += a + b > L[k]
    return ans


print(solve(L))


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

ans = 0
for i in range(N-1):
  k = li[i]
  for j in range(i+1, N):
    l = li[j]
    tmp = bisect_left(li, k+l)
    ans += tmp - i -1
    
    
print(ans)

import bisect

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

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

import bisect

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

ans = 0
for i in range(N-1):
  k = li[i]
  for j in range(i+1, N):
    l = li[j]
    tmp = bisect_left(li, k+l)
    ans += tmp - j -1
    
    
print(ans)


import bisect

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

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


Verdicts: Runtime Error

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


C = [0]*(2100)
for l in L:
    C[l] += 1


S = [0]
for i in range(2100):
    S.append(S[i]+C[i])

ans = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue

        left = abs(L[i]-L[j])
        right = L[i]+L[j]
        tmp = S[right]-S[left]

        if left <= L[i] <= right:
            tmp -= 1
        if left <= L[j] <= right:
            tmp -= 1
        ans += max(0, tmp)

print(ans//6)


import numpy as np

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

C = np.bincount(L,minlength=2010)
S = np.cumsum(C)


# C = [0]*(2010)
# for l in L:
#     C[l] += 1


# S = [0]

#     S.append(S[i]+C[i])

ans = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue

        left = abs(L[i]-L[j])+1
        right = L[i]+L[j]
        tmp = S[right]-S[left]

        if left <= L[i] <= right:
            tmp -= 1
        if left <= L[j] <= right:
            tmp -= 1
        ans += max(0, tmp)

print(ans//6)


import bisect

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

L.sort()
ans = 0
for i in range(N-1):
    for j in range(i+1, N-1):
        idx = bisect.bisect_left(L, L[i]+L[j])
        ans += max(0, idx-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):
from itertools import combinations
n = int(input())
l_ls = list(map(int, input().split()))
l_ls.sort()

def isOK(index, key, l):
    if l[index] >= key:
        return True
    else:
        return False
def meguru_search(l, key):
    
    left = -1
    right = len(l)

    while (right - left) > 1:
        mid = left + (right - left) // 2
        
            
                
            
        if isOK(mid, key, l):
            right = mid
        else:
            left = mid
    
    
    return right

count = 0
for a,b in combinations(l_ls,2):
    diff = abs(a-b)
    Sum = a + b
    Max = Sum - 1
    Min = diff + 1
    maxind = meguru_search(l_ls, Max)
    minind = meguru_search(l_ls, Min)
    count += maxind - minind + 1
    if a > diff and a < Sum:
            count -= 1
    if b > diff and a < Sum:
            count -= 1
print(count)

n = int(input())
a_ls = list(map(int, input().split()))
def isOK(a,b,c):
    return abs(a-b) < c < a+b
a_ls.sort()
ans = 0
for i in range(n):
    short = a_ls[i]
    r = i+1
    num = 0
    for l in range(i+1,n-1):
        while r+1 < n and isOK(short, a_ls[l], a_ls[r+1]):
            r += 1
        num += r - l
        if l == r:
            r += 1
    ans += num
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 sys
input=sys.stdin.readline
n = int(input())
#S = input()[:-1]
#N,M = map(int,input().split())
#S,T = map(str,input().split())
A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
d = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            a = A[i]
            b = A[j]
            c = A[k]
            if c < a+b:
                d += 1
print(d)

import sys
input=sys.stdin.readline
from bisect import insort_left
N = int(input())
#S = input()[:-1]
#N,M = map(int,input().split())
#S,T = map(str,input().split())
A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
d = 0
for i in range(N-1):
    for j in range(i+1,N):
        s = A[i]+A[j]
        dex = insort_left(A,s)
        
        d = d + dex - j-1
print(d)

import sys
input=sys.stdin.readline
N = int(input())
#S = input()[:-1]
#N,M = map(int,input().split())
#S,T = map(str,input().split())
A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
def binary_search(S,key,flag): 
    left  = 0
    right = N
    while left < right:
        mid = (left+right) // 2
        if S[mid] == key:
            flag = 1
            return mid
        elif S[mid] > key:
            right = mid
        else:
            left = mid + 1
    return left-1
d = 0
flag = 0
A.sort()
for i in range(N-1):
    for j in range(i+1,N):
        s = A[i]+A[j]
        dex = binary_search(A,s,flag)
        if flag == 0:
          d = d + dex - j
        else:
          while A[dex] == s:
            dex -= 1
          d = d + dex - j
print(d)

import sys
input=sys.stdin.readline
from bisect import bisect_left
N = int(input())
#S = input()[:-1]
#N,M = map(int,input().split())
#S,T = map(str,input().split())
A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
d = 0
A.sort()
for i in range(N-2):
    for j in range(i+1,N-1):
        s = A[i]+A[j]
        dex = bisect_left(A,s)
        if dex > j:
          d += dex -j -1
print(d)

Verdicts: 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):
n = int(input())
l = [int(i) for i in input().split(" ")]

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

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

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

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

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

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

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

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()
print(L)
c=N-1
ans=0
while c>1:
  for i in range(c):
    for j in range(i+1,c):
      if L[c]<L[i]+L[j]:
        ans+=c-j
        break

  c-=1
print(ans)

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

L.sort()
ans=0
i=0
while i<N-2:
    j=i+1
    k=j+1
    while j<N-1:
        while k<N:
            if L[i]+L[j]<=L[k]:
                ans+=k-j-1
                break
            k+=1
        if k==N:
            ans+=k-1-j
        j+=1
    i+=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 math
import itertools
 
n = int(input())
a = list(map(int,input().split()))
a.sort()

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

print(ans) 
            

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

ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        index = bisect.bisect_left(a,a[i]+a[j])
        ans += index-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()))
ans = 0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1, n):
            print(l[i], l[j], l[k])
            if ((l[i] + l[j]) > l[k]) & ((l[j]+l[k]) > l[i]) & ((l[k]+l[i]) > l[j]):
                ans += 1 
print(ans)

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

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):
        ans+=bisect.bisect_left(l, l[i] + l[j]) - 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):
N = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
for i in range(len(L)-1):
    for j in range(i+1,len(L)-1):
        a = L[i]
        b = L[j]
        c = L[j+1]
        if c-a < b and b < c+a:
            ans += bisect.bisect_left(L,b+a)-j-1
print(ans)

import bisect
N = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
for i in range(len(L)-1):
    for j in range(i+1,len(L)-1):
        a = L[i]
        b = L[j]
        c = L[j+1]
        if c-a < b and b < c+a:
            ans += bisect.bisect_left(L,b+a)-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 as bi
n = int(input())
l = list(map(int,input().split()))
l.sort()
#print(l)
ans = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    ans += (bi.bisect_right(l,l[i]+l[j]))-j-1
    
    #print(ans)
print(ans)

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

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

Verdicts: Wrong Answer

Wrong Answer

Accepted