CodeEff/ECCO huggingface dataset:
# Original solution
import bisect

def main():
    N = int(eval(input()))
    A = sorted([int(i) for i in input().split()])
    B = sorted([int(i) for i in input().split()])
    C = sorted([int(i) for i in input().split()])

    counter = 0
    for c in C:
        b_count = bisect.bisect_left(B, c)
        for b in B[0:b_count]:
            a_count = bisect.bisect_left(A, b)
            counter += a_count

    print(counter)

if __name__ == "__main__":
    main()


# Optimized solution
import bisect

def main():
    N = int(eval(input()))
    A = sorted([int(i) for i in input().split()])
    B = sorted([int(i) for i in input().split()])
    C = sorted([int(i) for i in input().split()])

    counter = 0
    for b in B:
        a_count = bisect.bisect_left(A, b)
        c_count = N - bisect.bisect_right(C, b)
        counter += a_count*c_count
            

    print(counter)

if __name__ == "__main__":
    main()
# Original solution
import math
import sys
import queue
import copy
import bisect#2分探索

def input():
    return sys.stdin.readline()[:-1]
def inputi():
    return int(input())
def inputl():
    return list(map(int, input().split()))
def printl(li):
    print(*li, sep="\n")
def argsort(s):
    return sorted(range(len(s)), key=lambda k: s[k])

#mod = 10**9+7

N = inputi()
#N, K = inputl()
#L = [int(input()) for i in range(N)]
A = inputl()
B = inputl()
C = inputl()
#S = [inputl() for i in range(H)]
#q = queue.Queue() #q.put(i) #q.get() 
#q = queue.LifoQueue() #q.put(i) #q.get() 

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b=copy.deepcopy(a)  #2次元配列はこうコピーする
#w.sort(key=lambda x:x[1],reverse=True)  #二個目の要素で降順並び替え

#素数リスト
# n = 100
# primes = set(range(2, n+1))
# for i in range(2, int(n**0.5+1)):
#     primes.difference_update(range(i*2, n+1, i))
# primes=list(primes)

#bisect.bisect_left(a, 4)#aはソート済みである必要あり。aの中から最も左の4位置を返す。
#bisect.insort_left(a, 4)#挿入
A.sort(reverse=True)
B.sort()
C.sort()
tot=0
cut=N

for a in A:
    cut=bisect.bisect_right(B[0:cut], a)
    cut2=N
    for i in reversed(range(cut,N)):
        b=B[i]
        cut2=bisect.bisect_right(C[0:cut2], b)
        tot+=N-cut2
print(tot)


# Optimized solution
import sys
#import math
#import queue
#import copy
import bisect#2分探索

def input():
    return sys.stdin.readline()[:-1]
def inputi():
    return int(input())
def inputl():
    return list(map(int, input().split()))
def printl(li):
    print(*li, sep="\n")
def argsort(s):
    return sorted(range(len(s)), key=lambda k: s[k])

#mod = 10**9+7

N = inputi()
#N, K = inputl()
#L = [int(input()) for i in range(N)]
A = inputl()
B = inputl()
C = inputl()
#S = [inputl() for i in range(H)]
#q = queue.Queue() #q.put(i) #q.get() 
#q = queue.LifoQueue() #q.put(i) #q.get() 

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b=copy.deepcopy(a)  #2次元配列はこうコピーする
#w.sort(key=lambda x:x[1],reverse=True)  #二個目の要素で降順並び替え

#素数リスト
# n = 100
# primes = set(range(2, n+1))
# for i in range(2, int(n**0.5+1)):
#     primes.difference_update(range(i*2, n+1, i))
# primes=list(primes)

#bisect.bisect_left(a, 4)#aはソート済みである必要あり。aの中から最も左の4位置を返す。
#bisect.insort_left(a, 4)#挿入


##TLE
# A.sort(reverse=True)
# B.sort()
# C.sort()
# tot=0
# cut=N
# for a in A:
#     cut=bisect.bisect_right(B[0:cut], a)
#     cut2=N
#     for i in reversed(range(cut,N)):
#         b=B[i]
#         cut2=bisect.bisect_right(C[0:cut2], b)
#         tot+=N-cut2

