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 sarch(l, left, right, target):
    global ans, cnt
    cnt += 1
    if cnt > 100000:
        return 0
    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 < l[mid]:
        # print(2)
        return sarch(l, mid, right, target)
    if target == l[mid]:
        return mid
    if l[mid] < target:
        # print(1)
        return sarch(l, left, mid, target)

cnt = 0
n = int(input())
l = list(map(int, input().split()))
l.sort()
l = l[::-1]
# print(l)
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 = sorted([int(x) for x in input().split()])
print(l)
ans = 0

for a in range(n):
    for b in range(a+1, n):
        for c in range(b+1, n):
            if l[c]<l[a]+l[b]:
                ans += 1
                #print(a,b,c)
                continue
            else:
                break
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

col = collections.Counter(L)
cmemo = [0] * 1001
for x in list(col.keys()):
    cmemo[x] += col[x]
for i in range(1, 1001):
    cmemo[i] += cmemo[i-1]

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        a, b = L[i], L[j]
        cmin, cmax = b-a, min(a+b, 1000)
        if cmin < a:
            ans += cmemo[cmax-1] - cmemo[cmin] - 2
        else:
            ans += cmemo[cmax-1] - cmemo[cmin] - 1
print(ans//3)

Submission status: Wrong Answer

Solution code:
n=int(input())
L=sorted(list(map(int,input().split())))
dp=[0]*n
M=[]
dp[2]=0 if L[0]+L[1]>L[2] else 1
if dp[2]==0:
  M.append(L[0]+L[1])
if n!=3:
    for i in range(3,n):
        dp[i]=dp[i-1]
        for m in M:
          if L[i]>=m:
            dp[i]+=1
        M=[]
        for j in range(i-1):
            if L[i-1]+L[j]<=L[i]:
                dp[i]+=1
            else:
                M.append(L[i-1]+L[j])
print(n*(n-1)*(n-2)//6-sum(dp))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
num = int(input())
cmlist = input().split(' ')
count = 0
for i in range(0, num):
  for j in range(i+1, num):
    for k in range(j+1, num):      
      if j<i+j and i<j+k and j<k+i:
        count+=1
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
h=list(int(x) for x in input().split())
sum=0
for i in range(n-2):
  for j in range(i+1,n):
    for k in range(i+j+1,n):
      l=[h[i],h[j],h[k]]
      max_neiborhood=max(l)
      l.remove(max_neiborhood)
      add_neiberhood=l[0]+l[1]
      if max_neiborhood<add_neiberhood:
        sum+=1
print(sum)

Submission status: Wrong Answer

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

ls = sorted(l)

count = 0
for i in range(n):
    for j in range(i + 1, n):
        x, y = ls[i], ls[j]
        tri_xy = [i for i in ls[j + 1:] if i < x + y]
        print(tri_xy)
        count += len(tri_xy)
print(count)

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
L = [int(i) for i in input().split()]
L.sort(reverse=True)
ans = 0
P = []
for i in range(N-1):
    for j in range(i+1,N):
        P.append(L[i]+L[j])
now = 0
ans = 0
for i in range(N-2):
    now += N - (i + 1)
    A = P[now:]
    A.sort()
    index = insert_index = bisect.bisect_left(A,L[i])
    ans += (len(A) - index)
print(ans)

Submission status: Wrong Answer

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

from collections import Counter
c = Counter(l2)
k = list(c.keys())
k.sort()

from bisect import bisect_left, bisect_right
l2.sort()

ans = 0
for i in range(len(k)):
    for j in range(i+1, len(k)):
        c_min = k[j] - k[i]
        c_max = k[i] + k[j]

        idx = bisect_left(l2, k[j])
        if idx < len(l2) and l2[idx] == k[j]:
            idx += 1
        tmp = l2[idx:]

        idx_min = bisect_right(tmp, c_min)
        idx_max = bisect_left(tmp, c_max)

        ans += max(0, idx_max - idx_min) * c[k[i]] * c[k[j]]

for _k in k:
    if c[_k] >= 2:
        idx = bisect_right(l2, _k)
        tmp = l2[idx:]
        idx_min = bisect_right(tmp, 0)
        idx_max = bisect_left(tmp, _k * 2)

        ans += max(0, idx_max - idx_min) * (c[_k] - 1) * c[_k] // 2

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import bisect
def input():
    return sys.stdin.readline()[:-1]
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):
        left=bisect.bisect_left(l,l[i]+l[j])
        right=bisect.bisect_right(l,(l[i]+l[j]+1)//2)
        # print(left)
        # print(right)
        # print()
        cnt=left-right+1
        if left<=j+1:
            # print(99)
            continue
        if right<j+2:
            cnt-=j+2-right
        if cnt>=0:
            ans+=cnt
        
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
L = list(map(int, input().split()))
l_set = set(L)
sort_L = sorted(list(l_set))
nl = len(sort_L)
ans = 0
for i in range(nl):
  for j in range(i+1, nl):
    a,b = sort_L[i],sort_L[j]
    for k in range(j+1, nl):
      c = sort_L[k]
      if c<a+b:
        ans += 1
      else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
L = [int(l) for l in input().split()]
L.sort()

total = 0

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]:
                total += 1
print(total)

Submission status: Wrong Answer

Solution code:
import itertools
n=int(input())
l=[int(_) for _ in input().split()]
c_l=list(itertools.combinations(l,3))
tr=[]
for i in range(len(c_l)):
	if c_l[i][0]<c_l[i][1]+c_l[i][2] and c_l[i][1]<c_l[i][0]+c_l[i][2] and c_l[i][2]<c_l[i][0]+c_l[i][1]:
		ans =[c_l[i][0],c_l[i][1],c_l[i][2]].sort()
		if ans not in tr:tr.append(ans)
print(len(tr))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

n = int(input())
a = sorted(map(int, input().split()))
print(sum(n - bisect_right(a, a[i] + a[j], j + 1)
          for i in range(1, n) for j in range(i)))

Submission status: Wrong Answer

Solution code:
n=int(input())
h=list(int(x) for x in input().split())

sum=0

for i in range(n-2):
  for j in range(i+1,n):
    for k in range(i+j+1,n):
      l=[h[i],h[j],h[k]]
      
      max_neiborhood=max(l)
      l.remove(max_neiborhood)
      add_neiberhood=l[0]+l[1]
    
      if max_neiborhood<add_neiberhood:
      
        sum+=1
print(sum)

Submission status: Wrong Answer

Solution code:
def calc(L, la):
    hash_map = {}
    ret = 0
    for idx, lb in enumerate(L):
        if lb * 2 < la: break
        for lc in L[idx + 1:]:
            if lb + lc < la: break
            ret += 1
    return ret

if __name__ == '__main__':
    N = int(input())
    L = [int(l) for l in input().split()]
    L.sort(reverse=True)
    ret = 0
    for idx, la in enumerate(L):
        ret += calc(L[idx + 1:], la)
    print(ret)

Submission status: Wrong Answer

Solution code:
n=int(input())
l = list(map(int,input().split()))	
l.sort()
ans=0
if l[0]+l[1]>l[n-1]:
    print((n*(n-1)*(n-2))//6)
    exit()
else:
    key=f=0
    for i in range(n-2):
        for j in range(n-i-2):
            j+=i+1
            for k in range(n-j-1-key):
                k+=j+1+key
                key=0
                if l[i]+l[j]<=l[k]:
                    ans+=k-j-1
                    key=k-j-2
                    if key<0:
                        key=0
                    break
                elif k==n-1 and l[i]+l[j]>l[k]:
                    ans+=((k-j)*(k-j+1))//2
                    f=1
                    break
            if f==1:
                f=key=0
                break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys


def main():
    n = int(sys.stdin.readline().strip())
    l = [int(s) for s in sys.stdin.readline().strip().split()]

    # n = 6
    # l = [9, 9, 9, 1] # 4
    # l = [9, 9, 1, 1] # 2
    # l = [1, 1, 1, 9, 9, 9] # 2 + 9

    table = [0] * 1001

    for i in range(n):
        length = l[i]
        table[length] += 1

    total_so_far = [0] * 1001
    total = 0
    for i in range(1001):
        total += table[i]
        total_so_far[i] = total

    def aC2(a):
        return a * (a-1) // 2

    def aC3(a):
        return a * (a-1) * (a-2) // 6

    # [l1, l2)
    def range_total(l1, l2):
        assert l1 > 0
        if l1 >= l2:
            return 0
        if l2 > 1001:
            l2 = 1001
        return total_so_far[l2-1] - total_so_far[l1-1]

    ans = 0
    for i in range(1, 1001):
        if table[i] == 0:
            continue
        if table[i] > 2:
            ans += aC3(table[i])

        if table[i] > 1:
            a_plus_b = 2 * i

            inc = aC2(table[i]) * range_total(i+1, a_plus_b)
            ans += inc

        for j in range(i+1, 1001):
            if table[j] == 0:
                continue
            if table[j] > 1:
                inc = table[i] * aC2(table[j])
                ans += inc
            a_plus_b = i + j
            inc = range_total(j+1, a_plus_b)
            ans += inc
    print(ans)


main()

Submission status: Wrong Answer

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

for i in range(0, n-2):
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      if (l[i] >= l[j] + l[k]) or (l[j] >= l[i] + l[k]) or (l[k] >= l[i] + l[j]):
        break
      else:
        c = c + 1
    else:
      continue
    break
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int, input().split()))
LM = 2000
L.sort()
dp = [0] * LM
pp = [0] * LM
for l in range(L[0] + L[1]):
    dp[l] = 1

