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

Solution code:

N = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
import bisect
for i in range(N-2):
    
    for j in range(i+1,N-1):
        a = L[i]
        b = L[j]
        k = bisect.bisect_left(L,a+b)
        l = bisect.bisect_left(L,b-a)
        ans += k-max(j+1,l)
print(ans)

"""
N,M,L = map(int,input().split())
## ダイクストラ法とは、グラフの""""""を求めるアルゴリズム
## 条件として、1.グラフに負辺がないこと(もちろん負の閉路はない)が必要
## DP的な発想
## 計算量はO((V+E)logV)
import heapq # 二分ヒープ
class Dijkstra: # 最短経路問題 V=ノード数,E=エッジ数とすると、計算量はO((V+E)logV)
    def __init__(self, route_map, start_point, goal_point=None):
        self.route_map = route_map #
        self.start_point = start_point # スタート位置
        self.goal_point = goal_point

    def execute(self):
        
        num_of_city = len(self.route_map) # ノード数
        dist = [float("inf") for _ in range(num_of_city)] # startからの距離を格納する
        prev = [float("inf") for _ in range(num_of_city)] # prev[i]:ノードiに向かう前のノード番号。これを持っておけば、goalからstartまで辿れる
        dist[self.start_point] = 0 # スタート位置までのコストは0
        heap_q = [] # 優先度つきキュー
        heapq.heappush(heap_q, (0, self.start_point)) # タプル(0,スタート位置)をheap_qに追加
        while len(heap_q) != 0:
            prev_cost, src = heapq.heappop(heap_q) # 直前にheap_qに入れたタプルから取り出す(src＝ソース)
            if dist[src] < prev_cost: # もし、スタート位置からsrcまでの距離がprev_costより小さいなら問題ないのでok
                continue
            for dest, cost in self.route_map[src].items(): # destはsrcから行ける頂点(目的地)
                if cost != float("inf") and dist[dest] > dist[src] + cost: # もし、destに有限のコストで行けて、srcからdestに行くのがスタートからの現状の最短距離になるなら、(単純な枝刈り by yosupot)
                    dist[dest] = dist[src] + cost # 更新する
                    heapq.heappush(heap_q, (dist[dest], dest)) # 更新したのでheap_qに入れておく。次のノードに移動した時に取り出して無駄な変更がないか確認する
                    prev[dest] = src
        if self.goal_point is not None: # ゴールまでの最短経路を返す
            return self.get_path(self.goal_point, prev)
        else: # スタートから各頂点までの最短距離を格納したリストを返す
            return dist

    def get_path(self, goal, prev):  # prev[i]:ノードiに向かう前のノード番号。これを持っておけば、goalからstartまで辿れる
        
        dest = goal # 目的地
        path = [goal] # 目的地の直前のノード
        while prev[dest] != float("inf"): # prev[start]はfloat("inf")になり、停止する
            
            path.append(prev[dest]) # 後ろから戻っていく
            dest = prev[dest]
        return list(reversed(path)) # 逆から辿ったので順を元に戻す

# 上のDijkstraを使う場合、隣接行列は辞書型でなくてはならない

D = [dict() for _ in range(N)]

for i in range(M):
    a,b,c = map(int,input().split())
    D[a-1][b-1] = c
    D[b-1][a-1] = c

Q = int(input())
for q in range(Q):  
    s,t = map(int,input().split())
    s-=1
    t-=1
    Dist = Dijkstra(D,s,t)
    path = Dist.execute()
    print(path)
    if len(path)==1:
        print(-1)
    else:
        now = L
        ans = 0
        for i in range(1,len(path)):
            if now>=D[path[i]][path[i-1]]:
                now -= D[path[i]][path[i-1]]
            else:
                ans += 1
                now = L+now-D[path[i]][path[i-1]]
        print(ans)

"""
N = int(input())
A = list(map(int,input().split()))
A.sort()
def RLE(S): # 文字列のランレングス圧縮(RunLengthEncoding)
    res = []
    if len(S)==0:
        return res
    now = S[0]
    id = 1
    num = 1
    while id < len(S):
        if now==S[id]:
            num+=1
            id+=1
        else:
            res.append(num)
            now=S[id]
            num=1
            id+=1
    res.append(num)
    return res # list[tuple(str,int),...]
B = RLE(A)
B.sort()

