Problem:


Score : 400 points

Problem Statement

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

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

a < b + c

b < c + a

c < a + b

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

Constraints

All values in input are integers.

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

1 \leq L_i \leq 10^3

Input

Input is given from Standard Input in the following format:

N
L_1 L_2 ... L_N

Constraints

Print the number of different triangles that can be formed.

Sample Input 1

4
3 4 2 1

Sample Output 1

1

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

Sample Input 2

3
1 1000 1

Sample Output 2

0

No triangles can be formed.

Sample Input 3

7
218 786 704 233 645 728 389

Sample Output 3

23



Sample input:
4
3 4 2 1


Sample output:
1

Submission status: Wrong Answer

Solution code:
# coding: utf-8
def binary_search(x, L2):
    l, r = 0, len(L2)-1
    mid = (r + l) // 2
    while r - l > 1:
        mid = (r + l) // 2
        if L2[mid] == x:
            return mid
        elif L2[mid] > x:
            l = mid
        elif L2[mid] < x:
            r = mid
    if L2[r] > c:
        return r
    else:
        return l
    # return r

N = int(input())
L = list(map(int, input().split()))
L.sort()
L = L[::-1]
ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        c = a - b
        r = binary_search(c, L)
        if r >= j and L[r] > c and L[r] < L[j]:
            ans += r - j
        elif a == b == L[r]:
            ans += r - j
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
def binary_search(x, L2):
    l, r = 0, len(L2)-1
    mid = (r + l) // 2
    while r - l > 1:
        mid = (r + l) // 2
        if L2[mid] == x:
            return mid
        elif L2[mid] > x:
            l = mid
        elif L2[mid] < x:
            r = mid
    if L2[r] > c:
        return r
    else:
        return l
    # return r

N = int(input())
L = list(map(int, input().split()))
L.sort()
L = L[::-1]
ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        c = a - b
        r = binary_search(c, L)
        if r >= j and L[r] > c and L[r] < L[j]:
            ans += r - j
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
def binary_search(x, L2):
    l, r = 0, len(L2)-1
    mid = (r + l) // 2
    while r - l > 1:
        mid = (r + l) // 2
        if L2[mid] == x:
            break
        elif L2[mid] > x:
            l = mid
        elif L2[mid] < x:
            r = mid
    if L2[mid] == c:
        return mid - 1
    elif L2[r] > c:
        return r
    else:
        return l
    # return r

N = int(input())
L = list(map(int, input().split()))
L.sort()
L = L[::-1]
ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        c = a - b
        r = binary_search(c, L)
        if r >= j and L[r] > c and L[r] < L[j]:
            ans += r - j
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
def binary_search(x, L2):
    l, r = 0, len(L2)-1
    mid = (r + l) // 2
    while r - l > 1:
        mid = (r + l) // 2
        if L2[mid] == x:
            break
        elif L2[mid] > x:
            l = mid
        elif L2[mid] < x:
            r = mid
    if L2[mid] == c:
        return mid - 1
    elif L2[r] > c:
        return r
    else:
        return l
    # return r

N = int(input())
L = list(map(int, input().split()))
L.sort()
L = L[::-1]
ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        c = a - b
        r = binary_search(c, L)
        if r >= j and L[r] > c:
            ans += r - j
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
def binary_search(x, L2):
    l, r = 0, len(L2)-1
    mid = (r + l) // 2
    while r - l > 1:
        mid = (r + l) // 2
        if L2[mid] == x:
            break
        elif L2[mid] > x:
            l = mid
        elif L2[mid] < x:
            r = mid
    if L2[r] > c:
        return r
    else:
        return l
    # return r

N = int(input())
L = list(map(int, input().split()))
L.sort()
L = L[::-1]
ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        c = a - b
        r = binary_search(c, L[j:]) + j
        if r > j and L[r] > c:
            ans += r - j
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
def binary_search(x, L2):
    l, r = 0, len(L2)-1
    mid = (r + l) // 2
    while r - l > 1:
        mid = (r + l) // 2
        if L2[mid] == x:
            break
        elif L2[mid] > x:
            l = mid
        elif L2[mid] < x:
            r = mid
    if L2[r] > c:
        return r
    else:
        return l

