CodeEff/ECCO huggingface dataset:
# Original solution
N=list(map(int,input().split()))
A=sorted(list(map(int,input().split())))
B=list(map(int,input().split()))
C=sorted(list(map(int,input().split())))

def countA(target,L):
  ok=-1
  ng=len(L)
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if L[mid]<target:
      ok=mid
    else:
      ng=mid
  return (ok+1)

def countC(target,L):
  ok=len(L)
  ng=-1
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if L[mid]>target:
      ok=mid
    else:
      ng=mid
  return len(L)-ok

ans=0
for i in range(len(B)):
  data=B[i]
  ans+=(countA(data,A)*countC(data,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())))

# Bの値を決める
# Bより小さいAを二分探索、Bより大きいAを二分探索、その積を各Bごとに求めて足していく

import bisect
ans=0
for i in range(len(B)):
  apos=bisect.bisect_left(A,B[i])
  cpos=bisect.bisect_right(C,B[i])
  ans+=(apos)*(N-cpos)
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())))
p = [0]*n
q = [0]*n
k = 0
for i in range(n):
  while k<n:
    if a[k]<b[i]:
      k += 1
    else:
      break
  p[i] = k
k = 0
for i in range(n):
  while k<n:
    if b[k]<c[i]:
      k += 1
    else:
      break
  q[i] = sum(p[:k])
print((sum(q)))


# 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())))
p = [0]*n
q = [0]*n
k = 0
for i in range(n):
  while k<n:
    if a[k]<b[i]:
      k += 1
    else:
      break
  p[i] = k
k = 0
s = 0
ans = 0
for i in range(n):
  while k<n:
    if b[k]<c[i]:
      s += p[k]
      k += 1
    else:
      break
  ans += s
print(ans)
# Original solution
from bisect import *
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 c in C:
    for b in B[:bisect_left(B,c)]:
        ans+=bisect_left(A,b)
print(ans)

# Optimized solution
from bisect import *
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:
    ans+=(n-bisect(C,b))*bisect_left(A,b)
print(ans)
# Original solution
def binary_search_A(N,A,b):
    upper = N - 1
    lower = 0
    
    while upper - lower > 1:
        middle = upper + lower // 2
        if A[middle] > b:
            upper = middle
        else:
            lower = middle
            
    if b >= A[upper]:
      return upper+1
    elif b >= A[lower]:
      return lower+1
    else:
      return lower

def binary_search_C(N,C,b):
    upper = N - 1
    lower = 0
    
    
    while upper - lower > 1:
        middle = upper + lower // 2
        if C[middle] > b:
            upper = middle
        else:
            lower = middle
            
            
    if b < C[lower]:
      return N-lower
    elif b < C[upper]:
      return N - (lower+1)
    else:
      return N - (upper+1)
    


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()
B.sort()
C.sort()

ans = 0

for i in range(N):
    j = binary_search_A(N, A, B[i])
    #print(j)
    k = binary_search_C(N, C, B[i])
    #print(k)
    ans += j * k
    
print(ans)

# Optimized solution
def binary_search_low(ls, v):
    """
    [input]
        ls: 二分探索するリスト(配列)
        v: 探索の基準となる値
    [output]
        ok: 基準を満たす最大index
        (ng: 基準を満たさない最小index)
    """
    ok = -1
    ng = n

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if ls[mid] < v: ok = mid
        else: ng = mid
        
    return ok  #, ng
    
def binary_search_high(ls, v):
    """
    [input]
        ls: 二分探索するリスト(配列)
        v: 探索の基準となる値
    [output]
        ok: 基準を満たす最大index
        (ng: 基準を満たさない最小index)
    """
    ng = -1
    ok = n

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if ls[mid] > v: ok = mid
        else: ng = mid
        
    return ok


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_count = binary_search_low(A,b) + 1
    b_count = n - binary_search_high(C, b)
    #print(a_count,b_count)

    ans += a_count*b_count


print(ans)
# Original solution
def binary_search_low(ls, v):
    """
    [input]
        ls: 二分探索するリスト(配列)
        v: 探索の基準となる値
    [output]
        ok: 基準を満たす最大index
        (ng: 基準を満たさない最小index)
    """
    ok = -1
    ng = n

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if ls[mid] < v: ok = mid
        else: ng = mid
        
    return ok  #, ng
    
