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-----
2
1 5
2 4
3 6

-----Sample Output-----
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

Difficulty: introductory

Starter code:

Solutions:
n = int(input())
a_list = sorted([int(x) for x in input().split()])
b_list = sorted([int(x) for x in input().split()])
c_list = sorted([int(x) for x in input().split()])

import bisect
sum = 0
for b in b_list:
    b_num = bisect.bisect_left(a_list,b)
    c_num = bisect.bisect_right(c_list,b)
    sum += b_num*(len(c_list)-c_num)
print(sum)

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

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 as bs
import numpy as np
A.sort()
C.sort()
#B_a:b未満のAのパーツ数、B_c:b超のCのパーツ数
B_a = np.array([bs.bisect_left(A,b) for b in B]) 
B_c = np.array([N-bs.bisect_right(C,b) for b in B])
ans = np.dot(B_a, B_c)
print(ans)

from bisect import bisect_left, bisect_right
N = int(input())
A, B, C = [sorted(map(int, input().split())) for _ in range(3)]
print(sum(bisect_left(A,b)*(N-bisect_right(C,b)) for b in B))

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:
    a = bisect.bisect_left(A, b)
    c = bisect.bisect_right(C, b)
    ans += a*(n-c)

print(ans)

import bisect
N=int(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)
ans=0
for i in range(len(b)):
    index_a=bisect.bisect_left(a,b[i])
    index_c=bisect.bisect_right(c,b[i])
    ans+=(index_a*(len(c)-index_c))
print(ans)

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 = i = j = 0

import bisect

for b in B:
    i = bisect.bisect_left(A,b)
    j = N - bisect.bisect_right(C,b)
    ans += i * j
print(ans)

import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N = NI()
    A = NLI()
    B = NLI()
    C = NLI()
    
    A = sorted(A)
    C = sorted(C)
    
    ans = 0
    
    for b in B:
        

        A_ng = -1       #ng:とり得る最小の値-1
        A_ok = len(A)  #ok:とり得る最大の値+1

        while (abs(A_ok - A_ng) > 1):
            A_mid = (A_ok + A_ng) // 2

            if A[A_mid] >= b:#計算の結果、midが条件を満たすならokにmidを代入。そうでなければngにmidを代入。
                A_ok = A_mid
            else:
                A_ng = A_mid
                
        C_ng = -1      #ng:とり得る最小の値-1
        C_ok = len(C)  #ok:とり得る最大の値+1

        while (abs(C_ok - C_ng) > 1):
            C_mid = (C_ok + C_ng) // 2

            if C[C_mid] > b:#計算の結果、midが条件を満たすならokにmidを代入。そうでなければngにmidを代入。
                C_ok = C_mid
            else:
                C_ng = C_mid
                
                
        len_C = len(C)
        
        ans += A_ok * (len_C-C_ok)
        
    print(ans)
def __starting_point():
    main()
__starting_point()

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:
    l = bisect.bisect_left(A, b)
    r = bisect.bisect_right(C, b)
    ans += l * (len(C) - r)

print(ans)

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


ans = 0
for i in range(n):
    B = b[i]
    b_in = bisect.bisect_left(a,B)
    if b_in == 0:
        continue
    c_in = bisect.bisect_right(c,B)
    c_cnt = n - c_in
    ans += b_in*c_cnt

print(ans)

# 二分探索
import bisect

