CodeEff/ECCO huggingface dataset:
# Original solution
def main():
    from bisect import bisect_left
    from bisect import bisect_right

    N = int(eval(input()))

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

    print((sum([bisect_left(A, Bi) * (N - bisect_right(C, Bi)) for Bi in B])))
    return


main()


# Optimized solution
def main():
    from bisect import bisect_left
    from bisect import bisect_right

    N = int(eval(input()))

    An = list(map(int, input().split()))
    Bn = list(map(int, input().split()))
    Cn = list(map(int, input().split()))

    A = sorted(An)
    B = sorted(Bn)
    C = sorted(Cn)

    print((sum([bisect_left(A, Bi) * (N - bisect_right(C, Bi)) for Bi in B])))
    return


main()
# Original solution
def main():
    N = int(eval(input()))

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

    def lowerBound(a, v):
        # 以上
        return lb(a, 0, len(a), v)

    def upperBound(a, v):
        # より大きい
        # 値をプラス1
        return lb(a, 0, len(a), v + 1)

    def lb(a, l, r, v):
        low = l - 1
        high = r

        while high - low > 1:
            mid = low + high >> 1
            if a[mid] >= v:
                high = mid
            else:
                low = mid

        return high

    print((sum([lowerBound(A, Bi) * (N - upperBound(C, Bi)) for Bi in B])))

    return


main()


# Optimized solution
def main():
    from bisect import bisect_left
    from bisect import bisect_right

    N = int(eval(input()))

    An = sorted(map(int, input().split()))
    Bn = sorted(map(int, input().split()))
    Cn = sorted(map(int, input().split()))

    ans = 0
    lx = 0
    ux = 0

    for Bi in Bn:
        # 以上
        lx = bisect_left(An, Bi, lx, N)

        # より大きい
        ux = bisect_right(Cn, Bi, ux, N)

        ans += lx * (N - ux)

    print(ans)
    return


main()
# Original solution
def main():
    from bisect import bisect_left
    from bisect import bisect_right

    N = int(eval(input()))

    An = sorted(map(int, input().split()))
    Bn = sorted(map(int, input().split()))
    Cn = sorted(map(int, input().split()))

    ans = 0
    lx = 0
    ux = 0

    for Bi in Bn:
        # 以上
        lx = bisect_left(An, Bi, lx, N)

        # より大きい
        ux = bisect_right(Cn, Bi, ux, N)

        ans += lx * (N - ux)

    print(ans)
    return


main()


# Optimized solution
N = int(eval(input()))

An = sorted(map(int, input().split()))
Bn = sorted(map(int, input().split()))
Cn = sorted(map(int, input().split()))


def f(xn, yn, zn):
    tn = [0] * N
    num = 0
    j = N - 1

    for i in range(N - 1, -1, - 1):
        while 0 <= j and xn[i] < yn[j]:
            num += zn[j]
            j -= 1
        tn[i] = num

    return tn


def main():
    Zn = [1] * N

    Zn = f(Bn, Cn, Zn)
    Zn = f(An, Bn, Zn)

    print((sum(Zn)))
    return


main()
# Original solution
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
INF = float("inf")

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

ans = 0
for i in range(N):
    r1 = bisect.bisect_right(B,A[i])
    for j in range(r1,N):
        r2 = bisect.bisect_right(C,B[j])
        ans += N - r2
print(ans)


# Optimized solution
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
INF = float("inf")

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

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

