CodeEff/ECCO huggingface dataset:
# 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 = sorted(a)
b = sorted(b)
c = sorted(c)

ans = 0

for x in b:
    aa = bisect.bisect_left(a,x)
    cc = len(c) - bisect.bisect_right(c,x)
    ans += aa * cc

print(ans)

# Optimized solution
import bisect

n = int(eval(input()))
lstA = sorted(list(map(int,input().split())))
lstB = sorted(list(map(int,input().split())))
lstC = sorted(list(map(int,input().split())))

ans = 0
for i in range(n):
    num = lstB[i]
    top = bisect.bisect_left(lstA, num)
    btm = n - bisect.bisect_right(lstC, num)
    ans += top*btm
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()
C.sort()

ans = 0
mem_idx_a = {}
for idx_b in range(N):
  idx_c = bisect.bisect_right(C,B[idx_b])
  idx_a = bisect.bisect_left(A,B[idx_b])
  ans += (N-idx_c)*idx_a
print(ans)

# Optimized solution
import bisect

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

ans = 0
for b in B:
    idx_a = bisect.bisect_left(A, b)
    idx_c = bisect.bisect(C, b)
    ans += idx_a * (N - idx_c)
print(ans)
# Original solution
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_check = [n] * n
c_check = [0] * n
for i,j in enumerate(sorted(b)):
    for k,l in enumerate(sorted(c)):
        if l > j:
            c_check[i] = n - k
            break
    for k,l in enumerate(sorted(a)):
        if l >= j:
            a_check[i] = k
            break
ans = 0
for i in range(n):
    ans += a_check[i] * c_check[i]
print(ans)

# Optimized solution
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()], reverse=True)

a.append(10**9)

check_a = 0
check_c = n - 1
ans = 0
for i in b:
    while a[check_a] < i and check_a < n :
        check_a += 1
    while c[check_c] <= i and check_c >= 0:
        check_c -= 1
    ans += check_a * (check_c + 1)
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()
length = len(A)
#A<B<Cの組み合わせの数が答え
for i in range(length):
    #Aを1つ決めた時、BがA以下の値
    A_miman = bisect.bisect_right(B,A[i])
    for j in range(A_miman,N):
        #Bを1つ決めた時、CがBより大きい値の数をansに足す
        ans += N - bisect.bisect_right(C, B[j])
        


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


#A<B<Cの組み合わせの数が答え
for i in range(N):
    #Bを1つ決めた時、AがB未満の場合の総数
    B_miman = bisect.bisect_left(A,B[i])
    #Bを1つ決めた時、CがB以上の場合の総数
    B_ijou = N - bisect.bisect_right(C, B[i])

    ans+= B_miman*B_ijou

print(ans)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

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

from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort

ans = 0