#right ans
tot=0
A.sort()
C.sort()
for b in B:
    cut1=bisect.bisect_left(A, b)
    cut2=bisect.bisect_right(C, b)
    tot+=cut1*(N-cut2)
print(tot)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for i in range(N):
    for j in range(N):
        if A[i] < B[j]:
            for k in range(N):
                if B[j] < C[N-1-k]:
                    ans += 1
                else:
                    break
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):
    a = bisect.bisect_left(A, B[i])
    c = bisect.bisect_right(C, B[i])
    ans += a*(N-c)

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

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

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

a2=[]
for i1 in range(N):
    a2.append(bisect.bisect_left(C,B[i1]+1))
ans=0
for i0 in range(N):
    a1 = bisect.bisect_left(B,A[i0]+1)
    for i1 in range(a1,N):
        ans += N - a2[i1]
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()

a2=[]
for i1 in range(N):
    a2.append(bisect.bisect_left(C,B[i1]+1))

a2c=[0]*(N+1)
for i1 in range(N-1,-1,-1):
    a2c[i1] = a2c[i1+1] + N - a2[i1]

ans=0
for i0 in range(N):
    a1 = bisect.bisect_left(B,A[i0]+1)
    ans += a2c[a1]
print(ans)
# Original solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def abc077_c():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))
    C = list(map(int, readline().split()))
    A.sort()
    B.sort()
    C.sort()
    ans = 0

    # 二分探索で Ai < Bj < Ck となる個数を数える
    from bisect import bisect_left
    for i in range(N):
        # 真に大きいが条件なので Ai + 1 が入るポイントを探す
        jst = bisect_left(B, A[i] + 1)
        if jst == N: continue
        for j in range(jst, N):
            kst = bisect_left(C, B[j] + 1)
            ans += N - kst
    print(ans)

abc077_c()

# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def abc077_c():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))
    C = list(map(int, readline().split()))
    A.sort()
    B.sort()
    C.sort()
    ans = 0

    from bisect import bisect_left

    # Bjに対するCの使える個数は、前処理で求めておく
    B2C = [0] * N
    # 真に大きいが条件なので Ai + 1 が入るポイントを探す
    for j in range(N):
        B2C[j] = N - bisect_left(C, B[j]+1)
    # 累積和
    accum = [0]
    for j in range(N):
        accum.append(accum[-1] + B2C[j])

    # Ai -> B は二分探索
    for i in range(N):
        jst = bisect_left(B, A[i]+1)
        if jst == N: continue
        # 前処理済みなので、Bj以降を使ったときにCが何個使えるかはすぐわかる
        ans += accum[N] - accum[jst]
    print(ans)

abc077_c()
# Original solution
N = int(eval(input()))
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

a_list.sort()
c_list.sort()
result = 0
for b in b_list:
    a_count = list([x for x in a_list if x < b])
    c_count = list([x for x in c_list if x >b])
    result += len(a_count)*len(c_count)

print(result)

# Optimized solution
import bisect
N = int(eval(input()))
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

a_list.sort()
c_list.sort()
result = 0

for b in b_list:
    a_count = bisect.bisect_left(a_list, b)
    c_count = bisect.bisect_right(c_list, b)
    result += a_count*(len(c_list)-c_count)

print(result)
# Original solution
import sys
import bisect
input = sys.stdin.readline

def slove():
    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)

    ans = 0

    for i in range(n):
        k = bisect.bisect(B,A[i])
        for j in range(k,n):
            l = bisect.bisect(C,B[j])
            ans += n-l
    return ans


if __name__ == "__main__":
    print((slove()))

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

def slove():
    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)

    ans = 0

    for i in range(n):
        k = B[i]
        a = bisect.bisect_left(A,k)
        c = n-bisect.bisect_right(C,k)
        ans += a*c
        
    return ans


if __name__ == "__main__":
    print((slove()))
# 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()))

ans = 0
for second in B:
    idx = bisect.bisect_left(A, second)
    first = len(A[:idx])

    idx = bisect.bisect_right(C, second)
    third = len(C[idx:])

    ans += (first*third)

print(ans)


# Optimized solution

import bisect

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

