input stringlengths 20 127k | target stringlengths 20 119k | problem_id stringlengths 6 6 |
|---|---|---|
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(" ")]
# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
return [ int(eval(input())) for _ in range(n)]
a,b = get_nums_l()
print((max(a+b, a-b, a*b))) |
import sys
def log(*args, **kwargs):
print(*args, file=sys.stderr)
log("hogehoge")
a,b = map(int, input().split())
print(max(a*b, a+b, a-b))
| p02945 |
a, b = list(map(int, input().split()))
x = a+b
y = a-b
v = a*b
print((max(x,y,v))) |
a, b = list(map(int, input().split()))
x = a+b
y = a-b
z = a*b
print((max(x,y,z))) | p02945 |
a,b=list(map(int, input().split()))
print((max(a+b,a-b,a*b))) | A,B=list(map(int,input().split()))
C=A+B
D=A-B
E=A*B
ans=max(C,D,E)
print(ans) | p02945 |
A, B = list(map(int, input().split()))
ans = max(A + B, A - B, A * B)
print(ans)
| A, B = list(map(int, input().split()))
x = A+B
y =A-B
z =A*B
if x > y:
if x>z:
ans = x
else:
ans = z
else:
if y>z:
ans = y
else:
ans = z
print(ans)
| p02945 |
A, B = list(map(int, input().split()))
if B > 0:
if A * B > (A + B):
val = A * B
else:
val = A + B
else:
if A * B > (A - B):
val = A * B
else:
val = A - B
print(("%d"%val))
| A, B = list(map(int, input().split()))
print(("%d"% max([A + B, A - B, A* B])))
| p02945 |
i = list(map(int, input().split()))
l = [i[0] + i[1], i[0] - i[1], i[0]*i[1]]
print((max(l, key=int))) | i = list(map(int, input().split()))
a = i[0]+i[1]
b = i[0]*i[1]
c = i[0]-i[1]
print((max(a,b,c)))
| p02945 |
a, b = list(map(int, input().split()))
print((max(a+b, a-b, a*b))) | a, b = list(map(int, input().split()))
print((max([a+b, a-b, a*b]))) | p02945 |
# A - +-x
def main():
a, b = list(map(int, input().split()))
print((max([a+b, a-b, a*b])))
if __name__ == '__main__':
main() | # A - +-x
def main():
a, b = list(map(int, input().split()))
print((max(a+b, a-b, a*b)))
if __name__ == '__main__':
main() | p02945 |
A,B=list(map(int,input().split()))
print((max(A*B,A+B,A-B))) | A,B = list(map(int,input().split()))
print((max(A+B,A-B,A*B))) | p02945 |
a, b = list(map(int, input().split()))
print((max(a-b, a+b, a*b))) | n, m = list(map(int, input().split()))
print((max(n+m, n-m, n*m))) | p02945 |
a,b = list(map(int,input().split()))
c = max(a+b, a-b, a*b)
print(c) | def resolve():
a, b = list(map(int, input().split()))
print((max(a+b, a-b, a*b)))
resolve() | p02945 |
a,b = list(map(int, input().split()))
li = [a+b, a-b,a*b]
print((max(li)))
| a,b=list(map(int,input().split()))
print((max(a+b,a-b,a*b))) | p02945 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)
def getN():
return int(eval(input()))
def getList():
return list(map(int, input().split()))
import math
a, b = getList()
print((max([a+b, a-b, a*b])))
# print(ans) | import sys
# from collections import defaultdict, deque
# import math
# import copy
# from bisect import bisect_left, bisect_right
# import heapq
# sys.setrecursionlimit(1000000)
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(eval(input()))
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
INF = 10 ** 20
MOD = 1000000007
def solve():
a,b = getList()
print((max([a+b, a - b, a * b])))
return
def main():
n = getN()
for _ in range(n):
solve()
if __name__ == "__main__":
# main()
solve()
| p02945 |
A,B = list(map(int,input().split()))
print((max(A+B,A-B,A*B)))
| a , b = input().split()
a =int(a)
b =int(b)
print((max(a + b,a - b,a * b)))
| p02945 |
a,b = list(map(int,input().split()))
print((max(a+b,a-b,a*b))) | a,b = list(map(int,input().split()))
ans1 = a+b
ans2 = a-b
ans3 = a*b
ans = max(ans1,ans2,ans3)
print(ans) | p02945 |
# ABC143 D Triangles
n = int(eval(input()))
l_list = [int(x) for x in input().split()]
l_list.sort()
ans = 0
# (i < j < k) -> (_a < _b < _c)
for i in range(n-2):
_a = l_list[i]
for j in range(i+1,n-1):
_b = l_list[j]
_tmp = _a + _b
for k in range(j+1,n):
_c = l_list[k]
if _c < _tmp:
ans += 1
else:
break
print(ans) | # ABC143 D Triangles
import bisect
n = int(eval(input()))
l_list = [int(x) for x in input().split()]
l_list.sort()
ans = 0
for i in range(n-2):
_a = l_list[i]
for j in range(i+1,n-1):
_b = l_list[j]
_tmp = bisect.bisect_left(l_list, _a+_b)
if j < _tmp:
ans += _tmp - j - 1
print(ans) | p02888 |
N = int(eval(input()))
L = list(map(int, input().split()))
from itertools import combinations
X = list(combinations(L, 3))
ans = 0
for a,b,c in X:
if a < b + c and b < c + a and c < a + b:
ans += 1
print(ans) | N = int(eval(input()))
L = list(map(int, input().split()))
SL = sorted(list(L))
A = [0] * (10 ** 3 + 10)
for i in SL:
A[i] = True
for i in range(len(A)):
if A[i] == True:
A[i] = A[i-1] + 1
else:
A[i] = A[i-1]
# print(A[4-1] - A[2])
ans = 0
for i in range(N-2):
for j in range(i+1, N-1):
for k in range(j+1, N):
# print(i, j, k)
a = SL[i]
b = SL[j]
c = SL[k]
if a < b + c and b < c + a and c < a + b:
ans += 1
print(ans) | p02888 |
N = int(eval(input()))
L = list(map(int, input().split()))
SL = sorted(list(L))
A = [0] * (10 ** 3 + 10)
for i in SL:
A[i] = True
for i in range(len(A)):
if A[i] == True:
A[i] = A[i-1] + 1
else:
A[i] = A[i-1]
# print(A[4-1] - A[2])
ans = 0
for i in range(N-2):
for j in range(i+1, N-1):
# for k in range(j+1, N):
# a = SL[i]
# b = SL[j]
# c = SL[k]
# if a < b + c and b < c + a and c < a + b:
# ans += 1
a = SL[i]
b = SL[j]
for k in range(j+1, N):
c = SL[k]
if abs(a - b) >= c:
print('continue')
continue
elif c >= a + b:
break
else:
ans += 1
print(ans) | N = int(eval(input()))
L = list(map(int, input().split()))
SL = sorted(list(L))
# print('SL', SL)
import bisect
ans = 0
for i in range(N-2):
for j in range(i+1, N-1):
ab = SL[i] + SL[j]
# print(i, j)
# print(SL[i], SL[j])
r = bisect.bisect_left(SL, ab)
l = j + 1
# print('r', r)
# print('l', l)
# print('---')
ans += max(0, r - l)
print(ans) | p02888 |
import bisect
n = int(eval(input()))
l = list(map(int,input().split()))
co = []
ol = sorted(l)
nl = sorted(l,reverse=True)
for i in range(1,n):
for j in range(1,n):
if i<j:
co.append(nl[i]+nl[j])
nco = list(reversed(co))
sk = 0
g = 0
for i in range(2,n):
a = ol[i]
x = nco[:(i)*(i-1)//2]
ind = bisect.bisect(x,a)
g += len(x)-ind
print(g) | import bisect
n=int(eval(input()))
l=sorted(list(map(int,input().split())))
g=0
for ai in range(n-2):
for bi in range(ai+1,n-1):
g+=max(0,bisect.bisect_left(l,l[bi]+l[ai])-1-bi)
print(g)
| p02888 |
N=int(eval(input()))
L=list(map(int,input().split()))
L=sorted(L)
a=0
for i in range(N-1):
for k in range(1,N-i-1):
a=a+sum(x<L[i]+L[i+k] for x in L[i+k+1:N])
print(a) | import bisect
N=int(eval(input()))
L=list(map(int,input().split()))
L=sorted(L)
ans=0
for i in range(N-1):
for k in range(i+1,N-1):
a=L[i]+L[k]
b=bisect.bisect_left(L,a)
ans=ans+(b-k-1)
print(ans) | p02888 |
import itertools
n = int(eval(input()))
list_score = list(map(int, input().split()))
list_score.sort()
p_list = list(itertools.combinations(list_score, 3))
a = len(p_list)
ans = 0
for i in range(a):
if p_list[i][0] + p_list[i][1] > p_list[i][2]:
ans += 1
print(ans) | import itertools
n = int(eval(input()))
list_score = list(map(int, input().split()))
list_score.sort()
ans = 0
for i in range(0, n):
for j in range(i+1, n):
for k in range(i+1, j):
if list_score[k] + list_score[i] > list_score[j]:
ans += 1
print(ans) | p02888 |
N = int(eval(input()))
ll = list(map(int, input().split()))
def is_triangle(t):
a, b, c = t
if a < b + c and b < c + a and c < a + b:
return True
return False
import itertools
comb = list(itertools.combinations(ll ,3))
ans = len(list(filter(is_triangle, comb)))
print(ans) | eval(input())
ll = list(map(int, input().split()))
ll.sort()
def is_triangle(a, b, c):
if a < b + c and b < c + a and c < a + b:
return True
return False
ans = 0
for i, a in enumerate(ll):
for j, b in enumerate(ll[i+1:]):
climit = a + b
for k, c in enumerate(ll[i+j+2:]):
if c >= (climit):
break
if is_triangle(a, b, c):
ans += 1
print(ans) | p02888 |
n=int(eval(input()))
l=list(map(int,input().split()))
l.sort(reverse=True)
ans=0
for i in range(0,n-1):
for j in range(i+1,n-1):
for k in range(j+1,n):
if l[i]+l[j]>l[k] and l[i]+l[k]>l[j] and l[k]+l[j]>l[i]:
ans+=1
#print(l[i],l[j],l[k])
print(ans)
| n=int(eval(input()))
l=list(map(int,input().split()))
l.sort(reverse=True)
ans=0
for i in range(0,n-2):
for j in range(i+1,n-1):
left = j
right = n
while right-left>1:
mid = (left + right)//2
if l[i]+l[j]>l[mid] and l[i]+l[mid]>l[j] and l[mid]+l[j]>l[i]:
left = mid
else:
right = mid
#print(i,j,left)
ans+=(left-j)
print(ans) | p02888 |
n = int(eval(input()))
L = list(map(int,input().split()))
def tri_judge(a,b,c):
if a<b+c and b<c+a and c<a+b:
return 1
else:
return 0
cnt = 0
for i in range(n-2):
for j in range(i+1,n-1):
check = L[i]+L[j]
for k in range(j+1,n):
if check>L[k]:
if(tri_judge(L[i],L[j],L[k])):
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(i+1,N):
cnt += bisect.bisect_left(L,L[i]+L[j])-(j+1)
print(cnt) | p02888 |
from bisect import bisect_left
n = int(eval(input()))
a = sorted(map(int, input().split()))
print((sum(bisect_left(a, a[i] + a[j], i + 1) - i - 1
for i in range(1, n - 1) for j in range(i))))
| from bisect import bisect_right
n = int(eval(input()))
a = sorted(map(int, input().split()))
print((sum(j - bisect_right(a, a[i] - a[j], 0, j)
for i in range(2, n) for j in range(1, i)))) | p02888 |
import itertools
def d():
_ = int(eval(input()))
ls = list(map(int, input().split()))
combs = list(itertools.combinations(ls, 3))
count = 0
a = 0
b = 1
c = 2
for comb in combs:
if comb[a] < comb[b] + comb[c] and comb[b] < comb[c] + comb[a] and comb[c] < comb[a] + comb[b]:
count += 1
print(count)
if __name__ == '__main__':
d()
| import itertools
def d():
_ = int(eval(input()))
ls = list(map(int, input().split()))
combs = list(itertools.combinations(ls, 2))
count = 0
a = 0
b = 1
visited = set()
for comb in combs:
for l in ls:
if {comb[a], comb[b], l} not in visited:
visited.add(frozenset({comb[a], comb[b], l}))
if l != comb[a] and l != comb[b] and abs(comb[a] - comb[b]) < l < comb[a] + comb[b]:
count += 1
print(count)
if __name__ == '__main__':
d()
| p02888 |
import itertools
def d():
_ = int(eval(input()))
ls = list(map(int, input().split()))
combs = list(itertools.combinations(ls, 2))
count = 0
a = 0
b = 1
visited = set()
for comb in combs:
for l in ls:
if {comb[a], comb[b], l} not in visited:
visited.add(frozenset({comb[a], comb[b], l}))
if l != comb[a] and l != comb[b] and abs(comb[a] - comb[b]) < l < comb[a] + comb[b]:
count += 1
print(count)
if __name__ == '__main__':
d()
| def d():
n = int(eval(input()))
ls = list(map(int, input().split()))
ls.sort()
count = 0
for i in range(n-1):
k = i + 2
for j in range(i+1, n-1):
while k < n and ls[i] + ls[j] > ls[k]:
k += 1
count += k - j - 1
print(count)
if __name__ == '__main__':
d()
| p02888 |
import bisect
n = int(eval(input()))
l = sorted(list(map(int, input().split())))
ans = 0
for i in range(n-2):
a = l[i]
for j in range(i + 1, n-1):
ans += bisect.bisect_left(l, l[j]+a, lo = j + 1)-j-1
print(ans) | import bisect
n = int(eval(input()))
l = sorted(list(map(int, input().split())))
ans = 0
for i in range(n-2):
a = l[i]
for j in range(i + 1, n-1):
ans += bisect.bisect_left(l, l[j]+a)-j-1
print(ans) | p02888 |
import math
N = int(eval(input()))
L = sorted(list(map(int, input().split())))
ans = 0
for a in range(N - 2):
b = a + 1
c = a + 2
while c < N and b < N - 1:
if L[c] >= L[a] + L[b]:
ans += c - 1 - b
b += 1
if b == c:
c += 1
else:
if c == N - 1:
ans += c - b
b += 1
else:
c += 1
print(ans) | import math
N = int(eval(input()))
L = sorted(list(map(int, input().split())))
ans = 0
for a in range(N - 2):
b = a + 1
c = a + 2
while c < N and b < N - 1:
if L[c] >= L[a] + L[b]:
ans += c - 1 - b
b += 1
if b == c:
c += 1
else:
if c == N - 1:
ans += (c - b) * (c - b + 1) // 2
break
else:
c += 1
print(ans) | p02888 |
import math
N = int(eval(input()))
L = sorted(list(map(int, input().split())))
ans = 0
for a in range(N - 2):
b = a + 1
c = a + 2
while c < N and b < N - 1:
if L[c] >= L[a] + L[b]:
ans += c - 1 - b
b += 1
if b == c:
c += 1
else:
if c == N - 1:
ans += (c - b) * (c - b + 1) // 2
break
else:
c += 1
print(ans) | N = int(eval(input()))
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(0, N - 2):
a = L[i]
for j in range(i + 1, N - 1):
b = L[j]
ok = j + 1
ng = N - 1
if L[ng] < a + b:
ans += ng - j
continue
if L[ok] >= a + b:
continue
while ok + 1 < ng:
c = (ok + ng) // 2
if L[c] < a + b:
ok = c
else:
ng = c
ans += ok - j
print(ans) | p02888 |
value = 0
N = int(eval(input()))
L = list(map(int,input().split()))
L = sorted(L)
for i in range(N-2):
for j in range(i+1,N-1):
x = L[i]+L[j]
B = N-1
A = j
max_c_index = j
# while True:
while A <= B: #A>Bとなったときに停めるようにすれば簡潔
# M = A + (B-A)//2
M = (A+B)//2 #こう書くほうがシンプル
if L[M] < x:
max_c_index = M
A = M+1
else:
# B = M
B = M-1
value += max_c_index - j
print(value) | 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): # 真ん中の長さの棒
ans += bisect_left(L, L[i] + L[j]) - (j + 1)
print(ans) | p02888 |
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): # 真ん中の長さの棒
ans += 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): # 1番短い棒 #どうせ増えないからNでも多分大丈夫
for j in range(i + 1, N-1): # 真ん中の長さの棒
ans += bisect_left(L, L[i] + L[j]) - (j + 1)
print(ans) | p02888 |
import sys
import itertools
# import numpy as np
import time
import math
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
L = list(sorted(map(int, readline().split())))
ans = 0
for i in range(n):
a = L[i]
for j in range(i + 1, n):
b = L[j]
for k in range(j + 1, n):
c = L[k]
if a < b + c and b < c + a and c < a + b:
ans += 1
else:
break
print(ans) | import sys
import itertools
# import numpy as np
import time
import math
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
L = list(sorted(map(int, readline().split())))
ans = 0
import bisect
for i in range(n):
a = L[i]
for j in range(i + 1, n):
b = L[j]
cs = bisect.bisect_left(L, a + b)
ans += cs - j - 1
print(ans) | p02888 |
from bisect import bisect_left
from bisect import bisect_right
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
"""
短いほうから2本固定して条件に合うものをさがす(長いほうから2本固定でもOK)
最長と最短を固定するとややこしくなるから、こういう場合は最長/最短どちらかから固定するほうがいいか
"""
ans = 0
for i in range(N-2):
for j in range(i+1, N-1):
# そもそもcがaやbより大きいので、下の解法のようにilを求める必要などなく、il=で考えれば良かったんや!
k = bisect_left(L, L[i]+L[j], lo=j)
ans += k - j - 1
"""
ans = 0
for i in range(N):
for j in range(i+1, N):
l = L[j] - L[i]
r = L[j] + L[i]
# a < b < c(場合によっては等号を含む)で考えたときの、b - a < cを満たすもの
il = bisect_right(L, l, lo=j)
# a < b < c(場合によっては等号を含む)で考えたときの、c < a + bを満たすもの
ir = bisect_left(L, r, lo=j)
# b - a < cを満たすものがない場合、飛ばす
if il == N-1:
break
ans += ir - il - 1
"""
print(ans)
| from bisect import bisect_left
from bisect import bisect_right
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
"""
短いほうから2本固定して条件に合うものをさがす(長いほうから2本固定でもOK)
最長と最短を固定するとややこしくなるから、こういう場合は最長/最短どちらかから固定するほうがいいか
"""
ans = 0
for i in range(N-2):
a = L[i]
for j in range(i+1, N-1):
b = L[j]
# そもそもcがaやbより大きいので、下の解法のようにilを求める必要などなく、il=で考えれば良かったんや!
k = bisect_left(L, a+b)
ans += k - j - 1
"""
ans = 0
for i in range(N):
for j in range(i+1, N):
l = L[j] - L[i]
r = L[j] + L[i]
# a < b < c(場合によっては等号を含む)で考えたときの、b - a < cを満たすもの
il = bisect_right(L, l, lo=j)
# a < b < c(場合によっては等号を含む)で考えたときの、c < a + bを満たすもの
ir = bisect_left(L, r, lo=j)
# b - a < cを満たすものがない場合、飛ばす
if il == N-1:
break
ans += ir - il - 1
"""
print(ans)
| p02888 |
from bisect import bisect_left
from bisect import bisect_right
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
"""
短いほうから2本固定して条件に合うものをさがす(長いほうから2本固定でもOK)
最長と最短を固定するとややこしくなるから、こういう場合は最長/最短どちらかから固定するほうがいいか
"""
ans = 0
for i in range(N-2):
a = L[i]
for j in range(i+1, N-1):
b = L[j]
# そもそもcがaやbより大きいので、下の解法のようにilを求める必要などなく、il=で考えれば良かったんや!
k = bisect_left(L, a+b)
ans += k - j - 1
"""
ans = 0
for i in range(N):
for j in range(i+1, N):
l = L[j] - L[i]
r = L[j] + L[i]
# a < b < c(場合によっては等号を含む)で考えたときの、b - a < cを満たすもの
il = bisect_right(L, l, lo=j)
# a < b < c(場合によっては等号を含む)で考えたときの、c < a + bを満たすもの
ir = bisect_left(L, r, lo=j)
# b - a < cを満たすものがない場合、飛ばす
if il == N-1:
break
ans += ir - il - 1
"""
print(ans)
| from bisect import bisect_left
from bisect import bisect_right
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
"""
短いほうから2本固定して条件に合うものをさがす(長いほうから2本固定でもOK)
最長と最短を固定するとややこしくなるから、こういう場合は最長/最短どちらかから固定するほうがいいか
"""
ans = 0
for i in range(N-2):
a = L[i]
for j in range(i+1, N-1):
#b = L[j]
# そもそもcがaやbより大きいので、下の解法のようにilを求める必要などなく、il=で考えれば良かったんや!
k = bisect_left(L, a+L[j])
ans += k - j - 1
"""
ans = 0
for i in range(N):
for j in range(i+1, N):
l = L[j] - L[i]
r = L[j] + L[i]
# a < b < c(場合によっては等号を含む)で考えたときの、b - a < cを満たすもの
il = bisect_right(L, l, lo=j)
# a < b < c(場合によっては等号を含む)で考えたときの、c < a + bを満たすもの
ir = bisect_left(L, r, lo=j)
# b - a < cを満たすものがない場合、飛ばす
if il == N-1:
break
ans += ir - il - 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):
index = bisect.bisect_right(L, L[i] + L[j]-1)
ans += index - j - 1
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):
for j in range(i+1, N):
x = L[i] + L[j]
y = bisect_left(L, x)
ans += y - j - 1
print(ans) | p02888 |
from collections import deque
from bisect import bisect_left
n = int(eval(input()))
l = sorted(map(int, input().split()))
ld = deque(l)
cnt = 0
for a in range(n - 2):
l_a = ld.popleft()
for b in range(a + 1, n - 1):
cnt += bisect_left(l[b + 1 :], l_a + l[b])
print(cnt) | from collections import deque
from bisect import bisect_left
n = int(eval(input()))
l = sorted(map(int, input().split()))
ld = deque(l)
cnt = 0
for a in range(n - 2):
l_a = ld.popleft()
for b in range(a + 1, n - 1):
cnt += bisect_left(l, l_a + l[b]) - b - 1
print(cnt) | p02888 |
from collections import deque
from bisect import bisect_left
n = int(eval(input()))
l = sorted(map(int, input().split()))
ld = deque(l)
cnt = 0
for a in range(n - 2):
l_a = ld.popleft()
for b in range(a + 1, n - 1):
cnt += bisect_left(l, l_a + l[b]) - b - 1
print(cnt) | def main():
from collections import deque
from bisect import bisect_left
n = int(eval(input()))
l = sorted(map(int, input().split()))
ld = deque(l)
cnt = 0
for a in range(n - 2):
l_a = ld.popleft()
for b in range(a + 1, n - 1):
cnt += bisect_left(l, l_a + l[b]) - b - 1
print(cnt)
if __name__ == "__main__":
main() | p02888 |
#coding:utf-8
import sys
import bisect
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
input = lambda : given().rstrip()
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
XLMIIS = lambda x : [LMIIS() for _ in range(x)]
N = II()
L = LMIIS()
L.sort()
count = 0
for i in range(N):
a = L[i]
for j in range(i+1,N):
b = L[j]
k = j+1
while k < N and a+b > L[k]:
k += 1
count += 1
print(count)
if __name__ == '__main__':
main()
| #coding:utf-8
import sys
import bisect
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
input = lambda : given().rstrip()
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
XLMIIS = lambda x : [LMIIS() for _ in range(x)]
N = II()
L = LMIIS()
L.sort()
count = 0
for i in range(N):
a = L[i]
k = i+2
for j in range(i+1,N):
b = L[j]
while k < N and a+b > L[k]:
k += 1
count += k - 1 - j
print(count)
if __name__ == '__main__':
main()
| p02888 |
import itertools
N = int(eval(input()))
L = list(map(int, input().split()))
T = list(itertools.combinations(L,3))
ans = 0
for t in T:
if t[0] < t[1]+t[2] and t[1] < t[0]+t[2] and t[2] < t[0]+t[1]:
ans += 1
print(ans)
| N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
ans = 0
for n1 in range(N):
for n2 in range(n1+1, N):
for n3 in range(n2+1, N):
if L[n1] + L[n2] > L[n3]:
ans += 1
print(ans)
| p02888 |
import math
N=int(eval(input()))
S=input().split()
list=[]
for i in range(0,N):
list.append(int(S[i]))
list.sort()
ans=0
for i in range(0,N-2):
a=list[i]
for j in range(i+1,N-1):
b=list[j]
L=j+1
R=N-1
while True:
if L==R or R==L+1:
break
if list[math.floor((L+R)/2)]>=a+b:
R=math.floor((L+R)/2)
else:
L=math.floor((L+R)/2)
if list[L]>=a+b:
ans=ans+L-j-1
else:
if list[R]>=a+b:
ans=ans+L-j
else:
ans=ans+R-j
print(ans) | import bisect
n = int(eval(input()))
l = sorted(list(map(int,input().split())))
count = 0
for i in range(n):
for j in range(i+1,n):
index = bisect.bisect_left(l,l[i]+l[j])
count += index - j - 1
print(count) | p02888 |
import itertools
N = int(eval(input()))
L = [int(i) for i in input().split()]
l=list(itertools.combinations(L,3))
result = 0
for i in l:
isOk=True
a,b,c=i
if a+b>c and a+c>b and c+b>a:
result+=1
print(result) | N = int(eval(input()))
L = [int(i) for i in input().split()]
result = 0
for aIndex,a in enumerate(L):
for bIndex,b in enumerate(L[aIndex+1:]):
for c in L[aIndex+bIndex+2:]:
if a<b+c and b<a+c and c<a+b:
result+=1
print(result) | p02888 |
from bisect import bisect_left
N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
result = 0
for aIndex,a in enumerate(L[:N-2]):
for bIndex,b in enumerate(L[aIndex+1:N-1]):
bIndex = aIndex + bIndex + 1
ab = a+b
n = bisect_left(L,ab) - bIndex - 1
result += n
print(result) | from bisect import bisect_left
N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
result = 0
for i,a in enumerate(L[:N-2]):
i += 1
for j,b in enumerate(L[i:N-1]):
j += i + 1
n = bisect_left(L,a+b) - j
result += n
print(result) | p02888 |
import bisect
n = int(eval(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_right(l, a + b)
for c in l[e+1:idx]:
if not c < a + b:
break
ans += 1
print(ans)
| import bisect
n = int(eval(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, 0)
print(ans)
| p02888 |
from bisect import bisect_left
N = int(eval(input()))
L = [int(i) for i in input().split()]
L.sort()
num_triangles = 0
for i in range(N-2):
for j in range(i+1, N-1):
idx = bisect_left(a=L, x=L[i]+L[j], lo=j+1)
num_triangles += idx-(j+1)
print(num_triangles)
| 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):
endpt = bisect_left(l, l[i] + l[j])
ans += endpt-j-1
print(ans) | p02888 |
from bisect import bisect_left
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
num_triangles = 0
for i in range(N-2):
for j in range(i+1, N-1):
idx = bisect_left(a=L, x=L[i]+L[j], lo=j+1)
num_triangles += idx-j-1
print(num_triangles)
| from bisect import bisect_left
N = int(eval(input()))
L = list(map(int, input().split(" ")))
L.sort()
num_triangles = 0
for i in range(N-2):
for j in range(i+1, N-1):
idx = bisect_left(L, L[i]+L[j], j+1)
num_triangles += idx-j-1
print(num_triangles)
| p02888 |
from collections import deque
from copy import copy
import bisect
n = int(eval(input()))
order = sorted(list(map(int, input().split())))
l = deque(order)
ans = 0
for _ in range(len(l)-2):
first = l.pop()
m = copy(l)
for _ in range(len(m)-1):
second = m.pop()
fix = first-second
ans += len(m)-bisect.bisect_right(list(m), fix)
print(ans) | from bisect import bisect_right
n = int(eval(input()))
order = sorted(list(map(int, input().split())))
ans = 0
for i in reversed(list(range(2, n))):
for j in reversed(list(range(1, i))):
ans += j - bisect_right(order[0:j], order[i]-order[j])
print(ans) | p02888 |
from bisect import bisect_right
n = int(eval(input()))
order = sorted(list(map(int, input().split())))
ans = 0
for i in reversed(list(range(2, n))):
for j in reversed(list(range(1, i))):
ans += j - bisect_right(order[0:j], order[i]-order[j])
print(ans) | from bisect import bisect_right
n = int(eval(input()))
order = sorted(list(map(int, input().split())))
ans = 0
for i in reversed(list(range(2, n))):
for j in reversed(list(range(1, i))):
fix = bisect_right(order, order[i]-order[j])
if j > fix:
ans += j - fix
print(ans) | p02888 |
from bisect import bisect_left, bisect_right
N, *X = list(map(int, open(0).read().split()))
X.sort()
ans = 0
for i in range(N - 2):
for j in range(i + 1, N - 1):
k1 = bisect_right(X, X[j] - X[i])
k2 = bisect_left(X, X[i] + X[j])
k1 = max(k1, j + 1)
ans += max(0, k2 - k1)
print(ans)
|
from bisect import bisect_left
N = int(eval(input()))
X = list(map(int, input().split()))
X.sort()
ans = 0
for i in range(N):
for j in range(i + 1, N):
k = bisect_left(X, X[i] + X[j])
ans += k - j - 1
print(ans)
| p02888 |
# encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect
import collections
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
def LI(): return list(map(int, sys.stdin.readline().split()))
"""
nC3
|b - c| < a < |b + c|
nC2
b_i, c_iを除くiの中で|b-c|< a <b+cを満たすaの数をタス
"""
N = int(eval(input()))
L = LI()
L.sort()
ans = 0
for i in range(N - 1, -1, -1):
for j in range(i - 1, -1, -1):
# print(i, j)
a,b = L[i], L[j]
# print(L[:j])
# print(bisect.bisect_right(L[:j], a- b))
ans += j - bisect.bisect_right(L[:j], a- b)
# ans += bisect.bisect_right(L[:j], a-b) - bisect.bisect_left(L[:j], a-b)
print(ans)
| # encoding:utf-8
import copy
import random
import bisect #bisect_left これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect
import collections
mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000
def LI(): return list(map(int, sys.stdin.readline().split()))
"""
nC3
|b - c| < a < |b + c|
nC2
b_i, c_iを除くiの中で|b-c|< a <b+cを満たすaの数をタス
"""
N = int(eval(input()))
L = LI()
L.sort()
ans = 0
for i in range(N - 1, -1, -1):
for j in range(i - 1, -1, -1):
ans += j - bisect.bisect_right(L[:j], L[i] - L[j])
print(ans) | p02888 |
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort(reverse=True)
ans = 0
for i in range(N):
j = N-2
temp = 0
while j > i:
if temp > 0:
k = temp
else:
k = N - 1
while k > j:
if L[i]-L[j]-L[k] < 0:
ans += k-j
temp = k
break
k -=1
j -= 1
print(ans)
| N = int(eval(input()))
L = list(map(int, input().split()))
L.sort(reverse=True)
ck = [0]*(N-2)
ans = 0
for i in range(N-2):
j = i + 1
k = N - 1
while j < k:
if L[i]-L[j]-L[k] < 0:
ans += k-j
j += 1
else:
k -=1
print(ans) | p02888 |
from bisect import bisect
from bisect import bisect_right
from bisect import bisect_left
from bisect import insort
from bisect import insort_right
from bisect import insort_left
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
#print(L)
cnt = 0
for i in range(N):
for j in range(i+1, N):
s = L[i] + L[j]
x = bisect_left(L, s)
#print((L[i], L[j]), s, x)
cnt += max(x - j - 1, 0)
print(cnt) | from bisect import bisect
from bisect import bisect_right
from bisect import bisect_left
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
#print(L)
cnt = 0
for i in range(N):
for j in range(i+1, N):
s = L[i] + L[j]
x = bisect_left(L, s)
#print((L[i], L[j]), s, x)
cnt += max(x - j - 1, 0)
print(cnt) | p02888 |
import itertools
N = int(eval(input()))
L = list(map(int, input().split(' ')))
count = 0
for l in list(itertools.combinations(L, 3)):
if l[0] < l[1] + l[2] and l[1] < l[0] + l[2] and l[2] < l[0] + l[1]:
count += 1
print(count) | import itertools
N = int(eval(input()))
L = list(map(int, input().split(' ')))
L = sorted(L)
count = 0
for i in range(N - 1):
for j in range(i + 1, N - 1):
x, y = L[i], L[j]
top = N
bottom = j + 1
tmp = (top + bottom) // 2
while(top - bottom > 1):
if L[tmp] >= x + y:
top = tmp
tmp = (top + bottom) // 2
elif L[tmp] < x + y:
bottom = tmp
tmp = (top + bottom) // 2
if bottom - j == 1:
if L[bottom] < x + y:
count += 1
else:
count += (bottom - j)
print(count) | p02888 |
import bisect
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.bisect_left(L,L[i]+L[j])-j-1
ans+=bisect.bisect_left(L,L[i]+L[j],j)-j-1
print(ans) | import bisect
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.bisect_left(L,L[i]+L[j])-j-1 # Code 1
# ans+=bisect.bisect_left(L,L[i]+L[j],j)-j-1 # Code 2
print(ans) | p02888 |
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect
def solve():
n = int(eval(input()))
l = list(map(int, input().split()))
l.sort()
res = 0
for i in range(n):
for j in range(i+1, n):
k = bisect.bisect_left(l, l[i]+l[j])
res += max(k-(j+1), 0)
print(res)
return 0
if __name__ == "__main__":
solve() | import math
import collections
import fractions
import itertools
import functools
import operator
import bisect
def solve():
n = int(eval(input()))
l = list(map(int, input().split()))
l.sort()
res = 0
for i in range(n):
k = i
for j in range(i+1, n):
while(k < n and l[k] < l[i]+l[j]):
k += 1
res += k - (j+1)
print(res)
return 0
if __name__ == "__main__":
solve() | p02888 |
import sys
input = sys.stdin.readline
N = int(eval(input()))
L = [int(i) for i in input().split()]
total = 0
L = sorted(L, reverse=True)
for i in range(N-2):
if L[i+1] + L[i+2] <= L[i]:
continue
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]:
total +=1
else:
break
print(total)
| import sys
input = sys.stdin.readline
N = int(eval(input()))
L = [int(i) for i in input().split()]
total = 0
L = sorted(L)
for i in range(N-2):
k = i + 2
for j in range(i+1, N):
while k < N and L[i] + L[j] > L[k]:
k+=1
if k > j:
total += k-j-1
print(total)
| p02888 |
n = int(eval(input()))
ln = list(map(int, input().split()))
ln.sort()
def binary_search(x, r):
left = r + 1
right = n-1
while left < right:
mid = (left + right) // 2
if ln[mid] == x:
return mid
elif ln[mid] > x:
right = mid - 1
else:
left = mid + 1
mid = (left + right) // 2
if ln[mid] > x:
return mid - 1
else:
return mid
ans = 0
for a in range(n-2):
for b in range(a+1, n-1):
cmin = ln[b] - ln[a] + 1
cmax = ln[b] + ln[a] - 1
ans += max(0, binary_search(cmax, b) - b)
print(ans) | n = int(eval(input()))
ln = list(map(int, input().split()))
ln.sort()
def binary_search(x, r):
left = r + 1
right = n - 1
while left <= right:
mid = (left + right) // 2
if ln[mid] >= x:
right = mid - 1
else:
left = mid + 1
if ln[mid] >= x:
return mid - 1
else:
return mid
ans = 0
for a in range(n-2):
for b in range(a+1, n-1):
cmax = ln[b] + ln[a]
ans += max(0, binary_search(cmax, b) - b)
print(ans) | p02888 |
#!/usr/bin/env python3
import sys
from bisect import bisect_left
def main():
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):
index = bisect_left(L,L[i]+L[j])
ans += max(0,index-j-1)
print(ans)
if __name__ == '__main__':
main()
| from bisect import bisect_right
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):
b = L[i]
c = L[j]
M = L[i+1:j]
ans += bisect_right(M, b + c - 1) - bisect_right(M, c - b)
print(ans) | p02888 |
from bisect import bisect_left, bisect_right
n = int(eval(input()))
ls = sorted(list(map(int, input().split())))
total = 0
for i in range(n):
for j in range(i+1, n):
b, c = ls[i], ls[j]
lower = abs(b-c) + 0.5
upper = b+c - 0.5
ii = bisect_left(ls, lower)
jj = bisect_left(ls, upper)
cnt = jj - ii
if i in range(ii, jj):
cnt -= 1
if j in range(ii, jj):
cnt -= 1
total += cnt
total //= 3
print(total)
| from bisect import bisect_left, bisect_right
n = int(eval(input()))
ls = sorted(list(map(int, input().split())))
total = 0
for i in range(n):
for j in range(i+1, n):
b, c = ls[i], ls[j]
lower = abs(b-c) + 0.5
upper = b+c - 0.5
ii = bisect_left(ls, lower)
jj = bisect_left(ls, upper)
cnt = jj - ii
if ii <= i < jj:
cnt -= 1
if ii <= j < jj:
cnt -= 1
total += cnt
total //= 3
print(total)
| p02888 |
import sys
input = sys.stdin.readline
import collections
import bisect
def main():
n = int(eval(input()))
l = input_list()
l.sort()
ans = 0
for i in range(n-2):
for j in range(i+1, n-1):
ind = bisect.bisect_left(l, l[i]+l[j])
num = ind - 1 - j
ans += num
print(ans)
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
import bisect
# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
n = int(eval(input()))
l = sorted(input_list())
ans = 0
for a in range(n):
for b in range(a+1, n):
ans += bisect.bisect_left(l, l[a]+l[b]) - (b+1)
print(ans)
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == "__main__":
main()
| p02888 |
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left
def solve():
n = int(eval(input()))
l = [int(x) for x in input().split()]
l.sort()
ans = 0
for i in range(n):
for j in range(i + 1, n):
r = bisect_left(l, l[i] + l[j])
if r > j:
ans += r - j - 1
print(ans)
t = 1
# t = int(input())
for case in range(1,t+1):
ans = solve()
"""
azyxwvutsrqponmlkjihgfedcb
"""
| # -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left
def solve():
n = int(eval(input()))
l = [int(x) for x in input().split()]
l.sort()
ans = 0
for i in range(n):
for j in range(i + 1, n):
r = bisect_left(l, l[i] + l[j])
# if r > j:
ans += r - j - 1
print(ans)
t = 1
# t = int(input())
for case in range(1,t+1):
ans = solve()
"""
azyxwvutsrqponmlkjihgfedcb
"""
| 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):
small = bisect.bisect_left(L, L[j]-L[i])
large = bisect.bisect_left(L, L[j]+L[i])
#print(i,j,L[i],L[j]," ",L[j]-L[i],L[j]+L[i],small,large)
ans += max(large-j-1,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):
for j in range(i+1,N-1):
#small = bisect.bisect_left(L, L[j]-L[i])
large = bisect.bisect_left(L, L[j]+L[i])
#print(i,j,L[i],L[j]," ",L[j]-L[i],L[j]+L[i],small,large)
ans += max(large-j-1,0)
print(ans) | p02888 |
eval(input())
a = input().split(' ')
b = []
for i in a:
b.append(int(i))
b.sort()
b.reverse()
out = 0
for i in range(len(b) - 2):
l = i + 1
r = len(b) - 1
while l < r:
if b[i] < b[l] + b[r]:
out += r - l
l += 1
else:
r -= 1
print(out)
| n = int(eval(input()))
sticks = list (map (int, input().strip().split()))
sticks.sort()
ans = 0
for a_idx in range(n - 1, 0, -1):
b_idx = a_idx - 1
c_idx = 0
while c_idx < b_idx:
if sticks[a_idx] < sticks[b_idx] + sticks[c_idx]:
ans += b_idx - c_idx
b_idx -= 1
else:
c_idx += 1
print(ans) | p02888 |
import sys
input = sys.stdin.readline
import itertools
import bisect
def main():
N = int(eval(input()))
L = [int(x) for x in input().split()]
ans = 0
L_sorted = sorted(L)
for i in range(N - 2):
for j in range(i + 1, N - 1):
a = L_sorted[i]
b = L_sorted[j]
l = bisect.bisect_left(L_sorted[j:], max(a - b, b - a))
r = bisect.bisect_left(L_sorted[j:], a + b)
ans += r - l - 1
print(ans)
if __name__ == '__main__':
main()
| import sys
input = sys.stdin.readline
import itertools
import bisect
def main():
N = int(eval(input()))
L = [int(x) for x in input().split()]
ans = 0
L_sorted = sorted(L)
for i in range(N - 2):
for j in range(i + 1, N - 1):
a = L_sorted[i]
b = L_sorted[j]
l = bisect.bisect_left(L_sorted, max(a - b, b - a), lo=j + 1)
r = bisect.bisect_left(L_sorted, a + b, lo=j + 1)
ans += r - l
print(ans)
if __name__ == '__main__':
main()
| p02888 |
import sys
input = sys.stdin.readline
import itertools
import bisect
def main():
N = int(eval(input()))
L = [int(x) for x in input().split()]
ans = 0
L_sorted = sorted(L)
for i in range(N - 2):
for j in range(i + 1, N - 1):
a = L_sorted[i]
b = L_sorted[j]
l = bisect.bisect_left(L_sorted, max(a - b, b - a), lo=j + 1)
r = bisect.bisect_left(L_sorted, a + b, lo=j + 1)
ans += r - l
print(ans)
if __name__ == '__main__':
main()
| import sys
input = sys.stdin.readline
import itertools
import bisect
def main():
N = int(eval(input()))
L = [int(x) for x in input().split()]
ans = 0
L_sorted = sorted(L)
for i in range(N - 2):
a = L_sorted[i]
for j in range(i + 1, N - 1):
b = L_sorted[j]
r = bisect.bisect_left(L_sorted, a + b, lo=j + 1)
ans += r - j - 1
print(ans)
if __name__ == '__main__':
main()
| p02888 |
# coding: utf-8
import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(eval(input()))
def MI() : return list(map(int, input().split()))
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(eval(input())) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in list(currentframe().f_back.f_locals.items())}; print((', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args)))
N = I()
L = LI()
L.sort()
ans = 0
for i, l in enumerate(L):
for j in range(i + 1, N):
for k in range(j + 1, N):
if l + L[j] <= L[k]:
break
ans += 1
print(ans) | # coding: utf-8
import sys
import math
import collections
import itertools
import bisect
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")
N = I()
L = LI()
L.sort()
ans = 0
for i in range(N):
for j in range(i+1, N):
c = bisect.bisect_left(L, L[i]+L[j])
ans += max(0, c - (j+1))
print(ans)
| p02888 |
from sys import stdout
import bisect
printn = lambda x: stdout.write(x)
inn = lambda : int(eval(input()))
inl = lambda: list(map(int, input().split()))
inm = lambda: list(map(int, input().split()))
DBG = True and False
BIG = 999999999
R = 10**9 + 7
def ddprint(x):
if DBG:
print(x)
n = inn()
l = inl()
acc = 0
l.sort()
for i in range(n-2):
a = l[i]
for j in range(i+1,n-1):
b = l[j]
e = bisect.bisect_left(l,a+b)
ddprint("a {} b {} i {} j {} e {}".format(a,b,i,j,e))
acc += e-j-1
print(acc)
| from sys import stdout
import bisect
printn = lambda x: stdout.write(x)
inn = lambda : int(eval(input()))
inl = lambda: list(map(int, input().split()))
inm = lambda: list(map(int, input().split()))
DBG = True and False
BIG = 999999999
R = 10**9 + 7
def ddprint(x):
if DBG:
print(x)
n = inn()
l = inl()
acc = 0
l.sort()
for i in range(n-2):
a = l[i]
for j in range(i+1,n-1):
b = l[j]
e = bisect.bisect_left(l[j+1:],a+b)
#ddprint("a {} b {} i {} j {} e {}".format(a,b,i,j,e))
acc += e #-j-1
print(acc)
| p02888 |
n = int(eval(input()))
a = list(map(int,input().split()))
a.sort()
ans = 0
for r in range(n-1,-1,-1):
m = r
for l in range(n):
if l == m and m + 1 < r:
m += 1
while True:
if a[l] + a[m-1] > a[r] and l < m-1:
m -= 1
else:
break
if l < m < r:
ans += r - m
#print(l,m,r)
print(ans) | n = int(eval(input()))
a = list(map(int,input().split()))
a.sort()
ans = 0
for r in range(n-1,-1,-1):
m = r
for l in range(n):
if l == m and m + 1 < r:
m += 1
else:
while True:
if a[l] + a[m-1] > a[r] and l < m-1:
m -= 1
else:
break
if l < m < r:
ans += r - m
#print(l,m,r)
print(ans) | p02888 |
import itertools
n = int(eval(input()))
l = list(map(int,input().split()))
c = [i for i in itertools.combinations(l,3) if i[0]<i[1]+i[2] and i[1]<i[2]+i[0] and i[2]<i[0]+i[1]]
print((len(c))) | 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 itertools
import bisect
n=int(eval(input()))
count = 0
a=sorted(list(map(int, input().split(" "))))
for i in range(2,n):
for j, k in itertools.combinations(a[:i], 2):
if j + k > a[i]:
count += 1
print(count) | n = int(eval(input()))
import bisect
a = sorted(list(map(int, input().split(" "))))
ans = 0
for i in range(1, n-1):
b = a[:i]
c = a[i + 1:]
#print(b, c)
for j in b:
ans += bisect.bisect(c, a[i]+j-0.1)
#print(bisect.bisect(c, a[i]+j-0.1))
print(ans) | p02888 |
import sys
N = int(eval(input()))
L = list(map(int, input().split()))
from itertools import permutations, combinations,combinations_with_replacement,product
nCr = list(combinations(list(range(N)), 3))
ret = 0
for i in nCr:
if L[i[0]]<L[i[1]]+L[i[2]] and L[i[1]]<L[i[2]]+L[i[0]] and L[i[2]]<L[i[0]]+L[i[1]]:
ret +=1
print(ret) | N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
ret = 0
for i in range(0, N-2):
for j in range(i+1, N-1):
ret += len([k for k in L[j+1:] if L[i]+L[j]>k])
print(ret) | p02888 |
import bisect
def main():
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
# print(L)
ab =[L[0]+L[1]]
ans = 0
for i in range(2, N):
c = L[i]
j = bisect.bisect_right(ab, c)
# print(j)
# print(ab)
ans += len(ab) - j
for k in range(i):
bisect.insort_left(ab, c+L[k])
# print(ab)
return ans
if __name__ == '__main__':
print((main())) | import bisect
def main():
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
# print(L)
ans = 0
for i in range(N-2):
for j in range(i+2, N):
a = L[i]
c = L[j]
k = bisect.bisect_left(L, c-a+1)
if k <= i:
ans += j-i-1
else:
ans += j-k
return ans
if __name__ == '__main__':
print((main())) | p02888 |
length = 2010
n = int(eval(input()))
L = list(map(int, input().split()))
ans = 0
L.sort()
sum_1 = [ 0 for _ in range(length)]
for i in range(n):
sum_1[L[i]]+=1
#棒の長さで累積和
for i in range(length-1):
sum_1[i+1] +=sum_1[i]
for i in range(n-1):
for j in range(i+1, n):
a = abs(L[i]-L[j])
b = L[i]+L[j]
ans = ans + sum_1[b-1] - sum_1[a]
if a<L[i] and L[i]<b:
ans -=1
if a<L[j] and L[j]<b:
ans -=1
print((ans//3)) | length = 2010
n = int(eval(input()))
L = list(map(int, input().split()))
ans = 0
L.sort()
sum_1 = [0]*length
for i in range(n):
sum_1[L[i]]+=1
#棒の長さで累積和
for i in range(length-1):
sum_1[i+1] +=sum_1[i]
for i in range(n-1):
for j in range(i+1, n):
a = abs(L[i]-L[j])
b = L[i]+L[j]
ans = ans + sum_1[b-1] - sum_1[a]
if a<L[i] and L[i]<b:
ans -=1
if a<L[j] and L[j]<b:
ans -=1
print((ans//3)) | p02888 |
import bisect
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
ans = 0
for k in range(N-2):
for j in range(k+1, N-1):
ans += bisect.bisect_left(L[j+1:], L[k]+L[j])
print(ans) | import bisect
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
ans = 0
from bisect import bisect_left
for k in range(N-2):
for j in range(k+1, N-1):
ans += bisect_left(L[j+1:], L[k]+L[j])
print(ans) | p02888 |
n = int(eval(input()))
l = list(map(int, input().split()))
s = 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]:
s += 1
print(s)
| n = int(eval(input()))
l = list(map(int, input().split()))
s = 0
l.sort()
for i in range(n-2):
j = n-2
k = n-1
while i < j:
if l[k] >= l[i] + l[j] and j < k:
#print(0, i, j, k)
k -= 1
else:
#print(1, i, j, k)
s += k - j
j -= 1
print(s)
| p02888 |
import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
def main():
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort(reverse=True)
max_l = max(L)
ans = 0
for a in range(N):
for b in range(a+1, N):
if L[a] >= L[b] + max_l:
continue
for c in range(b+1, N):
if L[a] < L[b] + L[c] and L[b] < L[c] + L[a] and L[c] < L[a] + L[b]:
ans += 1
else:
break
print(ans)
if __name__ == '__main__':
main() | import sys
import bisect
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce, reduce
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
def main():
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-1):
ab = L[a] + L[b]
i = bisect.bisect_left(L, ab) - 1
ans += i - b
print(ans)
if __name__ == '__main__':
main() | p02888 |
import bisect
n = int(eval(input()))
l = sorted([int(li) for li in input().split()])
sum = 0
for i in range(n)[::-1]:
for j in range(i)[::-1]:
k = bisect.bisect_right(l[:j],l[i]-l[j])
sum += j-k
print(sum)
| import bisect
n = int(eval(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,l[i]-l[j])
sum += j-k if j>k else 0
print(sum)
| p02888 |
N=int(eval(input()))
L=[int(x) for x in input().split()]
L.sort()
count=0
for i,a in enumerate(L):
for j,b in enumerate(L[i+1:]):
for k,c in enumerate(L[i+j+2:]):
if c>=a+b:
break
count+=1
print(count) | def main():
N=int(eval(input()))
L=[int(x) for x in input().split()]
L.sort()
count=0
dic={}
for i in range(N):
for j in range(i+1,N):
if i:
try:
start=dic[j]
count+=dic[j]-j-1
except:
count+=N-j-1
continue
else:
start=j+1
for k in range(start,N):
if L[k]>=L[i]+L[j]:
dic[j]=k
break
count+=1
print(count)
main()
| p02888 |
N = int(eval(input()))
L = list(map(int,input().split()))
L.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[k] < L[i] + L[j]:
cnt += 1
print(cnt) | import bisect
N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
cnt = 0
for i in range(N-2):
for j in range(i+1,N-1):
num = L[i] + L[j]
third = bisect.bisect_left(L,num)
if third > j:
cnt += third - j - 1
print(cnt) | p02888 |
import itertools
import sys
from collections import defaultdict
input = sys.stdin.readline
class AtCoder:
def main(self):
N = int(eval(input()))
L = list(map(int, input().split()))
ans = 0
for a,b,c in itertools.combinations(L,3):
if a < b + c and b < c + a and c < a + b:
ans += 1
print(ans)
# Run main
if __name__ == '__main__':
AtCoder().main()
| import bisect
import itertools
import sys
input = sys.stdin.readline
class AtCoder:
def main(self):
N = int(eval(input()))
L = list(map(int, input().split()))
ans = 0
L.sort()
for i in range(N - 2):
for j in range(i + 1, N - 1):
ind = bisect.bisect_left(L, L[i] + L[j])
ans += ind - j - 1
print(ans)
# Run main
if __name__ == '__main__':
AtCoder().main()
| p02888 |
n = int(eval(input()))
L = sorted(list(map(int, input().split())))
def isOK(target,a,b):
return target > abs(a-b) and target < a+b
def bin_search(a,b):
left = 1
right = n
while right-left>1:
mid = left+(right-left)//2
if isOK(L[mid],a,b):
left = mid
else:
right = mid
return left
ans = 0
for i in range(n):
for j in range(i+1,n):
a,b = L[i],L[j]
ans += max(0, bin_search(a,b) - j)
print(ans)
| n = int(eval(input()))
L = sorted(list(map(int, input().split())))
def isOK(target,a,b):
return target < a+b
def bin_search(a,b):
left = 1
right = n
while abs(right-left)>1:
mid = (left+right)//2
if isOK(L[mid],a,b):
left = mid
else:
right = mid
return left
ans = 0
for i in range(n-2):
for j in range(i+1,n):
a,b = L[i],L[j]
ans += max(0, bin_search(a,b) - j)
print(ans)
| p02888 |
import bisect
N= int(eval(input()))
L = list(map(int, input().split()))
L.sort(reverse=True)
#print(L)
for i in range(N):
L[i] *= -1
count = 0
for i in range(N-2):
#print(i)
for j in range(i+1, N-1):
if -L[i] >= -L[j] * 2:
break
data = L[i] - L[j]
#print(data, L[j + 1 : N])
#print(bisect.bisect_left(L[j + 1 : N], data))
count += bisect.bisect_left(L[j + 1 : N], data)
print(count) | import bisect
N= int(eval(input()))
L = list(map(int, input().split()))
L.sort(reverse=True)
#print(L)
for i in range(N):
L[i] *= -1
count = 0
for i in range(N-2):
#print(i)
for j in range(i+1, N-1):
if -L[i] >= -L[j] * 2:
break
data = L[i] - L[j]
#print(data, L[j + 1 : N])
#print(bisect.bisect_left(L[j + 1 : N], data))
count += bisect.bisect_left(L, data) - (j+1)
print(count) | p02888 |
import bisect
n = int(eval(input()))
L = sorted(map(int, input().split()))
ans = 0
for i in range(n-2):
a = L[i]
for j in range(i+1, n-1):
b = L[j]
l = bisect.bisect(L[j+1:n], a+b-1)
ans += l
print(ans)
| import bisect
n = int(eval(input()))
L = sorted(map(int, input().split()))
ans = 0
for i in range(n):
a = L[i]
for j in range(i+1, n):
b = L[j]
k = bisect.bisect_left(L, a+b)
if k > j:
ans += k - j - 1
print(ans)
| p02888 |
import bisect
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
cnt = 0
for i in range(N):
for j in range(i + 1, N):
idx = bisect.bisect_left(L, L[i] + L[j], lo=j + 1)
cnt += max(0, idx - (j + 1))
print(cnt) | import bisect
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
cnt = 0
for i in range(N):
for j in range(i + 1, N):
idx = bisect.bisect_left(L, L[i] + L[j])
cnt += max(0, idx - (j + 1))
print(cnt) | p02888 |
import bisect
N = int(eval(input()))
L = sorted(list(map(int, input().split())))
cnt = 0
for i in range(N - 2):
for j in range(i + 1, N - 1):
idx = bisect.bisect_left(L, L[i] + L[j], lo=j + 1)
cnt += max(0, idx - (j + 1))
print(cnt) | import bisect
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):
k = bisect.bisect_left(L, L[i] + L[j], j + 1) - 1
ans += k - j
print(ans)
| p02888 |
import sys
from bisect import bisect_left as bl
from bisect import bisect_right as br
input = sys.stdin.buffer.readline
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
dl = []
for i in range(N - 1):
for j in range(i + 1, N):
dl.append((L[i] + L[j], i, j, abs(L[i] - L[j])))
dl.sort()
#print(L)
#print(dl)
res = 0
for d in dl:
ind = bl(L, d[0])
ind2 = br(L, d[3])
res += ind - ind2
if ind2 <= d[1] <= ind:
res -= 1
if ind2 <= d[2] <= ind:
res -= 1
#print(res, d, ind, ind2)
print((res // 3)) | import sys
from bisect import bisect_left as bl
from bisect import bisect_right as br
input = sys.stdin.buffer.readline
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
dl = []
res = 0
for i in range(N - 1):
for j in range(i + 1, N):
d0 = L[i] + L[j]
d1 = i
d2 = j
d3 = abs(L[i] - L[j])
ind = bl(L, d0)
ind2 = br(L, d3)
res += ind - ind2
if ind2 <= d1 <= ind:
res -= 1
if ind2 <= d2 <= ind:
res -= 1
#print(res, d, ind, ind2)
print((res // 3)) | p02888 |
import bisect
def main():
n = int(eval(input()))
L = list(int(x) for x in 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)
if __name__ == '__main__':
main() | import bisect
def main():
n = int(eval(input()))
L = list(int(x) for x in input().split())
ans = 0
c = 0
L.sort()
for i in range(n-2):
for j in range(i+1, n-1):
c = L[i]+L[j]
l = j
r = bisect.bisect_left(L, c, lo=l) -1
ans += (r-l)
print(ans)
if __name__ == '__main__':
main() | p02888 |
from bisect import bisect_left
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
count = 0
for i in range(N):
for j in range(i+1, N):
max_len = L[i] + L[j]
count += bisect_left(L, max_len) - j - 1
print(count)
| from bisect import bisect_left
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-1):
for j in range(i+1, N):
l = L[i] + L[j]
k = bisect_left(L, l)
ans += max(0, k - j - 1)
print(ans) | p02888 |
import itertools
n = int(eval(input()))
l = list(map(int, input().split()))
counter = 0
for v in itertools.combinations(l, 3):
if 2 * max(v) < sum(v):
counter += 1
print(counter) | import bisect
n = int(eval(input()))
l = sorted(list(map(int, input().split())))
counter = 0
for i in range(n):
for j in range(i + 1, n):
counter += (bisect.bisect_left(l, l[i] + l[j]) - j - 1)
print(counter) | p02888 |
n = int(eval(input()))
l = sorted(list(map(int,input().split())))
ans = 0
import bisect
for i in range(n):
for j in range(i+1,n):
a1 = abs(l[i]-l[j])
a2 = l[i]+l[j]
x1 = bisect.bisect_right(l,a1)
x2 = bisect.bisect_left(l,a2)
buf = 0
if x1<=i<=x2:buf+=1
if x1<=j<=x2:buf+=1
ans += max(0,x2-x1-buf)
print((ans//3))
| n = int(eval(input()))
l = sorted(list(map(int,input().split())))
ans = 0
import bisect
for i in range(n):
for j in range(i+1,n):
a = l[i]+l[j]
x = bisect.bisect_left(l,a)
if x>j:
ans += max(0,x-j-1)
print(ans)
| p02888 |
# -*- coding: utf-8 -*-
import bisect
import sys
input = sys.stdin.readline
def main():
n = int(eval(input()))
l = list(map(int, input().split()))
l = sorted(l)
result = 0
for i in range(n-2):
for j in range(i + 1, n - 1):
result += bisect.bisect_left(l[j+1:], l[i] + l[j])
print(result)
if __name__ == '__main__':
main() | # -*- coding: utf-8 -*-
import bisect
import sys
input = sys.stdin.readline
def main():
n = int(eval(input()))
l = list(map(int, input().split()))
l = sorted(l)
result = 0
for i in range(n-2):
for j in range(i + 1, n - 1):
result += bisect.bisect_left(l, l[i] + l[j]) - (j + 1)
print(result)
if __name__ == '__main__':
main() | p02888 |
N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
ans = 0
import bisect
for i in range(N-2):
for j in range(i,N-1):
if i==j:
continue
a = L[i]
b = L[j]
k = bisect.bisect_left(L[j+1:],a+b)
l = bisect.bisect_left(L[j+1:],abs(a-b))
if k<N-j:
c = L[k+j]
d = L[l+j+1]
if 0<d<=c:
ans += k-l
print(ans)
| N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
ans = 0
import bisect
for i in range(N-2):
a = L[i]
for j in range(i+1,N-1):
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) | p02888 |
from bisect import bisect_left
n = int(eval(input()))
length_list = list(map(int, input().split()))
count = 0
length_list.sort()
for a_idx in range(n - 2):
for b_idx in range(a_idx + 1, n - 1):
a = length_list[a_idx]
b = length_list[b_idx]
if b > a:
a, b = b, a
left_count = bisect_left(length_list, a+b)
count += max(0, left_count - b_idx - 1)
print(count) | from bisect import bisect_left
n = int(eval(input()))
length_list = list(map(int, input().split()))
count = 0
length_list.sort()
for a_idx in range(n - 2):
for b_idx in range(a_idx + 1, n - 1):
a = length_list[a_idx]
b = length_list[b_idx]
left_count = bisect_left(length_list, a+b)
count += max(0, left_count - b_idx - 1)
print(count) | p02888 |
### a<=b<=cととることとし、a,bを固定すると
### cは c<a+b
from bisect import bisect_left
N = int(eval(input()))
lst = list(map(int, input().split()))
sor = sorted(lst)
res = 0
for i in range(N):
for j in range(i+1, N):##ここでa<=bを満たしている
ab = sor[i] + sor[j]
highbound = bisect_left(sor, ab)
res += highbound - j - 1
print(res)
### ライブラリを使おう!!! | ### a<=b<=cととることとし、a,bを固定すると
### cは c<a+b
from bisect import bisect_left
def main():
N = int(eval(input()))
lst = list(map(int, input().split()))
sor = sorted(lst)
res = 0
for i in range(N):
for j in range(i+1, N):##ここでa<=bを満たしている
ab = sor[i] + sor[j]
highbound = bisect_left(sor, ab)
res += highbound - j - 1
print(res)
main()
### ライブラリを使おう!!! | p02888 |
import bisect
N = int(eval(input()))
L = input().split()
for i in range(0, N):
L[i] = int(L[i])
L.sort()
ans = 0
for i in range(0, N-1):
for j in range(i+1, N):
a = L[j] - L[i]
b = L[j] + L[i]
c = bisect.bisect_right(L, a)
d = bisect.bisect_left(L, b)
if 2*L[i] > L[j]:
ans += d-c-2
else:
ans += d-c-1
print((ans // 3)) | import bisect
N = int(eval(input()))
L = input().split()
for i in range(0, N):
L[i] = int(L[i])
L.sort()
ans = 0
for i in range(0, N-1):
for j in range(i+1, N):
a = L[i] + L[j]
b = bisect.bisect_left(L, a)
ans += b-j-1
print(ans) | p02888 |
n = int(eval(input()))
l = list(map(int, input().split()))
l.sort()
def check(x, a):
if a < x:
return True
else:
return False
def bin_search(x, ok, ng, l):
while ng - ok > 1:
mid = (ng + ok) // 2
if check(x, l[mid]):
ok = mid
else:
ng = mid
return ok + 1
ans = 0
for i in range(n - 2):
for j in range(i + 1, n - 1):
ans += bin_search(l[i] + l[j], -1, n - j - 1, l[j + 1:])
print(ans) | n = int(eval(input()))
l = list(map(int, input().split()))
l.sort()
def bin_search(x, ok, ng, l):
while ng - ok > 1:
mid = (ng + ok) // 2
if l[mid] < x:
ok = mid
else:
ng = mid
return ok + 1
ans = 0
for i in range(n - 2):
for j in range(i + 1, n - 1):
ans += bin_search(l[i] + l[j], -1, n - j - 1, l[j + 1:])
print(ans) | p02888 |
N = int(eval(input()))
L = list(map(int, input().split()))
from itertools import combinations
cb = list(combinations(L, 3))
def my_def(x):
if x[0] + x[1] > x[2]:
if x[1] + x[2] > x[0]:
if x[0] + x[2] > x[1]:
return(True)
return(False)
print((sum(list(map(my_def, cb))))) | N = int(eval(input()))
L = list(map(int, input().split()))
from itertools import combinations
cb = combinations(L, 3)
def my_def(x):
#cb.sort
if x[1] + x[2] > x[0]:
if x[0] + x[2] > x[1]:
if x[0] + x[1] > x[2]:
return(True)
return(False)
print((sum(list(map(my_def, cb))))) | p02888 |
from bisect import bisect, bisect_left
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
cnt = 0
for i in range(N-1):
for j in range(i):
a, b = L[i], L[j]
k = i + 1
l = bisect_left(L[i+1:], a-b) + i+1
r = bisect_left(L, a+b)
cnt += max(r - l, 0)
print(cnt) | from bisect import bisect, bisect_left
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
cnt = 0
for i in range(N-1):
for j in range(i):
a, b = L[i], L[j]
r = bisect_left(L[i+1:], a+b) + i+1
cnt += max(r - i - 1, 0)
print(cnt) | p02888 |
#!/usr/bin/env python3
import sys
# import numpy as np
import bisect
def solve(N: int, L: "List[int]"):
L = sorted(L)
ct = 0
for a in range(len(L)-2):
a_ = L[a]
# for b in range(a+1, len(L)-1):
# ct+= bisect.bisect_left(L[b+1:],a_+L[b])
# print("L :{} a+Lb :{} b_in:{}".format(L[b+1:],a_+L[b],ct))
ct += sum([bisect.bisect_left(L[b+1:],a_+L[b]) for b in range(a+1, len(L)-1)])
print(ct)
return
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
L = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, L)
if __name__ == '__main__':
main()
| #!/usr/bin/env python3
import sys
# import numpy as np
import bisect
def solve(N: int, L: "List[int]"):
L = sorted(L)
ct = 0
for a in range(len(L)-2):
a_ = L[a]
for b in range(a+1, len(L)-1):
b_in = bisect.bisect_left(L,a_+L[b]) - b -1
if b_in > 0:
ct+=b_in
# print("L :{} a+Lb :{} b_in:{}".format(L[b+1:],a_+L[b],ct))
# ct += sum([bisect.bisect_left(L[b+1:],a_+L[b]) for b in range(a+1, len(L)-1)])
print(ct)
return
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
L = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, L)
if __name__ == '__main__':
main()
| p02888 |
N = int(eval(input()))
L = sorted(map(int, input().split()))
counter = 0
for i in range(N):
a = L[i]
for j in range(i+1, N):
b = L[j]
for k in range(j+1, N):
c = L[k]
if c >= a + b:
break
elif b < c + a and a < b + c:
counter += 1
print(counter) | import bisect
N = int(eval(input()))
L = sorted(map(int, input().split()))
counter = 0
for i in range(N):
a = L[i]
for j in range(i+1, N):
b = L[j]
k = bisect.bisect_left(L, a + b)
counter += max(0, k - (j + 1))
print(counter) | p02888 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.