Problem:
 Score : 300 points    Problem Statement The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.  He has N parts for each of the three categories. The size of the i -th upper part is A_i , the size of the i -th middle part is B_i , and the size of the i -th lower part is C_i .  To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.  How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.      Constraints  1 \leq N \leq 10^5  1 \leq A_i \leq 10^9(1\leq i\leq N)  1 \leq B_i \leq 10^9(1\leq i\leq N)  1 \leq C_i \leq 10^9(1\leq i\leq N)  All input values are integers.         Input Input is given from Standard Input in the following format:  N  A_1  ...  A_N  B_1  ...  B_N  C_1  ...  C_N       Output Print the number of different altars that Ringo can build.        Sample Input 1 2
1 5
2 4
3 6      Sample Output 1 3  The following three altars can be built:   Upper: 1 -st part, Middle: 1 -st part, Lower: 1 -st part  Upper: 1 -st part, Middle: 1 -st part, Lower: 2 -nd part  Upper: 1 -st part, Middle: 2 -nd part, Lower: 2 -nd part        Sample Input 2 3
1 1 1
2 2 2
3 3 3      Sample Output 2 27       Sample Input 3 6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288      Sample Output 3 87

Solution (Python):





from bisect import bisect_left, bisect_right
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


N = read_a_int()
A = read_ints()
B = read_ints()
C = read_ints()

A.sort()
C.sort()

ans = 0
for b in B:
    ans += bisect_left(A, b) * (N - bisect_right(C, b))
    
print(ans)

Solution (Python):





from bisect import bisect_left, bisect_right
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


N = read_a_int()
A = read_ints()
B = read_ints()
C = read_ints()

A.sort()
C.sort()

ans = 0
for b in B:
    ans += bisect_left(A, b) * (N - bisect_right(C, b))
    
print(ans)

Solution (Python):





from bisect import bisect_left, bisect_right
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


N = read_a_int()
A = read_ints()
B = read_ints()
C = read_ints()

A.sort()
B.sort()
C.sort()

ans = 0
for b in B:
    ans += bisect_left(A, b) * (N - bisect_right(C, b))
    
print(ans)

Solution (Python):
from bisect import bisect_left, bisect_right

n = int(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 = sorted(a)
c = sorted(c)
ans = 0
for i in range(n):
    ans += (bisect_left(a, b[i])) * (n - bisect_right(c, b[i]))
print(ans)

Solution (Python):
import bisect

def snukefestival(n , a , b , c):

    ans = 0
    a.sort()
    b.sort()
    c.sort()

    for i in b:
        ab = bisect.bisect_left(a , i)
        cb = bisect.bisect_right(c , i)
        ans += ab * (len(b) - cb)

    return ans

def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int , input().split()))
    print(snukefestival(n , a , b , c))

if __name__ == '__main__':
    main()

Solution (Python):
from bisect import bisect_left, bisect_right


def main():
    N = int(input())
    parts = [sorted(list(map(int, input().split()))) for _ in range(3)]
    answer = 0
    for b in parts[1]:
        a = bisect_left(parts[0], b)
        c = bisect_right(parts[2], b)
        answer += a * (N - c)
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
from bisect import bisect_left as bl
from bisect import bisect_right as br
n = int(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()
ans = 0
for i in range(n): ans += bl(a,b[i])*(n-br(c,b[i]))
print(ans)

Solution (Python):
import bisect

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
b.sort()
c.sort()
y = 0
bc = [0]
for i in range(1, n+1):
    bc.append(bc[-1] + n - bisect.bisect_right(c, b[-i]))
bc.reverse()
for i in a:
    y += bc[bisect.bisect_right(b, i)]
print(y)

Solution (Python):
n = int(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()

idx = 0
cnt = [0]*n
for i in range(n):
    while b[i] >= c[idx] and idx + 1 < n: idx += 1
    if b[i] >= c[idx]: break
    cnt[i] = n-idx

for i in range(n-1)[::-1]: cnt[i] += cnt[i+1]

idx = 0
ans = 0
for i in range(n):
    while a[i] >= b[idx] and idx + 1 < n: idx += 1
    if a[i] >= b[idx]: break
    ans += cnt[idx]

print(ans)

Solution (Python):
import numpy as np
N = int(input())
A = np.array(input().split(), dtype=int)
B = np.array(input().split(), dtype=int)
C = np.array(input().split(), dtype=int)
A.sort()
B.sort()
C.sort()

CB = np.searchsorted(B, C, side="left")
BA = np.searchsorted(A, B, side="left")
tmp = [0]+BA.cumsum().tolist()
tmp = np.array(tmp)

ans = tmp[CB].sum()
print(ans)

Solution (Python):
import bisect
N=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))
ans=0
Br=[0]*N
for i in range(N):
    t=bisect.bisect_left(A,B[i])
    if(i==0):
        Br[i]=t
    else:
        Br[i]=Br[i-1]+t