class BIT():
    def __init__(self,n):
        self.unity_sum = 0
        self.n = n
        self.dat = [0]*(n+1)


    def add(self,a,x): # a(0-indexed)番目の要素がx個追加される
        a += 1 # 本来は1-indexedなのでここで調整
        i = a
        while i < self.n:
            self.dat[i] += x
            i += i&-i

    def sum1(self,a): # 1番目からa(0-indexed)番目の要素の個数の総和
        a += 1 # 本来は1-indexedなのでここで調整
        i = a
        res = 0
        while i > 0:
            res += self.dat[i]
            i -= i&-i
        return res

    def sum2(self,a,b): # [a,b) a(0-indexed)番目からb(0-indexed)番目の要素の個数の総和
        return(sum1(b)-sum1(a))

    def search(self,k): # k(0-indexed)番目の数を二分探索
        k += 1
        res = 0
        N = 1
        while N < self.n:
            N *= 2

        i = N // 2
        while i > 0:
            if res+i < self.n and dat[res+i] < k:
                k -= dat[res+i]
                res += i
                i //= 2
        return res+1

T = BIT()

Submission status: Runtime Error

Solution code:
N = int(input())
L = list(map(int, input().split()))
C = sorted(L)
def X(n,j):
    L1 = j+1
    L2 = N-1
    while L1 != L2:
        a = (L1+L2)//2
        if C[a] == n:
            while C[a] == C[a-1]:
                a = a-1
            if j+1 <= a:
                return len(C[j+1:a])
            else:
                return 0
        elif L2 - L1 <= 1:
            while C[L1] == C[L1-1]:
                L1 = L1-1
            if C[L1] > n:
                return len(C[j+1:L1])
            elif C[L1] < n < C[L2]:
                return len(C[j+1:L2])
            else:
                return len(C[j+1:L2+1])
        elif C[a] < n:
            L1 = a
        else:
            L2 = a
    if C[L1] < n:
        return 1
    else:
        return 0
ans = 0
# print(C)
for i in range(N-2):
    for j in range(i+1,N-1):
        # print(X((C[i]+C[j]),j))
        ans += X((C[i]+C[j]),j)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
L = list(map(int, input().split()))
C = sorted(L)
def X(n,j):
    L1 = j+1
    L2 = N-1
    while L1 != L2:
        a = (L1+L2)//2
        if C[a] == n:
            while C[a] == C[a-1]:
                a = a-1
            return len(C[j+1:a])
        elif L2 - L1 <= 1:
            while C[L1] == C[L1-1]:
                L1 = L1-1
            if C[L1] > n:
                return len(C[j+1:L1])
            elif C[L1] < n < C[L2]:
                return len(C[j+1:L2])
            else:
                return len(C[j+1:L2+1])
        elif C[a] < n:
            L1 = a
        else:
            L2 = a
    if C[L1] < n:
        return 1
    else:
        return 0
ans = 0
# print(C)
for i in range(N-2):
    for j in range(i+1,N-1):
        # print(X((C[i]+C[j]),j))
        ans += X((C[i]+C[j]),j)
print(ans)

Submission status: Runtime Error

Solution code:
s = 0
for i in range(N-2):
    for j in range(i + 1, N-1):        
        if L[j + 1] > abs(L[i] - L[j]):
            s += N - (j + 1)
            k = N - 1
            while True:
                if L[k] > abs(L[i] - L[j]):
                    break
                else:
                    s -= 1
                    k -= 1
print(s)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from bisect import bisect_left
n=int(input())
l=list(map(int,input().split()))
l.sort()

ans=0
for a in range(n-2):
    for b in range(a+1,n-1):
        r=bisect_left(l, l[a] + l[b], b + 1, n)
        l=b+1
        ans+=r-l
        
print(ans)

Submission status: Runtime Error

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

for i in range(n):
    for j in range(i+1,n):
        k = bisect.bisect_left(l,l[i]+l[j])
        if k > j:
            cnt += k - j - 1
        else:
            continue
            
print(cnt)

Submission status: Runtime Error

Solution code:
import itertools
n = int(input())
a = list(map(int,input().split()))
s = itertools.permutations(n,3)
count = 0
for i in range(len(s)):
  r = [a[s[0]],a[s[1]],a[s[2]]]
  if (sum(r) - max(r)) >= max(r):
    count += 1
print(count)

Submission status: Runtime Error

Solution code:
mod = 10**9 + 7
import numpy as np