ans = 0
for second in B:
    ai = bisect.bisect_left(A, second)
    ci = bisect.bisect_right(C, second)

    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 b in B:
    a = bisect.bisect_left(A, b) # 挿入点はどの同じ値よりも左
    c = bisect.bisect_right(C, b) # 挿入点はどの同じ値よりも右
    ans += a * (len(C)-c)
print (ans)

# Optimized solution
import bisect
n=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
ans=0
for i in range(n):
  A=bisect.bisect_left(a,b[i])
  B=bisect.bisect_right(c,b[i])
  ans=ans+A*(n-B)
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 i in range(n):
  A=bisect.bisect_left(a,b[i])
  B=bisect.bisect_right(c,b[i])
  ans=ans+A*(n-B)
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 i in b:
    q=bisect.bisect_left(a,i)
    s=bisect.bisect_right(c,i)
    ans=ans+q*(n-s)
print(ans)
# Original solution
from collections import Counter
N=int(eval(input()))
A=Counter(input().split())
B=Counter(input().split())
C=Counter(input().split())
ans=0
for a_key,a_count in A.most_common():
    for b_key,b_count in B.most_common():
        for c_key,c_count in C.most_common():
            a_key,b_key,c_key=int(a_key),int(b_key),int(c_key)
            if a_key<b_key and b_key<c_key:
                ans+=a_count*b_count*c_count
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())))
print((sum(bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b)) for b in B)))
# 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 k in b:
    pos1 = bisect.bisect_left(a,k)
    pos2 = bisect.bisect_right(c,k)
    ans += (pos1*(n-pos2))
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 k in b:
    pos1 = bisect.bisect_left(a,k)
    pos2 = bisect.bisect_right(c,k)
    ans += (pos1*(n-pos2))
print(ans)
# Original solution

n = int(eval(input()))
A, B, C = [list(map(int, input().split()))  for _ in range(3)]
cnt = 0
# O(3*N) でギリギリ？pythonだと微妙かも
# 真ん中のやつを基準にして上のやつと下のやつを比べて
# あるいはバイナリサーチ

for b in B:
    a_cnt, c_cnt = 0, 0
    for i in range(n):
        if A[i]<b:
            a_cnt+=1
        if b<C[i]:
            c_cnt+=1
    cnt += a_cnt*c_cnt
print(cnt)

# Optimized solution
# バイナリサーチで解く。
# Bの要素を基準にしてa<b<cとなるものを選ぶ。すべての配列はソート済みとして、
# a<bとなる最大のa, b<cとなる最小のcを選び、それら独立する事象の数の積を足していく

n = int(eval(input()))
A, B, C = [list(sorted(map(int, input().split())))  for _ in range(3)]

cnt = 0

def bs_left(lis, target):
    # ソート済みのlisのうちtargetがどこに入るか（index）
    # 要素がtargetと重複する場合はより小さいインデックスを返す。すなわち「lisのうちtarget未満となる最大の要素のインデックス」
    # ex) min(lis)=mとするとtarget<=mのとき0
    low, high = 0, len(lis)
    while low<high:
        mid = (low+high)//2
        if lis[mid]<target:
            low = mid+1
        else:
            high = mid
    return low

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

for b in B:
    # 探索のときにちゃんとみているので a!=b and b!=cみたいな条件は必要ない
    cnt += (bs_left(A, b) * (n-bs_right(C, b)))
print(cnt)
# 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 ai in a:
    idx_b = bisect.bisect_right(b, ai)
    if idx_b == n:
        break
    for bi in b[idx_b:]:
        ans += n - bisect.bisect_right(c, bi)
print(ans)

# Optimized solution
from itertools import accumulate
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
b_ = []
for bi in reversed(b):
    b_.append(n - bisect.bisect_right(c, bi))
b_ = list(accumulate(b_))[::-1]
for ai in a:
    idx_b = bisect.bisect_right(b, ai)
    if idx_b == n:
        break
    ans += b_[idx_b]
print(ans)
# Original solution
import sys
import math

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

array1 = list()
for b in B:
    count = 0
    for c in C:
        if b < c:
            count += 1
    array1.append(count)
