N = int(eval(input()))

A = [int(x) for x in input().split()]

B = [int(x) for x in input().split()]

C = [int(x) for x in input().split()]



A.sort()

B.sort()

C.sort()

B += [10 ** 9 + 1] + [0]    # B[-1] = 0, B[N] = 10**9 + 1となるようにする

C += [10 ** 9 + 1] + [0]    # C[-1] = 0, C[N] = 10**9 + 1となるようにする



# For each j = 0, 1, ..., N-1,

# find k such that B[j] < C[k] and (C[k-1] <= B[j] or k = 0)

# Let K[j] = k for such k.

# If such k doesn't exist, let K[j] := N

K = [0] * N



for j in range(N):

    ng = -1 # C[ng] <= B[j]

    ok = N  # B[j] < C[ok]

    while ok - ng > 1:

        mid = (ok + ng) // 2

        if B[j] < C[mid]:

            ok = mid

        else:

            ng = mid

    K[j] = ok



# Let

# f[j] := B[j]より大きいC[k]の数 + B[j + 1]より大きいC[k]の数

#           ... + B[N-1]より大きいC[k]の数

f = [0] * (N - 1) + [N - K[N - 1]]

for j in range(N - 2, -1, -1):

    f[j] = f[j + 1] + N - K[j]



ans = 0

for i in range(N):

    # find j such that B[j - 1] <= A[i] < B[j]

    ng = -1  # B[ng] <= A[i]

    ok = N   # A[i] < B[ok]

    while ok - ng > 1:

        mid = (ok + ng) // 2

        if A[i] < B[mid]:

            ok = mid

        else:

            ng = mid

    if ok >= N: continue

    # 0 <= ok <= N - 1

    ans += f[ok]



print(ans)
import bisect



N = int(eval(input()))

A = [int(x) for x in input().split()]

B = [int(x) for x in input().split()]

C = [int(x) for x in input().split()]



A.sort()

B.sort()

C.sort()



ans = 0

for j in range(N):

    i = bisect.bisect_left(A, B[j])

    k = bisect.bisect_right(C, B[j])

    ans += i * (N - k)



print(ans)
N = int(eval(input()))
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
A.sort()
B.sort()
C.sort()
B += [10**9 + 1] + [0]  # B[-1] = 0, B[N] = 10**9 + 1となるようにする
C += [10**9 + 1] + [0]  # C[-1] = 0, C[N] = 10**9 + 1となるようにする
# For each j = 0, 1, ..., N-1,
# find k such that B[j] < C[k] and (C[k-1] <= B[j] or k = 0)
# Let K[j] = k for such k.
# If such k doesn't exist, let K[j] := N
K = [0] * N
for j in range(N):
    ng = -1  # C[ng] <= B[j]
    ok = N  # B[j] < C[ok]
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if B[j] < C[mid]:
            ok = mid
        else:
            ng = mid
    K[j] = ok
# Let
# f[j] := B[j]より大きいC[k]の数 + B[j + 1]より大きいC[k]の数
#           ... + B[N-1]より大きいC[k]の数
f = [0] * (N - 1) + [N - K[N - 1]]
for j in range(N - 2, -1, -1):
    f[j] = f[j + 1] + N - K[j]
ans = 0
for i in range(N):
    # find j such that B[j - 1] <= A[i] < B[j]
    ng = -1  # B[ng] <= A[i]
    ok = N  # A[i] < B[ok]
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if A[i] < B[mid]:
            ok = mid
        else:
            ng = mid
    if ok >= N:
        continue
    # 0 <= ok <= N - 1
    ans += f[ok]
print(ans)

import bisect

N = int(eval(input()))
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
A.sort()
B.sort()
C.sort()
ans = 0
for j in range(N):
    i = bisect.bisect_left(A, B[j])
    k = bisect.bisect_right(C, B[j])
    ans += i * (N - k)
print(ans)

+import bisect + -B += [10**9 + 1] + [0]  # B[-1] = 0, B[N] = 10**9 + 1となるようにする -C += [10**9 + 1] + [0]  # C[-1] = 0, C[N] = 10**9 + 1となるようにする -# For each j = 0, 1, ..., N-1, -# find k such that B[j] < C[k] and (C[k-1] <= B[j] or k = 0) -# Let K[j] = k for such k. -# If such k doesn't exist, let K[j] := N -K = [0] * N +ans = 0 -    ng = -1  # C[ng] <= B[j] -    ok = N  # B[j] < C[ok] -    while ok - ng > 1: -        mid = (ok + ng) // 2 -        if B[j] < C[mid]: -            ok = mid -        else: -            ng = mid -    K[j] = ok -# Let -# f[j] := B[j]より大きいC[k]の数 + B[j + 1]より大きいC[k]の数 -#           ... + B[N-1]より大きいC[k]の数 -f = [0] * (N - 1) + [N - K[N - 1]] -for j in range(N - 2, -1, -1): -    f[j] = f[j + 1] + N - K[j] -ans = 0 -for i in range(N): -    # find j such that B[j - 1] <= A[i] < B[j] -    ng = -1  # B[ng] <= A[i] -    ok = N  # A[i] < B[ok] -    while ok - ng > 1: -        mid = (ok + ng) // 2 -        if A[i] < B[mid]: -            ok = mid -        else: -            ng = mid -    if ok >= N: -        continue -    # 0 <= ok <= N - 1 -    ans += f[ok] +    i = bisect.bisect_left(A, B[j]) +    k = bisect.bisect_right(C, B[j]) +    ans += i * (N - k)