def main():
    N = iip(listed=False)
    L = iip(True)
    L.sort()
    L = np.array(L)

    ret = 0
    for i in range(N):
        for j in range(i+1, N):
            minl = L[j]-L[i]
            maxl = L[j]+L[i]

            left = np.searchsorted(L, minl, "left")
            left = max(j+1, left)

            right = np.searchsorted(L, maxl)
            #print(L[i], L[j], left, right)

            ret += (right-left)
    print(ret)




#####################################################ライブラリ集ここから

def iip(listed):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <=0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n-r+1, n+1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r+1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        #print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

    # O(N^2 * logN)の全探索で解く
    ans = 0
    for a_i in range(N):
        for b_i in range(a_i+1, N):
            c_i = bisect.bisect_left(Ls, Ls[a_i]+Ls[b_i])
            if c_i > b_i:
                ans += c_i - b_i - 1
            else:
                pass

    print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
Ls = list(map(int, input().split()))
Ls.sort()
# O(N^2 * logN)の全探索で解く
ans = 0
for a_i in range(N):
  for b_i in range(a_i+1, N):
    c_i = bisect.bisect_left(Ls, Ls[a_i]+Ls[b_i])
    if c_i > b_i:
　     ans += c_i - b_i - 1
    else:
       pass
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import numba

@numba.jit(nopython=True)
def main(ls):
    total = 0

    for i in range(len(ls) - 2):
        for j in range(i + 1, len(ls) - 1):
            a = ls[i]
            b = ls[j]
            ls2 = ls[j + 1:]
            if a + b == ls2[0]:
                 num = 0
            else:
                 num = np.searchsorted(ls2, a + b, side='right')
            total += num

    print(total)


_n = input()
ls = np.array(list(sorted(map(int, input().strip().split()))))

main(ls)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;


int main() {
    int n; cin >> n;
    vector<ll> l(n);
    rep(i, n) cin >> l[i];
    sort(all(l));

    ll ans = 0;
    rep(i, n) {
        for (int j=i+1;j<n;++j) {
            int k = lower_bound(all(l), l[i] + l[j]) - l.begin();
            ans += max(k - (j + 1), 0);
        }
    }

    cout << ans << endl;
}

Submission status: Runtime Error

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

dic = {}
ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    tmp = l[i] + l[j]
    
    index2 = dic.get(tmp, -1)
    
    if index2 == -1
      index2 = bisect.bisect_left(l, tmp)
      dic[tmp] = index2
      
    index1 = dic.get(l[j], -1)
    if index1 == -1:
      index1 = bisect.bisect_left(l, l[j])
      dic[l[j]] = index1     
    
    if l[i] == l[j]:
      d = index2 - index1 - 2
    else:
      d = index2 - index1 - 1
    
    ans += max(d,0)
    
print(ans)

Submission status: Runtime Error

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

dic = {}
ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    tmp = l[i] + l[j]
    
    index2 = dic.get(tmp, -1)
    
    if index2 == -1
      index2 = bisect.bisect_left(l, tmp)
      dic[tmp] = index2
      
    index1 = dic.get(l[j], -1)
    if index == -1:
      index1 = bisect.bisect_left(l, l[j])
      dic[l[j]] = index1     
    
    if l[i] == l[j]:
      d = index2 - index1 - 2
    else:
      d = index2 - index1 - 1
    
    ans += max(d,0)
    
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
l = list(map(int, input().split()))
l = sorted(l)
ans = 0
for i in range(n):
  a = l[i]
  for j in range(i + 1, n):
    b = l[j]
    bel1 = j #OK
    up1 = n #OUT
    while up1- bel1 > 1:
      mid = (bel1 + up1)//2
      if a + b > l[mid]:
        bel1 = mid
      else:
        up1 = mid
    ans += (bel1-j)
print(ans)

Submission status: Runtime Error

Solution code:
a = int(input())
l =  [int(x) for x in input().split()]

def ntuple(n, l,t=[], r=[]):
  for i in range(len(l)):
    if len(t) == n-1:
      r.append(t+[l[i]])
    r += ntuple(n, l[i+1:], t+[l[i]], [])
  return r

a = ntuple(3, l)
c = 0
for x in a:
  if (x[0] < x[1] + x[2]) and (x[1] < x[2] + x[0]) and (x[2] < x[0] + x[1]):
    c += 1

print(c)

Submission status: Runtime Error

