CodeEff/ECCO huggingface dataset:
# Original solution
import bisect
N = int(eval(input()))
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
count = 0
# ソートして
for c in C:
  under_c = bisect.bisect_left(B, c)
  for b in B[:under_c]:
    under_b = bisect.bisect_left(A, b)
    count += under_b
print(count)


# Optimized solution
import bisect
N = int(eval(input()))
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
count = 0
# ソートして
for b in B:
  upeer_b = N - bisect.bisect_right(C, b)
  downer_b = bisect.bisect_left(A, b)
  count += upeer_b * downer_b

# for c in C:
#   under_c = bisect.bisect_left(B, c)
#   for b in B[:under_c]:
#     under_b = bisect.bisect_left(A, b)
#     count += under_b

print(count)
# Original solution
# coding: utf-8
import math
N = int(eval(input()))
a_list = [int(x) for x in input().split()]
b_list = [int(x) for x in input().split()]
c_list = [int(x) for x in input().split()]
a_list.sort()
b_list.sort()
c_list.sort()

a_lt_b_index = [N] * N
i = j = 0
while (i < N and j < N):
    if (a_list[i] < b_list[j]):
        a_lt_b_index[i] = j
        i += 1
    else:
        j += 1

b_lt_c_count = [0] * (N+1)
i = j = 0
while (i < N and j < N):
    if (b_list[i] < c_list[j]):
        b_lt_c_count[i] = N-j
        i += 1
    else:
        j += 1

sum_of_b_lt_c = [sum(b_lt_c_count[i:]) for i in range(N+1)]

print((sum([sum_of_b_lt_c[a_lt_b_index[i]] for i in range(N)])))


# Optimized solution
N = int(eval(input()))
A_list = [int(a) for a in input().split()]
B_list = [int(b) for b in input().split()]
C_list = [int(c) for c in input().split()]
A_list.sort()
B_list.sort()
C_list.sort()

i = j = N-1
count_B_gt_A = [0] * N
while i >= 0 and j >= 0:
    if B_list[i] > A_list[j]:
        count_B_gt_A[i] = j+1
        i -= 1
    else:
        j -= 1

i = j = 0
count_B_lt_C = [0] * N
while i < N and j < N:
    if B_list[i] < C_list[j]:
        count_B_lt_C[i] = N - j
        i += 1
    else:
        j += 1
    
result = sum([B_gt_A * B_lt_C for B_gt_A, B_lt_C in zip(count_B_gt_A, count_B_lt_C)])
print(result)
# 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)
z = [0] * N
ans = 0
for i in range(N):
  e = b[i]
  cin = insert_index = bisect.bisect_right(c,e)
  z[i] = N-cin
for i in range(N):
  d = a[i]
  bind = insert_index = bisect.bisect_right(b,d)
  ans += sum(z[bind:])
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)
z = [0] * N
ans = 0
for i in range(N-1,-1,-1):
  e = b[i]
  cin =  bisect.bisect_right(c,e)
  if i + 1 == N:
    z[i] = N-cin
  else:
    z[i] = z[i+1] + N-cin
for i in range(N):
  d = a[i]
  bind =  bisect.bisect_right(b,d)
  if bind == N:
    continue
  ans += z[bind]
print(ans)
# Original solution
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 mid in B:
    n_bottom = len(C[bisect.bisect_right(C,mid):])
    n_top = len(A[:bisect.bisect_left(A,mid)])
    ans += n_bottom * n_top

print(ans)

# Optimized solution
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 mid in B:
    n_bottom = N - bisect.bisect_right(C,mid)
    n_top = bisect.bisect_left(A,mid)
    ans += n_bottom * n_top

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())))
cnt = 0
for i in range(N):
  l, r = 0, 0
  for j in range(N):
    k = i - j
    if(A[j] < B[i]):
      l += 1
    if(B[i] < C[k]):
      r += 1
  cnt += l*r
print(cnt)


# 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())))
a, c, cnt = 0, 0, 0
for b in B:
  while a < N and A[a] < b:
    a += 1
  while c < N and C[c] <= b:
    c += 1
  cnt += a * (N - c)