#################
n=int(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
#a[i]の個数
for i in range(n):
    a_count = bisect.bisect_left(a, b[i])
    c_count = bisect.bisect_right(c, b[i])
    count+=a_count*(len(c)-c_count)

print(count)


import bisect
N = int(input())
lsA = list(map(int,input().split()))
lsB = list(map(int,input().split()))
lsC = list(map(int,input().split()))
lsA.sort()
lsB.sort()
lsC.sort()
ans = 0
for i in range(N):
    B = lsB[i]
    indexA = bisect.bisect(lsA,B-1)
    indexC = N - bisect.bisect(lsC,B)
    ans += indexA*indexC
print(ans)

from bisect import bisect,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:
  i=bisect_left(A,b)
  j=bisect(C,b)
  ans+=i*(N-j)
print(ans)

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

cnt = 0
for b in B:
    i = bisect.bisect_left(A, b)
    j = bisect.bisect_right(C, b)
    cnt += i * (n-j)

print(cnt)

def binary_search(lst, t, i):
    left = -1
    right = len(lst)

    while abs(right - left) > 1:
        mid = (left + right) // 2
        if i == 0:
            if lst[mid] < t:
                left = mid
            else:
                right = mid
        elif i == 1:
            if lst[mid] > t:
                right = mid
            else:
                left = mid

    return left


def main():
    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:
        a = binary_search(A, b, 0)
        c = binary_search(C, b, 1)
        ans += (a + 1) * (n - c - 1)

    print(ans)


def __starting_point():
    main()

__starting_point()

from bisect import *
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:
    ans+=(n-bisect(C,b))*bisect_left(A,b)
print(ans)

import bisect as bs

def main():
    with open(0) as f:
        N = int(f.readline())
        A = sorted(list(map(int, f.readline().split())))
        B = list(map(int, f.readline().split()))
        C = sorted(list(map(int, f.readline().split())))

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

main()

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

from bisect import bisect_right

d=[]
for i in range(n):
    index = bisect_right(c,b[i])    

    d.append(n-index)

import numpy as np
s=sum(d)
cum=np.cumsum(d)

ans=0
for j in range(n):
    dex = bisect_right(b,a[j])
    if dex==0:
        ans+=s
    elif dex==n:
        continue
    else:
        ans+=s-cum[dex-1]

print(ans)
        


import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return list(map(int, input().split()))
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n = i_input()
    a = i_list()
    b = i_list()
    c = i_list()
    a.sort()
    b.sort()
    c.sort()

    al = []
    bl = [0]
    import bisect

    for k,i in enumerate(b):
        x = bisect.bisect(c, i)
        bl.append(bl[k]+(n-x))

    ans = 0

    for i in a:
        x = bisect.bisect(b,i)
        ans += bl[-1] - bl[x]
    print(ans)




def __starting_point():
    main()

__starting_point()

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

print(ans)

def bs_left(list, target):
    low = 0
    high = len(list)

    while low < high:
        mid = (low + high) // 2
        if target > list[mid]:
            low = mid + 1
        else:
            high = mid
    return low

def bs_right(list, target):
    low = 0
    high = len(list)
    while low < high:
        mid = (low + high) // 2
        if target < list[mid]:
            high = mid
        else:
            low = mid + 1
    return low

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:
    ans += (bs_left(A, b) * (n - bs_right(C, b)))
print(ans)



from bisect import bisect_left
from numpy import cumsum

N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
B_ = [0]*N
ans = 0
start = 0
for i, b in enumerate(B):
    j = bisect_left(A, b, start)
    B_[i] = j
    start = j
B_ = cumsum(B_)
start = 0
for c in C:
    i = bisect_left(B, c, start)
    start = i
    if i != 0:
        ans += B_[i-1]
print(ans)


#!/usr/bin/env python3
import sys
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()

a_index = 0
b_index = 0
c_index = 0

bc = []
while(b_index < len(b) and c_index < len(c)):
    if b[b_index] < c[c_index]:
        bc.append(len(c)-c_index)
        b_index += 1
    else:
        c_index += 1
    # print(b_index, c_index)

if len(bc) == 0:
    print((0))
    return

bc_sum = [bc[-1]]
for i in reversed(bc[:-1]):
    bc_sum.append(i+bc_sum[-1])
bc_sum = list(reversed(bc_sum))

# print(bc)
# print(bc_sum)
a_index = 0
b_index = 0
c_index = 0
ans = []
while(a_index < len(a) and b_index < len(b) and b_index < len(bc_sum)):
    if a[a_index] < b[b_index]:
        # ans.append(sum(bc[b_index:]))
        ans.append(bc_sum[b_index])
        a_index += 1
    else:
        b_index += 1
    # print(a_index, b_index)

# print(bc)
print((sum(ans)))


n=int(input())
alist=list(map(int, input().split()))
blist=list(map(int, input().split()))
clist=list(map(int, input().split()))
alist.sort()
blist.sort()
clist.sort()
import bisect
ans=0
for b in blist:
  num1=n-bisect.bisect(clist,b)
  num2=bisect.bisect_left(alist,b)
  ans+=num1*num2
print(ans)

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


#!/usr/bin/env python3
import sys
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()

a_index = 0
b_index = 0
c_index = 0

bc = []
while(b_index < len(b) and c_index < len(c)):
    if b[b_index] < c[c_index]:
        bc.append(len(c)-c_index)
        b_index += 1
    else:
        c_index += 1
    # print(b_index, c_index)

if len(bc) == 0:
    print((0))
    return

bc_sum = [bc[-1]]
for i in reversed(bc[:-1]):
    bc_sum.append(i+bc_sum[-1])
bc_sum = list(reversed(bc_sum))

if len(bc_sum) != len(bc):
    print(bc)
    print(bc_sum)
    return
# print(bc)
# print(bc_sum)
a_index = 0
b_index = 0
c_index = 0
ans = []
while(a_index < len(a) and b_index < len(b) and b_index < len(bc_sum)):
    if a[a_index] < b[b_index]:
        # ans.append(sum(bc[b_index:]))
        ans.append(bc_sum[b_index])
        a_index += 1
    else:
        b_index += 1
    # print(a_index, b_index)

# print(bc)
print((sum(ans)))


#!/usr/bin/env python3
def main():
    from bisect import bisect, bisect_left

    N = int(input())
    A = sorted([int(x) for x in input().split()])
    B = [int(x) for x in input().split()]
    C = sorted([int(x) for x in input().split()])

    print((sum([bisect_left(A, b) * (N - bisect(C, b)) for b in B])))


def __starting_point():
    main()

__starting_point()

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
# print(A)
# print(B)
# print(C)
for i in range(n):
    b = B[i]
    pos_a = bisect_left(A, b)
    pos_c = bisect_right(C, b)
    ans += pos_a * (n - pos_c)
    # print(b, pos_a, pos_c)
print(ans)


from bisect import bisect, bisect_left


def bin_search(n):

    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):
        upper_b = bisect_left(a, b[i])
        under_b = n - bisect(c, b[i])
        ans += upper_b * under_b
    return ans


