CodeEff/ECCO huggingface dataset:
# Original solution
#関数リスト
import sys
from bisect import bisect
input = sys.stdin.readline
def RD(): return input().rstrip()
def I(): return int(input().rstrip())
def MI(): return list(map(int, input().split()))
def MF(): return list(map(float,input().split()))
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]

def main():
    N = I()
    A = LI()
    A.sort()
    B = LI()
    B.sort()
    B_len = len(B)
    C = LI()
    C.sort()
    C_len = len(C)
    result = 0
    A_init = A[0]
    index = 0
    next_i = index
    
    for i in A:
        index = next_i
        for j in range(index, B_len):
            if B[j] <= i:
                next_i = j+1
            else:
                result += C_len - bisect(C,B[j])
    print(result)

if __name__ == "__main__":
    main()

# Optimized solution
#関数リスト
import sys
import bisect
input = sys.stdin.readline
def RD(): return input().rstrip()
def I(): return int(input().rstrip())
def MI(): return list(map(int, input().split()))
def MF(): return list(map(float,input().split()))
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]

def main():
    N = I()
    A = LI()
    A.sort()
    B = LI()
    B.sort()
    B_len = len(B)
    C = LI()
    C.sort()
    C_len = len(C)
    result = 0
    A_init = A[0]
    index = 0
    next_i = index
    
    for i in B:
        tempA = bisect.bisect_left(A,i) 
        tempC = C_len - bisect.bisect_right(C,i)
        result += tempA*tempC
    print(result)

if __name__ == "__main__":
    main()
# Original solution
from bisect import bisect_right, bisect_left
n = int(eval(input()))
li_a = list(map(int, input().split()))
li_b = list(map(int, input().split()))
li_c = list(map(int, input().split()))
li_a.sort()
li_b.sort()
li_c.sort()
relation_bc = [] #relation_bc[i] : 大きい方からi番目のbより大きいcがいくつあるか
for i in range(n):
    i += 1
    j = li_b[(-1)*i]
    k = bisect_right(li_c, j)
    relation_bc.append(len(li_c)-k)
ans = 0
for i in li_a:
    p = bisect_right(li_b, i) # i より大きいbがいくつあるか調べる
    p = n - p
    if p >= 1:
        s = 0
        for j in range(p):
            s += relation_bc[j]
        ans += s
    else:
        continue
print(ans)

# Optimized solution
from bisect import bisect_right, bisect_left
from itertools import accumulate
n = int(eval(input()))
li_a = list(map(int, input().split()))
li_b = list(map(int, input().split()))
li_c = list(map(int, input().split()))
li_a.sort()
li_b.sort()
li_c.sort()
relation_bc = [] #relation_bc[i] : 大きい方からi番目のbより大きいcがいくつあるか
for i in range(n):
    i += 1
    j = li_b[(-1)*i]
    k = bisect_right(li_c, j)
    relation_bc.append(len(li_c)-k)
ans = 0
li = list(accumulate(relation_bc))
for i in li_a:
    p = bisect_right(li_b, i) # i より大きいbがいくつあるか調べる
    p = n - p
    if p >= 1:
        ans += li[p-1]
    else:
        continue
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()
lenC = len(C)
anssum = 0
for i in A:
    for l in B[bisect.bisect_right(B,i):]:
        anssum += lenC - bisect.bisect_right(C,l)
print(anssum)

# 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()
anssum = 0
for i in B:
    moreB = N-bisect.bisect_right(C,i)
    lessB = bisect.bisect_left(A,i)
    anssum += moreB*lessB
print(anssum)
# 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
n = int(eval(input()))
abc = [tuple(map(int, input().split(" "))) for i in range(3)]

a, b, c = [sorted(abc_i) for abc_i in abc]

sum_num = 0
for b_i in b:
	can_a_count = n
	for i, a_i in enumerate(a):
		if a_i >= b_i:
			can_a_count = i
			break

	can_c_count = n
	for i, c_i in enumerate(c[::-1]):
		if c_i <= b_i:
			can_c_count = i
			break
	
	sum_num += can_a_count * can_c_count

