input stringlengths 20 127k | target stringlengths 20 119k | problem_id stringlengths 6 6 |
|---|---|---|
import bisect;N=int(eval(input()));A,B,C=[sorted(map(int,input().split())) for _ in "ABC"];print((sum([bisect.bisect_left(A,i)*(N-bisect.bisect_right(C,i)) for i in B])))
| from bisect import *;N=int(eval(input()));A,B,C=[sorted(map(int,input().split())) for _ in "ABC"];print((sum([bisect_left(A,i)*(N-bisect_right(C,i)) for i in B]))) | 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 b_search_l(B,key):
#key < B[s]を満たす最小のs
if key < B[0]:
return 0
elif key >= B[N-1]:
return N-1
else:
left,right = 0,N
while left < right:
mid = (left+right)//2
if B[mid] <= key and key < B[mid+1]:
return mid+1
elif B[mid] > key:
right = mid
else:
left = mid
def b_search_r(B,key):
#key > B[t]を満たす最大のt
if B[0] >= key:
return 0
elif B[N-1] < key:
return N-1
else:
left,right = 0,N
while left < right:
mid = (left+right)//2
if B[mid] < key and key <= B[mid+1]:
return mid
elif B[mid] >= key:
right = mid
else:
left = mid
ans = 0
for i in range(N):
for j in range(N):
if A[i] +1 < C[j]:
ans += (b_search_r(B,C[j]) - b_search_l(B,A[i])+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()
def b_search_l(B,key):
#key < B[s]を満たすsの個数
if key < B[0]:
return N
elif key >= B[N-1]:
return 0
else:
left,right = 0,N
while left < right:
mid = (left+right)//2
if B[mid] <= key and key < B[mid+1]:
return N-(mid+1)
elif B[mid] > key:
right = mid
else:
left = mid
def b_search_r(B,key):
#key > B[t]を満たすtの個数
if B[0] >= key:
return 0
elif B[N-1] < key:
return N
else:
left,right = 0,N
while left < right:
mid = (left+right)//2
if B[mid] < key and key <= B[mid+1]:
return mid+1
elif B[mid] >= key:
right = mid
else:
left = mid
#b_l:keyより多い奴の個数
#b_r:key未満の奴の個数
ans = 0
for i in range(N):
b_l,b_r = b_search_l(C,B[i]),b_search_r(A,B[i])
ans += (b_l)*(b_r)
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()
def b_search_l(B,key):
#key < B[s]を満たすsの個数
if key < B[0]:
return N
elif key >= B[N-1]:
return 0
else:
left,right = 0,N
while left < right:
mid = (left+right)//2
if B[mid] <= key and key < B[mid+1]:
return N-(mid+1)
elif B[mid] > key:
right = mid
else:
left = mid
def b_search_r(B,key):
#key > B[t]を満たすtの個数
if B[0] >= key:
return 0
elif B[N-1] < key:
return N
else:
left,right = 0,N
while left < right:
mid = (left+right)//2
if B[mid] < key and key <= B[mid+1]:
return mid+1
elif B[mid] >= key:
right = mid
else:
left = mid
#b_l:keyより多い奴の個数
#b_r:key未満の奴の個数
ans = 0
for i in range(N):
b_l,b_r = b_search_l(C,B[i]),b_search_r(A,B[i])
ans += (b_l)*(b_r)
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()
#bisect_left:keyを挿入できる最小のindex
#bisect_right:keyを挿入できる最大のindex
ans = 0
for i in range(N):
b_l,b_r = bisect_left(A,B[i]),N-bisect_right(C,B[i])
ans += (b_l)*(b_r)
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, b, c = sorted(a), sorted(b), sorted(c)
ans = 0
for i in b:
up_index = bisect.bisect_left(a,i)
down_index = bisect.bisect_right(c,i)
ans += len(a[:up_index])*len(c[down_index:])
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, b, c = sorted(a), sorted(b), sorted(c)
ans = 0
for i in b:
up_index = bisect.bisect_left(a,i)
down_index = bisect.bisect_right(c,i)
ans += up_index * (n-down_index)
print(ans)
| p03557 |
#!/mnt/c/Users/moiki/bash/env/bin/python
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
A2 = []
B2 = []
C2 = []
for a,b,c in zip(A,B,C):
bisect.insort_left(A2, a)
# bisect.insort_left(B2, b)
bisect.insort_left(C2, c)
# print(A,B,C)
# import numpy as np
sum = 0
for b in B:
sum += bisect.bisect_left(A, b) * (N - bisect.bisect_right(C, b))
# for c in C:
# for b in [x for x in B if x < c]:
# for a in [x for x in A if x < b]:
print(sum) | #!/mnt/c/Users/moiki/bash/env/bin/python
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
A2 = []
B2 = []
C2 = []
# for a,b,c in zip(A,B,C):
# bisect.insort_left(A2, a)
# # bisect.insort_left(B2, b)
# bisect.insort_left(C2, c)
# print(A,B,C)
# import numpy as np
sum = 0
for b in B:
sum += bisect.bisect_left(A, b) * (N - bisect.bisect_right(C, b))
# for c in C:
# for b in [x for x in B if x < c]:
# for a in [x for x in A if x < b]:
print(sum) | p03557 |
n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
c.sort()
### 二分探索
ans = 0
for i in range(n):
for j in range(n):
if a[i] < b[j]:
for k in range(len(c)):
low = 0
high = len(c) - 1
item = c[k]
while low <= high:
mid = (low + high) //2
guess = c[mid]
if guess == item:
break
if guess > item:
high = mid -1
else:
low = mid + 1
if c[mid] > b[j]:
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()
C.sort()
ans = 0
for i in range(N):
a = bisect.bisect_left(A, B[i])
c = bisect.bisect_right(C, B[i])
ans += a*(N-c)
print(ans)
| p03557 |
#!/usr/bin/python3
from bisect import bisect_left
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())))
res = 0
for a in A:
t = bisect_left(B, a + 1)
for b in B[t:]:
s = bisect_left(C, b + 1)
res += N - s
print(res)
if __name__ == '__main__':
main()
| #!/usr/bin/python3
from bisect import bisect_left, bisect_right
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())))
res = 0
for b in B:
res += bisect_left(A, b) * (N - bisect_right(C, b))
print(res)
if __name__ == '__main__':
main()
| p03557 |
icase=0
if icase==0:
n=int(eval(input())) #数値入力 「N」だけの入力のとき
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=list(map(int, input().split()))
elif icase==1:
n=2
a=[1,5]
b=[2,4]
c=[3,6]
elif icase==2:
n=6
a=[3, 14, 159, 2, 6, 53]
b=[58, 9, 79, 323, 84, 6]
c=[2643, 383, 2, 79, 50, 288]
a.sort()
b.sort()
c.sort()
icnt=0
ast=0
cst=0
for i in range(n):
if a[n-1]<=b[i]:
ast=n
# print("a1:",ast-1,a[ast-1],i,b[i])
elif a[0]>=b[i]:
ast=0
# print("a1:",ast-1,a[ast-1],i,b[i])
else:
while a[ast]<b[i] and ast<n-1:
ast=ast+1
# print("a2:",ast-1,a[ast-1],i,b[i])
if b[i]<c[0]:
cst=0
elif b[i]>=c[n-1]:
cst=n
# print("c1:",cst,c[cst],i,b[i])
else:
while b[i]>=c[cst] and cst<n-1:
cst=cst+1
# print("c2:",cst-1,c[cst-1],i,b[i])
# print(ast,i,n-cst)
icnt=icnt+(ast)*(n-cst)
print(icnt) | 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()))
lenc=len(c)
a.sort()
b.sort()
c.sort()
jsum=0
for j in b:
ai=bisect(a,j-1)
ci=lenc-bisect_left(c,j+1)
# print(j,ai,ci)
jsum+=ai*ci
print(jsum) | p03557 |
import bisect
def I(): return int(eval(input()))
def LI(): return list(map(int,input().split()))
N = I()
A = sorted(LI())
B = sorted(LI())
C = sorted(LI())
ans = 0
BC = []
for b in B:
C2 = C[:]
ok = bisect.bisect(C2,b)
if ok!=N:
bisect.insort(C2,b)
for _ in range(N-ok):
BC.append(C2[ok:])
for a in A:
for bc in BC:
if bisect.bisect(bc,a)==0:
ans += 1
print(ans)
| import bisect
def I(): return int(eval(input()))
def LI(): return list(map(int,input().split()))
N = I()
A = sorted(LI())
B = sorted(LI())
C = sorted(LI())
ans = 0
for b in B:
ok_a = bisect.bisect_left(A,b)
ok_c = bisect.bisect_right(C,b)
if ok_a!=0 and ok_c!=N:
ans += ok_a*(N-ok_c)
print(ans)
| p03557 |
import bisect
def I(): return int(eval(input()))
def LI(): return list(map(int,input().split()))
N = I()
A = sorted(LI())
B = sorted(LI())
C = sorted(LI())
ans = 0
for b in B:
ok_a = bisect.bisect_left(A,b)
ok_c = bisect.bisect_right(C,b)
if ok_a!=0 and ok_c!=N:
ans += ok_a*(N-ok_c)
print(ans)
| import bisect
def I(): return int(eval(input()))
def LI(): return list(map(int,input().split()))
N = I()
A = sorted(LI())
B = sorted(LI())
C = sorted(LI())
ans = 0
for b in B:
ok_a = bisect.bisect_left(A,b)
ok_c = bisect.bisect_right(C,b)
ans += ok_a*(N-ok_c)
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 = bisect.bisect_right(c, i)
#print(x, y)
ans = ans+x*(n-y)
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 b:
x = bisect.bisect_left(a, i)
y = bisect.bisect_right(c, i)
ans = ans + (x * (n-y))
print(ans) | p03557 |
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = I()
return l
def LIR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = LI()
return l
def SR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = S()
return l
def LSR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = SR()
return l
mod = 1000000007
#A
def A():
s = S()
t = S()
if s+t == t[::-1]+s[::-1]:
print("YES")
else:
print("NO")
#B
def B():
n = I()
for i in range(int(n**0.5)+2)[::-1]:
if i*i <= n:
print((i*i))
quit()
#C
def C():
n = I()
a = LI()
b = LI()
c = LI()
q = [0 for i in range(n)]
ans = 0
a.sort()
b.sort()
c.sort()
for i in range(n):
j = bisect.bisect_left(a,b[i])
q[i] = j
for i in range(n-1):
q[i+1] += q[i]
q.insert(0,0)
for i in range(n):
j = bisect.bisect_left(b,c[i])
ans += q[j]
print(ans)
#D
def D():
return
#E
def E():
return
#F
def F():
return
#G
def G():
return
#H
def H():
return
#Solve
if __name__ == "__main__":
C()
| #!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
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 LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n = I()
a = LI()
b = LI()
c = LI()
a.sort()
c.sort()
ans = 0
for i in range(n):
bi = b[i]
j = bisect.bisect_left(a,bi)
k = bisect.bisect_right(c,bi)
ans += j*(n-k)
print(ans)
return
#Solve
if __name__ == "__main__":
solve()
| p03557 |
n = int(eval(input()))
xs = sorted(map(int, input().split()))
ys = sorted(map(int, input().split()))
zs = sorted(map(int, input().split()))
bs = [0] * n
for i in range(n):
for j in range(n):
if xs[j] < ys[i]:
bs[i] += 1
else:
break
cs = [0] * n
for i in range(n):
for j in range(n):
if ys[j] < zs[i]:
cs[i] += bs[j]
else:
break
print((sum(cs)))
|
n = int(eval(input()))
xs = sorted(map(int, input().split()))
ys = sorted(map(int, input().split()))
zs = sorted(map(int, input().split()))
bs = [0] * n
j = 0
for i in range(n):
while j < n and xs[j] < ys[i]:
j += 1
bs[i] = j
cs = [0] * n
j = 0
k = 0
for i in range(n):
while j < n and ys[j] < zs[i]:
k += bs[j]
j += 1
cs[i] = k
print((sum(cs)))
| p03557 |
#関数リスト
import sys
from bisect import bisect
input = sys.stdin.readline
def RD(): return input().rstrip()
def I(): return int(input().rstrip())
def MI(): return list(map(int, input().split()))
def MF(): return list(map(float,input().split()))
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
def main():
N = I()
A = LI()
A.sort()
B = LI()
B.sort()
B_len = len(B)
C = LI()
C.sort()
C_len = len(C)
result = 0
A_init = A[0]
index = 0
next_i = index
for i in A:
index = next_i
for j in range(index, B_len):
if B[j] <= i:
next_i = j+1
else:
result += C_len - bisect(C,B[j])
print(result)
if __name__ == "__main__":
main() | #関数リスト
import sys
import bisect
input = sys.stdin.readline
def RD(): return input().rstrip()
def I(): return int(input().rstrip())
def MI(): return list(map(int, input().split()))
def MF(): return list(map(float,input().split()))
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
def main():
N = I()
A = LI()
A.sort()
B = LI()
B.sort()
B_len = len(B)
C = LI()
C.sort()
C_len = len(C)
result = 0
A_init = A[0]
index = 0
next_i = index
for i in B:
tempA = bisect.bisect_left(A,i)
tempC = C_len - bisect.bisect_right(C,i)
result += tempA*tempC
print(result)
if __name__ == "__main__":
main()
| p03557 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/22
Solved on 2019/3/
@author: shinjisu
"""
# ABC 077 C Festival
import collections
#import numpy as np
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
# def getIntList(): return np.array(input().split(), dtype=np.longlong)
def zeros(n): return [0]*n
# def zeros(n): return np.zeros(n, dtype=np.longlong)
def getIntLines(n): return [int(input()) for i in range(n)]
"""
def getIntLines(n):
data = zeros(n)
for i in range(n):
data[i] = getInt()
return data
"""
def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替
def getIntMat(n, m): # n行に渡って、1行にm個の整数
#mat = zeros((n, m))
mat = zeros2(n, m)
for i in range(n):
mat[i] = getIntList()
return mat
ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18
class Debug():
def __init__(self):
self.debug = True
def off(self):
self.debug = False
def dmp(self, x, cmt=''):
if self.debug:
if cmt != '':
print(cmt, ': ', end='')
print(x)
return x
def prob():
d = Debug()
d.off()
N = getInt()
d.dmp((N), 'N')
A = getIntList()
d.dmp((A), 'A')
B = getIntList()
d.dmp((B), 'B')
C = getIntList()
d.dmp((C), 'C')
aParts = sorted(A)
bParts = sorted(B)
cParts = sorted(C)
d.dmp((aParts), 'A')
d.dmp((bParts), 'B')
d.dmp((cParts), 'C')
combAB = zeros(N)
combBC = zeros(N)
j = 0
for i in range(N):
while j < N and bParts[j] <= aParts[i]:
j += 1
#d.dmp((i,j),'in while')
combAB[i] = N-j
#d.dmp((i,j),'in for')
d.dmp((combAB), 'combAB')
j = 0
for i in range(N):
while j < N and cParts[j] <= bParts[i]:
j += 1
combBC[i] = N-j
d.dmp((combBC), 'combBC')
count = 0
for i in range(N):
#d.dmp((N-combAB[i]), 'N-combAB[i]')
count += sum(combBC[N-combAB[i]:])
#d.dmp((count), 'count')
return count
ans = prob()
if ans is None:
pass
elif type(ans) == tuple and ans[0] == 1: # 1,ans
for elm in ans[1]:
print(elm)
else:
print(ans)
| #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/22
Solved on 2019/3/
@author: shinjisu
"""
# ABC 077 C Festival
import collections
#import numpy as np
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
# def getIntList(): return np.array(input().split(), dtype=np.longlong)
def zeros(n): return [0]*n
# def zeros(n): return np.zeros(n, dtype=np.longlong)
def getIntLines(n): return [int(input()) for i in range(n)]
"""
def getIntLines(n):
data = zeros(n)
for i in range(n):
data[i] = getInt()
return data
"""
def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替
def getIntMat(n, m): # n行に渡って、1行にm個の整数
#mat = zeros((n, m))
mat = zeros2(n, m)
for i in range(n):
mat[i] = getIntList()
return mat
ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18
class Debug():
def __init__(self):
self.debug = True
def off(self):
self.debug = False
def dmp(self, x, cmt=''):
if self.debug:
if cmt != '':
print(cmt, ': ', end='')
print(x)
return x
def prob():
d = Debug()
d.off()
N = getInt()
d.dmp((N), 'N')
aParts = getIntList()
bParts = getIntList()
cParts = getIntList()
aParts.sort()
bParts.sort()
cParts .sort()
d.dmp((aParts), 'A')
d.dmp((bParts), 'B')
d.dmp((cParts), 'C')
combAB = zeros(N) # Aのi番めのパーツが組み合わせられる数
combBC = zeros(N)
j = 0
for i in range(N):
while j < N and bParts[j] <= aParts[i]:
j += 1
#d.dmp((i,j),'in while')
combAB[i] = N-j
#d.dmp((i,j),'in for')
d.dmp((combAB), 'combAB')
j = 0
for i in range(N):
while j < N and cParts[j] <= bParts[i]:
j += 1
combBC[i] = N-j
d.dmp((combBC), 'combBC')
sm = zeros(N+1)
for i in range(N):
sm[-2-i] = combBC[-1-i]+sm[-1-i]
d.dmp((sm), 'sm')
count = 0
for i in range(N):
# count += sum(combBC[N-combAB[i]:])
count += sm[N-combAB[i]]
return count
ans = prob()
if ans is None:
pass
elif type(ans) == tuple and ans[0] == 1: # 1,ans
for elm in ans[1]:
print(elm)
else:
print(ans)
| p03557 |
from bisect import bisect_right, bisect_left
n = int(eval(input()))
li_a = list(map(int, input().split()))
li_b = list(map(int, input().split()))
li_c = list(map(int, input().split()))
li_a.sort()
li_b.sort()
li_c.sort()
relation_bc = [] #relation_bc[i] : 大きい方からi番目のbより大きいcがいくつあるか
for i in range(n):
i += 1
j = li_b[(-1)*i]
k = bisect_right(li_c, j)
relation_bc.append(len(li_c)-k)
ans = 0
for i in li_a:
p = bisect_right(li_b, i) # i より大きいbがいくつあるか調べる
p = n - p
if p >= 1:
s = 0
for j in range(p):
s += relation_bc[j]
ans += s
else:
continue
print(ans) | from bisect import bisect_right, bisect_left
from itertools import accumulate
n = int(eval(input()))
li_a = list(map(int, input().split()))
li_b = list(map(int, input().split()))
li_c = list(map(int, input().split()))
li_a.sort()
li_b.sort()
li_c.sort()
relation_bc = [] #relation_bc[i] : 大きい方からi番目のbより大きいcがいくつあるか
for i in range(n):
i += 1
j = li_b[(-1)*i]
k = bisect_right(li_c, j)
relation_bc.append(len(li_c)-k)
ans = 0
li = list(accumulate(relation_bc))
for i in li_a:
p = bisect_right(li_b, i) # i より大きいbがいくつあるか調べる
p = n - p
if p >= 1:
ans += li[p-1]
else:
continue
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()
lenC = len(C)
anssum = 0
for i in A:
for l in B[bisect.bisect_right(B,i):]:
anssum += lenC - bisect.bisect_right(C,l)
print(anssum) | 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()
anssum = 0
for i in B:
moreB = N-bisect.bisect_right(C,i)
lessB = bisect.bisect_left(A,i)
anssum += moreB*lessB
print(anssum) | p03557 |
from collections import Counter
N=int(eval(input()))
A=Counter(input().split())
B=Counter(input().split())
C=Counter(input().split())
ans=0
for a_key,a_count in A.most_common():
for b_key,b_count in B.most_common():
for c_key,c_count in C.most_common():
a_key,b_key,c_key=int(a_key),int(b_key),int(c_key)
if a_key<b_key and b_key<c_key:
ans+=a_count*b_count*c_count
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())))
print((sum(bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b)) for b in B))) | p03557 |
n = int(eval(input()))
abc = [tuple(map(int, input().split(" "))) for i in range(3)]
a, b, c = [sorted(abc_i) for abc_i in abc]
sum_num = 0
for b_i in b:
can_a_count = n
for i, a_i in enumerate(a):
if a_i >= b_i:
can_a_count = i
break
can_c_count = n
for i, c_i in enumerate(c[::-1]):
if c_i <= b_i:
can_c_count = i
break
sum_num += can_a_count * can_c_count
print(sum_num) | import bisect
n = int(eval(input()))
abc = [tuple(map(int, input().split(" "))) for i in range(3)]
# n = 100000
# abc = [tuple(range(n)) for i in range(3)]
a, b, c = [sorted(abc_i) for abc_i in abc]
print((sum(bisect.bisect_left(a, b_i) * (n-bisect.bisect(c, b_i)) for b_i in b))) | 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())))
answer = 0
for a in A:
bi = bisect.bisect_right(B, a)
for i in range(bi, N):
ci = bisect.bisect_right(C, B[i])
answer += N - ci
print(answer) | 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())))
answer = 0
for b in B:
ai = bisect.bisect_left(A, b)
ci = bisect.bisect_right(C, b)
answer += ai * (N - ci)
print(answer)
| p03557 |
from bisect import bisect_left, bisect_right
N = int(eval(input()))
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
answer = 0
for b in B:
ai = bisect_left(A, b)
ci = bisect_right(C, b)
answer += len(A[:ai]) * len(C[ci:])
print(answer)
| from bisect import bisect_left, bisect_right
N = int(eval(input()))
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
answer = 0
CL = len(C)
for b in B:
ai = bisect_left(A, b)
ci = bisect_right(C, b)
answer += ai * (CL - ci)
print(answer) | p03557 |
N = int(eval(input()))
a = sorted(list(map(int, input().split())))
b = list(map(int, input().split()))
c = sorted(list(map(int, input().split())))
a_b = 0
b_c = 0
count = 0
for b_item in b:
while a_b < N and a[a_b] < b_item:
if a[a_b] >= b_item:
break
a_b += 1
while b_c < N and c[b_c] <= b_item:
if c[b_c] > b_item:
break
b_c += 1
b_c = N - b_c
count += (a_b * b_c)
a_b = 0
b_c = 0
print(count)
| 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 = 0
b_c = 0
count = 0
for b_item in b:
while a_b < N and a[a_b] < b_item:
a_b += 1
while b_c < N and c[b_c] <= b_item:
b_c += 1
count += (a_b * (N - b_c))
print(count)
| p03557 |
import math
import sys
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 = sorted(A)
B = sorted(B)
C = sorted(C)
BAcnt = [0] * N
for i in range(N):
BAcnt[i] = bisect.bisect_left(A, B[i])
ret = 0
for i in range(N):
csize = C[i]
for j in range(N):
bsize = B[j]
if bsize < csize:
ret += BAcnt[j]
print(ret)
| import math
import sys
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 = sorted(A)
B = sorted(B)
C = sorted(C)
BAcnt = [0] * N
for i in range(N):
BAcnt[i] = bisect.bisect_left(A, B[i])
BAruiseki = [0] * N
BAruiseki[0] = BAcnt[0]
for i in range(1,N):
BAruiseki[i] = BAruiseki[i-1] + BAcnt[i]
ret = 0
for i in range(N):
j = bisect.bisect_left(B, C[i]) - 1
if len(BAruiseki) > j and j>=0:
ret += BAruiseki[j]
print(ret)
| p03557 |
n=int(eval(input()))
a=list(map(int,input().split(' ')))
b=list(map(int,input().split(' ')))
c=list(map(int,input().split(' ')))
a=[0]+sorted(a)+[float('inf')]
c=[0]+sorted(c)+[float('inf')]
def bin_search_a(a,b):
low=0
high=len(a)-1
while low<=high:
mid=(low+high)//2
if a[mid] < b <= a[mid+1]:
return mid
if a[mid] >= b:
high=mid-1
else:
low=mid+1
def bin_search_c(c,b):
low=0
high=len(c)-1
while low<=high:
mid=(low+high)//2
if c[mid] <= b < c[mid+1]:
return mid
if c[mid] > b:
high=mid-1
else:
low=mid+1
altar=0
for bi in b:
s=bin_search_a(a,bi)*(n-bin_search_c(c,bi))
altar+=s
print(altar) | n=int(eval(input()))
a=list(map(int,input().split(' ')))
b=list(map(int,input().split(' ')))
c=list(map(int,input().split(' ')))
a=[0]+sorted(a)+[float('inf')]
c=[0]+sorted(c)+[float('inf')]
def meguru_a(bi):
ng=n+1 ; ok=0
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if a[mid] < bi :
ok = mid
else:
ng = mid
return ok
def meguru_c(bi):
ng=-1 ; ok=n
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if bi < c[mid+1]:
ok = mid
else:
ng = mid
return ok
altar=0
for bi in b:
s=meguru_a(bi)*(n - meguru_c(bi))
altar+=s
print(altar) | p03557 |
def nibu(list,item):
high=len(list)-1
low=0
while low <= high:
mid=(low+high)//2
guess=list[mid]
if guess==item:
return mid+1
break
elif guess < item:
low = mid +1
elif guess > item:
high = mid - 1
if guess != item:
return high+1
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()
Bs=[]
s=0
for i in range(n):
Bs.append(n-nibu(C,B[i]))
for i in range(n):
Bss=Bs[:]
Bss=Bs[nibu(B,A[i]):]
s+=sum(Bss)
print(s)
| 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) | p03557 |
import bisect
N=int(eval(input()))
As=list(map(int,input().split()))
Bs=list(map(int,input().split()))
Cs=list(map(int,input().split()))
As.sort()
Bs.sort()
Cs.sort()
pyout=0
for i in range(N):
num1=bisect.bisect_left(Bs,Cs[i])
for j in range(num1):
num2=bisect.bisect_left(As,Bs[j])
pyout+=num2
print(pyout) | import bisect
N=int(eval(input()))
As=list(map(int,input().split()))
Bs=list(map(int,input().split()))
Cs=list(map(int,input().split()))
As.sort()
Cs.sort()
pyout=0
for i in range(N):
num1=bisect.bisect_left(As,Bs[i])
num2=N-bisect.bisect_right(Cs,Bs[i])
pyout+=num2*num1
print(pyout) | 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()
BtoC = [0]*N
for i in range(N):
BtoC[i] = N - bisect.bisect_right(C,B[i])
s = [0]*N
for i in range(N):
i = N-1-i
if i == N-1:
s[i] = BtoC[i]
continue
s[i] = s[i+1]+BtoC[i]
res = 0
for a in A:
ind = bisect.bisect_right(B,a)
if ind >= N:
break
res += s[ind]
print(res) | 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()
BtoC = [0]*N
for i in range(N):
BtoC[i] = N - bisect.bisect_right(C,B[i])
s = [0]*N
for i in range(N):
i = N-1-i
if i == N-1:
s[i] = BtoC[i]
continue
s[i] = s[i+1]+BtoC[i]
res = 0
for a in A:
ind = bisect.bisect_right(B,a)
res += s[ind] if ind <= N-1 else 0
print(res) | 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=[0 for i in range(N)]
BC=[0 for i in range(N)]
def find_gt(a,x):
i = bisect.bisect_right(a,x)
if i != len(a):
return N-i
else:
return 0
for i in range(N):
AB[i]=find_gt(B,A[i])
BC[i]=find_gt(C,B[i])
ans=0
for i in range(N):
ans+=sum(BC[N-AB[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):
a=bisect.bisect_left(A,B[i])
c=N-bisect.bisect_right(C,B[i])
ans+=a*c
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()
cnt = 0
for j in range(N):
i = bisect.bisect_left(A, B[j])
k = bisect.bisect_right(C, B[j])
cnt += i * (N - k)
print(cnt) | from bisect import bisect,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 b in B:
i=bisect_left(A,b)
j=bisect(C,b)
ans+=i*(N-j)
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()
B.sort()
C.sort()
cnt = 0
a_left = 0
c_left = 0
for i in range(N):
b = B[i]
a_left += bisect_left(A[a_left:], b)
c_left += bisect_right(C[c_left:], b)
cnt += a_left * (N - c_left)
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()
C.sort()
cnt = 0
for b in B:
cnt += bisect_left(A, b) * (N - bisect_right(C, b))
print(cnt) | p03557 |
import sys
from bisect import bisect
def main():
input = sys.stdin.readline
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())))
Bn = [0] * N
for i in range(N):
b = B[i]
m = bisect(C, b)
Bn[i] = (N - m)
ans = 0
for i in range(N):
a = A[i]
m = bisect(B, a)
ans += sum(Bn[m:])
print(ans)
if __name__ == '__main__':
main()
| import sys
from bisect import bisect
from itertools import accumulate
def main():
input = sys.stdin.readline
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())))
Bn = [0] * N
for i in range(N):
b = B[i]
m = bisect(C, b)
Bn[i] = (N - m)
Bn = list(accumulate(Bn[::-1]))[::-1]
Bn += [0]
ans = 0
for i in range(N):
a = A[i]
m = bisect(B, a)
ans += Bn[m]
print(ans)
if __name__ == '__main__':
main()
| p03557 |
n=int(eval(input()))
s=[list(map(int,input().split()))for i in range(3)]
c=0
for i in range(n):
p=s[2][i]
q=[j for j in s[1] if j<p]
f=[j for j in s[0] if j<p]
for a in range(len(q)):
r=q[a]
t=[j for j in f if j<r]
c+=len(t)
print(c) | n=int(eval(input()))
s=[list(map(int,input().split()))for i in range(3)]
s[0].sort()
s[1].sort()
s[2].sort()
c,d,e=0,0,0
for i in range(n):
while d<n and s[0][d]<s[1][i]:
d+=1
while e<n and s[2][e]<=s[1][i]:
e+=1
c+=d*(n-e)
print(c) | 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()))
ans=0
A.sort()
B.sort()
C.sort()
for i in range(len(B)):
ans+=bisect.bisect_left(A,B[i])*(len(C)-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()))
#print(A)
A.sort()
B.sort()
C.sort()
#print(A)
import bisect
ans=0
for i in range(N):
cnt=bisect.bisect_left(A,B[i])*(N-bisect.bisect_right(C,B[i]))
ans+=cnt
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()]
b.sort()
c=[int(i) for i in input().split()]
c.sort()
#print(n,a,b,c)
ans=0
for j in range(n):
aa=bisect.bisect_right(b, a[j])
if aa < n:
for i in range(aa,n):
ans+=n-bisect.bisect_right(c, b[i])
print(ans)
| import bisect
n=int(eval(input()))
a=[int(i) for i in input().split()]
a.sort()
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
c.sort()
#print(n,a,b,c)
ans=0
for j in range(n):
aa=bisect.bisect_left(a, b[j])
bb=bisect.bisect_right(c, b[j])
ans+=aa*(n-bb)
print(ans) | p03557 |
N=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
sum=0
for i in range(N):
j_start=0
for j in range(N):
if B[j]<=A[i]:
continue
for k in range(j_start,N):
#print "# loop C"
#print A[i],B[j],C[k],N-k
if C[k]>B[j]:
#print A[i],B[j],C[k],N-k
sum+=(N-k)
j_start=k
break
print(sum)
| import bisect
N=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()
sum=0
for val_b in B:
sum+=bisect.bisect_left(A, val_b)*( N-bisect.bisect_right(C, val_b) )
print(sum) | p03557 |
N=int(eval(input()))
*A,=sorted(map(int,input().split()))
*B,=sorted(map(int,input().split()))
*C,=sorted(map(int,input().split()))
from bisect import *
cnt=0
for a in A:
in_b = bisect_right(B, a)
for b in B[in_b:]:
in_c = bisect_right(C, b)
for c in C[in_c:]:
cnt+=1
print(cnt) | N=int(eval(input()))
*A,=sorted(map(int,input().split()))
*B,=sorted(map(int,input().split()))
*C,=sorted(map(int,input().split()))
lenc=len(C)
from bisect import *
cnt=0
for b in B:
in_a = bisect_left(A, b)
in_c = bisect_right(C, b)
cnt+= in_a*(lenc-in_c)
print(cnt) | p03557 |
N=int(eval(input()))
*A,=sorted(map(int,input().split()))
*B,=sorted(map(int,input().split()))
*C,=sorted(map(int,input().split()))
lenc=len(C)
from bisect import *
cnt=0
for b in B:
in_a = bisect_left(A, b)
in_c = bisect_right(C, b)
cnt+= in_a*(lenc-in_c)
print(cnt) | N=int(eval(input()))
f=lambda:sorted(map(int,input().split()))
*A,=f()
*B,=f()
*C,=f()
from bisect import *
print((sum([bisect_left(A, b)*(N-bisect_right(C, b)) for b in B]))) | p03557 |
import sys
input = sys.stdin.readline
import itertools
def is_saidan(parts):
tmp = 0
for j in parts:
if j > tmp:
tmp = j
else:
break
else:
return True
return False
def snuke_festival(a,b,c):
comb = list(itertools.product(a,b,c))
count = 0
for i in comb:
if is_saidan(i):
count += 1
return count
if __name__ == "__main__":
n = int(eval(input()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
print((snuke_festival(a,b,c)))
| import sys
input = sys.stdin.readline
def snuke_festival(a,b,c):
count = 0
a_sorted = sorted(a)
c_sorted = sorted(c)
for n in b:
ab = 0
bc = 0
for i in a_sorted:
if n > i:
ab += 1
for i in c_sorted:
if n < i:
bc += 1
count += ab * bc
return count
if __name__ == "__main__":
n = int(eval(input()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
print((snuke_festival(a,b,c)))
| p03557 |
import sys
input = sys.stdin.readline
def binary_search(ys,target,low,high,reverse=True):
xs = sorted(ys)
maxlen = len(xs)
middle = 0
#print("array => %s, target => %d" %(xs,target))
while(low <= high):
middle = (low + high) // 2
#print("target %d, low %d, mid %d, high %d" %(target,low,middle,high))
if xs[middle] == target:
#print("find ",middle)
if reverse == False:
return middle
else:
return middle+1
if xs[middle] > target:
high = middle - 1
elif xs[middle] < target:
low = middle + 1
middle = (low + high) // 2 +1
# print("target %d, low %d, mid %d, high %d" %(target,low,middle,high))
return middle
def snuke_festival(a,b,c):
count = 0
b_sorted = sorted(b)
high = len(b)-1
low = 0
ab = 0
bc = 0
mid_a = 0
mid_b = 0
maxlen=len(b)
for n in range(maxlen):
mid_a = binary_search(a,b_sorted[n],mid_a,high,False)
ab = mid_a
mid_b = binary_search(c,b_sorted[n],low,mid_b,True)
bc = maxlen - mid_b
count += ab * bc
return count
if __name__ == "__main__":
n = int(eval(input()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
print((snuke_festival(a,b,c)))
| import sys
input = sys.stdin.readline
import bisect
def snuke_festival(a,b,c):
count = 0
a_sorted = sorted(a)
b_sorted = sorted(b)
c_sorted = sorted(c)
maxlen=len(b)
for target in b_sorted:
#mid_a = binary_search_left(a_sorted,target)
#mid_c = binary_search_right(c_sorted,target)
mid_a = bisect.bisect_left(a_sorted,target)
mid_c = bisect.bisect_right(c_sorted,target)
count += mid_a * (maxlen - mid_c)
#print("mid_a %d, mid_c %d, count %d" %(mid_a,maxlen - mid_c,count))
return count
if __name__ == "__main__":
n = int(eval(input()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
print((snuke_festival(a,b,c)))
| 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()
lenC = len(C)
cnt = 0
for a in A:
for b in B:
if a >= b: continue
ii = bisect.bisect_right(C, b)
cnt += lenC - ii
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()
lenC = len(C)
cnt = 0
for b in B:
ind_a = bisect.bisect_left(A, b)
ind_c = bisect.bisect_right(C, b)
cnt += ind_a * (lenC - ind_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()
ans=0
for a in A:
bidx=bisect.bisect_right(B,a)
if bidx==len(B): break
for b in B[bidx:]:
cidx=bisect.bisect_right(C,b)
if cidx==len(B): break
ans+=len(C)-cidx
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:
aidx=bisect.bisect_left(A,b)
cidx=bisect.bisect_right(C,b)
ans+=aidx*(len(C)-cidx)
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()
b_ptn = [0] * (N)
for idx, b in enumerate(B):
cnt = 0
for a in A:
if a < b:
cnt += 1
else:
break
b_ptn[idx] = cnt
ans = 0
for c in C:
for idx, b in enumerate(B):
if b >= c:
break
if idx == N-1:
ans += b_ptn[idx]
break
ans += b_ptn[idx]
print(ans)
| N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
nums = []
for idx in range(N):
nums.append((1, A[idx]))
nums.append((2, B[idx]))
nums.append((3, C[idx]))
nums.sort(key=lambda x:(x[1], -x[0]))
sum_a = 0
sum_b = 0
sum_c = 0
for idx in range(3*N):
if nums[idx][0] == 1:
sum_a += 1
elif nums[idx][0] == 2:
sum_b += sum_a
elif nums[idx][0] == 3:
sum_c += sum_b
print(sum_c) | 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()
cnt = 0
for a in A:
pos_b = bisect.bisect_right(B, a)
for pb in range(pos_b, N):
pos_c = bisect.bisect_right(C, B[pb])
cnt += N-pos_c
if pos_c == N-1:
break
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()
C.sort()
cnt = 0
for b in B:
pos_a = bisect.bisect_left(A, b)
pos_c = bisect.bisect_right(C, b)
cnt += pos_a * (N-pos_c)
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()))
a.sort()
b.sort()
c.sort()
count=0
import bisect
for i in range(0,n):
tempb=bisect.bisect_right(b,a[i])
if tempb!=len(b):
for j in range(tempb,n):
tempc=bisect.bisect_right(c,b[j])
tempcl=n-tempc
count=count+tempcl
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):
temp1=bisect.bisect_left(a,b[i])
temp2=bisect.bisect(c,b[i])
ans=ans+temp1*(n-temp2)
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 = sorted(B,reverse=True)
C = sorted(C,reverse=True)
b_list = {-1:0}
for i in range(N):
for j in range(N):
if B[i] >= C[j]:
b_list[i] = j + b_list[i-1]
break
b_list[i] = N + b_list[i-1]
m = 0
for i in range(N):
for j in range(N-1,-1,-1):
if B[j] > A[i]:
m += b_list[j]
break
print(m)
| 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 = sorted(B)
C = sorted(C)
b_list = {N:0}
for i in range(N-1,-1,-1):
j = bisect_right(C,B[i])
b_list[i] = N - j + b_list[i+1]
m = 0
for i in range(N):
j = bisect_right(B,A[i])
m += b_list[j]
print(m)
| p03557 |
from bisect import bisect_right
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
N = int(readline())
A = [int(i) for i in readline().split()]
B = [int(i) for i in readline().split()]
C = [int(i) for i in readline().split()]
A.sort()
B.sort()
C.sort()
a_ind = []
b_ind = []
for i in range(N):
a_ind.append(bisect_right(B, A[i]))
b_ind.append(N - bisect_right(C, B[i]))
b_acc = [0]
for b in b_ind:
b_acc.append(b_acc[-1] + b)
sum_b = b_acc[-1]
ans = 0
for i in a_ind:
ans += sum_b - b_acc[i]
print(ans)
if __name__ == "__main__":
main()
| from bisect import bisect_right, bisect_left
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
N = int(readline())
A = [int(i) for i in readline().split()]
B = [int(i) for i in readline().split()]
C = [int(i) for i in readline().split()]
A.sort()
B.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 bisect
N=int(eval(input()))
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)
count=0
for num in (A):
a=bisect.bisect_right(B,num)
for i in range(a,len(B)):
K=B[i]
l=bisect.bisect_right(C,K)
count+=len(C)-l
print(count) | import bisect
N=int(eval(input()))
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)
count=0
for num in (B):
a=bisect.bisect_left(A,num)
b=bisect.bisect_right(C,num)
count+=a*(N-b)
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())))
cnt = 0
for i in range(n):
for j in range(n):
if C[i]>B[j]:
for k in range(n):
if B[j]>A[k]:
cnt+=1
print(cnt) | 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())))
cnt = 0
for i in range(n):
a = bisect.bisect_left(A, B[i])
c = bisect.bisect_right(C, B[i])
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()
ans = 0
for i in C:
index = bisect.bisect_left(B,i)
for j in range(index):
index2 = bisect.bisect_left(A,B[j])
ans += index2
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()
mid_list = [0]*N
for i in range(N):
index = bisect.bisect_left(A,B[i])
if i == 0:
mid_list[i] = index
else:
mid_list[i] = mid_list[i-1] + index
ans = 0
for i in range(N):
index = bisect.bisect_left(B,C[i])
if index == 0:
continue
ans += mid_list[index-1]
print(ans) | p03557 |
import bisect
n = int(eval(input()))
bb = [0] * (n+1)
ans = 0
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()
for i in range(1,n+1):
bb[i] = bisect.bisect_left(a,b[i-1]) + bb[i-1]
for i in range(n):
ans += bb[bisect.bisect_left(b,c[i])]
print(ans) | import bisect
n = int(eval(input()))
ans = 0
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):
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()))
A = sorted(A,reverse=True)
B = sorted(B,reverse=True)
C = sorted(C,reverse=True)
count = 0
for i in range(N):
a = A[i]
for j in range(N):
b = B[j]
if a >= b:
#flag = True
break
for k in range(N):
c = C[k]
if b >= c:
break
#print(a,b,c)
count += 1
print(count)
| def bs_left(A, target):
low, high = 0, len(A)
while low<high:
mid = (low+high)//2
if A[mid]<target:
low = mid+1
else:
high = mid
return low
def bs_right(C, target):
low, high = 0, len(C)
while low<high:
mid = (low+high)//2
if target<C[mid]:
high = mid
else:
low = mid+1
return low
if __name__ == '__main__':
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)
count = 0
for i in range(N):
b = B[i]
count = count + bs_left(A,b) * (N - bs_right(C,b))
print(count)
| p03557 |
import sys
input = lambda: sys.stdin.readline().rstrip()
def resolve():
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_left(a, x):
l = -1
r = len(a)
while r-l>1:
m = (l+r)//2
if x<a[m]:
r = m
else:
l = m
return r
def binsearch_right(a, x):
l = -1
r = len(a)
while r-l>1:
m = (l+r)//2
if x<=a[m]:
r = m
else:
l = m
return r
ans = 0
for b in B:
a_r = binsearch_right(A, b)
c_l = binsearch_left(C, b)
ans += a_r * (N - c_l)
print(ans)
if __name__ == '__main__':
resolve()
| import sys
input = lambda: sys.stdin.readline().rstrip()
import bisect
def resolve():
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_r = bisect.bisect_left(A, b)
c_l = bisect.bisect_right(C, b)
ans += a_r * (N - c_l)
print(ans)
if __name__ == '__main__':
resolve()
| p03557 |
import bisect
def solve(N,A,B,C):
# A=['3', '14', '159', '2', '6', '53']
# B=['58', '9', '79', '323', '84', '6']
# C=['2643', '383', '2', '79', '50', '288']
A,B,C=list(map(int, A)),list(map(int, B)),list(map(int, C))
A=sorted(A)
B=sorted(B)
C=sorted(C)
# print(A)
# print(B)
# print(C)
D = [0]*N
E = [0]*N
for i in range(N):
a = A[i]
# print(N-bisect.bisect_right(B,a))
D[i]= N-bisect.bisect_right(B,a)
#bはaより大きい数字が何個あるか分かれば良い
#cはbの
# print(D)
for i in range(N):
b = B[i]
E[i] = N-bisect.bisect_right(C,b)
# print(E)
answer = 0
for i in range(N):
d=N-D[i]
answer+=sum(E[d:])
print(answer)
def main():
N = int(eval(input()))
A=input().rstrip().split()
B=input().rstrip().split()
C=input().rstrip().split()
solve(N,A,B,C)
if __name__ == '__main__':
main() |
import bisect
def solve(N,A,B,C):
# A=['3', '14', '159', '2', '6', '53']
# B=['58', '9', '79', '323', '84', '6']
# C=['2643', '383', '2', '79', '50', '288']
A,B,C=list(map(int, A)),list(map(int, B)),list(map(int, C))
A=sorted(A)
B=sorted(B)
C=sorted(C)
# print(A)
# print(B)
# print(C)
D = [0]*N
# E = [0]*N
# for i in range(N):
# a = A[i]
# # print(N-bisect.bisect_right(B,a))
# D[i]= N-bisect.bisect_right(B,a)
# #bはaより大きい数字が何個あるか分かれば良い
# #cはbの
# # print(D)
for i in range(N):
b = B[i]
D[i]=bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b))
# print(b,'より小さいのは',bisect.bisect_left(A,b))
# print(b,'より大きいのは',N-bisect.bisect_right(C,b))
print((sum(D)))
# print(E)
# answer = 0
# for i in range(N):
# d=N-D[i]
# answer+=sum(E[d:])
# print(answer)
def main():
N = int(eval(input()))
# A,B,C=0,0,0
A=input().rstrip().split()
B=input().rstrip().split()
C=input().rstrip().split()
solve(N,A,B,C)
if __name__ == '__main__':
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()
b_num = [0 for _ in range(len(b))]
for b_i in range(len(b)):
c_i = bisect.bisect_right(c, b[b_i])
b_num[b_i] = len(b) - c_i
ans = 0
for a_i in range(len(a)):
b_i = bisect.bisect_right(b, a[a_i])
for j in range(b_i, len(b_num)):
ans += b_num[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()
b_num = [0 for _ in range(n)]
for b_i in range(n):
c_i = bisect.bisect_right(c, b[b_i])
b_num[b_i] = n - c_i
for i in range(1, len(b_num)):
b_num[len(b_num) - 1 - i] += b_num[len(b_num) - i]
ans = 0
for a_i in range(len(a)):
b_i = bisect.bisect_right(b, a[a_i])
if b_i >= n:
continue
ans += b_num[b_i]
print(ans) | p03557 |
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline.rstrip()
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(eval(input()))
def inpm(): return list(map(int,input().split()))
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(eval(input())) for _ in range(n))
def inplL(n): return [list(eval(input())) for _ in range(n)]
def inplT(n): return [tuple(eval(input())) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
n = inp()
A = sorted(inpl())
B = sorted(inpl())
C = sorted(inpl())
ans = 0
d = defaultdict(int)
pre = 0
for b in B:
tmp = bisect.bisect_right(C[pre:],b)
pre += tmp
d[b] = n - pre
pre = 0
for a in A:
tmp = bisect.bisect_right(B[pre:],a)
pre += tmp
for b in B[pre:]:
ans += d[b]
print(ans) | import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(eval(input()))
def inpm(): return list(map(int,input().split()))
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(eval(input())) for _ in range(n))
def inplL(n): return [list(eval(input())) for _ in range(n)]
def inplT(n): return [tuple(eval(input())) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
n = inp()
A = sorted(inpl())
B = sorted(inpl())
C = sorted(inpl())
ans = 0
for b in B:
tmp = bisect.bisect_right(C,b)
tmp2 = bisect.bisect_left(A,b)
ans += (n-tmp) * tmp2
print(ans) | p03557 |
from bisect import bisect_left, bisect_right
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()])
ans = 0
for b in B:
ans += len(A[:bisect_right(A, b - 1)]) * len(C[bisect_left(C, b + 1):])
print(ans)
| from bisect import bisect_left, bisect_right
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()])
ans = 0
for b in B:
ans += bisect_right(A, b - 1) * (N - bisect_left(C, b + 1))
print(ans)
| p03557 |
N = int(eval(input()))
Alist = sorted(list(map(int, input().split())))
Blist = sorted(list(map(int, input().split())))
Clist = sorted(list(map(int, input().split())))
def binary_search(num_list, target):
ans_counter = 0
if target <= num_list[0]:
return -1
if num_list[-1] < target:
return(len(num_list))
while True:
middle = num_list[len(num_list) // 2]
left = num_list[:len(num_list) // 2]
right = num_list[len(num_list) // 2:]
if target > left[-1] and right[0] >= target:
ans_counter += len(left)
return ans_counter
elif target <= left[-1]:
num_list = left
elif right[0] < target:
ans_counter += len(left)
num_list = right
ans = 0
for C in Clist:
b_point = 0
b_point = binary_search(Blist, C)
if b_point >= 0:
for B in Blist[:b_point]:
a_point = binary_search(Alist, B)
# print(B,C,a_point)
ans += (a_point)
print(ans)
#for C in Clist:
| import bisect
N = int(eval(input()))
Alist = sorted(list(map(int, input().split())))
Blist = sorted(list(map(int, input().split())))
Clist = sorted(list(map(int, input().split())))
ans = 0
for B in Blist:
Aindex = bisect.bisect_left(Alist, B)
Cindex = bisect.bisect_right(Clist, B)
# print(B, Aindex, N-Cindex)
ans += Aindex * (N - Cindex)
print(ans)
| p03557 |
def read_input():
n = int(eval(input()))
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))
clist = list(map(int, input().split()))
return n, alist, blist, clist
def submit():
n, alist, blist, clist = read_input()
alist.sort(reverse=True)
blist.sort(reverse=True)
clist.sort(reverse=True)
i = j = 0
count = 0
while i < n:
# 下段を選ぶ
c = clist[i]
# 下段で選んだcよりも小さいb候補を探す
while j < n and blist[j] >= c:
j += 1
if j == n:
break
bcand = blist[j:]
for b in bcand:
# b候補より小さいa候補を探す
k = 0
while k < n and alist[k] >= b:
k += 1
if k == n:
break
# このkより右側は構成可能
count += (n - k)
i += 1
print(count)
return
if __name__ == '__main__':
submit() |
def read_input():
n = int(eval(input()))
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))
clist = list(map(int, input().split()))
return n, alist, blist, clist
def submit():
n, alist, blist, clist = read_input()
alist.sort(reverse=True)
blist.sort(reverse=True)
clist.sort(reverse=True)
b_a_n = [0] * n
i = j = 0
while j < n:
while i < n and alist[i] >= blist[j]:
i += 1
b_a_n[j] = n - i
j += 1
b_a_sum = b_a_n.copy()
for i in range(2, n + 1):
b_a_sum[n - i] = b_a_sum[n - i + 1] + b_a_n[n - i]
count = 0
i = j = 0
while i < n:
while blist[j] >= clist[i]:
j += 1
if j == n:
print(count)
return
count += b_a_sum[j]
i += 1
print(count)
if __name__ == '__main__':
submit() | p03557 |
import bisect
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()
cnt = 0
for j in B:
a_index = bisect.bisect_left(A, j)
c_index = bisect.bisect_right(C, j)
cnt += len(A[:a_index])*len(C[c_index:])
print(cnt) | import bisect
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()
cnt = 0
for j in B:
a_index = bisect.bisect_left(A, j)
c_index = bisect.bisect_right(C, j)
cnt += a_index*(N-c_index)
print(cnt) | p03557 |
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)
ans = 0
for ai in a:
for bi in b:
if bi <= ai:
break
for ci in c:
if ci <= bi:
break
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 bi in b:
upper = bisect.bisect_left(a, bi)
lower = n - bisect.bisect_right(c, bi)
ans += upper * lower
print(ans)
| p03557 |
def binarySearchLeft(nums, target):
low = 0
high = len(nums) - 1
while low <= high:
mid = low + high >> 1
if target == nums[mid]:
if mid == 0 or target != nums[mid - 1]:
return mid
else:
high = mid - 1
elif target < nums[mid]:
high = mid - 1
else:
low = mid + 1
return low
def solve(N, A, B, C):
A.sort()
B.sort()
C.sort()
ret = 0
for a in A:
b_idx = binarySearchLeft(B, a + 1)
if not (0 <= b_idx < N):
continue
for j in range(b_idx, N):
c_idx = binarySearchLeft(C, B[j] + 1)
ret += N - c_idx if 0 <= c_idx < N else 0
print(ret)
if __name__ == "__main__":
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
solve(N, A, B, C)
| def binarySearchLeft(nums, target):
low = 0
high = len(nums) - 1
while low <= high:
mid = low + high >> 1
if target == nums[mid]:
if mid == 0 or target != nums[mid - 1]:
return mid
else:
high = mid - 1
elif target < nums[mid]:
high = mid - 1
else:
low = mid + 1
return low
def binarySearchRight(nums, target):
low = 0
high = len(nums) - 1
while low <= high:
mid = low + high >> 1
if target == nums[mid]:
if mid == len(nums) - 1 or target != nums[mid + 1]:
return mid
else:
low = mid + 1
elif target < nums[mid]:
high = mid - 1
else:
low = mid + 1
return high
def solve(N, A, B, C):
A.sort()
B.sort()
C.sort()
ret = 0
for j in range(N):
i = binarySearchRight(A, B[j] - 1)
k = binarySearchLeft(C, B[j] + 1)
ret += (i + 1) * (N - k) if 0 <= i < N and 0 <= k < N else 0
print(ret)
if __name__ == "__main__":
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
solve(N, A, B, C)
| p03557 |
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 = sorted(a)
b = sorted(b)
c = sorted(c)
ans = 0
for x in b:
aa = bisect.bisect_left(a,x)
cc = len(c) - bisect.bisect_right(c,x)
ans += aa * cc
print(ans) | import bisect
n = int(eval(input()))
lstA = sorted(list(map(int,input().split())))
lstB = sorted(list(map(int,input().split())))
lstC = sorted(list(map(int,input().split())))
ans = 0
for i in range(n):
num = lstB[i]
top = bisect.bisect_left(lstA, num)
btm = n - bisect.bisect_right(lstC, num)
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.sort()
C.sort()
ans = 0
mem_idx_a = {}
for idx_b in range(N):
idx_c = bisect.bisect_right(C,B[idx_b])
idx_a = bisect.bisect_left(A,B[idx_b])
ans += (N-idx_c)*idx_a
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:
idx_a = bisect.bisect_left(A, b)
idx_c = bisect.bisect(C, b)
ans += idx_a * (N - idx_c)
print(ans)
| 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()]
a_check = [n] * n
c_check = [0] * n
for i,j in enumerate(sorted(b)):
for k,l in enumerate(sorted(c)):
if l > j:
c_check[i] = n - k
break
for k,l in enumerate(sorted(a)):
if l >= j:
a_check[i] = k
break
ans = 0
for i in range(n):
ans += a_check[i] * c_check[i]
print(ans) | 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()], reverse=True)
a.append(10**9)
check_a = 0
check_c = n - 1
ans = 0
for i in b:
while a[check_a] < i and check_a < n :
check_a += 1
while c[check_c] <= i and check_c >= 0:
check_c -= 1
ans += check_a * (check_c + 1)
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()
length = len(A)
#A<B<Cの組み合わせの数が答え
for i in range(length):
#Aを1つ決めた時、BがA以下の値
A_miman = bisect.bisect_right(B,A[i])
for j in range(A_miman,N):
#Bを1つ決めた時、CがBより大きい値の数をansに足す
ans += N - bisect.bisect_right(C, B[j])
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()
#A<B<Cの組み合わせの数が答え
for i in range(N):
#Bを1つ決めた時、AがB未満の場合の総数
B_miman = bisect.bisect_left(A,B[i])
#Bを1つ決めた時、CがB以上の場合の総数
B_ijou = N - bisect.bisect_right(C, B[i])
ans+= B_miman*B_ijou
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()
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
ans = 0
for b in B:
ans += bisect_left(A,b) * (N - bisect_right(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()
from bisect import *
ans = 0
for b in B:
a = bisect_left(A,b)
c = N-bisect_right(C,b)
ans += a*c
print(ans) | p03557 |
N = int(eval(input()))
ABC = [sorted(list(map(int,input().split()))) for i in range(3)]
ans = 0
for i in range(N):
for j in range(N):
if ABC[0][i]>=ABC[1][j]:
continue
else:
for k in range(N):
if ABC[1][j]>=ABC[2][k]:
continue
else:
ans += 1
print(ans) | import bisect
N = int(eval(input()))
ABC = [sorted(list(map(int,input().split()))) for i in range(3)]
ans = 0
for b in ABC[1]:
ans += bisect.bisect_left(ABC[0],b)*(N-bisect.bisect_right(ABC[2],b))
print(ans) | p03557 |
import bisect
n = int(eval(input()))
a,b,c = [list(sorted(map(int, input().split()))) for _ in range(3)]
ans = 0
for i in range(n):
x = bisect.bisect_left(a, b[i])
y = len(c) - bisect.bisect_right(c, b[i])
ans += x*y
print(ans) | import bisect
n = int(eval(input()))
a,b,c = [list(sorted(map(int, input().split()))) for _ in range(3)]
ans = 0
for i in b:
x = bisect.bisect_left(a, i)
y = len(c) - bisect.bisect_right(c, i)
ans += x*y
print(ans) | p03557 |
#!/usr/bin/env python3
from itertools import product, permutations, combinations
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)
ret = 0
for i in C:
small_b = [b for b in B if b < i]
for j in small_b:
small_a = [a for a in A if a < j]
ret += len(small_a)
print(ret) | #!/usr/bin/env python3
from itertools import product, permutations, combinations
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())))
ret = 0
for i in range(N):
# 中段を決めた時、その値より小さくなる上段を探す
new_A = bisect_left(A, B[i])
# 中段を決めた時、その値より大きくなる下段を探す
new_C = bisect_right(C, B[i])
# 組み合わせ
ret += new_A * (N - new_C)
print(ret) | 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 is_ok(arg, target, abc):
if abc[arg] > target:
return True
else:
return False
def bict(left, right, target, abc):
while(right - left > 1):
mid = (right + left)//2
if is_ok(mid, target, abc):
right = mid
else:
left = mid
return right
cnt = 0
for a in A:
b_min_index = bict(-1, N, a, B)
for b_index in range(b_min_index,N):
c_min_index = bict(-1, N ,B[b_index],C)
c_num = N - c_min_index
cnt += c_num
print(cnt)
|
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 is_ok(arg, target, abc):
if abc[arg] >= target:
return True
else:
return False
def is_ok2(arg, target, abc):
if abc[arg] > target:
return True
else:
return False
def bict(left, right, target, abc, jug):
while(right - left > 1):
mid = (right + left)//2
if jug(mid, target, abc):
right = mid
else:
left = mid
return right
cnt = 0
for b in B:
a_min_index = bict(-1, N, b, A, is_ok)
c_min_index = bict(-1, N, b, C, is_ok2)
temp = (a_min_index - 1 + 1) * (N - c_min_index)
cnt += temp
print(cnt)
| p03557 |
import sys
import bisect
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()
cnt = 0
for i in range(n):
if a[i] > b[n - 1]:
break
insert_index_b = bisect.bisect_right(b, a[i]) # 昇順
for j in range(insert_index_b, n):
insert_index_c = bisect.bisect_right(c, b[j])
cnt += n - insert_index_c
print(cnt)
| import sys
import bisect
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()
cnt = 0
ans = 0
memo = [0] * n
for i in range(n):
insert_index_c = bisect.bisect_right(c, b[i])
cnt += n - insert_index_c
memo[i] += cnt
for i in range(n):
if a[i] > b[n - 1]:
break
insert_index_b = bisect.bisect_right(b, a[i]) # 昇順
if insert_index_b >= 1:
ans += memo[n - 1] - memo[insert_index_b - 1]
else:
ans += memo[n - insert_index_b - 1]
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
#初めから、どこに挿入されるのかを考えておく
A = {}
B = {}
C = {}
for i in range(n):
B[c[i]] = min(bisect.bisect_left(b, c[i]), n)
A[b[i]] = min(bisect.bisect_left(a, b[i]), n)
for i in range(n):
Bindex = B[c[i]]
for j in range(Bindex):
Aindex = A[b[j]]
ans += (Aindex)
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
#初めから、どこに挿入されるのかを考えておく
Bcount = [0 for i in range(n+1)]
for i in range(1,n+1):
Bcount[i] = bisect.bisect_left(a, b[i-1]) + Bcount[i - 1]
for i in range(n):
index = bisect.bisect_left(b,c[i])
ans += Bcount[index]
print(ans)
| 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()]
a.sort()
c.sort(reverse=True)
p=0
q=0
i = 0
ans = 0
for bss in b:
p = 0
q = 0
for ass in a:
if ass < bss:
p += 1
for css in c:
if css > bss:
q += 1
ans += p*q
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
def find_lt(a, x):
'Find rightmost value less than x'
i = bisect.bisect_left(a, x)
if i:
return i
return 0
def find_gt(a, x):
'Find leftmost value greater than x'
i = bisect.bisect_right(a, x)
if i != len(a):
return len(a)-i
return 0
for bs in b:
ans += find_lt(a, bs)*find_gt(c,bs)
print(ans)
| p03557 |
N=int(eval(input()))
A,B,C=[sorted(map(int,input().split())) for i in range(3)]
ans=a=c=0
for i in B:
for j in A[a:]:
if i>j:a+=1
else: break
for k in C[c:]:
if i<k:break
else: c+=1
if c==N:break
ans+=a*(N-c)
print(ans) | N=int(eval(input()))
A,B,C=[sorted(map(int,input().split())) for i in range(3)]
ans=a=c=0
for i in B:
while a<N and A[a]<i:
a+=1
while c<N and C[c]<=i:
c+=1
if c==N:break
ans+=a*(N-c)
print(ans) | p03557 |
import sys
import bisect
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
c = list(map(int, sys.stdin.readline().split()))
a.sort()
b.sort()
c.sort()
b_ans_list = [0 for _ in range(n)]
for i in range(n):
# b[i]における選択可能なcの個数
b_ans_list[i] = n - bisect.bisect_right(c, b[i])
ans = 0
for i in range(n):
b_index = bisect.bisect_right(b, a[i])
ans += sum(b_ans_list[b_index::])
print(ans)
| import sys
import bisect
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
c = list(map(int, sys.stdin.readline().split()))
a.sort()
b.sort()
c.sort()
b_ans_list = [0 for _ in range(n)]
for i in reversed(list(range(n))):
# b[i]における選択可能なcの個数
if i == n-1:
b_ans_list[i] = n - bisect.bisect_right(c, b[i])
else:
b_ans_list[i] = n - bisect.bisect_right(c, b[i]) + b_ans_list[i+1]
ans = 0
for i in range(n):
b_index = bisect.bisect_right(b, a[i])
if b_index < n: ans += b_ans_list[b_index]
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())))
counter = 0
for i in range(len(A)):
b_index = bisect.bisect(B,A[i])
if b_index >= len(B):
break
b_diam = B[b_index]
for j in range(b_index,len(B)):
c_index = bisect.bisect(C,B[j])
if c_index >= len(C):
break
counter += len(C)-c_index
print(counter)
| 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())))
counter = 0
for i in range(len(B)):
#Bより小さいAの探索
Ind_A = bisect.bisect_left(A,B[i])
if A[Ind_A-1] == B[i]:
Ind_A -= 1
#Bより大きいCの探索
Ind_C = bisect.bisect_right(C,B[i])
num_C = len(C)-Ind_C
counter += round(Ind_A*num_C)
#print('B[i] =' +str(B[i]),end='')
#print(' Ind_A =' +str(Ind_A),end='')
#print(' Ind_C =' +str(Ind_C),end = '')
#print(' num_C =' +str(num_C),end = '')
#print(' 総数 ' + str(Ind_A*num_C))
print(counter)
| 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_idx = bisect.bisect_right(B, A[i])
for j in range(b_idx, N):
c_idx = bisect.bisect_right(C, B[j])
count += N - c_idx
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()
BtoC = [0 for i in range(N+1)]
for i in range(N-1, -1, -1):
c_idx = bisect.bisect_right(C, B[i])
BtoC[i] = BtoC[i+1] + (N - c_idx)
count = 0
for i in range(N):
b_idx = bisect.bisect_right(B, A[i])
count += BtoC[b_idx]
print(count) | 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) | 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:
lower_a = bisect.bisect_left(A, b)
upper_c = N - bisect.bisect_right(C, b)
ans += lower_a*upper_c
print(ans)
| p03557 |
#https://atcoder.jp/contests/abc077/tasks/arc084_a
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 bi in b:
ai = 0
ci = N-1
while ai < N and a[ai] < bi:
ai += 1
while ci >= 0 and c[ci] > bi:
ci -= 1
ans += ai * (N - 1 -ci)
print(ans)
| #https://atcoder.jp/contests/abc077/tasks/arc084_a
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()
ai = 0
ci = 0
for bi in b:
while ai < N and a[ai] < bi:
ai += 1
while ci < N and c[ci] <= bi:
ci += 1
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())))
cnt = 0
info = []
for i in range(n):
b_p = bisect.bisect_left(a, b[i])
info.append(b_p)
for k in range(n):
a_p = bisect.bisect_left(b, c[k])
cnt += sum(info[:a_p])
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
info1 = []
for i in range(n):
b_p = bisect.bisect_left(a, b[i])
info1.append(b_p) # bがそれぞれ何種類のaを載せれるか
info2 = [info1[0]]
for l in range(1, n):
info2.append(info2[l-1] + info1[l])
for k in range(n):
a_p = bisect.bisect_left(b, c[k])
if a_p != 0:
cnt += info2[a_p - 1] # cがそれぞれ何種類のbを載せれるか
print(cnt)
| 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()))
ans = 0
y_low = {}
i = 0
for x in A:
y_low[i] = bisect_right(B, x)
i += 1
for y_lowi in list(y_low.values()):
for y in B[y_lowi:]:
z_low = bisect_right(C, y)
ans += N - z_low
print(ans)
| 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()))
ans = 0
y_low = {}
i = 0
for y in B:
x = bisect_left(A, y)
z = bisect_right(C, y)
ans += x * (N-z)
print(ans)
| p03557 |
def lowerBound(arr, n):
arr += [10e9+7]
low, high = 0, len(arr)
mid = (low+high)//2
while high-low>1:
if arr[mid]>=n: high = mid
else: low = mid
mid = (low+high)//2
return high
def upperBound(arr, n):
arr = [0] + arr
low, high = 0, len(arr)
mid = (low+high)//2
while high-low>1:
if arr[mid]>n: high = mid
else: low = mid
mid = (low+high)//2
return low
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:
cnt_a = lowerBound(a, i)
cnt_b = n - upperBound(c, i)
ans += cnt_a * cnt_b
print(ans) | def lowerBound(arr, n):
low, high = -1, len(arr)
while high-low>1:
mid = (low+high)//2
if arr[mid]>=n: high = mid
else: low = mid
return high
def upperBound(arr, n):
low, high = -1, len(arr)
while high-low>1:
mid = (low+high)//2
if arr[mid]>n: high = mid
else: low = mid
return low+1
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:
cnt_a = lowerBound(a, i)
cnt_b = n - upperBound(c,i)
ans += cnt_a * cnt_b
print(ans) | 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()]
a.sort()
b.sort()
c.sort()
c = c[::-1]
answer,x,y = 0,0,0
for j in b:
for k in range(x,n):
if a[k] >= j:
x = k
break
elif k == n-1:
x = n
for k2 in range(n):
if c[k2] <= j:
y = k2
break
elif k2 == n-1:
y = n
answer += x*y
print(answer)
| 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()
answer = 0
for i in b:
x = bisect.bisect_right(c,i)
y = bisect.bisect_left(a,i)
answer += (n-x)*y
print(answer) | 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())))
sm=0
for i in C:
b=bisect.bisect_left(B,i)
for j in B[:b]:
sm+=bisect.bisect_left(A,j)
print(sm)
| 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())))
sm=0
for j in B:
sm+=bisect.bisect_left(A,j)*(n-bisect.bisect_right(C,j))
print(sm)
| p03557 |
import bisect
N = int(eval(input()))
A = list(map(int, input().split()))
B = sorted(list(map(int, input().split())))
l_b = len(B)
C = sorted(list(map(int, input().split())))
l_c = len(C)
ans = 0
for a in A:
i = bisect.bisect_right(B, a)
for j in range(i, l_b):
num = bisect.bisect_right(C, B[j])
ans += l_c - num
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())))
l_c = len(C)
ans = 0
for b in B:
n_a = bisect.bisect_left(A, b)
n_c = l_c - bisect.bisect_right(C, b)
ans += n_a*n_c
print(ans)
| p03557 |
N = int(eval(input()))
A = [int(a) for a in input().split(" ")]
B = [int(b) for b in input().split(" ")]
C = [int(c) for c in input().split(" ")]
A.sort()
B.sort()
C.sort()
combiBC = [0] * len(B)
# combiBC[i] : number of combination of B, C when B[i] is selected
ic = 0
lc = len(C)
for ib in range(len(B)):
b = B[ib]
while ic < lc:
c = C[ic]
if b >= c:
ic += 1
else:
combiBC[ib] = lc - ic
break
cnt = 0
ib = 0
for ia in range(len(A)):
a = A[ia]
while ib < len(B):
b = B[ib]
if a >= b:
ib += 1
else:
cnt += sum(combiBC[ib:])
break
print(cnt) | N = int(eval(input()))
A = [int(a) for a in input().split(" ")]
B = [int(b) for b in input().split(" ")]
C = [int(c) for c in input().split(" ")]
A.sort()
B.sort()
C.sort()
combiBC = [0] * len(B)
# combiBC[i] : number of combination of B, C when B[i] is selected
ic = 0
lc = len(C)
for ib in range(len(B)):
b = B[ib]
while ic < lc:
c = C[ic]
if b >= c:
ic += 1
else:
combiBC[ib] = lc - ic
break
sumCombiBC = []
for i in range(len(combiBC)):
if i == 0:
sumCombiBC.append(combiBC[-1])
else:
sumCombiBC.insert(0, combiBC[-i-1] + sumCombiBC[0])
cnt = 0
ib = 0
for ia in range(len(A)):
a = A[ia]
while ib < len(B):
b = B[ib]
if a >= b:
ib += 1
else:
cnt += sumCombiBC[ib]
break
print(cnt) | p03557 |
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))
N = ii()
S = [sorted(li()) for _ in range(3)]
rec = [[0]*N for i in range(2)]
for i in range(N):
for j in range(2):
rec[j][i] = bisect.bisect_right(S[j+1], S[j][i])
ans = 0
for i in range(N):
for j in range(rec[0][i], N):
ans += N - rec[1][j]
print(ans) | import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
from itertools import accumulate #list(accumulate(A))
N = ii()
S = [sorted(li()) for _ in range(3)]
rec = [[0]*N for i in range(3)]
for i in range(N):
#for j in range(2):
#rec[0][i] = bisect.bisect_right(S[1], S[0][i])
rec[1][i] = N - bisect.bisect_right(S[2], S[1][i])
acc = list(accumulate(rec[1]))
#acc_1 = [0] * N
#for i in range(N):
#ind = bisect.bisect_right(S[2], acc_
ans = 0
for i in range(N):
#for j in range(rec[0][i], N):
ind = bisect.bisect_right(S[1], S[0][i])
if ind == 0:
ans += acc[-1]
else:
ans += acc[-1] - acc[ind-1]
print(ans) | p03557 |
n = eval(input())
top = list(map(int, input().split()))
top.sort()
middle = list(map(int, input().split()))
middle.sort()
under = list(map(int, input().split()))
under.sort()
cnt = 0
for i in top[::-1]:
for j in middle[::-1]:
if j <= i: break
for k in under[::-1]:
if k <= j: break
cnt += 1
# print '{} {} {}'.format(i,j,k)
print(cnt) | # coding:utf-8
INF = float('inf')
def inpl(): return list(map(int, input().split()))
N = int(eval(input()))
A = sorted(inpl())
B = sorted(inpl())
C = sorted(inpl())
ans = 0
i_a = 0
i_c = 0
for i_b in range(N):
while i_a < N and A[i_a] < B[i_b]:
i_a += 1
while i_c < N and C[i_c] <= B[i_b]:
i_c += 1
ans += i_a * (N - i_c)
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()))
ans = 0
for _c in c:
i = bisect.bisect_left(b, _c)
for j in range(i):
ans += bisect.bisect_left(a, b[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:
aNum = bisect.bisect_left(a, _b)
cNum = len(c) - bisect.bisect_right(c, _b)
ans += aNum*cNum
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()))
ans = 0
for _b in b:
aNum = bisect.bisect_left(a, _b)
cNum = len(c) - bisect.bisect_right(c, _b)
ans += aNum*cNum
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:
ans += bisect.bisect_left(a, _b)*(n - bisect.bisect_right(c, _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 range(n):
a = A[i]
for b in B[bisect.bisect_right(B, a):]:
ans += len(C[bisect.bisect_right(C, b):])
print(ans) | import bisect, itertools
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())))
c_num = [0]*n
for i in range(n):
c_num[i] = n - bisect.bisect_right(C, B[i])
c_accum = [0] + list(itertools.accumulate(c_num))
ans = 0
for i in range(n):
b_index = bisect.bisect_right(B, A[i])
ans += (c_accum[-1] - c_accum[b_index])
print(ans) | 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()
cnt = 0
for a in A:
for b in B:
if a >= b:
continue
for c in C:
if b >= c:
continue
cnt += 1
print(cnt)
if __name__ == '__main__':
main() | #!/usr/bin/env python
import bisect
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()
cnt = 0
for b in B:
a_index = bisect.bisect_left(A, b)
c_index = bisect.bisect_right(C, b)
cnt += a_index * (N - c_index)
print(cnt)
if __name__ == '__main__':
main()
| p03557 |
# ABC_077_C_Sunuke_Festival.py
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()))
# B[j]を固定してA[i]<=B[j]<=C[k]を満たす(i,j)の個数を求める
# ソートして二分探索すれば間に合う
A.sort()
# B.sort()
C.sort()
# print(A)
# print(B)
# print(C)
def bisectsearch_left(L, a):
i = bisect_left(L, a)
return(i)
def bisectsearch_right(L, a):
i = bisect_right(L, a)
return(i)
ans = 0
for j in range(N):
b = B[j]
cti = bisectsearch_left(A, b)
ctk = N-bisectsearch_right(C, b)
# print(cti, ctk)
ans += cti*ctk
print(ans)
| from bisect import bisect_right, 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()
c.sort()
ans=0
for i in range(N):
s=b[i]
k=bisect_left(a,s)*(N-bisect_right(c,s))
ans+=k
print(ans) | p03557 |
import bisect
from itertools import accumulate
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
b_to_c = [0]*n
for i in range(n):
b_to_c[i] = n - bisect.bisect_right(C, B[i])
Q = list(accumulate(b_to_c[::-1]))[::-1]
for i in A:
t = bisect.bisect_right(B, i)
if t < n:
ans += Q[t]
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()))
#A2 = sorted(A)
#B2 = sorted(B)
#C2 = sorted(C)
def numadd(up, down):
array = []
count = 0
last = 0
for i in range(0,N):
while down[i] > up[count]:
count = count + 1
if count == N:
count = count - 1
last = 1
break
array.append(count + last)
return array
B3 = numadd(sorted(A),sorted(B))
C3 = numadd(sorted(B),sorted(C))
B4 = [B3[0]]
for i in range(0,N-1):
B4.append(B4[i] + B3[i+1])
ans = 0
for i in range (0,N):
if C3[i] > 0:
ans = ans + B4[C3[i]-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()))
A2 = sorted(A)
B2 = sorted(B)
C2 = sorted(C)
A2.append(2000000000)
B2.append(2000000000)
def numadd(up, down):
array = []
count = 0
for i in range(0,N):
while down[i] > up[count]:
count = count + 1
array.append(count) #+ last)
return array
B3 = numadd(A2,B2)
C3 = numadd(B2,C2)
B4 = [B3[0]]
for i in range(0,N-1):
B4.append(B4[i] + B3[i+1])
ans = 0
for i in range (0,N):
if C3[i] > 0:
ans = ans + B4[C3[i]-1]
print(ans) | p03557 |
import bisect
n = int(eval(input()))
a,b,c = [sorted(map(int,input().split())) for _ in "abc"]
print((sum([bisect.bisect_left(a,x)*(n-bisect.bisect_right(c,x)) for x in b]))) | 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())))
print((sum(bisect_left(A,b)*(N-bisect_right(C,b)) for b in B))) | p03557 |
#-*-coding:utf-8-*-
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()))
a_list.sort()
b_list.sort()
c_list.sort()
cnt = 0
for i in range(n):
for j in range(n):
if a_list[i] < b_list[j]:
position = bisect.bisect_right(c_list, b_list[j])
cnt += n - position
print(cnt)
if __name__ == '__main__':
main() | #-*-coding:utf-8-*-
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()))
a_list.sort()
b_list.sort()
c_list.sort()
cnt = 0
for b in b_list:
i = bisect.bisect_left(a_list, b)
j = n - bisect.bisect_right(c_list, b)
cnt += i * j
print(cnt)
if __name__ == '__main__':
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()
C.sort()
ans = 0
for b in B:
ai = bisect.bisect_left(A,b)
ci = bisect.bisect(C,b)
ans += ai*(N-ci)
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:
ai = bisect.bisect_left(A, b)
ci = bisect.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())))
a_n = [0] * n
b_n = [0] * n
for i in range(n):
a_n[i] = bisect.bisect_right(b, a[i])
for i in range(n):
b_n[i] = n - bisect.bisect_right(c, b[i])
ans = 0
for i in a_n:
ans += sum(b_n[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())))
a_n = [0] * n
b_n = [0] * n
for i in range(n):
a_n[i] = bisect.bisect_right(b, a[i])
for i in range(n):
b_n[i] = n - bisect.bisect_right(c, b[i])
ans = 0
b_n_t = [0]
for i in range(n):
b_n_t.append(b_n[i] + b_n_t[i])
for i in a_n:
ans += b_n_t[-1] - b_n_t[i]
print(ans) | p03557 |
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc077/tasks/arc084_a
"""
import sys
from sys import stdin
from bisect import bisect_left, bisect_right
from functools import lru_cache
input = stdin.readline
@lru_cache(maxsize=None)
def calc(i):
ans = 0
for b in B[i:]:
j = lut_B[b]
if j == N:
break
ans += (N - j)
return ans
lut_B = {}
B = []
N = 0
def main(args):
global lut_B
global B
global N
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()
lut_A = {a:bisect_right(B, a) for a in A}
lut_B = {b:bisect_right(C, b) for b in B}
ans = 0
for a in A:
i = lut_A[a]
if i == N:
break
ans += calc(i)
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
| # -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc077/tasks/arc084_a
"""
import sys
from sys import stdin
from bisect import bisect_left, bisect_right
input = stdin.readline
def main(args):
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()
lut_A = {}
lut_C = {}
for b in B:
i = bisect_left(A, b)
lut_A[b] = i
j = bisect_right(C, b)
lut_C[b] = N - j
ans = 0
for b in B:
i = lut_A[b]
j = lut_C[b]
ans += i * j
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
| p03557 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.