print(ans)
# Original solution
from bisect import bisect_left
from bisect import bisect_right
N = int(eval(input()))
A = sorted(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(map(int, input().split()))
r = 0
for i in range(N):
  ai = bisect_left(A, B[i])
  ci = bisect_right(C, B[i])
  r += len(A[:ai]) * len(C[ci:])
print(r)

# Optimized solution
from bisect import bisect_left
from bisect import bisect_right
N = int(eval(input()))
A = sorted(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(map(int, input().split()))
r = 0
for i in range(N):
  ai = bisect_left(A, B[i])
  ci = bisect_right(C, B[i])
  r += ai * (N - ci)
print(r)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
bidx = 0
cidx = 0
abnums = [0] * (N+1)
bcnums = [0] * (N+1)
idx = 0
for i, a in enumerate(A):
    abnums[i+1] = abnums[i]
    if abnums[i+1] == N:
        continue
    for j, b in enumerate(B[idx:]):
        if a < b:
            abnums[i+1] += 1
        else:
            idx = j + idx
            break

idx = 0
for i, b in enumerate(B):
    bcnums[i+1] = bcnums[i]
    if bcnums[i+1] == N:
        continue
    for j, c in enumerate(C[idx:]):
        if b < c:
            bcnums[i+1] += 1
        else:
            idx = j + idx
            break

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

ans = 0
for n in abnums[1:]:
    ans += bcnums[n]
print(ans)

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
idxa = 0
idxc = 0
ans = 0
for b in range(N):
    while idxa < N and A[idxa] < B[b]:
        idxa += 1
    while idxc < N and B[b] >= C[idxc]:
        idxc += 1
    ans += idxa * (N - idxc)
print(ans)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a=sorted(a)
b=sorted(b)
c=sorted(c)
c.insert(0,-1)
c.append(10**10)
B=[0]*n
ans=0
for i in range(n):
    x=b[i]
    l=0
    r=n+1
    while r-l>1:
        m=(l+r)//2
        if c[m]>x:
            r=m
        elif c[m]<=x:
            l=m
    B[i]=n-l
g=[0]*n


g[n-1]=B[n-1]
for i in range(n-1):
    g[-2-i]=g[-1-i]+B[-2-i]
g.append(0)

b.insert(0,-1)
b.append(10**10)
for i in range(n):
    x=a[i]
    l=0
    r=n+1
    while r-l>1:
        m=(l+r)//2
        if b[m]>x:
            r=m
        elif b[m]<=x:
            l=m
    ans+=g[l]
print(ans)


# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a=sorted(a)
b=sorted(b)
c=sorted(c)
c.insert(0,-1)
c.append(10**10)
a.insert(0,-1)
a.append(10**10)
ans=0
for i in range(n):
    x=b[i]
    l=0
    r=n+1
    while r-l>1:
        m=(l+r)//2
        if a[m]<x:
            l=m
        else:
            r=m
    L=0
    R=n+1
    while R-L>1:
        M=(L+R)//2
        if c[M]<=x:
            L=M
        else:
            R=M
    ans+=l*(n+1-R)
print(ans)
# Original solution
from collections import deque

n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

q = deque()
for i in a:
    q.append([i])

ans = 0
while q:
    now = q.popleft()
    n = len(now)
    if n == 3:
        ans += 1
    elif n == 2:
        for x in c:
            if now[-1] < x:
                q.append(now + [x])
    elif n == 1:
        for y in b:
            if now[-1] < y:
                q.append(now + [y])

print(ans)


# Optimized solution
import bisect

n = int(eval(input()))
a = sorted(list(map(int, input().split())))
b = list(map(int, input().split()))
c = sorted(list(map(int, input().split())))

ans = 0
for i in b:
    a_pos = bisect.bisect_left(a, i)
    c_pos = n - bisect.bisect_right(c, i)
    ans += a_pos * c_pos

print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

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

ans = 0

for b in B:
    l = -1
    r = N
    while r - l > 1:
        m = (r + l) // 2
        if A[m] < b:
            l = m
        else:
            r = m
    a_cnt = l + 1 if l != -1 else 0

    l = -1
    r = N
    while r - l > 1:
        m = (r + l) // 2
        if C[m] > b:
            r = m
        else:
            l = m
    c_cnt = N - r

    ans += a_cnt * c_cnt

print(ans)


# Optimized solution
import sys

input = sys.stdin.readline

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


def count_a(A, X):
    l = -1
    r = N
    while r - l > 1:
        m = (r + l) // 2
        if A[m] < b:
            l = m
        else:
            r = m
    return l + 1


def count_c(C, X):
    l = -1
    r = N
    while r - l > 1:
        m = (r + l) // 2
        if C[m] > b:
            r = m
        else:
            l = m
    return N - r


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

ans = 0
A_min = A[0]
C_max = C[-1]

for b in B:
    if b <= A_min or b >= C_max:
        continue

    a_cnt = count_a(A, b)
    if a_cnt == 0:
        continue
    c_cnt = count_c(C, b)

    ans += a_cnt * c_cnt

print(ans)
# Original solution
from bisect import bisect_left, bisect

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

cnt = 0
for i in B:
    #print( A[:bisect_left(A,i)],C[bisect(C,i):])
    cnt += len(A[:bisect_left(A,i)]) *len(C[bisect(C,i):])
    
print(cnt)  

# Optimized solution
from bisect import bisect_left, bisect

n=int(eval(input()))
la=sorted(list(map(int,input().split())))
lb=list(map(int,input().split()))
lc=sorted(list(map(int,input().split())))
ans=0
for i in lb:
    ans+=bisect_left(la,i)*(len(lc)-bisect(lc,i)) #iの挿入点つまりiより小さい値の数×(Cの総数-
print(ans)
# Original solution
N = int(eval(input()))
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))