for b in B:
    ans += bisect_left(A,b) * (N - bisect_right(C,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()
from bisect import *
ans = 0
for b in B:
  a = bisect_left(A,b)
  c = N-bisect_right(C,b)
  ans += a*c
print(ans)
# Original solution
N = int(eval(input()))
ABC = [sorted(list(map(int,input().split()))) for i in range(3)]

ans = 0
for i in range(N):
  for j in range(N):
    if ABC[0][i]>=ABC[1][j]:
      continue
    else:
      for k in range(N):
        if ABC[1][j]>=ABC[2][k]:
          continue
        else:
          ans += 1
    
print(ans)

# Optimized solution
import bisect
N = int(eval(input()))
ABC = [sorted(list(map(int,input().split()))) for i in range(3)]

ans = 0
for b in ABC[1]:
  ans += bisect.bisect_left(ABC[0],b)*(N-bisect.bisect_right(ABC[2],b))
print(ans)
# Original solution
import bisect

n = int(eval(input()))
a,b,c = [list(sorted(map(int, input().split())))  for _ in range(3)]

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

# Optimized solution
import bisect

n = int(eval(input()))
a,b,c = [list(sorted(map(int, input().split())))  for _ in range(3)]

ans = 0
for i in b:
    x = bisect.bisect_left(a, i)
    y = len(c) - bisect.bisect_right(c, i)
    ans += x*y

print(ans)
# Original solution
#!/usr/bin/env python3
from itertools import product, permutations, combinations
N=int(eval(input()))
A=sorted(list(map(int, input().split())), reverse=True)
B=sorted(list(map(int, input().split())), reverse=True)
C=sorted(list(map(int, input().split())), reverse=True)

ret = 0
for i in C:
    small_b = [b for b in B if b < i]
    for j in small_b:
        small_a = [a for a in A if a < j]
        ret += len(small_a)

print(ret)

# Optimized solution
#!/usr/bin/env python3
from itertools import product, permutations, combinations
from bisect import bisect_right,bisect_left
N=int(eval(input()))
A=sorted(list(map(int, input().split())))
B=sorted(list(map(int, input().split())))
C=sorted(list(map(int, input().split())))


ret = 0
for i in range(N):
    # 中段を決めた時、その値より小さくなる上段を探す
    new_A = bisect_left(A, B[i])
    # 中段を決めた時、その値より大きくなる下段を探す
    new_C = bisect_right(C, B[i])
    # 組み合わせ
    ret += new_A * (N - new_C)

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

def is_ok(arg, target, abc):
    if abc[arg] > target:
        return True
    else:
        return False

def bict(left, right, target, abc):

    while(right - left > 1):
        mid = (right + left)//2

        if is_ok(mid, target, abc):
            right = mid
        else:
            left = mid

    return right

cnt = 0
for a in A:
    b_min_index = bict(-1, N, a, B)
    for b_index in range(b_min_index,N):
        c_min_index = bict(-1, N ,B[b_index],C)
        c_num = N - c_min_index
        cnt += c_num

print(cnt)


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

def is_ok(arg, target, abc):
    if abc[arg] >= target:
        return True
    else:
        return False

def is_ok2(arg, target, abc):
    if abc[arg] > target:
        return True
    else:
        return False


def bict(left, right, target, abc, jug):

    while(right - left > 1):
        mid = (right + left)//2

        if jug(mid, target, abc):
            right = mid
        else:
            left = mid

    return right

cnt = 0
for b in B:
    a_min_index = bict(-1, N, b, A, is_ok)
    c_min_index = bict(-1, N, b, C, is_ok2)
    temp = (a_min_index - 1 + 1) * (N - c_min_index)
    cnt += temp

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

n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
cnt = 0

for i in range(n):
    if a[i] > b[n - 1]:
        break
    insert_index_b = bisect.bisect_right(b, a[i])  # 昇順
    for j in range(insert_index_b, n):
        insert_index_c = bisect.bisect_right(c, b[j])
        cnt += n - insert_index_c

print(cnt)


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

n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
cnt = 0
ans = 0
memo = [0] * n

for i in range(n):
    insert_index_c = bisect.bisect_right(c, b[i])
    cnt += n - insert_index_c
    memo[i] += cnt

for i in range(n):
    if a[i] > b[n - 1]:
        break
    insert_index_b = bisect.bisect_right(b, a[i])  # 昇順
    if insert_index_b >= 1:
        ans += memo[n - 1] - memo[insert_index_b - 1]
    else:
        ans += memo[n - insert_index_b - 1]

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
#初めから、どこに挿入されるのかを考えておく
A = {}
B = {}
C = {}
for i in range(n):
    B[c[i]] = min(bisect.bisect_left(b, c[i]), n)
    A[b[i]] = min(bisect.bisect_left(a, b[i]), n)
for i in range(n):
    Bindex = B[c[i]]
    for j in range(Bindex):
        Aindex = A[b[j]]
        ans +=  (Aindex)
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
#初めから、どこに挿入されるのかを考えておく
Bcount = [0 for i in range(n+1)]
for i in range(1,n+1):
    Bcount[i] = bisect.bisect_left(a, b[i-1]) + Bcount[i - 1]

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

    ans += Bcount[index]
print(ans)
# Original solution
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(reverse=True)
p=0
q=0
i = 0
ans = 0
for bss in b:
  p = 0
  q = 0
  for ass in a:
    if ass < bss:
      p += 1
  for css in c:
    if css > bss:
      q += 1
  ans += p*q
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()
c.sort()
ans = 0
def find_lt(a, x):
    'Find rightmost value less than x'
    i = bisect.bisect_left(a, x)
    if i:
        return i
    return 0
def find_gt(a, x):
    'Find leftmost value greater than x'
    i = bisect.bisect_right(a, x)
    if i != len(a):
        return len(a)-i
    return 0
for bs in b:
  ans += find_lt(a, bs)*find_gt(c,bs)
print(ans)
# Original solution
N=int(eval(input()))
A,B,C=[sorted(map(int,input().split())) for i in range(3)]
ans=a=c=0
for i in B:
    for j in A[a:]:
        if i>j:a+=1
        else: break
    for k in C[c:]:
        if i<k:break
        else: c+=1
    if c==N:break
    ans+=a*(N-c)
print(ans)

# Optimized solution
N=int(eval(input()))
A,B,C=[sorted(map(int,input().split())) for i in range(3)]
ans=a=c=0
for i in B:
    while a<N and A[a]<i:
        a+=1
    while c<N and C[c]<=i:
        c+=1
    if c==N:break
    ans+=a*(N-c)
print(ans)
# Original solution
import sys
import bisect

n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
c = list(map(int, sys.stdin.readline().split()))

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

b_ans_list = [0 for _ in range(n)]
for i in range(n):
    # b[i]における選択可能なcの個数
    b_ans_list[i] = n - bisect.bisect_right(c, b[i])

ans = 0

for i in range(n):
    b_index = bisect.bisect_right(b, a[i])
    ans += sum(b_ans_list[b_index::])

print(ans)


# Optimized solution
import sys
import bisect

n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
c = list(map(int, sys.stdin.readline().split()))

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

b_ans_list = [0 for _ in range(n)]
for i in reversed(list(range(n))):
    # b[i]における選択可能なcの個数
    if i == n-1:
        b_ans_list[i] = n - bisect.bisect_right(c, b[i])
    else:
        b_ans_list[i] = n - bisect.bisect_right(c, b[i]) + b_ans_list[i+1]

ans = 0
for i in range(n):
    b_index = bisect.bisect_right(b, a[i])
    if b_index < n: ans += b_ans_list[b_index]

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())))
counter = 0
for i in range(len(A)):
    b_index = bisect.bisect(B,A[i])
    if b_index >= len(B):
        break
    b_diam = B[b_index]
    for j in range(b_index,len(B)):
        c_index = bisect.bisect(C,B[j])
        if c_index >= len(C):
            break
        counter += len(C)-c_index