for i in range(N):
    t=bisect.bisect_left(B,C[i])
    if(t==0):
        continue
    ans+=Br[t-1]
print(ans)

Solution (Python):
N = int(input())
A = sorted(map(int, input().split()))
B = sorted(list(map(int, input().split())))
C = sorted(map(int, input().split()))
import bisect
ans = 0
 
for i in B:
    iA = bisect.bisect_left(A, i)
    iB = bisect.bisect_right(C, i)
    ans += (iA)*(N-iB)
print(ans)

Solution (Python):
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A.sort()
A = np.array(A)
B = list(map(int, input().split()))
B.sort()
B = np.array(B)
C = list(map(int, input().split()))
C.sort()
C = np.array(C)

cnt_A = np.searchsorted(A,B,side='left')
cnt_C = np.searchsorted(C,B,side='right')

ans = (cnt_A * (N-cnt_C)).sum()

print(ans)

Solution (Python):
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A.sort()
A = np.array(A)
B = list(map(int, input().split()))
B.sort()
B = np.array(B)
C = list(map(int, input().split()))
C.sort()
C = np.array(C)

ans = 0
for i in range(N):
	b = B[i]
	a_ind = np.searchsorted(A,b,side='left')
	c_ind = np.searchsorted(C,b,side='right')
	ans += a_ind * (N-c_ind)

print(ans)

Solution (Python):
import bisect
n = int(input())
*a, = map(int, input().split())
*b, = map(int, input().split())
*c, = 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)

Solution (Python):
from bisect import bisect_left, bisect_right

n = int(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)
ans = 0
for i in range(n):
    ans += (bisect_left(a, b[i])) * (n - bisect_right(c, b[i]))
print(ans)

Solution (Python):

def lower_bound(al, key):
    """
    一般に左側が満たしておらず、右側は満たしている判定基準(境目は一つ)ならlower_boundになる
    (条件を満たすもののうち、最小のインデックスを返す)
    単調にさえなっていれば、左右が逆になっていても検索には使える(ng/okも一緒に逆にする必要がある)
    """
    def isOk(a):
        
        
        return a>=key

    ng = -1
    ok = len(al)

    while abs(ok-ng)>1:
        mid = (ok+ng)//2

        if isOk(al[mid]):
            ok = mid
        else:
            ng = mid

    return ok