from bisect import bisect_left, bisect

ans = 0
for i in range(N):
    b = B[i]
    a = bisect_left(A,b)
    c = bisect(C,b)
    #print(b,A[:a],C[c:])
    ans += len(A[:a])*len(C[c:])
print(ans)

# Optimized solution
N = int(eval(input()))
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))

from bisect import bisect_left, bisect

ans = 0
for i in range(N):
    b = B[i]
    a = bisect_left(A,b)
    c = bisect(C,b)
    #print(b,a,c)
    #print(b,A[:a],C[c:])
    ans += a*(N-c)
print(ans)
# Original solution
# coding: utf-8
n = int(eval(input()))
al = sorted(list(int(i) for i in input().split()))
bl = sorted(list(int(i) for i in input().split()))
cl = sorted(list(int(i) for i in input().split()))
ans = 0

def low_left(a, key):
    left = -1
    right = len(a)
    while right - left > 1:
        center = (left + right) // 2
        if a[center] >= key:
            right = center
        else:
            left = center
    return left+1 
    
def high_right(a, key):
    left = -1
    right = len(a)
    while right - left > 1:
        center = (left + right) // 2
        if a[center] <= key:
            left = center
        else:
            right = center
    return n-right
    
for i in bl:
    ans += low_left(al, i) * high_right(cl, i)

print(ans)

# Optimized solution
import bisect

n = int(eval(input()))
al, bl, cl = list(sorted(map(int, input().split())) for i in range(3))
ans = 0

for key in bl:
    top = bisect.bisect_left(al, key)
    btm = len(cl) - bisect.bisect_right(cl, key)
    ans += top * btm

print(ans)
# Original solution
import bisect

n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a = sorted(a)
b = sorted(b)
c = sorted(c)

num_b = [0 for _ in range(n)]
j = 0
for i in range(n):
    if j == n:
        num_b[i] = n
        continue
    while a[j] < b[i]:
        j += 1
        if j == n:
            break
    num_b[i] = j

ans = 0
j = 0
for i in range(n):
    while b[j] < c[i]:
        j += 1
        if j == n:
            ans += (n - i) * sum(num_b)
            break
    if j == n:
        break
    ans += sum(num_b[:j])

print(ans)


# Optimized solution
import bisect

n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a = sorted(a)
b = sorted(b)
c = sorted(c)

num_b = [0 for _ in range(n)]
j = 0
for i in range(n):
    if j == n:
        num_b[i] = n
        continue
    while a[j] < b[i]:
        j += 1
        if j == n:
            break
    num_b[i] = j

ans = 0
j = 0
temp_sum = 0
for i in range(n):
    while b[j] < c[i]:
        temp_sum += num_b[j]
        j += 1
        if j == n:
            ans += (n - i) * sum(num_b)
            break
    if j == n:
        break
    ans += temp_sum

print(ans)
# Original solution
N=int(eval(input()))
arr=[list(map(int,input().split())) for i in range(3)]

count=0

for i in range(N):
    for j in range(N):

        if arr[0][i]<arr[1][j]:
            for k in range(N):

                if arr[1][j]<arr[2][k]:
                    count+=1

print(count)
                

# Optimized solution
N=int(eval(input()))
A,B,C=[list(sorted(map(int,input().split()))) for i in range(3)]

count=0

def bs_l(lis,x):
    low,high=0,len(lis)
    while low<high:
        mid=(low+high)//2
        if lis[mid]<x:
            low=mid+1
        else:
            high=mid
    return low        

def bs_r(lis,x):
    low,high=0,len(lis)
    while low<high:
        mid=(low+high)//2
        if lis[mid]>x:
            high=mid
        else:
            low=mid+1
    return low        

for i in B:
    count+=bs_l(A,i)*(N-bs_r(C,i))