N = int(input())
L = list(map(int, input().split()))
L.sort()
L = L[::-1]
ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        c = a - b
        r = binary_search(c, L)
        if r > j and L[r] > c:
            ans += r - j
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
def binary_search(x, L2):
    l, r = 0, len(L2)-1
    mid = (r + l) // 2
    while r - l > 1:
        mid = (r + l) // 2
        if L2[mid] == x:
            return len(L2) - mid
        elif L2[mid] > x:
            l = mid
        elif L2[mid] < x:
            r = mid
    if L2[r] > c:
        return r
    else:
        return l

N = int(input())
L = list(map(int, input().split()))
L.sort()
L = L[::-1]
ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        c = a - b
        r = binary_search(c, L)
        if r > j and L[r] > c:
            ans += r - j
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

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

    print(ans)

Submission status: Wrong Answer

Solution code:
def sort_list(list_n):
    ans = 0
    n_lst = tuple(sorted(list_n, reverse=True))
    for idx in range(len(list_n)-2):
        for diff_idx in range(idx+1, len(list_n)-1):
            diff = n_lst[idx] - n_lst[diff_idx]
            for search in range(diff_idx+1, len(list_n)):
                if n_lst[search] <= diff:
                    search -= 1
                    break
            ans += search - diff_idx
    return ans


def main():
    _ = input()
    K = [int(x) for x in input().split()]
    ans = sort_list(K)
    print(ans)

Submission status: Wrong Answer

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

s = 0
for i, di in enumerate(d):
    d2 = d[i+1:]
    for j, dj in enumerate(d2):
        d3 = d2[j+1:]
        for dk in d3:
            if (di < dj + dk) and (dj < di + dk) and (dk < di + dj):
                print(di, dj, dk)
                s += 1

print(s)

Submission status: Wrong Answer

Solution code:
import bisect

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

ans = 0

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

Submission status: Wrong Answer

Solution code:
import bisect

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

ans = 0

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

Submission status: Wrong Answer

Solution code:
import bisect

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

ans = 0

for i in range(N-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)

Submission status: Wrong Answer

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

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

print(count)

Submission status: Wrong Answer

Solution code:
import copy
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):
        #print(L[i])
        #print(L[j])
        maxi = L[i] + L[j] -1
        mini = abs(L[i] - L[j]) +1
        #print("maxi"+str(maxi)+"mini"+str(mini))
        #cL = copy.copy(L)
        #print(cL)
        mi = bisect.bisect_left(L[:j+1],mini)
        ma = bisect.bisect_right(L[:j+1], maxi)
        #print("mi"+str(mi)+"ma"+str(ma))
        if ma >= mi:
            count += ma-mi
print(count)

Submission status: Wrong Answer

Solution code:
import copy
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):
        print(L[i])
        print(L[j])
        maxi = L[i] + L[j] -1
        mini = abs(L[i] - L[j]) +1
        print("maxi"+str(maxi)+"mini"+str(mini))
        cL = copy.copy(L)
        del cL[:j+1]
        print(cL)
        mi = bisect.bisect_left(cL,mini)
        ma = bisect.bisect_right(cL, maxi)
        print("mi"+str(mi)+"ma"+str(ma))
        if ma >= mi:
            count += ma-mi
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
L = Counter(int(i) for i in input().split())
maxL = max(L)
key = sorted(L.keys())
val = [L[i] for i in range(1, max(L) + 1)]
acc = [0] * (len(val) + 1)
for i in range(len(val)):
    acc[i + 1] = acc[i] + val[i]
cnt = 0
for a in key:
    cnt += L[a] * (L[a] - 1) * (L[a] - 2) // 6
    cnt += max(acc[min(2 * a - 1, maxL)] - acc[a], 0) * L[a] * (L[a] - 1) // 2