def __starting_point():
    n = int(input())
    print((bin_search(n)))

__starting_point()

#
# abc077 c
#
import sys
from io import StringIO
import unittest
import bisect


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)


def resolve():
    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:
        an = bisect.bisect_left(A, b)
        cn = N - bisect.bisect_right(C, b)
        ans += an*cn

    print(ans)


def __starting_point():
    # unittest.main()
    resolve()

__starting_point()

from bisect import bisect
import random


def binary_search(L, n, i, j):
    # print(L, n, i, j)
    low = i
    high = j

    while low <= high:
        mid = (low + high) //2
        guess = L[mid]
        # if guess == n:
            # return mid
        if guess > n:
            high = mid -1
        else:
            low = mid + 1
    # print(low)
    return low

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
# N = 10 ** 5
# A = [random.randint(1, 10**9) for _ in range(N)]
# B = [random.randint(1, 10**9) for _ in range(N)]
# C = [random.randint(1, 10**9) for _ in range(N)]

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

ans = 0
i, j = 0, 0

A_ind = []
B_cum = [0]

for a in A:
    # i = binary_search(B, a, i, N-1)
    i = bisect(B, a)
    A_ind.append(i)

s = 0
for b in B:
    # j = binary_search(C, b, j, N-1)
    j = i = bisect(C, b)
    s += N-j
    B_cum.append(s)

for a in A_ind:
    ans += B_cum[-1] - B_cum[a]
print(ans)



# -*- coding: utf-8 -*-

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    return N, A, B, C


def get_lb(l: list, key: int) -> int:
    """
    l[index] > keyとなる最小のindexを求める.

    Args:\n
        l (list): リスト
        key (int): 整数

    Returns:\n
        int: l[index] > keyとなる最小のindex
    """
    low = -1
    high = len(l)
    while 1 < high - low:
        mid = (low + high) // 2
        guess = l[mid]
        if guess > key:
            high = mid
        else:
            low = mid
    return high


def get_ub(l: list, key: int) -> int:
    """
    l[index] < keyとなる最大のindexを求める.

    Args:\n
        l (list): リスト
        key (int): 整数

    Returns:\n
        int: l[index] < keyとなる最大のindex
    """
    low = -1
    high = len(l)
    while 1 < high - low:
        mid = (low + high) // 2
        guess = l[mid]
        if guess < key:
            low = mid
        else:
            high = mid
    return low


def main(N: int, A: list, B: list, C: list) -> None:
    """
    メイン処理.

    Args:\n
        N (int): パーツの数(1 <= N <= 10**5)
        A (list): 上部のパーツのサイズ(1 <= A_i <= 10**9)
        B (list): 中部のパーツのサイズ(1 <= B_i <= 10**9)
        C (list): 下部のパーツのサイズ(1 <= C_i <= 10**9)
    """
    # 事前にリストをソートしておく
    A = sorted(A)
    B = sorted(B)
    C = sorted(C)

    # 求解処理
    ans = 0
    for i in range(N):
        B_i = B[i]
        ans += (get_ub(A, B_i) + 1) * (N - get_lb(C, B_i))

    # 結果出力
    print(ans)


def __starting_point():
    # 標準入力を取得
    N, A, B, C = get_input()

    # メイン処理
    main(N, A, B, C)

__starting_point()

def solve():
    def bin_l(arr, key):
        l = 0
        r = len(arr) - 1
        while l <= r:
            mid = (l + r)//2
            if arr[mid] > key:
                r = mid - 1
            else:
                l = mid + 1
            
        if l < len(arr):
            return l
        else:
            return None
    
    def bin_s(arr, key):
      l = 0
      r = len(arr) - 1
      while l <= r:
        mid = (l + r) // 2
        if arr[mid] >= key:
          r = mid - 1
        else:
          l = mid + 1
      
      if r >= 0 :
        return r
      else:
        return None
        
    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)
    
    sum = 0
    for b in B:
        a = bin_s(A, b)
        c = bin_l(C, b)
        a = a + 1 if a is not None else None
        c = n - c if c is not None else None
        if a is not None and c is not None:
            sum += a*c
    
    print(sum)

def __starting_point():
    solve()

__starting_point()

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


#!/usr/bin/env python3
import sys
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()

a_index = 0
b_index = 0
c_index = 0

bc = [0]*n
# bc = []
while(b_index < len(b) and c_index < len(c)):
    if b[b_index] < c[c_index]:
        # bc.append(len(c)-c_index)
        bc[b_index] = len(c)-c_index
        b_index += 1
    else:
        c_index += 1
    # print(b_index, c_index)

if len(bc) != len(b):
    return


if len(bc) == 0:
    print((0))
    return

bc_sum = [bc[-1]]
for i in reversed(bc[:-1]):
    bc_sum.append(i+bc_sum[-1])
bc_sum = list(reversed(bc_sum))

# print(bc)
# print(bc_sum)
a_index = 0
b_index = 0
c_index = 0
ans = []
while(a_index < len(a) and b_index < len(b) and b_index < len(bc_sum)):
    if a[a_index] < b[b_index]:
        # ans.append(sum(bc[b_index:]))
        ans.append(bc_sum[b_index])
        a_index += 1
    else:
        b_index += 1
    # print(a_index, b_index)

