CodeEff/ECCO huggingface dataset:
# 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):
  j=bisect.bisect_left(b,a[i]+1)
  if j>=n:
    break
  for k in range(j,n):
    l=bisect.bisect_left(c,b[k]+1)
    if l>=n:
      break
    ans+=n-l
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):
  j=bisect.bisect_left(a,b[i])
  k=n-bisect.bisect_right(c,b[i])
  ans+=j*k
print(ans)
# Original solution
import sys
input = sys.stdin.readline

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
bfla=0
cfla=0
for i in range(n):
    x=a[i]
    bfla=0
    cfla=0
    for j in range(bfla,n):
        if b[j] > x :
            y=b[j]
            bfla=j
        else:
            continue
        for k in range(cfla,n):
            if c[k]>y:
                z=c[k]
                ans+=n-k
                cfla=k
                break
print(ans)


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

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 j in range(n):
    al=bisect.bisect_left(a,b[j])
    cl=n-bisect.bisect_right(c,b[j])
    ans+=al*cl
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_sorted = sorted(A)
B_sorted = sorted(B)
C_sorted = sorted(C)

ans = 0
for b in B_sorted:
    #Aのうちbより小さいの数
    left = -1
    right = N 
    while right - left > 1:
        mid = left + (right - left) // 2
        if A_sorted[mid] < b:
            left = mid
        else:
            right = mid
    a_count = right
    #Cのうちbより大きいの数
    left = -1
    right = N 
    while right - left > 1:
        mid = left + (right - left) // 2
        if C_sorted[mid] > b:
            right = mid
        else:
            left = mid
    c_count = N - right
    
    ans += a_count * c_count

print(ans)

# Optimized solution
import bisect
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_sorted = sorted(A)
B_sorted = sorted(B)
C_sorted = sorted(C)

ans = 0
for b in B_sorted:
    #Aのうちbより小さいの数
    a_count = bisect.bisect_left(A_sorted, b)
    
    #Cのうちbより大きいの数
    c_count = N - bisect.bisect_right(C_sorted, b)
    
    ans += a_count * c_count

print(ans)
# Original solution
from collections import Counter

def altar(a,b):
    cnt = 0
    for k in range(len(b)):
        while a and a[0][0]<b[k][0]:
           cnt += a.pop(0)[1]
        b[k] = (b[k][0],b[k][1]*cnt)

eval(input())
a,b,c = [sorted(list(dict(Counter(list(map(int,input().split())))).items()),key=lambda x:x[0])for _ in "abc"]
altar(a,b)
altar(b,c)
print((sum([x[1] for x in c])))

# Optimized solution
import bisect
n=int(eval(input()))
a,b,c = [sorted(map(int,input().split())) for _ in "abc"]
print((sum([bisect.bisect_left(a,x)*(n-bisect.bisect_right(c,x)) for x in b])))
# Original solution
import bisect

n = int(eval(input()))
aa = list(sorted(map(int, input().split())))
bb = list(sorted(map(int, input().split())))
cc = list(sorted(map(int, input().split())))

ans = 0
for a in aa:
    bi = bisect.bisect(bb, a)
    bx = len(bb) - bi
    for b in range(bi, len(bb)):
        ci = bisect.bisect(cc, bb[b])
        cx = len(cc) - ci
        ans += cx

print(ans)


# Optimized solution
import bisect

n = int(eval(input()))
aa = list(sorted(map(int, input().split())))
bb = list(sorted(map(int, input().split())))
cc = list(sorted(map(int, input().split())))

ans = 0
for b in bb:
    ax = bisect.bisect_left(aa, b)
    ci = bisect.bisect(cc, b)
    cx = len(cc) - ci
    ans += ax * cx
print(ans)
# Original solution
import copy
n =int(eval(input()))
a=[]
b=[]
c=[]
a =list(map(int,input().split()))
a.sort()
b =list(map(int,input().split()))
b.sort()
c =list(map(int,input().split()))

c.sort()
c2 = copy.copy(c)
b_limit = 0
c_limit =0
count =0
c_count =0
b_score =[0]*n
for i in a:
    c_count =0
    c = copy.copy(c2)
    if b_limit == 1:
        break
    for j in  reversed(list(range(len(b)))):
        if b[j] <= i:
            if b[j] == max(b):
                b_limit +=1
            break
        else:
            if not b_score[j] == 0:
                count += b_score[j]
                continue
            if len(c) ==0:
                count +=c_count
                if b_score[j] ==0:
                    b_score[j] = c_count
                continue
        for k in reversed(list(range(len(c)))):
            if c[k] <= b[j]:
                count += c_count
                if b_score[j] ==0:
                    b_score[j] = c_count
                break
            c.pop(k)
            c_count +=1
            if k == 0:
                count +=c_count
                if b_score[j] ==0:
                    b_score[j] = c_count
