Ringo is preparing for the Snuke Festival and needs to build an altar with three parts: upper, middle, and lower. He has N parts for each category, with sizes A_i, B_i, and C_i respectively. To build an altar, the middle part must be larger than the upper part, and the lower part must be larger than the middle part. Ringo needs to determine how many different altars he can build. The input format includes N followed by the sizes of the parts, and the output should be the number of different altars.

# Buggy version:
import bisect
from collections import deque
N = int(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()

d = deque([])
for i in range(N):
  n = bisect.bisect_right(C, B[N-1-i])
  if len(d) == 0:
    d.appendleft(N-n)
  else:
    d.appendleft(N-n+d[0])
  
ans = 0
for i in range(N):
  n = bisect.bisect_right(B, A[i])
  ans += d[n]
print(ans)

# Fixed version:
import bisect
from collections import deque
N = int(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()

d = deque([])
for i in range(N):
  n = bisect.bisect_right(C, B[N-1-i])
  if len(d) == 0:
    d.appendleft(N-n)
  else:
    d.appendleft(N-n+d[0])
  
ans = 0
for i in range(N):
  m = bisect.bisect_right(B, A[i])
  if m < N:
    ans += d[m]
print(ans)

# Buggy version:
import bisect
import sys
n = int(input())
up = sorted(list(set(map(int, input().split()))))
mid = sorted(list(set(map(int, input().split()))))
low = sorted(list(set(map(int, input().split()))))
ans = 0
for i in range(len(mid)):
    pre = bisect.bisect_left(up, mid[i])
    over = len(low) - bisect.bisect(low, mid[i])
    ans += pre * over

print(ans)


# Fixed version:
import bisect
import sys
n = int(input())
up = sorted(list(map(int, input().split())))
mid = sorted(list(map(int, input().split())))
low = sorted(list(map(int, input().split())))
ans = 0
for i in range(len(mid)):
    pre = bisect.bisect_left(up, mid[i])
    over = len(low) - bisect.bisect(low, mid[i])
    ans += pre * over

print(ans)

# Buggy version:
import bisect

N= int(input())
a = map(int, input().split(" "))
b = map(int, input().split(" "))
c = map(int, input().split(" "))

a = sorted(a)
b = sorted(b)
c = sorted(c,reverse=True)

result = 0
for i in b:
    ta = bisect.bisect_left(a,i)
    tc = bisect.bisect_right(c,i)
    result += ta*(N-tc)
print(result)

# Fixed version:
import bisect

N= int(input())
a = map(int, input().split(" "))
b = map(int, input().split(" "))
c = map(int, input().split(" "))

a = sorted(a)
b = sorted(b)
c = sorted(c)

result = 0
for i in b:
    ta = bisect.bisect_left(a,i)
    tc = bisect.bisect_right(c,i)
    result += ta*(N-tc)
print(result)

# Buggy version:
import bisect

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

ans=0

for i in range(n):
    num1 = bisect.bisect(a,b[i])
    num2 = n - bisect.bisect_left(c,b[i])
    ans += num1*num2

print(ans)

# Fixed version:
import bisect

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

ans=0

for i in range(n):
    num1 = bisect.bisect_left(a,b[i])
    num2 = n - bisect.bisect(c,b[i])
    ans += num1*num2

print(ans)

# Buggy version:
import bisect
num=0
n=int(input())
top=list(map(int,input().split()))
mid=list(map(int,input().split()))
und=list(map(int,input().split()))
top.sort()
mid.sort()
und.sort()
for i in mid:
    a=bisect.bisect_left(top,i)
    c=num-bisect.bisect_right(und,i)
    num+=a*c
print(num)

# Fixed version:
import sys
import bisect
input = sys.stdin.readline
num=0
n=int(input())
top=list(map(int,input().split()))
mid=list(map(int,input().split()))
und=list(map(int,input().split()))
top.sort()
mid.sort()
und.sort()
for i in mid:
    a=bisect.bisect_left(top,i)
    c=n-bisect.bisect_right(und,i)
    num+=a*c
print(num)

# Buggy version:
import bisect
N = int(input())
A = []
for _ in range(3):
  a = list(map(int, input().split()))
  a.sort()
  A.append(a)
print(A)
ans = 0
for b in A[1]:
  a = bisect.bisect_left(A[0], b)
  c = bisect.bisect_right(A[2], b)
  ans += a * (N-c)
print(ans)  

# Fixed version:
import bisect
N = int(input())
A = []
for _ in range(3):
  a = list(map(int, input().split()))
  a.sort()
  A.append(a)
  
ans = 0
for b in A[1]:
  a = bisect.bisect_left(A[0], b)
  c = bisect.bisect_right(A[2], b)
  ans += a * (N-c)
print(ans)

# Buggy version:
import bisect
n=int(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):
  x=b[i]
  y=bisect.bisect_left(a,x)
  z=bisect.bisect_right(c,x)
    ans+=(n-z)*y
print(ans)

# Fixed version:
import bisect


n = int(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):
    num = b[i]
    x = bisect.bisect_left(a, num)
    y = bisect.bisect_right(c, num)
    ans += x * (n - y)

print(ans)

# Buggy version:
from bisect import*
r=lambda:sorted(map(int,input().split()))
N=r()[0]
A,B,C,w,s=r(),r(),r(),[0]*N,0
for i in range(N-1,-1,-1):s=w[i]=s+N-bisect(C,B[i])
print(sum(w[bisect(B,A[i])]for i in range(N)))

# Fixed version:
from bisect import*
N=int(input())
r=lambda:sorted(map(int, input().split()))
A,B,C,w=r(),r(),r(),[0]*(N+1)
for i in range(N-1,-1,-1):w[i]=w[i+1]+N-bisect(C,B[i])
print(sum(w[bisect(B,A[i])]for i in range(N)))

# Buggy version:
import bisect

N=int(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: #O(N)
    s = bisect.bisect_left(A,b) #O(logN)
    t = bisect.bisect_right(C,b) #O(logN)
    print(s,N-t,s*(N-t))
    ans += s*(N-t)
   
print(ans)


# Fixed version:
import bisect

N=int(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: #O(N)
    s = bisect.bisect_left(A,b) #O(logN)
    t = bisect.bisect_right(C,b) #O(logN)
    #print(s,N-t,s*(N-t))
    ans += s*(N-t)
   
print(ans)

# Buggy version:
# -*- coding: cp932 -*-

import sys
import os
import re
import datetime
import bisect

def Test(value):
    a = [1,3,5]
    #x = 4

    insert_index = bisect.bisect_left(a, value)
    
    print("insert_index = ", insert_index)

####### main #######
    
if False:   
    while(True): 
        Test(int(input('? ')));
    sys.exit()
 
N = int(input())

partsNumA = sorted(map(int, input().split()))
partsNumB = sorted(map(int, input().split()))
partsNumC = sorted(map(int, input().split()))

# Bに対してAの個数のBによるループ
partsNumSumBa = []
sumA = 0
for curPartsB in partsNumB:
    indexA = bisect.bisect_left(partsNumA, curPartsB)
    numA = indexA
    sumA += numA
    partsNumSumBa.append(sumA)

# Cに対してBの個数のCによるループ
sumBAll = 0
for curPartsC in partsNumC:
    indexB = bisect.bisect_left(partsNumB, curPartsC)
    if indexB == 0:
        continue
    numB = partsNumSumBa[indexB - 1]
    sumBAll += numB
        
print(sumBAll)

# Fixed version:
import sys
import os
import re
import datetime
import bisect

def Test(value):
    a = [1,3,5]
    #x = 4

    insert_index = bisect.bisect_left(a, value)
    
    print("insert_index = ", insert_index)
    
if False:   
    while(True): 
        Test(int(input('? ')));
    sys.exit()
 
N = int(input())

partsNumA = sorted(map(int, input().split()))
partsNumB = sorted(map(int, input().split()))
partsNumC = sorted(map(int, input().split()))

# Bに対してAの個数のBによるループ
partsNumSumBa = []
sumA = 0
#for i in range(N):
for curPartsB in partsNumB:
    indexA = bisect.bisect_left(partsNumA, curPartsB)
    numA = indexA
    sumA += numA
    partsNumSumBa.append(sumA)

if False:
    print("Sorted A" , partsNumA)
    print("Sorted B" , partsNumB)
    print("Sorted C" , partsNumC)

    print("B loop" , partsNumSumBa)

# Cに対してBの個数のCによるループ
sumBAll = 0
for curPartsC in partsNumC:
    indexB = bisect.bisect_left(partsNumB, curPartsC)
    if indexB == 0:
        continue
    numB = partsNumSumBa[indexB - 1]
    sumBAll += numB
        
print(sumBAll)

# Buggy version:
from bisect import bisect_right

if __name__ == "__main__":
    n = int(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

    # まずあるbを選んだ時のcの組み合わせの数のリストを作る。
    clist = [0] * n
    clist[n-1] = n - bisect_right(c, b[n-1])
    for i in range(n-2, -1, -1):
        clist[i] = n - bisect_right(c, b[i]) + clist[i+1]

    for aa in a:
        b_pos = bisect_right(b, aa)
        ans += clist[b_pos]

    print(ans)


# Fixed version:
from bisect import bisect_right

if __name__ == "__main__":
    n = int(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

    # まずあるbを選んだ時のcの組み合わせの数のリストを作る。
    clist = [0] * n
    clist[n-1] = n - bisect_right(c, b[n-1])
    for i in range(n-2, -1, -1):
        clist[i] = n - bisect_right(c, b[i]) + clist[i+1]

    for aa in a:
        b_pos = bisect_right(b, aa)
        if b_pos != n:
            ans += clist[b_pos]

    print(ans)

# Buggy version:
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ali = [0] * (N+1)
bli = [N - bisect.bisect_left(C,B[i]) for i in range(N)]
for i in range(N):
    ali[i+1] = ali[i] + bli[i]
print(sum([ali[N]-ali[bisect.bisect_left(B,A[i])] for i in range(N)]))

# Fixed version:
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ali = [0] * (N+1)
bli = [N - bisect.bisect_left(C,B[i]+1) for i in range(N)]
for i in range(N):
    ali[i+1] = ali[i] + bli[i]
print(sum([ali[N]-ali[bisect.bisect_left(B,A[i]+1)] for i in range(N)]))

# Buggy version:
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ad = defaultdict(lambda: -1)
i, j = 0, 0
while i < N and j < N:
    if A[i] < B[j]:
        ad[i] = j
        i += 1
    else:
        j += 1
bd = defaultdict(lambda: -1)
i, j = 0, 0
while i < N and j < N:
    if B[i] < C[j]:
        bd[i] = j
        i += 1
    else:
        j += 1
csum = [0] * N
for i in range(N):
    if bd[i] >= 0:
        csum[i] = N-bd[i]
bsum = [0]* N
cnt = 0
for i in range(N):
    cnt += csum[N-1-i]
    bsum[N-1-i] = cnt
ans = 0
for i in range(N):
    if ad[i] >= 0:
        ans += bsum[ad[i]]
print(ans)

# Fixed version:
from collections import defaultdict
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ad = defaultdict(lambda: -1)
i, j = 0, 0
while i < N and j < N:
    if A[i] < B[j]:
        ad[i] = j
        i += 1
    else:
        j += 1
bd = defaultdict(lambda: -1)
i, j = 0, 0
while i < N and j < N:
    if B[i] < C[j]:
        bd[i] = j
        i += 1
    else:
        j += 1
csum = [0] * N
for i in range(N):
    if bd[i] >= 0:
        csum[i] = N-bd[i]
bsum = [0]* N
cnt = 0
for i in range(N):
    cnt += csum[N-1-i]
    bsum[N-1-i] = cnt
ans = 0
for i in range(N):
    if ad[i] >= 0:
        ans += bsum[ad[i]]
print(ans)

# Buggy version:
import bisect
import sys
readline = sys.stdin.buffer.readline


def main():
    n = int(readline())
    a = list(map(int,readline().rsplit()))
    b = list(map(int,readline().rsplit()))
    c = list(map(int,readline().rsplit()))
    a.sort()
    c.sort()
    ans = 0
    for i in b:
        d = bisect.bisect_left(a, i)
        e = len(c) - bisect.bisect_right(c, i)
        print(d,e)
        ans += d * e
    print(ans)

if __name__ == '__main__':
    main()

# Fixed version:
import bisect
import sys
readline = sys.stdin.buffer.readline


def main():
    n = int(readline())
    a = list(map(int,readline().rsplit()))
    b = list(map(int,readline().rsplit()))
    c = list(map(int,readline().rsplit()))
    a.sort()
    c.sort()
    ans = 0
    for i in b:
        d = bisect.bisect_left(a, i)
        e = len(c) - bisect.bisect_right(c, i)
        ans += d * e
    print(ans)

if __name__ == '__main__':
    main()

# Buggy version:
import bisect
n=int(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):
  x=a[i]
  y=bisect.bisect_right(x)
  z=bisect.bisect_right(b[y])
  ans+=n-z
print(ans)

# Fixed version:
import bisect
n=int(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):
  x=b[i]
  y=bisect.bisect_left(a,x)
  z=bisect.bisect_right(c,x)
  ans+=(n-z)*y
print(ans)

# Buggy version:
import bisect
n = int(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):
    l = (bisect.bisect_left(a,b[i]))*(n-bisect.bisect_right(c,b[i]))
    ans += 1
print(ans)

# Fixed version:
import bisect
n = int(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):
    l = (bisect.bisect_left(a,b[i]))*(n-bisect.bisect_right(c,b[i]))
    ans += l
print(ans)

# Buggy version:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
s = 0

A = sorted(A)
B = sorted(B)
C = sorted(C)

ia = 0
ic = 0

for b in B:
  while True:
    if ia == N-1 or A[ia+1]>=b: 
      break
    ia += 1
  while True:
    if ic == N-1 or C[ic+1]>b:
      break
    ic += 1
  s += (ia+1)*(N-ic-1)
    
print(s)

# Fixed version:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
s = 0

A = sorted(A)
B = sorted(B)
C = sorted(C)

ia = -1
ic = -1

for b in B:
  while True:
    if ia == N-1 or A[ia+1]>=b: 
      break
    ia += 1
  while True:
    if ic == N-1 or C[ic+1]>b:
      break
    ic += 1
  s += (ia+1)*(N-ic-1)
    
print(s)

# Buggy version:
import bisect
N=int(input())
A=sorted(set(map(int,input().split())))
B=sorted(set(map(int,input().split())))
C=sorted(set(map(int,input().split())))
s=0
for b in B:
    a=bisect.bisect_left(A,b)
    c=N-bisect.bisect_right(C,b)
    s+=a*c
print(s)

# Fixed version:
import bisect
N=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))
s=0
for b in B:
    a=bisect.bisect_left(A,b)
    c=N-bisect.bisect_right(C,b)
    s+=a*c
print(s)

# Buggy version:
import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
cnt = 0
for bb in b:
    anum = bisect.bisect_left(a, bb)
    cnum = bisect.bisect_right(c, bb)
    cnt += (anum * cnum)
print(cnt)

# Fixed version:
import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
cnt = 0
for bb in b:
    anum = bisect.bisect_left(a, bb)
    cnum = n - bisect.bisect_right(c, bb)
    cnt += (anum * cnum)
print(cnt)

# Buggy version:
import bisect
a = int(input())
b = list(map(int, input().split()))
b.sort()
c = list(map(int, input().split()))
d = list(map(int, input().split()))
d.sort()
ans = 0
for i in range(a):
    ans += bisect.bisect_left(b, c[i]) * (a - bisect.bisect_right(d, c[i]))
  

# Fixed version:
import bisect
n=int(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(n):
    ans+=bisect.bisect_left(a,b[i])*(n-bisect.bisect_right(c,b[i]))
print(ans)

# Buggy version:
import bisect

N = int(input())

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

count = 0

for i in range(len(B)):
    a_b = bisect.bisect_left(A,B[i])
    c_b = bisect.bisect_right(C,B[i])
    count += a_b * (N - c_b)

print(count)

# Fixed version:
import bisect

N = int(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(len(B)):
    a_b = bisect.bisect_left(A,B[i])
    c_b = bisect.bisect_right(C,B[i])
    count += a_b * (N - c_b)

print(count)

# Buggy version:
import bisect
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0
for i in b:
    x=bisect.bisect_left(a,i)
    y=bisect.bisect_right(c,i)
    ans+=x*(n-y)
    print(x,y)
print(ans)

# Fixed version:
import bisect
n=int(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 b:ans+=bisect.bisect_left(a,i)*(n-bisect.bisect_right(c,i))
print(ans)

# Buggy version:
n=int(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()
i,j=0,0
m1=[]
for k in a:
  if b[i]>k:
    j+=1
  else:
    m1.append(j)
for t in range(len(m1),len(b)):
  m1.append(j)
i,j=0,0
m2=[]
for k in range(n):
  if c[i]>k:
    j+=m1[b[k]]
  else:
    m2.append(j)
for t in range(len(m2),len(c)):
  m2.append(j)
print(sum(m2))


# Fixed version:
n=int(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()
i,j,k=0,0,0
m1=[]
while k<n and i<n:
  if b[i]>a[k]:
    j+=1
    k+=1
  else:
    m1.append(j)
    i+=1
for t in range(len(m1),len(b)):
  m1.append(j)
i,j,k=0,0,0
m2=[]
while k<n and i<n:
  if c[i]>b[k]:
    j+=m1[k]
    k+=1
  else:
    m2.append(j)
    i+=1
for t in range(len(m2),len(c)):
  m2.append(j)
print(sum(m2))

# Buggy version:
from collections import defaultdict
A = defaultdict(int)
B = defaultdict(int)
C = defaultdict(int)

N = int(input())
a = [k for k in map(int, input().split())]
b = [k for k in map(int, input().split())]
c = [k for k in map(int, input().split())]

for k in range(N):
  A[a[k]] += 1
  B[b[k]] += 1
  C[c[k]] += 1

Aset = sorted(set(a))
Bset = sorted(set(b))
Cset = sorted(set(c))

cnt = 0
index_a = 0
index_c = 0
a = 0
c = N

for b in Bset:
  flag_a = False
  flag_c = False
  for k in range(index_a, len(Aset)):
    if Aset[k] < b:
      a += A[Aset[k]] 
    else:
      index_a = k
      flag_a = True
      break
  for k in range(index_c, len(Cset)):
    if Cset[k] <= b:
      c -= C[Cset[k]]
    else:
      index_c = k
      flag_c = True
      break
  if flag_a == False:
    a = len(Aset)
  if flag_c == False:
    c = 0
  cnt += a*c*B[b]
print(cnt)

# Fixed version:
from collections import defaultdict
A = defaultdict(int)
B = defaultdict(int)
C = defaultdict(int)

N = int(input())
a = [k for k in map(int, input().split())]
b = [k for k in map(int, input().split())]
c = [k for k in map(int, input().split())]

for k in range(N):
  A[a[k]] += 1
  B[b[k]] += 1
  C[c[k]] += 1

Aset = sorted(set(a))
Bset = sorted(set(b))
Cset = sorted(set(c))

cnt = 0
index_a = 0
index_c = 0
a = 0
c = N

for b in Bset:
  flag_a = False
  flag_c = False
  if a < N:
    for k in range(index_a, len(Aset)):
      if Aset[k] < b:
        a += A[Aset[k]] 
      else:
        index_a = k
        flag_a = True
        break
  for k in range(index_c, len(Cset)):
    if Cset[k] <= b:
      c -= C[Cset[k]]
    else:
      index_c = k
      flag_c = True
      break
  if flag_a == False:
    a = N
  if flag_c == False:
    break
  cnt += a*c*B[b]
print(cnt)

# Buggy version:
from bisect import bisect_left, bisect_right
N=int(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 j in range(N):
    a=bisect_left(a, B[i])
    c=bisect_right(a, B[i])
    ans+=a*c
print(ans)


# Fixed version:
from bisect import bisect_left, bisect_right
N=int(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 j in range(N):
    a=bisect_left(A, B[j])
    c=bisect_right(C, B[j])
    ans+=a*(N-c)
print(ans)

# Buggy version:
import bisect
n=int(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):
  d=bisect.bisect_left(a,b[i])
  e=bisect.bisect_right(c,b[i])
  ans+=d*e
print(ans)


# Fixed version:
import bisect

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

print(ans)

# Buggy version:
import bisect

n = int(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:
    print(x)
    aa = bisect.bisect_left(a,x)
    cc = len(c) - bisect.bisect_right(c,x)
    ans += aa * cc
    print("aa",aa)
    print("cc",cc)
    print("ans",ans)

print(ans)



# Fixed version:
import bisect

n = int(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)

# Buggy version:
import bisect

N = int(input())
A = list(set(map(int, input().split())))
B = list(set(map(int, input().split())))
C = list(set(map(int, input().split())))
ans = 0
A.sort()
B.sort()
C.sort()
# print(A, B, C)
for b in B:
    a_i = bisect.bisect_left(A, b)
    c_i = bisect.bisect_right(C, b)
    cnt = (a_i) * (N - c_i)
    # print(b, a_i, c_i, cnt)
    ans += cnt

print(ans)

# Fixed version:
import bisect

N = int(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()
# print(A, B, C)
for b in B:
    a_i = bisect.bisect_left(A, b)
    c_i = bisect.bisect_right(C, b)
    cnt = (a_i) * (N - c_i)
    # print(b, a_i, c_i, cnt)
    ans += cnt

print(ans)

# Buggy version:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))


i = 0
j = 0
k = 0
p = []
while i < n and j < n:
    if a[i] < b[j]:
        i += 1
    else:
        p.append(i + k)
        k = p[-1]
        j += 1
else:
    while j < n:
        p.append(n + k)
        k = p[-1]
        j += 1

i = 0
j = 0
s = 0
while i < n and j < n:
    if b[i] < c[j]:
        i += 1
    else:
        s += p[i]
        j += 1
else:
    while j < n:
        s += p[-1]
        j += 1

print(s)

# Fixed version:
n = int(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()

i = 0
j = 0
k = 0
p = []
while i < n and j < n:
    if a[i] < b[j]:
        i += 1
    else:
        p.append(i + k)
        k = p[-1]
        j += 1
else:
    while j < n:
        p.append(n + k)
        k = p[-1]
        j += 1
       
i = 0
j = 0
k = 0
s = []
while i < n and j < n:
    if b[i] < c[j]:
        i += 1
    else:
        if i == 0:
            s.append(0)
        else:
            s.append(p[i-1] + k)
        k = s[-1]
        j += 1
else:
    while j < n:
        s.append(p[-1] + k)
        k = s[-1]
        j += 1

print(s[-1])

# Buggy version:
from bisect import bisect_left, bisect_right, insort_left, insort_right
def main():
    N = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(int, input().split())))

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

    BC = []
    for i in range(N):
        b = B[i]
        BC.append(N - bisect_left(C, b))
    # print(BC)

    Cum = []
    S = sum(BC)
    tmp = S
    for i in range(N):
        Cum.append(tmp)
        tmp -= BC[i]
    Cum.append(0)
    # print(Cum)

    count = 0
    for i in range(N):
        a = A[i]
        count += Cum[bisect_right(B, a)]
        # print(a, Cum[bisect_right(B, a)])

    print(count)


if __name__ == "__main__":
    main()


# Fixed version:
from bisect import bisect_left, bisect_right, insort_left, insort_right

def main():
    N = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(lambda x: int(x)-1, input().split())))


    BC = []
    for i in range(N):
        b = B[i]
        BC.append(N - bisect_left(C, b))

    Cum = []
    S = sum(BC)
    tmp = S
    for i in range(N):
        Cum.append(tmp)
        tmp -= BC[i]
    Cum.append(0)

    count = 0
    for i in range(N):
        a = A[i]
        count += Cum[bisect_right(B, a)]

    print(count)


if __name__ == "__main__":
    main()