# print(bc)
print((sum(ans)))


from bisect import bisect_left
from itertools import accumulate
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()
bs = [0]*N
for i in range(N):
    b = B[i]
    ai = bisect_left(A, b)
    bs[i] = ai
bs = [0]+list(accumulate(bs, lambda x,y:x+y))
ans = 0
for i in range(N):
    c = C[i]
    bi = bisect_left(B, c)
    ans += bs[bi]
print(ans)

from bisect import*
(n,), a, b, c = [sorted(map(int, o.split())) for o in open(0)]
print(sum(bisect_left(a, i) * (n - bisect(c, i)) for i in b))

from bisect import *
N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))

cnt = []

for b in B:
    cnt.append(bisect_left(A, b) * (N - bisect_right(C, b)))
print((sum(cnt)))


from bisect import bisect, bisect_left

N = int(input())
A, B, C = (sorted(map(int, input().split())) for _ in range(3))

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

print(ans)

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 as bi
ans=0
for i in range(n):
    q=B[i]
    oka= bi.bisect_left(A,q)
    okb= n- bi.bisect_right(C,q)
    ans+=oka*okb
print(ans)

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

# x以上のイテレータを
def lower_bound(arr , x):
    l = 0
    r = len(c)
    for j in range(30):
        mid = (l + r) // 2
        # print(l , r , mid)
        if x <= arr[mid]:
            r = mid
        else:
            l = mid
    return r


count = 0
for i in range(n):
    a_count = lower_bound(a , b[i])
    c_count = len(c) - lower_bound(c , b[i] + 1)
    count += a_count * c_count

print(count)


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
import bisect
b = []
for i in B:
    x = bisect.bisect_right(C,i)
    b.append(N-x)
y = sum(b)
c = [y]
for i in range(1,N):
    y -= b[i-1]
    c.append(y)
c.append(0)
for i in A:
    a = bisect.bisect_right(B,i)
    ans += c[a]
print(ans)

def lb(k, a):
    n = len(a)
    l, u = 0, n
    while l < u:
        m = (l + u) // 2
        if k < a[m]:
            u = m
        else:
            l = m + 1
    return l

def ub(k, a):
    n = len(a)
    l, u = -1, n - 1
    while l < u:
        m = (l + u + 1) // 2
        if a[m] < k:
            l = m
        else:
            u = m - 1
    return l

N = int(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
for i in range(N):
    j = ub(B[i], A)
    k = lb(B[i], C)
    res += (j + 1)*(N - k)

print(res)

import copy
import math
import time
import statistics
import math
import itertools
import bisect

# a = get_int()
def get_int():
    return int(input())
# a = get_string()
def get_string():
    return input()
# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]
# a_list = get_string_list():
def get_string_list():
    return input().split()
# a, b = get_int_multi()
def get_int_multi():
    return list(map(int, input().split()))
# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))
# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''

def main():
    start = time.time()
    n = get_int()

    a_list = get_int_list()
    b_list = get_int_list()
    c_list = get_int_list()

    a_list.sort()
    b_list.sort()
    c_list.sort()

    a_count = []
    b_count = []
    b_count2 = []

    idx = 0
    for a in a_list:
        idx = bisect.bisect_right(b_list, a, idx)
        a_count.append(idx)

    idx = 0
    for b in b_list:
        idx = bisect.bisect_right(c_list, b, idx)
        b_count.append(idx)

    ruikei = 0
    for i in range(n-1, -1, -1):
        ruikei += n - b_count[i]
        b_count2.append(ruikei)

    b_count2.sort(reverse=True)

    ans = 0
    for a in a_count:
        if a == n:
            continue
        ans += b_count2[a]

    print(ans)
    #print(time.time() - start)

def __starting_point():
    main()



__starting_point()

from bisect import bisect,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:
  i=bisect_left(A,b)
  j=bisect(C,b)
  ans+=i*(N-j)
print(ans)

#!/usr/bin/env python3
import sys
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()

a_index = 0
b_index = 0
c_index = 0

bc = [0]*n
# bc = []
while(b_index < len(b) and c_index < len(c)):
    if b[b_index] < c[c_index]:
        # bc.append(len(c)-c_index)
        bc[b_index] = len(c)-c_index
        b_index += 1
    else:
        c_index += 1
    # print(b_index, c_index)

if len(bc) != len(b):
    return


if len(bc) == 0:
    print((0))
    return

bc_sum = [bc[-1]]
for i in reversed(bc[:-1]):
    bc_sum.append(i+bc_sum[-1])
bc_sum = list(reversed(bc_sum))

# print(bc)
# print(bc_sum)
a_index = 0
b_index = 0
c_index = 0
ans = []
while(a_index < len(a) and b_index < len(b)):
    if a[a_index] < b[b_index]:
        # ans.append(sum(bc[b_index:]))
        ans.append(bc_sum[b_index])
        a_index += 1
    else:
        b_index += 1
    # print(a_index, b_index)

# print(bc)
print((sum(ans)))


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

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

pat = 0

for i in B:
    numA = bisect.bisect_left(A,i)
    numC = bisect.bisect(C,i)
    pat += numA * (len(C)-numC)

print(pat)

def II(): return int(input())
def LII(): return list(map(int, input().split()))

n=II()
alist=LII()
blist=LII()
clist=LII()

alist.sort()
blist.sort()
clist.sort()

#あるbより小さいaの数
def count_a(b):
    ok,ng = -1,n
    def is_ok(i):
        return alist[i]<b
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok+1

def count_c(b):
    ok,ng = n,-1
    def is_ok(i):
        return clist[i]>b
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return n-ok

result=0
for b in blist:
    result += count_a(b) * count_c(b)

print(result)

import bisect

_ = 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 b in B:
    a = bisect.bisect_left(A, b)
    c = len(C) - bisect.bisect_right(C, b)
    ans += a * c
else:
    print(ans)

n = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())))
bl = [0]*n
blli = [0]*n
al = [0]*n
alli = [0]*n
import bisect