ans = 0
for i in range(N):
    count = 0
    for a in A:
        if B[i] > a:
            count += 1
    ans += count * array1[i]
print(ans)

# Optimized solution
import sys
import math

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

array1 = list()
count = 0
f = 0
for j in range(N):
    for i in range(f, N):
        if B[N-1-j] < C[N-1-i]:
            count += 1
            if i == N-1:
                f = N
        else:
            f = i
            break
    array1.append(count)
ans = 0
f = 0
count = 0
for i in range(N):
    for j in range(f, N):
        if B[i] > A[j]:
            count += 1
            if j == N-1:
                f = N
        else:
            f = j
            break
    ans += count * array1[N-1-i]
print(ans)
# Original solution
from bisect import bisect_left, bisect_right

N = int(eval(input()))
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

A.sort()
C.sort()

result = 0

for i in range(N):
    a = bisect_left(A,B[i])
    c = bisect_right(C,B[i])
    result += len(A[:a]) * len(C[c:])

print(result)



# Optimized solution
from bisect import bisect_left, bisect_right

N = int(eval(input()))
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

A.sort()
C.sort()

result = 0

for i in B:
    a = bisect_left(A,i)
    c = bisect_right(C,i)
    result += a * (N - c)

print(result)
# Original solution
import bisect

N=int(eval(input()))
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
C=[int(i) for i in input().split()]
A.sort()
B.sort()
C.sort()
# print(A)
# print(B)
# print(C)

# ans=0
# for i in range(N):
#     part1=A[i]
#     part2_pos=bisect.bisect_right(B,part1)
#     for j in range(part2_pos,N):
#         part2=B[j]
#         part3_pos=bisect.bisect_right(C,part2)
#         # print(i,j,part3_spos,": ",A[i],B[j],C[part3_pos])
#         ans+=(N-part3_pos)
# print(ans)

AtoB_Pos=[]
BtoC_Pos=[]
ans=0
for i in range(N):
    B_Pos=bisect.bisect_right(B,A[i])
    AtoB_Pos.append(B_Pos)

for i in range(N):
    C_Pos=bisect.bisect_right(C,B[i])
    BtoC_Pos.append(C_Pos)
# print(AtoB_Pos)
# print(BtoC_Pos)
for i in range(N):
    for j in range(AtoB_Pos[i],N):
        # print(i,j,": ",A[i],B[j])
        # print(N-AtoB_Pos[i],N-BtoC_Pos[j])
        ans+=(N-BtoC_Pos[j])
print(ans)


# Optimized solution
import bisect

N=int(eval(input()))
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
C=[int(i) for i in input().split()]
A.sort()
B.sort()
C.sort()
# print(A)
# print(B)
# print(C)

ans=0
for j in range(N):
    a_num=bisect.bisect_left(A,B[j])
    c_num=bisect.bisect_right(C,B[j])
    # print(B[j],A[:a_num],C[c_num:])
    # print(a_num,c_num)
    ans+=a_num*(N-c_num)
print(ans)
# Original solution
import bisect
N=int(eval(input()))
ue=list(map(int,input().split()))
naka=list(map(int,input().split()))
sita=list(map(int,input().split()))
ue.sort(),sita.sort(),naka.sort()
count=0
stop=[0]*N
for i in range(N):
    k=naka[i]
    stop_index=bisect.bisect_right(sita,k)
    if stop_index!=N:
        stop[i]=N-stop_index
for i in range(N):
    k=ue[i]
    a=bisect.bisect_right(naka,k)
    if a!=N:
        count+=sum(stop[a:N])
print(count)


# Optimized solution
import bisect
N=int(eval(input()))
ue=list(map(int,input().split()))
naka=list(map(int,input().split()))
sita=list(map(int,input().split()))
sita.sort(),naka.sort(),ue.sort()
count2=[0]*N
count1=[0]*N
for i in range(N):
    m = naka[i]
    k=naka[i]
    small=bisect.bisect_left(ue,k)
    count1[i]=small
    big = bisect.bisect_right(sita, m)
    count2[i]=N-big
ans=0
for i in range(N):
    ans+=count1[i]*count2[i]