print(sum_num)

# Optimized solution
import bisect

n = int(eval(input()))
abc = [tuple(map(int, input().split(" "))) for i in range(3)]
# n = 100000
# abc = [tuple(range(n)) for i in range(3)]

a, b, c = [sorted(abc_i) for abc_i in abc]

print((sum(bisect.bisect_left(a, b_i) * (n-bisect.bisect(c, b_i)) for b_i in b)))
# 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())))

answer = 0
for a in A:
    bi = bisect.bisect_right(B, a)
    for i in range(bi, N):
        ci = bisect.bisect_right(C, B[i])
        answer += N - ci

print(answer)

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

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

print(answer)
# Original solution
from bisect import bisect_left, bisect_right

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

answer = 0
for b in B:
    ai = bisect_left(A, b)
    ci = bisect_right(C, b)
    answer += len(A[:ai]) * len(C[ci:])
print(answer)


# Optimized solution
from bisect import bisect_left, bisect_right

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

answer = 0
CL = len(C)
for b in B:
    ai = bisect_left(A, b)
    ci = bisect_right(C, b)
    answer += ai * (CL - ci)
print(answer)
# Original solution
N = int(eval(input()))
a = sorted(list(map(int, input().split())))
b = list(map(int, input().split()))
c = sorted(list(map(int, input().split())))

a_b = 0
b_c = 0
count = 0
for b_item in b:
    while a_b < N and a[a_b] < b_item:
        if a[a_b] >= b_item:
            break
        a_b += 1
    while b_c < N and c[b_c] <= b_item:
        if c[b_c] > b_item:
            break
        b_c += 1
    b_c = N - b_c
    count += (a_b * b_c)
    a_b = 0
    b_c = 0

print(count)


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

a_b = 0
b_c = 0
count = 0
for b_item in b:
    while a_b < N and a[a_b] < b_item:
        a_b += 1
    while b_c < N and c[b_c] <= b_item:
        b_c += 1
    count += (a_b * (N - b_c))

print(count)
# Original solution
import math
import sys
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)

BAcnt = [0] * N

for i in range(N):
    BAcnt[i] = bisect.bisect_left(A, B[i])

ret = 0
for i in range(N):
    csize = C[i]
    for j in range(N):
        bsize = B[j]
        if bsize < csize:
            ret += BAcnt[j]

print(ret)


# Optimized solution
import math
import sys
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)

BAcnt = [0] * N


for i in range(N):
    BAcnt[i] = bisect.bisect_left(A, B[i])

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

ret = 0
for i in range(N):
    j = bisect.bisect_left(B, C[i]) - 1
    if len(BAruiseki) > j and j>=0:
        ret += BAruiseki[j]


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=[0]+sorted(a)+[float('inf')]
c=[0]+sorted(c)+[float('inf')]


def bin_search_a(a,b):
    low=0
    high=len(a)-1
    while low<=high:
        mid=(low+high)//2
        if a[mid] < b <= a[mid+1]:
            return mid
        if a[mid] >= b:
            high=mid-1
        else:
            low=mid+1
    
def bin_search_c(c,b):
    low=0
    high=len(c)-1
    while low<=high:
        mid=(low+high)//2
        if c[mid] <= b < c[mid+1]:
            return mid
        if c[mid] > b:
            high=mid-1
        else:
            low=mid+1

altar=0

for bi in b:
    s=bin_search_a(a,bi)*(n-bin_search_c(c,bi))
    altar+=s
print(altar)

# 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=[0]+sorted(a)+[float('inf')]
c=[0]+sorted(c)+[float('inf')]


def meguru_a(bi):
    ng=n+1 ; ok=0
    while (abs(ok - ng) > 1): 
        mid = (ok + ng) // 2
        if a[mid] < bi :
            ok = mid
        else:
            ng = mid
    return ok

def meguru_c(bi):
    ng=-1 ; ok=n
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if bi < c[mid+1]:
            ok = mid
        else:
            ng = mid
    return ok

altar=0