print(cnt)
# Original solution
import math
import copy
import sys
import fractions
# import numpy as np
# import statistics
import decimal
import heapq
import collections
import itertools
import bisect


# from operator import mul

# sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputIntList():
    outputDataList = []
    inputData = input().split()
    outputDataList = [int(n) for n in inputData]

    return outputDataList

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(eval(input()))
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n = int(eval(input()))
a = getInputIntList()
b = getInputIntList()
c = getInputIntList()

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

ans = 0
for i in range(n):
    x = bisect.bisect_left(b, c[i])
    for j in range(x-1, -1, -1):
        y = bisect.bisect_left(a, b[j])
        ans += y

print(ans)
















# Optimized solution
import math
import copy
import sys
import fractions
# import numpy as np
# import statistics
import decimal
import heapq
import collections
import itertools
import bisect


# from operator import mul

# sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputIntList():
    outputDataList = []
    inputData = input().split()
    outputDataList = [int(n) for n in inputData]

    return outputDataList

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(eval(input()))
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n = int(eval(input()))
a = getInputIntList()
b = getInputIntList()
c = getInputIntList()

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

ans = 0
for tmp in b:
    top = bisect.bisect_left(a, tmp)
    bottom = bisect.bisect_right(c, tmp)
    ans += top * (n-bottom)

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()

ans = 0
for b in B:
    a_index = bisect.bisect_left(A, b)
    c_index = bisect.bisect_right(C, b)
    ans += len(A[:a_index])*len(C[c_index:])
print(ans)

# Optimized solution
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:
    a_index = bisect.bisect_left(A, b)
    c_index = bisect.bisect_right(C, b)
    ans += a_index*(N-c_index)
print(ans)
# Original solution
# TODO: unknown
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.append(10 ** 9 + 1)
b.append(10 ** 9 + 2)
c.append(10 ** 9 + 3)

ab = [0] * (n + 1)
j = 0
for i in range(n + 1):
    while b[j] <= a[i]:
        j += 1
    ab[i] = j

k = 0
bc = [0] * (n + 1)
for j in range(n + 1):
    while c[k] <= b[j]:
        k += 1
    bc[j] = k

bc_acc = [0] * (n + 1)
bc_acc[n] = 0
for j in range(n-1, -1, -1):
    bc_acc[j] = bc_acc[j+1] + n - bc[j]

ans = 0
for i in range(n):
    ans += bc_acc[ab[i]]

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()

import bisect

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)
# 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()

import bisect

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)


# Optimized solution
from bisect import bisect_left
from itertools import accumulate

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()

ba_cnt = [bisect_left(a, e) for e in b]
ba_acm = [0] + list(accumulate(ba_cnt))

ans = 0
for e in c:
    i = bisect_left(b, e)
    ans += ba_acm[i]

print(ans)
# Original solution
from bisect import bisect_left as bl,bisect_right as br
n=int(eval(input()))
a,b,c=[sorted(list(map(int,input().split()))) for i in range(3)]
ans=0
for v in b:
  if v<=a[0] or v>=c[-1]:continue
  ans+=bl(a,v)*(n-br(c,v))
print(ans)

# Optimized solution
from bisect import bisect_left as bl,bisect_right as br
n=int(eval(input()))
a,b,c=[sorted(list(map(int,input().split()))) for i in range(3)]
print((sum(bl(a,v)*(n-br(c,v))for v in b)))
# Original solution
from bisect import 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()
b.sort()
c.sort()
cnt = 0
for i in range(n):
    num_c = c[i]
    b_idx = bisect_left(b,num_c)
    for j in range(b_idx):
        num_b = b[j]
        a_idx = bisect_left(a, num_b)
        cnt += a_idx
print(cnt)


# Optimized solution
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()
len_c = len(c)
total = 0
for num in b:
    idx_a = bisect_left(a, num)
    idx_c = bisect_right(c, num)
    cnt = idx_a * (len_c - idx_c)
    total += cnt
print(total)
# Original solution
# https://atcoder.jp/contests/abc077/tasks/arc084_a
# C - Snuke Festival

