input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
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() c.reverse() #print(a) #print(b) #print(c) pat=0 ikeep=-1 for i in range(n): x=b[i] if(x!=ikeep): ikeep=x else: pat+=paty*patz continue for j in range(n): y=a[j] paty=n if(x<=y): paty=j break for j in range(n): z=c[j] patz=n if(z<=x): patz=j break #print(paty,patz) pat+=paty*patz print(pat)
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) pat=0 ikeep=-1 for i in range(n): x=b[i] if(x!=ikeep): ikeep=x else: pat+=paty*patz continue paty=bisect.bisect_left(a,x) patz=n-bisect.bisect_right(c,x) #print(paty,patz) pat+=paty*patz print(pat)
p03557
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() ans=0 for i in range(n): for j in range(n): if a[i]>=b[j]: continue else: ans+=n-bisect_left(c,b[j]+1) print(ans)
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() ans=0 for i in range(n): A=bisect_left(a,b[i]) C=n-bisect_right(c,b[i]) ans+=A*C print(ans)
p03557
import itertools 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 i in range(0,len(c)): b_index=bisect.bisect_left(b,c[-i-1]) for u in range(b_index): cnt+=bisect.bisect_left(a,b[b_index-1-u]) print(cnt)
import itertools 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 i in range(0,len(b)): a_index = bisect.bisect_left(a,b[i]) c_index = bisect.bisect_right(c,b[i]) cnt+=a_index*(len(c)-c_index) print(cnt)
p03557
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(eval(input())) A = list(sorted(map(int, input().split()))) B = list(sorted(map(int, input().split()))) C = list(sorted(map(int, input().split()))) base = [0] * N for i, b in enumerate(B): left = -1 right = N while (right - left) > 1: mid = left + (right - left) // 2 if C[mid] > b: right = mid else: left = mid base[i] = N - right acc = [0] * (N + 1) for i in range(1, N + 1): acc[i] = acc[i - 1] + base[i - 1] ans = 0 for i, a in enumerate(A): left = -1 right = N while right - left > 1: mid = left + (right - left) // 2 if B[mid] > a: right = mid else: left = mid ans += acc[N] - acc[right] 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(eval(input())) A = list(sorted(map(int, input().split()))) B = list(sorted(map(int, input().split()))) C = list(sorted(map(int, input().split()))) ans = 0 for i, b in enumerate(B): left = -1 right = N while (right - left) > 1: mid = left + (right - left) // 2 if C[mid] > b: right = mid else: left = mid Cs = N - right left = -1 right = N while (right - left) > 1: mid = left + (right - left) // 2 if A[mid] >= b: right = mid else: left = mid As = right ans += As * Cs print(ans)
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 = list(map(int, input().split())) ans = 0 for c in C: max_index_B = bisect_left(B, c) for i in range(max_index_B): ans += bisect_left(A, B[i]) print(ans)
from bisect import bisect_left, bisect_right 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 b in B: max_index_A = bisect_left(A, b) max_index_C = N - bisect_right(C, b) ans += (max_index_A) * (max_index_C) print(ans)
p03557
n = int(eval(input())) a = sorted(map(int, input().split())) b = sorted(map(int, input().split())) c = sorted(map(int, input().split())) import bisect ans = 0 for i in b: A = bisect.bisect_left(a, i) C = n - bisect.bisect_right(c, i) ans += A * 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()))) import bisect ans = 0 for bi in b: a_cnt = bisect.bisect_left(a, bi) c_cnt = N - bisect.bisect_right(c, bi) ans += a_cnt * c_cnt #print(a_cnt, c_cnt) print(ans)
p03557
import bisect as bi 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 range(N): for j in range(bi.bisect_left(B,C[i])): ans+=bi.bisect_left(A,B[j]) print(ans)
import bisect as bi 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 Bi in B: a=bi.bisect_left(A,Bi) c=N-bi.bisect_right(C,Bi) ans+=a*c print(ans)
p03557
N=int(eval(input())) s=sorted(list(map(int,input().split()))) t=sorted(list(map(int,input().split())),reverse=True) u=sorted(list(map(int,input().split())),reverse=True) ans=0 for j in range(N): tt=[] for k in range(N): if s[j]<t[k]: tt.append(t[k]) else: break for ii in range(len(tt)): for jj in range(N): if tt[ii]<u[jj]: ans+=1 else: break 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: aa=bisect.bisect_left(a,i) cc=N-bisect.bisect_right(c,i) ans+=aa*cc print(ans)
p03557
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: aa=bisect.bisect_left(a,i) cc=N-bisect.bisect_right(c,i) ans+=aa*cc print(ans)
import bisect N=int(eval(input())) s=[list(sorted(map(int,input().split()))) for i in range(3)] t=[] q=0 for i in s[1]: t.append(N-bisect.bisect_right(s[2],i)) for i in range(N): q+=bisect.bisect_left(s[0],s[1][i])*t[i] print(q)
p03557
from bisect import bisect_left N = int(eval(input())) upper = sorted(list(map(int, input().split()))) middle = sorted(list(map(int, input().split()))) lower = list(map(int, input().split())) ans = 0 for l in lower: idx = bisect_left(middle, l) if idx>=1: for m in middle[:idx]: idx2 = bisect_left(upper, m) ans += idx2 print(ans)
from bisect import bisect_left, bisect_right N = int(eval(input())) upper = sorted(list(map(int, input().split()))) middle = list(map(int, input().split())) lower = sorted(list(map(int, input().split()))) ans = 0 for m in middle: idx_u = bisect_left(upper, m) idx_l = N-bisect_right(lower, m) ans += idx_u*idx_l print(ans)
p03557
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """077-c""" import sys import pprint import re import itertools pp = pprint.PrettyPrinter(indent=2) def main(): """Main function.""" N = int(eval(input())) As = sorted(list(map(int, input().split(' ')))) Bs = sorted(list(map(int, input().split(' ')))) Cs = sorted(list(map(int, input().split(' ')))) Bs_count = [len(list([c for c in Cs if b < c])) for b in Bs] As_count = [len(list([b for b in Bs if a < b])) for a in As] count = 0 for c in As_count: if -1 * c == 0: break for c_ in Bs_count[-1 * c:]: count += c_ print(count) if __name__ == '__main__': sys.exit(main())
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """077-c""" import sys import pprint import re import itertools import bisect pp = pprint.PrettyPrinter(indent=2) def main(): """Main function.""" N = int(eval(input())) As = sorted(list(map(int, input().split(' ')))) Bs = list(map(int, input().split(' '))) Cs = sorted(list(map(int, input().split(' ')))) count = 0 for b in Bs: i = bisect.bisect_left(As, b) k = N - bisect.bisect_right(Cs, b) count += i * k print(count) if __name__ == '__main__': sys.exit(main())
p03557
from bisect import bisect import random def binary_search(L, n, i, j): # print(L, n, i, j) low = i high = j while low <= high: mid = (low + high) //2 guess = L[mid] # if guess == n: # return mid if guess > n: high = mid -1 else: low = mid + 1 # print(low) return low N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) # N = 10 ** 5 # A = [random.randint(1, 10**9) for _ in range(N)] # B = [random.randint(1, 10**9) for _ in range(N)] # C = [random.randint(1, 10**9) for _ in range(N)] A.sort() B.sort() C.sort() ans = 0 i, j = 0, 0 A_ind = [] B_cum = [0] for a in A: # i = binary_search(B, a, i, N-1) i = bisect(B, a) A_ind.append(i) s = 0 for b in B: # j = binary_search(C, b, j, N-1) j = i = bisect(C, b) s += N-j B_cum.append(s) for a in A_ind: ans += B_cum[-1] - B_cum[a] print(ans)
from bisect import bisect_left, bisect_right # import random N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) # N = 10 ** 5 # A = [random.randint(1, 10**9) for _ in range(N)] # B = [random.randint(1, 10**9) for _ in range(N)] # C = [random.randint(1, 10**9) for _ in range(N)] A.sort() B.sort() C.sort() ans = 0 for b in B: a = bisect_left(A, b) c = N-bisect_right(C, b) ans += a * c print(ans)
p03557
from bisect import bisect_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()))) cnt = [0] * N for i in range(N): cnt[i] = N - bisect_right(C, B[i]) res = 0 for i in range(N): idx = bisect_right(B, A[i]) if idx < N: res += sum(cnt[idx:]) print(res)
from bisect import bisect_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()))) cnt = [0] * N for i in range(N): cnt[i] = N - bisect_right(C, B[i]) cumsum = [0] * (N + 1) for i in range(N): cumsum[i + 1] = cumsum[i] + cnt[N - i - 1] res = 0 for i in range(N): res += cumsum[N - bisect_right(B, A[i])] print(res)
p03557
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() bb = [0 for _ in range(N)] for i,b in enumerate(B): for c in C[::-1]: if c > b: bb[i]+=1 else: break count = 0 for a in A: for i,b in enumerate(B[::-1]): if b > a: count += bb[-i-1] else: break return count print((main()))
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() count = 0 Ai = -1 Ci = -1 for i in range(N): if Ai<N-1: while A[Ai+1]<B[i]: Ai += 1 if Ai == N-1: break if Ci<N-1: while C[Ci+1]<=B[i]: Ci += 1 if Ci==N-1: break count += (Ai+1) * (N-(Ci+1)) return count if __name__ == '__main__': print((main()))
p03557
# def binary_search(lst): # pass import bisect n = int(eval(input())) lst_A = list(map(int, input().split())) lst_B = list(map(int, input().split())) lst_C = list(map(int, input().split())) lst_A.sort() lst_B.sort() lst_C.sort() ans = 0 for b in lst_B: ia = bisect.bisect_left(lst_A, b) ic = bisect.bisect_right(lst_C, b) na = len(lst_A[:ia]) nc = len(lst_C[ic:]) ans += na * nc print(ans)
import bisect n = int(eval(input())) lst_A = list(map(int, input().split())) lst_B = list(map(int, input().split())) lst_C = list(map(int, input().split())) lst_A.sort() lst_B.sort() lst_C.sort() ans = 0 for b in lst_B: na = bisect.bisect_left(lst_A, b) nc = n - bisect.bisect_right(lst_C, b) ans += na * nc print(ans)
p03557
import bisect n = int(eval(input())) lst_A = list(map(int, input().split())) lst_B = list(map(int, input().split())) lst_C = list(map(int, input().split())) lst_A.sort() lst_B.sort() lst_C.sort() ans = 0 for b in lst_B: na = bisect.bisect_left(lst_A, b) nc = n - bisect.bisect_right(lst_C, b) ans += na * nc print(ans)
from bisect import bisect_left, bisect_right n = int(eval(input())) lst_A = sorted(map(int, input().split())) lst_B = sorted(map(int, input().split())) lst_C = sorted(map(int, input().split())) ans = 0 for b in lst_B: na = bisect_left(lst_A, b) nc = n - bisect_right(lst_C, b) ans += na * nc 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()))) Clen = len(C) total = 0 for i in A: Bmin = bisect.bisect_right(B, i) for j in B[Bmin :]: total += Clen - bisect.bisect_right(C, j) print(total)
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()))) total = 0 for b in B: i = N - bisect.bisect_right(C, b) j = bisect.bisect_left(A, b) total += i * j print(total)
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() Bcon = [0] * N res = 0 p = 0 for n in range(N): while p <= N - 1 and B[n] > A[p]: p += 1 Bcon[n] = p p = 0 for n in range(N): while p <= N - 1 and C[n] > B[p]: p += 1 res += sum(Bcon[:p]) print(res)
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() Bcon = [0] * (N + 1) res = 0 p = 0 for n in range(N): while p <= N - 1 and B[n] > A[p]: p += 1 Bcon[n + 1] = p + Bcon[n] p = 0 for n in range(N): while p <= N - 1 and C[n] > B[p]: p += 1 res += Bcon[p] print(res)
p03557
from bisect import bisect from itertools import accumulate 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() ainb = [bisect(b, ea) for ea in a] bc = [n - bisect(c, eb) for eb in b] bcaccum = tuple(accumulate(bc)) tr = 0 for eainb in ainb: if eainb != 0: tr += bcaccum[eainb - 1] r = bcaccum[-1] * n - tr print(r) if __name__ == '__main__': main()
import sys read = sys.stdin.read #readlines = sys.stdin.readlines from bisect import bisect, bisect_left from itertools import accumulate def main(): data = list(map(int, read().split())) n = data[0] a = data[1:n + 1] b = data[n + 1: n * 2 + 1] c = data[n * 2 + 1:] a.sort() b.sort() c.sort() b2 = [bisect_left(a, be) for be in b] b2a = list(accumulate(b2)) b2a = [0] + b2a ans = sum([b2a[bisect_left(b, ce)] for ce in c]) print(ans) if __name__ == '__main__': main()
p03557
#ABC077C N=int(eval(input())) #大きい順に# 並べる A=sorted(list(map(int,input().split())), reverse=True) B=sorted(list(map(int,input().split())), reverse=True) C=sorted(list(map(int,input().split())), reverse=True) #あるBの下にいくつCが入るか数える C_under_B=[0]*N #i番目のBの下に入るCの数 for i in range(N): if i > 0: if B[i] == B[i-1]: C_under_B[i]=C_under_B[i-1] continue for j in range(N): if C[j]>B[i]: C_under_B[i]+=1 else: #C[j+1]>C[j]>B[i]なので検討を中止する break #あるAの下にいくつBが入るか数える B_under_A=[0]*N #i番目のBの下に入るCの数 for i in range(N): if i > 0: if A[i] == A[i-1]: B_under_A[i]=B_under_A[i-1] continue for j in range(N): if B[j]>A[i]: B_under_A[i]+=1 else: #B[j+1]>B[j]>A[i]なので検討を中止する break #あるAのもとに入るBのもとに入るCを数える C_under_B_under_A=[0]*N for i in range(N): C_under_B_under_A[i]=sum([C_under_B[j] for j in range(B_under_A[i])]) #出力 print((sum(C_under_B_under_A)))
#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()))) #あるBの下にいくつCが入るか数える C_under_B=[0]*N #i番目のBの下に入るCの数 for i in range(N): C_under_B[i]=N-bisect.bisect_right(C,B[i]) #あるBの上にいくつAが乗るか数える A_on_B=[0]*N #i番目のBの上に乗るAの数 for i in range(N): A_on_B[i]=bisect.bisect_left(A,B[i]) #あるBの上下におけるものを数えて出力 ans=0 for i in range(N): ans+=C_under_B[i]*A_on_B[i] 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() count = 0 for i in range(n): b = bisect.bisect(B,A[i]) for j in range(b,n): c = bisect.bisect(C,B[j]) count += n-c 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 range(n): a = bisect.bisect_left(A,B[i]) c = bisect.bisect_right(C,B[i]) count += a*(n-c) print(count)
p03557
import bisect n = int(eval(input())) al = sorted(list(map(int, input().split()))) bl = sorted(list(map(int, input().split()))) cl = sorted(list(map(int, input().split()))) a_len = len(al) b_len = len(bl) c_len = len(cl) ans = 0 for a in al: b_index = bisect.bisect_right(bl, a) if b_index >= b_len: break tmp_bl = bl[b_index:] for b in tmp_bl: c_index = bisect.bisect_right(cl, b) if c_index >= c_len: break ans += c_len - c_index # print(f'a:{a}, b_index:{b_index}, c_index:{c_index}, ans:{ans}') print(ans)
import bisect n = int(eval(input())) al = sorted(list(map(int, input().split()))) bl = sorted(list(map(int, input().split()))) cl = sorted(list(map(int, input().split()))) ans = 0 for b in bl: i = bisect.bisect_left(al, b) j = bisect.bisect_right(cl, b) ans += i*(n-j) print(ans)
p03557
# coding:UTF-8 import sys from math import factorial MOD = 10 ** 9 + 7 INF = 10000000000 def binary_search_section(list, min, max): low = 0 high = len(list) - 1 upper = len(list) lower = -1 while low <= high: mid = (low + high) // 2 guess = list[mid] if guess >= min: high = mid - 1 else: low = mid + 1 lower = mid low = 0 high = len(list) - 1 while low <= high: mid = (low + high) // 2 guess = list[mid] if guess > max: high = mid - 1 upper = mid else: low = mid + 1 return [lower, upper] def main(): # ------ 入力 ------# # 1行入力 n = int(eval(input())) # 数字 aList = list(map(int, input().split())) # スペース区切り連続数字 bList = list(map(int, input().split())) # スペース区切り連続数字 cList = list(map(int, input().split())) # スペース区切り連続数字 # ------ 処理 ------# aListSorted = sorted(aList) bListSorted = sorted(bList) cListSorted = sorted(cList) result = 0 for a in aListSorted: sec = binary_search_section(bListSorted, a+1, bListSorted[-1]) for j in range(sec[0]+1, len(bListSorted)): b = bListSorted[j] sec2 = binary_search_section(cListSorted, b+1, cListSorted[-1]) result += len(cListSorted) - (sec2[0] + 1) # ------ 出力 ------# print(("{}".format(result))) # if flg == 0: # print("YES") # else: # print("NO") if __name__ == '__main__': main()
# coding:UTF-8 import sys from math import factorial MOD = 10 ** 9 + 7 INF = 10000000000 def binary_search_section(list, min, max): low = 0 high = len(list) - 1 upper = len(list) lower = -1 while low <= high: mid = (low + high) // 2 guess = list[mid] if guess >= min: high = mid - 1 else: low = mid + 1 lower = mid low = 0 high = len(list) - 1 while low <= high: mid = (low + high) // 2 guess = list[mid] if guess > max: high = mid - 1 upper = mid else: low = mid + 1 return [lower, upper] def main(): # ------ 入力 ------# # 1行入力 n = int(eval(input())) # 数字 aList = list(map(int, input().split())) # スペース区切り連続数字 bList = list(map(int, input().split())) # スペース区切り連続数字 cList = list(map(int, input().split())) # スペース区切り連続数字 # ------ 処理 ------# aListSorted = sorted(aList) bListSorted = sorted(bList) cListSorted = sorted(cList) result = 0 # for a in aListSorted: # sec = binary_search_section(bListSorted, a+1, bListSorted[-1]) # for j in range(sec[0]+1, len(bListSorted)): # b = bListSorted[j] # sec2 = binary_search_section(cListSorted, b+1, cListSorted[-1]) # result += len(cListSorted) - (sec2[0] + 1) for b in bListSorted: sec = binary_search_section(aListSorted, aListSorted[0], b-1) sec2 = binary_search_section(cListSorted, b+1, cListSorted[-1]) result += (sec[1] - sec[0] - 1)*(sec2[1] - sec2[0] - 1) # ------ 出力 ------# print(("{}".format(result))) # if flg == 0: # print("YES") # else: # print("NO") if __name__ == '__main__': main()
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())) 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 = sorted(map(int, input().split())) B = sorted(map(int, input().split())) C = sorted(map(int, input().split())) ans = 0 for b in B: a_ind = bisect.bisect_left(A, b) c_ind = bisect.bisect_right(C, b) ans += a_ind*(n-c_ind) print(ans)
p03557
def main(): n = int(eval(input())) a = [int(s) for s in input().split()] b = [int(s) for s in input().split()] c = [int(s) for s in input().split()] print((solve(n, a, b, c))) def solve(n, a, b, c): d = [c, b, a] dp = [] dp.append([1 for _ in range(n)]) dp.append([0 for _ in range(n)]) dp.append([0 for _ in range(n)]) for i in range(1, 3): for j in range(n): dp[i][j] = sum(dp[i-1][k] for k in range(n) if d[i-1][k] > d[i][j]) return sum(dp[2]) def ilen(it): c = 0 for _ in it: c += 1 return c main()
import bisect def main(): n = int(eval(input())) a = sorted([int(s) for s in input().split()]) b = sorted([int(s) for s in input().split()]) c = sorted([int(s) for s in input().split()]) print((solve(n, a, b, c))) def solve(n, a, b, c): d = [c, b, a] dp = [] dp.append([n - i for i in range(n)]) dp.append([0 for _ in range(n)]) dp.append([0 for _ in range(n)]) for i in range(1, 3): for j in reversed(list(range(n))): k = bisect.bisect(d[i-1], d[i][j]) if k == n: continue dp[i][j] = dp[i-1][k] if j != n - 1: dp[i][j] += dp[i][j+1] return dp[2][0] def ilen(it): c = 0 for _ in it: c += 1 return c main()
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()))) """ minnum以上で最小の数のindexを返す。無いときはlen(List)を返す 計算量log(len(List)) def bts(List,minnum,under=0): if List[0]>=minnum: return under if List[-1]<minnum: return len(List)+under i = int(len(List)/2) if List[i]>=minnum and List[i-1]<minnum: return i + under if List[i]<minnum: return bts(List[i+1:],minnum,under+i+1) return bts(List[:i],minnum,under) """ def binary_search(list, item): if list[0]>=item: return 0 if list[-1]<item: return len(list) low = 0 high = len(list) - 1 while low <= high: mid = (low + high) //2 guess = list[mid] if guess >= item and list[mid-1] < item: return mid if guess >= item: high = mid -1 else: low = mid + 1 return None res = 0 for i in range(N): b = B[i] a = binary_search(A,b) c = N - binary_search(C,b+1) res += a*c print(res)
import bisect n=int(eval(input())) al=list(map(int,input().split())) bl=list(map(int,input().split())) cl=list(map(int,input().split())) al.sort() bl.sort() cl.sort() ans=0 for b in bl: ac=bisect.bisect_right(al,b-1) cc=n-bisect.bisect_left(cl,b+1) ans+=ac*cc 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()))) neo_b = [[] for _ in range(n)] ans = 0 for i in range(n): neo_b[i] = bisect.bisect_left(a,b[i]) for i in range(n): ans += sum(neo_b[:bisect.bisect_left(b,c[i])]) 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 range(n): ans += bisect.bisect_left(a,b[i])*(n-bisect.bisect_right(c,b[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())) ans = 0 for a in A: for b in B: for c in C: if a < b < c: ans += 1 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 n in range(N): i = bisect.bisect_left(A,B[n]) j = len(C) - bisect.bisect_right(C,B[n]) ans += i * j 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() bans = [] last = 0 for bi in range(n): bnow = b[bi] for ci in range(last,n): if c[ci] > bnow: bans.append([bnow,n-ci]) last = ci break else: bans.append([bnow,0]) bsun = 0 for bi in range(n): bsun += bans[n-1-bi][1] bans[n-1-bi].append(bsun) ans = 0 last = 0 for ai in range(n): anow = a[ai] for bi in range(last,n): if bans[bi][0] > anow: ans += bans[bi][2] last = bi break #print(bans) 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() bans = [] for bi in range(n): bnow = b[bi] here = bisect.bisect_right(c,bnow) bans.append([bnow,n-here]) bsun = 0 for bi in range(n): bsun += bans[n-1-bi][1] bans[n-1-bi].append(bsun) ans = 0 for ai in range(n): anow = a[ai] here = bisect.bisect_right(b,anow) if here != n: ans += bans[here][2] #print(bans) 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()))) def check_a(a_num, b_num): res = False if a_num < b_num: res = True return res def check_c(c_num, b_num): res = False if b_num < c_num: res = True return res ans = 0 cnt_a = 0 cnt_c = 0 for bi in range(len(b)): left = 0 right = len(a)-1 if check_a(a[0], b[bi]) is False: cnt_a = 0 elif check_a(a[-1], b[bi]) is True: cnt_a = len(a) else: while right-left > 1: mid = (left + right) // 2 if check_a(a[mid], b[bi]): left = mid else: right = mid cnt_a = left + 1 left = 0 right = len(c) - 1 if check_c(c[0], b[bi]) is True: cnt_c = len(c) elif check_c(c[-1], b[bi]) is False: cnt_c = 0 else: while right - left > 1: mid = (left + right) // 2 if check_c(c[mid], b[bi]): right = mid else: left = mid cnt_c = len(c) - right ans += cnt_a * cnt_c print(ans)
n = int(eval(input())) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) cnt = [0] * len(b) a = sorted(a) c = sorted(c) for i in range(len(b)): target = b[i] # decide a cnt l = 0 r = len(a) - 1 if a[l] >= target: cnt[i] += 0 elif a[r] < target: cnt[i] += len(a) else: while r - l > 1: mid = (l + r) // 2 if a[mid] >= target: r = mid else: l = mid cnt[i] += l + 1 # decide c cnt l = 0 r = len(c) - 1 if c[l] > target: cnt[i] *= len(c) elif c[r] <= target: cnt[i] *= 0 else: while r - l > 1: mid = (l + r) // 2 if c[mid] > target: r = mid else: l = mid cnt[i] *= len(c) - (l + 1) print((sum(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(" ")))) count = 0 for i in b: #print((a[:bisect.bisect(a, i - 1)]), i, c[bisect.bisect_left(c, i + 1):]) count += len(a[:bisect.bisect(a, i - 1):]) * len(a[bisect.bisect_right(c, i):]) print(count)
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(" ")))) count = 0 for i in b: #print((a[:bisect.bisect_right(a, i - 1)]), i, c[bisect.bisect_left(c, i + 1):]) #print(bisect.bisect_right(a, i - 1), i, (n - bisect.bisect_left(c, i + 1)) ) count += bisect.bisect_right(a, i - 1) * (n - bisect.bisect_left(c, i + 1)) print(count)
p03557
#!/usr/bin python3 # -*- coding: utf-8 -*- from bisect import bisect_left, bisect_right 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() ret = 0 for a in A: ib = bisect_right(B,a) for b in B[ib:]: ic = bisect_right(C,b) ret += N - ic print(ret) if __name__ == '__main__': main()
#!/usr/bin python3 # -*- coding: utf-8 -*- from bisect import bisect_left, bisect_right 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() ret = 0 for b in B: ia = bisect_left(A,b) ic = bisect_right(C,b) ret += ia*(N-ic) print(ret) if __name__ == '__main__': main()
p03557
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) counter = 0 for a in A: for b in B: if a < b: for c in C: if b < c: counter = counter + 1 else: pass else: pass print(counter)
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) C = sorted(C) counter = 0 for k in range(N): i = bisect.bisect_left(A, B[k]) j = N - bisect.bisect_right(C, B[k]) counter += i * j print(counter)
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()] a.sort() b.sort() b=b[::-1] c.sort() ans=tmp=0 for i in a: for j in b: if i>=j: break tmp=bisect.bisect_right(c, j) ans+=(n-tmp) print(ans)
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() b.sort() b=b[::-1] c.sort() ans=tmp=0 for i in b: x=bisect.bisect_left(a,i) y=bisect.bisect_right(c, i) ans+=x*(n-y) 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())) al=sorted(a) bl=sorted(b) cl=sorted(c) abl=[] i=0 for j in range(n): i=n-1 while al[i]>=bl[j]: i-=1 if i==-1: break if i==-1: abl.append(0) else: abl.append(i+1) bcl=[] j=0 for j in range(n): k=0 while cl[k]<=bl[j]: k+=1 if k==n: break if k==n: bcl.append(0) else: bcl.append(n-k) ans=0 for s in range(n): ans+=abl[s]*bcl[s] print(ans)
n=int(eval(input())) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) al=sorted(a) bl=sorted(b) cl=sorted(c) abl=[0]*n bcl=[0]*n i=n-1 for j in range(n-1,-1,-1): if i==-1: abl[j]=0 continue while al[i]>=bl[j]: i-=1 if i==-1: break if i==-1: abl[j]=0 else: abl[j]=i+1 j=0 bcl=[0]*n k=0 for j in range(n): if k==n: bcl[j]=0 continue while cl[k]<=bl[j]: k+=1 if k==n: break if k==n: bcl[j]=0 else: bcl[j]=(n-k) ans=0 for s in range(n): ans+=abl[s]*bcl[s] print(ans)
p03557
def main(): from bisect import bisect_left n, *abc = list(map(int, open(0).read().split())) a, b, c = abc[:n], abc[n:2 * n], abc[2 * n:] a, b, c = sorted(a), sorted(b), sorted(c) ans = 0 for i in c: j = bisect_left(b, i) for k in b[:j]: l = bisect_left(a, k) ans += l print(ans) if __name__ == '__main__': main()
def main(): from bisect import bisect_left, bisect_right n, *abc = list(map(int, open(0).read().split())) a, b, c = abc[:n], abc[n:2 * n], abc[2 * n:] a, b, c = sorted(a), sorted(b), sorted(c) ans = 0 for i in b: j = bisect_left(a, i) k = n - bisect_right(c, i) ans += j * k print(ans) if __name__ == '__main__': main()
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() AtoB=[0 for i in range(n)] BtoC=[0 for i in range(n+1)] for i in range(n): top=a[i] h=n l=-1 while h-l>1: mid=(h+l)//2 if b[mid]>top: h=mid else: l=mid if h==0 and top>b[0]: h=-1 AtoB[i]=h #smallestB-index for i in range(n-1,-1,-1): top=b[i] h=n l=-1 while h-l>1: mid=(h+l)//2 if c[mid]>top: h=mid else: l=mid BtoC[i]+=BtoC[i+1]+n-h #according to B,C patten ans=0 for i in range(n): ans+=BtoC[AtoB[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() ans=0 for i in range(n): middle=b[i] h=n l=-1 while h-l>1: m=(h+l)//2 if a[m]<middle: l=m else: h=m ab=l+1 h=n l=-1 while h-l>1: m=(h+l)//2 if c[m]>middle: h=m else: l=m bc=n-h ans+=ab*bc print(ans)
p03557
N = int(eval(input())) a = [] for i in range(3): a.append(list(map(int, input().split()))) for i in range(3): a[i].sort() dataa = [] datab = [] memo = 0 for i in range(N): flag = 0 for j in range(memo, N): if a[0][i] < a[1][j]: memo = j dataa.append(N - j) flag = 1 break if flag == 0: dataa.append(0) memo = 0 for i in range(N): flag = 0 for j in range(memo, N): if a[1][i] < a[2][j]: memo = j datab.append(N - j) flag = 1 break if flag == 0: datab.append(0) ruiseki = [] count = 0 for i in range(len(datab)-1, -1, -1): count += datab[i] ruiseki.append(count) count2 = 0 for i in range(len(dataa)): if dataa[i] != 0: count2 += ruiseki[dataa[i] - 1] print(count2)
N = int(eval(input())) a = [] for i in range(3): a.append(list(map(int, input().split()))) for i in range(3): a[i].sort() dataa = [] datab = [] memo = 0 #print(a) for i in range(N): flag = 0 for j in range(memo, N): #print(a[0][i], a[1][j]) if a[0][i] < a[1][j]: memo = j dataa.append(N - j) flag = 1 break if flag == 0: for j in range(N - i): dataa.append(0) break memo = 0 for i in range(N): flag = 0 for j in range(memo, N): if a[1][i] < a[2][j]: memo = j datab.append(N - j) flag = 1 break if flag == 0: for j in range(N - i): datab.append(0) break ruiseki = [] count = 0 for i in range(len(datab)-1, -1, -1): count += datab[i] ruiseki.append(count) count2 = 0 for i in range(len(dataa)): if dataa[i] != 0: count2 += ruiseki[dataa[i] - 1] print(count2)
p03557
import bisect num = int(eval(input())) top = sorted([int(x) for x in input().split()]) middle = sorted([int(x) for x in input().split()]) bottom = sorted([int(x) for x in input().split()]) res = 0 for i in top: index = bisect.bisect_right(middle, i) if index != len(middle): for j in middle[index:]: index2 = bisect.bisect_right(bottom, j) if index2 != len(bottom): res += len(bottom) - index2 print(res)
import bisect num = int(eval(input())) top = sorted([int(x) for x in input().split()]) middle = sorted([int(x) for x in input().split()]) bottom = sorted([int(x) for x in input().split()]) # middleの配列でループを回したほうが早い(topとbottomを同時に処理できるため) res = 0 for i in middle: index = bisect.bisect_left(top, i) index2 = len(bottom)-bisect.bisect_right(bottom, i) res += index*index2 print(res)
p03557
import bisect 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 for cc in c: b_res = bisect.bisect_left(b, cc) for bb in b[:b_res]: res += (bisect.bisect_left(a, bb)) print(res)
import bisect 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 for bb in b: b_res = bisect.bisect_left(a, bb) c_res = len(c) - bisect.bisect_right(c, bb) res += (b_res*c_res) print(res)
p03557
# C - Snuke Festival 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()) B.sort() C.sort() def binarySearch(a, b): l = -1 r = N while l+1<r: m = (l+r)//2 if a[m]<=b: l = m else: r = m return l+1 BC = [] for i in range(N): tmp = binarySearch(C, B[i]) BC.append((N - tmp)) BC = BC[::-1] BC2 = [0] * (N+1) for i in range(N): BC2[i+1] = BC2[i] + BC[i] BC2 = BC2[::-1] ans = 0 for i in range(N): b = binarySearch(B, A[i]) ans += BC2[b] print(ans)
# C - Snuke Festival 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.sort() C.sort() def binarySearchLeft(a, b): l = -1 r = N while l+1<r: m = (l+r)//2 if a[m]<b: l = m else: r = m return r def binarySearchRight(a, b): l = -1 r = N while l+1<r: m = (l+r)//2 if a[m]<=b: l = m else: r = m return r ans = 0 for j in range(N): ans += binarySearchLeft(A, B[j]) * (N - binarySearchRight(C, B[j])) print(ans)
p03557
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from bisect import bisect_left 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() result = 0 for c in C: index_c_b = bisect_left(B, c) for b in B[:index_c_b]: result += bisect_left(A, b) print(result) if __name__ == "__main__": main()
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from bisect import bisect_left, bisect_right 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() result = 0 for b in B: a = bisect_left(A, b) c = bisect_right(C, b) result += a * (N - c) print(result) if __name__ == "__main__": main()
p03557
n=int(eval(input())) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) ans=[] ans_2=[] for i in range(n): cnt=0 for j in range(n): if a[j]<b[i]: cnt+=1 ans.append(cnt) for i in range(n): cnt_2=0 for j in range(n): if b[i]<c[j]: cnt_2+=1 ans_2.append(cnt_2) num=0 for i in range(n): num+=ans[i]*ans_2[i] print(num)
n=int(eval(input())) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) import bisect a.sort() c.sort() cl=len(c) cnt=0 for i in b: x=bisect.bisect_left(a,i) y=bisect.bisect_right(c,i) cnt+=x*(cl-y) print(cnt)
p03557
n=int(eval(input())) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) import bisect a.sort() c.sort() cl=len(c) cnt=0 for i in b: x=bisect.bisect_left(a,i) y=bisect.bisect_right(c,i) cnt+=x*(cl-y) print(cnt)
n=int(eval(input())) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) import bisect a.sort() b.sort() c.sort() ans=0 for i in range(n): ans+=bisect.bisect_left(a,b[i])*(n-bisect.bisect_right(c,b[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())) import bisect a.sort() b.sort() c.sort() ans=0 for i in range(n): ans+=bisect.bisect_left(a,b[i])*(n-bisect.bisect_right(c,b[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())) import bisect ans=0 a.sort() b.sort() c.sort() for i in range(n): lift=bisect.bisect_left(a,b[i]) right=bisect.bisect_right(c,b[i]) right=n-right ans+=lift*right 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()))) import bisect ans = 0 for i in a: comb = 1 index = bisect.bisect_right(b,i) for j in b[index:]: ans += n-bisect.bisect_right(c,j) 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 cnt = [] for i in b: cnt.append(n-bisect.bisect_right(c,i)) cnt += [0] for i in range(n-1,-1,-1): cnt[i] += cnt[i+1] for i in a: ans += cnt[bisect.bisect_right(b,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.append(10 ** 10) B.append(10 ** 10) C.append(10 ** 10) A.sort() B.sort() C.sort() i, j, k = 0, 0, 0 count = 0 total = [] result = 0 while i < N: while C[i] > B[j] and j < N: while B[j] > A[k] and k < N: count += 1 k += 1 total.append(count) j += 1 result += sum(total) i += 1 print(result)
N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.append(10 ** 10) B.append(10 ** 10) C.append(10 ** 10) A.sort() B.sort() C.sort() i, j, k = 0, 0, 0 count = 0 total = 0 result = 0 while i < N: while C[i] > B[j] and j < N: while B[j] > A[k] and k < N: count += 1 k += 1 total += count j += 1 result += total i += 1 print(result)
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() def binsearch(threshold, lst): left, right = -1, len(lst) while right - left > 1: mid = (left + right) // 2 if lst[mid] > threshold: right = mid else: left = mid return right ans = 0 for a in A: b_min_index = binsearch(a, B) for i in range(b_min_index, N): c_min_index = binsearch(B[i], C) ans += N - c_min_index #print(a, B[b_min_index], C[c_min_index]) 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() def binsearch(threshold, lst): left, right = -1, len(lst) while right - left > 1: mid = (left + right) // 2 if lst[mid] > threshold: right = mid else: left = mid return right ans = 0 BtoC = [None] * N for i in range(0, N): BtoC[i] = N - binsearch(B[i], C) #print(BtoC) cumulative=[0] for i in range(N): cumulative.append(cumulative[i] + BtoC[N-i-1]) #print(cumulative) cumulative.reverse() #print(cumulative) for j in range(0, N): temp = binsearch(A[j], B) ans += cumulative[temp] 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())) t = 0 ans = 0 u =[0]*n d =[0]*n for i in range(n): for j in range(n): if b[i]>a[j]: t+=1 u[i]=t t=0 for i in range(n): for j in range(n): if b[i]<c[j]: t+=1 d[i]=t t=0 for i in range(n): ans+=u[i]*d[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())) t = 0 ans = 0 u =[0]*n d =[0]*n a2 =[] b2 =[] c2 =[] for i in range(n): a2.append([2,a[i]]) for i in range(n): b2.append([1,b[i]]) for i in range(n): c2.append([0,c[i]]) a2b2=a2+b2 b2c2=b2+c2 a2b2.sort(key = lambda x:(x[1],x[0])) b2c2.sort(key = lambda x:(x[1],x[0]),reverse=True) j=0 c=0 for i in range(2*n): if a2b2[i][0]==2: c+=1 if a2b2[i][0]==1: u[j]=c j+=1 j=0 c=0 for i in range(2*n): if b2c2[i][0]==0: c+=1 if b2c2[i][0]==1: d[j]=c j+=1 d.reverse() for i in range(n): ans+=u[i]*d[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())) t = 0 ans = 0 u =[0]*n d =[0]*n a2 =[] b2 =[] c2 =[] for i in range(n): a2.append([2,a[i]]) for i in range(n): b2.append([1,b[i]]) for i in range(n): c2.append([0,c[i]]) a2b2=a2+b2 b2c2=b2+c2 a2b2.sort(key = lambda x:(x[1],x[0])) b2c2.sort(key = lambda x:(x[1],x[0]),reverse=True) j=0 c=0 for i in range(2*n): if a2b2[i][0]==2: c+=1 if a2b2[i][0]==1: u[j]=c j+=1 j=0 c=0 for i in range(2*n): if b2c2[i][0]==0: c+=1 if b2c2[i][0]==1: d[j]=c j+=1 d.reverse() for i in range(n): ans+=u[i]*d[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() def n_smaller_a(num): if num>a[n-1]: return n if num<=a[0]: return 0 left=0 right=n-1 mid=(left+right)//2 while right-left>1: if a[mid]>=num: right=mid else: left=mid mid=(left+right)//2 if a[left]==num: return left else: return left+1 def n_bigger_c(num): if num >= c[n-1]: return 0 if num < c[0]: return n left=0 right=n-1 mid=(left+right)//2 while right-left>1: if c[mid]>num: right=mid else: left=mid mid=(left+right)//2 if c[right]==num: return n-right-1 else: return n-right ans = 0 for i in range(n): ans+=n_bigger_c(b[i])*n_smaller_a(b[i]) print(ans)
p03557
n = int(eval(input())) al = list(map(int, input().split())) bl = list(map(int, input().split())) cl = list(map(int, input().split())) al = sorted(al) bl = sorted(bl) cl = sorted(cl) total = 0 for alnum in al: truebl = [blnum for blnum in bl if blnum > alnum] for blnum in truebl: total += sum(clnum>blnum for clnum in cl) print(total)
# C import bisect n = int(eval(input())) al = list(map(int, input().split())) bl = list(map(int, input().split())) cl = list(map(int, input().split())) al = sorted(al) bl = sorted(bl) cl = sorted(cl) total = 0 for blnum in bl: alcnt = bisect.bisect_left(al, blnum) clcnt = n - bisect.bisect_right(cl, blnum) total += alcnt*clcnt print(total)
p03557
from bisect import bisect_right,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()))) ans=0 for i in range(n): na=bisect_left(a,b[i]) nc=bisect_right(c,b[i]) ans+=na*(n-nc) print(ans)
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() ans=0 for i in range(n): indea=bisect_left(a,b[i]) indec=bisect_right(c,b[i]) ans+=indea*(n-indec) 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 a in A: b = bisect.bisect_left(B,a+1) if b == N: continue for i in range(b,N): c = bisect.bisect_left(C,B[i]+1) if c == N: continue count += N-c 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: a = bisect.bisect_left(A,b) c = bisect.bisect_right(C,b) count += a*(N-c) print(count)
p03557
import bisect as bi def main(): from builtins import input, int, map 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): a = bi.bisect_left(A,B[i]) c = len(C[bi.bisect_right(C,B[i]):]) ans += a*c print(ans) main()
import bisect as bi def main(): from builtins import input, int, map 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): a = bi.bisect_left(A,B[i]) c = N-bi.bisect_right(C,B[i]) ans += a*c print(ans) main()
p03557
def low_left(ls,key): left,right = -1,len(ls) while right - left > 1: mid = (right+left)//2 if ls[mid] >= key: right = mid else: left = mid return len(ls[:(left+1)]) def high_right(ls,key): left,right = -1,len(ls) while right - left > 1: mid = (right+left)//2 if ls[mid]<=key: left = mid else: right = mid return len(ls[right:]) def test(): n = int(eval(input())) A,B,C = [list(sorted(map(int,input().split()))) for i in range(3)] ans = 0 for b in B: ans += high_right(C,b)*low_left(A,b) print(ans) if __name__ == "__main__": test()
def low_left(ls,key): left,right = -1,len(ls) while right - left > 1: mid = (right+left)//2 if ls[mid] >= key: right = mid else: left = mid return left+1 def high_right(ls,key): left,right = -1,len(ls) while right - left > 1: mid = (right+left)//2 if ls[mid]<=key: left = mid else: right = mid return right def test(): n = int(eval(input())) A,B,C = [list(sorted((list(map(int,input().split()))))) for i in range(3)] ans = 0 for b in B: ans += (n-high_right(C,b))*low_left(A,b) print(ans) if __name__ == "__main__": test()
p03557
from bisect import bisect_right N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) B.sort() C.sort() ans = 0 for a in A: b_index = bisect_right(B, a) if b_index == len(B): continue b_cnt = len(B)-b_index for b in B[b_index:]: c_index = bisect_right(C, b) if c_index == len(C): continue c_cnt = len(C)-c_index ans += c_cnt 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 range(N): a_cnt = bisect.bisect_left(A, B[i]) c_cnt = N-bisect.bisect_right(C, B[i]) ans += a_cnt*c_cnt print(ans)
p03557
import bisect import itertools n = int(eval(input())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) count = 0 #for i in range(n): #for s in range(bisect.bisect_right(b, a[i]),n): #count += n-bisect.bisect_right(c, b[s]) for i in itertools.product(a, b, c): if i[0] < i[1] < i[2]: count += 1 print(count)
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 i in b: q=bisect.bisect_left(a,i) s=bisect.bisect_right(c,i) ans=ans+q*(n-s) print(ans)
p03557
#!/usr/bin/env python3 #ABC77 C 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 a: s = 0 x = bisect.bisect_right(b,i) for j in b[x:]: y = bisect.bisect_right(c,j) ans += n-y print(ans)
#!/usr/bin/env python3 #ABC77 C 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 b: x = bisect.bisect_left(a,i) y = bisect.bisect_right(c,i) ans += x*(n-y) print(ans)
p03557
import sys from bisect import bisect_right, bisect_left from functools import reduce readline = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 def lcm_base(x, y): return (x * y) // gcd(x, y) def lcm_list(numbers): return reduce(lcm_base, numbers, 1) 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 = 0 for i in range(N): top = bisect_left(A, B[i]) bottom = bisect_right(C, B[i]) if top>0 and bottom != N: ans += top*(N-bottom) print(ans) if __name__ == '__main__': main()
import sys read = sys.stdin.read readline = sys.stdin.buffer.readline from bisect import bisect_right, bisect_left sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 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 = 0 for b in B: a = bisect_left(A, b) c = bisect_right(C, b) ans += a*(N-c) print(ans) if __name__ == '__main__': main()
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() B += [10 ** 9 + 1] + [0] # B[-1] = 0, B[N] = 10**9 + 1となるようにする C += [10 ** 9 + 1] + [0] # C[-1] = 0, C[N] = 10**9 + 1となるようにする # For each j = 0, 1, ..., N-1, # find k such that B[j] < C[k] and (C[k-1] <= B[j] or k = 0) # Let K[j] = k for such k. # If such k doesn't exist, let K[j] := N K = [0] * N for j in range(N): ng = -1 # C[ng] <= B[j] ok = N # B[j] < C[ok] while ok - ng > 1: mid = (ok + ng) // 2 if B[j] < C[mid]: ok = mid else: ng = mid K[j] = ok # Let # f[j] := B[j]より大きいC[k]の数 + B[j + 1]より大きいC[k]の数 # ... + B[N-1]より大きいC[k]の数 f = [0] * (N - 1) + [N - K[N - 1]] for j in range(N - 2, -1, -1): f[j] = f[j + 1] + N - K[j] ans = 0 for i in range(N): # find j such that B[j - 1] <= A[i] < B[j] ng = -1 # B[ng] <= A[i] ok = N # A[i] < B[ok] while ok - ng > 1: mid = (ok + ng) // 2 if A[i] < B[mid]: ok = mid else: ng = mid if ok >= N: continue # 0 <= ok <= N - 1 ans += f[ok] print(ans)
import bisect 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 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
import bisect def main(): n = int(eval(input())) a_list = list(map(int, input().split())) b_list = list(map(int, input().split())) c_list = list(map(int, input().split())) ans = 0 b_list.sort() c_list.sort() for i in range(n): tob_insert_num = a_list[i] tob_insert_index = bisect.bisect_right(b_list, tob_insert_num) for j in range(tob_insert_index,n): toc_insert_num = b_list[j] toc_insert_index = bisect.bisect_right(c_list, toc_insert_num) ans += n - toc_insert_index print(ans) if __name__ == '__main__': main()
import bisect def main(): n = int(eval(input())) a_list = list(map(int, input().split())) b_list = list(map(int, input().split())) c_list = list(map(int, input().split())) ans = 0 a_list.sort() c_list.sort() for i in range(n): toa_insert_index = bisect.bisect_left(a_list, b_list[i]) toc_insert_index = bisect.bisect_right(c_list, b_list[i]) ans += toa_insert_index * ( n - toc_insert_index ) print(ans) if __name__ == '__main__': main()
p03557
# -*- coding: utf-8 -*- import math def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) def permutations_count(n, r): return math.factorial(n) // math.factorial(n - r) N = int(eval(input())) An = list(map(int, input().split())) Bn = list(map(int, input().split())) Cn = list(map(int, input().split())) An.sort() Bn.sort() Cn.sort() # # print(An) # print(Bn) # print(Cn) #B B_cnt = [] j = 0 for i in range(N): while j < N: if Bn[i] < Cn[j]: B_cnt.append(N - j) break else: j += 1 # print(B_cnt) A_cnt = 0 j = 0 for i in range(N): while j < N: if An[i] < Bn[j]: for cnt in B_cnt[j:]: A_cnt += cnt break else: j += 1 print(A_cnt)
# -*- coding: utf-8 -*- import math def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) def permutations_count(n, r): return math.factorial(n) // math.factorial(n - r) N = int(eval(input())) An = list(map(int, input().split())) Bn = list(map(int, input().split())) Cn = list(map(int, input().split())) An.sort() Bn.sort() Cn.sort() # print(An) # print(Bn) # print(Cn) # B C_cnt = [] C_sum = 0 j = 0 for i in range(N): while j < N: if Bn[i] < Cn[j]: C_cnt.append(N - j) C_sum += N - j break else: j += 1 B_cnt = [] temp_sum = 0 for cnt in C_cnt: B_cnt.append(C_sum - temp_sum) temp_sum += cnt A_cnt = 0 j = 0 for i in range(N): while j < N: if An[i] < Bn[j]: if j < len(B_cnt): A_cnt += B_cnt[j] break else: j += 1 # print(C_cnt) # print(B_cnt) print(A_cnt)
p03557
import sys input=sys.stdin.readline #from collections import defaultdict #d = defaultdict(int) #import fractions #import math #import collections #from collections import deque #from bisect import bisect_left #from bisect import insort_left #N = int(input()) #A = list(map(int,input().split())) #S = list(input()) #S.remove("\n") #N,M = map(int,input().split()) #S,T = map(str,input().split()) #A = [int(input()) for _ in range(N)] #S = [input() for _ in range(N)] #A = [list(map(int,input().split())) for _ in range(N)] #import itertools #import heapq 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() from bisect import bisect_left ans = 0 for i in range(N): a = A[i] indb = bisect_left(B,a+1) if indb == N: continue for j in range(indb,N): b = B[j] indc = bisect_left(C,b+1) ans += N-indc print(ans)
import sys input=sys.stdin.readline #from collections import defaultdict #d = defaultdict(int) #import fractions #import math #import collections #from collections import deque #from bisect import bisect_left #from bisect import insort_left #N = int(input()) #A = list(map(int,input().split())) #S = list(input()) #S.remove("\n") #N,M = map(int,input().split()) #S,T = map(str,input().split()) #A = [int(input()) for _ in range(N)] #S = [input() for _ in range(N)] #A = [list(map(int,input().split())) for _ in range(N)] #import itertools #import heapq 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() from bisect import bisect_left ans = 0 for i in range(N): b = B[i] inda = bisect_left(A,b) indc = bisect_left(C,b+1) ans += (N-indc)*inda 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(" "))) m = 0 A.sort() B.sort() C.sort(reverse=True) for j in B: for i in range(N): if A[i] >= j: break if A[N-1] < j: i = N for k in range(N): if j >= C[k]: break if j < C[N-1]: k = N m = m + i * k print(m)
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() C.reverse() ans = 0 ai = 0 ci = N-1 for b in B: while ai < N and A[ai] < b: ai += 1 while ci >= 0 and C[ci] <= b: ci -= 1 ans += ai * (ci+1) print(ans)
p03557
import bisect N=int(eval(input())) alist=list(map(int,input().split())) blist=list(map(int,input().split())) clist=list(map(int,input().split())) alist.sort() blist.sort() clist.sort() answer=0 for bi in range(N): ai=bisect.bisect_left(alist,blist[bi]) ci=bisect.bisect(clist,blist[bi]) #print(ai,bi,ci) answer+=ai*(N-ci) print(answer)
import bisect N=int(eval(input())) alist=list(map(int,input().split())) blist=list(map(int,input().split())) clist=list(map(int,input().split())) alist.sort() blist.sort() clist.sort() answer=0 ai,ci=0,0 for bi in range(N): while(ai<N and alist[ai]<blist[bi]): ai+=1 while(ci<N and blist[bi]>=clist[ci]): ci+=1 #print(ai,bi,ci) answer+=ai*(N-ci) print(answer)
p03557
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()] A2=sorted(A) B2=sorted(B) C2=sorted(C) ans = 0 sum = 0 t =0 b = 0 for i in range(N): a = A2[i] low = 0 high = N-1 while True: t = (low + high) // 2 if B2[t] <= a: if t == N-1: b = False break elif B2[t] <= a <B2[t+1]: b = B2[t+1] t = t + 1 break else: low = t+1 continue elif B2[t] > a: if t == 0: b = B2[0] break elif B2[t] > a >= B2[t-1]: b = B2[t] break else: high = t - 1 continue if b != False: for j in range(t,N): b = B2[j] low = 0 high = N - 1 while True: #print(a, b) t = (low + high) // 2 if C2[t] <= b: if t == N-1: ans = 0 break elif C2[t] <= b < C2[t + 1]: c = C2[t + 1] ans = N - t - 1 break else: low = t + 1 continue elif C2[t] > b: if t == 0: ans = N break elif C2[t] > b >= C2[t - 1]: c = C2[t] ans = N - t break else: high = t - 1 continue #print("ans={}".format(ans)) sum += ans print(sum)
N = int(eval(input())) A = list(int(i) for i in input().split()) B = list(int(i) for i in input().split()) C = list(int(i) for i in input().split()) A.sort() B.sort() C.sort() sum = 0 for j in range(N): low = low2 = 0 high = high2 = N b = B[j] mid = mid2 = 0 #print(b) while(high>low): mid = (high + low)//2 if b > A[mid]: low = mid +1 else: high = mid acount = low while (high2>low2): mid2 = (high2 + low2)//2 if b < C[mid2]: high2 = mid2 else: low2 = mid2 + 1 ccount=N-low2 sum += acount*ccount print(sum)
p03557
import bisect as bis 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 range(n): top = a[i] for j in range(n): mid = b[j] if top >= mid: continue k = bis.bisect_right(c, mid) ans += n - k print(ans)
import bisect as bis 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_e in b: n_top = bis.bisect_left(a, b_e) n_bottom = n - bis.bisect_right(c, b_e) ans += n_top * n_bottom print(ans)
p03557
#!/usr/bin/env python3 def main(): from bisect import bisect 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()]) lst = [N - bisect(C, b) for b in B] ans = 0 for a in A: ans += sum(lst[bisect(B, a):]) print(ans) if __name__ == '__main__': main()
#!/usr/bin/env python3 def main(): from bisect import bisect 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()]) lst = [N - bisect(C, b) for b in B] lst = lst[::-1] tmp_lst = [lst[0]] for i in lst[1:]: tmp_lst.append(i + tmp_lst[-1]) tmp_lst = tmp_lst[::-1] ans = 0 for a in A: res = bisect(B, a) ans += tmp_lst[res] if res < N else 0 print(ans) if __name__ == '__main__': main()
p03557
#!/usr/bin/env python3 def main(): from bisect import bisect 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()]) lst = [N - bisect(C, b) for b in B] lst = lst[::-1] tmp_lst = [lst[0]] for i in lst[1:]: tmp_lst.append(i + tmp_lst[-1]) tmp_lst = tmp_lst[::-1] ans = 0 for a in A: res = bisect(B, a) ans += tmp_lst[res] if res < N else 0 print(ans) if __name__ == '__main__': main()
#!/usr/bin/env python3 def main(): from bisect import bisect, bisect_left 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()]) print((sum([bisect_left(A, b) * (N - bisect(C, b)) for b in B]))) if __name__ == '__main__': main()
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) # C.append(-1) a_count = [0 for i in range(N)] b_count = [0 for i in range(N)] # i, j = 0, 0 # while i < N: # if B[i] >= C[j]: # b_count[i] = j # i += 1 # else: # j += 1 for i in range(N): for j in range(N): if B[i] < C[j]: b_count[i] += 1 for i in range(N): for j in range(N): if A[i] < B[j]: a_count[i] += b_count[j] print((sum(a_count)))
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) c_cnt = [1 for i in range(N)] def count(A, B, b_cnt): B.append(-1) a_cnt = [0 for i in range(N)] i, j = 0, 0 while i < N: if A[i] < B[j]: a_cnt[i] += b_cnt[j] j += 1 else: i += 1 if 1 <= i < N: a_cnt[i] = a_cnt[i-1] return a_cnt b_cnt = count(B, C, c_cnt) a_cnt = count(A, B, b_cnt) print((sum(a_cnt)))
p03557
from bisect import bisect_right 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())) ans = 0 A.sort() B.sort() C.sort() for i in range(N): a = A[i] bb = bisect_right(B, a) if bb == N + 1: continue for j in range(bb, N): b = B[j] cc = bisect_right(C, b) if cc == N + 1: continue ans += (N - cc) print(ans)
from bisect import bisect_right, bisect_left 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())) A.sort() B.sort() C.sort() ans = 0 for j in range(N): b = B[j] i = bisect_left(A, b) k = bisect_right(C, b) ans += i * (N - k) print(ans)
p03557
import bisect eval(input()) A=[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()]) ans=0 for a in A: for b in B[bisect.bisect_right(B,a):]: ans+=len(C[bisect.bisect_right(C,b):]) print(ans)
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()]) ans=0 for b in B: ans+=bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b)) print(ans)
p03557
# -*- coding: utf-8 -*- # AtCoder Beginner Contest # Problem C if __name__ == '__main__': n = int(eval(input())) a = sorted(list(map(int, input().split()))) b = list(map(int, input().split())) c = sorted(list(map(int, input().split()))) count = 0 # See: # https://img.atcoder.jp/arc084/editorial.pdf # https://docs.python.jp/3/library/bisect.html from bisect import bisect_left from bisect import bisect_right for number in b: high = bisect_left(a, number) low = bisect_right(c, number) count += len(a[:high]) * len(c[low:]) print(count)
# -*- coding: utf-8 -*- # AtCoder Beginner Contest # Problem C if __name__ == '__main__': n = int(eval(input())) a = sorted(list(map(int, input().split()))) b = list(map(int, input().split())) c = sorted(list(map(int, input().split()))) count = 0 # See: # https://img.atcoder.jp/arc084/editorial.pdf # https://docs.python.jp/3/library/bisect.html # https://beta.atcoder.jp/contests/abc077/submissions/1740764 from bisect import bisect_left from bisect import bisect_right for number in b: a_count = bisect_left(a, number) c_count = n - bisect_right(c, number) count += a_count * c_count print(count)
p03557
# -*- coding: utf-8 -*- def main(): from bisect import bisect_left from bisect import bisect_right 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 bi in b: less = bisect_left(a, bi) greater = n - bisect_right(c, bi) ans += less * greater print(ans) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- def main(): from bisect import bisect_left from bisect import bisect_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 bi in b: less = bisect_left(a, bi) greater = n - bisect_right(c, bi) ans += less * greater print(ans) if __name__ == '__main__': main()
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()))) A_B = [] B_C = [] total = 0 for a in A: k = bisect.bisect_right(B, a) l = N - k A_B.append(l) for b in B: k = bisect.bisect_right(C, b) l = N - k B_C.append(l) for n in range(N): total += sum(B_C[N-A_B[n]:]) print(total)
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()))) A_B = [] B_C = [] total = 0 for b in B: k = bisect.bisect_left(A,b) l = bisect.bisect_right(C,b) total += k * (N-l) print(total)
p03557
#!/usr/bin/python # AtCoder Beginner Contest 077 # C - Snuke Festival from sys import stdin def solve(As, Bs, Cs): # Bs :: [(b, # of bottom parts > b)] Bs = [(b, sum([1 for c in Cs if c > b])) for b in Bs] # As :: [# of mid & bottom parts > a] As = [sum([b[1] for b in Bs if b[0] > a]) for a in As] return sum(As) N = int(stdin.readline()) As = [int(w) for w in stdin.readline().split()] Bs = [int(w) for w in stdin.readline().split()] Cs = [int(w) for w in stdin.readline().split()] if len(As) != N or len(Bs) != N or len(Cs) != N: raise print((solve(As, Bs, Cs)))
#!/usr/bin/python # AtCoder Beginner Contest 077 # C - Snuke Festival from sys import stdin def solve(As, Bs, Cs): As.sort() Bs.sort() Cs.sort() # Bs :: [(b, # of bottom parts > b)] # Bs = [(b, sum([1 for c in Cs if c > b])) for b in Bs] j = 0 for i in range(len(Bs)): while j < len(Cs) and Bs[i] >= Cs[j]: j += 1 Bs[i] = (Bs[i], len(Cs) - j) # Accumulate Bs[][1] for i in range(len(Bs) - 1, 0, -1): Bs[i-1] = (Bs[i-1][0], Bs[i-1][1] + Bs[i][1]) # As :: [# of mid & bottom parts > a] # As = [sum([b[1] for b in Bs if b[0] > a]) for a in As] j = 0 for i in range(len(As)): while j < len(Bs) and As[i] >= Bs[j][0]: j += 1 As[i] = Bs[j][1] if j < len(Bs) else 0 return sum(As) N = int(stdin.readline()) # <= 1e+5 As = [int(w) for w in stdin.readline().split()] Bs = [int(w) for w in stdin.readline().split()] Cs = [int(w) for w in stdin.readline().split()] if len(As) != N or len(Bs) != N or len(Cs) != N: raise print((solve(As, Bs, Cs)))
p03557
import bisect import sys def input(): return sys.stdin.readline().strip() def I(): return int(eval(input())) def LI(): return list(map(int, input().split())) def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def S(): return eval(input()) def LS(): return input().split() def main(): n = I() a = LI() b = LI() c = LI() a.sort() b.sort() c.sort() ans = 0 for bi in b: a_ind = bisect.bisect_left(a, bi) a_oks = a[:a_ind] c_ind = bisect.bisect_right(c, bi) c_oks = c[c_ind:] ans += len(a_oks) * len(c_oks) print(ans) main()
import bisect import sys def input(): return sys.stdin.readline().strip() def I(): return int(eval(input())) def LI(): return list(map(int, input().split())) def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def S(): return eval(input()) def LS(): return input().split() def main(): n = I() a = LI() b = LI() c = LI() a.sort() b.sort() c.sort() ans = 0 for bi in b: num_a = bisect.bisect_left(a, bi) num_c = n - bisect.bisect_right(c, bi) ans += num_a * num_c print(ans) main()
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 i in range(N): up = A[i] middleIndex = bisect.bisect(B, up) if middleIndex < N: for j in range(middleIndex, N): middle = B[j] lowIndex = bisect.bisect(C, middle) if lowIndex < N: cnt = N - lowIndex ans += cnt print(ans)
import bisect import itertools 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 dp = [0] * N for i in range(N): up = A[i] middleIndex = bisect.bisect(B, up) if middleIndex < N: if i == 0: for j in range(middleIndex, N): middle = B[j] lowIndex = bisect.bisect(C, middle) if lowIndex < N: cnt = N - lowIndex dp[j] = cnt ans += cnt else: dp[j] = 0 dp = list(itertools.accumulate(dp[::-1])) else: ans += dp[-middleIndex-1] print(ans)
p03557
N = int(eval(input())) A = list(map(int, input().split())) #A = [int(x) for x in input().split()] B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort() A = [-float('inf')] + A + [float('inf')] B.sort() C.sort() C = [-float('inf')] + C + [float('inf')] total = 0 for i in range(N): low = 0 high = N + 1 while low + 1 < high: mid1 = (low + high) // 2 if A[mid1] < B[i]: low = mid1 else: high = mid1 mid1 = low low = 0 high = N + 1 while low + 1 < high: mid2 = (low + high) // 2 if C[mid2] <= B[i]: low = mid2 else: high = mid2 mid2 = high total = total + mid1 * (N + 1 - mid2) print(total)
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: ans += bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b)) 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() total = 0 for i in range(N): low1 = 0 high = N while low1 < high: mid = (low1 + high) // 2 if A[mid] < B[i]: low1 = mid + 1 else: high = mid low2 = 0 high = N while low2 < high: mid = (low2 + high) // 2 if C[mid] <= B[i]: low2 = mid + 1 else: high = mid total += low1 * (N - low2) print(total)
N = int(eval(input())) A = sorted([int(i) for i in input().split()]) B = [int(i) for i in input().split()] C = sorted([int(i)-1 for i in input().split()]) def bis(x,y): low = 0 high = N while low < high: mid = (low + high) // 2 if x[mid] < y: low = mid + 1 else: high = mid return low total = 0 for b in B: total += bis(A,b) * (N - bis(C,b)) print(total)
p03557
import bisect def find_ge(a, x): i = bisect.bisect_right(a,x) return i def solve(n, a, b, c): b_count = [0]*len(b) for i, x in enumerate(b): b_count[i] = len(c) - find_ge(c, x) ans = 0 for i in a: x = find_ge(b, i) ans += sum(b_count[x:]) return ans if __name__ == "__main__": 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()]) print((solve(n, a, b, c)))
import bisect import itertools def find_ge(a, x): i = bisect.bisect_right(a,x) return i def solve(n, a, b, c): tmp = len(c) b_count =list(itertools.accumulate([tmp - find_ge(c, x) for x in b])) ans = 0 for i in a: min_index = find_ge(b, i) ans += b_count[-1] -(0 if min_index == 0 else b_count[min_index-1]) return ans if __name__ == "__main__": 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()]) print((solve(n, a, b, c)))
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()))) BDP = [-1] * N ans = 0 for a in A: b_idx = bisect.bisect_right(B, a) for i in range(b_idx,N): if BDP[i] == -1: c_idx = bisect.bisect_right(C, B[i]) BDP[i] = N - c_idx ans += BDP[i] 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: ans += bisect.bisect_left(A, b) * (N - bisect.bisect_right(C, b)) print(ans)
p03557
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()]) count = 0 for mid in b: upper_count = len(list([x for x in a if x<mid])) lower_count = len(list([x for x in c if x>mid])) count += upper_count * lower_count print(count)
import bisect n = int(eval(input())) a = sorted(list([int(x) for x in input().split()])) b = sorted(list([int(x) for x in input().split()])) c = sorted(list([int(x) for x in input().split()])) count = 0 for mid in b: upper_count = bisect.bisect_left(a,mid) lower_count = len(c) - bisect.bisect_right(c,mid) count += upper_count * lower_count print(count)
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())) b.sort() c.sort() ans = 0 for i in range(n): pos = 0 for j in range(bisect.bisect_right(b,a[i]),n): while (pos < n and c[pos] <= b[j]): pos += 1 ans += n-pos 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 range(n): ans += bisect.bisect_left(a,b[i])*(n-bisect.bisect_right(c,b[i])) 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: x, y = 0, 0 for j in A: if j < i: x += 1 else: break for j in reversed(C): if i < j: y += 1 else: break 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: 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())) b.append(0) c.append(0) a.sort() b.sort() c.sort() def isok(na , index , key): if na[index] >= key: return True else: return False def bs(nar,key): left = -1 right = len(nar) while (right - left) > 1: mid = left + (right - left) // 2 if isok(nar , mid , key): right = mid else: left = mid return right ans = 0 for i in a: q = bs(b,i+1) d = b[q:] for j in d: r = bs(c,j+1) f = c[r:] ans += len(f) 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() def isok(na , index , key): if na[index] >= key: return True else: return False def bs(nar,key): left = -1 right = len(nar) while (right - left) > 1: mid = left + (right - left) // 2 if isok(nar , mid , key): right = mid else: left = mid return right ans = 0 for i in b: q = bs(a,i) r = bs(c,i+1) ans += q*(n-r) print(ans)
p03557
import sys def input(): return sys.stdin.readline().rstrip() def main(): 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 b in B: sum_v = 1 l = -1 r = N while r - l > 1: m = (l + r) // 2 if b > A[m]: l = m else: r = m sum_v *= l + 1 l = -1 r = N while r - l > 1: m = (l + r) // 2 if b < C[m]: r = m else: l = m sum_v *= N - r ans += sum_v print(ans) if __name__ == '__main__': main()
import sys import bisect def input(): return sys.stdin.readline().rstrip() def main(): 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 b in B: ans += bisect.bisect_left(A, b) * (N - bisect.bisect_right(C, b)) print(ans) if __name__ == '__main__': main()
p03557
n = int(eval(input())) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) num = 0 for i in range(n): for j in range(n): for k in range(n): if a[i] < b[j] < c[k]: num += 1 print(num)
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()))) #print(a,b,c) cnt = 0 for i in range(n): d = bisect.bisect_left(a,b[i]) e = bisect.bisect_right(c,b[i]) cnt += d*(n-e) print(cnt)
p03557
import sys import collections # import math # import string # import bisect def main(): n, *parts = (int(x) for x in sys.stdin.read().split()) uppers, middles, lowers = (parts[n*i:n*(i+1)] for i in range(3)) count = 0 for a, ca in list(collections.Counter(uppers).items()): for b, cb in list(collections.Counter((b for b in middles if b > a)).items()): count += ca * cb * len([c for c in lowers if c > b]) print(count) if __name__ == "__main__": main()
import sys # import collections # import math # import string import bisect def main(): n, *parts = (int(x) for x in sys.stdin.read().split()) uppers, middles, lowers = (parts[n*i:n*(i+1)] for i in range(3)) uppers.sort() lowers.sort() count = 0 for j in middles: i = bisect.bisect_left(uppers, j) k = len(lowers) - bisect.bisect_right(lowers, j) count += i * k print(count) if __name__ == "__main__": main()
p03557
import sys from bisect import bisect_left as bi_l, bisect_right as bi_r n = int(sys.stdin.readline().rstrip()) *a, = list(map(int, sys.stdin.readline().split())) *b, = list(map(int, sys.stdin.readline().split())) *c, = list(map(int, sys.stdin.readline().split())) def main(): a.sort() b.sort() c.sort() res = 0 for i in b: cnt_a = bi_l(a, i) cnt_c = n - bi_r(c, i) res += cnt_a * cnt_c return res if __name__ == '__main__': ans = main() print(ans)
import sys from bisect import bisect_left as bi_l, bisect_right as bi_r n = int(sys.stdin.readline().rstrip()) a = sorted(map(int, sys.stdin.readline().split())) b = sorted(map(int, sys.stdin.readline().split())) c = sorted(map(int, sys.stdin.readline().split())) def main(): combs = 0 for x in b: combs += bi_l(a, x) * (n - bi_r(c, x)) print(combs) if __name__ == '__main__': main()
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=[0]*N E=[0]*N for i in range(N): D[i]=N-bisect.bisect_right(C,B[i]) for i in range(N): E[i]=sum(D[bisect.bisect_right(B,A[i]):]) print((sum(E)))
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 range(N): ans+=(bisect.bisect_left(A,B[i]))*(N-bisect.bisect_right(C,B[i])) 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()))) second = [] third = [] ans = 0 for i in range(N): second.append(N - bisect.bisect_right(B,A[i])) third.append(N - bisect.bisect_right(C,B[i])) for i in range(0,N): if second[i] == 0: continue ans += sum(third[-second[i]:]) 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 range(N): ans += bisect.bisect_left(A,B[i]) * (N - bisect.bisect_right(C,B[i])) print(ans)
p03557
from bisect import * 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 range(n): for j in range(bisect_right(b,a[i]),n): ans+=n-bisect_right(c,b[j]) print(ans)
from bisect import * 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 range(n): x=bisect_left(a,b[i]) y=n-bisect_right(c,b[i]) ans+=x*y 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())) bika=[0] cika=[0] j=0 k=0 a.sort() b.sort() c.sort() for i in range(n): if j<n: while a[j]<b[i]: bika[i]+=1 j+=1 if j>=n: break if i!=n-1: bika.append(bika[i]) for i in range(n): if k<n: while b[k]<c[i]: cika[i]+=bika[k] k+=1 if k>=n: break if i!=n-1: cika.append(cika[i]) print((sum(cika)))
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: x=bisect.bisect_left(a,i) y=n-bisect.bisect_right(c,i) ans+=x*y print(ans)
p03557
import copy 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() p = 0 c.sort() q = 0 count = 0 x = 0 for i in range(n): p = 0 q = 0 while p<n: if (b[p] > a[i]): while q<n: if (c[q] > b[p]): count += (n-q) p += 1 break else: q += 1 else: p += 1 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() 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
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() C.sort() ans = 0 #Bの中の数iに対して、Aの中でiより小さい数の個数と、Cの中でiより大きい数の個数の積を探索 for i in B: ans += bisect_right(A, i-0.1) * (N-bisect_left(C, i+0.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() # print (A, B ,C) ans = 0 for i in B: # print (i) # print (bisect.bisect_left(A, i-0.1)) ans += bisect.bisect_left(A, i-0.1) * (N-bisect.bisect_right(C, i+0.1)) print (ans)
p03557
N = int(eval(input())) def binary_search(L, target): """ >>> binary_search([1,3,5],2) 2 >>> binary_search([1,3,5],5) 0 >>> binary_search([1,3,5],9) 0 >>> binary_search([1,3,3,3,3,5],3) 1 >>> binary_search([1,3,3,3,3,5],4) 1 """ if L[0] > target: return len(L) if L[-1] <= target: return 0 right_i = len(L) - 1 left_i = 0 j = 0 while left_i + 1 != right_i: med_i = (right_i + left_i) // 2 if L[med_i] < target: left_i = med_i elif L[med_i] > target: right_i = med_i else: while L[med_i + 1] == target: med_i += 1 return len(L) - med_i - 1 return len(L) - right_i D = [] for _ in range(3): D.append(list(map(int, input().split()))) A, B, C = D A = [-a for a in A] A.sort() C.sort() ans = 0 for b in B: ans += binary_search(A, -b) * binary_search(C, b) 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() def hoge(): count = 0 Ai = -1 Ci = -1 for i in range(N): if Ai < N - 1: while A[Ai + 1] < B[i]: Ai += 1 if Ai == N - 1: break if Ci < N - 1: while C[Ci + 1] <= B[i]: Ci += 1 if Ci == N - 1: break count += (Ai + 1) * (N - (Ci + 1)) return count print((hoge()))
p03557
import sys from bisect import bisect_left, bisect, bisect_right input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) def main(): 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 x in a: i = bisect(b, x) for y in b[i:]: j = bisect(c, y) cnt += len(c[j:]) print(cnt) if __name__ == '__main__': main()
import sys from bisect import bisect_left, bisect_right input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) def main(): 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 x in b: cnt += bisect_left(a, x)*(n-bisect_right(c, x)) print(cnt) if __name__ == '__main__': main()
p03557
import itertools N = int(eval(input())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) L = list(itertools.product(A,B,C,repeat=1)) cnt = 0 for i,j,k in L: if i<j<k: cnt += 1 print(cnt)
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 x in B: # 小さい sm = bisect.bisect_left(A,x) # 大きい bi = len(C) - bisect.bisect_right(C,x) ans += sm*bi 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() count = 0 for i in a: for j in range(bisect.bisect(b, i), len(b)): count += len(b) - bisect.bisect(c, b[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())) a.sort() b.sort() c.sort() count = 0 for i in b: count += bisect.bisect_left(a, i) * (len(c) - bisect.bisect(c, i)) print(count)
p03557