def binary_search_high(ls, v):
    """
    [input]
        ls: 二分探索するリスト(配列)
        v: 探索の基準となる値
    [output]
        ok: 基準を満たす最大index
        (ng: 基準を満たさない最小index)
    """
    ng = -1
    ok = n

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if ls[mid] > v: ok = mid
        else: ng = mid
        
    return ok


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_count = binary_search_low(A,b) + 1
    b_count = n - binary_search_high(C, b)
    #print(a_count,b_count)

    ans += a_count*b_count


print(ans)




# Optimized solution
def binary_search_low(ls, v):
    """
    ・基準(v)より小さい値が配列の中に何個あるか, 二分探索によって見つける.
    [input]
        ls: 二分探索するリスト(配列)
        v: 探索の基準となる値
    [output]
        return: 基準を満たす配列の要素数
    """
    ok = -1
    ng = n

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if ls[mid] < v: ok = mid
        else: ng = mid
        
    return ok+1
    
def binary_search_high(ls, v):
    """
    ・基準(v)より大きい値が配列の中に何個あるか, 二分探索によって見つける.
    [input]
        ls: 二分探索するリスト(配列)
        v: 探索の基準となる値
    [output]
        return: 基準を満たす配列の要素数
    """
    ng = -1
    ok = n

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if ls[mid] > v: ok = mid
        else: ng = mid
        
    return len(ls) - ok


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_count = binary_search_low(A,b)
    b_count = binary_search_high(C, b)
    ans += a_count*b_count

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())))
ans=0
for i in b:
    he=-1
    ta=n
    while ta-he>1:
        mid=(he+ta)//2
        if i>a[mid]:
            he=mid
        else:
            ta=mid
    x=he+1

    he_=-1
    ta_=n
    while ta_-he_>1:
        mid_=(he_+ta_)//2
        if i>=c[mid_]:
            he_=mid_
        else:
            ta_=mid_
    y=n-ta_
    ans+=x*y
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 i in b:
    x=bisect.bisect_left(a,i)
    y=n-bisect.bisect_right(c,i)
    ans+=x*y
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 i in b:
    x=bisect.bisect_left(a,i)
    y=n-bisect.bisect_right(c,i)
    ans+=x*y
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 i in b:
    A=bisect.bisect_left(a,i)
    B=len(b)-bisect.bisect_right(c,i)
    ans+=A*B
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 i in b:
    A=bisect.bisect_left(a,i)
    B=len(b)-bisect.bisect_right(c,i)
    ans+=A*B
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:
    ans+=(n-bisect.bisect_right(c,i))*bisect.bisect_left(a,i)

print(ans)
# Original solution
import bisect
ans = 0
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()
lis_B = [0] * N
for i in range(N):
  tmp = bisect.bisect_right(C, B[i])
  if tmp  == N:
    break
  lis_B[i] = N - tmp
for i in range(N):
  tmp = bisect.bisect_right(B, A[i])
  if tmp == N:
    break
  ans += sum(lis_B[tmp:N])
print(ans)

# Optimized solution
import bisect
ans = 0
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()
for i in range(N):
  tmp_1 = bisect.bisect_right(C, B[i])
  tmp_2 = bisect.bisect_left(A, B[i])
  ans += (N - tmp_1) * tmp_2
print(ans)
# Original solution
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    n = int(eval(input()))
    # 整数複数個
    # a, b = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    #N = [list(map(int, input().split())) for i in range(3)]

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

    import bisect
    cnt = 0
    for ai in range(n):
        j = bisect.bisect_right(B, A[ai])

        for bi in range(j, n):
            k = bisect.bisect_right(C, B[bi])
            cnt += n - k
        #print(cnt)

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

resolve()

# Optimized solution
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    n = int(eval(input()))
    # 整数複数個
    # a, b = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    #N = [list(map(int, input().split())) for i in range(3)]

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

    import bisect
    cnt = 0
    for bi in B:
        a_ok = bisect.bisect_left(A, bi)
        c_ok = bisect.bisect_right(C, bi)
        cnt += a_ok * (n - c_ok)
    print(cnt)

resolve()
# 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()
memo = [0]*(n+1)
for i in range(n):
    memo[bisect.bisect_left(b,c[i])] += 1