print(ans)
# Original solution
def search(key, L):
    inc = -1
    exc = N
    while abs(inc-exc) > 1:
        mid = (inc+exc) // 2
        if True if L[mid] <= key else False:
            inc = mid
        else:
            exc = mid
    return exc


def main():
    ans = 0
    for a in A:
        for i in range(search(a, B), N):
            ans += N - search(B[i], C)
    print(ans)


if __name__ == "__main__":
    N = int(eval(input()))
    A = [int(a) for a in input().split()]
    B = sorted([int(b) for b in input().split()])
    C = sorted([int(c) for c in input().split()])
    main()


# Optimized solution
def search(key, L):
    inc = -1
    exc = N
    while abs(inc-exc) > 1:
        mid = (inc+exc) // 2
        if True if L[mid] <= key else False:
            inc = mid
        else:
            exc = mid
    return exc


def main():
    ans = 0
    for a in A:
        e = search(a, B)
        if e < N:
            ans += E[e]
    print(ans)


if __name__ == "__main__":
    N = int(eval(input()))
    A = [int(a) for a in input().split()]
    B = sorted([int(b) for b in input().split()])
    C = sorted([int(c) for c in input().split()])
    E = [0]*N
    for i in range(1, N+1):
        E[-i] = (N-search(B[N-i], C)) + E[-i+1]
    main()
# Original solution
import bisect

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

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

up_mid = [N - bisect.bisect_right(B, x) for x in A]
mid_down = [N - bisect.bisect_right(C, x) for x in B]

ans = 0
for i in up_mid:
    ans += sum(mid_down[::-1][:i])
print(ans)

# Optimized solution
import bisect

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

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

ans = 0
for b in B:
    ans += bisect.bisect_left(A, b) * (N - bisect.bisect_right(C, b))
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()))
AB = []
total = 0
for i in range(len(B)):
  count = 0
  for j in range(len(A)):
    if A[j]<B[i]:
      count+=1
  AB.append(count)
for i in range(len(C)):
  for j in range(len(B)):
    if B[j]<C[i]:
      total+=AB[j]
print(total)

# 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()
AB = [0]*N
total = 0
for i in range(N):
  left = -1
  right = N
  while right-left>1:
    mid = left + (right-left)//2
    if A[mid]>=B[i]:
      right = mid
    else:
      left = mid
  AB[i]=right
for i in range(1,N):
  AB[i]+=AB[i-1]
for i in range(N):
  left = -1
  right = N
  while right-left>1:
    mid = left + (right-left)//2
    if B[mid]>=C[i]:
      right = mid
    else:
      left = mid
  if right!=0:
    total+=AB[right-1]
print(total)
# 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()
AB = [0]*N
total = 0
for i in range(N):
  left = -1
  right = N
  while right-left>1:
    mid = left + (right-left)//2
    if A[mid]>=B[i]:
      right = mid
    else:
      left = mid
  AB[i]=right
for i in range(1,N):
  AB[i]+=AB[i-1]
for i in range(N):
  left = -1
  right = N
  while right-left>1:
    mid = left + (right-left)//2
    if B[mid]>=C[i]:
      right = mid
    else:
      left = mid
  if right!=0:
    total+=AB[right-1]
print(total)

# 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()
total = 0
for i in range(N):
  left = -1
  right = N
  while right-left>1:
    mid = left + (right-left)//2
    if A[mid]>=B[i]:
      right = mid
    else:
      left = mid
  left2 = -1
  right2 = N
  while right2-left2>1:
    mid2 = left2 + (right2-left2)//2
    if C[mid2]>B[i]:
      right2 = mid2
    else:
      left2 = mid2
  total+=right*(N-right2)
print(total)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
B = list(map(int, input().split()))
B.sort(reverse=True)
C = list(map(int, input().split()))
C.sort(reverse=True)

Bn = [0] * N
prea = 0
for b in range(N):
    for a in range(prea, N):
        if A[a] < B[b]:
            prea = a
            break
    else:
        break
    Bn[b] = N-a

ans = 0
preb = 0
for c in range(N):
    for b in range(preb, N):
        if B[b] < C[c]:
            preb = b
            break
    else:
        break
    ans += sum(Bn[b:])

print(ans)


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

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

print(ans)