for i in range(n):
    bl[i]=n-bisect.bisect(c,b[i])

blli[0] = sum(bl)
for i in range(n-1):
    blli[i+1] = blli[i]-bl[i]
   
for i in range(n):
    al[i]=n-bisect.bisect(b,a[i])

for i in range(n):
    if al[i]!=0:
        alli[i] = blli[-al[i]]

print(sum(alli))

import bisect
n = int(input())
a, b, c = map(list, [sorted(list(map(int, input().split()))) for i in range(3)])
ans = 0
for i in range(n):
    ans += bisect.bisect_left(a, b[i]) * (n - bisect.bisect_right(c, b[i]))
print(ans)

# coding:UTF-8
import sys
from math import factorial

MOD = 10 ** 9 + 7
INF = 10000000000

def binary_search_section(list, min, max):
    low = 0
    high = len(list) - 1
    upper = len(list)
    lower = -1
    while low <= high:
        mid = (low + high) // 2
        guess = list[mid]
        if guess >= min:
            high = mid - 1
        else:
            low = mid + 1
            lower = mid
    low = 0
    high = len(list) - 1
    while low <= high:
        mid = (low + high) // 2
        guess = list[mid]
        if guess > max:
            high = mid - 1
            upper = mid
        else:
            low = mid + 1

    return [lower, upper]

def main():
    # ------ 入力 ------#
    # 1行入力
    n = int(input())    # 数字
    aList = list(map(int, input().split()))     # スペース区切り連続数字
    bList = list(map(int, input().split()))     # スペース区切り連続数字
    cList = list(map(int, input().split()))     # スペース区切り連続数字

    # ------ 処理 ------#
    aListSorted = sorted(aList)
    bListSorted = sorted(bList)
    cListSorted = sorted(cList)

    result = 0
    # for a in aListSorted:
    #     sec = binary_search_section(bListSorted, a+1, bListSorted[-1])
    #     for j in range(sec[0]+1, len(bListSorted)):
    #         b = bListSorted[j]
    #         sec2 = binary_search_section(cListSorted, b+1, cListSorted[-1])
    #         result += len(cListSorted) - (sec2[0] + 1)
    for b in bListSorted:
        sec = binary_search_section(aListSorted, aListSorted[0], b-1)
        sec2 = binary_search_section(cListSorted, b+1, cListSorted[-1])
        result += (sec[1] - sec[0] - 1)*(sec2[1] - sec2[0] - 1)

    # ------ 出力 ------#
    print(("{}".format(result)))
    # if flg == 0:
    #     print("YES")
    # else:
    #     print("NO")


def __starting_point():
    main()

__starting_point()

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
import bisect
for i in b:
  t=bisect.bisect_left(a, i)
  q=bisect.bisect_right(c, i)
  ans+=t*(n-q)
print(ans)


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=len(b)-bisect.bisect_right(c,i)
    ans+=A*B
print(ans)

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

def bin_serch(array,num):
    head = 0
    tail = len(array)
    while head < tail:
        center = (head + tail) // 2
        if num < array[center]:
            tail = center
        else:
            head = center + 1
    return head

BC = [0 for _ in range(len(B))]
for i in range(len(B)):
    BC[i] = len(C) - bin_serch(C,B[i])
    
s = 0
for i in range(len(BC)-1, -1, -1):
    s += BC[i]
    BC[i] = s

ans = 0
for a in A:
    b = bin_serch(B,a)
    if b < len(B):
        ans += BC[b]
    
print(ans)

import bisect

n = int(input())
al = sorted(list(map(int, input().split())))
bl = sorted(list(map(int, input().split())))
cl = sorted(list(map(int, input().split())))
ans = 0

for b in bl:
    i = bisect.bisect_left(al, b)
    j = bisect.bisect_right(cl, b)
    ans += i*(n-j)

print(ans)

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())))
cnt = 0

for b in B:
    a = bisect.bisect_left(A,b)
    c = bisect.bisect_right(C,b)
    cnt += a * (len(C)-c)

print(cnt)

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

from bisect import bisect, bisect_left

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

C_accum = [0]
for b in B:
  C_accum.append(C_accum[-1] + N - bisect(C, b))

ans = 0
for a in A:
  i = bisect(B, a)
  ans += C_accum[-1] - C_accum[i]