for i in range(n-1,-1,-1):
    memo[i] += memo[i+1]
for i in range(n-1,-1,-1):
    memo[i] += memo[i+1]
memo = memo[1:]+[0]
ans = 0

for i in range(n):
    ans += memo[bisect.bisect_right(b,a[i])]
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()
b.sort()
c.sort()
ans = 0
for i in range(n):
    t = b[i]
    ci = bisect.bisect_right(c,t)
    ai = bisect.bisect_left(a,t)
    ans += ai*(n-ci)
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 a in A:
    i = bisect.bisect_right(B, a)
    for b in B[i:]:
        j = bisect.bisect_right(C, b)
        ans += N-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.sort()
B.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)
# Original solution
def C_SnukeFestival(N, A, B, C):
    a = sorted(A)
    b = sorted(B)
    c = sorted(C)

    l = N
    ans = 0
    for i in range(N):
        for j in range(N):
            for k in range(N):
                if a[i] < b[j] and b[j] < c[k]:
                    ans += 1
    return ans

N = int(eval(input()))
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]
print((C_SnukeFestival(N, A, B, C)))
#間に合いそうもない

# Optimized solution
def C_SnukeFestival(N, A, B, C):
    a = sorted(A)
    b = sorted(B)
    c = sorted(C)

    import bisect
    ans = 0
    for j in range(N):
        # b[j]より小さなaの要素の個数
        i = bisect.bisect_left(a, b[j])
        # b[j]より大きなcの要素の個数
        k = N - bisect.bisect_right(c, b[j])
        ans += i * k
    return ans

N = int(eval(input()))
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]
print((C_SnukeFestival(N, A, B, C)))
# Original solution
import bisect
import math
 
N=int(eval(input()))
b1=0

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

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

B.append(math.inf)

for i in range(len(A)):
  b1=bisect.bisect_right(B,A[i])
  for j in range(b1,len(B)-1):
    ans += D[j]

print(ans)

# Optimized solution
import bisect
 