ans = 0
for i in range(2,N):
    pp = dp
    dp = [0] * LM
    for l in range(L[0]+L[i]):
        dp[l] = pp[l] + i
    j = 1
    for l in range(L[0]+L[i], L[i]+L[i-1]):
        if l >= L[i] + L[j]:
            j += 1
        dp[l] = pp[l] + i - j
    ans += pp[L[i]]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
# input
_ = int(input()) 
bars = list(map(int, input().split()))
bars = list(set(bars))
n = len(bars)
count = 0

for i in range(n):
    bar1 = bars[i]
    for j in range(i+1, n):
        bar2 = bars[j]
        for k in range(j+1, n):
            bar3 = bars[k]
            cands = [bar1, bar2, bar3]
            if 2 * max(cands) < sum(cands):
                count += 1
            cands = []
print(count)

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

Submission status: Wrong Answer

Solution code:
#4 Triangles
import itertools
N = map(int, input())
L_list = list(map(int, input().split()))

#L_list = [3 4 2 1]なら[3,4,2],[3,4,1],[3,2,1],[4,2,1]の4通り
list_test = list(itertools.combinations(L_list,3))
print(list_test)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
cnt = 0
for i in range(2, len(l)):
    for j in range(i):
        for k in range(j+1, i):
            if l[i] < l[j] + l[k]:
                cnt = cnt + ((k-j)+(k-j)+(i-k-1))*(i-k)//2
                break
        else:
            continue
        break