print(count)
# Original solution
import bisect
N = int(eval(input()))
A = sorted(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(map(int, input().split()))
print((sum(len(A[:bisect.bisect_left(A, b)]) * len(C[bisect.bisect(C, b):]) for b in B)))


# Optimized solution
import bisect
N = int(eval(input()))
A = sorted(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(map(int, input().split()))
print((sum(bisect.bisect_left(A, b) * (N - bisect.bisect(C, b)) for b in B)))
# Original solution
import bisect

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

ans = 0
for j in range(len(B)):
    axb = bisect.bisect_left(A, B[j])
    bxc = len(C) - len(C[:bisect.bisect(C, B[j])])
    ans += axb * bxc
print(ans)


# Optimized solution
import bisect

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

print((sum(bisect.bisect_left(A, B[j]) * (N - bisect.bisect(C, B[j])) for j in range(N))))
# Original solution
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 20 10:21:00 2018
ABC077C
@author: maezawa
"""
import bisect

n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
b.sort()
c.sort()

cnt = 0
for ci in c:
    j = bisect.bisect_left(b, ci)
    for bi in b[:j]:
        k = bisect.bisect_left(a, bi)
        #print(ci, bi, k, cnt)
        cnt += k
print(cnt)
    

# Optimized solution
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 20 10:21:00 2018
ABC077C
@author: maezawa
"""
import bisect

n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
b.sort()
c.sort()

bcnt = [0]*n
for i, bi in enumerate(b):
    j = bisect.bisect_left(a, bi)
    if i == 0:
        bcnt[i] = j
    else:
        bcnt[i] = bcnt[i-1] + j
cnt = 0
for i, ci in enumerate(c):
    j = bisect.bisect_left(b, ci)
    if j == 0:
        continue
    else:
        cnt += bcnt[j-1]
    #print(ci, j, bcnt[j-1], cnt)
    
print(cnt)
# Original solution
N = int(eval(input()))
A = [int(i) for i in input().split()]	# 1 2 3 4 5 ...
B = [int(i) for i in input().split()]	# 1 2 3 4 5 ...
C = [int(i) for i in input().split()]	# 1 2 3 4 5 ...

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

#print(A)
#print(B)
#print(C)
##exit(0)

ab=[0]*N
bc=[0]*N

b=N-1
c=N-1
count=0
while (0<=b):
	while (0<=c):
		if B[b]<C[c]:
			count += 1
			c -= 1
		else:
			break
	bc[b] = count
	b -= 1

a=N-1
b=N-1
count=0
while (0<=a):
	while (0<=b):
		if A[a]<B[b]:
			count += 1
			b -= 1
		else:
			break
	ab[a] = count
	a -= 1


#print(ab)
#print(bc)

ans=0

for i in ab:
#	print(i, bc[N-i:N])
	ans += sum(bc[N-i:N])

print(ans)


# Optimized solution
N = int(eval(input()))
A = [int(i) for i in input().split()]	# 1 2 3 4 5 ...
B = [int(i) for i in input().split()]	# 1 2 3 4 5 ...
C = [int(i) for i in input().split()]	# 1 2 3 4 5 ...

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

#print(A)
#print(B)
#print(C)
##exit(0)

ab=[0]*N
bc=[0]*N

b=N-1
c=N-1
count=0
while (0<=b):
	while (0<=c):
		if B[b]<C[c]:
			count += 1
			c -= 1
		else:
			break
	bc[b] = count
	if b<N-1:
		bc[b] += bc[b+1]
	b -= 1

a=N-1
b=N-1
count=0
while (0<=a):
	while (0<=b):
		if A[a]<B[b]:
			count += 1
			b -= 1
		else:
			break
	ab[a] = count
	a -= 1


#print(ab)
#print(bc)

ans=0

for i in ab:
#	print(i, bc[N-i:N])
#	ans += sum(bc[N-i:N])
	if i>0:
		ans += bc[N-i]

print(ans)
# Original solution
import bisect

n=int(eval(input()))
a=[int(i) for i in input().split(" ")]
b=[int(i) for i in input().split(" ")]
c=[int(i) for i in input().split(" ")]

b.sort()
c.sort()
lc=len(c)

print((sum([sum([lc-bisect.bisect_right(c,j) for j in b[bisect.bisect_right(b,i):]]) for i in a])
))

# Optimized solution
import bisect

n=int(eval(input()))
a=[int(i) for i in input().split(" ")]
b=[int(i) for i in input().split(" ")]
c=[int(i) for i in input().split(" ")]

a.sort()
c.sort()
lc=len(c)
print((sum([(lc-bisect.bisect_right(c,j))*(bisect.bisect_left(a,j)) for j in b])))
# Original solution
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)


# Optimized solution

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

A.sort()
C.sort()

def bin_search_withR(vlist, targ):
    lb = -1
    ub = len(vlist)
    while ub - lb > 1:
        mid = (lb + ub) // 2
        if vlist[mid] >= targ:
            ub = mid
        else:
            lb = mid
    return ub, lb

def bin_search_withL(vlist, targ):
    lb = -1
    ub = len(vlist)
    while ub - lb > 1:
        mid = (lb + ub) // 2
        if vlist[mid] > targ:
            ub = mid
        else:
            lb = mid
    return ub, lb

total = 0
for b in B:
    a_ub, a_lb = bin_search_withR(A, b)
    c_ub, c_lb = bin_search_withL(C, b)
    total += a_ub * (N - c_ub)

print(total)
# Original solution
# ABC077C

import bisect

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

bC=[0 for i in range(N)]
for i in range(N):
    bC[i]=N-bisect.bisect(C,B[i])
    
ans=0
for i in range(N):
    x=bisect.bisect(B,A[i])
    for j in range(x,N):
        ans+=bC[j]
        
print(ans)

# Optimized solution
# ABC077C

import bisect

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

bC=[0 for i in range(N)]
for i in range(N):
    bC[i]=N-bisect.bisect(C,B[i])
    
bCS=[0]*(N+1)
for i in range(N):
    bCS[i+1] = bCS[i]+bC[i]
    
ans=0
for i in range(N):
    x=bisect.bisect(B,A[i])
    ans+=bCS[N]-bCS[x]
        
print(ans)
# Original solution
#二分探索
from bisect import bisect_left
#input
N = int(eval(input()))
#print(N)

A = sorted(list(map(int, input().split()))) #この表記について...
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
#print(A,B,C)

#sort 昇順に並び替え
#A.sort()
#B.sort()
#C.sort()
Bis_B = []
for i in range(N):
    Bis_B.append(bisect_left(A,B[i]))

#print(Bis_B)

ans = 0
for i in range(N):
    M = bisect_left(B, C[i])
    if M == 0: #この文で余分な動作を少し減らせる
        continue
    ans += sum(Bis_B[:M]) #この探索を複数回やってしまっている？
print(ans)


# Optimized solution
from bisect import bisect_left
from bisect import bisect_right
#input
N = int(eval(input()))
#print(N)

A = sorted(list(map(int, input().split()))) #この表記について...
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
#print(A,B,C)

#sort 昇順に並び替え
#A.sort()
#B.sort()
#C.sort()
ans = 0
for i in range(N):
    ab = bisect_left(A,B[i])
    bc = N-bisect_right(C,B[i])
    #print(ab, end='  ')
    #print(bc)
    ans += ab*bc
print(ans)
# Original solution
import bisect

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

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

#print(A)
#print(B)
#print(C)

ans = 0
for b in B:
    a = bisect.bisect_right(A, b-1)
    c = N - bisect.bisect_right(C, b)
    #print("smaller",a,"bigger",c)
    ans += a*c

print(ans)

# Optimized solution
import bisect

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

A.sort()
C.sort()

ans = 0
for b in B:
    a = bisect.bisect_right(A, b-1)
    c = len(C)-bisect.bisect_right(C, b)
    ans += a*c
print(ans)
# Original solution
import bisect
n = int(eval(input()))
al = [int(a) for a in input().split()]
bl = [int(b) for b in input().split()]
cl = [int(c) for c in input().split()]

al.sort()
bl.sort()
cl.sort()

k = 0
for a in al:
    for b in bl[bisect.bisect_right(bl, a):]:
        k += n - bisect.bisect_right(cl, b)
print(k)

# Optimized solution
import bisect
n = int(eval(input()))
al = [int(a) for a in input().split()]
bl = [int(b) for b in input().split()]
cl = [int(c) for c in input().split()]

al.sort()
bl.sort()
cl.sort()

k = 0
for b in bl:
    k += bisect.bisect_left(al, b) * (n - bisect.bisect_right(cl, b))
print(k)
# Original solution
n = int(input())
ais = list(map(int, input().split()))
bis = list(map(int, input().split()))
cis = list(map(int, input().split()))


count = 0
ais.sort()
bis.sort()
cis.sort()

for a in ais:
	i,j = 0,0
	while(i < len(bis) and not(bis[i] > a)): i+=1
	while(i < len(bis)):
		while(j < len(cis) and not(cis[j] > bis[i])): j +=1
		if j < len(cis):
			count +=  ( n - j)
		i+=1
print(count)

# Optimized solution
n = int(input())
ais = list(map(int, input().split()))
bis = list(map(int, input().split()))
cis = list(map(int, input().split()))


count = 0
ais.sort()
bis.sort()
cis.sort()

i,j = 0,0
for b in bis:
	while(i < len(ais) and ais[i] < b):
		i += 1
	while(j < len(cis) and cis[j] <= b):
		j += 1
	count += i * (n - j)
print(count)
# Original solution
N = int(eval(input()))
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

from bisect import bisect_left

mids = []
for b in B:
    ind = bisect_left(A, b)
    mids.append(ind)
cs = [0]
for i in range(N):
    cs.append(cs[i]+mids[i])
ans = 0
for c in C:
    ind = bisect_left(B, c)
    ans += cs[ind]
print(ans)


# Optimized solution
N = int(eval(input()))
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

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