for bi in b:
    s=meguru_a(bi)*(n - meguru_c(bi))
    altar+=s
print(altar)
# Original solution
def nibu(list,item):

    high=len(list)-1

    low=0
    while low <= high:
        mid=(low+high)//2
        guess=list[mid]
        if guess==item:
            return mid+1
            break
        elif guess < item:
            low = mid +1
        elif guess > item:
            high = mid - 1
    if guess != item:
        return high+1



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()
Bs=[]
s=0
for i in range(n):
    Bs.append(n-nibu(C,B[i]))
for i in range(n):
    Bss=Bs[:]
    Bss=Bs[nibu(B,A[i]):]
    s+=sum(Bss)
print(s)


# Optimized 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)
# Original solution
import bisect
N=int(eval(input()))
As=list(map(int,input().split()))
Bs=list(map(int,input().split()))
Cs=list(map(int,input().split()))
As.sort()
Bs.sort()
Cs.sort()
pyout=0
for i in range(N):
    num1=bisect.bisect_left(Bs,Cs[i])
    for j in range(num1):
        num2=bisect.bisect_left(As,Bs[j])
        pyout+=num2
print(pyout)

# Optimized solution
import bisect
N=int(eval(input()))
As=list(map(int,input().split()))
Bs=list(map(int,input().split()))
Cs=list(map(int,input().split()))
As.sort()
Cs.sort()
pyout=0

for i in range(N):
    num1=bisect.bisect_left(As,Bs[i])
    num2=N-bisect.bisect_right(Cs,Bs[i])
    pyout+=num2*num1
print(pyout)
# 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()

BtoC = [0]*N
for i in range(N):
    BtoC[i] = N - bisect.bisect_right(C,B[i])
s = [0]*N
for i in range(N):
    i = N-1-i
    if i == N-1:
        s[i] = BtoC[i]
        continue
    s[i] = s[i+1]+BtoC[i]
res = 0
for a in A:
    ind = bisect.bisect_right(B,a)
    if ind >= N:
        break
    res += s[ind]
print(res)

# 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]*N
for i in range(N):
    BtoC[i] = N - bisect.bisect_right(C,B[i])
s = [0]*N
for i in range(N):
    i = N-1-i
    if i == N-1:
        s[i] = BtoC[i]
        continue
    s[i] = s[i+1]+BtoC[i]
res = 0
for a in A:
    ind = bisect.bisect_right(B,a)
    res += s[ind] if ind <= N-1 else 0
print(res)
# 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()
AB=[0 for i in range(N)]
BC=[0 for i in range(N)]

def find_gt(a,x):
    i = bisect.bisect_right(a,x)
    if i != len(a):
        return N-i
    else:
        return 0

for i in range(N):
    AB[i]=find_gt(B,A[i])
    BC[i]=find_gt(C,B[i])

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

cnt = 0 
for j in range(N):
  i = bisect.bisect_left(A, B[j])
  k = bisect.bisect_right(C, B[j])
  cnt += i * (N - k)
  
print(cnt)

# Optimized solution
from bisect import bisect,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())))
ans=0
for b in B:
  i=bisect_left(A,b)
  j=bisect(C,b)
  ans+=i*(N-j)
print(ans)
# Original 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()

cnt = 0
a_left = 0
c_left = 0
for i in range(N):
    b = B[i]
    a_left += bisect_left(A[a_left:], b)
    c_left += bisect_right(C[c_left:], b)
    cnt += a_left * (N - c_left)
print(cnt)

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

cnt = 0
for b in B:
    cnt += bisect_left(A, b) * (N - bisect_right(C, b))
print(cnt)
# Original solution
import sys
from bisect import bisect

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

    Bn = [0] * N
    for i in range(N):
        b = B[i]
        m = bisect(C, b)
        Bn[i] = (N - m)

    ans = 0
    for i in range(N):
        a = A[i]
        m = bisect(B, a)
        ans += sum(Bn[m:])

    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