print(counter)


# 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())))
counter = 0
for i in range(len(B)):
    #Bより小さいAの探索
    Ind_A = bisect.bisect_left(A,B[i])
    if A[Ind_A-1] == B[i]:
        Ind_A -= 1
    
    #Bより大きいCの探索
    Ind_C = bisect.bisect_right(C,B[i])
    num_C = len(C)-Ind_C
    counter += round(Ind_A*num_C)
    #print('B[i] =' +str(B[i]),end='')
    #print(' Ind_A =' +str(Ind_A),end='')
    #print(' Ind_C =' +str(Ind_C),end = '')
    #print(' num_C =' +str(num_C),end = '')    
    #print(' 総数 ' + str(Ind_A*num_C))
print(counter)
# 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()

count = 0
for i in range(N):
    b_idx = bisect.bisect_right(B, A[i])
    for j in range(b_idx, N):
        c_idx = bisect.bisect_right(C, B[j])
        count += N - c_idx

print(count)

# 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()
BtoC = [0 for i in range(N+1)]
for i in range(N-1, -1, -1):
    c_idx = bisect.bisect_right(C, B[i])
    BtoC[i] = BtoC[i+1] + (N - c_idx)
count = 0
for i in range(N):
    b_idx = bisect.bisect_right(B, A[i])
    count += BtoC[b_idx]


print(count)
# Original solution
N = int(input().rstrip())
A = list(map(int, input().rstrip().split()))
B = list(map(int, input().rstrip().split()))
C = list(map(int, input().rstrip().split()))

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

def bin_search(vlist, targ):
    lb = -1
    ub = len(vlist)
    while ub - lb > 1:
        mid = (lb + ub) // 2
        if vlist[mid] >= targ:
            ub = mid
        else:
            lb = mid
    return ub

total = 0
for c in C:
    b_ub = bin_search(B, c)
    for b in B[:b_ub]:
        a_ub = bin_search(A, b)
        total += len(A[:a_ub])

print(total)

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

print(ans)
# Original solution
#https://atcoder.jp/contests/abc077/tasks/arc084_a
N = int(eval(input()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
a.sort()
b.sort()
c.sort()
for bi in b:
    ai = 0
    ci = N-1
    while ai < N and a[ai] < bi:
        ai += 1
    while ci >= 0 and c[ci] > bi:
        ci -= 1
    ans += ai * (N - 1 -ci)
print(ans)


# Optimized solution
#https://atcoder.jp/contests/abc077/tasks/arc084_a
N = int(eval(input()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
a.sort()
b.sort()
c.sort()
ai = 0
ci = 0
for bi in b:
    while ai < N and a[ai] < bi:
        ai += 1
    while ci < N and c[ci] <= bi:
        ci += 1
    ans += ai * (N -ci)
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())))
cnt = 0
info = []

for i in range(n):
    b_p = bisect.bisect_left(a, b[i])
    info.append(b_p)

for k in range(n):
    a_p = bisect.bisect_left(b, c[k])
    cnt += sum(info[:a_p])

print(cnt)

# 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())))
cnt = 0
info1 = []


for i in range(n):
    b_p = bisect.bisect_left(a, b[i])
    info1.append(b_p) # bがそれぞれ何種類のaを載せれるか

info2 = [info1[0]]
for l in range(1, n):
    info2.append(info2[l-1] + info1[l])

for k in range(n):
    a_p = bisect.bisect_left(b, c[k])
    if a_p != 0:
        cnt += info2[a_p - 1]  # cがそれぞれ何種類のbを載せれるか
print(cnt)
# Original solution
from bisect import bisect_right

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

ans = 0
y_low = {}
i = 0
for x in A:
    y_low[i] = bisect_right(B, x)
    i += 1
for y_lowi in list(y_low.values()):
    for y in B[y_lowi:]:
        z_low = bisect_right(C, y)
        ans += N - z_low
print(ans)


# Optimized solution
from bisect import bisect_left
from bisect import bisect_right


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

ans = 0
y_low = {}
i = 0
for y in B:
    x = bisect_left(A, y)
    z = bisect_right(C, y)
    ans += x * (N-z)
print(ans)
# Original solution
def lowerBound(arr, n):
    arr += [10e9+7]
    low, high = 0, len(arr)
    mid = (low+high)//2
    while high-low>1:
        if arr[mid]>=n: high = mid
        else: low = mid
        mid = (low+high)//2
    return high

def upperBound(arr, n):
    arr = [0] + arr
    low, high = 0, len(arr)
    mid = (low+high)//2
    while high-low>1:
        if arr[mid]>n: high = mid
        else: low = mid
        mid = (low+high)//2
    return low

n = int(eval(input()))
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))