print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect

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

chouhen = set()
kosuu = 0

for i in range(N):
    for j in range(i+1, N):
        a, b = min(L[i], L[j]), max(L[i], L[j])
        chouhen.add((a, b))

L.sort()

for hen in chouhen:
    hidari = max(hen[0] - hen[1], hen[1] - hen[0])
    migi = sum(hen)

    hidari_idx = bisect.bisect_right(L, hidari)
    migi_idx = bisect.bisect_left(L, migi)

    if L[hidari_idx] <= hen[0] <= L[migi_idx - 1]:
        kosuu -= 1
    if L[hidari_idx] <= hen[1] <= L[migi_idx - 1]:
        kosuu -= 1

    kosuu += migi_idx - hidari_idx

print(max(0, kosuu // 3))

Submission status: Wrong Answer

Solution code:
from collections import Counter

def tri_check(a,b,c):
  if a<b+c and b<a+c and c<a+b:
    return True
  else:
    return False

N = int(input())
L = list(map(int, input().split()))
S = Counter(L)
keys = list(S.keys())
keys.sort(reverse=True)
l_keys = len(keys)
ans = 0
for i in range(l_keys):
  for j in range(i+1,l_keys):
    for k in range(j+1,l_keys):
      a, b, c = keys[i],keys[j],keys[k]
      if tri_check(a,b,c):
        ans += S[a]*S[b]*S[c]
      else:
        break
    else:
      continue
    break
    
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
n=int(input())
List = [int(i) for i in input().split()]
List2=sorted(List)
ans = 0

for i in range(0,n-1): #aにたいし
  for j in range(i+1,n):
    #print(i,j)
    tmp1 = List2[i]
    tmp2 = List2[j]
    
    a=bisect.bisect_right(List2,tmp1+tmp2) -j-1
    ans += a
    #print(a,List2,tmp1,tmp2,j)
print(ans)

Submission status: Wrong Answer

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

from collections import Counter
c = Counter(l2)
k = list(c.keys())
k.sort()

from bisect import bisect_left, bisect_right
l2.sort()

ans = 0
for i in range(len(k)):
    for j in range(i+1, len(k)):
        c_min = k[j] - k[i]
        c_max = k[i] + k[j]

        idx = bisect_right(l2, k[j])
        tmp = l2[idx:]

        idx_min = bisect_right(tmp, c_min)
        idx_max = bisect_left(tmp, c_max)

        ans += max(0, idx_max - idx_min) * c[k[i]] * c[k[j]]

for _k in k:
    if c[_k] >= 2:
        idx = bisect_right(l2, _k)
        tmp = l2[idx:]
        idx_min = bisect_right(tmp, 0)
        idx_max = bisect_left(tmp, _k * 2)

        ans += max(0, idx_max - idx_min) * (c[_k] - 1) * c[_k] // 2

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
args = sys.argv
if len(args) == 2:
  from IPython import embed
  em = True
else:
  em = False
input = sys.stdin.readline
N  = int(input())
Ls = list(map(int, input().split()))
if em: sys.stdin = open('/dev/tty')
L_map = [0 for _ in range(1000 + 1)]
for L in Ls:
  L_map[L] += 1
ans = 0
for i in range(1, 1000):
  if L_map[i] == 0: continue
  for j in range(i, 1000 + 1):
    if i == j:
      a, b = 1 , L_map[j] - 1
    else:
      a, b = L_map[i] , L_map[j]
    L_map[i] -= 1
    L_map[j] -= 1
    ans += a * b * sum(L_map[max(j-i+1, j+1):i+j])
    L_map[i] += 1
    L_map[j] += 1
    if i == j:
      t = L_map[i]
      ans += int(t*(t-1)*(t-2) / (2*3))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
from collections import deque
def input():
    return sys.stdin.readline()[:-1]
# input
_ = int(input()) 
bars = list(map(int, input().split()))
bars = list(set(bars))
n = len(bars)
count = 0

for i in range(n):
    bar1 = bars[i]
    for j in range(i+1, n):
        bar2 = bars[j]
        for k in range(j+1, n):
            bar3 = bars[k]
            cands = [bar1, bar2, bar3]
            if 2 * max(cands) < sum(cands):
                count += 1
            cands = []
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import add, mul
from functools import reduce
import bisect


def nCr(n, r):
    r = min(r, n - r)
    num = reduce(mul, range(n, n - r, -1), 1)
    den = reduce(mul, range(1, r + 1), 1)
    return num // den


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

c = Counter(L)
l = list(c.keys())
l.sort()
len_l = len(l)
ans = 0

for li in l:
    if c[li] >= 3:
        ans += nCr(c[li], 3)

if len_l >= 2:
    for i in range(len_l - 1):
        for j in range(i + 1, len_l):
            if c[l[j]] >= 2:
                ans += nCr(c[l[j]], 2)
            if l[j] < 2 * l[i] and c[l[i]] >= 2:
                ans += nCr(c[l[i]], 2)

acu_cl = [0]
for li in l:
    acu_cl.append(acu_cl[-1] + c[li])

if len_l >= 3:
    for i in range(1, len_l - 1):
        for j in range(i + 1, len_l):
            k = bisect.bisect_left(l, l[j] - l[i] + 1, 0, i)
            ans += c[l[i]] * c[l[j]] * (acu_cl[i] - acu_cl[k])

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import bisect
def main():
    _ = int(input())
    l = list(map(int,input().split()))
    d = defaultdict(int)
    for i in l:
        d[i] += 1
    dk = sorted(list(d.keys()))
    dk2 = [i*2 for i in dk]
    ans = 0
    while dk:
        x = dk[-1]
        _ = dk2.pop(-1)
        bs = bisect.bisect(dk2,x)
        tmp = dk[bs:]
        if not tmp:
            break
        for i in tmp:
            for j in dk:
                if i+j > x and i >= j:
                    if i == j and i == x:
                        ans += d[x]*(d[x]-1)*(d[x]-2)//6
                    elif i == j:
                        ans += d[x]*d[i]*(d[i]-1)//2
                    elif i == x:
                        ans += d[x]*(d[x]-1)*d[j]//2
                    else:
                        ans += d[x]*d[i]*d[j]
        del dk[-1]
        if len(dk) < 3:
            break
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys


def create_triple(triple):
  if len(triple)==3:
    if triple[0]<triple[1]+triple[2] and triple[1]<triple[0]+triple[2] and triple[2]<triple[0]+triple[1]:
      ans.append(triple)
  
  for l in L:
    if l in triple: break
    create_triple(triple+[l])


N = int(sys.stdin.readline().strip())
L = [int(n) for n in sys.stdin.readline().strip().split()]

ans = []
create_triple([])
print(len(ans))

Submission status: Wrong Answer

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

result=0
dic={}
dic[0]=0

for i in range(1,a[-1]+1):
  if i in a:
    dic[i]=dic[i-1]+1
  else:
    dic[i]=dic[i-1]

#print(dic)
  
for i in range(n-2):
  for j in range(i+1,n-1):
    if a[i]+a[j]>a[j+1]:
      temp=a[i]+a[j]
      result+=max(0,dic[min(a[-1],temp-1)]-dic[a[j]])
      #print(a[i],a[j],a[j+1:],result)

print(result)

Submission status: Wrong Answer

Solution code:
N=int(input())
L_list=[int(thing) for thing in input().split()]
L_list.sort(reverse=True)

ret=0
for i in range(N):
    n=L_list[i]
    diff=0
    for j in range(i+1,N-1):
        k=L_list[j]
        m=n-k
        s= len([l for l in L_list[j + 1:N] if l > m])
        diff=diff+s
        if s==0:
            break
    if diff==0:
        break
    else:
        ret=ret+diff
print(ret)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int, input().split()))
d = sorted(d)[::-1]
ans = 1
for i in range(n-2):
  if d[i+2] + d[i+1] > d[i]:
    for j in range(i+1, n-1):
    	ans += len([j for k in range(j+1, n) if d[k] + d[j] > d[i]])
    print(ans)
  else:
    break