N = int(input().split()[0])
a_list = sorted(list(map(int, input().split())))
b_list = sorted(list(map(int, input().split())))
c_list = sorted(list(map(int, input().split())))

comb_n = 0

for i in range(N):  # 10 ** 5
    b = b_list[i]
    c_n = len([c for c in c_list if c > b])  # 10 ** 5
    a_n = len([a for a in a_list if a < b])  # 10 ** 5
    comb_n += a_n * c_n

ans = comb_n
print(ans)


# Optimized solution
# https://atcoder.jp/contests/abc077/tasks/arc084_a
# C - Snuke Festival
import bisect

N = int(input().split()[0])
a_list = sorted(list(map(int, input().split())))
b_list = sorted(list(map(int, input().split())))
c_list = sorted(list(map(int, input().split())))

comb_n = 0
comb_n_list = []

# 自分より大きい個数
start_c_index = 0
start_a_index = 0

for i in range(N):  # 10 ** 5
    b = b_list[i]
    a_n = bisect.bisect_left(a_list, b)
    c_n = N - bisect.bisect_right(c_list, b)
    comb_n += a_n * c_n
ans = comb_n
print(ans)
# Original solution
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()))
cnt = 0
bn = []
for i in range(n):
    x2 = bisect_right(c, b[i])
    bn.append(n-x2)
for i in range(n):
    x1 = bisect_right(b, a[i])
    cnt += sum(bn[x1:])
print(cnt)

# Optimized solution
from bisect import bisect_right
from bisect import bisect_left