ans = 0
for i in b:
    cnt_a = lowerBound(a, i)
    cnt_b = n - upperBound(c, i)
    ans += cnt_a * cnt_b
print(ans)

# Optimized solution
def lowerBound(arr, n):
    low, high = -1, len(arr)
    while high-low>1:
        mid = (low+high)//2
        if arr[mid]>=n: high = mid
        else: low = mid
    return high

def upperBound(arr, n):
    low, high = -1, len(arr)
    while high-low>1:
        mid = (low+high)//2
        if arr[mid]>n: high = mid
        else: low = mid
    return low+1

n = int(eval(input()))
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))

ans = 0
for i in b:
    cnt_a = lowerBound(a, i)
    cnt_b = n - upperBound(c,i)
    ans += cnt_a * cnt_b
print(ans)
# Original solution
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()
c = c[::-1]
answer,x,y = 0,0,0
for j in b:
	for k in range(x,n):
		if a[k] >= j:
			x = k
			break
		elif k == n-1:
			x = n
	for k2 in range(n):
		if c[k2] <= j:
			y = k2
			break
		elif k2 == n-1:
			y = n
	answer += x*y
print(answer)


# 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()
c.sort()
answer = 0
for i in b:
	x = bisect.bisect_right(c,i)
	y = bisect.bisect_left(a,i)
	answer += (n-x)*y
print(answer)
# 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())))
sm=0
for i in C:
  b=bisect.bisect_left(B,i)
  for j in B[:b]:
    sm+=bisect.bisect_left(A,j)
print(sm)
  

# 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())))
sm=0
for j in B:
  sm+=bisect.bisect_left(A,j)*(n-bisect.bisect_right(C,j))
print(sm)
# Original solution
import bisect
N = int(eval(input()))
A = list(map(int, input().split()))
B = sorted(list(map(int, input().split())))
l_b = len(B)
C = sorted(list(map(int, input().split())))
l_c = len(C)
ans = 0
for a in A:
    i = bisect.bisect_right(B, a)
    for j in range(i, l_b):
        num = bisect.bisect_right(C, B[j])
        ans += l_c - num
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())))
l_c = len(C)
ans = 0
for b in B:
    n_a = bisect.bisect_left(A, b)
    n_c = l_c - bisect.bisect_right(C, b)
    ans += n_a*n_c
print(ans)
# Original solution
N = int(eval(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

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 += sum(combiBC[ib:])
			break

print(cnt)

# Optimized solution
N = int(eval(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)
# Original solution
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N = ii()
S = [sorted(li()) for _ in range(3)]
rec = [[0]*N for i in range(2)]

for i in range(N):
    for j in range(2):
        rec[j][i] = bisect.bisect_right(S[j+1], S[j][i])

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

print(ans)

# Optimized solution
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
from itertools import accumulate #list(accumulate(A))

N = ii()
S = [sorted(li()) for _ in range(3)]
rec = [[0]*N for i in range(3)]

for i in range(N):
    #for j in range(2):
    #rec[0][i] = bisect.bisect_right(S[1], S[0][i])
    rec[1][i] = N - bisect.bisect_right(S[2], S[1][i])

acc = list(accumulate(rec[1]))
#acc_1 = [0] * N
#for i in range(N):
    #ind = bisect.bisect_right(S[2], acc_

ans = 0
for i in range(N):
    #for j in range(rec[0][i], N):
    ind = bisect.bisect_right(S[1], S[0][i])
    if ind == 0:
        ans += acc[-1]
    else:
        ans += acc[-1] - acc[ind-1]

print(ans)