print(ans)

Submission status: Wrong Answer

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

count = 0
for i in range(n):
    start_j = i + 1
    a = l_list[i]
    for j in range(start_j, n):
        start_k = j + 1
        b = l_list[j]
        for k in range(start_k, n):
            c = l_list[k]
            if (a+b<=c or a+c<=b or b+c<=a):
                break
            
            count+=1

print(count)

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
l = list(map(int, input().split()))
l.sort()

cnt = 0
pre_a = -1
for i in range(N-1,1,-1):
    tmp = 0
    a = l[i]
    if pre_a==a:
        cnt += tmp
        continue
    lm = a//2
    for j in range(i-1,0,-1):
        b = l[j]
        if b<=lm:
            continue
        a_b = a+b
        for k in range(j):
            c = l[k]
            if (b+c>a):
                tmp += j-k
                break
    cnt += tmp
    pre_a = a
print(cnt)

Submission status: Wrong Answer

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

cnt = 0

for j in range(1,N-1):
  k=j+1
  for i in range(j-1,-1,-1):
    while True:
      
      if k == N or S[i]+S[j] <= S[k]:
        k-=1
        break
      k+=1
    #print(i,j,k)
    #print(S[i],S[j], S[j+1:k+1],k-j)
    cnt += k-j
      
         
        