Solution code:
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            array = [L[i],L[j],L[k]]
            if(array[0]>=array[1]+array[2]):
                break
            else:
                num += 1
print(num)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from sys import stdin
import bisect
        
N = int(stdin.readline().rstrip())
L = [int(x) for x in stdin.readline().rstrip().split()]
L.sort()
 
ans = 0
for a in range(len(L)-2):
    for b in range(a + 1, len(L)-1):
        c = bisect.bisect_left(L, L[a] + L[b])
        	ans += c - 1 - b
 
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import combinations
import numpy as np

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

hoge = np.sort(l)
ans = 0

for v in combinations(hoge, 3):
    if v[2] < v[0] + v[1]:
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy
from math import ceil, floor

def main():
  n  = int(input())
  Ls = list(map(int, input().strip().split()))
  Ls = numpy.sort(numpy.array(Ls))
  counts  = numpy.zeros(2*10**3+1, dtype=numpy.int)
  for L in Ls:
    counts[:L+1] += 1
    
  count =0 
  for i in range(n-2):
    for j in range(i+1, n-1):
      if Ls[i] == Ls[j]:
        x = 2
      else:
        x = 1
      count +=  max((counts[Ls[j]]-x) - counts[Ls[i]+Ls[j]], 0)
  print(count,'x')
  
if __name__=='__main__':
  main()

Submission status: Runtime Error

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

counts = {}
x = v[0]
c = 0
for i in v:
    if i != x:
        counts[x] = c
        x = i
        c = 0
    c += 1
counts[x] = c

v1 = list(counts)

sums = [0]
for i in range(1, 1005):
    try:
        sums.append(v1.index(i))
    except ValueError:
        sums.append(sums[-1])


total = 0
for i, x in enumerate(v1[:n-2]):
    if x == 1:
        continue
    for j, y in enumerate(v1[i+1:n-1]):
        total += (sums[min(1004, x+y-1)] - sums[y])



for i, c in counts.items():
    if c >= 2:
        total += (sums[min(1004, 2*i-1)] - sums[c])





# v3
total += sum(True if c >= 3 else False for c in counts.values())


print(total)

Submission status: Runtime Error

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

counts = {}
x = v[0]
c = 0
for i in v:
    if i != x:
        counts[x] = c
        x = i
        c = 0
    c += 1
counts[x] = c

v1 = list(counts)

sums = [0]
for i in range(1, 1005):
    try:
        sums.append(v1.index(i))
    except ValueError:
        sums.append(sums[-1])


total = 0
for i, x in enumerate(v[:n-2]):
    if x == 1:
        continue
    for j, y in enumerate(v[i+1:n-1]):
        total += (sums[min(1004, x+y-1)] - sums[y])



for i, c in counts.items():
    if c >= 2:
        total += (sums[min(1004, 2*i-1)] - sums[c])





# v3
total += sum(True if c >= 3 else False for c in counts.values())


print(total)

Submission status: Runtime Error

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

counts = {}
x = v[0]
c = 0
for i in v:
    if i != x:
        counts[x] = c
        x = i
        c = 0
    c += 1
counts[x] = c

v1 = list(counts)

sums = [0]
for i in range(1, 1001):
    try:
        sums.append(v1.index(i))
    except ValueError:
        sums.append(sums[-1])


total = 0
for i, x in enumerate(v[:n-2]):
    if x == 1:
        continue
    for j, y in enumerate(v[i+1:n-1]):
        total += (sums[min(1000, x+y-1)] - sums[y])



for i, c in counts.items():
    if c >= 2:
        total += (sums[min(1000, 2*i-1)] - sums[c])





# v3
total += sum(True if c >= 3 else False for c in counts.values())


print(total)

Submission status: Runtime Error

Solution code:
def main():
    import bisect
    N = int(input())
    L = sorted([int(x) for x in input().split()])

    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            a = L[i]
            b = L[j]
            lo = bisect.bisect_right(L, b-a, lo=j+1)
            if lo == len(N):
                continue 
            # print(i, j, a, b, L[lo])
            # if lo <= j:
            #     continue
            hi = bisect.bisect_left(L, a+b, lo=j+1)
            ans += (hi - lo)
            # print(a, b, L[lo:hi])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import itertools

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

l = list(itertools.combinations(l,3))
# print(l)

for i in l:
    if(i[0]+i[1]<i[2] :
        continue
    if i[0]+i[2]<i[1] :
        continue
    if i[1]+i[2]>i[0]):
        count+=1