import sys
from bisect import bisect
from itertools import accumulate

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

    Bn = [0] * N
    for i in range(N):
        b = B[i]
        m = bisect(C, b)
        Bn[i] = (N - m)

    Bn = list(accumulate(Bn[::-1]))[::-1]
    Bn += [0]

    ans = 0
    for i in range(N):
        a = A[i]
        m = bisect(B, a)
        ans += Bn[m]

    print(ans)


if __name__ == '__main__':
    main()
# Original solution
n=int(eval(input()))
s=[list(map(int,input().split()))for i in range(3)]
c=0
for i in range(n):
    p=s[2][i]
    q=[j for j in s[1] if j<p]
    f=[j for j in s[0] if j<p]
    for a in range(len(q)):
        r=q[a]
        t=[j for j in f if j<r]
        c+=len(t)
print(c)

# Optimized solution
n=int(eval(input()))
s=[list(map(int,input().split()))for i in range(3)]
s[0].sort()
s[1].sort()
s[2].sort()
c,d,e=0,0,0
for i in range(n):
    while d<n and s[0][d]<s[1][i]:
        d+=1
    while e<n and s[2][e]<=s[1][i]:
        e+=1
    c+=d*(n-e)
print(c)
# 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()))

ans=0
A.sort()
B.sort()
C.sort()

for i in range(len(B)):
    ans+=bisect.bisect_left(A,B[i])*(len(C)-bisect.bisect_right(C,B[i]))
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()))
#print(A)
A.sort()
B.sort()
C.sort()
#print(A)
import bisect

ans=0
for i in range(N):
    cnt=bisect.bisect_left(A,B[i])*(N-bisect.bisect_right(C,B[i]))
    ans+=cnt
print(ans)
# Original solution
import bisect

n=int(eval(input()))
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
b.sort()
c=[int(i) for i in input().split()]
c.sort()
#print(n,a,b,c)

ans=0
for j in range(n):
    aa=bisect.bisect_right(b, a[j])
    if aa < n:
        for i in range(aa,n):
            ans+=n-bisect.bisect_right(c, b[i])

print(ans)


# Optimized solution
import bisect

n=int(eval(input()))
a=[int(i) for i in input().split()]
a.sort()
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
c.sort()
#print(n,a,b,c)

ans=0
for j in range(n):
    aa=bisect.bisect_left(a, b[j])
    bb=bisect.bisect_right(c, b[j])
    ans+=aa*(n-bb)

print(ans)
# Original solution
N=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()
#print A
#print B
#print C

sum=0

for i in range(N):
	j_start=0
	for j in range(N):
		if B[j]<=A[i]:
			continue
		for k in range(j_start,N):
			#print "# loop C"
			#print A[i],B[j],C[k],N-k
			if C[k]>B[j]:
				#print A[i],B[j],C[k],N-k
				sum+=(N-k)
				j_start=k
				break

print(sum)
			



# Optimized solution
import bisect
N=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()

sum=0
for val_b in B:
	sum+=bisect.bisect_left(A, val_b)*( N-bisect.bisect_right(C, val_b) )
			
print(sum)
# Original solution
N=int(eval(input()))
*A,=sorted(map(int,input().split()))
*B,=sorted(map(int,input().split()))
*C,=sorted(map(int,input().split()))
from bisect import *

cnt=0
for a in A:
    in_b = bisect_right(B, a)
    for b in B[in_b:]:
        in_c = bisect_right(C, b)
        for c in C[in_c:]:
            cnt+=1
print(cnt)

# Optimized solution
N=int(eval(input()))
*A,=sorted(map(int,input().split()))
*B,=sorted(map(int,input().split()))
*C,=sorted(map(int,input().split()))

lenc=len(C)

from bisect import *

cnt=0
for b in B:
    in_a = bisect_left(A, b)
    in_c = bisect_right(C, b)
    cnt+= in_a*(lenc-in_c)

print(cnt)
# Original solution
N=int(eval(input()))
*A,=sorted(map(int,input().split()))
*B,=sorted(map(int,input().split()))
*C,=sorted(map(int,input().split()))

lenc=len(C)

from bisect import *