print(ans)

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):
    a_cand = bisect.bisect_right(A,B[i]-1)
    c_cand = N-bisect.bisect_right(C,B[i])
    count += a_cand*c_cand
print(count)


import bisect
n=int(input())
a = list(map(int, input("").split()))
b = list(map(int, input("").split()))
c = list(map(int, input("").split()))
out=0
a.sort()
b.sort()
c.sort()
for i in b:
    na = bisect.bisect_left(a,i)
    nc = bisect.bisect(c,i)
    out += na * (len(c)-nc)
print(out)

import sys
read = sys.stdin.read
#readlines = sys.stdin.readlines
from bisect import bisect, bisect_left
from itertools import accumulate
def main():
    data = list(map(int, read().split()))
    n = data[0]
    a = data[1:n + 1]
    b = data[n + 1: n * 2 + 1]
    c = data[n * 2 + 1:]
    a.sort()
    b.sort()
    c.sort()
    b2 = [bisect_left(a, be) for be in b]
    b2a = list(accumulate(b2))
    b2a = [0] + b2a
    ans = sum([b2a[bisect_left(b, ce)] for ce in c])
    print(ans)

def __starting_point():
    main()
__starting_point()

import bisect
n = int(input())
X = sorted(list(map(int,input().split())))
Y = sorted(list(map(int,input().split())))
Z = sorted(list(map(int,input().split())))
print(sum(bisect.bisect_left(X,b) * (n-bisect.bisect_right(Z,b)) for b in Y))

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 range(n):
    aa = bisect.bisect_left(a,b[i])
    ca = n-bisect.bisect_right(c,b[i])
    ans += aa * ca
print(ans)


import numpy as np
N = int(input())
A = np.array(input().split(), dtype=np.int32)
B = np.array(input().split(), dtype=np.int32)
C = - np.array(input().split(), dtype=np.int32)
 
A.sort()
B.sort()
C.sort()
 
cnt_A = np.searchsorted(A,B,side='left')
cnt_C = np.searchsorted(C,-B,side='left')
 
answer = (cnt_A * cnt_C).sum()
print(answer)

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]
    a_idx = bisect.bisect_left(A, b)
    # print(b_idx)
    if a_idx == 0: continue
    c_idx = bisect.bisect_right(C, b)
    c_cnt = N - c_idx
    ans += a_idx * c_cnt
print(ans)


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

A_cnt = [1] * N
A_sum = [i+1 for i in range(N)]
A_sum.append(0)
B_cnt = [0] * N
B_sum = [0] * N
C_cnt = [0] * N
C_sum = [0] * N

for i in range(N):
    key = B[i]
    ok = -1
    ng = N
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if A[mid] < key:
            ok = mid
        else:
            ng = mid
    B_cnt[i] = A_sum[ok]

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

for i in range(N):
    key = C[i]
    ok = -1
    ng = N
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if B[mid] < key:
            ok = mid
        else:
            ng = mid
    C_cnt[i] = B_sum[ok]

C_sum[0] = C_cnt[0]
for i in range(1, N):
    C_sum[i] = C_sum[i-1] + C_cnt[i]

print((C_sum[-1]))

# print(A)
# print(B)
# print(C)
# print(A_cnt)
# print(B_cnt)
# print(C_cnt)
# print(A_sum)
# print(B_sum)
# print(C_sum)


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

# x以上のイテレータを
def lower_bound(arr , x):
    l = 0
    r = len(c)
    for j in range(30):
        mid = (l + r) // 2
        # print(l , r , mid)
        if x <= arr[mid]:
            r = mid
        else:
            l = mid
    return r


count = 0
for i in range(n):
    a_count = lower_bound(a , b[i])
    c_count = len(c) - lower_bound(c , b[i] + 1)
    count += a_count * c_count

print(count)


from bisect import *

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:
    index_A = bisect_left(A, b)
    index_C = bisect_right(C, b)
    ans += index_A * (n - index_C)
print(ans)

from bisect import bisect_right
from itertools import accumulate


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

B_to_C = [0] * (N + 1)
for i in range(N):
    idx = bisect_right(C, B[i])
    B_to_C[i + 1] = N - idx
B_to_C = list(accumulate(B_to_C))

ans = 0
for i in range(N):
    idx = bisect_right(B, A[i])
    ans += B_to_C[N] - B_to_C[idx]
print(ans)


def bin_l(arr, key):
    l = 0
    r = len(arr) - 1
    while l <= r:
        mid = (l + r)//2
        if arr[mid] > key:
            r = mid - 1
        else:
            l = mid + 1
        
    if l < len(arr):
        return l
    else:
        return None

def bin_s(arr, key):
  l = 0
  r = len(arr) - 1
  while l <= r:
    mid = (l + r) // 2
    if arr[mid] >= key:
      r = mid - 1
    else:
      l = mid + 1
  
  if r >= 0 :
    return r
  else:
    return None
    
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)

sum = 0
for b in B:
    a = bin_s(A, b)
    c = bin_l(C, b)
    a = a + 1 if a is not None else None
    c = n - c if c is not None else None
    if a is not None and c is not None:
        sum += a*c

print(sum)