print(count)



# Optimized solution
import bisect

ans =0

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

for i in b:
    s = bisect.bisect_right(c,i)
    s_num = n-s

    t = bisect.bisect_left(a,i)
    t_num = t

    ans += s_num * t_num

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()
M = 0
for i in range(N):
    low = 0
    high = N - 1
    t = (low + high) // 2
    if A[N-1] < B[i]:
        t = N-1
    elif A[0] >= B[i]:
        t = -1
    else:
        while (low <= high):
            if A[t] < B[i] <= A[t+1]:
                break
            elif B[i] <= A[t]:
                high = t
            elif A[t+1] < B[i]:
                low = t+1
            t = (low + high) // 2
    low = 0
    high = N - 1
    s = (low + high) // 2
    if C[N-1] <= B[i]:
        s = N-1
    elif B[i] < C[0]:
        s = -1
    else:
        while (low <= high):
            if C[s] <= B[i] < C[s+1]:
                break
            elif B[i] < C[s]:
                high = s
            elif C[s+1] <= B[i]:
                low = s + 1
            s = (low + high) // 2
    M += (t+1)*(N-s-1)
print(M)


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


# Optimized solution
from bisect import bisect_left,bisect_right;N=int(eval(input()));A=sorted([int(i) for i in input().split()]);B=[int(i) for i in input().split()];C=sorted([int(i) for i in input().split()]);print((sum([bisect_left(A,B[i])*(N-bisect_right(C,B[i])) for i in range(N)])))
# Original solution
from bisect import bisect_left,bisect_right;N=int(eval(input()));A,B,C=[list(map(int,input().split())) for _ in "ABC"];A.sort();C.sort();print((sum([bisect_left(A,B[i])*(N-bisect_right(C,B[i])) for i in range(N)])))

# Optimized solution
from bisect import bisect_left,bisect_right;N=int(eval(input()));A,B,C=[list(map(int,input().split())) for _ in "ABC"];A.sort();C.sort();print((sum([bisect_left(A,i)*(N-bisect_right(C,i)) for i in B])))
# Original solution
import bisect;N=int(eval(input()));A,B,C=[sorted(map(int,input().split())) for _ in "ABC"];print((sum([bisect.bisect_left(A,i)*(N-bisect.bisect_right(C,i)) for i in B])))


# Optimized solution
from bisect import *;N=int(eval(input()));A,B,C=[sorted(map(int,input().split())) for _ in "ABC"];print((sum([bisect_left(A,i)*(N-bisect_right(C,i)) for i in B])))
# 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 b_search_l(B,key):
    #key < B[s]を満たす最小のs
    if key < B[0]:
        return 0
    elif key >= B[N-1]:
        return N-1
    else:
        left,right = 0,N
        while left < right:
            mid = (left+right)//2
            if B[mid] <= key and key < B[mid+1]:
                return mid+1
            elif B[mid] > key:
                right = mid
            else:
                left = mid

def b_search_r(B,key):
    #key > B[t]を満たす最大のt
    if B[0] >= key:
        return 0
    elif B[N-1] < key:
        return N-1
    else:
        left,right = 0,N
        while left < right:
            mid = (left+right)//2
            if B[mid] < key and key <= B[mid+1]:
                return mid
            elif B[mid] >= key:
                right = mid
            else:
                left = mid

ans = 0
for i in range(N):
    for j in range(N):
        if A[i] +1 < C[j]:
            ans += (b_search_r(B,C[j]) - b_search_l(B,A[i])+1)

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

def b_search_l(B,key):
    #key < B[s]を満たすsの個数
    if key < B[0]:
        return N
    elif key >= B[N-1]:
        return 0
    else:
        left,right = 0,N
        while left < right:
            mid = (left+right)//2
            if B[mid] <= key and key < B[mid+1]:
                return N-(mid+1)
            elif B[mid] > key:
                right = mid
            else:
                left = mid

def b_search_r(B,key):
    #key > B[t]を満たすtの個数
    if B[0] >= key:
        return 0
    elif B[N-1] < key:
        return N
    else:
        left,right = 0,N
        while left < right:
            mid = (left+right)//2
            if B[mid] < key and key <= B[mid+1]:
                return mid+1
            elif B[mid] >= key:
                right = mid
            else:
                left = mid

#b_l:keyより多い奴の個数
#b_r:key未満の奴の個数
ans = 0
for i in range(N):
    b_l,b_r = b_search_l(C,B[i]),b_search_r(A,B[i])
    ans += (b_l)*(b_r)
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()