N=int(eval(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)
# Original solution
import bisect
N = int(eval(input()))
# サイズが下の方が大きくないとダメtop<mid<bottom
tops = sorted(list(map(int, input().split(" "))))
mids = list(map(int, input().split(" ")))
bottoms = sorted(list(map(int, input().split(" "))))
# print(tops)
# print(mids)
# print(bottoms)


# def left_binary_search(check_list, num, left, right):
#     if left > right:
#         return left
#     mid = (left + right) // 2
#     if check_list[mid] >= num:
#         return left_binary_search(check_list, num, left, mid - 1)
#     else:
#         return left_binary_search(check_list, num, mid + 1, right)


# def right_binary_search(check_list, num, left, right):
#     if left > right:
#         return left
#     mid = (left + right) // 2
#     if check_list[mid] > num:
#         return right_binary_search(check_list, num, left, mid - 1)
#     else:
#         return right_binary_search(check_list, num, mid + 1, right)


total_count = 0
for mid in mids:
    # bottom_start_index = right_binary_search(bottoms, mid, 0, N - 1)
    bottom_start_index = bisect.bisect_right(bottoms, mid)
    # top_end_index = left_binary_search(tops, mid, 0, N - 1)
    top_end_index = bisect.bisect_left(tops, mid)
    total_count += ((N - bottom_start_index) * top_end_index)
print(total_count)


# Optimized solution
N = int(eval(input()))
tops = list(map(int, input().split()))
middles = list(map(int, input().split()))
bottoms = list(map(int, input().split()))
tops.sort()
middles.sort()
bottoms.sort()
# print(tops)
# print(middles)
# print(bottoms)
# top<middle<bottomでないといけない
# middleをfor文で繰り返して、topとbottomで二分探索をする。
# そしてそれ以下の数を出して、掛け算すれば組み合わせの数を出せる


def left_binary_search(target, nums):
    left = 0
    right = len(nums) - 1
    while left <= right:
        # 0+7 /2 = 3
        # print(left, right)
        mid = int((left + right) / 2)
        # print(f'mid: {mid}')
        if nums[mid] < target:
            left = mid + 1
        elif nums[mid] > target:
            right = mid - 1
        else:
            right = mid - 1

    # 0,1,2,3,4
    # 2
    # => return 2
    # print(left, right)
    return left


def right_binary_search(target, nums):
    left = 0
    right = len(nums) - 1
    while left <= right:
        # 0+7 /2 = 3
        # print(left, right)
        mid = int((left + right) / 2)
        if nums[mid] < target:
            left = mid + 1
        elif nums[mid] > target:
            right = mid - 1
        else:
            left = mid + 1

    # 0,1,2,3,4
    # 2
    # => return 2
    # print(left, right)
    return left


count = 0
for middle in middles:
    top_index = left_binary_search(middle, tops)
    bottom_index = right_binary_search(middle, bottoms)
    # print(top_index, bottom_index, (top_index) * (len(bottoms) - bottom_index))
    count += (top_index) * (len(bottoms) - bottom_index)
print(count)
# Original solution
from sys import stdin


def input():
    return stdin.readline().strip()


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

    nums = [0] * (N + 1)

    for i, b in enumerate(B):
        ng = -1
        ok = N
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if C[mid] > b:
                ok = mid
            else:
                ng = mid

        nums[i] = N - ok

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

    ans = 0
    for a in A:
        ng = -1
        ok = N
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if B[mid] > a:
                ok = mid
            else:
                ng = mid

        ans += nums[ok]

    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
from sys import stdin


def input():
    return stdin.readline().strip()


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

    nums = [0] * (N + 1)

    ng = -1
    for i, b in enumerate(B):
        ok = N
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if C[mid] > b:
                ok = mid
            else:
                ng = mid

        nums[i] = N - ok

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

    ans = 0
    ng = -1
    for a in A:
        ok = N
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if B[mid] > a:
                ok = mid
            else:
                ng = mid

        ans += nums[ok]

    print(ans)


if __name__ == "__main__":
    main()
# Original solution
from sys import stdin


def input():
    return stdin.readline().strip()


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

    nums = [0] * (N + 1)

    ng = -1
    for i, b in enumerate(B):
        ok = N
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if C[mid] > b:
                ok = mid
            else:
                ng = mid

        nums[i] = N - ok

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

    ans = 0
    ng = -1
    for a in A:
        ok = N
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if B[mid] > a:
                ok = mid
            else:
                ng = mid

        ans += nums[ok]

    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
from sys import stdin
from bisect import bisect_left


def input():
    return stdin.readline().strip()


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

    nums = [0] * (N + 1)

    pos = 0
    for i, b in enumerate(B):
        pos = bisect_left(C, b + 1, pos)
        nums[i] = N - pos

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

    ans = 0
    pos = 0
    for a in A:
        pos = bisect_left(B, a + 1, pos)
        ans += nums[pos]

    print(ans)


if __name__ == "__main__":
    main()
# Original solution
from sys import stdin
from bisect import bisect_right, bisect_left


def input():
    return stdin.readline().strip()


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

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

    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
from sys import stdin
from bisect import bisect_right, bisect_left


def input():
    return stdin.readline().strip()


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

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


if __name__ == "__main__":
    main()
# Original solution
from sys import stdin
from bisect import bisect_right, bisect_left


def input():
    return stdin.readline().strip()


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 = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B)
    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
from sys import stdin
from bisect import bisect_right, bisect_left


def input():
    return stdin.readline().strip()


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

    print(ans)


if __name__ == "__main__":
    main()
# Original solution
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N, *ABC = list(map(int, read().split()))
    A = sorted(ABC[:N])
    B = sorted(ABC[N : 2 * N])
    C = sorted(ABC[2 * N : 3 * N])

    ans = 0
    for b in B:
        ok = -1
        ng = N
        while ng - ok > 1:
            mid = (ok + ng) // 2
            if A[mid] < b:
                ok = mid
            else:
                ng = mid
        a_num = ok + 1

        ok = N
        ng = -1
        while ok - ng > 1:
            mid = (ok + ng) // 2
            if C[mid] > b:
                ok = mid
            else:
                ng = mid
        c_num = N - ok

        ans += a_num * c_num

    print(ans)
    return


if __name__ == '__main__':
    main()


# Optimized solution
import sys
from bisect import bisect_left, bisect_right

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N, *ABC = list(map(int, read().split()))
    A = sorted(ABC[:N])
    B = ABC[N : 2 * N]
    C = sorted(ABC[2 * N : 3 * N])

    ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B)

    print(ans)
    return


if __name__ == '__main__':
    main()