input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
import bisect n = int(eval(input())) A = sorted(list(map(int,input().split()))) B = sorted(list(map(int,input().split()))) C = sorted(list(map(int,input().split()))) cnt = 0 for b in B : a_cnt = len(A[:bisect.bisect_left(A,b)]) c_cnt = len(C[bisect.bisect_right(C,b):]) cnt += a_cnt * c_cnt print(cnt)
import bisect n = int(eval(input())) A = sorted(list(map(int,input().split()))) B = sorted(list(map(int,input().split()))) C = sorted(list(map(int,input().split()))) cnt = 0 for j in range(n) : a = bisect.bisect_left(A,B[j]) c = bisect.bisect_right(C,B[j]) cnt += a * (n-c) print(cnt)
p03557
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() count = 0 for i in range(n): x = a[i] + 1 index1 = bisect.bisect_left(b, x) if index1 >= n: break b_tmp = b[index1:] for j in b_tmp: y = j + 1 index2 = bisect.bisect_left(c, y) if index2 >= n: break c_tmp = c[index2:] count += len(c_tmp) print(count)
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() count = 0 for i in b: x = bisect.bisect_left(a, i) y = bisect.bisect_right(c, i) count += x * (len(c) - y) print(count)
p03557
n = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) ans=0 for a in A: for i in range(len(B)): if a < B[i]: for j in range(len(C)): if B[i] < C[j]: ans += len(C)-j break print(ans)
n = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) import bisect ans = 0 for b in B: a = bisect.bisect_left(A,b) c = n - bisect.bisect_right(C,b) ans += a*c print(ans)
p03557
N = int(eval(input())) A = sorted(map(int, input().split())) B = list(map(int, input().split())) C = sorted(map(int, input().split()), reverse=True) counts = 0 checked = {} for _numB in B: if _numB in checked: counts += checked[_numB] else: countsA = 0 for _numA in A: if (_numB > _numA): countsA += 1 else: break countsC = 0 for _numC in C: if (_numC > _numB): countsC += 1 else: break checked[_numB] = countsA * countsC counts += countsA * countsC print(counts)
import bisect N = int(eval(input())) A = sorted(map(int, input().split())) B = list(map(int, input().split())) C = sorted(map(int, input().split())) counts = 0 checked = {} for _numB in B: if _numB not in checked: countsA = bisect.bisect_left(A, _numB) countsC = bisect.bisect_right(C, _numB) checked[_numB] = countsA * (N - countsC) counts += checked[_numB] print(counts)
p03557
n=int(eval(input())) lists1=sorted(list(map(int,input().split()))) lists2=sorted(list(map(int,input().split()))) lists3=sorted(list(map(int,input().split())),reverse=True) lists_small=[] lists_big=[] for x in lists2: numbers=0 for y in lists1: if y<x: numbers+=1 if numbers==n: lists_small.append(numbers) break else: continue else: lists_small.append(numbers) break for z in lists2: numbers=0 for w in lists3: if w>z: numbers+=1 if numbers==n: lists_big.append(numbers) break else: continue else: lists_big.append(numbers) break ans=0 for _ in range(n): ans+=lists_small[_]*lists_big[_] print(ans)
n=int(eval(input())) lists1=sorted(list(map(int,input().split())))+[10**9+1] lists2=sorted(list(map(int,input().split())))+[10**9+2] lists3=sorted(list(map(int,input().split())))+[10**9+3] lists_small=[0]*(n+1) lists_big=[0]*(n+1) numbers=0 for x in range(n): while lists1[numbers]<lists2[x]: numbers+=1 lists_small[x]=numbers numberss=0 for y in range(n): while lists3[numberss]<=lists2[y]: numberss+=1 changes=n-numberss lists_big[y]=changes ans=0 for xy in range(n): ans+=lists_big[xy]*lists_small[xy] print(ans)
p03557
def lma():return list(map(int, input().split()))#x or y a = int(eval(input())) k=[] s=[] co=[0]*a*3 c=0 s= [lma()] x2= lma() x3 = lma() s.append(x2) s.append(x3) res =0 for j in range(3): for i in range(a): k.append([j,s[j][i]]) k.sort(key=lambda x: x[1], reverse=True) for i in range(a*3): if k[i][0] == 2: c+=1 elif k[i][0] == 1: co[i] = c else: res+=sum(co[:i]) print(res)
def lma():return list(map(int, input().split()))#x or y a = int(eval(input())) k=[] s=[] c=0 s= [lma()] x2= lma() x3 = lma() s.append(x2) s.append(x3) res =0 r =0 for j in range(3): for i in range(a): k.append([j,s[j][i]]) k.sort(key=lambda x: x[1], reverse=True) for i in range(a*3): if k[i][0] == 2: c+=1 elif k[i][0] == 1: r+=c else: #res+=sum(co[:i]) res+=r print(res)
p03557
import sys from heapq import heapify,heappop,heappush from collections import defaultdict read=sys.stdin.read readline=sys.stdin.readline def main(): n=int(readline()) a,b,c=(list(map(int,lst.split())) for lst in read().splitlines()) a.sort() b.sort() c=[-x for x in c] c.sort() def bise(x,lst): left=0 right=len(lst) while right-left>0: mid=(right+left)//2 if lst[mid]>=x: right=mid else: left=mid+1 return left print((sum(bise(x,a)*bise(-x,c) for x in b))) if __name__=='__main__': main()
import sys from bisect import bisect_right,bisect_left read=sys.stdin.read readline=sys.stdin.readline def main(): n=int(readline()) a,b,c=(list(map(int,lst.split())) for lst in read().splitlines()) a.sort() b.sort() c=[-x for x in c] c.sort() print((sum(bisect_left(a,x)*bisect_left(c,-x) for x in b))) if __name__=='__main__': main()
p03557
N = int(input()) As = input().split(" ") Bs = input().split(" ") Cs = input().split(" ") As = [(int(i), 2) for i in As] Bs = [(int(i), 1) for i in Bs] Cs = [(int(i), 0) for i in Cs] l = sorted(As + Bs + Cs, key=lambda x: x[0] + x[1] * 0.1) ac = 0 bc = 0 cc = 0 for i in l: if i[1] == 2: ac += 1 elif i[1] == 1: bc += ac elif i[1] == 0: cc += bc print(cc)
N = int(input()) As = [(int(i), 2) for i in input().split(" ")] Bs = [(int(i), 1) for i in input().split(" ")] Cs = [(int(i), 0) for i in input().split(" ")] l = sorted(As + Bs + Cs, key=lambda x: x[0] + x[1] * 0.1) ac = 0 bc = 0 cc = 0 for i in l: if i[1] == 2: ac += 1 elif i[1] == 1: bc += ac elif i[1] == 0: cc += bc print(cc)
p03557
N = int(input()) As = [(int(i), 2) for i in input().split(" ")] Bs = [(int(i), 1) for i in input().split(" ")] Cs = [(int(i), 0) for i in input().split(" ")] l = sorted(As + Bs + Cs, key=lambda x: x[0] + x[1] * 0.1) ac = 0 bc = 0 cc = 0 for i in l: if i[1] == 2: ac += 1 elif i[1] == 1: bc += ac elif i[1] == 0: cc += bc print(cc)
N = int(input()) As = [(int(i), 2) for i in input().split(" ")] Bs = [(int(i), 1) for i in input().split(" ")] Cs = [(int(i), 0) for i in input().split(" ")] l = sorted(As + Bs + Cs) ac = 0 bc = 0 cc = 0 for i in l: if i[1] == 2: ac += 1 elif i[1] == 1: bc += ac elif i[1] == 0: cc += bc print(cc)
p03557
import bisect n = int(eval(input())) a = sorted(list(map(int,input().split()))) b = sorted(list(map(int,input().split()))) c = sorted(list(map(int,input().split()))) d = [-1] * n ansum = 0 def stat(array,par): return bisect.bisect(array,par) for i in range(n): indexC = stat(c,b[i]) d[i] = max(0,n-indexC) for i in range(n-1): d[n-i-2] += d[n-i-1] for A in a: index = stat(b,A) if index < n: ansum += d[index] print(ansum)
import bisect n = int(eval(input())) a = sorted(list(map(int,input().split()))) b = sorted(list(map(int,input().split()))) c = sorted(list(map(int,input().split()))) ansum = 0 for B in b: index = bisect.bisect_left(a,B) index2= bisect.bisect_right(c,B) ansum += index*(n-index2) print(ansum)
p03557
import bisect n = int(eval(input())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) count = 0 a1 = sorted(a) b1 = sorted(b) c1 = sorted(c) for i in c1: prior_c = bisect.bisect_left(b1,i) prior_c_list = b1[:prior_c] for j in prior_c_list: count += bisect.bisect_left(a1,j) print(count)
import bisect n = int(eval(input())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) a1 = sorted(a) c1 = sorted(c) count = 0 for i in b: count += bisect.bisect_left(a1,i) * (n - bisect.bisect_right(c1,i)) print(count)
p03557
N = int(eval(input())) A = sorted(list(map(int,input().split()))) B = sorted(list(map(int,input().split()))) C = sorted(list(map(int,input().split()))) ans = 0 import bisect for i in A: a = bisect.bisect_right(B,i) for j in range(a,N): b = bisect.bisect_right(C,B[j]) ans += N-b print(ans)
N = int(eval(input())) A = sorted(list(map(int,input().split()))) B = sorted(list(map(int,input().split()))) C = sorted(list(map(int,input().split()))) ans = 0 import bisect b = [] for i in B: x = bisect.bisect_right(C,i) b.append(N-x) y = sum(b) c = [y] for i in range(1,N): y -= b[i-1] c.append(y) c.append(0) for i in A: a = bisect.bisect_right(B,i) ans += c[a] print(ans)
p03557
import bisect from sys import stdin N = int(eval(input())) lines = stdin.readlines l = [[int(i) for i in line.split()] for line in lines()] An = l[0] Bn = l[1] Cn = l[2] def main(): An.sort() Cn.sort() ans = 0 for Bi in Bn: # 以上 lx = bisect.bisect_left(An, Bi) # より大きい ux = bisect.bisect(Cn, Bi) ans += lx * (N - ux) print(ans) return main()
import bisect N = int(eval(input())) An = list(map(int, input().split())) Bn = list(map(int, input().split())) Cn = list(map(int, input().split())) def main(): A = sorted(An) C = sorted(Cn) ans = 0 for Bi in Bn: # 以上 lx = bisect.bisect_left(A, Bi) # より大きい ux = bisect.bisect(C, Bi) ans += lx * (N - ux) print(ans) return main()
p03557
def main(): from bisect import bisect_left from bisect import bisect_right N = int(eval(input())) An = list(map(int, input().split())) Bn = list(map(int, input().split())) Cn = list(map(int, input().split())) A = sorted(An) C = sorted(Cn) print((sum(bisect_left(A, Bi) * (N - bisect_right(C, Bi)) for Bi in Bn))) return main()
def main(): from bisect import bisect_left from bisect import bisect_right N = int(eval(input())) An = list(map(int, input().split())) Bn = list(map(int, input().split())) Cn = list(map(int, input().split())) A = sorted(An) B = sorted(Bn) C = sorted(Cn) print((sum([bisect_left(A, Bi) * (N - bisect_right(C, Bi)) for Bi in B]))) return main()
p03557
def main(): from bisect import bisect_left from bisect import bisect_right N = int(eval(input())) A = sorted(map(int, input().split())) B = sorted(map(int, input().split())) C = sorted(map(int, input().split())) print((sum([bisect_left(A, Bi) * (N - bisect_right(C, Bi)) for Bi in B]))) return main()
def main(): from bisect import bisect_left from bisect import bisect_right N = int(eval(input())) An = list(map(int, input().split())) Bn = list(map(int, input().split())) Cn = list(map(int, input().split())) A = sorted(An) B = sorted(Bn) C = sorted(Cn) print((sum([bisect_left(A, Bi) * (N - bisect_right(C, Bi)) for Bi in B]))) return main()
p03557
def main(): N = int(eval(input())) A = sorted(map(int, input().split())) B = sorted(map(int, input().split())) C = sorted(map(int, input().split())) def lowerBound(a, v): # 以上 return lb(a, 0, len(a), v) def upperBound(a, v): # より大きい # 値をプラス1 return lb(a, 0, len(a), v + 1) def lb(a, l, r, v): low = l - 1 high = r while high - low > 1: mid = low + high >> 1 if a[mid] >= v: high = mid else: low = mid return high print((sum([lowerBound(A, Bi) * (N - upperBound(C, Bi)) for Bi in B]))) return main()
def main(): from bisect import bisect_left from bisect import bisect_right N = int(eval(input())) An = sorted(map(int, input().split())) Bn = sorted(map(int, input().split())) Cn = sorted(map(int, input().split())) ans = 0 lx = 0 ux = 0 for Bi in Bn: # 以上 lx = bisect_left(An, Bi, lx, N) # より大きい ux = bisect_right(Cn, Bi, ux, N) ans += lx * (N - ux) print(ans) return main()
p03557
def main(): from bisect import bisect_left from bisect import bisect_right N = int(eval(input())) An = sorted(map(int, input().split())) Bn = sorted(map(int, input().split())) Cn = sorted(map(int, input().split())) ans = 0 lx = 0 ux = 0 for Bi in Bn: # 以上 lx = bisect_left(An, Bi, lx, N) # より大きい ux = bisect_right(Cn, Bi, ux, N) ans += lx * (N - ux) print(ans) return main()
N = int(eval(input())) An = sorted(map(int, input().split())) Bn = sorted(map(int, input().split())) Cn = sorted(map(int, input().split())) def f(xn, yn, zn): tn = [0] * N num = 0 j = N - 1 for i in range(N - 1, -1, - 1): while 0 <= j and xn[i] < yn[j]: num += zn[j] j -= 1 tn[i] = num return tn def main(): Zn = [1] * N Zn = f(Bn, Cn, Zn) Zn = f(An, Bn, Zn) print((sum(Zn))) return main()
p03557
import itertools import math from collections import deque from collections import defaultdict from itertools import permutations import heapq import bisect INF = float("inf") N = int(eval(input())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A.sort() B.sort() C.sort() ans = 0 for i in range(N): r1 = bisect.bisect_right(B,A[i]) for j in range(r1,N): r2 = bisect.bisect_right(C,B[j]) ans += N - r2 print(ans)
import itertools import math from collections import deque from collections import defaultdict from itertools import permutations import heapq import bisect INF = float("inf") N = int(eval(input())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A.sort() B.sort() C.sort() ans = 0 for i in range(N): l = bisect.bisect_left(A,B[i]) r = bisect.bisect_right(C,B[i]) ans += l*(N-r) print(ans)
p03557
from bisect import bisect_left from bisect import bisect_right N = int(eval(input())) A = sorted(map(int, input().split())) B = list(map(int, input().split())) C = sorted(map(int, input().split())) r = 0 for i in range(N): ai = bisect_left(A, B[i]) ci = bisect_right(C, B[i]) r += len(A[:ai]) * len(C[ci:]) print(r)
from bisect import bisect_left from bisect import bisect_right N = int(eval(input())) A = sorted(map(int, input().split())) B = list(map(int, input().split())) C = sorted(map(int, input().split())) r = 0 for i in range(N): ai = bisect_left(A, B[i]) ci = bisect_right(C, B[i]) r += ai * (N - ci) print(r)
p03557
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) bidx = 0 cidx = 0 abnums = [0] * (N+1) bcnums = [0] * (N+1) idx = 0 for i, a in enumerate(A): abnums[i+1] = abnums[i] if abnums[i+1] == N: continue for j, b in enumerate(B[idx:]): if a < b: abnums[i+1] += 1 else: idx = j + idx break idx = 0 for i, b in enumerate(B): bcnums[i+1] = bcnums[i] if bcnums[i+1] == N: continue for j, c in enumerate(C[idx:]): if b < c: bcnums[i+1] += 1 else: idx = j + idx break for i in range(1, N+1): bcnums[i] += bcnums[i-1] ans = 0 for n in abnums[1:]: ans += bcnums[n] print(ans)
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() idxa = 0 idxc = 0 ans = 0 for b in range(N): while idxa < N and A[idxa] < B[b]: idxa += 1 while idxc < N and B[b] >= C[idxc]: idxc += 1 ans += idxa * (N - idxc) print(ans)
p03557
n=int(eval(input())) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) a=sorted(a) b=sorted(b) c=sorted(c) c.insert(0,-1) c.append(10**10) B=[0]*n ans=0 for i in range(n): x=b[i] l=0 r=n+1 while r-l>1: m=(l+r)//2 if c[m]>x: r=m elif c[m]<=x: l=m B[i]=n-l g=[0]*n g[n-1]=B[n-1] for i in range(n-1): g[-2-i]=g[-1-i]+B[-2-i] g.append(0) b.insert(0,-1) b.append(10**10) for i in range(n): x=a[i] l=0 r=n+1 while r-l>1: m=(l+r)//2 if b[m]>x: r=m elif b[m]<=x: l=m ans+=g[l] print(ans)
n=int(eval(input())) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) a=sorted(a) b=sorted(b) c=sorted(c) c.insert(0,-1) c.append(10**10) a.insert(0,-1) a.append(10**10) ans=0 for i in range(n): x=b[i] l=0 r=n+1 while r-l>1: m=(l+r)//2 if a[m]<x: l=m else: r=m L=0 R=n+1 while R-L>1: M=(L+R)//2 if c[M]<=x: L=M else: R=M ans+=l*(n+1-R) print(ans)
p03557
from collections import deque n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) q = deque() for i in a: q.append([i]) ans = 0 while q: now = q.popleft() n = len(now) if n == 3: ans += 1 elif n == 2: for x in c: if now[-1] < x: q.append(now + [x]) elif n == 1: for y in b: if now[-1] < y: q.append(now + [y]) print(ans)
import bisect n = int(eval(input())) a = sorted(list(map(int, input().split()))) b = list(map(int, input().split())) c = sorted(list(map(int, input().split()))) ans = 0 for i in b: a_pos = bisect.bisect_left(a, i) c_pos = n - bisect.bisect_right(c, i) ans += a_pos * c_pos print(ans)
p03557
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() ans = 0 for b in B: l = -1 r = N while r - l > 1: m = (r + l) // 2 if A[m] < b: l = m else: r = m a_cnt = l + 1 if l != -1 else 0 l = -1 r = N while r - l > 1: m = (r + l) // 2 if C[m] > b: r = m else: l = m c_cnt = N - r ans += a_cnt * c_cnt print(ans)
import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) def count_a(A, X): l = -1 r = N while r - l > 1: m = (r + l) // 2 if A[m] < b: l = m else: r = m return l + 1 def count_c(C, X): l = -1 r = N while r - l > 1: m = (r + l) // 2 if C[m] > b: r = m else: l = m return N - r A.sort() B.sort() C.sort() ans = 0 A_min = A[0] C_max = C[-1] for b in B: if b <= A_min or b >= C_max: continue a_cnt = count_a(A, b) if a_cnt == 0: continue c_cnt = count_c(C, b) ans += a_cnt * c_cnt print(ans)
p03557
from bisect import bisect_left, bisect N = int(eval(input())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A = sorted(A,reverse = False) C = sorted(C,reverse = False) cnt = 0 for i in B: #print( A[:bisect_left(A,i)],C[bisect(C,i):]) cnt += len(A[:bisect_left(A,i)]) *len(C[bisect(C,i):]) print(cnt)
from bisect import bisect_left, bisect n=int(eval(input())) la=sorted(list(map(int,input().split()))) lb=list(map(int,input().split())) lc=sorted(list(map(int,input().split()))) ans=0 for i in lb: ans+=bisect_left(la,i)*(len(lc)-bisect(lc,i)) #iの挿入点つまりiより小さい値の数×(Cの総数- print(ans)
p03557
N = int(eval(input())) A = sorted(list(map(int,input().split()))) B = sorted(list(map(int,input().split()))) C = sorted(list(map(int,input().split()))) from bisect import bisect_left, bisect ans = 0 for i in range(N): b = B[i] a = bisect_left(A,b) c = bisect(C,b) #print(b,A[:a],C[c:]) ans += len(A[:a])*len(C[c:]) print(ans)
N = int(eval(input())) A = sorted(list(map(int,input().split()))) B = sorted(list(map(int,input().split()))) C = sorted(list(map(int,input().split()))) from bisect import bisect_left, bisect ans = 0 for i in range(N): b = B[i] a = bisect_left(A,b) c = bisect(C,b) #print(b,a,c) #print(b,A[:a],C[c:]) ans += a*(N-c) print(ans)
p03557
# coding: utf-8 n = int(eval(input())) al = sorted(list(int(i) for i in input().split())) bl = sorted(list(int(i) for i in input().split())) cl = sorted(list(int(i) for i in input().split())) ans = 0 def low_left(a, key): left = -1 right = len(a) while right - left > 1: center = (left + right) // 2 if a[center] >= key: right = center else: left = center return left+1 def high_right(a, key): left = -1 right = len(a) while right - left > 1: center = (left + right) // 2 if a[center] <= key: left = center else: right = center return n-right for i in bl: ans += low_left(al, i) * high_right(cl, i) print(ans)
import bisect n = int(eval(input())) al, bl, cl = list(sorted(map(int, input().split())) for i in range(3)) ans = 0 for key in bl: top = bisect.bisect_left(al, key) btm = len(cl) - bisect.bisect_right(cl, key) ans += top * btm print(ans)
p03557
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a = sorted(a) b = sorted(b) c = sorted(c) num_b = [0 for _ in range(n)] j = 0 for i in range(n): if j == n: num_b[i] = n continue while a[j] < b[i]: j += 1 if j == n: break num_b[i] = j ans = 0 j = 0 for i in range(n): while b[j] < c[i]: j += 1 if j == n: ans += (n - i) * sum(num_b) break if j == n: break ans += sum(num_b[:j]) print(ans)
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a = sorted(a) b = sorted(b) c = sorted(c) num_b = [0 for _ in range(n)] j = 0 for i in range(n): if j == n: num_b[i] = n continue while a[j] < b[i]: j += 1 if j == n: break num_b[i] = j ans = 0 j = 0 temp_sum = 0 for i in range(n): while b[j] < c[i]: temp_sum += num_b[j] j += 1 if j == n: ans += (n - i) * sum(num_b) break if j == n: break ans += temp_sum print(ans)
p03557
N=int(eval(input())) arr=[list(map(int,input().split())) for i in range(3)] count=0 for i in range(N): for j in range(N): if arr[0][i]<arr[1][j]: for k in range(N): if arr[1][j]<arr[2][k]: count+=1 print(count)
N=int(eval(input())) A,B,C=[list(sorted(map(int,input().split()))) for i in range(3)] count=0 def bs_l(lis,x): low,high=0,len(lis) while low<high: mid=(low+high)//2 if lis[mid]<x: low=mid+1 else: high=mid return low def bs_r(lis,x): low,high=0,len(lis) while low<high: mid=(low+high)//2 if lis[mid]>x: high=mid else: low=mid+1 return low for i in B: count+=bs_l(A,i)*(N-bs_r(C,i)) print(count)
p03557
import bisect N = int(eval(input())) A = sorted(map(int, input().split())) B = list(map(int, input().split())) C = sorted(map(int, input().split())) print((sum(len(A[:bisect.bisect_left(A, b)]) * len(C[bisect.bisect(C, b):]) for b in B)))
import bisect N = int(eval(input())) A = sorted(map(int, input().split())) B = list(map(int, input().split())) C = sorted(map(int, input().split())) print((sum(bisect.bisect_left(A, b) * (N - bisect.bisect(C, b)) for b in B)))
p03557
import bisect N = int(eval(input())) A = sorted(map(int, input().split())) B = list(map(int, input().split())) C = sorted(map(int, input().split())) ans = 0 for j in range(len(B)): axb = bisect.bisect_left(A, B[j]) bxc = len(C) - len(C[:bisect.bisect(C, B[j])]) ans += axb * bxc print(ans)
import bisect N = int(eval(input())) A = sorted(map(int, input().split())) B = list(map(int, input().split())) C = sorted(map(int, input().split())) print((sum(bisect.bisect_left(A, B[j]) * (N - bisect.bisect(C, B[j])) for j in range(N))))
p03557
# -*- coding: utf-8 -*- """ Created on Sat Oct 20 10:21:00 2018 ABC077C @author: maezawa """ import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() cnt = 0 for ci in c: j = bisect.bisect_left(b, ci) for bi in b[:j]: k = bisect.bisect_left(a, bi) #print(ci, bi, k, cnt) cnt += k print(cnt)
# -*- coding: utf-8 -*- """ Created on Sat Oct 20 10:21:00 2018 ABC077C @author: maezawa """ import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() bcnt = [0]*n for i, bi in enumerate(b): j = bisect.bisect_left(a, bi) if i == 0: bcnt[i] = j else: bcnt[i] = bcnt[i-1] + j cnt = 0 for i, ci in enumerate(c): j = bisect.bisect_left(b, ci) if j == 0: continue else: cnt += bcnt[j-1] #print(ci, j, bcnt[j-1], cnt) print(cnt)
p03557
N = int(eval(input())) A = [int(i) for i in input().split()] # 1 2 3 4 5 ... B = [int(i) for i in input().split()] # 1 2 3 4 5 ... C = [int(i) for i in input().split()] # 1 2 3 4 5 ... A.sort() B.sort() C.sort() #print(A) #print(B) #print(C) ##exit(0) ab=[0]*N bc=[0]*N b=N-1 c=N-1 count=0 while (0<=b): while (0<=c): if B[b]<C[c]: count += 1 c -= 1 else: break bc[b] = count b -= 1 a=N-1 b=N-1 count=0 while (0<=a): while (0<=b): if A[a]<B[b]: count += 1 b -= 1 else: break ab[a] = count a -= 1 #print(ab) #print(bc) ans=0 for i in ab: # print(i, bc[N-i:N]) ans += sum(bc[N-i:N]) print(ans)
N = int(eval(input())) A = [int(i) for i in input().split()] # 1 2 3 4 5 ... B = [int(i) for i in input().split()] # 1 2 3 4 5 ... C = [int(i) for i in input().split()] # 1 2 3 4 5 ... A.sort() B.sort() C.sort() #print(A) #print(B) #print(C) ##exit(0) ab=[0]*N bc=[0]*N b=N-1 c=N-1 count=0 while (0<=b): while (0<=c): if B[b]<C[c]: count += 1 c -= 1 else: break bc[b] = count if b<N-1: bc[b] += bc[b+1] b -= 1 a=N-1 b=N-1 count=0 while (0<=a): while (0<=b): if A[a]<B[b]: count += 1 b -= 1 else: break ab[a] = count a -= 1 #print(ab) #print(bc) ans=0 for i in ab: # print(i, bc[N-i:N]) # ans += sum(bc[N-i:N]) if i>0: ans += bc[N-i] print(ans)
p03557
import bisect n=int(eval(input())) a=[int(i) for i in input().split(" ")] b=[int(i) for i in input().split(" ")] c=[int(i) for i in input().split(" ")] b.sort() c.sort() lc=len(c) print((sum([sum([lc-bisect.bisect_right(c,j) for j in b[bisect.bisect_right(b,i):]]) for i in a]) ))
import bisect n=int(eval(input())) a=[int(i) for i in input().split(" ")] b=[int(i) for i in input().split(" ")] c=[int(i) for i in input().split(" ")] a.sort() c.sort() lc=len(c) print((sum([(lc-bisect.bisect_right(c,j))*(bisect.bisect_left(a,j)) for j in b])))
p03557
N = int(input().rstrip()) A = list(map(int, input().rstrip().split())) B = list(map(int, input().rstrip().split())) C = list(map(int, input().rstrip().split())) A.sort() B.sort() C.sort() def bin_search(vlist, targ): lb = -1 ub = len(vlist) while ub - lb > 1: mid = (lb + ub) // 2 if vlist[mid] >= targ: ub = mid else: lb = mid return ub total = 0 for c in C: b_ub = bin_search(B, c) for _b in B[:b_ub]: a_ub = bin_search(A, _b) total += len(A[:a_ub]) print(total)
N = int(input().rstrip()) A = list(map(int, input().rstrip().split())) B = list(map(int, input().rstrip().split())) C = list(map(int, input().rstrip().split())) A.sort() C.sort() def bin_search_withR(vlist, targ): lb = -1 ub = len(vlist) while ub - lb > 1: mid = (lb + ub) // 2 if vlist[mid] >= targ: ub = mid else: lb = mid return ub, lb def bin_search_withL(vlist, targ): lb = -1 ub = len(vlist) while ub - lb > 1: mid = (lb + ub) // 2 if vlist[mid] > targ: ub = mid else: lb = mid return ub, lb total = 0 for b in B: a_ub, a_lb = bin_search_withR(A, b) c_ub, c_lb = bin_search_withL(C, b) total += a_ub * (N - c_ub) print(total)
p03557
# ABC077C import bisect N=int(eval(input())) A=sorted(list(map(int,input().split()))) B=sorted(list(map(int,input().split()))) C=sorted(list(map(int,input().split()))) bC=[0 for i in range(N)] for i in range(N): bC[i]=N-bisect.bisect(C,B[i]) ans=0 for i in range(N): x=bisect.bisect(B,A[i]) for j in range(x,N): ans+=bC[j] print(ans)
# ABC077C import bisect N=int(eval(input())) A=sorted(list(map(int,input().split()))) B=sorted(list(map(int,input().split()))) C=sorted(list(map(int,input().split()))) bC=[0 for i in range(N)] for i in range(N): bC[i]=N-bisect.bisect(C,B[i]) bCS=[0]*(N+1) for i in range(N): bCS[i+1] = bCS[i]+bC[i] ans=0 for i in range(N): x=bisect.bisect(B,A[i]) ans+=bCS[N]-bCS[x] print(ans)
p03557
#二分探索 from bisect import bisect_left #input N = int(eval(input())) #print(N) A = sorted(list(map(int, input().split()))) #この表記について... B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) #print(A,B,C) #sort 昇順に並び替え #A.sort() #B.sort() #C.sort() Bis_B = [] for i in range(N): Bis_B.append(bisect_left(A,B[i])) #print(Bis_B) ans = 0 for i in range(N): M = bisect_left(B, C[i]) if M == 0: #この文で余分な動作を少し減らせる continue ans += sum(Bis_B[:M]) #この探索を複数回やってしまっている? print(ans)
from bisect import bisect_left from bisect import bisect_right #input N = int(eval(input())) #print(N) A = sorted(list(map(int, input().split()))) #この表記について... B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) #print(A,B,C) #sort 昇順に並び替え #A.sort() #B.sort() #C.sort() ans = 0 for i in range(N): ab = bisect_left(A,B[i]) bc = N-bisect_right(C,B[i]) #print(ab, end=' ') #print(bc) ans += ab*bc print(ans)
p03557
import bisect N = int(eval(input())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A.sort() B.sort() C.sort() #print(A) #print(B) #print(C) ans = 0 for b in B: a = bisect.bisect_right(A, b-1) c = N - bisect.bisect_right(C, b) #print("smaller",a,"bigger",c) ans += a*c print(ans)
import bisect n = int(eval(input())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A.sort() C.sort() ans = 0 for b in B: a = bisect.bisect_right(A, b-1) c = len(C)-bisect.bisect_right(C, b) ans += a*c print(ans)
p03557
import bisect n = int(eval(input())) al = [int(a) for a in input().split()] bl = [int(b) for b in input().split()] cl = [int(c) for c in input().split()] al.sort() bl.sort() cl.sort() k = 0 for a in al: for b in bl[bisect.bisect_right(bl, a):]: k += n - bisect.bisect_right(cl, b) print(k)
import bisect n = int(eval(input())) al = [int(a) for a in input().split()] bl = [int(b) for b in input().split()] cl = [int(c) for c in input().split()] al.sort() bl.sort() cl.sort() k = 0 for b in bl: k += bisect.bisect_left(al, b) * (n - bisect.bisect_right(cl, b)) print(k)
p03557
n = int(input()) ais = list(map(int, input().split())) bis = list(map(int, input().split())) cis = list(map(int, input().split())) count = 0 ais.sort() bis.sort() cis.sort() for a in ais: i,j = 0,0 while(i < len(bis) and not(bis[i] > a)): i+=1 while(i < len(bis)): while(j < len(cis) and not(cis[j] > bis[i])): j +=1 if j < len(cis): count += ( n - j) i+=1 print(count)
n = int(input()) ais = list(map(int, input().split())) bis = list(map(int, input().split())) cis = list(map(int, input().split())) count = 0 ais.sort() bis.sort() cis.sort() i,j = 0,0 for b in bis: while(i < len(ais) and ais[i] < b): i += 1 while(j < len(cis) and cis[j] <= b): j += 1 count += i * (n - j) print(count)
p03557
N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) from bisect import bisect_left mids = [] for b in B: ind = bisect_left(A, b) mids.append(ind) cs = [0] for i in range(N): cs.append(cs[i]+mids[i]) ans = 0 for c in C: ind = bisect_left(B, c) ans += cs[ind] print(ans)
N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) from bisect import bisect_left, bisect_right ans = 0 for b in B: ai = bisect_left(A, b) ci = bisect_right(C, b) ans += ai * (N-ci) print(ans)
p03557
import bisect N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) count = 0 # ソートして for c in C: under_c = bisect.bisect_left(B, c) for b in B[:under_c]: under_b = bisect.bisect_left(A, b) count += under_b print(count)
import bisect N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) count = 0 # ソートして for b in B: upeer_b = N - bisect.bisect_right(C, b) downer_b = bisect.bisect_left(A, b) count += upeer_b * downer_b # for c in C: # under_c = bisect.bisect_left(B, c) # for b in B[:under_c]: # under_b = bisect.bisect_left(A, b) # count += under_b print(count)
p03557
# coding: utf-8 import math N = int(eval(input())) a_list = [int(x) for x in input().split()] b_list = [int(x) for x in input().split()] c_list = [int(x) for x in input().split()] a_list.sort() b_list.sort() c_list.sort() a_lt_b_index = [N] * N i = j = 0 while (i < N and j < N): if (a_list[i] < b_list[j]): a_lt_b_index[i] = j i += 1 else: j += 1 b_lt_c_count = [0] * (N+1) i = j = 0 while (i < N and j < N): if (b_list[i] < c_list[j]): b_lt_c_count[i] = N-j i += 1 else: j += 1 sum_of_b_lt_c = [sum(b_lt_c_count[i:]) for i in range(N+1)] print((sum([sum_of_b_lt_c[a_lt_b_index[i]] for i in range(N)])))
N = int(eval(input())) A_list = [int(a) for a in input().split()] B_list = [int(b) for b in input().split()] C_list = [int(c) for c in input().split()] A_list.sort() B_list.sort() C_list.sort() i = j = N-1 count_B_gt_A = [0] * N while i >= 0 and j >= 0: if B_list[i] > A_list[j]: count_B_gt_A[i] = j+1 i -= 1 else: j -= 1 i = j = 0 count_B_lt_C = [0] * N while i < N and j < N: if B_list[i] < C_list[j]: count_B_lt_C[i] = N - j i += 1 else: j += 1 result = sum([B_gt_A * B_lt_C for B_gt_A, B_lt_C in zip(count_B_gt_A, count_B_lt_C)]) print(result)
p03557
import bisect N = int(eval(input())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) a = sorted(a) b = sorted(b) c = sorted(c) z = [0] * N ans = 0 for i in range(N): e = b[i] cin = insert_index = bisect.bisect_right(c,e) z[i] = N-cin for i in range(N): d = a[i] bind = insert_index = bisect.bisect_right(b,d) ans += sum(z[bind:]) print(ans)
import bisect N = int(eval(input())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) a = sorted(a) b = sorted(b) c = sorted(c) z = [0] * N ans = 0 for i in range(N-1,-1,-1): e = b[i] cin = bisect.bisect_right(c,e) if i + 1 == N: z[i] = N-cin else: z[i] = z[i+1] + N-cin for i in range(N): d = a[i] bind = bisect.bisect_right(b,d) if bind == N: continue ans += z[bind] print(ans)
p03557
import bisect N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) ans = 0 for mid in B: n_bottom = len(C[bisect.bisect_right(C,mid):]) n_top = len(A[:bisect.bisect_left(A,mid)]) ans += n_bottom * n_top print(ans)
import bisect N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) ans = 0 for mid in B: n_bottom = N - bisect.bisect_right(C,mid) n_top = bisect.bisect_left(A,mid) ans += n_bottom * n_top print(ans)
p03557
N = int(eval(input())) A = sorted(list(map(int,input().split()))) B = sorted(list(map(int,input().split()))) C = sorted(list(map(int,input().split()))) cnt = 0 for i in range(N): l, r = 0, 0 for j in range(N): k = i - j if(A[j] < B[i]): l += 1 if(B[i] < C[k]): r += 1 cnt += l*r print(cnt)
N = int(eval(input())) A = sorted(list(map(int,input().split()))) B = sorted(list(map(int,input().split()))) C = sorted(list(map(int,input().split()))) a, c, cnt = 0, 0, 0 for b in B: while a < N and A[a] < b: a += 1 while c < N and C[c] <= b: c += 1 cnt += a * (N - c) print(cnt)
p03557
import math import copy import sys import fractions # import numpy as np # import statistics import decimal import heapq import collections import itertools import bisect # from operator import mul # sys.setrecursionlimit(100001) # input = sys.stdin.readline # sys.setrecursionlimit(10**6) # ===FUNCTION=== def getInputIntList(): outputDataList = [] inputData = input().split() outputDataList = [int(n) for n in inputData] return outputDataList def getSomeInputInt(n): outputDataList = [] for i in range(n): inputData = int(eval(input())) outputDataList.append(inputData) return outputDataList def getSomeInputListInt(n): inputDataList = [] outputDataList = [] for i in range(n): inputData = input().split() inputDataList = [int(n) for n in inputData] outputDataList.append(inputDataList) return outputDataList # ===CODE=== n = int(eval(input())) a = getInputIntList() b = getInputIntList() c = getInputIntList() a.sort() b.sort() c.sort() ans = 0 for i in range(n): x = bisect.bisect_left(b, c[i]) for j in range(x-1, -1, -1): y = bisect.bisect_left(a, b[j]) ans += y print(ans)
import math import copy import sys import fractions # import numpy as np # import statistics import decimal import heapq import collections import itertools import bisect # from operator import mul # sys.setrecursionlimit(100001) # input = sys.stdin.readline # sys.setrecursionlimit(10**6) # ===FUNCTION=== def getInputIntList(): outputDataList = [] inputData = input().split() outputDataList = [int(n) for n in inputData] return outputDataList def getSomeInputInt(n): outputDataList = [] for i in range(n): inputData = int(eval(input())) outputDataList.append(inputData) return outputDataList def getSomeInputListInt(n): inputDataList = [] outputDataList = [] for i in range(n): inputData = input().split() inputDataList = [int(n) for n in inputData] outputDataList.append(inputDataList) return outputDataList # ===CODE=== n = int(eval(input())) a = getInputIntList() b = getInputIntList() c = getInputIntList() a.sort() b.sort() c.sort() ans = 0 for tmp in b: top = bisect.bisect_left(a, tmp) bottom = bisect.bisect_right(c, tmp) ans += top * (n-bottom) print(ans)
p03557
import bisect N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() ans = 0 for b in B: a_index = bisect.bisect_left(A, b) c_index = bisect.bisect_right(C, b) ans += len(A[:a_index])*len(C[c_index:]) print(ans)
import bisect N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) ans = 0 for b in B: a_index = bisect.bisect_left(A, b) c_index = bisect.bisect_right(C, b) ans += a_index*(N-c_index) print(ans)
p03557
# TODO: unknown n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() a.append(10 ** 9 + 1) b.append(10 ** 9 + 2) c.append(10 ** 9 + 3) ab = [0] * (n + 1) j = 0 for i in range(n + 1): while b[j] <= a[i]: j += 1 ab[i] = j k = 0 bc = [0] * (n + 1) for j in range(n + 1): while c[k] <= b[j]: k += 1 bc[j] = k bc_acc = [0] * (n + 1) bc_acc[n] = 0 for j in range(n-1, -1, -1): bc_acc[j] = bc_acc[j+1] + n - bc[j] ans = 0 for i in range(n): ans += bc_acc[ab[i]] print(ans)
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() import bisect ans = 0 for j in range(n): i = bisect.bisect_left(a, b[j]) k = bisect.bisect_right(c, b[j]) ans += i * (n - k) print(ans)
p03557
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() import bisect ans = 0 for j in range(n): i = bisect.bisect_left(a, b[j]) k = bisect.bisect_right(c, b[j]) ans += i * (n - k) print(ans)
from bisect import bisect_left from itertools import accumulate n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() ba_cnt = [bisect_left(a, e) for e in b] ba_acm = [0] + list(accumulate(ba_cnt)) ans = 0 for e in c: i = bisect_left(b, e) ans += ba_acm[i] print(ans)
p03557
from bisect import bisect_left as bl,bisect_right as br n=int(eval(input())) a,b,c=[sorted(list(map(int,input().split()))) for i in range(3)] ans=0 for v in b: if v<=a[0] or v>=c[-1]:continue ans+=bl(a,v)*(n-br(c,v)) print(ans)
from bisect import bisect_left as bl,bisect_right as br n=int(eval(input())) a,b,c=[sorted(list(map(int,input().split()))) for i in range(3)] print((sum(bl(a,v)*(n-br(c,v))for v in b)))
p03557
from bisect import bisect_left n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() cnt = 0 for i in range(n): num_c = c[i] b_idx = bisect_left(b,num_c) for j in range(b_idx): num_b = b[j] a_idx = bisect_left(a, num_b) cnt += a_idx print(cnt)
from bisect import bisect_left, bisect_right n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() len_c = len(c) total = 0 for num in b: idx_a = bisect_left(a, num) idx_c = bisect_right(c, num) cnt = idx_a * (len_c - idx_c) total += cnt print(total)
p03557
# https://atcoder.jp/contests/abc077/tasks/arc084_a # C - Snuke Festival N = int(input().split()[0]) a_list = sorted(list(map(int, input().split()))) b_list = sorted(list(map(int, input().split()))) c_list = sorted(list(map(int, input().split()))) comb_n = 0 for i in range(N): # 10 ** 5 b = b_list[i] c_n = len([c for c in c_list if c > b]) # 10 ** 5 a_n = len([a for a in a_list if a < b]) # 10 ** 5 comb_n += a_n * c_n ans = comb_n print(ans)
# https://atcoder.jp/contests/abc077/tasks/arc084_a # C - Snuke Festival import bisect N = int(input().split()[0]) a_list = sorted(list(map(int, input().split()))) b_list = sorted(list(map(int, input().split()))) c_list = sorted(list(map(int, input().split()))) comb_n = 0 comb_n_list = [] # 自分より大きい個数 start_c_index = 0 start_a_index = 0 for i in range(N): # 10 ** 5 b = b_list[i] a_n = bisect.bisect_left(a_list, b) c_n = N - bisect.bisect_right(c_list, b) comb_n += a_n * c_n ans = comb_n print(ans)
p03557
from bisect import bisect_right n = int(eval(input())) a = sorted(map(int, input().split())) b = sorted(map(int, input().split())) c = sorted(map(int, input().split())) cnt = 0 bn = [] for i in range(n): x2 = bisect_right(c, b[i]) bn.append(n-x2) for i in range(n): x1 = bisect_right(b, a[i]) cnt += sum(bn[x1:]) print(cnt)
from bisect import bisect_right from bisect import bisect_left n = int(eval(input())) a = sorted(map(int, input().split())) b = sorted(map(int, input().split())) c = sorted(map(int, input().split())) cnt = 0 bn = [] for i in range(n): x1 = bisect_left(a, b[i]) x2 = bisect_right(c, b[i]) cnt += x1*(n-x2) print(cnt)
p03557
import bisect import sys input = sys.stdin.readline def main(): N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort(reverse=True) # print(A) # print(B) # print(C) ans = 0 last_b = N for c in C: last_b = bisect.bisect_left(B, c, hi=last_b) if last_b==0: break last_a = N for b in reversed(B[:last_b]): last_a = bisect.bisect_left(A, b, hi=last_a) if last_a==0: break ans += last_a # print(b) # print("last_b: "+str(last_b)) # print("last_a: "+str(last_a)) print(ans) if __name__ == '__main__': main()
import bisect import sys input = sys.stdin.readline def main(): N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() C.sort() ans = 0 for b in B: cnt_a = bisect.bisect_left(A, b) cnt_c = N - bisect.bisect_right(C, b) ans += cnt_a * cnt_c # print(str(cnt_a) + "*" + str(cnt_c)) print(ans) if __name__ == '__main__': main()
p03557
def n0():return int(eval(input())) def n1():return [int(x) for x in input().split()] def n2(n):return [int(eval(input())) for _ in range(n)] def n3(n):return [[int(x) for x in input().split()] for _ in range(n)] n=n0() a=n1() b=n1() c=n1() a.sort() b.sort() c.sort() from bisect import bisect_left,bisect_right b2=[] for i in b: b2.append(bisect_left(a,i)) import itertools b3=list(itertools.accumulate(b2)) ans=0 for i in c: t=bisect_left(b,i) if t>0: ans+=b3[t-1] print(ans)
def s0():return eval(input()) def s1():return input().split() def s2(n):return [eval(input()) for x in range(n)] def s3(n):return [[input().split()] for _ in range(n)] def n0():return int(eval(input())) def n1():return [int(x) for x in input().split()] def n2(n):return [int(eval(input())) for _ in range(n)] def n3(n):return [[int(x) for x in input().split()] for _ in range(n)] n=n0() a=n1() b=n1() c=n1() a.sort() b.sort() c.sort() from bisect import bisect_left,bisect_right b2=[] for i in b: b2.append(bisect_left(a,i)) import itertools b3=list(itertools.accumulate(b2)) ans=0 for i in c: t=bisect_left(b,i) if t>0: ans+=b3[t-1] print(ans)
p03557
import bisect N = int(eval(input())) A = sorted(map(int, input().split())) B = sorted(map(int, input().split())) C = sorted(map(int, input().split())) D = len(C) ans = 0 for i in A: for k in B[bisect.bisect_right(B,i):]: ans += D - bisect.bisect_right(C,k) print(ans)
import bisect N = int(eval(input())) A = sorted(map(int, input().split())) B = sorted(map(int, input().split())) C = sorted(map(int, input().split())) ans = 0 for i in B: ans += bisect.bisect_left(A,i)*(N - bisect.bisect_right(C,i)) print(ans)
p03557
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() C.sort() def binary_search(lst, value, high): l = 0 r = N - 1 while l <= r: mid = (l + r) // 2 if lst[mid] < value: l = mid + 1 elif lst[mid] > value: r = mid - 1 else: # lstの中にある場合 if high: # 真に大きい try: while lst[mid] == value: mid += 1 except IndexError: return N return mid else: # 真に小さい try: while lst[mid] == value: mid -= 1 except IndexError: return -1 return mid if high: return l else: return r def main(): ans = 0 # Bの値でループしてそれより小さいA、大きいCの個数を求めて掛け合わせる for middle in B: lower = binary_search(A, middle, False) + 1 # 0-indexedで返るので+1する higher = N - binary_search(C, middle, True) ans += lower * higher print(ans) if __name__ == "__main__": main()
#import generator N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) """ with open('generator.txt', 'r') as f: read = f.read().split('\n') N = int(read[0]) A = list(map(int, read[1].split())) B = list(map(int, read[2].split())) C = list(map(int, read[3].split())) """ A.sort() C.sort() def binary_search(lst, value, high): l = 0 r = N - 1 while l <= r: mid = (l + r) // 2 if lst[mid] < value: l = mid + 1 elif lst[mid] > value: r = mid - 1 else: # lstの中にある場合 if high: # 真に大きい return binary_search(lst, value + 0.5, high) else: # 真に小さい return binary_search(lst, value - 0.5, high) if high: return l else: return r def main(): ans = 0 # Bの値でループしてそれより小さいA、大きいCの個数を求めて掛け合わせる for middle in B: lower = binary_search(A, middle, False) + 1 # 0-indexedで返るので+1する higher = N - binary_search(C, middle, True) ans += lower * higher print(ans) # 愚直解 def main2(): ans = 0 for a in A: for b in B: for c in C: if a < b < c: ans += 1 print(ans) if __name__ == "__main__": main() #main2()
p03557
N = int(eval(input())) A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] C = [int(x) for x in input().split()] A.sort() B.sort() C.sort() ans = 0 for i in B: OK = -1 NG = N while NG - OK > 1: mid = (OK + NG) // 2 if A[mid] < i: OK = mid else: NG = mid countA = OK + 1 OK = N NG = -1 while OK - NG > 1: mid = (OK + NG) // 2 if C[mid] > i: OK = mid else: NG = mid countC = N - NG - 1 ans += countA * countC print(ans)
N = int(eval(input())) A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] C = [int(x) for x in input().split()] A.sort() C.sort() ans = 0 def bisect(array, threshold, equal=False): OK = -1 NG = N while NG - OK > 1: mid = (OK + NG) // 2 if array[mid] < threshold: OK = mid elif equal == True and array[mid] == threshold: OK = mid else: NG = mid return OK + 1 for i in B: ans += bisect(A, i) * (N - bisect(C, i, True)) print(ans)
p03557
n=int(eval(input())) a=list(map(int,input().split())) a.sort() b=list(map(int,input().split())) b.sort() c=list(map(int,input().split())) c.sort() ans=0 import bisect for bb in b: ao=bisect.bisect(a,bb-1) cnta=len(a[:ao]) cs=bisect.bisect(c,bb) cntc=len(c[cs:]) ans+=cnta*cntc print(ans)
n=int(eval(input())) a=list(map(int,input().split())) a.sort() b=list(map(int,input().split())) b.sort() c=list(map(int,input().split())) c.sort() ans=0 import bisect for i in range(n): x=bisect.bisect_left(a,b[i]) y=bisect.bisect_right(c,b[i]) ans+=x*(n-y) print(ans)
p03557
n = int(eval(input())) a = sorted([int(x) for x in input().split()]) b = sorted([int(x) for x in input().split()]) c = sorted([int(x) for x in input().split()]) def func1(list_1, list_2): res = [] cnt = 0 i = 0 for x in list_2: while i <= n-1 and list_1[i] < x: cnt += 1 i += 1 res.append((x, cnt)) return res def func2(list_res, list_3): res = 0 cnt = 0 i = 0 for x in list_3: while i <= n-1 and list_res[i][0] < x: cnt += list_res[i][1] i += 1 res += cnt return res ans = func2(func1(a, b), c) print(ans)
n = int(eval(input())) a = sorted([int(x) for x in input().split()]) b = sorted([int(x) for x in input().split()]) c = sorted([int(x) for x in input().split()]) res = 0 res_b = 0 cnt = 0 i, j = 0, 0 for c_ in c: while i <= n-1 and c_ > b[i]: while j <= n-1 and b[i] > a[j]: cnt += 1 j += 1 res_b += cnt i += 1 res += res_b print(res)
p03557
def main(): from bisect import bisect import sys sys.setrecursionlimit(200000) N = int(eval(input())) A = sorted(list(map(int,input().split()))) B = sorted(list(map(int,input().split()))) C = sorted(list(map(int,input().split()))) ans = 0 for a in A: bIdx = bisect(B,a) if N - bIdx > 0: for j in range(bIdx,N): b = B[j] cIdx = bisect(C,b) if N - cIdx > 0: ans += N-cIdx print(ans) main()
""" 前処理で下記のようなメモを作っておく必要がある。 candidate[j] -> 昇順ソートされたBの中でインデックスj以降のパーツを使えるときに、考えられるB,Cの組み合わせの数。 candidateリストを作成するためにまずは、下記のmemoを用意して、その総和としてcandidateを作成する。 memo[j] -> Bの中のインデックスjのパーツを使った場合に使用可能なCの数。 """ def main(): from bisect import bisect import sys sys.setrecursionlimit(200000) N = int(eval(input())) A = sorted(list(map(int,input().split()))) B = sorted(list(map(int,input().split()))) C = sorted(list(map(int,input().split()))) memo = [0]*(N) for j in range(N): b = B[j] cIdx = bisect(C,b) memo[j] = N-cIdx candidate = [0]*(N) candidate[-1] = memo[-1] for j in range(N-2,-1,-1): candidate[j] += candidate[j+1]+memo[j] ans = 0 for a in A: bIdx = bisect(B,a) if bIdx < N: ans += candidate[bIdx] print(ans) main()
p03557
from bisect import bisect_left N = int(eval(input())) A = sorted(list(map(int,input().split()))) B = sorted(list(map(int,input().split()))) C = sorted(list(map(int,input().split()))) """ まず、前処理として、「Bの祭壇から大きさb以下のパーツを使うとき、Aの祭壇のパーツとの組み合わせはいくつあるか」というのを調べてメモしておく。 次に、Cの祭壇の大きさがcのとき、という風に場合わけして、選べるBの祭壇の大きさを絞って、A,B,Cの組み合わせの数を加算していく。 """ tmpSum = 0 dicB = {} for i in range(N): b = B[i] if b not in dicB: dicB[b] = tmpSum idx = bisect_left(A,b) dicB[b] += idx tmpSum += idx ans = 0 for i in range(N): c = C[i] idx = bisect_left(B,c) if idx != 0: b = B[idx-1] ans += dicB[b] print(ans)
from bisect import bisect N = int(eval(input())) A = sorted(list(map(int,input().split()))) B = sorted(list(map(int,input().split()))) C = sorted(list(map(int,input().split()))) """ 前処理で、中部の祭壇でBi以下のサイズを選べるときの、中段と上段のパーツの組み合わせのパターン数を計算しておく。 """ BPattern = [] for i in range(N): b = B[i] idx = bisect(A,b-1) if i == 0: BPattern.append(idx) else: BPattern.append(BPattern[-1]+idx) ans = 0 for i in range(N): c = C[i] idx = bisect(B,c-1) if idx: ans+=BPattern[idx-1] print(ans)
p03557
from bisect import bisect_right def solve(): N, *ABC = list(map(int, open(0).read().split())) A = ABC[:N] B = ABC[N:2*N] C = ABC[2*N:] B.sort() C.sort() ans = 0 for i in range(N): index = bisect_right(B, A[i]) for j in range(index, N): ans += N - bisect_right(C, B[j]) print(ans) if __name__ == '__main__': solve()
from bisect import bisect_left, bisect_right def solve(): N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() C.sort() ans = 0 for i in range(N): cnt_a = bisect_left(A, B[i]) cnt_b = N - bisect_right(C, B[i]) ans += cnt_a * cnt_b print(ans) if __name__ == '__main__': solve()
p03557
N=list(map(int,input().split())) A=sorted(list(map(int,input().split()))) B=list(map(int,input().split())) C=sorted(list(map(int,input().split()))) def countA(target,L): ok=-1 ng=len(L) while abs(ok-ng)>1: mid=(ok+ng)//2 if L[mid]<target: ok=mid else: ng=mid return (ok+1) def countC(target,L): ok=len(L) ng=-1 while abs(ok-ng)>1: mid=(ok+ng)//2 if L[mid]>target: ok=mid else: ng=mid return len(L)-ok ans=0 for i in range(len(B)): data=B[i] ans+=(countA(data,A)*countC(data,C)) print(ans)
N=int(eval(input())) A=sorted(list(map(int,input().split()))) B=sorted(list(map(int,input().split()))) C=sorted(list(map(int,input().split()))) # Bの値を決める # Bより小さいAを二分探索、Bより大きいAを二分探索、その積を各Bごとに求めて足していく import bisect ans=0 for i in range(len(B)): apos=bisect.bisect_left(A,B[i]) cpos=bisect.bisect_right(C,B[i]) ans+=(apos)*(N-cpos) print(ans)
p03557
n = int(eval(input())) a = sorted(list(map(int,input().split()))) b = sorted(list(map(int,input().split()))) c = sorted(list(map(int,input().split()))) p = [0]*n q = [0]*n k = 0 for i in range(n): while k<n: if a[k]<b[i]: k += 1 else: break p[i] = k k = 0 for i in range(n): while k<n: if b[k]<c[i]: k += 1 else: break q[i] = sum(p[:k]) print((sum(q)))
n = int(eval(input())) a = sorted(list(map(int,input().split()))) b = sorted(list(map(int,input().split()))) c = sorted(list(map(int,input().split()))) p = [0]*n q = [0]*n k = 0 for i in range(n): while k<n: if a[k]<b[i]: k += 1 else: break p[i] = k k = 0 s = 0 ans = 0 for i in range(n): while k<n: if b[k]<c[i]: s += p[k] k += 1 else: break ans += s print(ans)
p03557
from bisect import * n=int(eval(input())) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) A.sort() B.sort() C.sort() ans=0 for c in C: for b in B[:bisect_left(B,c)]: ans+=bisect_left(A,b) print(ans)
from bisect import * n=int(eval(input())) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) A.sort() B.sort() C.sort() ans=0 for b in B: ans+=(n-bisect(C,b))*bisect_left(A,b) print(ans)
p03557
def binary_search_A(N,A,b): upper = N - 1 lower = 0 while upper - lower > 1: middle = upper + lower // 2 if A[middle] > b: upper = middle else: lower = middle if b >= A[upper]: return upper+1 elif b >= A[lower]: return lower+1 else: return lower def binary_search_C(N,C,b): upper = N - 1 lower = 0 while upper - lower > 1: middle = upper + lower // 2 if C[middle] > b: upper = middle else: lower = middle if b < C[lower]: return N-lower elif b < C[upper]: return N - (lower+1) else: return N - (upper+1) N = int(eval(input())) A = [int(i) for i in input().split()] B = [int(i) for i in input().split()] C = [int(i) for i in input().split()] A.sort() B.sort() C.sort() ans = 0 for i in range(N): j = binary_search_A(N, A, B[i]) #print(j) k = binary_search_C(N, C, B[i]) #print(k) ans += j * k print(ans)
def binary_search_low(ls, v): """ [input] ls: 二分探索するリスト(配列) v: 探索の基準となる値 [output] ok: 基準を満たす最大index (ng: 基準を満たさない最小index) """ ok = -1 ng = n while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if ls[mid] < v: ok = mid else: ng = mid return ok #, ng def binary_search_high(ls, v): """ [input] ls: 二分探索するリスト(配列) v: 探索の基準となる値 [output] ok: 基準を満たす最大index (ng: 基準を満たさない最小index) """ ng = -1 ok = n while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if ls[mid] > v: ok = mid else: ng = mid return ok n = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) ans = 0 for b in B: a_count = binary_search_low(A,b) + 1 b_count = n - binary_search_high(C, b) #print(a_count,b_count) ans += a_count*b_count print(ans)
p03557
def binary_search_low(ls, v): """ [input] ls: 二分探索するリスト(配列) v: 探索の基準となる値 [output] ok: 基準を満たす最大index (ng: 基準を満たさない最小index) """ ok = -1 ng = n while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if ls[mid] < v: ok = mid else: ng = mid return ok #, ng def binary_search_high(ls, v): """ [input] ls: 二分探索するリスト(配列) v: 探索の基準となる値 [output] ok: 基準を満たす最大index (ng: 基準を満たさない最小index) """ ng = -1 ok = n while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if ls[mid] > v: ok = mid else: ng = mid return ok n = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) ans = 0 for b in B: a_count = binary_search_low(A,b) + 1 b_count = n - binary_search_high(C, b) #print(a_count,b_count) ans += a_count*b_count print(ans)
def binary_search_low(ls, v): """ ・基準(v)より小さい値が配列の中に何個あるか, 二分探索によって見つける. [input] ls: 二分探索するリスト(配列) v: 探索の基準となる値 [output] return: 基準を満たす配列の要素数 """ ok = -1 ng = n while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if ls[mid] < v: ok = mid else: ng = mid return ok+1 def binary_search_high(ls, v): """ ・基準(v)より大きい値が配列の中に何個あるか, 二分探索によって見つける. [input] ls: 二分探索するリスト(配列) v: 探索の基準となる値 [output] return: 基準を満たす配列の要素数 """ ng = -1 ok = n while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if ls[mid] > v: ok = mid else: ng = mid return len(ls) - ok n = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) ans = 0 for b in B: a_count = binary_search_low(A,b) b_count = binary_search_high(C, b) ans += a_count*b_count print(ans)
p03557
n=int(eval(input())) a=sorted(list(map(int,input().split()))) b=sorted(list(map(int,input().split()))) c=sorted(list(map(int,input().split()))) ans=0 for i in b: he=-1 ta=n while ta-he>1: mid=(he+ta)//2 if i>a[mid]: he=mid else: ta=mid x=he+1 he_=-1 ta_=n while ta_-he_>1: mid_=(he_+ta_)//2 if i>=c[mid_]: he_=mid_ else: ta_=mid_ y=n-ta_ ans+=x*y print(ans)
import bisect n=int(eval(input())) a=sorted(list(map(int,input().split()))) b=sorted(list(map(int,input().split()))) c=sorted(list(map(int,input().split()))) ans=0 for i in b: x=bisect.bisect_left(a,i) y=n-bisect.bisect_right(c,i) ans+=x*y print(ans)
p03557
import bisect n=int(eval(input())) a=sorted(list(map(int,input().split()))) b=sorted(list(map(int,input().split()))) c=sorted(list(map(int,input().split()))) ans=0 for i in b: x=bisect.bisect_left(a,i) y=n-bisect.bisect_right(c,i) ans+=x*y print(ans)
import bisect n=int(eval(input())) a=sorted(list(map(int,input().split()))) b=sorted(list(map(int,input().split()))) c=sorted(list(map(int,input().split()))) ans=0 for i in b: A=bisect.bisect_left(a,i) B=len(b)-bisect.bisect_right(c,i) ans+=A*B print(ans)
p03557
import bisect n=int(eval(input())) a=sorted(list(map(int,input().split()))) b=sorted(list(map(int,input().split()))) c=sorted(list(map(int,input().split()))) ans=0 for i in b: A=bisect.bisect_left(a,i) B=len(b)-bisect.bisect_right(c,i) ans+=A*B print(ans)
import bisect n=int(eval(input())) a=sorted(list(map(int,input().split()))) b=list(map(int,input().split())) c=sorted(list(map(int,input().split()))) ans=0 for i in b: ans+=(n-bisect.bisect_right(c,i))*bisect.bisect_left(a,i) print(ans)
p03557
import bisect ans = 0 N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() lis_B = [0] * N for i in range(N): tmp = bisect.bisect_right(C, B[i]) if tmp == N: break lis_B[i] = N - tmp for i in range(N): tmp = bisect.bisect_right(B, A[i]) if tmp == N: break ans += sum(lis_B[tmp:N]) print(ans)
import bisect ans = 0 N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() for i in range(N): tmp_1 = bisect.bisect_right(C, B[i]) tmp_2 = bisect.bisect_left(A, B[i]) ans += (N - tmp_1) * tmp_2 print(ans)
p03557
def resolve(): import sys input = sys.stdin.readline # 整数 1 つ n = int(eval(input())) # 整数複数個 # a, b = map(int, input().split()) # 整数 N 個 (改行区切り) # N = [int(input()) for i in range(N)] # 整数 N 個 (スペース区切り) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) # 整数 (縦 H 横 W の行列) #N = [list(map(int, input().split())) for i in range(3)] A.sort() B.sort() C.sort() import bisect cnt = 0 for ai in range(n): j = bisect.bisect_right(B, A[ai]) for bi in range(j, n): k = bisect.bisect_right(C, B[bi]) cnt += n - k #print(cnt) print(cnt) # print(A) # print(B) # print(C) resolve()
def resolve(): import sys input = sys.stdin.readline # 整数 1 つ n = int(eval(input())) # 整数複数個 # a, b = map(int, input().split()) # 整数 N 個 (改行区切り) # N = [int(input()) for i in range(N)] # 整数 N 個 (スペース区切り) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) # 整数 (縦 H 横 W の行列) #N = [list(map(int, input().split())) for i in range(3)] A.sort() B.sort() C.sort() import bisect cnt = 0 for bi in B: a_ok = bisect.bisect_left(A, bi) c_ok = bisect.bisect_right(C, bi) cnt += a_ok * (n - c_ok) print(cnt) resolve()
p03557
import bisect n = int(eval(input())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) a.sort() b.sort() c.sort() memo = [0]*(n+1) for i in range(n): memo[bisect.bisect_left(b,c[i])] += 1 for i in range(n-1,-1,-1): memo[i] += memo[i+1] for i in range(n-1,-1,-1): memo[i] += memo[i+1] memo = memo[1:]+[0] ans = 0 for i in range(n): ans += memo[bisect.bisect_right(b,a[i])] print(ans)
import bisect n = int(eval(input())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) a.sort() b.sort() c.sort() ans = 0 for i in range(n): t = b[i] ci = bisect.bisect_right(c,t) ai = bisect.bisect_left(a,t) ans += ai*(n-ci) print(ans)
p03557
import bisect N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() ans = 0 for a in A: i = bisect.bisect_right(B, a) for b in B[i:]: j = bisect.bisect_right(C, b) ans += N-j print(ans)
import bisect N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() ans = 0 for b in B: i = bisect.bisect_left(A, b) j = bisect.bisect_right(C, b) ans += i*(N-j) print(ans)
p03557
def C_SnukeFestival(N, A, B, C): a = sorted(A) b = sorted(B) c = sorted(C) l = N ans = 0 for i in range(N): for j in range(N): for k in range(N): if a[i] < b[j] and b[j] < c[k]: ans += 1 return ans N = int(eval(input())) A = [int(_) for _ in input().split()] B = [int(_) for _ in input().split()] C = [int(_) for _ in input().split()] print((C_SnukeFestival(N, A, B, C))) #間に合いそうもない
def C_SnukeFestival(N, A, B, C): a = sorted(A) b = sorted(B) c = sorted(C) import bisect ans = 0 for j in range(N): # b[j]より小さなaの要素の個数 i = bisect.bisect_left(a, b[j]) # b[j]より大きなcの要素の個数 k = N - bisect.bisect_right(c, b[j]) ans += i * k return ans N = int(eval(input())) A = [int(_) for _ in input().split()] B = [int(_) for _ in input().split()] C = [int(_) for _ in input().split()] print((C_SnukeFestival(N, A, B, C)))
p03557
import bisect import math N=int(eval(input())) b1=0 ans=0 A=list(map(int, input().split())) A=sorted(A) B=list(map(int, input().split())) B=sorted(B) C=list(map(int, input().split())) C=sorted(C) D=[] for b in B: D.append(len(C)-bisect.bisect_right(C,b)) B.append(math.inf) for i in range(len(A)): b1=bisect.bisect_right(B,A[i]) for j in range(b1,len(B)-1): ans += D[j] print(ans)
import bisect N=int(eval(input())) b1=0 d=0 ans=0 A=list(map(int, input().split())) A=sorted(A) B=list(map(int, input().split())) B=sorted(B, reverse=True) C=list(map(int, input().split())) C=sorted(C) D=[] E=[] for b in B: d=d+len(C)-bisect.bisect_right(C,b) D.append(d) D=sorted(D, reverse= True) B=sorted(B) for a in A: if 0 <= bisect.bisect_right(B,a) <= len(D)-1: ans += D[bisect.bisect_right(B,a)] print(ans)
p03557
import bisect N = int(eval(input())) # サイズが下の方が大きくないとダメtop<mid<bottom tops = sorted(list(map(int, input().split(" ")))) mids = list(map(int, input().split(" "))) bottoms = sorted(list(map(int, input().split(" ")))) # print(tops) # print(mids) # print(bottoms) # def left_binary_search(check_list, num, left, right): # if left > right: # return left # mid = (left + right) // 2 # if check_list[mid] >= num: # return left_binary_search(check_list, num, left, mid - 1) # else: # return left_binary_search(check_list, num, mid + 1, right) # def right_binary_search(check_list, num, left, right): # if left > right: # return left # mid = (left + right) // 2 # if check_list[mid] > num: # return right_binary_search(check_list, num, left, mid - 1) # else: # return right_binary_search(check_list, num, mid + 1, right) total_count = 0 for mid in mids: # bottom_start_index = right_binary_search(bottoms, mid, 0, N - 1) bottom_start_index = bisect.bisect_right(bottoms, mid) # top_end_index = left_binary_search(tops, mid, 0, N - 1) top_end_index = bisect.bisect_left(tops, mid) total_count += ((N - bottom_start_index) * top_end_index) print(total_count)
N = int(eval(input())) tops = list(map(int, input().split())) middles = list(map(int, input().split())) bottoms = list(map(int, input().split())) tops.sort() middles.sort() bottoms.sort() # print(tops) # print(middles) # print(bottoms) # top<middle<bottomでないといけない # middleをfor文で繰り返して、topとbottomで二分探索をする。 # そしてそれ以下の数を出して、掛け算すれば組み合わせの数を出せる def left_binary_search(target, nums): left = 0 right = len(nums) - 1 while left <= right: # 0+7 /2 = 3 # print(left, right) mid = int((left + right) / 2) # print(f'mid: {mid}') if nums[mid] < target: left = mid + 1 elif nums[mid] > target: right = mid - 1 else: right = mid - 1 # 0,1,2,3,4 # 2 # => return 2 # print(left, right) return left def right_binary_search(target, nums): left = 0 right = len(nums) - 1 while left <= right: # 0+7 /2 = 3 # print(left, right) mid = int((left + right) / 2) if nums[mid] < target: left = mid + 1 elif nums[mid] > target: right = mid - 1 else: left = mid + 1 # 0,1,2,3,4 # 2 # => return 2 # print(left, right) return left count = 0 for middle in middles: top_index = left_binary_search(middle, tops) bottom_index = right_binary_search(middle, bottoms) # print(top_index, bottom_index, (top_index) * (len(bottoms) - bottom_index)) count += (top_index) * (len(bottoms) - bottom_index) print(count)
p03557
from sys import stdin def input(): return stdin.readline().strip() def main(): N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() nums = [0] * (N + 1) for i, b in enumerate(B): ng = -1 ok = N while abs(ok - ng) > 1: mid = (ok + ng) // 2 if C[mid] > b: ok = mid else: ng = mid nums[i] = N - ok for i in range(N, 0, -1): nums[i - 1] += nums[i] ans = 0 for a in A: ng = -1 ok = N while abs(ok - ng) > 1: mid = (ok + ng) // 2 if B[mid] > a: ok = mid else: ng = mid ans += nums[ok] print(ans) if __name__ == "__main__": main()
from sys import stdin def input(): return stdin.readline().strip() def main(): N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() nums = [0] * (N + 1) ng = -1 for i, b in enumerate(B): ok = N while abs(ok - ng) > 1: mid = (ok + ng) // 2 if C[mid] > b: ok = mid else: ng = mid nums[i] = N - ok for i in range(N, 0, -1): nums[i - 1] += nums[i] ans = 0 ng = -1 for a in A: ok = N while abs(ok - ng) > 1: mid = (ok + ng) // 2 if B[mid] > a: ok = mid else: ng = mid ans += nums[ok] print(ans) if __name__ == "__main__": main()
p03557
from sys import stdin def input(): return stdin.readline().strip() def main(): N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() nums = [0] * (N + 1) ng = -1 for i, b in enumerate(B): ok = N while abs(ok - ng) > 1: mid = (ok + ng) // 2 if C[mid] > b: ok = mid else: ng = mid nums[i] = N - ok for i in range(N, 0, -1): nums[i - 1] += nums[i] ans = 0 ng = -1 for a in A: ok = N while abs(ok - ng) > 1: mid = (ok + ng) // 2 if B[mid] > a: ok = mid else: ng = mid ans += nums[ok] print(ans) if __name__ == "__main__": main()
from sys import stdin from bisect import bisect_left def input(): return stdin.readline().strip() def main(): N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() nums = [0] * (N + 1) pos = 0 for i, b in enumerate(B): pos = bisect_left(C, b + 1, pos) nums[i] = N - pos for i in range(N, 0, -1): nums[i - 1] += nums[i] ans = 0 pos = 0 for a in A: pos = bisect_left(B, a + 1, pos) ans += nums[pos] print(ans) if __name__ == "__main__": main()
p03557
from sys import stdin from bisect import bisect_right, bisect_left def input(): return stdin.readline().strip() def main(): N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() ans = 0 i, j = 0, 0 for b in B: i = bisect_left(A, b, lo=i) j = bisect_right(C, b, lo=j) ans += i * (N - j) print(ans) if __name__ == "__main__": main()
from sys import stdin from bisect import bisect_right, bisect_left def input(): return stdin.readline().strip() def main(): N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B) print(ans) if __name__ == "__main__": main()
p03557
from sys import stdin from bisect import bisect_right, bisect_left def input(): return stdin.readline().strip() def main(): N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() C.sort() ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B) print(ans) if __name__ == "__main__": main()
from sys import stdin from bisect import bisect_right, bisect_left def input(): return stdin.readline().strip() def main(): N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() C.sort() ans = 0 for b in B: ans += bisect_left(A, b) * (N - bisect_right(C, b)) print(ans) if __name__ == "__main__": main()
p03557
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 def main(): N, *ABC = list(map(int, read().split())) A = sorted(ABC[:N]) B = sorted(ABC[N : 2 * N]) C = sorted(ABC[2 * N : 3 * N]) ans = 0 for b in B: ok = -1 ng = N while ng - ok > 1: mid = (ok + ng) // 2 if A[mid] < b: ok = mid else: ng = mid a_num = ok + 1 ok = N ng = -1 while ok - ng > 1: mid = (ok + ng) // 2 if C[mid] > b: ok = mid else: ng = mid c_num = N - ok ans += a_num * c_num print(ans) return if __name__ == '__main__': main()
import sys from bisect import bisect_left, bisect_right read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 def main(): N, *ABC = list(map(int, read().split())) A = sorted(ABC[:N]) B = ABC[N : 2 * N] C = sorted(ABC[2 * N : 3 * N]) ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B) print(ans) return if __name__ == '__main__': main()
p03557
import sys from bisect import bisect_left, bisect_right read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 def main(): N, *ABC = list(map(int, read().split())) A = sorted(ABC[:N]) B = ABC[N : 2 * N] C = sorted(ABC[2 * N : 3 * N]) ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B) print(ans) return if __name__ == '__main__': main()
import sys from bisect import bisect_left, bisect_right read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 def main(): N = int(readline()) A = list(map(int, readline().split())) B = list(map(int, readline().split())) C = list(map(int, readline().split())) A.sort() C.sort() ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B) print(ans) return if __name__ == '__main__': main()
p03557
from sys import stdin from bisect import bisect_right, bisect_left def input(): return stdin.readline().strip() def main(): N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() B.sort() C.sort() ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B) print(ans) if __name__ == "__main__": main()
import sys from bisect import bisect_left, bisect_right read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 def main(): N = int(readline()) A = list(map(int, readline().split())) B = list(map(int, readline().split())) C = list(map(int, readline().split())) A.sort() B.sort() C.sort() ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B) print(ans) return if __name__ == '__main__': main()
p03557
#ABC077 C - Snuke Festival from bisect import bisect_left, bisect_right si = lambda: eval(input()) ni = lambda: int(eval(input())) nm = lambda: list(map(int, input().split())) nl = lambda: list(map(int, input().split())) N = ni() A = nl() B = nl() C = nl() A.sort() B.sort() C.sort() ans = 0 for i in range(N): t = 0 tt = 0 t = bisect_left(B,C[i]) for j in range(t,0,-1): tt = bisect_left(A,B[j-1]) ans += tt print(ans)
#ABC077 C - Snuke Festival from bisect import bisect_left, bisect_right si = lambda: eval(input()) ni = lambda: int(eval(input())) nm = lambda: list(map(int, input().split())) nl = lambda: list(map(int, input().split())) N = ni() A = nl() B = nl() C = nl() A.sort() C.sort() ans = 0 for i in range(N): t = 0 tt = 0 t = bisect_left(A,B[i]) tt = N-bisect_right(C,B[i]) ans += t*tt print(ans)
p03557
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() ans = 0 dict_a = dict() dict_b = dict() for i in range(n): if a[i] in list(dict_a.keys()): b_mid = dict_a[a[i]] else: left = n - 1 right = 0 b_mid = n // 2 while left >= right: if b[b_mid] > a[i]: left = b_mid - 1 else: right = b_mid + 1 b_mid = (left + right) // 2 b_mid += 1 dict_a[a[i]] = b_mid for j in range(b_mid, n): if b[j] in list(dict_b.keys()): c_mid = dict_b[b[j]] else: left = n - 1 right = 0 c_mid = n // 2 while left >= right: if c[c_mid] > b[j]: left = c_mid - 1 else: right = c_mid + 1 c_mid = (left + right) // 2 dict_b[b[j]] = c_mid ans += n - c_mid - 1 print(ans)
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() ans = 0 i = [] k = [] for j in range(n): left = n - 1 right = 0 a_mid = n // 2 while left >= right: if a[a_mid] >= b[j]: left = a_mid - 1 else: right = a_mid + 1 a_mid = (left + right) // 2 i.append(a_mid + 1) for j in range(n): left = n - 1 right = 0 c_mid = n // 2 while left >= right: if c[c_mid] > b[j]: left = c_mid - 1 else: right = c_mid + 1 c_mid = (left + right) // 2 k.append(n - c_mid - 1) ans = sum(x * y for x, y in zip(i, k)) print(ans)
p03557
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() ans = 0 i = [] k = [] for j in range(n): left = n - 1 right = 0 a_mid = n // 2 while left >= right: if a[a_mid] >= b[j]: left = a_mid - 1 else: right = a_mid + 1 a_mid = (left + right) // 2 i.append(a_mid + 1) for j in range(n): left = n - 1 right = 0 c_mid = n // 2 while left >= right: if c[c_mid] > b[j]: left = c_mid - 1 else: right = c_mid + 1 c_mid = (left + right) // 2 k.append(n - c_mid - 1) ans = sum(x * y for x, y in zip(i, k)) print(ans)
import bisect n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() ans = 0 for j in range(n): i = bisect.bisect_left(a, b[j]) k = n - bisect.bisect_right(c, b[j]) ans += i * k print(ans)
p03557
def is_ok_under(array, mid, target): return array[mid] < target def is_ok_over(array, mid, target): return array[mid] > target # ok is -1. ng is len(array) def bSearchUnder(array, ok, ng, target): while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok_under(array, mid, target): ok = mid else: ng = mid return ok # ng is -1. ok is len(array) def bSearchOver(array, ok, ng, target): while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok_over(array, mid, target): ok = mid else: ng = mid return ok n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() ans = 0 for i in range(len(b)): add = 1 add *= bSearchUnder(a, -1, len(a), b[i]) + 1 add *= len(c) - bSearchOver(c, len(c), -1, b[i]) ans += add print(ans)
def binSearch(array, num): n = len(array) l = -1 r = n while l + 1 < r: m = (l + r) // 2 if num <= array[m]: r = m else: l = m return r n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() c.sort() ans = 0 for i in range(len(b)): a_idx = binSearch(a, b[i]) c_idx = binSearch(c, b[i] + 1) ans += a_idx * (n - c_idx) print(ans)
p03557
N = int(eval(input())) A = list(map(int,input().split())) B = list(map(int,input().split())) C = list(map(int,input().split())) A.sort() B.sort() C.sort() ans = 0 for i in A: for j in B: for k in C: if (i<j)&(j<k): ans += 1 print(ans)
import bisect n= int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) a.sort() b.sort() c.sort() ans = 0 for i in range(n): x = bisect.bisect_left(a,b[i]) y = bisect.bisect_right(c,b[i]) ans += x*(n-y) print(ans)
p03557
import bisect N = int(eval(input())) A = sorted([int(i) for i in input().split()]) B = sorted([int(i) for i in input().split()]) C = sorted([int(i) for i in input().split()]) cnt = 0 for i in range(N): x = bisect.bisect_right(B, A[i]) for j in B[x:]: y = bisect.bisect_right(C, j) cnt += N - y print(cnt)
import bisect N = int(eval(input())) A = sorted([int(i) for i in input().split()]) B = sorted([int(i) for i in input().split()]) C = sorted([int(i) for i in input().split()]) cnt = 0 for b in B: cnt += bisect.bisect_left(A, b) * (N - bisect.bisect_right(C, b)) print(cnt)
p03557
import bisect n = int(eval(input())) a = sorted(list(map(int, input().split()))) b = sorted(list(map(int, input().split()))) c = sorted(list(map(int, input().split()))) bnum = [n - bisect.bisect_right(c, b[i]) for i in range(n)] ans = 0 for i in range(n): ai = a[i] ans += sum(bnum[bisect.bisect_right(b, ai):n]) print(ans)
import bisect n = int(eval(input())) a = sorted(list(map(int, input().split()))) b = sorted(list(map(int, input().split()))) c = sorted(list(map(int, input().split()))) ans = 0 for i in b: ai = bisect.bisect_left(a, i) ci = n - bisect.bisect_right(c, i) ans += ai*ci print(ans)
p03557
def biserch(l,key,flag=True): if flag is True: func = judge_1 else: func = judge_2 left = -1; right = len(l) while right - left > 1: middle = (left+right) // 2 if func(l,key,middle) is True: right = middle else: left = middle return right def judge_1(l,key,middle): if key <= l[middle]: return True else: return False def judge_2(l,key,middle): if key < l[middle]: return True else: return False N = int(eval(input())) A = sorted(list(map(int,input().split()))) B = sorted(list(map(int,input().split()))) C = sorted(list(map(int,input().split()))) ans = 0 for b in B: top = biserch(A,b) bottom = N - biserch(C,b,flag=False) ans += top*bottom print(ans)
def biserch_min(l,key): left = 0; right = len(l) while left < right: mid = (left+right)//2 if l[mid] < key: left = mid+1 else: right = mid return left def biserch_max(l,key): left = 0; right = len(l) while left < right: mid = (left+right)//2 if key < l[mid]: right = mid else: left = mid+1 return right N = int(eval(input())) A = sorted(list(map(int,input().split()))) B = sorted(list(map(int,input().split()))) C = sorted(list(map(int,input().split()))) ans = 0 for b in B: top = biserch_min(A,b) bottom = N - biserch_max(C,b) ans += top*bottom print(ans)
p03557
import bisect N = int(eval(input())) lst_a = sorted([int(x) for x in input().split()]) lst_b = sorted([int(x) for x in input().split()]) lst_c = sorted([int(x) for x in input().split()]) ans = 0 for b in lst_b: i = bisect.bisect_left(lst_a, b) j = bisect.bisect_right(lst_c, b) if i > 0 and j != len(lst_c): ans += i * (N - j) print(ans)
import bisect N = int(eval(input())) lst_a = sorted([int(x) for x in input().split()]) lst_b = sorted([int(x) for x in input().split()]) lst_c = sorted([int(x) for x in input().split()]) ans = 0 for b in lst_b: i = bisect.bisect_left(lst_a, b) j = bisect.bisect_right(lst_c, b) ans += i * (N - j) print(ans)
p03557
import sys sys.setrecursionlimit(4100000) input=sys.stdin.readline # coding: utf-8 # Your code here! n=int(eval(input())) a = [list(map(int, input().split())) for _ in range(3)] a[0].sort() a[2].sort() """ print(a[0]) print(a[1]) print(a[2]) """ def bin_lower(b): if a[0][0]>=b: return 0 pl=0 pr=n-1 while True: pc=(pl+pr)//2 if a[0][pc]>=b and a[0][pc-1]<b: return pc elif a[0][pc]<b: pl=pc+1 if pl>n-1: return n """ else: pr=pc-1 if pr<0: return 0 """ def bin_upper(b): if a[2][n-1]<=b: return 0 pl=0 pr=n-1 while True: pc=(pl+pr)//2 if a[2][pc]<=b and a[2][pc+1]>b: return n-1-pc elif a[2][pc]>b: pr=pc-1 if pr<0: return n """ else: pl=pc+1 if pl>n-1: return 0 """ """ print(bin_upper(a[1][0])) print(bin_lower(a[1][0])) print(bin_upper(a[1][1])) print(bin_lower(a[1][1])) print(bin_upper(a[1][2])) print(bin_lower(a[1][2])) """ cnt=0 for i in range(n): cnt+=bin_lower(a[1][i])*bin_upper(a[1][i]) print(cnt)
import sys input = sys.stdin.readline # coding: utf-8 # Your code here! n = int(eval(input())) a = [list(map(int, input().split())) for _ in range(3)] a[0].sort() a[2].sort() def bin_chisaimono(b): if a[0][0] >= b: return 0 pl = 0 pr = n - 1 while True: pc = (pl + pr) // 2 if pc == n - 1 and a[0][pc] < b: return n elif a[0][pc] < b <= a[0][pc + 1]: return pc + 1 elif a[0][pc] >= b: pr = pc -1 else: pl = pc + 1 def bin_okimono(b): if a[2][n - 1] <= b: return 0 pl = 0 pr = n - 1 while True: pc = (pl + pr) // 2 if pc == 0 and a[2][pc] > b: return n elif a[2][pc - 1] <= b < a[2][pc]: return n - pc elif a[2][pc] <= b: pl = pc + 1 else: pr = pc - 1 cnt = 0 for i in range(n): cnt += bin_chisaimono(a[1][i]) * bin_okimono(a[1][i]) print(cnt)
p03557
import bisect n=int(eval(input())) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) a.sort() b.sort() c.sort() ab=[] bc=[] for i in range(n): ab.append(bisect.bisect_left(a, b[i])) bc.append(bisect.bisect_left(b, c[i])) ans=0 for i in bc: ans+=sum(ab[:i]) print(ans)
import bisect n=int(eval(input())) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) a.sort() c.sort() ans=0 for i in b: up=bisect.bisect_left(a, i) dn=n-bisect.bisect_right(c, i) ans+=up*dn print(ans)
p03557
t = eval(input()) lst = list(map(int, input().split())) a = max(lst) b = min(lst) c = sum(lst) print((str(b) + " " + str(a) + " " + str(c)))
t = int(eval(input())) lst = list(map(int, input().split())) a = min(lst) b = max(lst) c = sum(lst) print((str(a) + " " + str(b) + " " + str(c)))
p02402
n = eval(input()) a = list(map(int,input().split())) a.sort() print(a[0],a[n-1],sum(a))
n = eval(input()) a = list(map(int,input().split())) print(min(a),max(a),sum(a))
p02402
eval(input()) nums = [int(x) for x in input().split(" ")] print(("{0} {1} {2}".format(min(nums), max(nums), sum(nums))))
line = eval(input()) nums = list(map(int, input().split())) print(f"{min(nums)} {max(nums)} {sum(nums)}")
p02402
from functools import reduce n = eval(input()) l = sorted(map(int,input().split())) print(l[0], l[n-1], reduce(lambda x,y: x+y, l))
n = eval(input()) l = list(map(int,input().split())) print(min(l), max(l), sum(l))
p02402