for i in range(len(key) - 2):
    a = key[i]
    for j in range(i + 1, len(key) - 1):
        b = key[j]
        cnt += max(acc[min(a + b - 1, maxL)] - acc[b], 0) * L[a] * L[b]
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
L = Counter(int(i) for i in input().split())
maxL = max(L)
key = sorted(L.keys())
val = [L[i] for i in range(1, max(L) + 1)]
acc = [0] * (len(val) + 1)
for i in range(len(val)):
    acc[i + 1] = acc[i] + val[i]
cnt = 0
for i in range(len(key) - 2):
    a = key[i]
    if L[a] >= 3:
        cnt += L[a] * (L[a] - 1) * (L[a] - 2) // 6
    if L[a] >= 2:
        cnt += max(acc[min(2 * a - 1, maxL)] - acc[a], 0) * L[a] * (L[a] - 1) // 2
    for j in range(i + 1, len(key) - 1):
        b = key[j]
        cnt += max(acc[min(a + b - 1, maxL)] - acc[b], 0) * L[a] * L[b]
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
L = Counter(int(i) for i in input().split())
maxL = max(L)
key = sorted(L.keys())
val = [L[i] for i in range(1, max(L) + 1)]
acc = [0] * (len(val) + 1)
for i in range(len(val)):
    acc[i + 1] = acc[i] + val[i]
cnt = 0
for i in range(len(key) - 2):
    for j in range(i + 1, len(key) - 1):
        a, b = key[i], key[j]
        cnt += max(acc[min(a + b - 1, maxL)] - acc[b], 0) * L[a] * L[b]
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
L = Counter(int(i) for i in input().split())
maxL = max(L)
key = sorted(L.keys())
val = [L[i] for i in range(1, max(L) + 1)]
acc = [0] * (len(val) + 1)
for i in range(len(val)):
    acc[i + 1] = acc[i] + val[i]
cnt = 0
for i in range(len(key) - 2):
    for j in range(i + 1, len(key) - 1):
        a, b = key[i], key[j]
        cnt += max(acc[min(a + b - 1, maxL)] - acc[b], 0)
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
L = Counter(int(i) for i in input().split())
key = sorted(L.keys())
val = [L[i] for i in range(1, max(L) + 1)]
acc = [0] * (len(val) + 1)
for i in range(len(val)):
    acc[i + 1] = acc[i] + val[i]
cnt = 0
for i in range(len(key) - 2):
    for j in range(i + 1, len(key) - 1):
        a, b = key[i], key[j]
        cnt += max(acc[min(a + b - 1, max(L))] - acc[b], 0)
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
N = int(input())
L = sorted([int(i) for i in input().split()])

res = 0

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

print(res)

Submission status: Wrong Answer

Solution code:
import bisect
from bisect import bisect_left

n = int(input()) #n行の入力をリストに入れる
l = []
l = list(map(int, input().split( )))

l.sort()
result =0
for i in range(n-2):
    a =l[i]
    for j in range(i+1,n-1):
        b=l[j]
        k = bisect_left(l,a+b-1)
        result += k-j-1

print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
A=sorted([int(i) for i in input().split()])
count=0
for i in range(n - 1, 0, -1): 
    l = 0; 
    r = i - 1; 
    while(l < r): 
        if(A[l] + A[r] > A[i]):  
            count += r - l;  
            print(A[i])
            r -= 1;  
        else: 
            l += 1;  
            
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=sorted([int(i) for i in input().split()])
count=0
for i in range(n - 1, 0, -1): 
    l = 0; 
    r = i - 1; 
    while(l < r): 
        if(A[l] + A[r] > A[i]):  
            count += 1;  
            r -= 1;  
        else: 
            l += 1;  
            
print(count)

Submission status: Wrong Answer

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

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

L = Counter(L_)
Edge = list(L.keys())
Edge.sort()

ans = 0
for e, cnt in L.items():
    if cnt >= 2:
        ans += bisect_left(Edge, e * 2) - bisect_right(Edge, e)
        if cnt >= 3:
            ans += 1