import bisect
n=int(input())
a,b,c=map(list,[sorted(list(map(int, input().split()))) for i in range(3)])
ans=0
for i in range(n):
    ans+=bisect.bisect_left(a,b[i])*(n-bisect.bisect_right(c,b[i]))
print(ans)

import bisect
N = int(input())
top = list(map(int,input().split()))
middle = list(map(int,input().split()))	
bottom = list(map(int,input().split()))	

top.sort()
middle.sort()
bottom.sort()

ans = 0
for i in middle:
  can_put_upstair = bisect.bisect_left(top,i)
  can_put_downstair = N - bisect.bisect_right(bottom,i)
  #print(can_put_upstair,can_put_downstair)
  ans += can_put_upstair*can_put_downstair

print(ans)


import bisect
 
N=int(input())
b1=0
d=0

ans=0
 
A=list(map(int, input().split()))
A=sorted(A)
B=list(map(int, input().split()))
B=sorted(B, reverse=True)
C=list(map(int, input().split()))
C=sorted(C)
D=[]
E=[]

for b in B:
  d=d+len(C)-bisect.bisect_right(C,b)
  D.append(d)

D=sorted(D, reverse= True)  
B=sorted(B)

for a in A:
  if 0 <= bisect.bisect_right(B,a) <= len(D)-1:
    ans += D[bisect.bisect_right(B,a)]
print(ans)

def isOK(index, key, in_ls):
    if key<in_ls[index]: return True
    else: return False

def bs(in_ls, key):
    ng = -1
    ok = len(in_ls)
    while 1<abs(ok - ng):
        mid = (ng + ok)//2
        if isOK(mid, key, in_ls): ok = mid
        else: ng = mid
    return ok

def main():
    n = int(input())
    a_list = list(map(int, input().split(" ")))
    b_list = list(map(int, input().split(" ")))
    c_list = list(map(int, input().split(" ")))
    #a < b < c

    a_sorted = list(sorted(a_list))
    b_sorted = list(sorted(b_list))
    c_sorted = list(sorted(c_list))

    bc_dict = {}
    score = 0
    score_list = [0 for i in range(n)]
    for i, b in enumerate(b_sorted[::-1]):
        ok = bs(c_sorted, b)
        score+=n - ok
        score_list[n-i-1]+=score

    total = 0
    for a in a_sorted:
        ok = bs(b_sorted, a)
        if ok==n:
            continue
        total+=score_list[ok]

    print(total)

def __starting_point():
    main()

__starting_point()

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
As = list(range(N+1))

Bs = [0] * N
s = 0
for i,b in enumerate(B):
    ind = bisect.bisect_left(A,b)
    s += As[ind]
    Bs[i] = s
Bs = [0] + Bs
Cs = [0] * N
ans = 0
for i,c in enumerate(C):
    ind = bisect.bisect_left(B,c)
    ans += Bs[ind]

print(ans)



def bin_src_l(arr, key):
  l = 0
  r = len(arr) - 1
  while l <= r:
    mid = (l + r) // 2
    if arr[mid] > key:
      r = mid - 1
    else:
      l = mid + 1
  
  if l < len(arr):
    return l
  else:
    return None

def bin_src_s(arr, key):
  l = 0
  r = len(arr) - 1
  while l <= r:
    mid = (l + r) // 2
    if arr[mid] >= key:
      r = mid - 1
    else:
      l = mid + 1
  
  if r >= 0 :
    return r
  else:
    return None


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)

sum = 0
for b in B:
  a = bin_src_s(A, b)
  c = bin_src_l(C, b)
  a = a + 1 if a is not None else None
  c = N - c if c is not None else None
  if a is not None and c is not None:
    sum += a * c
  
print(sum)

import bisect
import sys

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

A.sort()
C.sort()

ans = 0
for b in B:
    cnt1 = bisect.bisect_left(A, b)
    cnt2 = len(C) - bisect.bisect(C, b)

    ans += cnt1 * cnt2

print(ans)

def abc077c_snuke_festival():
    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())))
    total = 0
    for i in range(n):
        b_size = b[i]
        j = bisect.bisect_left(a, b_size)
        j = n - j
        k = bisect.bisect_right(c, b_size)

        total += (n - j) * (n - k)
    print(total)


abc077c_snuke_festival()

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.append(float("INF"))
AB = [0] * (N+1)
j = 0
for i in range(N):
    while A[j] < B[i]:
        j += 1
        if j == N:
            break
    AB[i+1] = AB[i] + j

ans = 0
B.append(float("INF"))
j = 0
for i in range(N):
    while B[j] < C[i]:
        j += 1
        if j == N:
            break
    ans += AB[j]

print(ans)

import bisect

import sys
stdin=sys.stdin

ip=lambda: int(sp())
fp=lambda: float(sp())
lp=lambda:list(map(int,stdin.readline().split()))
sp=lambda:stdin.readline().rstrip()
yp=lambda:print('Yes')
np=lambda:print('No')

n=ip()
a=lp()
b=lp()
c=lp()

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

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)




def main():
    import bisect

    N = int(input())
    upper = list(map(int, input().split()))
    middle = list(map(int, input().split()))
    lower = list(map(int, input().split()))

    upper.sort()
    middle.sort()
    lower.sort()

    cnt = 0

    for i in range(N):
        mid = middle[i]
        index_up = bisect.bisect_left(upper, mid)
        index_low = bisect.bisect_right(lower, mid)
        
        cnt += index_up * (N - index_low)
    
    print(cnt)