print(cnt)

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

        for j in range((i+1), N):
            if L[i]/2 >= L[j]:
                break
            elif L[i] == L[j]:
                ans += len(L[j+1::])
                break
            
            #for k in range((j+1), N):
            #    if L[i] < (L[j]+L[k]):
            #        ans += 1

            ans += len([t for t in L[j+1::] if L[i] < (L[j]+t)])





    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def is_triangle(a,b,c):
    if a < b + c and b < c + a and c < a + b:
        return True
    else:
        return False

def combinations(iterable, r):
    cnt = 0
    pool = tuple(iterable)
    n = len(pool)
    if r > n:
        return
    indices = list(range(r))
    ret = tuple(pool[i] for i in indices)
    if is_triangle(ret[0], ret[1], ret[2]):
        cnt += 1
    while True:
        for i in reversed(range(r)):
            if indices[i] != i + n - r:
                break
        else:
            return
        indices[i] += 1
        for j in range(i+1, r):
            indices[j] = indices[j-1] + 1
        ret2 = tuple(pool[i] for i in indices)
        if is_triangle(ret2[0], ret2[1], ret2[2]):
            cnt += 1
    return cnt

cnt = combinations(L, 3)


print(cnt)

Submission status: Wrong Answer

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

L_sort = sorted(L, reverse=True)