for i, j in combinations(Edge, 2):
    ans += bisect_left(Edge, i + j) - bisect_right(Edge, max(i, j))

print(ans)

Submission status: Wrong Answer

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

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

L = Counter(L_)
Edge = list(L.keys())
Edge.sort()

ans = 0
for e, cnt in L.items():
    if cnt >= 2:
        ans += bisect_left(Edge, e * 2) - bisect_right(Edge, e)
        if cnt == 3:
            ans += 1

for i, j in combinations(Edge, 2):
    ans += bisect_left(Edge, i + j) - bisect_right(Edge, max(i, j))

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
lt = [n] * (l[n-1] + l[n-2] + 1)
ans = 0
for i in range(l[0]+1):
    lt[i] = 0
length = l[0]
for i in range(1, n):
  if length < l[i]:
    for j in range(length, l[i]+1):
      lt[j] = i
    length = l[i]

for i in range(n):
  for j in range(i+1, n):
    right = l[i]+l[j]
    ans += max(0,  lt[right] - (j+1))
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from bisect import bisect
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n):
  for j in range(i+1, n):
    left = l[j]-l[i]
    right = l[i]+l[j]
    ans += max(0, bisect_left(l, right) - bisect(l,left))
    if left < l[i] < right:
      ans -= 1
    if left < l[j] < right:
      ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    rod_list = list(map(int, input().split()))

    pattern = set()

    for i in range(N):
        rod1 = rod_list[i]
        for j in range(i + 1, N):
            rod2 = rod_list[j]
            for k in range(j + 1, N):
                rod3 = rod_list[k]
                print(rod1, rod2, rod3)
                if rod1 >= rod2+rod3 or rod2 >= rod1+rod3 or rod3 >= rod1+rod2:
                    continue

                tmp = sorted([str(rod1), str(rod2), str(rod3)])
                if "-".join(tmp) in pattern:
                    continue

                pattern.add("-".join(tmp))

    print(len(pattern))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left


def main(N, L):
    L.sort()
    ans = 0
    for i in range(0, N-1):
        for j in range(i+1, N):
            l = bisect_left(L, L[j] + 1)
            r = bisect_left(L, L[i] + L[j])
            ans += r - l
    return ans

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

Submission status: Wrong Answer

Solution code:
def main(N, L):
    M = [0] * (10**3+1)
    for l in L:
        M[l] += 1
    ans = 0
    for i in range(1, 10**3-1):
        if not M[i]:
            continue
        for j in range(i+1, 10**3):
            if not M[j]:
                continue
            for k in range(max(j+1,abs(j-i)+1), min(i + j, 10**3+1)):
                ans += M[k]
    print(ans)

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

Submission status: Wrong Answer

Solution code:
n = int(input())
L = sorted(list(map(int, input().split())))
def isOK(target,a,b):
  return target > abs(a-b) and target < a+b

def bin_search(a,b):
  left = 1
  right = n
  while abs(right-left)>1:
    mid = (left+right)//2
    if isOK(L[mid],a,b):
      left = mid
    else:
      right = mid
  return left
ans = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    a,b = L[i],L[j]
    ans += max(0, bin_search(a,b) - j)
      
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = sorted(list(map(int, input().split())))
def isOK(target,a,b):
  return target > abs(a-b) and target < a+b

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

Submission status: Wrong Answer

Solution code:
n = int(input())
L = sorted(list(map(int, input().split())))
def isOK(target,a,b):
  return target > abs(a-b) and target < a+b
 
def bin_search(a,b):
  left = 1
  right = n
  while right-left>1:
    mid = (left+right)//2
    if isOK(L[mid],a,b):
      left = mid
    else:
      right = mid
  return left
ans = 0
for i in range(n):
  for j in range(i+1,n):
    a,b = L[i],L[j]
    ans += max(0, bin_search(a,b) - j)
      
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = sorted(list(map(int, input().split())))
def isOK(target,a,b):
  return target > abs(a-b) and target < a+b
 