n = int(eval(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)
# Original solution
import bisect
import sys
input = sys.stdin.readline


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(reverse=True)
    # print(A)
    # print(B)
    # print(C)

    ans = 0
    last_b = N
    for c in C:
        last_b = bisect.bisect_left(B, c, hi=last_b)
        if last_b==0:
            break
        last_a = N
        for b in reversed(B[:last_b]):
            last_a = bisect.bisect_left(A, b, hi=last_a)
            if last_a==0:
                break
            ans += last_a
            # print(b)
            # print("last_b: "+str(last_b))
            # print("last_a: "+str(last_a))
    
    print(ans)


if __name__ == '__main__':
    main()

# Optimized solution
import bisect
import sys
input = sys.stdin.readline


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()
    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(str(cnt_a) + "*" + str(cnt_c))
    
    print(ans)


if __name__ == '__main__':
    main()
# Original solution
def n0():return int(eval(input()))
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(eval(input())) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
a=n1()
b=n1()
c=n1()

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

from bisect import bisect_left,bisect_right
b2=[]
for i in b:
    b2.append(bisect_left(a,i))

import itertools
b3=list(itertools.accumulate(b2))
    
ans=0
for i in c:
    t=bisect_left(b,i)
    if t>0:
        ans+=b3[t-1]
    
print(ans)

# Optimized solution

def s0():return eval(input())
def s1():return input().split()
def s2(n):return [eval(input()) for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(eval(input()))
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(eval(input())) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
a=n1()
b=n1()
c=n1()

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

from bisect import bisect_left,bisect_right
b2=[]
for i in b:
    b2.append(bisect_left(a,i))

import itertools
b3=list(itertools.accumulate(b2))
    
ans=0
for i in c:
    t=bisect_left(b,i)
    if t>0:
        ans+=b3[t-1]
    
print(ans)
# Original solution
import bisect

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

ans = 0
for i in A:
    for k in B[bisect.bisect_right(B,i):]:
        ans += D - bisect.bisect_right(C,k)
print(ans)

# Optimized solution
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 i in B:
    ans += bisect.bisect_left(A,i)*(N - bisect.bisect_right(C,i))
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()
C.sort()


def binary_search(lst, value, high):
    l = 0
    r = N - 1
    while l <= r:
        mid = (l + r) // 2
        if lst[mid] < value:
            l = mid + 1
        elif lst[mid] > value:
            r = mid - 1
        else:
            # lstの中にある場合
            if high:
                # 真に大きい
                try:
                    while lst[mid] == value:
                        mid += 1
                except IndexError:
                    return N
                return mid
            else:
                # 真に小さい
                try:
                    while lst[mid] == value:
                        mid -= 1
                except IndexError:
                    return -1
                return mid
    if high:
        return l
    else:
        return r


def main():
    ans = 0
    # Bの値でループしてそれより小さいA、大きいCの個数を求めて掛け合わせる
    for middle in B:
        lower = binary_search(A, middle, False) + 1 # 0-indexedで返るので+1する
        higher = N - binary_search(C, middle, True)
        ans += lower * higher
    print(ans)


if __name__ == "__main__":
    main()

# Optimized solution
#import generator


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

"""
with open('generator.txt', 'r') as f:
    read = f.read().split('\n')
    N = int(read[0])
    A = list(map(int, read[1].split()))
    B = list(map(int, read[2].split()))
    C = list(map(int, read[3].split()))
"""
A.sort()
C.sort()


def binary_search(lst, value, high):
    l = 0
    r = N - 1
    while l <= r:
        mid = (l + r) // 2
        if lst[mid] < value:
            l = mid + 1
        elif lst[mid] > value:
            r = mid - 1
        else:
            # lstの中にある場合
            if high:
                # 真に大きい
                return binary_search(lst, value + 0.5, high)
            else:
                # 真に小さい
                return binary_search(lst, value - 0.5, high)
    if high:
        return l
    else:
        return r


def main():
    ans = 0
    # Bの値でループしてそれより小さいA、大きいCの個数を求めて掛け合わせる
    for middle in B:
        lower = binary_search(A, middle, False) + 1 # 0-indexedで返るので+1する
        higher = N - binary_search(C, middle, True)
        ans += lower * higher
    print(ans)

    
# 愚直解
def main2():
    ans = 0
    for a in A:
        for b in B:
            for c in C:
                if a < b < c:
                    ans += 1
    print(ans)
    

if __name__ == "__main__":
    main()
    #main2()
# Original solution
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 i in B:
    OK = -1
    NG = N
    while NG - OK > 1:
        mid = (OK + NG) // 2
        if A[mid] < i:
            OK = mid
        else:
            NG = mid
    countA = OK + 1
    
    OK = N
    NG = -1
    while OK - NG > 1:
        mid = (OK + NG) // 2
        if C[mid] > i:
            OK = mid
        else:
            NG = mid
    countC = N - NG - 1
    ans += countA * countC

print(ans)

# Optimized solution
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()
C.sort()

ans = 0

def bisect(array, threshold, equal=False):
    OK = -1
    NG = N
    while NG - OK > 1:
        mid = (OK + NG) // 2
        if array[mid] < threshold:
            OK = mid
        elif equal == True and array[mid] == threshold:
            OK = mid
        else:
            NG = mid
    return OK + 1

for i in B:
    ans += bisect(A, i) * (N - bisect(C, i, True))

print(ans)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
a.sort()
b=list(map(int,input().split()))
b.sort()
c=list(map(int,input().split()))
c.sort()
ans=0
import bisect
for bb in b:
  ao=bisect.bisect(a,bb-1)
  cnta=len(a[:ao])
  cs=bisect.bisect(c,bb)
  cntc=len(c[cs:])
  ans+=cnta*cntc
print(ans)

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
a.sort()
b=list(map(int,input().split()))
b.sort()
c=list(map(int,input().split()))
c.sort()
ans=0
import bisect
for i in range(n):
    x=bisect.bisect_left(a,b[i])
    y=bisect.bisect_right(c,b[i])
    ans+=x*(n-y)
print(ans)
# Original solution
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()])

def func1(list_1, list_2):
    res = []
    cnt = 0
    i = 0
    for x in list_2:
        while i <= n-1 and list_1[i] < x:
            cnt += 1
            i += 1
        res.append((x, cnt))
    return res

def func2(list_res, list_3):
    res = 0
    cnt = 0
    i = 0
    for x in list_3:
        while i <= n-1 and list_res[i][0] < x:
            cnt += list_res[i][1]
            i += 1
        res += cnt
    return res