c = 0
for i in range(0, N - 2):
    for j in range(i + 1, N - 1):
        k = j + 1
        while k <= N - 1 and int(L_sort[j]) + int(L_sort[k]) > int(L_sort[i]):
            c += 1
            k += 1

print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int , input().split()))
l = sorted(l, key=None, reverse=True)
ans = 0
for i in range(0, n):
    for j in range(i + 1, n):
        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]:
                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 = sorted(l, key=None, reverse=True)
ans = 0
for i in range(0, n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            print(i,j,k)
            if l[i] < l[j] + l[k] and l[j] < l[i] + l[k] and l[k] < l[i] + l[j]:
                ans += 1
                print('ok')
            else:
                print('break')
                break
        else:
            continue
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = [int(x) for x in input().split()]

L = sorted(L)
ans = 0
for i in range(N - 2):
    if L[N - 1] < L[i] * 2:
        break
    for j in reversed(range(i + 2, N)):
        if L[j] < L[i] * 2:
            break
        k = j - 1
        while L[k] > L[j] - L[i] and k > i:
            ans += 1
            k -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = []
l[:] = map(int,input().split())
l.sort()

c = 0
for i in range(0,n-2):
    if (l[i]+l[i+1]>l[i+2]):
        continue
    for j in range(i+1, n-1):
        if(l[i]+l[j]>l[j+1]):
            continue
        for k in range(j+1, n):
            if(l[i]+l[j]>l[k]):
                c+=1
            else:
                continue
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted(map(int, input().split()))
ans = 0

print(A)
for i in range(0, N-2):
       for k in range(i+1, N-1):
            for l in range(k+1, N):
                if A[i]+A[k] > A[l]:
                    ans +=  1
                elif A[i]+A[k] <= A[l]:                  
                    break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int, input().split()))
count = 0
for l in range(0,N-3,1):
  for m in range(1,N-2,1):
    for n in range(2,N-1,1):
      a, b, c = L[l], L[m], L[n]
      if a < b+c and b < c+a and c < a+b: count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
ans = 0
L.sort()
tmp = 0
nc = 0
jud = False
for na,a in enumerate(L[:N-2]):
    for nb_,b in enumerate(L[na+1:N-1]):
        nb = nb_+na+1
        if tmp-b >= 0 and nc-nb>0:
            ans += nc-nb
            continue 
        
        for nc_,c in enumerate(L[nb+1:]):
            nc = nc_+nb+1
            if c >= a+b:
                tmp = c-a-b
                ans += nc-nb-1
                break
        else:
            ans += (nc-nb)*(nc-nb+1)//2
            break