def bin_search(a,b):
  left = 1
  right = n
  while right-left>1:
    mid = left+(right-left)//2
    if isOK(L[mid],a,b):
      left = mid
    else:
      right = mid
  return left
ans = 0
for i in range(n):
  for j in range(i+1,n):
    a,b = L[i],L[j]
    ans += max(0, bin_search(a,b) - j)
      
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = sorted(list(map(int, input().split())))
def isOK(target,a,b):
  return target > abs(a-b) and target < a+b

def bin_search(a,b):
  left = 1
  right = n
  while right-left>1:
    mid = left+(right-left)//2
    if isOK(L[mid],a,b):
      left = mid
    else:
      right = mid
  return left
ans = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    a,b = L[i],L[j]
    ans += bin_search(a,b) - j
      
print(ans)

Submission status: Wrong Answer

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

x = []

for a in l:
    for b in l:
        if b == a:
            continue
        for c in l:
            if (c == a) or (c == b):
                continue
            elif (a < b + c) and (b < a + c) and (c < a + b):
                i = [a, b, c]
                x.append(sorted(i))

y = []

for d in x:
    if d not in y:
        y.append(d)

print(len(y))

Submission status: Wrong Answer

Solution code:
N=int(input())
num=list(map(int, input().split()))
c=0
for i in range(0,N-3,1): 
    for j in range(i+1,N-2,1):
        for k in range(i+2,N-1,1):
            t=int((num[i]+num[j]+num[k])/2)
            if num[i]<t and num[j]<t and num[k]<t:
                c+=1
print (c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect

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

MAX=L[-1]
count=0
for i in range(N-2):
    for  j in range(i+1,N-1):
        # print(i,j)
        # print(L[i+1:-1])
        minInd=j+1
        # print(minInd)
        
        # if L[minInd]> L[i]+L[j]:
        #     continue
        # if MAX<L[i]+L[j]:
        #     count+=N-1-minInd+1
        # else:
        #     ind = bisect.bisect_left(L[minInd:], L[i]+L[j]) # number of < a+b
        #     count+=ind
        
        count+= bisect.bisect_right(L, L[i]+L[j]) # number of < a+b
print(count)

Submission status: Wrong Answer

Solution code:
import bisect

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

MAX=L[-1]
count=0
for i in range(N-2):
    for  j in range(i+1,N-1):
        # print(i,j)
        # print(L[i+1:-1])
        minInd=j+1
        # print(minInd)
        
        # if L[minInd]> L[i]+L[j]:
        #     continue
        # if MAX<L[i]+L[j]:
        #     count+=N-1-minInd+1
        # else:
        #     ind = bisect.bisect_left(L[minInd:], L[i]+L[j]) # number of < a+b
        #     count+=ind
        
        count+= bisect.bisect_right(L[minInd:], L[i]+L[j]) # number of < a+b
print(count)

Submission status: Wrong Answer

Solution code:
import bisect

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

MAX=L[-1]
count=0
for i in range(N-2):
    for  j in range(i+1,N-1):
        # print(i,j)
        # print(L[i+1:-1])
        minInd=j+1
        # print(minInd)
        if L[minInd]> L[i]+L[j]:
            continue
        if MAX<L[i]+L[j]:
            count+=N-1-minInd+1
        else:
            ind = bisect.bisect_right(L[minInd:], L[i]+L[j]) # number of < a+b
            count+=ind
        # print(count)
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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:
    # def bin_search_le_rightmost(s: int, e: int, target: int):
    #   if s == e:
    #     if ls[s] > target:
    #       return None
    #     else:
    #       return s
    #
    #   mid = s + (e - s) // 2
    #
    #   if ls[mid] <= target and (mid + 1 < n and ls[mid + 1] > target):
    #     return mid
    #   elif ls[mid] <= target:
    #     return bin_search_le_rightmost(mid + 1, e, target)
    #   else:
    #     return bin_search_le_rightmost(s, mid, target)

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

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

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left,bisect_right
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 += max(bisect_right(L,L[i]+L[j]-1)-j-1,0)

print(count)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
N = int(input(()))
L = list(map(int,input().split()))
count = 0

for i in range(N):
    k = L[i]
    j = i - 1
    while(j >= 0)and(L[j]>k):
        L[j+1]=L[j]
        j -= 1
    L[j+1] = k

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

print(count)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
N = int(input(()))
L = list(map(int,input().split()))
count = 0

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

print(count)

Submission status: Wrong Answer

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

for i in range(N):
    k = L[i]
    j = i - 1
    while(j >= 0)and(L[j]>k):
        L[j+1]=L[j]
        j -= 1
    L[j+1] = k
L = L[::-1]
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]) and (L[j]<L[i]+L[k]) and (L[j]>=L[k]):
                count += 1