print(count)

Submission status: Runtime Error

Solution code:
import itertools

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

l = list(itertools.combinations(l,3))
# print(l)

for i in l:
    if(i[0]+i[1]<i[2] :
        continue
    elif i[0]+i[2]<i[1] :
        continue
    elif i[1]+i[2]>i[0]):
        count+=1
print(count)

Submission status: Runtime Error

Solution code:
import itertools

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

l = list(itertools.combinations(l,3))
# print(l)

for i in l:
    if(i[0]+i[1]<i[2] :
        continue
    and i[0]+i[2]<i[1] :
        continue
    and i[1]+i[2]>i[0]):
        count+=1
print(count)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int N;
    cin>>N;
    vector<int> L(N);
    for (int &l: L)
        cin>>l;

    sort(L.begin(), L.end());
    int ans = 0;
    for (int i=0; i<N; i++)
    {
        int j = i+1;
        for (int k=i+2; k<N; k++)
        {
            while (j<k && L[i]+L[j]<=L[k])
                j++;
            ans += k-j;
        }
    }
    cout<<ans<<endl;
}

Submission status: Runtime Error

Solution code:
import bisect

n = int(input())
l = sorted([int(i) for i in input().split()])
ans = 0
for d in range(n):
    for e in range(d+1, n):
        a, b = l[d], l[e]
        idx = bisect.bisect_left(l, a + b)
        ans += max(idx - e - 1,)
print(ans)

Submission status: Runtime Error

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

if len(set(L)) > 3:
  L = list(set(L))

ans = 0
for a in range(0, N-2):
  for b in range(a+1, N-1):
    for c in range(b+1, N):
      if L[a] < (L[b]+L[c]):
        if L[b] < (L[a]+L[c]):
          if L[c] < (L[a]+L[b]):
            ans += 1

print(ans)

Submission status: Runtime Error

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

ans = 0
for a in range(0, N-2):
  for b in range(a+1, N-1):
    for c in range(b+1, N):
      if L[a] < (L[b]+L[c]):
        if L[b] < (L[a]+L[c]):
          if L[c] < (L[a]+L[b]):
            ans += 1

print(ans)

Submission status: Runtime Error

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

count = 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]:
                if L[j] < L[i] + L[k]:
                    if L[k] < L[i] + L[j]:
                        count += 1

print(count)

Submission status: Runtime Error

Solution code:
def triangle(a, b, c):
    return (a < b + c) and (b < a + c) and (c < a + b)


def main():
    N = int(input())
    ll = input().split(" ")
    ll.sort()
    ll.reverse()
    L = []
    M = []
    tmp = ''
    for l in ll:
        if tmp != l:
            L.append(int(l))
            tmp = l
        else:
            M.append(int(l))
    result = 0
    # 3辺相異なるとき
    for i in range(len(L)):
        for j in range(i + 1, len(L)):
            a = L[i]
            b = L[j]
            for k in range(j + 1, len(L)):
                c = L[k]
                if triangle(a, b, c):
                    result += 1

    # 二等辺(正三角形含む)
    tmp = False
    for i in range(len(M)):
        a = M[i]
        for j in range(i + 1, len(M)):
            b = j[i]
            if a == b and tmp:
                tmp = True
                result += 1
            elif a == b and not tmp:
                continue
            elif triangle(a, a, b):
                tmp = False
                result += 1
            else:
                continue

    print(result)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

L.sort()

for i in range(n-2):
    for j in range(i+1, n):
        c = L[i]+L[j]
        l = j
        r = bisect.bisect_left(L, c, lo=l) -1
        ans += (r-l)

print(ans)

Submission status: Runtime Error

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

L.sort()

for i in range(n-2):
  for j in range(i+1, n):
    c = L[i]+L[j]
    l = j
    r = bisect.bisect_left(L, c, lo=l) -1
    ans += (r-l)

print(ans)

Submission status: Runtime Error

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

import bisect

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import bisect
from bisect import bisect_left

n = int(input()) #n行の入力をリストに入れる
l = []
for i in range(n):
    l.append(input()) 

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

print(result)

Submission status: Runtime Error

Solution code:
from bisect import bisect
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans = 0
b_c= [0]*n
for i  in range(n-2):
    a = l[i]
    pre_k = 2
    for j in range(i+1,n-1):
        b = l[j]
        max_c = a+b-1
        k = bisect(l[j+pre_k-1:],max_c)
        ans += (pre_k-2 + )