print(ans)

Submission status: Wrong Answer

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

s_num = sorted(num, reverse=True)

c = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(1,n-j):
            if s_num[i] - s_num[j] < s_num[-k]:
                print(s_num[i],s_num[j],s_num[-k])
                c += (n - j - k)
                break
                
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
L_list = list(map(int,input().split()))
ans = 0
L_list.sort()

for i in range(N-2):
    J = i+1
    for x in range(N-i-1):
        j = J+x
        K = j+1
        for y in range(N-j-1):
            k = K+y
            print(L_list[i],L_list[j],L_list[k])
            if L_list[i] + L_list[j] > L_list[k]:
                ans += 1
            else:
                break

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
N = int(input())
L = set(map(int,input().split()))
L = itertools.combinations(L,3)
ans = 0
for a,b,c in L:
  if a + b > c and b + c > a and c + a > b:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

L = list(map( lambda x:int(x), input().split(" ") ))

L = sorted(L, reverse=True)

count = 0

for i1 in range(0, len(L)-2):
    for i2 in range(i1+1, len(L)-1):
        flag = False
        for i3 in range(i2+1, len(L)):
            a = L[i1]
            b = L[i2]
            c = L[i3] 
        
            # discount if-then
            if(a<b+c):
                count += 1
            else:
                flag=True
                break
        if flag:
            break
                
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
import bisect
for i in range(n):
    for j in range(n):
        if i<j:
            a=l[i]
            b=l[j]
            x=bisect.bisect_left(l,a+b)
            y=bisect.bisect_right(l,b-a)
            if b-a>a:
                ans+=max(0,x-y-1)
            else:
                ans+=max(0,x-y-2)
print(ans//3)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
t = 2
c = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        tem = 0
        for k in range(max(t, j + 1), n):
            if l[i] + l[j] > l[k]:
                tem += 1
                c += 1
            else:
                c += ((tem * (tem - 1)) // 2)
                t = k
                break
print(c)

Submission status: Wrong Answer

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

def calc(N, sticks):
    sums = [0 for i in range(1001)]
    for stick in sticks:
        for i in range(stick + 1):
            sums[i] += 1
    total = 0
    for i in range(N):
        for j in range(N):
            if i == j: continue
            a, b = sticks[i], sticks[j]

            lo = abs(b-a)+1
            hi = min(a+b, 1000)
            
            val = sums[lo] - sums[hi] - (lo <= a) - (lo <= b)
            if val <= 0: continue
            total += val
    return total // 6

print(calc(N, sticks))

Submission status: Wrong Answer

Solution code:
import itertools
input()
L = sorted(map(int, input().split()))
D = [1 for a,b,c in itertools.combinations(L, 3) if a+b<c]
print(len(D))

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int, input().split()))
L.sort()
count = 0
for i, l1 in enumerate(L):
    for k, l2 in enumerate(L[i+1:]):
        num = i + k + 2
        for l3 in L[num:]:
            if l1 + l2 > l3:
                break
            if l1 < l2 + l3 and l2 < l1 + l3 and l3 < l2 + l1:
                count += 1
            else:
                break

print(count)

Submission status: Wrong Answer

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

l = sorted(l, reverse = True)
count = 0
d = []
for i in range(n-1):
    if l[i] == l[i+1]:
        count += 1
    else:
        if count >= 2:
            d.append(l[i])
        count = 0
if count >= 2:
    d.append(l[i])

for i in range(len(d)):
    l = [j for j in l if j != d[i]]
    l.append(d[i])
    l.append(d[i])

l = sorted(l, reverse = True)
ans = len(d)
x = []
for i in range(len(l)-2):
    for j in range(len(l)-2-i):
        if l[i] > 2 * l[i+j+1]:
            break
        for k in range(len(l)-2-i-j):
            if l[i] < l[i+j+1] + l[i+j+k+2]:
                if [l[i], l[i+j+1], l[i+j+k+2]] not in x:
                    x.append([l[i], l[i+j+1], l[i+j+k+2]])
                    ans += 1
            else:
                break
print(ans)