def b_search_l(B,key):
    #key < B[s]を満たすsの個数
    if key < B[0]:
        return N
    elif key >= B[N-1]:
        return 0
    else:
        left,right = 0,N
        while left < right:
            mid = (left+right)//2
            if B[mid] <= key and key < B[mid+1]:
                return N-(mid+1)
            elif B[mid] > key:
                right = mid
            else:
                left = mid

def b_search_r(B,key):
    #key > B[t]を満たすtの個数
    if B[0] >= key:
        return 0
    elif B[N-1] < key:
        return N
    else:
        left,right = 0,N
        while left < right:
            mid = (left+right)//2
            if B[mid] < key and key <= B[mid+1]:
                return mid+1
            elif B[mid] >= key:
                right = mid
            else:
                left = mid

#b_l:keyより多い奴の個数
#b_r:key未満の奴の個数
ans = 0
for i in range(N):
    b_l,b_r = b_search_l(C,B[i]),b_search_r(A,B[i])
    ans += (b_l)*(b_r)
print(ans)


# Optimized solution
from bisect import bisect_left,bisect_right

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

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

#bisect_left:keyを挿入できる最小のindex
#bisect_right:keyを挿入できる最大のindex
ans = 0
for i in range(N):
    b_l,b_r = bisect_left(A,B[i]),N-bisect_right(C,B[i])
    ans += (b_l)*(b_r)
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, b, c = sorted(a), sorted(b), sorted(c)

ans = 0
for i in b:
    up_index = bisect.bisect_left(a,i)
    down_index = bisect.bisect_right(c,i)
    ans += len(a[:up_index])*len(c[down_index:])

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, b, c = sorted(a), sorted(b), sorted(c)

ans = 0
for i in b:
    up_index = bisect.bisect_left(a,i)
    down_index = bisect.bisect_right(c,i)
    ans += up_index * (n-down_index)

print(ans)
# Original solution
#!/mnt/c/Users/moiki/bash/env/bin/python
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
A2 = []
B2 = []
C2 = []
for a,b,c in zip(A,B,C):
    bisect.insort_left(A2, a)
    # bisect.insort_left(B2, b)
    bisect.insort_left(C2, c)
# print(A,B,C)
# import numpy as np

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

# for c in C:
#     for b in [x for x in B if x < c]:
#         for a in [x for x in A if x < b]:

print(sum)

# Optimized solution
#!/mnt/c/Users/moiki/bash/env/bin/python
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
A2 = []
B2 = []
C2 = []
# for a,b,c in zip(A,B,C):
#     bisect.insort_left(A2, a)
#     # bisect.insort_left(B2, b)
#     bisect.insort_left(C2, c)
# print(A,B,C)
# import numpy as np

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

# for c in C:
#     for b in [x for x in B if x < c]:
#         for a in [x for x in A if x < b]:

print(sum)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

c.sort()

### 二分探索
ans = 0
for i in range(n):
    for j in range(n):
        if a[i] < b[j]:
            for k in range(len(c)):
                low = 0
                high = len(c) - 1
                item = c[k]

                while low <= high:
                    mid = (low + high) //2
                    guess = c[mid]
                    if guess == item:
                        break
                    if guess > item:
                        high = mid -1
                    else:
                        low = mid + 1

                if c[mid] > b[j]:
                    ans += 1
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
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
#!/usr/bin/python3

from bisect import bisect_left


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

    res = 0
    for a in A:
        t = bisect_left(B, a + 1)
        for b in B[t:]:
            s = bisect_left(C, b + 1)
            res += N - s

    print(res)


if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/python3

from bisect import bisect_left, bisect_right


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

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

    print(res)


if __name__ == '__main__':
    main()
# Original solution
icase=0
if icase==0:
    n=int(eval(input()))  #数値入力 「N」だけの入力のとき
    a=list(map(int, input().split()))
    b=list(map(int, input().split()))
    c=list(map(int, input().split()))
elif icase==1:
    n=2
    a=[1,5]
    b=[2,4]
    c=[3,6]
elif icase==2:
    n=6
    a=[3, 14, 159, 2, 6, 53]
    b=[58, 9, 79, 323, 84, 6]
    c=[2643, 383, 2, 79, 50, 288]
    
a.sort()
b.sort()
c.sort()
   
icnt=0
ast=0
cst=0
for i in range(n):
    if a[n-1]<=b[i]:
        ast=n
#        print("a1:",ast-1,a[ast-1],i,b[i])
    elif a[0]>=b[i]:
        ast=0
#        print("a1:",ast-1,a[ast-1],i,b[i])
    else:
        while a[ast]<b[i] and ast<n-1:
            ast=ast+1
#            print("a2:",ast-1,a[ast-1],i,b[i])
    if b[i]<c[0]:
        cst=0 
    elif b[i]>=c[n-1]:
        cst=n 