ans = func2(func1(a, b), c)

print(ans)

# Optimized solution
n = int(eval(input()))
a = sorted([int(x) for x in input().split()])
b = sorted([int(x) for x in input().split()])
c = sorted([int(x) for x in input().split()])

res = 0
res_b = 0
cnt = 0
i, j = 0, 0
for c_ in c:
    while i <= n-1 and c_ > b[i]:
        while j <= n-1 and b[i] > a[j]:
            cnt += 1
            j += 1
        res_b += cnt
        i += 1
    res += res_b

print(res)
# Original solution
def main():
    from bisect import bisect
    import sys
    sys.setrecursionlimit(200000)

    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 a in A:
        bIdx = bisect(B,a)
        if N - bIdx > 0:
            for j in range(bIdx,N):
                b = B[j]
                cIdx = bisect(C,b)
                if N - cIdx > 0:
                    ans += N-cIdx

    print(ans)
main()

# Optimized solution
"""
前処理で下記のようなメモを作っておく必要がある。
candidate[j] -> 昇順ソートされたBの中でインデックスj以降のパーツを使えるときに、考えられるB,Cの組み合わせの数。
candidateリストを作成するためにまずは、下記のmemoを用意して、その総和としてcandidateを作成する。
memo[j] -> Bの中のインデックスjのパーツを使った場合に使用可能なCの数。
"""

def main():
    from bisect import bisect
    import sys
    sys.setrecursionlimit(200000)

    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())))

    memo = [0]*(N)
    for j in range(N):
        b = B[j]
        cIdx = bisect(C,b)
        memo[j] = N-cIdx
    candidate = [0]*(N)
    candidate[-1] = memo[-1]
    for j in range(N-2,-1,-1):
        candidate[j] += candidate[j+1]+memo[j]

    ans = 0
    for a in A:
        bIdx = bisect(B,a)
        if bIdx < N:
            ans += candidate[bIdx]

    print(ans)
main()
# Original solution
from bisect import 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())))

"""
まず、前処理として、「Bの祭壇から大きさb以下のパーツを使うとき、Aの祭壇のパーツとの組み合わせはいくつあるか」というのを調べてメモしておく。
次に、Cの祭壇の大きさがcのとき、という風に場合わけして、選べるBの祭壇の大きさを絞って、A,B,Cの組み合わせの数を加算していく。
"""


tmpSum = 0
dicB = {}
for i in range(N):
    b = B[i]
    if b not in dicB:
        dicB[b] = tmpSum
    idx = bisect_left(A,b)
    dicB[b] += idx
    tmpSum += idx

ans = 0
for i in range(N):
    c = C[i]
    idx = bisect_left(B,c)
    if idx != 0:
        b = B[idx-1]
        ans += dicB[b]

print(ans)


# Optimized solution
from bisect 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())))

"""
前処理で、中部の祭壇でBi以下のサイズを選べるときの、中段と上段のパーツの組み合わせのパターン数を計算しておく。
"""
BPattern = []
for i in range(N):
    b = B[i]
    idx = bisect(A,b-1)
    if i == 0:
        BPattern.append(idx)
    else:
        BPattern.append(BPattern[-1]+idx)

ans = 0
for i in range(N):
    c = C[i]
    idx = bisect(B,c-1)
    if idx:
        ans+=BPattern[idx-1]

print(ans)
# Original solution
from bisect import bisect_right


def solve():
    N, *ABC = list(map(int, open(0).read().split()))
    A = ABC[:N]
    B = ABC[N:2*N]
    C = ABC[2*N:]
    B.sort()
    C.sort()
    
    ans = 0
    for i in range(N):
        index = bisect_right(B, A[i])
        for j in range(index, N):
            ans += N - bisect_right(C, B[j])
    print(ans)


if __name__ == '__main__':
    solve()


# Optimized solution
from bisect import bisect_left, bisect_right


def solve():
    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):
        cnt_a = bisect_left(A, B[i])
        cnt_b = N - bisect_right(C, B[i])
        ans += cnt_a * cnt_b
    print(ans)


if __name__ == '__main__':
    solve()