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:
def tri_check(a,b,c):
  if a<b+c and b<a+c and c<a+b:
    return True
  else:
    False

N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
ans = 0
for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      if tri_check(L[i],L[j],L[k]):
        ans += 1
      else:
        break
    else:
      continue
    break
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
l.sort()
l.reverse()
b=0
ans = 0
for i in range(len(l)-2):
  b = 0
  max_length = l[0]
  for j in range(1,len(l)-1):
    if b == 1:
      break
    length_2 = l[j]
    for k in range(j+1,len(l)):
      length_3 = l[k]
      if max_length < length_2 + length_3:
        ans+=1
      else:
        b=1
        del l[0]
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort()
k2 = 2
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        s = L[i]+L[j]
        for k in range(k2,N):
            if L[k] >= s:
                k2 = k
                ans += N-k
                break
print((N*(N-1)*(N-2)//6 - ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
cnt = [0]*(3*10**3+1)
for i in range(N):
    cnt[L[i]] += 1
cum = [0]*(3*10**3+1)
for i in range(3*10**3):
    cum[i+1] = cum[i]+cnt[i+1]

ans = 0
for a in range(1,10**3+1):
    if cnt[a] == 0:
        continue
    for b in range(a+1,10**3+1):
        if cnt[b] == 0:
            continue
        ans  += (cum[a+b-1]-cum[b])*cnt[a]*cnt[b]

for a in range(5*10**2):
    if cnt[a] < 2:
        continue
    ans += ((cum[2*a]-cnt[a])*cnt[a]*(cnt[a]-1))//2

for a in range(10**3+1):
    if cnt[a] < 3:
        continue
    ans += (cnt[a]*(cnt[a]-1)*(cnt[a]-2))//6

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
	import sys
	input = sys.stdin.readline
	
	n = int(input())
	arr = sorted(map(int, input().split()))
	
	ans = 0
	for i in range(2, n):
		for j in range(i - 1):
			l = j + 1
			r = i
			while r - l != 1:
				if arr[l + r >> 1] + arr[j] > arr[i]:
					l = l + r >> 1
				else:
					r = l + r >> 1
			ans += i - r
	
	print(ans)
	
	return 0

main()

Submission status: Wrong Answer

Solution code:
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 l[i]+l[j]>=l[k] and abs(l[i]-l[j])<l[k]:
                                    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
#ABC143D
import sys
import math
import collections
#sys.setrecursionlimit(100000)


n=int(input())

tmp = input().split()
l = list(map(lambda a: int(a), tmp))

sum=0

#print(l)
l.sort()
#print(l)

for i in range(n):
	for j in range(i+1,n):
		tmp1 = l[i]+l[j]
		tmp2 = abs(l[i]-l[j])
		for k in range(j+1,n):
			if(tmp1<l[k]):
				break
			if(tmp2>l[k]):
				break
			sum+=1
print(sum)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
from bisect import bisect_left, bisect_right
n = getN()

nums = getList()
nums.sort()

ans = 0
for i, num1 in enumerate(nums):
    for j , num2 in enumerate(nums[i+1:]):
        tmp = num1 + num2
        idx_min = bisect_left(nums, tmp)
        idx_max = bisect_right(nums, num2 - num1)
        # print(num1, num2, idx_min - idx_max)
        ans += idx_min - idx_max - 2
        if num2 >= num1 * 2:
            ans += 1
# print("=======")
# anss = 0
# for i, n1 in enumerate(nums):
#     for j, n2 in enumerate(nums):
#         for k, n3 in enumerate(nums):
#             if i != j and j != k and k != i:
#                 if n1 < n2 + n3 and n2 < n1 + n3 and n3 < n1 + n2:
#                     print(n1, n2, n3)
#                     anss += 1

print(ans/ 3)
# print(anss/6)

"""
1 2 1  0
1 3 1  0
1 4 1  0
1 5 1  0
2 3 3  234 - 23 > 1 234
2 4 3  345 - 4 > 234, 245 
2 5 2  45 - 5 > 245
3 4 4  2345 - 34 > 234, 345
3 5 3  345 - 35 > 345 
4 5 4  2345 - 45 > 245, 345 
"""

Submission status: Wrong Answer

Solution code:
import glob
import bisect

# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\143\\D'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class D(Common):

    def resolve(self):

        N = int(self.input_data())
        rods = [int(i) for i in self.input_data().split()]
        rods.sort()
        print(rods)
        result = 0

        for i in range(len(rods)):
            for j in range(i+1, len(rods)):
                error = bisect.bisect_left(rods, rods[i]+rods[j])
                result += error - j - 1

        print(str(result))


solver = D(REL_PATH)
solver.exec_resolve()

Submission status: Wrong Answer

Solution code:
n=int(input())
hoge=list(map(int,input().split()))
hoge.sort(reverse=True)
ans=0

for i in range(n):
  for j in range(max(n-(i+1),0)):
    for k in range(max(n-(i+1)-(j+1),0)):
      flag=0
      print(i,i+j+1,i+j+k+2)
      if(hoge[i]<hoge[i+j+1]+hoge[i+j+k+2]):
        flag+=1
      if(hoge[i+j+1]<hoge[i]+hoge[i+j+k+2]):
        flag+=1
      if(hoge[i+j+k+2]<hoge[i+j+1]+hoge[i]):
        flag+=1
      if(flag==3):
        ans+=1
        
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[int(x) for x in input().split()]
num_l=[0]*1001
ans=0
for x in l:
  num_l[x]+=1
for a in range(1,1001):
  if(num_l[a]==0):
    continue
  for b in range(a,1001):
    if(num_l[b]==0):
      continue
    for c in range(b,min(a+b,1001)):
      ans+=num_l[a]*num_l[b]*num_l[c]
      if(a==b!=c):
        ans-=num_l[a]*num_l[c]
      elif(b==c!=a):
        ans-=num_l[a]*num_l[b]
      elif(a==b==c):
        ans+=(-3)*(num_l[a]**2)+2*num_l[a]
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

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

Ls = list(set(Ls))

ans = 0
for cs in combinations(Ls, 3):
    a, b, c = cs

    ret = (a < (b + c)) and (b < (c + a)) and (c < (a + b))
    if ret:
        ans += 1

print(ans)

Submission status: Wrong Answer

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

R = []
for i in L:
    for j in L:
        if i == j:
            continue
        for k in L:
            if i == k or j == k:
                continue
            if i < j+k and j < i+k and k < i+j:
                r = {i, j, k}
                if not r in R:
                    R.append(r)

print(len(R))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from bisect import bisect_right, bisect_left
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    n = int(input())
    l = sorted(map(int, input().split()))
    print(l)

    o = 0

    for i in range(n):
        for j in range(i):
            a, b = l[i], l[j]

            s = bisect_right(l, a - b)
            e = bisect_left(l, a + b)

            o += (e - s - (a - b < a) - (a - b < b))

    print(o // 3)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def sarch(l, left, right, target):
    global ans
    mid = right + left
    mid //= 2
    # print(left, right, target, ans)
    if right - left <= 1:
        if l[right] >= target:
            return right
        if l[left] >= target:
            return left
        else:
            return 0
    if target < mid:
        return sarch(l, left, mid, target)
    if target == mid:
        return sarch(l, mid, right, target)
    if mid < target:
        return sarch(l, mid, right, target)


n = int(input())
l = list(map(int, input().split()))
l.sort()
l = l[::-1]
ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        tmp = l[i] - l[j] + 1
        tmp = sarch(l, j + 1, n - 1, tmp)
        # print(tmp, j)
        if tmp > j:
            ans += (tmp - j)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
biSet = set()
triSet = set()

for i in range(n):
    for j in range(i+1, n):
        length = l[i] + l[j]
        t = str(l[i]) + str(l[j])
        if t in biSet:
            break
        else:
            biSet.add(t)

        for k in range(j+1, n):
            if l[k] >= length:
                break
            else:
                t2 = str(l[i]) + str(l[j]) + str(l[k])
                if t2 not in triSet:
                    triSet.add(t2)
                    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

n = int(input())
d = set([int(i) for i in input().split()])
z = 0
for i in combinations(d, 3):
    a, b, c = i
    if a < b + c and b < c + a and c < a + b:
        z += 1
print(z)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

L.sort()
print(L)
cnt = 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:
                break
            cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
List = [int(i) for i in input().split()]
List2=sorted(List)
import numpy as np
A=np.asarray(List2)
ans = 0

for i in range(1,n-1): #aにたいし
  for j in range(i,n):
    tmp1 = List[i]
    tmp2 = List[j]
    ans += np.count_nonzero(A-tmp1-tmp2>0)
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = sorted(list(map(int,input().split())))
maxl = max(l)
csum = [0]*(maxl + 2)
ans = 0
for i in l:
    csum[i] += 1
for i in range(1,len(csum)):
    csum[i] += csum[i-1]

for i in range(n):
    for j in range(i + 1,n):
        if l[i] + l[j] - 1 > l[j]:
            ans += csum[min(maxl,l[i] + l[j] - 1)] - csum[l[j]]
print(ans)

Submission status: Wrong Answer

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

lis = sorted(l)
lis.reverse()

ret = 0
for i in range(n - 2):
    longest = lis[i]
    ok = True
    for i1 in range(i + 1, n - 1):
        l1 = lis[i1]
        if ok == False:
            break
        for i2 in range(i1 + 1, n):
            l2 = lis[i2]
            if longest < (l1 + l2):
                ret += 1
            else:
                ok = False
                break
print(ret)

Submission status: Wrong Answer

Solution code:

N = int(input())
D = input().split(' ')

D.sort(reverse=True)

count = 0
for i in range(N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            if int(D[i]) < int(D[j]) + int(D[k]):
                count += 1


print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import itertools

def solve(N: int, L: "List[int]"):
    ans = 0
    ls = list(set(L))
    from collections import Counter
    c = Counter(L)

    for x,y,z in list(itertools.combinations(ls, 3)):
        if(x < y+z and y < x+z and z < x+y):
            ans += c[x]*c[y]*c[z]

    print(ans)    

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

Submission status: Wrong Answer

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

cnt = 0
k = 2
for i in range(N-2):
  for j in range(i+1,N-1):
    
    k = max(j+1,k)
    
    while k < N:
      if S[i]+S[j] <= S[k]:
        cnt += k-j-1
        break 
      k += 1
    else:
      if S[i]+S[j] > S[k-1]:
        cnt += k-j-1
         
        
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools

import queue
from collections import deque



def main():
    num = int(input())
    data = list(map(int, input().split()))

    data.sort()
    dp = [0 for i in range(max(data) * 2 + 1)]

    count = Counter(data)

    for i in range(1, max(data) * 2 + 1):
        dp[i] = dp[i - 1] + count[i]

    count = sorted(count.items(), key=lambda x: x[0])
    ans = 0

    # print(data)
    # print(count)
    # print(dp)

    for i in range(len(count)):
        if count[i][1] >= 3:
            ans += (count[i][1] * (count[i][1] - 1) * (count[i][1] - 2)) // 6
        if count[i][1] >= 2:
            nokori = count[i][0] * 2 - 1
            ans += (count[i][1] * (count[i][1] - 1)) // 2 * (dp[nokori] - dp[count[i][0]])

        for j in range(i + 1, len(count)):
            max_data = count[i][0] + count[j][0] - 1
            kari = count[i][1] * count[j][1] * (dp[max_data] - dp[count[j][0]])
            ans += kari

    print(ans)








if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
List = [int(i) for i in input().split()]
List2=sorted(List)
import numpy as np
A=np.asarray(List2)
ans = 0

for i in range(1,n-1): #aにたいし
  for j in range(i,n):
    tmp1 = List[i]
    tmp2 = List[j]
    ans += np.count_nonzero(A-tmp1-tmp2>0)
    print(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n= int(input())
l= list(map(int,input().split()))
l=sorted(l)
count=0
for  i  in range(2,n):
    for j in range(1, i):
        r=list(reversed(range(0,j)))
        for k in r:
            if l[i]<l[j]+l[k]:
                count+=(k+1)
                break
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
triSet = set()

for i in range(n):
    for j in range(i+1, n):
        length = l[i] + l[j]
        t = str(l[i]) + str(l[j])
        if t in triSet:
            break
        else:
            triSet.add(t)

        for k in range(j+1, n):
            if l[k] >= length:
                break
            else:
                ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys; readline = sys.stdin.readline
from collections import deque


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

L.sort()

Ns = [0] * (2*10**3 + 10)

for l in L:
    Ns[l] += 1

cNs = [0] * len(Ns)
for i in range(1, len(Ns)):
    cNs[i] = cNs[i - 1] + Ns[i]

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

        if L[j] == m:
            count += max(0, Ns[L[j]] - 1)
        

print(count)

Submission status: Wrong Answer

Solution code:

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):
            #print(count,Llist[i],Llist[j],Llist[k])
            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)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
L = sorted([int(x) for x in input().split()])
c = 0
Lcnt = Counter(L)
Lset = sorted(list(set(L)))
Nset = len(Lset)
for i in range(Nset - 2):
  for j in range(i + 1, Nset - 1):
    for k in range(j + 1, Nset):
      if Lset[i] + Lset[j] > Lset[k]:
        c += Lcnt[Lset[i]] * Lcnt[Lset[j]] * Lcnt[Lset[k]]
      else:
        break
print(c)

Submission status: Wrong Answer

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

N=10**3
L=[1]*N

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
      else:
        break
        
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
	import sys
	input = sys.stdin.readline
	
	n = int(input())
	arr = sorted(map(int, input().split()))
	
	ans = 0
	for i in range(2, n):
		r = 1
		for l in range(i - 1):
			while r <= l or arr[l] + arr[r] <= arr[i]:
				r += 1
			
			ans += i - r
	
	print(ans)
	
	return 0

main()

Submission status: Wrong Answer

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

    L = sorted(L, reverse=True)

    ans = 0
    for i in range(N-2):

        #if (L[i] + L[i+1] + L[i+2])/2 > L[i]:
        #   ans += 1

        if (L[i] + L[i+1]) > L[i+2] and (L[i] + L[i+2]) > L[i+1] and (L[i+1] + L[i+2]) > L[i]:
            ans += 1
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

N=2*10**3
L=[1]*N

N=10**3
L=[1]*N

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
      else:
        break
        
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
a=0
b=0
c=0
cnt=0
my_bool=False
for i in range(n-2):
    for j in range(i+1,n):
        for m in range(j+1,n):
            if l[i]<l[j]+l[m]:
                cnt+=1
            else:
                my_bool=True
                break
        if my_bool:
            my_bool=False
            break
print(cnt)

Submission status: Wrong Answer

Solution code:
import heapq

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

h = []

for i in range(N):
    heapq.heappush(h, L[i])

triangles = 0

for i in range(N):
    first = h[i]
    for j in range(i+1, N):
        second = h[j]
        fs = first + second
        for k in range(j+1, N):
            third = h[k]
            if third >= fs:
                break
            if second >= first + third:
                continue
            triangles = triangles + 1

print(triangles)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [int(i) for i in input().split()]

l = list(set(l))
ans = 0
for i in range(len(l)-2):
    for j in range(i + 1, len(l) - 1):
        for k in range(j + 1, len(l)):
            if l[i] < l[j] + l[k] and l[j] < l[i] + l[k] and l[k] < l[i] + l[j]:
                ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools

import queue
from collections import deque



def main():
    num = int(input())
    data = list(map(int, input().split()))

    data.sort()
    dp = [0 for i in range(max(data) * 2 + 1)]
    count = Counter(data)

    for i in range(1, max(data) * 2 + 1):
        dp[i] = dp[i - 1] + count[i]

    count = sorted(count.items(), key=lambda x: x[0])
    ans = 0

    # print(data)
    # print(count)
    # print(dp)

    for i in range(len(count) - 1):
        if count[i][1] >= 3:
            ans += (count[i][1] * (count[i][1] - 1) * (count[i][1] - 2)) // 6
        if count[i][1] >= 2:
            nokori = count[i][0] * 2 - 1
            ans += (count[i][1] * (count[i][1] - 1)) // 2 * (dp[nokori] - dp[count[i][0]])

        for j in range(i + 1, len(count)):
            max_data = count[i][0] + count[j][0] - 1
            kari = count[i][1] * count[j][1] * (dp[max_data] - dp[count[j][0]])
            ans += kari

    print(ans)








if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
total=0
for i in range(n-2):
  if l[i]<l[i+1]+l[i+2]:
    for j in range(i+1,n-1):
      for k in range(j+1,n):
        if l[i]<l[j]+l[k]:
          total+=1
        else:
          break
  else:
    break
print(total)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans = 0
a=0
for i  in range(n-2):
    if l[i]==a:
        continue
    a = l[i]
    b = 0
    for j in range(i+1,n-1):
        if l[j]==b:
            continue
        b = l[j]
        c = 0 
        for k in range(j+1,n):
            if l[k]==c:
                continue
            c = l[k]
            if c-b < a:
                ans += 1
            else:
                break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import bisect


def main():
  input()
  values = list(map(int, input().split()))
  values.sort()
  result = 0

  for i in range(len(values) - 2):
    for j in range(i + 1, len(values) - 1):
      targets = values[j + 1:]
      index = bisect.bisect(targets, values[i] + values[j])
      result += index

  print(result)


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import bisect

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

L.sort()
print(L)

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

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
ans=0
f=False
for i in range(n-2):
    for j in range(n-2-i):
        for k in range(n-2-i-j):
            if l[i]<l[i+j+1]+l[i+j+k+2]:
                ans+=1
            else:
                if j==0:
                    f=True
                break;
        if f:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
import itertools 
def findsubsets(s, n): 
    return list(itertools.combinations(s, n)) 
com = findsubsets(set(l), 3)
c = 0
fin = []
for i in com:
    tem = list(i)
    tem.sort()
    fin.append(tem)
for i in fin:
    if i[0] + i[1] > i[2]: c += 1
print(c)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())
L = np.array(read().split(),np.int32)

U = 1001
counter = np.bincount(L,minlength=U)

def F1():
    # 正三角形
    return np.count_nonzero(counter >= 3)

def F2():
    # (a,a,2a未満のa以外)
    exist = (counter > 0)
    cum = exist.cumsum()
    # counter_cum[2a-1] - 1 
    a = np.where(counter >= 2)[0]
    b = np.minimum(2*a-1,U-1)
    return (cum[b] - 1).sum()

def F3():
    # 3種類
    # a,b,c であって、b<c<a+b
    exist = (counter > 0)
    cum = exist.cumsum()
    a = np.where(counter>0)[0]
    b = np.where(counter>0)[0]
    upper = np.minimum(a[:,None] + b[None,:] - 1,U-1)
    lower = b
    cnt_c = cum[upper] - cum[lower][None,:]
    return np.triu(cnt_c,1).sum()

answer = F1() + F2() + F3()
print(answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

from collections import defaultdict

d = defaultdict(int)

for i in range(n):
    d[s[i]]+= 1

r = 0
key = sorted(list(d.keys()))
ng = len(key)
for i in range(ng)[::-1]:
    for j in range(i+1):
        for k in range(j, i+1)[::-1]:
            if key[i] == key[j] and key[j] == key[k] and d[key[i]] < 3:
                continue
            if key[i] == key[j] and d[key[i]] < 2:
                continue
            if key[j] == key[k] and d[key[k]] < 2:
                continue
            if key[i] == key[k] and d[key[i]] < 2:
                continue
            if key[j] + key[k] <= key[i]:
                break
            else:
                r+=1
print(r)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
cnt = [0 for i in range(1001)]
for l in L:
	cnt[l] += 1
total = [0 for i in range(1001)]
for i in range(1, 1001):
	total[i] = total[i-1] + cnt[i]

ans = 0
for i in range(3, 1001):
	if cnt[i] <= 0:
		continue
	I = cnt[i]
	for j in range(i, 1001):
		J = cnt[j]
		if J <= 0:
			continue
		if i == j and J <= 1:
			continue
		base = (I * (I - 1)) // 2 if i == j else I * J
		M = min(1000, i + j)
		if i == j and cnt[j] >= 3:
			ans += (I * (I-1) * (I-2)) // 6
		elif cnt[j] >= 2:
			ans += I * (J * (J-1)) // 2
		ans += base * (total[M] - total[j])
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

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

_sum = 0

if len(L) < 3:
    print(0)
    exit()

for _ in list(itertools.combinations(L,3)):
    if _[0] < _[1]+_[2] and _[1] < _[2]+_[0] and _[2] < _[0]+_[1]:
        _sum += 1
print(_sum)

Submission status: Wrong Answer

Solution code:
import bisect
import sys

input = sys.stdin.readline


def read_i():
    return list(map(int, input().split()))


n = int(input())
ls = sorted(read_i())
res = 0
for i, x in enumerate(ls):
    for j, y in enumerate(ls[i + 1:], i + 1):
        if y == x:
            continue
        k = bisect.bisect(ls, max(x, y))
        l = bisect.bisect_left(ls, x + y)
        res += l - k
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort()
C = [0] * (3 * 10**3)
for ia, a in enumerate(L):
    for ib, b in enumerate(L[ia+1:]):
        C[b+1] += 1
        C[a+b] -= 1
c = 0
for i in range(10**3+1):
    C[i] = c = C[i] + c


ans = 0
for l in L:
    ans += C[l]

print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect,bisect_left

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

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