input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
import bisect n = int(eval(input())) l = sorted(list((list(map(int, input().split()))))) cnt = 0 for i in range(n - 2): for j in range(i + 1, n - 1): length = l[i] + l[j] cnt += bisect.bisect_left(l[j+1:], length) print(cnt)
import bisect n = int(eval(input())) l = sorted(list((list(map(int, input().split()))))) cnt = 0 for i in range(n - 2): for j in range(i + 1, n - 1): cnt += max(0, bisect.bisect_left(l, l[i] + l[j]) - j - 1) print(cnt)
p02888
from bisect import bisect_left from itertools import combinations N = int(eval(input())) L = list(map(int, input().split())) ans = 0 for e1, e2, e3 in combinations(L, 3): if e1 < e2 + e3 and e2 < e1 + e3 and e3 < e1 + e2: ans += 1 print(ans)
from bisect import bisect_left, bisect_right N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for a in range(N): for b in range(a + 1, N): c = bisect_left(L, L[a] + L[b]) ans += c - b - 1 print(ans)
p02888
N = int(eval(input())) L = list(map(int, input().split())) L.sort() count = 0 for i in range(0, N - 2): for p in range(i + 1, N - 1): left = p + 1 right = N - 1 tmp = (left + right) // 2 if left == right: if L[i] + L[p] > L[left]: count += (...
import bisect N = int(eval(input())) L = list(map(int, input().split())) L.sort() count = 0 for i in range(0, N - 2): for p in range(i + 1, N - 1): count += bisect.bisect_left(L, L[i] + L[p]) - p - 1 print(count)
p02888
#!/usr/bin/env python3 import sys import itertools from operator import mul from functools import reduce from bisect import bisect_left, bisect_right from collections import Counter def solve(N: int, L: "List[int]"): ans = 0 L.sort() for x in range(N): for y in range(x+1,N): ...
#!/usr/bin/env python3 import sys from bisect import bisect_left, bisect_right def solve(N: int, L: "List[int]"): ans = 0 L.sort() for x in range(N): for y in range(x+1,N): ze = bisect_left(L, L[x]+L[y]) ans += (ze-y-1) print(...
p02888
#!/usr/bin/env python3 import sys def solve(N: int, L: "List[int]"): L.sort() ans = 0 for i in range(N): for j in range(i+1, N): from bisect import bisect_left, bisect_right k = bisect_left(L, L[i]+L[j]) ans += (k-(j+1)) print(ans) ret...
#!/usr/bin/env python3 import sys from bisect import bisect_left, bisect_right def solve(N: int, L: "List[int]"): L.sort() ans = 0 for i in range(N): for j in range(i+1, N): k = bisect_left(L, L[i]+L[j]) ans += (k-j-1) print(ans) return # Gener...
p02888
N=int(eval(input())) l=list(map(int,input().split())) L=list(l) a=0 for i in range(N): for j in range(N-i-1): for k in range(N-j-i-2): if L[i]<L[i+j+1]+L[k+i+j+2] and L[i]>abs(L[i+j+1]-L[k+i+j+2]): a+=1 print(a)
import sys input = sys.stdin.readline N=int(eval(input())) L=list(map(int,input().split())) L.sort() ans=0 for i in range(N-2): mid =i+1 l=0 r=i+2 while r<N: if L[r]-L[l]<L[mid]: ans+=(mid-l) r+=1 else: if l==mid-1: r+=1 else: l+=1 print(ans)
p02888
N=int(eval(input())) *L,=list(map(int,input().split())) L.sort() from bisect import* i=0 ans=0 for i in range(N-1): for j in range(i+1,N): ans+=bisect_left(L[j:],L[i]+L[j])-1 print(ans)
N=int(eval(input())) *L,=list(map(int,input().split())) L.sort() from bisect import* i=0 ans=0 while i<N: j=i+1 while j<N: ans+=bisect_left(L,L[i]+L[j])-j-1 j+=1 i+=1 print(ans)
p02888
from bisect import bisect_left, bisect_right N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i, A in enumerate(L): for j, B in enumerate(L): if i == j: continue left = bisect_right(L, abs(A - B)) right = bisect_left(L, A + B) ...
from bisect import bisect_left N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i, A in enumerate(L): for j, B in enumerate(L[i + 1:], start=i + 1): right = bisect_left(L, A + B) ans += right - j - 1 print(ans)
p02888
import math import sys from collections import Counter import bisect readline = sys.stdin.readline def main(): cnt = 0 n = int(readline().rstrip()) L = sorted(list(map(int, readline().rstrip().split()))) for a in range(0, n - 2): for b in range(a + 1, n - 1): k = L[a] ...
import math import sys from collections import Counter import bisect readline = sys.stdin.readline def main(): cnt = 0 n = int(readline().rstrip()) L = sorted(list(map(int, readline().rstrip().split()))) for a in range(0, n - 2): for b in range(a + 1, n - 1): k = L[a] ...
p02888
N = int(eval(input())) L = list(map(int,input().split())) L.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 L[i]+L[j] > L[k]: #and L[j]+L[k] > L[i] and L[k]+L[i] > L[j]: c += 1 else: break print(c)
N = int(eval(input())) L = list(map(int,input().split())) L.sort() c = 0 for i in range(N-2): for j in range(i+1,N-1): zum = L[i]+L[j] start = j+1 goal = N-1 now = (start + goal)//2 if zum > L[goal]: c += goal - j elif zum <= L[start]: ...
p02888
N = int(eval(input())) L = list(map(int, input().split())) L.sort() count = 0 for i in reversed(list(range(N))): for j in reversed(list(range(i))): for k in range(j): if L[j] + L[k] > L[i]: count += j - k break print(count)
N = int(eval(input())) L = list(map(int, input().split())) L.sort() count = 0 for i in reversed(list(range(N))): kmin = 0 for j in reversed(list(range(i))): for k in range(kmin,j): if L[j] + L[k] > L[i]: count += j - k kmin = k break print(count)
p02888
n = int(eval(input())) arr = sorted(list(map(int,input().split()))) count = 0 for a in range(n-2): for b in range(a+1,n-1): for c in range(b+1,n): if arr[a]<arr[b]+arr[c] and arr[b]<arr[c]+arr[a] and arr[c]<arr[a]+arr[b]: count +=1 else: b...
n = int(eval(input())) arr = list(map(int,input().split())) arr.sort() count = 0 for a in range(n-2): k = a+2 for j in range(a+1,n): while (k < n and arr[a] + arr[j] > arr[k]): k+=1 if k>j: count += k-j-1 print(count)
p02888
import itertools def resolve(): n = int(eval(input())) l = tuple(map(int,input().split())) cnt = 0 for i in itertools.combinations(l,3): a,b,c = i if a<b+c and b<c+a and c<a+b: cnt += 1 print(cnt) resolve()
import bisect def resolve(): n = int(eval(input())) l = sorted(list(map(int,input().split()))) ans = 0 for a in range(n): for b in range(a+1,n): c = bisect.bisect_left(l,l[a]+l[b]) if c > b: ans += c-b-1 else: pass ...
p02888
import math from functools import reduce from collections import deque import sys sys.setrecursionlimit(10**7) def s(generator, splitter, mapper): return [ mapper(s) for s in generator().split(splitter) ] # スペース区切りの入力を読み込んで数値リストにして返します。 def get_nums_l(): return [ int(s) for s in input().split(" ")]...
import math from functools import reduce from collections import deque import sys sys.setrecursionlimit(10**7) def s(generator, splitter, mapper): return [ mapper(s) for s in generator().split(splitter) ] # スペース区切りの入力を読み込んで数値リストにして返します。 def get_nums_l(): return [ int(s) for s in input().split(" ")]...
p02888
import sys import math # input = sys.stdin.readline def binary_search(arr, key,j): ok = j ng = len(arr) while abs(ok - ng) > 1: mid = int((ok + ng) / 2) if arr[mid] < key: ok = mid else: ng = mid return ok def main(): N = ...
import sys #import math # input = sys.stdin.readline def binary_search(arr, key,j): ok = j ng = len(arr) while abs(ok - ng) > 1: mid = int((ok + ng) / 2) if arr[mid] < key: ok = mid else: ng = mid return ok def main(): N =...
p02888
from itertools import combinations as comb n = int(eval(input())) l = list(map(int,input().split())) l.sort() tri = set() for a,b,c in comb(l,3): if a<b+c and b<c+a and c<a+b: tri.add((a,b,c)) print((len(tri)))
import bisect n = int(eval(input())) l = list(map(int,input().split())) l.sort() c = 0 for i in range(n-2): for j in range(i+1,n-1): c += bisect.bisect_right(l,l[j]+l[i]-1) - bisect.bisect_left(l,l[j],j+1) print(c)
p02888
import bisect N = int(eval(input())) L = sorted([int(x) for x in input().split()]) cnt = 0 #print(L) for i in range(N-2): for j in range(i+1, N-1): #print(i, j) #print(bisect.bisect_left(L, L[i]+L[j])) cnt += bisect.bisect_left(L, L[i]+L[j]) - (j+1) print(cnt)
import bisect N = int(eval(input())) L = list(map(int,input().split())) L.sort() ans = 0 for i in range(N-2): for j in range(i+1,N-1): tmp = L[i]+L[j] point = bisect.bisect_left(L,tmp) ans += point - j - 1 print(ans)
p02888
n = int(eval(input())) l = list(map(int, input().split(' '))) l.sort() counter = 0 for i in range(n-2): for j in range(i+1,n-1): s = j + 1 while s < n and l[i] + l[j] > l[s]: s += 1 counter += s-j-1 print(counter)
n = int(eval(input())) l = list(map(int, input().split(' '))) l.sort() counter = 0 for i in range(n): s = i + 2 for j in range(i+1,n): while (s < n and l[i] + l[j] > l[s]): s += 1 counter += s-j-1 print(counter)
p02888
import bisect N = int(eval(input())) L = sorted(list(map(int, input().split()))) res = 0 for i in range(N - 1, 1, - 1): for j in range(i - 1, 0, - 1): k = L[i] - L[j] + 1 if k > L[j - 1]: break res += j - bisect.bisect_left(L, k) print(res)
N = int(eval(input())) L = sorted(list(map(int, input().split()))) res = 0 for i in range(N - 1, 1, - 1): j = i - 1 k = 0 while j > k: while j > k and L[i] >= L[j] + L[k]: k += 1 res += j - k j -= 1 print(res)
p02888
N = int(eval(input())) L = sorted(list(map(int, input().split()))) res = 0 for i in range(N - 1, 1, - 1): j = i - 1 k = 0 while j > k: while j > k and L[i] >= L[j] + L[k]: k += 1 res += j - k j -= 1 print(res)
N = int(eval(input())) L = sorted(list(map(int, input().split()))) res = 0 for i in range(N - 1, 1, - 1): j = i - 1 k = 0 while j > k: if L[i] < L[j] + L[k]: res += j - k j -= 1 else: k += 1 print(res)
p02888
n=int(eval(input())) l=list(map(int,input().split())) c=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] and l[j]<l[i]+l[k] and l[k]<l[i]+l[j]: c+=1 print(c)
n=int(eval(input())) l=list(map(int,input().split())) c=0 dp=[] l.sort() for i in range(n-2): k=i+2 for j in range(i+1,n-1): while k<n and (l[i]+l[j])>l[k]: k+=1 c+=k-j-1 print(c) ''' 1 2 3 4 1 < 2+3 2 < 1+3 3 < 1+2 6 - 1 = 5 6 - 2 = 4 6 - 3 = 3 '''
p02888
import bisect N = int(eval(input())) Ln = list(map(int,input().split(' '))) def binary_area_search(target_list: list, target_item: int) -> int: ''' @params target_list: [1,3,5](ACC) target_item: 2 @return return index ''' low = 0 high = len(target_list) - 1 while...
import bisect N = int(eval(input())) Ln = list(map(int,input().split(' '))) def binary_area_search(target_list: list, target_item: int) -> int: ''' @params target_list: [1,3,5](ACC) target_item: 2 @return return index ''' low = 0 high = len(target_list) - 1 while...
p02888
import bisect N = int(eval(input())) Ln = list(map(int,input().split(' '))) def binary_area_search(target_list: list, target_item: int) -> int: ''' @params target_list: [1,3,5](ACC) target_item: 2 @return return index ''' low = 0 high = len(target_list) - 1 while...
import bisect N = int(eval(input())) Ln = list(map(int,input().split(' '))) def binary_area_search(target_list: list, target_item: int) -> int: ''' @params target_list: [1,3,5](ACC) target_item: 2 @return return index ''' low = 0 high = len(target_list) - 1 while...
p02888
from bisect import bisect_left N=int(eval(input())) L=list(map(int, input().split())) L.sort() ans=0 for i in range(N): for j in range(i+1, N): ans+=bisect_left(L[j+1:], L[i]+L[j]) print(ans)
import bisect N=int(eval(input())) L=list(map(int, input().split())) L.sort() ans=0 for i in range(N): a=L[i] for j in range(i+1, N): b=L[j] ans+=bisect.bisect_left(L, a+b)-(j+1) print(ans)
p02888
import bisect N=int(eval(input())) L=list(map(int, input().split())) L.sort() ans=0 for i in range(N): a=L[i] for j in range(i+1, N): b=L[j] ans+=bisect.bisect_left(L, a+b)-(j+1) print(ans)
import bisect N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N): a = L[i] for j in range(i+1, N): b = L[j] ans += bisect.bisect_left(L, a+b)-j-1 print(ans)
p02888
import itertools n = int(eval(input())) l = list(map(int,input().split())) cnt = 0 for x,y,z in itertools.combinations(l,3): lt = sorted([x,y,z]) if lt[2] < lt[0] + lt[1]: cnt += 1 print(cnt)
import bisect n = int(eval(input())) l = sorted(list(map(int,input().split()))) cnt = 0 for i in range(n): for j in range(1+i,n): a,b = l[i],l[j] cnt += bisect.bisect_left(l,a+b)-(j+1) print(cnt)
p02888
n=int(eval(input())) l=list(map(int,input().split())) l.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 l[i]+l[j]>l[k]: c+=1 print(c)
n=int(eval(input())) l=list(map(int,input().split())) l.sort(reverse=True) c=0 for i in range(n-2): for j in range(i+1,n-1): u=l[i]-l[j] if l[j+1]<=u: break ok=j+1 ng=n while ng-ok>1: center=(ok+ng)//2 if l[center]>u: ok=center else: ng=cente...
p02888
n = int(eval(input())) l = input().split() l = list(l) for i in range(n): l[i] = int(l[i]) l.sort() count = 0 #a<b+c, a>b-c, a>c-b for a in range(n): for b in range(a+1,n): for c in range(b+1,n): if l[a]<l[b]+l[c]: if l[b]<l[c]+l[a]: if l[c]<l[a]+l[b]: count += 1 else: ...
import bisect n = int(eval(input())) l = list(map(int,input().split())) l.sort() ans = 0 #a<b+c, a>b-c, a>c-b for a in range(n-2): for b in range(a+1,n-1): index = bisect.bisect_left(l,l[a]+l[b]) ans += index - (b+1) print(ans)
p02888
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() def resolve(): from bisect import bisect_left n=int(eval(input())) L=list(map(int,input().split())) L.sort() ans=0 for i in range(1,n): for j in range(i+1,n):...
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() def resolve(): n=int(eval(input())) L=list(map(int,input().split())) L.sort() ans=0 for b in range(1,n-1): c=b+1 for a in range(b): while(c<n...
p02888
# ソートしたやつの小さい方から2つを決めてもうひとつはにぶたん # 3, 5としたときに残りの一つは5, 6, 7みたいになる # このにぶたんなんか実装がめっっっちゃむずくない?サンプル1が通らんのだが import bisect n = int(eval(input())) arr = sorted(list(map(int, input().split()))) def lower_bound(arr, x): l, r = 0, len(arr) while l < r: mid = (l + r) // 2 if arr[mid] < x...
# ソートしたやつの小さい方から2つを決めてもうひとつはにぶたん # 3, 5としたときに残りの一つは5, 6, 7みたいになる # このにぶたんなんか実装がめっっっちゃむずくない?サンプル1が通らんのだが # やったけどTLEなるな import bisect n = int(eval(input())) arr = sorted(list(map(int, input().split()))) def lower_bound(arr, x): l, r = 0, len(arr) while l < r: mid = (l + r) // 2 ...
p02888
import itertools N = int(eval(input())) L = list(map(int, input().split())) listarray = itertools.combinations(L,3) count = 0 for items in listarray: a = items[0] b = items[1] c = items[2] if a < b + c and b < c + a and c < a + b: count +=1 print(count)
from bisect import bisect_left N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N - 2): a = L[i] for j in range(i + 1, N - 1): b = L[j] c = bisect_left(L, a + b) ans += c - j - 1 print(ans)
p02888
import itertools N = int(eval(input())) L = list(map(int, input().split())) listarray = itertools.combinations(L,3) count = 0 for items in listarray: a = items[0] b = items[1] c = items[2] if a < b + c and b < c + a and c < a + b: count +=1 print(count)
from bisect import bisect_left N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N - 2): a = L[i] for j in range(i + 1, N - 1): b = L[j] c = bisect_left(L, a + b) ans += c - j - 1 print(ans)
p02888
n = int(eval(input())) li = list(map(int, input().split())) li.sort(reverse=True) count = 0 for i in range(n-2): for j in range(i+1, n-1): right = n - 1 rightFlag = 1 while rightFlag == 1 and right - j >= 1: if li[i] - li[j] >= li[right]: right -= 1 ...
n = int(eval(input())) li = list(map(int, input().split())) li.sort(reverse=True) count = 0 for i in range(n-2): for j in range(i+1, n-1): left = j right = n while right - left > 1: mid = (left + right)//2 if li[i]-li[j] < li[mid]: left ...
p02888
import bisect # 入力 def read_data(): N_ = int(eval(input())) L_ = list(map(int, input().split())) return N_, L_ #探索 def binarySearch(N :int, L): ans = 0 L.sort() # a,b は固定する for a_index in range(N): for b_index in range(a_index + 1, N): sum_of_a_and_b = L[...
import bisect # 入力 def read_data(): N_ = int(eval(input())) L_ = list(map(int, input().split())) return N_, L_ #探索 def binarySearch(N :int, L): ans = 0 L.sort() # a,b は固定する for a_index in range(N): for b_index in range(a_index + 1, N): sum_of_a_and_b = L[...
p02888
import bisect # 入力 def read_data(): N_ = int(eval(input())) L_ = list(map(int, input().split())) return N_, L_ # 探索 def Search(N, L): ans = 0 L.sort() # a, b は固定する for a_index in range(N): for b_index in range(a_index + 1, N): sum_of_a_and_b = L[a_index] + L[b_ind...
import bisect # 入力 def read_data(): N_ = int(eval(input())) L_ = list(map(int, input().split())) return N_, L_ # 探索 def Search(N, L): ans = 0 L.sort() # a, b は固定する for a_index in range(N): for b_index in range(a_index + 1, N): sum_of_a_and_b = L[a_index] + L...
p02888
def compose(): N = int( eval(input()) ) t_list = list( map( int, input().split() ) ) t_list.sort() t_list.reverse() counter = 0 a = 0 for i in t_list: a += 1 b = a for j in t_list[a:]: b += 1 new_list = [ k for k in t_list[b:] if k ...
from bisect import bisect_left N = int ( eval(input()) ) t_list = list ( map ( int, input().split() ) ) t_list.sort() ans = 0 for i in range ( N - 2 ): a = t_list[i] for j in range ( i + 1, N - 1 ): b = t_list[j] c = bisect_left ( t_list , a + b) ans += c - j - 1 print(ans)
p02888
n = int(eval(input())) l = list(map(int,input().split())) ans = 0 for i in range(n-2) : for j in range(i+1,n-1) : for k in range(j+1,n) : if l[i] < l[j]+l[k] and l[j] < l[i]+l[k] and l[k] < l[j]+l[i] : ans += 1 print(ans)
import bisect n = int(eval(input())) l = list(map(int,input().split())) l.sort() ans = 0 for i in range(n-2) : for j in range(i+1,n-1) : index = bisect.bisect_left(l,l[i]+l[j]) ans += index-1-j print(ans)
p02888
import bisect N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 # a <= b <= c for b in range(1,N-1): for c in range(b+1,N): # search min(c) with a + b > c <=> a > c - b idx = bisect.bisect_left(L[:b],L[c]-L[b]+1) #print(L[b],L[c],idx) ans += max(b-idx,0) if i...
import bisect N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 # a <= b <= c for b in range(1,N-1): for c in range(b+1,N): # search min(c) with a + b > c <=> a > c - b idx = bisect.bisect_left(L,L[c]-L[b]+1) #print(L[b],L[c],idx) ans += max(b-idx,0) if idx >...
p02888
""" nC3 のすべての組み合わせに対して、三角形が成立するかを調べると、O(n^3)で計算量がだめ ソートしてから、maxの辺を固定する 他の2つのへんをfor loop *2で回すが、a >= b + c になった段階でbreakする この時の計算量はo(n^3)だけど半分くらいに減るはず。 これでTLEするか試す """ n = int(eval(input())) l = list(map(int,input().split())) l.sort() ans = 0 for i in range(n-1,1,-1): for j in range(i-1,0,-1): for k in ...
import sys input = sys.stdin.readline n = int(input()[:-1]) li = list(map(int,input().split())) li.sort() ans = 0 for i in range(n-1,1,-1): for j in range(i-1,0,-1): l = 0 r = j while r-l > 0: p = (r+l)//2 if li[p] + li[j] > li[i]: r = p else: l = p + 1 ...
p02888
import bisect import sys input = sys.stdin.readline n = int(eval(input())) l = sorted([int(i) for i in input().split()]) ans = 0 for i in range(1,n-1): for j in range(i+1,n): if l[j] - l[i] >= l[i-1]: break elif i - bisect.bisect_right(l,(l[j]-l[i])) > 0: ans += i ...
import sys input = sys.stdin.readline n = int(eval(input())) l = sorted([int(i) for i in input().split()]) ans = 0 for i in range(1,n-1): tmp=0 for j in range(i+1,n): if l[j] - l[i] >= l[i-1]: break else: for k in range(tmp,i): if l[tmp] > l[j]...
p02888
import bisect n = int(eval(input())) L = sorted([int(i) for i in input().split()]) ans = 0 for b in range(n): for a in range(b): ab = L[a] + L[b] r = bisect.bisect_left(L,ab) l = b+1 ans += max(0,r-l) print(ans)
import bisect n = int(eval(input())) l = sorted(list(map(int, input().split()))) ans = 0 for a in range(n): for b in range(a): over_c = l[a] + l[b] over_c_index = bisect.bisect_left(l,over_c) quantity = over_c_index - a - 1 ans += max(quantity,0) print(ans)
p02888
import sys import itertools N = int(eval(input())) L = [int(v) for v in sys.stdin.readline().split()] print((len([(a, b, c) for a, b, c in itertools.combinations(L, 3) if a + b > c and b + c > a and a + c > b])))
import sys import itertools N = int(eval(input())) L = [int(v) for v in sys.stdin.readline().split()] print((len([0 for a, b, c in itertools.combinations(L, 3) if a + b > c and b + c > a and a + c > b])))
p02888
import sys import itertools N = int(eval(input())) L = [int(v) for v in sys.stdin.readline().split()] print((len([0 for a, b, c in itertools.combinations(L, 3) if a + b > c and b + c > a and a + c > b])))
import sys from bisect import bisect_left N = int(eval(input())) A = [int(v) for v in sys.stdin.readline().split()] A = sorted(A) cnt = 0 for i in range(N - 2): for j in range(i+1, N - 1): ij = A[i] + A[j] cnt += bisect_left(A, ij) - (j + 1) print(cnt)
p02888
#3本目を選ぶ時に2本目と同じ長さのものを選べることに注意する import bisect n=int(eval(input())) l=sorted(list(map(int,input().split()))) cnt=0 for i in range(0,n-2): for j in range(i+1,n-1): p=bisect.bisect_right(l,l[i]+l[j]-1) cnt+=max(p-j-1,0) print(cnt)
import bisect n=int(eval(input())) l=sorted(list(map(int,input().split()))) cnt=0 for i in range(0,n-2): for j in range(i+1,n-1): p=bisect.bisect_right(l,l[i]+l[j]-1) cnt+=p-j-1 print(cnt)
p02888
import bisect N = int(eval(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): minc = L[a] + L[b] indc = bisect.bisect_left(L[b+1:], minc) ans += max(indc, 0) print(ans)
import bisect N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N-2): a = L[i] for j in range(i+1, N-1): b = L[j] ans += bisect.bisect_left(L, a+b) - j - 1 print(ans)
p02888
def slove(): import sys input = sys.stdin.readline n = int(input().rstrip('\n')) l = sorted(list(map(int, input().rstrip('\n').split()))) cnt = 0 for i, iv in enumerate(l[:n-2]): for j, jv in enumerate(l[i+1:n-1]): t = iv + jv for k, kv in enumerate(l[i+j...
def slove(): import sys import bisect input = sys.stdin.readline n = int(input().rstrip('\n')) l = list(map(int, input().rstrip('\n').split())) l.sort() cnt = 0 for i in range(n-2): for j in range(i+1, n-1): t = l[i] + l[j] p = bisect.bisect_lef...
p02888
from bisect import bisect_left N=int(eval(input())) ll=list(map(int,input().split())) ll.sort() ans=0 for i in range(N): for j in range(i+1,N): delta=bisect_left(ll,ll[i]+ll[j],lo=j)-j-1 if delta>0: ans+=delta #print(i,j,delta) print(ans)
from bisect import bisect_left N=int(eval(input())) ll=list(map(int,input().split())) ll.sort() ans=0 for i in range(N): for j in range(i+1,N): if j==i+1: delta=bisect_left(ll,ll[i]+ll[i+1],lo=i+1)-i-2 if delta>0: ans+=delta in_b=delta+i+1+1 ...
p02888
from bisect import bisect_left, bisect_right N = int(eval(input())) L = [int(c) for c in input().split()] L.sort() ans = 0 for i in range(N): for j in range(i+1, N): x = L[i]+L[j] ind = bisect_left(L, x) IND = bisect_right(L,x) ans += ind-j-1 if ind-j>0 else 0 # print(x,ind) print(ans...
from bisect import bisect_left N = int(eval(input())) L = [int(c) for c in input().split()] L.sort() ans = 0 for i in range(N): for j in range(i+1, N): x = L[i]+L[j] ind = bisect_left(L, x) ans += ind-j-1 # print(x,ind) print(ans)
p02888
from itertools import combinations n=int(eval(input())) li=[int(x) for x in input().split()] l = list(range(n)) s = combinations(l,3) d=0 for a,b,c in list(s): if li[a]<(li[b]+li[c]): if li[b]<(li[a]+li[c]): if li[c]<(li[b]+li[a]): d=d+1 print(d)
def findNumberOfTriangles(arr, n): count = 0 for i in range(n): for j in range(i + 1, n): for k in range(j + 1, n): if (arr[i] + arr[j] > arr[k] and arr[i] + arr[k] > arr[j] and arr[k] + arr[j] > arr[i]): count += 1 return count n...
p02888
n = int(eval(input())) l = list(map(int, input().split())) l.sort(reverse=True) cnt = 0 for i in range(n - 2): for j in range(i + 1, n - 1): base = l[i] - l[j] for k in range(j + 1, n): if l[k] > base: cnt += 1 else: break print...
import bisect n = int(eval(input())) l = list(map(int, input().split())) l.sort() cnt = 0 for i in range(n - 1, 0, -1): for j in range(i - 1, -1, -1): base = l[i] - l[j] idx = bisect.bisect_right(l, base) cnt += max(j - idx, 0) print(cnt)
p02888
n=int(eval(input())) L_lst=sorted(list(map(int,input().split()))) cnt=0 for j in range(n-1,1,-1): i=j-1 x=0 while x<i: if L_lst[i]+L_lst[x]>L_lst[j]: cnt+=i-x i-=1 x=0 else: x+=1 print(cnt)
n=int(eval(input())) L_lst=sorted(list(map(int,input().split()))) cnt=0 for j in range(n-1,1,-1): i=j-1 x=0 while x<i: if L_lst[i]+L_lst[x]>L_lst[j]: cnt+=i-x i-=1 else: x+=1 print(cnt)
p02888
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from bisect import bisect_left, bisect_right from functools import reduce, lru_cache from heapq import heappush, heappop, heapify import itertools import math, fractions import sys, copy def L(): return sys.stdin.readline...
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from bisect import bisect_left, bisect_right from functools import reduce, lru_cache from heapq import heappush, heappop, heapify import itertools import math, fractions import sys, copy def L(): return sys.stdin.readline...
p02888
import bisect n = int(eval(input())) l_li = list(map(int,input().split())) l_li.sort() ans = 0 for i in range(n-2): for j in range(i+1,n-1): ind = bisect.bisect_left(l_li,l_li[i]+l_li[j]) num = ind-1 - j if num > 0: ans += num print(ans)
import bisect n = int(eval(input())) l_li = list(map(int,input().split())) l_li.sort() ans = 0 for i in range(n-2): for j in range(i+1,n-1): ind = bisect.bisect_left(l_li,l_li[i]+l_li[j]) num = ind-1 - j ans += num print(ans)
p02888
import bisect n = int(eval(input())) l_li = list(map(int,input().split())) l_li.sort() ans = 0 for i in range(n-2): for j in range(i+1,n-1): ind = bisect.bisect_left(l_li,l_li[i]+l_li[j]) num = ind-1 - j ans += num print(ans)
import bisect n = int(eval(input())) l_li = list(map(int,input().split())) l_li.sort() ans = 0 for i in range(n-2): for j in range(i+1,n-1): ind = bisect.bisect_left(l_li,l_li[i]+l_li[j]) ans += ind-1 - j print(ans)
p02888
# -*- coding: utf-8 -*- n = int(eval(input())) l = sorted(list(map(int, input().split(' '))), reverse = True) ans = 0 for ai in range(len(l)-2): a = l[ai] for bj in range(ai+1, len(l)-1): b = l[bj] for ck in range(bj+1, len(l)): c = l[ck] if a < b+c: ...
# -*- coding: utf-8 -*- from bisect import bisect_left n = int(eval(input())) l = sorted(list(map(int, input().split(' ')))) ans = 0 for i in range(n-1): for j in range(i+1, n): t = l[i]+l[j] idx = bisect_left(l, t) ans += max(0, idx-j-1) print(ans)
p02888
import sys N = int(sys.stdin.readline().strip()) l_list = list(sorted(list(map(int, sys.stdin.readline().strip().split(" "))))) count = 0 for i in reversed(list(range(2, N))): t_max = l_list[i] point = None for j in range(0, i-1): if l_list[j]+l_list[i-1] > t_max: point = j ...
import sys def bi_search(array, target): l, r = -1, len(array)-1 while r-l > 1: mid = int((r+l)/2) if array[mid] > target: r = mid else: l = mid return r N = int(sys.stdin.readline().strip()) l_list = list(sorted(list(map(int, sys.stdin.readline...
p02888
import bisect def main(): n = int(eval(input())) ll = list(map(int, input().split())) ll.sort() ans = 0 for i in range(n-2): e1 = ll[i] for j in range(i+1, n-1): e2 = ll[j] ans += bisect.bisect_left(ll[j+1:], e1+e2) print(ans) if __na...
import bisect def main(): n = int(eval(input())) ll = list(map(int, input().split())) ll.sort() ans = 0 for i in range(n-2): e1 = ll[i] for j in range(i+1, n-1): e2 = ll[j] # ans += bisect.bisect_left(ll[j+1:], e1+e2) comb = bisect.b...
p02888
import bisect def main(): n = int(eval(input())) ll = list(map(int, input().split())) ll.sort() ans = 0 for i in range(n-2): e1 = ll[i] for j in range(i+1, n-1): e2 = ll[j] # ans += bisect.bisect_left(ll[j+1:], e1+e2) comb = bisect.b...
import bisect n = int(eval(input())) ll = list(map(int, input().split())) ll.sort() ans = 0 for i in range(n-2): e1 = ll[i] for j in range(i+1, n-1): e2 = ll[j] comb = bisect.bisect_left(ll, e1+e2) comb -= (j+1) ans += max(comb,0) print(ans)
p02888
import bisect n = int(eval(input())) ll = list(map(int, input().split())) ll.sort() ans = 0 for i in range(n-2): e1 = ll[i] for j in range(i+1, n-1): e2 = ll[j] comb = bisect.bisect_left(ll[j+1:], e1+e2) # comb -= (j+1) ans += max(comb,0) print(ans)
import bisect n = int(eval(input())) ll = list(map(int, input().split())) ll.sort() ans = 0 for i in range(n-2): e1 = ll[i] for j in range(i+1, n-1): e2 = ll[j] cnt = bisect.bisect_left(ll, e1+e2) cnt -= (j+1) ans += max(cnt,0) print(ans)
p02888
n = int(eval(input())) L = [int(i) for i in input().split()] L.sort() ans = 0 for a in range(len(L)): for b in range(a+1,len(L)): c_max = L[a]+L[b]-1 left = b+1 right = len(L) mid = (right+left)//2 while left<right: mid = (right+left)//2 ...
n = int(eval(input())) L = [int(i) for i in input().split()] L.sort() ans = 0 """ #二分探索ver -> import bisectと同じでもTLE. #importはC言語veっで実行してるらしい.積極的に使おう for a in range(len(L)): for b in range(a+1,len(L)): c_max = L[a]+L[b]-1 left = b+1 right = len(L) mid = (right+left)//2 ...
p02888
import bisect N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N-1): for j in range(i+1, N): a = L[i] b = L[j] l = bisect.bisect_right(L, abs(a-b)) r = bisect.bisect_left(L, a+b) ans += r-l if a in L[l:r]: ...
import bisect N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N-1): for j in range(i+1, N): a = L[i] b = L[j] l = bisect.bisect_right(L, abs(a-b)) r = bisect.bisect_left(L, a+b) ans += r-l if L[l] <= a <= L[...
p02888
import itertools n = int(eval(input())) L = list(map(int, input().split())) M = [] for v in itertools.combinations(L, 3): M.append(list(v)) cnt = 0 for v in M: if v[0] < v[1]+v[2] and v[1] < v[0]+v[2] and v[2] < v[0]+v[1]: cnt += 1 print(cnt)
from bisect import bisect_left n = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(n): for j in range(i+1, n): ans += bisect_left(L, L[i]+L[j])-j-1 print(ans)
p02888
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math from bisect import bisect_left, bisect_right import random from itertools import permutations, accumulate, combinations import sys import string INF = float('inf') def LI(): return list(map(int, s...
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math from bisect import bisect_left, bisect_right import random from itertools import permutations, accumulate, combinations import sys import string INF = float('inf') def LI(): return list(map(int, s...
p02888
from itertools import combinations N = int(eval(input())) L = [i for i in map(int, input().split())] ans = 0 # print(list(combinations(L,3))) for i, j ,k in list(combinations(L, 3)): if i < j + k and j < i + k and k < i + j: ans += 1 print(ans)
import sys N = int(eval(input())) L = [i for i in map(int, input().split())] ans = 0 L.sort() #print(L) if N == 3: if L[0] + L[1] > L[2]: print("1") sys.exit() for i in range(len(L)-2): for j in range(i+1,len(L)-1): for k in range(j+1,len(L)): if L[i] + L[j] ...
p02888
N = int(eval(input())) L_list = list(map(int, input().split())) L_list = sorted(L_list) count = 0 for i in range(N-2): for j in range(i+1, N-1): for k in range(j+1, N): if L_list[i] + L_list[j] > L_list[k]: count += 1 else: break print...
import bisect N = int(eval(input())) L_list = list(map(int, input().split())) L_list = sorted(L_list) total = 0 for i in range(N-2): for j in range(i+1, N-1): total += bisect.bisect_left(L_list, L_list[i] + L_list[j]) - j -1 print(total)
p02888
import sys import math stdin = sys.stdin mod = 10**9 + 7 ns = lambda: stdin.readline().rstrip() ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)] n = ni() l = na() l.sort(reverse=True) c = 0 for ll in ...
import sys import math import bisect stdin = sys.stdin mod = 10**9 + 7 ns = lambda: stdin.readline().rstrip() ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)] n = ni() l = na() l.sort() c = 0 for...
p02888
import bisect N = int(eval(input())) L = list(map(int,input().split())) L.sort() ans = 0 for b in range(N): l = b + 1 for a in range(b): maxL = L[a] + L[b] r = bisect.bisect_left(L, maxL) ans += max(0, r-l) print(ans)
N = int(eval(input())) L = list(map(int,input().split())) L.sort() ans = 0 for b in range(N): l = b + 1 r = l for a in range(b): maxL = L[a] + L[b] while r<N and L[r]<maxL: r += 1 ans += max(0, r-l) print(ans)
p02888
N = int(eval(input())) L = list(map(int,input().split())) L.sort() cmax = L[-1] + L[-2] csum = list(0 for _ in range(cmax+1)) for i in range(N): csum[L[i]] += 1 for i in range(1,cmax+1): csum[i] += csum[i-1] ans = 0 for ib in range(N): b = L[ib] for ia in range(ib): a = L[ia] minL, m...
import bisect N = int(eval(input())) L = list(map(int,input().split())) L.sort() ans = 0 for b in range(N): for a in range(b): ans += bisect.bisect_left(L, L[a] + L[b])-(b+1) print(ans)
p02888
import bisect N = int(eval(input())) L = list(map(int,input().split())) L.sort() ans = 0 for b in range(N): for a in range(b): ans += bisect.bisect_left(L, L[a] + L[b])-(b+1) print(ans)
N = int(eval(input())) L = list(map(int,input().split())) L.sort() ans = 0 for b in range(N): r = b + 1 for a in range(b): while r<N and L[r]<L[a]+L[b]: r += 1 ans += r-(b+1) print(ans)
p02888
from bisect import bisect_left N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N-2): for j in range(i+1, N-1): ans += max(0, bisect_left(L, L[i]+L[j]) - j - 1) print(ans)
from bisect import bisect_left N = int(eval(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_left(L, L[i]+L[j]) - j - 1 print(ans)
p02888
import bisect n = int(eval(input())) l = sorted(list(map(int,input().split()))) ans = 0 for ai in range(n): for bi in range(ai+1,n): ci = bisect.bisect_left(l,l[ai]+l[bi]) if ci>bi: ans += ci-bi-1 print(ans)
n = int(eval(input())) l = sorted(list(map(int,input().split()))) ans = 0 for ai in range(n): for bi in range(ai+1,n): ok,ng = bi,n while ng-ok>1: mid = (ng+ok)//2 if l[mid]<l[ai]+l[bi]: ok = mid else: ng = mid ans += ok-bi print(ans)
p02888
import bisect from copy import deepcopy N = int(eval(input())) L = sorted(map(int, input().split())) ans = 0 for i in range(N): for j in range(i + 1, N - 1): b = L[j] + L[i] x = bisect.bisect_left(L, b) - j - 1 if x > 0: ans += x print(ans)
import bisect n = int(eval(input())) L = sorted(map(int, input().split())) m = L[-1] ans = 0 for i in range(n): for j in range(i + 1, n): k = L[i] + L[j] ans += bisect.bisect_left(L, k) - j-1 print(ans)
p02888
import itertools, bisect N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N): for j in range(i+1, N): cindex = bisect.bisect_left(L, int(L[i]) + int(L[j])) for _ in reversed(list(range(j+1, cindex))): ans += 1 print(ans)
import itertools, bisect N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N): for j in range(i+1, N): cindex = bisect.bisect_left(L, int(L[i]) + int(L[j])) ans += cindex-1 - j print(ans)
p02888
from itertools import combinations n = int(eval(input())) l = list(map(int, input().split())) combination_line = list(combinations(l, 3)) count = 0 for i in combination_line: line1 = i[0] line2 = i[1] line3 = i[2] if line1 < line2 + line3 and line2 < line1 + line3 and line3 < line1 + line2: ...
n = int(eval(input())) l = list(map(int, input().split())) sort_l = sorted(l) count = 0 for i in range(n-2): for j in range(i+1, n-1): for k in range(j+1, n): two_line = sort_l[i] + sort_l[j] one_line = sort_l[k] if two_line > one_line: c...
p02888
import itertools N = int(eval(input())) d_list = list(map(int, input().split())) c_d_list = list(itertools.combinations(d_list, 3)) count = 0 for i in c_d_list: a = i[0] b = i[1] c = i[2] if a < b + c: if b < a + c: if c < a + b: count += 1 print(count)
import itertools N = int(eval(input())) d_list = list(map(int, input().split())) c_d_list = list(itertools.combinations(d_list, 3)) count = 0 for i in c_d_list: a = i[0] b = i[1] c = i[2] if a < b + c and b < a + c and c < a + b: count += 1 print(count)
p02888
n = int(eval(input())) d = list([int(x) for x in input().split()]) res = 0 def is_triangle(i, j, k): return 1 if i < j + k and j < i + k and k < i + j else 0 i = 0 j = 1 k = 2 while i < n: while j < n: while k < n: res += is_triangle(d[i],d[j],d[k]) k += 1...
n = int(eval(input())) d = list([int(x) for x in input().split()]) d.sort() res = 0 for i in range(n-2): k = i + 2 for j in range(i+1, n-1): while k < n and d[i] + d[j] > d[k]: k += 1 if k > j: res += k - j - 1 print(res)
p02888
n = int(eval(input())) d = list([int(x) for x in input().split()]) d.sort() res = 0 for i in range(n-2): k = i + 2 for j in range(i+1, n-1): while k < n and d[i] + d[j] > d[k]: k += 1 if k > j: res += k - j - 1 print(res)
def find_triangle_count(d): n = len(d) d.sort() res = 0 for i in range(n - 2): k = i + 2 for j in range(i + 1, n - 1): while k < n and d[i] + d[j] > d[k]: k += 1 if k > j: res += k - j - 1 return res def solve():...
p02888
from itertools import combinations n = int(eval(input())) l = [int(x) for x in input().split()] l1 = list(combinations(l, 3)) c = 0 for i in l1: if i[0] < i[1] + i[2] and i[1] < i[0] + i[2] and i[2] < i[0] + i[1]: c += 1 print(c)
def findnumberofTriangles(arr): # Sort array and initialize count as 0 n = len(arr) arr.sort() count = 0 # Fix the first element. We need to run till n-3 as # the other two elements are selected from arr[i+1...n-1] for i in range(0,n-2): # Initialize index ...
p02888
import bisect def main(): N = int(eval(input())) L = list(map(int,input().split())) L.sort() Lind = [] count = 0 for i in reversed(list(range(2,N))): for j in reversed(list(range(1,i))): if L[i] < 2*L[j]: Lind.append([i,j]) for l in Lind: ...
import bisect def main(): N = int(eval(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): c = bisect.bisect_left(L,L[i]+L[j]) count += max(0,c-1 - j) print(count) main(...
p02888
N = int(eval(input())) L = input().split() L = [int(L[i]) for i in range(len(L))] tri = 0 bar = [[L[i], L[j], L[k]] for i in range(N) for j in range(i+1,N) for k in range(j+1,N)] for i in range(len(bar)): if bar[i][0] + bar[i][1] > bar[i][2]: if bar[i][0] + bar[i][2] > bar[i][1]: if bar[i][1] + ba...
N = int(eval(input())) L = input().split() L = [int(L[i]) for i in range(len(L))] L.sort(reverse=True) tri = 0 for i in range(N): for j in range(i+1,N): for k in range(j+1,N): if L[k] + L[j] > L[i]: tri += 1 print(tri)
p02888
import bisect import copy n=int(eval(input())) a=list(map(int,input().split())) a.sort() ans=0 for i in range(n): for j in range(i+1,n): if i==j: continue b=copy.deepcopy(a) b.remove(a[i]) b.remove(a[j]) ans+=bisect.bisect_left(b,a[i]+a[j])-j+1 print(ans)
import bisect n=int(eval(input())) a=list(map(int,input().split())) a.sort() ans=0 for i in range(n): for j in range(i+1,n): ans+=bisect.bisect_left(a,a[i]+a[j])-j-1 print(ans)
p02888
import itertools as it N=int(eval(input())) L=list(map(int,input().split())) count=0 L.sort() A=list(it.combinations(L,3)) for a in A: if a[2]<a[0]+a[1]: count+=1 print(count)
N=int(eval(input())) L=list(map(int,input().split())) count=0 l=sorted(L,reverse=True) 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]: count+=1 print(count)
p02888
def triangle_check(a, b, c): if a>b+c: return False elif b>a+c: return False elif c>a+b: return False else: return True def count_triangles(n, sticks): assert len(sticks) == n, "lenght of sticks does not match `n`" count = 0 for i in range(len(sticks)): for j in rang...
def triangle_check(a, b, c): if a>b+c: return False elif b>a+c: return False elif c>a+b: return False else: return True def count_triangles(n, sticks): assert len(sticks) == n, "lenght of sticks does not match `n`" count = 0 for i in range(len(sticks)-2): for j in ra...
p02888
n = int(eval(input())) arr = [int(i) for i in input().split()] arr.sort() works= lambda a,b,c : (a<(b+c)) and (b<(a+c)) and (c<(b+a)) total = 0 for i in range(n): aI = arr[i] for j in range(i+1,n): aJ = arr[j] for k in range(j+1,n): if works(arr[k],aI,aJ): ...
n = int(eval(input())) arr = [int(i) for i in input().split()] arr.sort() total = 0 for i in range(n-2): aI = arr[i] k = i + 2 for j in range(i+1,n): mySum = aI+arr[j] while (k<n) and arr[k]<mySum: k+=1 if k>j: total+= k-...
p02888
import sys import bisect readline = sys.stdin.readline n = int(readline()) A = list(map(int,readline().split())) A.sort() ans =0 for i in range(1,n): for j in range(i+1,n): ans += i- bisect.bisect(A,A[j]-A[i],hi=i) print(ans)
import sys import bisect readline = sys.stdin.readline n = int(readline()) A = list(map(int,readline().split())) memo1 = {} memo2 = {} A.sort() memo1[A[0]+A[1]] =1 memo2[A[0]] =1 if A[1] in memo2: memo2[A[1]] +=1 else: memo2[A[1]] =1 ans = 0 for c in A[2:]: for l,amount in list(memo1.items()...
p02888
import itertools N = int(eval(input())) L = list(map(int, input().split())) lst = list(itertools.combinations(L, 3)) cnt = 0 for i in lst: if i[0]+i[1] > i[2] and i[1]+i[2] > i[0] and i[0]+i[2] > i[1]: cnt += 1 print(cnt)
N = int(eval(input())) lst = list(map(int, input().split())) lst.sort() lst.append(10**10) total = 0 for i in range(N-1): for j in range(i+1, N-1): cnt = 0 k = j+1 while lst[j]+lst[i] > lst[k]: cnt += 1 k += 1 total += cnt print(total)
p02888
import bisect N = int(eval(input())) L = list(map(int,input().split())) L.sort() count = 0 # aとbを固定 for a in range(N-2): for b in range(a+1,N-1): aADDb = L[a] + L[b] maxL = bisect.bisect_left(L,aADDb) # cの範囲は、[b+1,maxL) count += max(0,maxL-(b+1)) print(count)
N = int(eval(input())) L = [int(i) for i in input().split()] L.sort() from bisect import bisect_left ans = 0 # a < b < c for a in range(N): for b in range(a+1, N): right = bisect_left(L, L[a] + L[b]) # [b+1, right) ans += max(0, right - (b + 1)) print(ans)
p02888
n=int(eval(input())) lengths=sorted([int(i) for i in input().split()]) import itertools as it import math as ma cnt=0 triangle=[list(i) for i in it.combinations(lengths,3)] for i in range(len(triangle)): a=triangle[i].pop(0) b=triangle[i].pop(0) c=triangle[i].pop(0) if ma.floor(b-a)<c<(b+...
import math import itertools n=int(eval(input())) L=[int(i) for i in input().split()] L.sort() ans=0 for i in range(2,n): c=list(itertools.combinations(L[:i],2)) for j in range(len(c)): if math.floor(c[j][0]-c[j][1])<L[i]<c[j][0]+c[j][1]: ans+=1 print(ans)
p02888
from bisect import bisect_right n=int(eval(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): c=L[i]+L[j]-1 ans+=bisect_right(L,c)-j-1 print(ans)
n=int(eval(input())) L=[int(i) for i in input().split()] L.sort(reverse=True) def binary(a,b,mid): if L[mid]+L[j]>L[i]: return True else: return False ans=0 for i in range(n-2): for j in range(i+1,n-1): l=j r=n while r-l>1: mid=(r+l)//2 if binary(i,j,mid): ...
p02888
n = int(eval(input())) l = list(map(int, input().split())) l.sort() ans = 0 for i in range(n): a = l[i] for j in range(i+1, n): b = l[j] c_candidate = [k for k in l[j+1:] if k < a+b] ans += len(c_candidate) print(ans)
import bisect n = int(eval(input())) l = list(map(int, input().split())) l.sort() ans = 0 for i in range(n): a = l[i] for j in range(i+1, n): b = l[j] ans += bisect.bisect_left(l, a+b)-j-1 print(ans)
p02888
from bisect import bisect_left n = int(eval(input())) l = list(map(int, input().split())) l.sort() c = 0 for i in range(n-2): for j in range(i+1, n-1): c += bisect_left(l, l[i]+l[j]) - j - 1 print(c)
from bisect import bisect_left n = int(eval(input())) l = list(map(int, input().split())) l.sort() c = sum(bisect_left(l, l[i]+l[j])-j-1 for i in range(n-2) for j in range(i+1, n-1)) print(c)
p02888
def main(): from bisect import bisect_right N = int(eval(input())) *e, = list(map(int, input().split())) e.sort() ans = 0 for j in range(2, N): for i in range(1, j): d = e[j] - e[i] ans += i - bisect_right(e, d, lo=0, hi=i) print(ans) if...
def main(): from bisect import bisect_right N = int(eval(input())) *e, = list(map(int, input().split())) e.sort() ans = 0 for j in range(2, N): for i in range(1, j): d = e[j] - e[i] ans += max(0, i - bisect_right(e, d)) print(ans) if __n...
p02888
from sys import stdin N = int(stdin.readline()) L = [int(x) for x in stdin.readline().rstrip().split()] L.sort() tmp = 0 for i in range(N): for j in range(N-i-1): j = j + i + 1 for k in range(N-j-1): k = k + j + 1 if L[k] < L[i] + L[j]: ...
# 本番では解けず。 from sys import stdin import bisect N = int(stdin.readline()) L = [int(x) for x in stdin.readline().rstrip().split()] # (1)Lを昇順にソートする L.sort() s = 0 for i in range(N-2): for j in range(i+1, N-1): # (2)Lから2つの辺を固定で選ぶ(L[i]をa L[j]をbとする) # この場合、a < b + c, b < a + c はソート済みの...
p02888
from bisect import bisect_left N = int(eval(input())) L = list(map(int,input().split())) L.sort() ans = 0 for i in range(N-2): for j in range(i+1,N-1): ans += bisect_left(L[j+1:],L[i]+L[j]) print(ans)
from bisect import bisect_left N = int(eval(input())) L = list(map(int,input().split())) L.sort() ans = 0 for i in range(N-2): for j in range(i+1,N-1): ans += bisect_left(L,L[i]+L[j])-(j+1) print(ans)
p02888
n = int(eval(input())) l = [int(i) for i in input().split()] l.sort() a = 0 for i in range(n): for j in range(i+1, n): for k in range(n - 1, j, -1): if l[i] + l[j] > l[k]: a += k - j break print(a)
n = int(eval(input())) l = [int(i) for i in input().split()] l.sort() ans = 0 for i in range(n): for j in range(i + 1, n): a = l[i] + l[j] mi = 0 ma = n - 1 while mi != ma: m = (mi + ma) // 2 + 1 if l[m] < a: mi = m ...
p02888
import bisect n=int(eval(input())) *L,=list(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-(j+1) print(ans)
import bisect n=int(eval(input())) L=list(map(int,input().split())) L.sort() ans=0 for i in range(n-1): for j in range(i+1,n): idx=bisect.bisect_left(L,L[i]+L[j]) ans+=idx-(j+1) print(ans)
p02888
# coding: utf-8 def binary_search(x, L2): l, r = 0, len(L2)-1 mid = (r + l) // 2 while r - l > 1: mid = (r + l) // 2 if L2[mid] == x: break elif L2[mid] > x: l = mid elif L2[mid] < x: r = mid if L2[r] > c: return r ...
# coding: utf-8 from bisect import bisect_left N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N-2): a = L[i] for j in range(i+1, N-1): b = L[j] ans += bisect_left(L, a+b) - 1 - j print(ans)
p02888
import bisect # 三角形の条件: c < a+b N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 # a と b を固定 for a in range(N): for b in range((a+1), N): # c の動ける範囲の右端を求める c = L[a]+L[b] k = bisect.bisect_left(L, c) # c の動ける範囲は、[j+1, k) ans += k - b - 1 print(ans)
import bisect # 三角形の条件: c < a+b N = int(eval(input())) L = list(map(int, input().split())) L.sort() ans = 0 for i in range(N-1, 1, -1): a = 0 b = i-1 while a<b: if L[a]+L[b] > L[i]: ans += b-a b -= 1 else: a += 1 print(ans)
p02888
from sys import stdin import bisect N = int(eval(input())) L = list(map(int,stdin.readline().strip().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): if L[k] < (L[i]+L[j]): ans+=1 print(ans)
from sys import stdin import bisect N = int(eval(input())) L = list(map(int,stdin.readline().strip().split())) L.sort() ans = 0 for i in range(N-2): for j in range(i+1,N-1): idx = bisect.bisect_left(L,L[i]+L[j],j) ans += (idx-j-1) print(ans)
p02888
import bisect n=int(eval(input())) l=list(map(int,input().split())) l.sort() ans=0 for i in range(n-2): for j in range(i+1,n-1): res=l[i]+l[j] mid=bisect.bisect_left(l,res) ans+=mid-j-1 print(ans)
import bisect n=int(eval(input())) l=list(map(int,input().split())) l.sort() ans=0 for i in range(n-2): for j in range(i+1,n-1): res=l[i]+l[j] ans+=bisect.bisect_left(l,res)-1-j print(ans)
p02888