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:
# -*- coding:utf-8 -*-
import bisect

def solve():
    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+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)

if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
N = int(input())

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

L.sort()

count = 0

for i in range(N):
    for j in range(i+1, N):
        L_copy = L[:]
        a = L_copy.pop(i)
        b = L_copy.pop(j-1)
        start = j-2
        finish = N-3
        if j != 0:
            while L_copy[start] == L_copy[start-1]:
                start -= 1
        start_first = start
        while start < finish:
            n = finish - start + 1
            if L_copy[start + (n//2)] < a + b:
                start += (n//2)
            else:
                finish = start + (n//2)
        count += (finish - start_first + 1)
print(count)

Submission status: Runtime Error

Solution code:
n=int(input())
l=sorted(list(map(int,input().split())))
import bisect
count=0
for i in range(n-1):
  for j in range(1,n):
    if i==j:
      pass
    else:
      left=bisect.bisect_left(abs(l[i]-l[j]))
      right=bisect.bisect_right(l[i]+l[j])
      count+=right-left
print(count)

Submission status: Runtime Error

Solution code:
import bisect

n = int(input())
l = list(map(int,input().split()))
l.sort()
count = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        short_2hen = l[i] + l[j]
        l_long = l[j+1:n]
        bis = bisect.bisect_right(l_long, short_2hen-1)
        count += bis
        print(l_long)
        print(bis)
print(count)

Submission status: Runtime Error

Solution code:
import bisect

n=int(input())
*L,=map(int,input().split())

L.sort()

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

Submission status: Runtime Error

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

L.sort()
a=0
for i in range(N-2):
    for j in range(i+1,N-1):
        a+=bisect_left(L,L[i]+L[j])-j-1
print(result)

Submission status: Runtime Error

Solution code:
N=int(input())
L=map(int, input().split())
a=0
for i in range(0,N-2,1):
  for j in range(i+1,N-1,1):
    for q in range(j+1,N,1):
        if L[i]<L[j]+L[q] and L[j]<L[i]+L[q] and L[q]<L[i]+L[j]:
          a+=1
print(a)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

N = int(input())
L = list(map(int, input().split()))
 
L.sort()
 
from itertools import combinations
 
cb = combinations(L, 2)
cb = list(map(lambda x: sorted(x, reverse=True), cb))
# print(cb)
 
rslt = 0
m = 10000
 
if N-2 < m:
    m = N-2
 
for i in cb:
    set_L = L.copy()
    set_L.remove(i[0])
    set_L.remove(i[1])
    split_list = [set_L[i:i+m] for i in range(0, len(set_L), m)]
 
    for j in split_list:
        if i[0]-i[1]<j[0] and i[1]>=j[0]:
            if i[0]-i[1]<j[-1] and i[1]>=j[-1]:
                # 上界fit, 下界fit
                rslt = rslt + len(j)
            else:
                for k in j:
                    if i[0]-i[1]<k and i[1]>=k:
                        rslt = rslt + 1
                        #print(i, k)
        else:
            if i[0]-i[1]<j[-1] and i[1]>=j[-1]:
                for k in j:
                    if i[0]-i[1]<k and i[1]>=k:
                        rslt = rslt + 1
                        #print(i, k)
            else:
                # 上界fitしない, 下界しない
                None
 
print(rslt)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
l=[map(int,input().split())]
l.sort()
ans=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[k]<l[i]+l[j]:
        ans+=1
        
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[map(int,input().split)]
l.sort()
ans=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[k]<l[i]+l[j]:
        ans+=1
        
print(ans)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

using namespace std;

int main(){

    int n;
    cin >> n;
    vector<int> arr(n);
    for(int i = 0; i < n; i++)
        cin >> arr[i];

    sort(arr.begin(), arr.end());
    long long cnt = 0;
    for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
            int lb = arr[j] - arr[i] + 1;
            int up = arr[i] + arr[j] - 1;
            int tot = upper_bound(arr.begin(), arr.end(), up) - lower_bound(arr.begin(), arr.end(), lb);
            if( arr[i] >= lb )
                tot--;
            if( arr[j] >= lb )
                tot--;
            cnt += tot;
        }
    }

    cout << cnt/3 << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
N=int(inpiut())
L=list(map(int,input().split()))
ans=0
for i in range(N-2):
    for j in range(i,N-1):
        for k in range(j,N):
            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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import bisect

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

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

Submission status: Runtime Error

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

for i in range(n):
  for j in range(i,n):
    for k in range(j,n):
      if l[i]+l[j]>l[k] and l[j]+l[k]<l[i] and l[k]+l[i]<l[j]:
        count+=1
        
        
ptiny(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
L = []
for i in range(N):
    L.append(int(input()))

L.sort(reverse=True)
counter = 0
for i1 in range(len(L)-2):
    for i2 in range((i1+1),(len(L)-1)):
        for i3 in range((i2+1),len(L)):
            if L[i1] < L[i2]+L[i3]:
                counter += 1
print(counter)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left

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

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

Submission status: Runtime Error

Solution code:
mport bisect
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
 
 
def solve2():
    N = int(input())
    L = list(map(int, input().split()))
    L = sorted(L)
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            min_sum = L[i]+L[j]
            more_than = bisect.bisect_left(L[j+1:], min_sum)
            ans += more_than
    print(ans)
 
 
solve2()

Submission status: Runtime Error

Solution code:
N=int(input())
L=list(map(int,input().split()))
L.sort()
d=[]
def kinds(a,b,c):
  if a<b+c and b<a+c:
    if set([a,b,c]) not in d:
      d.append(set([a,b,c]))
for j in range(N):
  i=0
  while (N-1-j)-i+1>=3:
    if L[N-1-j]<N[i]+[i+1]:
      kinds(L[i],L[i+1],L[N-1-j])
    i+=1
print(len(d))

Submission status: Runtime Error

Solution code:
N=int(input())
L=list(map(int,input().split()))
d=[]
def triangles(a,b,c):
    if a<b+c and b<a+c and c<a+b:
        d.append([a,b,c])
    else:
        pass
for i in range(N-1):
    for j in range(i+1,N):
        for k in range(j+1,N+1):
              triangles(L[i],L[j],L[k])
                
print(len(set(d)))

Submission status: Runtime Error

Solution code:
N=int(input())
L=list(map(int,input().split()))
d=[]
def triangles(a,b,c):
    if a<b+c and b<a+c and c<a+b:
        d.append([a,b,c])
    else:
        pass
for i in range(N=1):
    for j in range(i+1,N):
        for k in range(j+1,N+1):
              triangles(L[i],L[j],L[k])
                
print(len(set(d)))

Submission status: Runtime Error

Solution code:
N=int(input())
L=list(map(int,input().split()))
d=[]
s=0
def triangles(a,b,c):
    if a<b+c and b<a+c and c<a+b:
        d.append([a,b,c])
    else:
        pass
for i in range(N):
    for j in range(N):
        for k in range(N):
            if i!=j and j!=k and k!=i:
              triangles(L[i],L[j],L[k])
                
print(len(set(d)))

Submission status: Runtime Error

Solution code:
N=int(input())
L=list(map(int,input().split()))
d=[]
s=0
def triagles(a,b,c):
    if a<b+c and b<a+c and c<a+b:
        d.append([a,b,c])
    else:
        pass
for i in range(N):
    for j in range(N):
        for k in range(N):
            if i!=j and j!=k and k!=i:
              triangles(L[i],L[j],L[k])
                
print(len(set(d)))

Submission status: Runtime Error

Solution code:
import itertools
n = input()
l = list(map(int,input().split()))
ans = 0
for i in list(itertools.combinations(l,3)):
    i.sort()
    a,b,c = i[0],i[1],i[2]
    if c<a+b:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
# https://atcoder.jp/contests/abc143/tasks/abc143_d
# -*- coding: utf-8 -*-

stick_cnt = int(input())
stick_len = list(map(int, input().strip().split()))

stick_sort = sorted(stick_len, reverse=True)

tri_cnt = 0
for i in range(0,stick_cnt-2):
    for j in range(i+1,stick_cnt-1):
        stick_slice = stick_sort[j+1:]
        work = stick_sort[i] - stick_sort[j]
        match = [i for i in stick_slice if i > stick_sort[k]]
        tri_cnt += len(match)

print(tri_cnt)

Submission status: Runtime Error

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

ans = 0
for i in range(n-1, 1, -1):
    for j in range(i-1, 0, -1):
        ans += j - bisect.bisect_right(L[:j], L[i]-L[j])

print(ans)

Submission status: Runtime Error

Solution code:
def func():
    N = int(input())
    li = sorted(list(map(int, input().split())))

    print(li)
    r = 0
    for i, n1 in enumerate(li):
        for j, n2 in enumerate(li):
            for k, n3 in enumerate(li):
                if j + 1 > N or k > N or i >= j or j >= k:
                    continue
                if i + 3 == N:
                    if n1 + n2 > n3:
                        r += 1
                    return r
　　　　　       if n1 + n2 > n3:
                    r += 1
                    print("r : " + str(r))
                else:
                    break

print(func())

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
res = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    s = j+1
    while a[i]+a[j] > a[s]:
      res += 1
      s += 1
print(res)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
res = 0
for i in range(n):
  for j in range(i+1,n):
    s = j+1
    while a[i]+a[j] > a[s]:
      res += 1
      s += 1

Submission status: Runtime Error

Solution code:
import numpy as np


def main():
    N = int(input())
    L = np.array([int(s) for s in input().split(" ")])astype(np.uint8)
    u = L[np.newaxis, :] + L[:, np.newaxis]
    l = np.abs(L[np.newaxis, :] - L[:, np.newaxis])
    u = np.resize(u, (N, N, N))
    l = np.resize(l, (N, N, N))
    L2 = np.resize(L, (N, N, N)).transpose((2, 0, 1))
    L3 = np.logical_and(L2 < u, L2 > l)
    a = np.identity(N) != 1
    a = np.resize(a, (N, N, N))
    b = a.transpose((1, 0, 2))
    c = a.transpose((2, 1, 0))
    d = np.logical_and(a, np.logical_and(b, c))

    count = np.sum(np.logical_and(L3, d))
    print(int(count / 6))


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

Submission status: Runtime Error

Solution code:
import numpy as np


def main():
    N = int(input())
    L = np.array([int(s) for s in input().split(" ")])
    u = L[np.newaxis, :] + L[:, np.newaxis]
    l = np.abs(L[np.newaxis, :] - L[:, np.newaxis])
    u = np.resize(u, (N, N, N))
    l = np.resize(l, (N, N, N))
    L2 = np.resize(L, (N, N, N)).transpose((2, 0, 1))
    L3 = np.logical_and(L2 < u, L2 > l)
    a = np.identity(N) != 1
    a = np.resize(a, (N, N, N))
    b = a.transpose((1, 0, 2))
    c = a.transpose((2, 1, 0))
    d = np.logical_and(a, np.logical_and(b, c))

    count = np.sum(np.logical_and(L3, d))
    print(int(count / 6))


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

Submission status: Runtime Error

Solution code:
n = int(input())
li = list(map(int,input().split()))
li2 = sorted(li,reverse=True)
cnt = 0

for i in range(n):
    for j in range(i+1,n):
        if li2[i] > li2[j] + li2[j+1]:
            break
        else:
            for k in range(j+1,n):
                if li2[i] < li2[j]+li2[k]:
                    cnt += 1
                else:
                    break
print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

int main() {
    vector<int> ll; 
    int n;
	cin >> n;
    for(int i=0; i<n; i++) {
    	int x;
    	cin >> x;
    	ll.push_back(x);
    }
    long long ans = 0;
    for(int i=0; i<n; i++) {
        for(int j=i+1; j<n; j++) {
            for(int k=j+1; k<n; k++) {
                if(ll[i] < ll[j] + ll[k] && ll[j] < ll[i] + ll[k] && ll[k] < ll[i] + ll[j]) {
                    ans += 1;
                }
            }
        }
    }
    cout << ans << '\n';
    
}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int main(){
    int N; cin >> N;
    vector<int> L(N);
    
    for (int i=0;i < N; i++) cin >> L.at(i);
    sort(L.begin(),L.end());

    int ans = 0;

    for(int i=0;i < N;i++){
        for(int j = i+1; j < N;j++){
            int it = lower_bound(L.begin(),L.end(),L.at(i) + L.at(j)) - L.begin();
            int an = it - (j + 1);
            /*
            cout << i << " " << j << endl;
            cout << it << " " << an << endl;
            cout << "------------------" << endl;
            */

            ans += max(it - (j + 1),0);
        }
    }

    cout << ans << endl;

    return 0;
}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int main(){
    int N; cin >> N;
    vector<int> L(N);
    
    for (int i=0;i < N; i++) cin >> L.at(i);
    sort(L.begin(),L.end());

    int ans = 0;

    for(int i=0;i < N;i++){
        for(int j = i+1; j < N;j++){
            int it = lower_bound(L.begin(),L.end(),L.at(i) + L.at(j)) - L.begin();
            int an = it - (j + 1);
            ans += it - (j + 1);
        }
    }

    cout << ans << endl;

    return 0;
}

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().split()))
d={i:l.count(i) for i in set(l)}
t=tuple(l.keys())
m=len(t)
T=0
for i in range(m-2):
  a=t[i]
  for j in range(m-i-1):
    b=t[i+j+1]
    for k in range(m-i-j-2):
      c=t[i+j+k+2]
      if a<b+c and b<c+a and c<a+b:
        T+=d[a]*d[b]*d[c]
print(T)

Submission status: Runtime Error

Solution code:
# ABC143D - Triangles
def binary_search(cur: int, upper_bound: int = 1 << 60, lower_bound: int = -1) -> int:
    ok, ng, ret = upper_bound, lower_bound, 0
    while abs(ok - ng) > 1:
        if L[ok] + L[ng] > cur:
            ret += ok - ng
            ok -= 1
        else:
            ng += 1
    return ret


def main():
    # fix the longest edge -> binary search
    N, *L = map(int, open(0).read().split())
    L.sort()
    ans = sum(binary_search(L[i], i - 1, 0) for i in range(N - 1, 1, -1))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def search(m,n,l): //startCは常に満たす、stopC+1は常に満たさない
  if l[0]<=m: return 0
  elif l[n-1]>m: return n
  startC,stopC=0,n-1
  while startC-stopC!=0:
    if l[(stopC-startC)>>1]<=m:
      stopC=startC-1+(stopC-startC)>>1
    else:
      startC+=(stopC-startC)>>1
  return stopC+1

n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    ans+=search(l[i]-l[j],n,l[j+1:]) //l[i]-l[j]<l[ans]を満たす最小のansを求める
print(ans)

Submission status: Runtime Error

Solution code:
def search(m,n,l): //startCは常に満たす、stopCは常に満たさない
  if l[0]<=m: return 0
  elif l[n-1]>m: return n
  startC,stopC=0,n
  while startC-stopC+1!=0:
    if l[(stopC-startC)>>1]>m:
      stopC=startC+(stopC-startC)>>1
    else:
      startC+=(stopC-startC)>>1
  return stopC

n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
ans=0
for i in range(n-2):
  for j in range(1,n-i-1):
    ans+=search(l[i]-l[j+i+1],n,l[j+i+2]) //l[i]-l[j]<l[ans]を満たす最小のansを求める

Submission status: Runtime Error

Solution code:
n = int(input())
li = list(map(int(input().split())))
li_asw = []
for i in range(n):
  for j in range(n):
    for k in range(n):
      if li[i] < li[j]+li[k] and li[j] <li[i]+li[k] and li[k]<li[i]+li[j]:
        li_a = [li[i], li[j], li[k]]
        li_asw.append(li_a.sort())
print(len(set(li_asw)))

Submission status: Runtime Error

Solution code:
n = int(input())
li = list(int(input().split()))
li_asw = []
for i in range(n):
  for j in range(n):
    for k in range(n):
      if li[i] < li[j]+li[k] and li[j] <li[i]+li[k] and li[k]<li[i]+li[j]:
        li_a = [li[i], li[j], li[k]]
        li_asw.append(li_a.sort())
print(len(set(li_asw)))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
l = list(map(int,input().split()))
import bisect
l.sort()
count = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        s = bisect.bisect_left(l[j+1:],l[a]+l[b])
        count += s
        # print(l,a,b,s)
print(count)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.radline
n = int(input())
l = list(map(int,input().split()))
import bisect
l.sort()
count = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        s = bisect.bisect_left(l[j+1:],l[a]+l[b])
        count += s
        # print(l,a,b,s)
print(count)

Submission status: Runtime Error

Solution code:
def comp(ext,list0,dev):
    if list0[int((ext[0]+ext[1])/2)]>dev:
        return ext[0],int((ext[0]+ext[1])/2)
    else:
        return int((ext[0]+ext[1])/2),ext[1]


def bis(a,b,list0,dev):
    ls=[a,b]
    while ls[0]+1<ls[1]:
        ls=comp(ls,list0,dev)
    if list0[ls[0]]==dev:
        return ls[0]-1
    elif list0[ls[1]]==dev:
        return ls[1]-1
    else:
        return ls[0]


n=int(input())
l=[int(x) for x in input().split()]
l.sort()
s=0
for a in range(0,n-2):
    for b in range(a+1,n-1):
        if l[a]+l[b]>l[n-1]:
            c=n-1
        elif l[a]+l[b]<l[b+1]:
            c=b
        else:
            c=bis(b+1,n-1,l,l[a]+l[b])
        s=s+c-b
print(s)

Submission status: Runtime Error

Solution code:
n=int(input())
l=int(input())
ans=0
for i in range(0,len(l)):
    for j in range(i+1,len(l)):
        for k in range(j+1,len(l)):
            if l[i]>=l[j] and l[i]>=l[k]:
                if l[i]>l[j]+l[k]:
                    ans+=1
                else:
                    ans+=0
            if l[j]>=l[i] and l[j]>=l[k]:
                if l[j]>l[i]+l[k]:
                    ans+=1
                else:
                    ans+=0
            if l[k]>=l[i] and l[k]>=l[j]:
                if l[k]>l[i]+l[j]:
                    ans+=1
                else:
                    ans+=0   
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
l=int(input())
ans=0
for i in range(0,len(l)):
  for j in range(i+1,len(l)):
    for k in range(j+1,len(l)):
      if l[i]>=l[j] and l[i]>=l[k]:
        if l[i]>l[j]+l[k]:
          ans+=1
        else:
          ans+=0
      if l[j]>=l[i] and l[j]>=l[k]:
        if l[j]>l[i]+l[k]:
          ans+=1
        else:
          ans+=0
      if l[k]>=l[i] and l[k]>=l[j]:
        if l[k]>l[i]+l[j]:
          ans+=1
        else:
          ans+=0   
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(int,input())
ans=0
for i in range(0,len(l)):
  for j in range(i+1,len(l)):
    for k in range(j+1,len(l)):
      if l[i]>=l[j] and l[i]>=l[k]:
        if l[i]>l[j]+l[k]:
          ans+=1
        else:
          ans+=0
      if l[j]>=l[i] and l[j]>=l[k]:
        if l[j]>l[i]+l[k]:
          ans+=1
        else:
          ans+=0
      if l[k]>=l[i] and l[k]>=l[j]:
        if l[k]>l[i]+l[j]:
          ans+=1
        else:
          ans+=0   
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(int,input())
ans=0
for i in range(0,len(l)):
  for j in range(i+1,len(l)):
    for k in range(j+1,len(l)):
      if i>=j and i>=k:
        if i>j+k:
          ans+=1
        else:
          ans+=0
      if j>=i and j>=k:
        if j>i+k:
          ans+=1
        else:
          ans+=0
      if k>=i and k>=j:
        if k>i+j:
          ans+=1
        else:
          ans+=0   
print(ans)

Submission status: Runtime Error

Solution code:
import bisect

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

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

print(sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input().split())
ns = input().split()

dic = {}

for i in range(N):
  	if(ns[i] in dic.keys() and dic[ns[i]]<2):
    	dic[ns[i]] += 1
    elif(ns[i] not in dic.keys()):
      	dic[ns[i]] = 1

a,b,c = 0,0,0
for i in range(N):
  	if(dic[ns[i]] == 1):
      	a += 1
    elif(dic[ns[i]] == 2):
      	b += 1
    elif(dic[ns[i]] == 3):
      	c += 1

unique = a+b+c
sum_ = 0

sum_ += c
sum_ += (b+c)*(unique-1)
sum_ += unique*(unique-1)*(unique-2)/6

print(sum_)

Submission status: Runtime Error

Solution code:
import numpy as np

L_MAX = 3000 + 7

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

cnt = np.zeros((L_MAX, ), dtype=np.int)
for i in range(N):
  cnt[L[i]] += 1

s = np.cumsum(cnt)

ans = 0
for _i in range(N*N):
  i, j = _i // N, _i % N

  if i == j: continue

  a, b = L[i], L[j]

  c_min, c_max = abs(a-b), abs(a+b)

  add = s[c_max-1] - s[c_min]
  if c_min < a < c_max: add -= 1
  if c_min < b < c_max: add -= 1

  ans += add

print(ans // 6)

Submission status: Runtime Error

Solution code:

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



cnt = 0
for i in range(len(L)):
    for j in range(i+1, len(L)):
        sum = L[i] + L[j]

        for k in range(j+1, len(L)):
            if sum > L[k]:
                cnt += 1

print(cnt)

Submission status: Runtime Error

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

print(N)
print(L)
L.sort()

print(L)

cnt = 0
for i in range(len(L)):
    for j in range(i+1, len(L)):
        sum = L[i] + L[j]

        for k in range(j+1, len(L)):
            if sum > L[k]:
                cnt += 1

Submission status: Runtime Error

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

L_list.sort()

from bisect import bisect_left
# print(bisect_left(L_list, 3))

for i in range(N):
    for j in range(i+1, N):
        t = L_list[i]+L_list[j]
        idx = bisect_left(L_list, t)
        sum += max(0, idx-(j+1))
        
print(sum)

Submission status: Runtime Error

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

for i in range(n-2):
  for j in range(n-i-1):
    a=ln[i]
    b=ln[i+j+1]
    #b+c>aを探す
    
    right=n-1
    left=i+j+2
    while left<=right :
      mid=int((right+left)/2)
      c=ln(mid)
      if(b+c)<a:    
        right=mid-1
      else :
        left=mid+1
    c=ln[left]
    if b+c>a :
      ans+=left-(i+j+1)

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import bisect
n = int(input())
l = np.array(list(map(int, input().split())))
l = np.sort(l)
l_unique, l_uniue_index = np.unique(l, return_counts = True)
m = len(l_unique)
ans = 0

ans += len(np.where(l_uniue_index >= 3)[0])
print(ans)

for a in l_unique[np.where(l_uniue_index >= 2)[0]]:
    ans += bisect.bisect_left(l_unique, a * 2) - 1
print(ans)    
    
for i in range(m):
    for j in range(i+1, m):
        ans += bisect.bisect_left(l_unique[j+1:], l_unique[i] + l_unique[j])
print(ans)

Submission status: Runtime Error

Solution code:
#143d
from itertools import combinations
from bisect import bisect_left, bisect_right

N = int(input()) #2*10**3

L_list = [int(e) for e in input().split()]
index_list = [i for i in range(N)]

L_list.sort()

ans = 0

for comb in combinations(index_list, 2): #(2*10*3)*(2*10*3 -1)/2 ≒ 2*10*6
    print(comb," ",end="")
    a = L_dict[comb[0]]
    b = L_dict[comb[1]]
    
    #print("min:",b,"max:",a+b,"……",end="") #a,b a <= b   #c < a+b かつ c > b (三角形を作る為。)
    
    index_left = bisect_left(L_list, a+b) #log(2*10**6)≒6.3
    index_right = bisect_right(L_list, b) #log(2*10**6)
    
    #print(index_left,index_right)
    
    ans += index_left - index_right
    
print(ans)

Submission status: Runtime Error

Solution code:
import bisect
N=int(input())
L=list(map(int, input().split()))
ans=0
L_LENGTH=len(L)
L=sorted(L)
for i in range(L_LENGTH-2):
    for j in range(i+1, L_LENGTH-1):
        a=L[i]+L[j]
        idx=bisect.bisect_left(l, t)
        ans+=max(0, idx-j-1)
print(ans)

Submission status: Runtime Error

Solution code:
import bisect
from itertools import combinations
from collections import Counter
import numpy as np


N = int(input())
l = map(int,input().split())
l = sorted(l)
l_dict = dict()
c = Counter(l)
set_l = set(c.keys())

unique_num  = len(set_l)
count_list = [0 for _ in range(unique_num)]
for i,one in enumerate(set_l):
    l_dict[one] = i
    count_list[i] = c[one]

count_list = np.array(count_list)
cumsum_list = list(count_list[::-1].cumsum()[::-1])


    
counter = 0
if len(set_l) >= 3:
    # 辺の長さが全て違うやつ
    for a,b in combinations(set_l,2):
        tmp = a + b
        ref = bisect.bisect_left(set_l,tmp)
        counter += cumsum_list[ref]
for one in set_l:
    if c[one] >= 2:
        num = c[one]
        counter += num*(num-1)/2*(unique_num-1)
        if num >= 3:
            counter += num*(num-1)*(num-2)/6
    
print(int(counter))

Submission status: Runtime Error

Solution code:
        print(a,b,c,l[a]+l[b]>l[c])

Submission status: Runtime Error

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


print(a)

Submission status: Runtime Error

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


print(a)

Submission status: Runtime Error

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


print(a)

Submission status: Runtime Error

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

L.sort()

count = 0
for i, l1 in enumerate(L):
    for j, l2 in enumerate(L):
        if i < j:
            s = bisect_right(L[j+1:], abs(l1-l2))
            e = bisect_left(L[j+1:], l1+l2)

            # print((i, j), (l1, l2), (abs(l1-l2), l1+l2), (s, e))
            count += max(0, e-s)
            # abs(l1-l2) <= m <= l1+l2

print(count)

Submission status: Runtime Error

Solution code:
N=int(input())
L=list(map(int,input().split()))
sorted (L)[::-1]
s=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(k)<=L(i)-L(j):
				break
			else:
				s+=1
print(s)