def __starting_point():
    main()
__starting_point()

#!/usr/bin/env python3
def main():
    from bisect import bisect

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

    lst = [N - bisect(C, b) for b in B]
    lst = lst[::-1]
    tmp_lst = [lst[0]]
    for i in lst[1:]:
        tmp_lst.append(i + tmp_lst[-1])
    tmp_lst = tmp_lst[::-1]

    ans = 0
    for a in A:
        res = bisect(B, a)
        ans += tmp_lst[res] if res < N else 0
    print(ans)


def __starting_point():
    main()

__starting_point()

#!/usr/bin/env python3
def main():
    from bisect import bisect, bisect_left

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

    print((sum([bisect_left(A, b) * (N - bisect(C, b)) for b in B])))


def __starting_point():
    main()

__starting_point()

n = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))
A_list = sorted(A_list)
B_list = sorted(B_list)
C_list = sorted(C_list)
cnt = 0

def is_ok(arg): #　B　より小さい最大の　A
    return A_list[arg] < B_list[i]

def bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

def is_ok2(arg): #　B　より大きい最小の　A
    return C_list[arg] > B_list[i]

def bisect2(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok2(mid):
            ok = mid
        else:
            ng = mid
    return ok

for i in range(n): #Bを固定
    #Bより小さいAを探す
    A_key = bisect(len(A_list), 0)
    if A_list[A_key] < B_list[i]:
        #Bより大きいCを探す
        C_key = bisect2(-1, len(C_list)-1)
        if B_list[i] < C_list[C_key]:
            #print(A_key, i, C_key, A_list[A_key], B_list[i], C_list[C_key])
            cnt += (n-C_key)*(A_key+1)

print(cnt)


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

print(ans)


import bisect
N = int(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)
#print(A,B,C)
Count_A = [0]*N
Count_C = [0]*N
for i in range(N):
  # A Count
  Count_A[i] = bisect.bisect_left(A,B[i])
  # C Count
  Count_C[i] = N-bisect.bisect(C,B[i])
#print(Count_A,Count_C)
Patterns = 0
for i in range(N):
  Patterns=Patterns+Count_A[i]*Count_C[i]
  
print(Patterns)

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

def binary1(L, R, list_, threshold):
    while L + 1 < R:
        x = (L + R)//2
        if list_[x] < threshold:
            L = x            
        else:
            R = x
    return L

def binary2(L, R, list_, threshold):
    while L + 1 < R:
        x = (L + R)//2
        if list_[x] > threshold:
            R = x            
        else:
            L = x
    return L

ans = []
for b in B:
    L = -1
    R = N
    a = binary1(L, R, A, b) + 1
    c = N - binary2(L, R, C, b) - 1
    ans.append(a*c)
print((sum(ans)))


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

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

cnt = 0
for b in B:
    i = bisect.bisect_left(A, b)
    j = n-bisect.bisect_right(C, b)
    cnt += i*j

print(cnt)


import bisect
import itertools

N = int(input()) # それぞれのパーツの数
A = list(map(int, input().split())) # 小さい
B = list(map(int, input().split())) # 中くらい
C = list(map(int, input().split())) # 大きい

# Cは並び替え不要
A.sort()
B.sort()

# Bの各要素でAを二分探索して返ってきたindexを先に保有しておく
b_counts = [0] * N
for i in range(N):
    b_count = bisect.bisect_left(A, B[i])
    b_counts[i] = b_count

cumsum_b_counts = list(itertools.accumulate(b_counts))
cumsum_b_counts = [0] + cumsum_b_counts

# Cの各要素でBを二分探索。上記で保有しておいたb_countsを活用する
total = 0
for c in C:
    count = bisect.bisect_left(B, c)
    total += cumsum_b_counts[count]

print(total)



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

print(ans)

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


def upper_bound(A, x):
    s, t = -1, len(A)
    while t - s > 1:
        m = (s+t)//2
        if A[m] > x:
            t = m
        else:
            s = m
    
    return t

def lower_bound(A, x):
    s, t = -1, len(A)
    while t - s > 1:
        m = (s+t)//2
        if A[m] >= x:
            t = m
        else:
            s = m
    
    return t


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 += lower_bound(A, b) * (N - upper_bound(C, b))

print(ans)

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 j in range(n):
    i = bisect.bisect_left(A, B[j])
    k = n - bisect.bisect_right(C, B[j])
    ans += int(i*k)
print(ans)

from bisect import *

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

for b in B:
    cnt.append(bisect_left(A,b) * (N - bisect_right(C,b)))
print((sum(cnt)))



import bisect
n = int(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)
b_ans = [0] * len(b)
for i in range(len(b)):
         b_ans[i] = bisect.bisect_left(a, b[i])

ruiseki_b = [0]
for i in range(len(b_ans)):
         ruiseki_b.append(ruiseki_b[i] + b_ans[i])
ans = 0
for i in range(len(c)):
         ans += ruiseki_b[bisect.bisect_left(b, c[i])]
print(ans)


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

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