#        print("c1:",cst,c[cst],i,b[i])
    else:
        while b[i]>=c[cst] and cst<n-1:
            cst=cst+1
#            print("c2:",cst-1,c[cst-1],i,b[i])
#    print(ast,i,n-cst)
    icnt=icnt+(ast)*(n-cst)
    
print(icnt)

# Optimized solution
from bisect import bisect_left,bisect
 
n=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
lenc=len(c)

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

jsum=0
for j in b:
    ai=bisect(a,j-1)
    ci=lenc-bisect_left(c,j+1)
#    print(j,ai,ci)
    jsum+=ai*ci

print(jsum)
# Original solution
import bisect
def I(): return int(eval(input()))
def LI(): return list(map(int,input().split()))
N = I()
A = sorted(LI())
B = sorted(LI())
C = sorted(LI())
ans = 0
BC = []
for b in B:
    C2 = C[:]
    ok = bisect.bisect(C2,b)
    if ok!=N:
        bisect.insort(C2,b)
        for _ in range(N-ok):
            BC.append(C2[ok:])
for a in A:
    for bc in BC:
        if bisect.bisect(bc,a)==0:
            ans += 1
print(ans)


# Optimized solution
import bisect
def I(): return int(eval(input()))
def LI(): return list(map(int,input().split()))
N = I()
A = sorted(LI())
B = sorted(LI())
C = sorted(LI())
ans = 0
for b in B:
    ok_a = bisect.bisect_left(A,b)
    ok_c = bisect.bisect_right(C,b)
    if ok_a!=0 and ok_c!=N:
        ans += ok_a*(N-ok_c)
print(ans)
# Original solution
import bisect
def I(): return int(eval(input()))
def LI(): return list(map(int,input().split()))
N = I()
A = sorted(LI())
B = sorted(LI())
C = sorted(LI())
ans = 0
for b in B:
    ok_a = bisect.bisect_left(A,b)
    ok_c = bisect.bisect_right(C,b)
    if ok_a!=0 and ok_c!=N:
        ans += ok_a*(N-ok_c)
print(ans)


# Optimized solution
import bisect
def I(): return int(eval(input()))
def LI(): return list(map(int,input().split()))
N = I()
A = sorted(LI())
B = sorted(LI())
C = sorted(LI())
ans = 0
for b in B:
    ok_a = bisect.bisect_left(A,b)
    ok_c = bisect.bisect_right(C,b)
    ans += ok_a*(N-ok_c)
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 = bisect.bisect_right(c, i)
  #print(x, y)
  ans = ans+x*(n-y)

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 b:
  x = bisect.bisect_left(a, i)
  y = bisect.bisect_right(c, i)
  ans = ans + (x * (n-y))
print(ans)
# Original solution
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    s = S()
    t = S()
    if s+t == t[::-1]+s[::-1]:
        print("YES")
    else:
        print("NO")

#B
def B():
    n = I()
    for i in range(int(n**0.5)+2)[::-1]:
        if i*i <= n:
            print((i*i))
            quit()
#C
def C():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    q = [0 for i in range(n)]
    ans = 0
    a.sort()
    b.sort()
    c.sort()
    for i in range(n):
        j = bisect.bisect_left(a,b[i])
        q[i] = j
    for i in range(n-1):
        q[i+1] += q[i]
    q.insert(0,0)
    for i in range(n):
        j = bisect.bisect_left(b,c[i])
        ans += q[j]
    print(ans)
#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()


# Optimized solution
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    a.sort()
    c.sort()
    ans = 0
    for i in range(n):
        bi = b[i]
        j = bisect.bisect_left(a,bi)
        k = bisect.bisect_right(c,bi)
        ans += j*(n-k)
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()
# Original solution

n = int(eval(input()))

xs = sorted(map(int, input().split()))
ys = sorted(map(int, input().split()))
zs = sorted(map(int, input().split()))

bs = [0] * n
for i in range(n):
    for j in range(n):
        if xs[j] < ys[i]:
            bs[i] += 1
        else:
            break

cs = [0] * n
for i in range(n):
    for j in range(n):
        if ys[j] < zs[i]:
            cs[i] += bs[j]
        else:
            break

print((sum(cs)))


# Optimized solution

n = int(eval(input()))

xs = sorted(map(int, input().split()))
ys = sorted(map(int, input().split()))
zs = sorted(map(int, input().split()))

bs = [0] * n
j = 0
for i in range(n):
    while j < n and xs[j] < ys[i]:
        j += 1
    bs[i] = j

cs = [0] * n
j = 0
k = 0
for i in range(n):
    while j < n and ys[j] < zs[i]:
        k += bs[j]
        j += 1
    cs[i] = k

print((sum(cs)))