n = int(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()

res = 0
for b in bl:
    na = lower_bound(al, b)
    nc = n - lower_bound(cl, b+1)
    res += na*nc
print(res)

Solution (Python):
import sys

input = sys.stdin.readline

n = int(input())
a = [list(map(int, input().split())) for _ in range(3)]
a[0].sort()
a[2].sort()


def bin_chisaimono(b):
    if a[0][0] >= b:
        return 0
    pl = 0
    pr = n - 1

    while True:
        pc = (pl + pr) // 2
        if pc == n - 1 and a[0][pc] < b:
            return n
        elif a[0][pc] < b <= a[0][pc + 1]:
            return pc + 1
        elif a[0][pc] >= b:
            pr = pc - 1
        else:
            pl = pc + 1


def bin_okimono(b):
    if a[2][n - 1] <= b:
        return 0
    pl = 0
    pr = n - 1

    while True:
        pc = (pl + pr) // 2
        if pc == 0 and a[2][pc] > b:
            return n
        elif a[2][pc - 1] <= b < a[2][pc]:
            return n - pc
        elif a[2][pc] <= b:
            pl = pc + 1
        else:
            pr = pc - 1


cnt = 0
for i in range(n):
    cnt += bin_chisaimono(a[1][i]) * bin_okimono(a[1][i])
print(cnt)

Solution (Python):

import sys

input = sys.stdin.readline


n = int(input())
a = [list(map(int, input().split())) for _ in range(3)]
a[0].sort()
a[2].sort()

def bin_chisaimono(b):
    if a[0][0] >= b:
        return 0
    pl = 0
    pr = n - 1

    while True:
        pc = (pl + pr) // 2
        if pc == n - 1 and a[0][pc] < b:
            return n
        elif a[0][pc] < b <= a[0][pc + 1]:
            return pc + 1
        elif a[0][pc] >= b:
            pr = pc -1
        else:
            pl = pc + 1


def bin_okimono(b):
    if a[2][n - 1] <= b:
        return 0
    pl = 0
    pr = n - 1

    while True:
        pc = (pl + pr) // 2
        if pc == 0 and a[2][pc] > b:
            return n
        elif a[2][pc - 1] <= b < a[2][pc]:
            return n - pc
        elif a[2][pc] <= b:
            pl = pc + 1
        else:
            pr = pc - 1


cnt = 0
for i in range(n):
    cnt += bin_chisaimono(a[1][i]) * bin_okimono(a[1][i])
print(cnt)

Solution (Python):
def sup(A, j):
	if A[0] >= j:
		return 0
	l = 0
	r = len(A) - 1
	while True:
		i = (l+r) // 2
		if i == len(A) - 1 and A[i] < j:
			return len(A)
		elif A[i]<j and A[i+1]>=j:
			return i+1
		else:
			if A[i] >= j:
				r = i-1
			else: 
				l = i+1		

def inf(A, j): 
    if A[-1] <= j:
        return 0
    l = 0
    r = len(A) - 1
    while True:
        i = (l+r) // 2
        if i == 0 and A[i]>j:
            return len(A)
        elif A[i]>j and A[i-1]<=j:
            return len(A)-i
        else:
            if A[i] <= j:
                l = i+1
            else: 
                r = i-1		

N = int(input())
[A, B, C] = [sorted([int(i) for i in input().split()]) for j in range(3)]
ans = 0
for j in B:
	ans += sup(A, j) * inf(C, j)
print(ans)

Solution (Python):
import bisect

N = int(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:
    cnt_a = bisect.bisect_left(A, b)
    cnt_c = N - bisect.bisect_right(C, b)
    ans += cnt_a * cnt_c

print(ans)

Solution (Python):
from bisect import bisect_left

N = int(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()

ba = [0]*N
for i in range(N):
	ba[i] = bisect_left(A, B[i])

for i in range(N-1):
	ba[i+1] += ba[i]

ans = 0
for i in range(N):
	t = bisect_left(B,C[i])
	if t<=0:
		continue
	ans += ba[t-1]

print(ans)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = sorted(inpl())
b = sorted(inpl())
c = sorted(inpl())
x = [0] * n
for i in range(n):
    x[i] = bisect.bisect_left(a,b[i])
xx = [0] * (n+1)
xx[0] = 0
xx[1] = x[0]
for i in range(1,n):
    xx[i+1] = xx[i] + x[i] 

res = 0
for i in range(n):
    tmp = bisect.bisect_left(b,c[i])
    res += xx[tmp]
print(res)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
B.sort()
C=list(map(int,input().split()))
C.sort()
from bisect import bisect_right
ret=0
Cb=[0]*(N+1)
for i in range(N):
  Cb[i]=N-bisect_right(C,B[i])
for i in range(N-1,-1,-1):
  Cb[i]+=Cb[i+1]
for a in A:
  bi=bisect_right(B,a)
  ret+=Cb[bi]
print(ret)

Solution (Python):
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
C.sort()

ans = 0

for b in B:
  a = bisect.bisect_left(A, b)
  c = bisect.bisect_right(C, b)

  ans += a * (len(C) - c)

print(ans)

Solution (Python):
import bisect
n = int(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:
    lower = bisect.bisect_left(a, i)
    higher = n - (bisect.bisect_right(c, i))
    ans += lower * higher

print(ans)

Solution (Python):
import bisect
N=int(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))

Solution (Python):
import sys
input=sys.stdin.readline
from bisect import bisect_right, bisect_left
n=int(input())
a = [list(map(int, input().split())) for _ in range(3)]
a[0].sort()
a[2].sort()



cnt=0
for i in range(n):
    index_1 = bisect_left(a[0],a[1][i])
    index_2 = n-bisect_right(a[2],a[1][i])
    cnt+=index_1*index_2
print(cnt)

Solution (Python):
from bisect import bisect_left, bisect_right

n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
ba = [bisect_left(a, bi) for bi in b]
bc = [bisect_right(c, bi) for bi in b]
cnt = 0
for i in range(n):
    cnt += ba[i] * (n - bc[i])
print(cnt)

Solution (Python):
import bisect
import sys
input = sys.stdin.readline

n = int(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:
    ans += bisect.bisect_left(a,i)*(n-bisect.bisect_right(c,i))
print(ans)

Solution (Python):
import bisect

n = int(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:
    ans += bisect.bisect_left(a,i)*(n-bisect.bisect_right(c,i))
print(ans)

Solution (Python):
import bisect
N = int(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:
    a = bisect.bisect_left(A,i)
    b = N - bisect.bisect_right(C,i)
    ans += a*b
print(ans)

Solution (Python):
import bisect
N=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))
ans=0
for i in B:
  a=bisect.bisect_left(A,i)
  b=N-bisect.bisect_right(C,i)
  ans+=a*b
print(ans)

Solution (Python):
import bisect

n = int(input())
aList = sorted(list(map(int,input().split())))
bList = sorted(list(map(int,input().split())))
cList = sorted(list(map(int,input().split())))




count = 0
for i in bList:
  idxA = bisect.bisect_left(aList,i)
  idxC = bisect.bisect_right(cList,i)



  count += (idxA)*(n-idxC)

print(count)

Solution (Python):

from bisect import bisect_left
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

n = int(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:
    smallPos = bisect_left(a, i)
    BigPos = bisect_left(c, i+1)
    ans += smallPos*(n-BigPos)
print(ans)

Solution (Python):
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

nA = nC = 0
ans = 0
for i, b in enumerate(B):
    while nA<N and A[nA]< b: nA += 1
    while nC<N and C[nC]<=b: nC += 1
    ans += nA*(N-nC)

print(ans)

Solution (Python):
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
B = list(map(int, input().split()))
C = sorted(list(map(int, input().split())))

def binary_search(x, lst, l , r):
    while l < r:
        mid = (l + r) // 2
        mid_val = lst[mid]
        if x == mid_val:
            return mid - 1
        elif x < mid_val:
            r = mid - 1
        else:
            l = mid + 1
    else:
        return l

ans = 0
for i in range(N):
    max_ab = bisect.bisect_left(A, B[i])
    max_bc = N - bisect.bisect_right(C, B[i])
    ans += (max_ab * max_bc)
print(ans)

Solution (Python):
from bisect import bisect_right
from bisect import bisect_left

n = int(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:
    j=bisect_left(a,i)
    an=j
    k=bisect_right(c,i)
    cn=max(0,n-k)
    ans+=an*cn
print(ans)

Solution (Python):
import bisect

N = int(input(), 10)

heads = list(sorted(map(int,input().split())))
bodies = list(map(int,input().split()))
legs = list(sorted(map(int,input().split())))


cnt = 0
for body in bodies:
    
    head_cnt = bisect.bisect_left(heads, body)
    
    leg_cnt = N - bisect.bisect_right(legs, body)

    cnt += head_cnt * leg_cnt 

print(cnt)

Solution (Python):
N=int(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 B:
  a=bisect.bisect_left(A,i)
  b=N-bisect.bisect_right(C,i)
  ans+=a*b
print(ans)

Solution (Python):
import bisect

n = int(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()

ans = 0
for b in li_b:
    aa = bisect.bisect_left(li_a, b)
    cc = len(li_c) - bisect.bisect_right(li_c, b)
    ans += aa * cc

print(ans)

Solution (Python):
import numpy as np
import sys
import bisect
sys.setrecursionlimit(10 ** 7)



N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

'''
A = np.array(input().split(), dtype=np.int64)
B = np.array(input().split(), dtype=np.int64)
C = np.array(input().split(), dtype=np.int64)
'''

A.sort()
B.sort()
C.sort()

cntB = [0] * (N+1)


for i in range(N):
    b = bisect.bisect_right(C, B[i])
    cntB[i+1] = cntB[i] + N - b


ans = 0
for i in range(N):
    a = bisect.bisect_right(B, A[i])
    c = cntB[N] - cntB[a]
    ans += c

print(ans)

Solution (Python):
import bisect
N = int(input())
A = [int(x) for x in input().split()]
B = [int(y) for y in input().split()]
C = [int(z) for z in input().split()]
centertoover = [0] * N  
undertocenter = [0] * N  
sort_A = sorted(A)
sort_B = sorted(B)
sum = 0
sum_B = [0]*N
for i in range(N):
    sum += bisect.bisect_left(sort_A, sort_B[i])
    sum_B[i] += sum
ans = 0

for j in range(N):
    index = bisect.bisect_left(sort_B, C[j])
    if index != 0:
        ans += sum_B[index-1]

print(ans)

Solution (Python):
from bisect import bisect_left,bisect_right
n=int(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):
    ai=bisect_left(a,b[i])
    ci=bisect_right(c,b[i])
    ans+=ai*(n-ci)
print(ans)

Solution (Python):
from bisect import bisect_right
from bisect import bisect_left

N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
answer = 0
for i in range(N):
    x1 = bisect_left(A, B[i])
    x2 = bisect_right(C, B[i])
    
    answer += x1 * (N - x2)

print(answer)

Solution (Python):
from bisect import bisect_right
from bisect import bisect_left
 
n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
cnt = 0
bn = []
for i in range(n):
    x1 = bisect_left(a, b[i])
    x2 = bisect_right(c, b[i])
    cnt += x1*(n-x2)
print(cnt)

Solution (Python):
from bisect import bisect_right
from bisect import bisect_left

n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
cnt = 0
bn = []
for i in range(n):
    x1 = bisect_left(a, b[i])
    x2 = bisect_right(c, b[i])
    cnt += x1*(n-x2)
print(cnt)

Solution (Python):
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)







from itertools import accumulate



def C(x, ub):
    return x < ub


def resolve():
    
    N = [int(x) for x in sys.stdin.readline().split()][0]  
    
    a_list = [int(x) for x in sys.stdin.readline().split()]  
    b_list = [int(x) for x in sys.stdin.readline().split()]  
    c_list = [int(x) for x in sys.stdin.readline().split()]  

    
    
    
    

    logger.debug('{}'.format([]))

    a_list = sorted(a_list, reverse=True)
    b_list = sorted(b_list, reverse=True)
    c_list = sorted(c_list, reverse=True)

    total_count = 0
    i_b_upper = -1
    i_a_upper = -1

    b_count_list = None
    for c in c_list:
        if b_list[-1] >= c or a_list[-1] >= c:
            break
        i_b_lower = N

        while (i_b_lower - i_b_upper > 1):
            i_b_middle = (i_b_lower + i_b_upper) // 2
            if C(b_list[i_b_middle], c):
                i_b_lower = i_b_middle
            else:
                i_b_upper = i_b_middle

        if b_count_list is None:
            b_count_list = [0 for _ in range(N)]
            for i in range(i_b_lower, N):
                b = b_list[i]
                if a_list[-1] >= b:
                    break
                i_a_lower = N

                while (i_a_lower - i_a_upper > 1):
                    i_a_middle = (i_a_lower + i_a_upper) // 2
                    if C(a_list[i_a_middle], b):
                        i_a_lower = i_a_middle
                    else:
                        i_a_upper = i_a_middle

                b_count_list[i] = N - i_a_lower

                total_count += (N - i_a_lower)

            b_count_list = reversed(b_count_list)
            b_count_list = list(reversed(list(accumulate(b_count_list))))
        else:
            total_count += b_count_list[i_b_lower]

    print(total_count)


if __name__ == "__main__":
    resolve()





import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2
1 5
2 4
3 6"""
        output = """3"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3
1 1 1
2 2 2
3 3 3"""
        output = """27"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288"""
        output = """87"""
        self.assertIO(input, output)


if __name__ == "__main__":
    unittest.main()

Solution (Python):
import sys
input = sys.stdin.readline
N = int(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()]
import bisect
A.sort()
B.sort()
C.sort()
ans = 0
for i in B:
    idx_1 = bisect.bisect_left(A, i)
    idx_2 = N - bisect.bisect(C, i)
    ans += idx_1 * idx_2
print(ans)

Solution (Python):
from bisect import bisect_right, bisect_left

N = int(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_left(A, b) * (N - bisect_right(C, b))

print(ans)

Solution (Python):
from bisect import bisect_right

N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ca = [0] * N
cb = [0] * N

for i in range(N):
  ca[i] = bisect_right(B, A[i])
  cb[i] = N - bisect_right(C, B[i])

cb.append(0)
for i in range(N, 0, -1):
  cb[i-1] += cb[i]

print(sum([cb[i] for i in ca]))

Solution (Python):
import bisect

n = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
ans = 0

for b_i in B:
  top_n = bisect.bisect_left(A, b_i)
  bottom_n = n-bisect.bisect_right(C, b_i)
  ans += top_n*bottom_n
  
print(ans)

Solution (Python):
import bisect

n = int(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)

Solution (Python):
N = int(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 range(N):
    b = B[i]
    x = bisect.bisect_left(A,b)
    y = N - bisect.bisect_right(C,b)
    ans += x*y
print(ans)

Solution (Python):
import bisect

N = int(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)

Solution (Python):
import sys
import bisect

input = sys.stdin.readline


def main():
    N = int(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_ruiseki = [0]

    for i, b in enumerate(B):
        B_ruiseki.append(bisect.bisect_left(A, b) + B_ruiseki[i])

    ans = 0
    for i, c in enumerate(C):
        ans += B_ruiseki[bisect.bisect_left(B, c)]

    print(ans)




    

if __name__ == '__main__':
    main()

Solution (Python):
from bisect import bisect_left, bisect_right

n = int(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):
    idx_a = bisect_left(a, b[i])
    select_b = idx_a

    idx_c = bisect_right(c, b[i])
    select_c = n - idx_c
    ans += select_b * select_c








print(ans)

Solution (Python):
N = int(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)

Solution (Python):
import sys
import bisect
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(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):
    b = B[i]
    num_a = bisect.bisect_left(A, b)
    num_c = N - bisect.bisect_right(C, b)

    ans += num_a * num_c
print(ans)

Solution (Python):
import math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce
import itertools
from collections import defaultdict
import bisect

N = int(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_num = bisect.bisect_right(A,B[i]-1)
    c_num = N-bisect.bisect_left(C,B[i]+1)
    ans += a_num * c_num

print(ans)

Solution (Python):
import bisect
 
n = int(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()
 
ans = 0
for b in bs_:
  ans += bisect.bisect_left(as_, b) * (n-bisect.bisect_right(cs_, b))
print(ans)

Solution (Python):
import bisect
 
n = int(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()
 
ans = 0
for b in bs_:
  ans += bisect.bisect_left(as_, b) * (n-bisect.bisect_right(cs_, b))
print(ans)

Solution (Python):
from itertools import accumulate
from bisect import bisect_left
N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
I = [0] * (N+1)
J = [0] * (N+1)
for i in range(N): I[bisect_left(B, A[i]+1)] += 1
I = list(accumulate(I))
for i in range(N): J[bisect_left(C, B[i]+1)] += I[i]
print(sum(accumulate(J[:-1])))

Solution (Python):

from itertools import product, permutations, combinations
from bisect import bisect_right,bisect_left
N=int(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)

Solution (Python):
from bisect import bisect_right,bisect_left
n=int(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)

Solution (Python):
import bisect

n = int(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)

Solution (Python):
from bisect import bisect_left, bisect_right

N = int(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):
  len_a = bisect_left(A, B[i])
  c_index = bisect_right(C, B[i])
  len_c = N - c_index
  ans += len_a * len_c
print(ans)

Solution (Python):
import bisect
N = int(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_max = bisect.bisect_left(A, b)
    c_min = bisect.bisect_right(C, b)
    ans += a_max * (N - c_min)
print(ans)

Solution (Python):
import bisect
N = int(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 range(N):
    b = B[i]
    cind = bisect.bisect_right(C,b)
    aind = bisect.bisect_left(A,b)
    count+=(N-cind)*aind
print(count)