cnt=0
for b in B:
    in_a = bisect_left(A, b)
    in_c = bisect_right(C, b)
    cnt+= in_a*(lenc-in_c)

print(cnt)

# Optimized solution
N=int(eval(input()))
f=lambda:sorted(map(int,input().split()))
*A,=f()
*B,=f()
*C,=f()
from bisect import *
print((sum([bisect_left(A, b)*(N-bisect_right(C, b)) for b in B])))
# Original solution
import sys
input = sys.stdin.readline
import itertools

def is_saidan(parts):
    tmp = 0
    for j in parts:
        if j > tmp:
            tmp = j
        else:
            break
    else:
        return True
    return False

def snuke_festival(a,b,c):
    comb = list(itertools.product(a,b,c))
    count = 0
    for i in comb:
        if is_saidan(i):
            count += 1
    return count
        
if __name__ == "__main__":
    n = int(eval(input()))
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print((snuke_festival(a,b,c)))


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

def snuke_festival(a,b,c):
    count = 0
    a_sorted = sorted(a)
    c_sorted = sorted(c)

    for n in b:
        ab = 0
        bc = 0
        for i in a_sorted:
            if n > i:
                ab += 1

        for i in c_sorted:
            if n < i:
                bc += 1

        count += ab * bc
    return count
        
if __name__ == "__main__":
    n = int(eval(input()))
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print((snuke_festival(a,b,c)))
# Original solution
import sys
input = sys.stdin.readline

def binary_search(ys,target,low,high,reverse=True):
    xs = sorted(ys)
    maxlen = len(xs)

    middle = 0
    #print("array => %s, target => %d" %(xs,target))
    while(low <= high):
        middle = (low + high) // 2
        #print("target %d, low %d, mid %d, high %d" %(target,low,middle,high))
        if xs[middle] == target:
             #print("find ",middle)
            if reverse == False:
                return middle
            else:
                return middle+1
        if xs[middle] > target:
            high = middle - 1
        elif xs[middle] < target:
            low = middle + 1

    middle = (low + high) // 2 +1
   # print("target %d, low %d, mid %d, high %d" %(target,low,middle,high))
    return middle
    


def snuke_festival(a,b,c):
    count = 0
    b_sorted = sorted(b)
    high = len(b)-1
    low = 0
    ab = 0
    bc = 0
    mid_a = 0
    mid_b = 0
    maxlen=len(b)
    for n in range(maxlen):
        mid_a = binary_search(a,b_sorted[n],mid_a,high,False)
        ab = mid_a
        mid_b = binary_search(c,b_sorted[n],low,mid_b,True)
        bc = maxlen - mid_b
        count += ab * bc
    return count

if __name__ == "__main__":
    n = int(eval(input()))
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print((snuke_festival(a,b,c)))


# Optimized solution
import sys
input = sys.stdin.readline
import bisect
    
def snuke_festival(a,b,c):
    count = 0
    a_sorted = sorted(a)
    b_sorted = sorted(b)
    c_sorted = sorted(c)
    maxlen=len(b)

    for target in b_sorted:
        #mid_a = binary_search_left(a_sorted,target)
        #mid_c = binary_search_right(c_sorted,target)
        mid_a = bisect.bisect_left(a_sorted,target)
        mid_c = bisect.bisect_right(c_sorted,target)
        count += mid_a * (maxlen - mid_c)
        #print("mid_a %d, mid_c %d, count %d" %(mid_a,maxlen - mid_c,count))
    return count

if __name__ == "__main__":
    n = int(eval(input()))
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))

    print((snuke_festival(a,b,c)))
# 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()

lenC = len(C)
cnt = 0

for a in A:
    for b in B:
        if a >= b: continue

        ii = bisect.bisect_right(C, b)
        cnt += lenC - ii

print(cnt)

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

lenC = len(C)

cnt = 0

for b in B:
    ind_a = bisect.bisect_left(A, b)
    ind_c = bisect.bisect_right(C, b)
    cnt += ind_a * (lenC - ind_c)

print(cnt)