print(count)

Submission status: Wrong Answer

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

for i in range(N):
    k = L[i]
    j = i - 1
    while(j >= 0)and(L[j]>k):
        L[j+1]=L[j]
        j -= 1
    L[j+1] = k
L = L[::-1]
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]) and (L[j]<L[i]+L[k]) and (L[j]>L[k]):
                count += 1

print(count)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import bisect


def main():
    n = int(input())
    l = [int(x) for x in input().split()]
    l = sorted(l)

    ans = 0
    for i in range(2, n):
        for j in range(1, i):
            c = l[i]
            b = l[j]
            lo = bisect.bisect_right(l, c-b)
            hi = bisect.bisect_left(l, b)
            if hi > lo:
                ans += hi - lo
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i,j in list(combinations(L,2)):
  if j <= 2*i:
    ans += max(0, bisect.bisect_left(L, i+j) - bisect.bisect_right(L, j-i)-2)
  else:
    ans += max(0, bisect.bisect_left(L, i+j) - bisect.bisect_right(L, j-i)-1)
print(ans//3)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i,j in list(combinations(L,2)):
  print(i,j)
  if j <= 2*i:
    ans += max(0, bisect.bisect_left(L, i+j) - bisect.bisect_right(L, j-i)-2)
  else:
    ans += max(0, bisect.bisect_left(L, i+j) - bisect.bisect_right(L, j-i)-1)
print(ans//3)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i,j in list(combinations(L,2)):
  ans += max(0, bisect.bisect_left(L, i+j) - bisect.bisect_right(L, j-i))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
nums = list(map(int, input().split()))
nums.sort(reverse=True)
ans = 0
bk2 = False
for x in range(len(nums)):
    for y in range(x + 1, len(nums)):
        for z in range(y + 1, len(nums)):
            # abs(a - b) >= c
            if abs(nums[x] - nums[y]) >= nums[z]:
                bk2 = True
                break
            # a + b <= c
            if nums[x] + nums[y] <= nums[z]:
                break
            #print("{} {} {}".format(x, y, z))
            ans = ans + 1
        if bk2:
            bk2 = False
            break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sum = 0
count_b = 0
count_c = 0
for a in range(N):
    count_b = count_b + 1
    for b in range(count_b, N):
        sum += bisect.bisect_left(dlist,dlist[a] - dlist[b]) 
print(sum-1)

Submission status: Wrong Answer

Solution code:
import bisect

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

# def solve(N, L):
# def makeTriangle(a, b, c):
#     return (a < b + c) and (b < c + a) and (c < a + b)

#     total = 0
#     # naive implementation O(N^3)
#     for i in range(N):
#         for j in range(i+1, N):
#             for k in range(j+1, N):
#                 total += int(makeTriangle(L[i], L[j], L[k]))
#     return total
# print(solve(N, L))
L = sorted(L)
total = 0
for i in range(N):
    for j in range(i+1, N):
        diff = L[j] - L[i]
        sup = bisect.bisect(L, L[i])
        inf = bisect.bisect(L, diff)
        total += sup - inf

print(total)

Submission status: Wrong Answer

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