print(ans)

Submission status: Runtime Error

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 = abs(a-b)
    right = a+b
    ans += max(0, bisect_left(l, right) - bisect(l,left))
    if left < a < right:
      ans -= 1
    if left < b < right:
      ans -= 1
print(ans)

Submission status: Runtime Error

Solution code:
from bisect import bisect
N = int(input())
sides = sorted(map(int, input().split()))
print(sum(N - j - bisect(sides, sides[-i] - sides[-j], hi=N-j) for j in range(i + 1, N + 1) for i in range(1, N - 1)))

Submission status: Runtime Error

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

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

print(ans)

Submission status: Runtime Error

Solution code:
import bisect
from typing import List


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

  def n_possible_cs(a: int, b: int, first_ic: int) -> int:
    # 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: Runtime Error

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

nums.sort()
counts = 0

for i in range(n):
  start, end = 0, i - 1
  while start < end:
    if nums[start] + nums[end] > nums[i]:
      counts += end - start
      end -= 1
    else:
      start += 1
print(counts)

Submission status: Runtime Error

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

nums.sort()
res = 0
for k in range(n-1, 1, -1):
    i, j = 0, k-1
    while i < j and nums[i] + nums[j] <= nums[k]:
        i += 1
    while i < j and nums[i] + nums[j] > nums[k]:
        res += j - i
        j -= 1
print(res)

Submission status: Runtime Error

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

nums.sort()
res = 0
for k in range(n-1, 1, -1):
    i, j = 0, k-1
    while i < j and nums[i] + nums[j] <= nums[k]:
      	i += 1
    while i < j and nums[i] + nums[j] > nums[k]:
      	res += j - i
        j -= 1
print(res)

Submission status: Runtime Error

Solution code:
input = sys.stdin.readline
n = int(input())
nums = list(map(int, input().split()))
nums.sort(reverse=True)
ans = 0
for x in range(len(nums)):
    for y in range(x + 1, len(nums)):
        for z in range(y + 1, len(nums)):
            if nums[x] >= nums[y] + nums[z]:
                break
            #print("{} {} {}".format(x, y, z))
            ans = ans + 1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
dlist = list(map(int, input().split()))
dlist.sort(reverse=True)
sum = 0
N_2 = 2 ** N
for i in range(N_2):
    if bin(i).count('1') == 3:
        bin_i = bin(i)
        i_2 = bin_i.split('0b')[1]
        if len(i_2) < N:
            N_i = (N - len(i_2))
            N_0 = '0' * N_i
            i_2 = N_0 + i_2
        a_find = i_2.find('1')
        b_find = i_2.find('1',a_find + 1)
        c_find = i_2.find('1',b_find + 1)
        a = dlist[a_find]
        b = dlist[b_find]
        c = dlist[c_find]
        if a < b + c:
            sum += 1
print(sum

Submission status: Runtime Error

Solution code:
N=int(input())
L=list(map(int,input().split()))
L.sort()
L.reverse()
count=0
count1=0
a=len(L)
#print(L)
for i in range(a-2):
  for j in range(i+1,a-1):
    for k in range(j+1,a):
      if L[i]<L[j]+L[k]:
        #print(L[i],L[j],L[k])
      else:
        break

print(count)

Submission status: Runtime Error

Solution code:
import bisect

n = int(input())
s = list(map(int,input().split()))
l = sorted(s)
count = 0
for i in range(n-1):
    for j in range(i+1,n):
        limit = l[i] + l[j]
        count += bisect.bisect_left((l,limit)) - (j+1)

print(count)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
l.sort()
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      elif l[i]+l[j]>l[-1]:
        ans+=n-j-1
        break
      if l[i]+l[j]<=l[k] :
        ans+=k-j-1
        ans1+=k-j-1
        break
      
      
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
l.sort()
ans=0
ans1=0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+ans1,n):
      ans1=0
      elif l[i]+l[j]>l[-1]:
        ans+=n-j-1
        break
      if l[i]+l[j]<=l[k] :
        ans+=k-j-1
        ans1+=k-j-1
        break
      
      
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
l.sort()
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+ans1,n):
      ans1=0
      elif l[i]+l[j]>l[-1]:
        ans+=n-j-1
        break
      if l[i]+l[j]<=l[k] :
        ans+=k-j-1
        ans1+=k-j-1
        break
      
      
print(ans)