CodeEff/ECCO huggingface dataset:
# Original solution
import bisect as bs

n = int(eval(input()))

a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))
c_l = list(map(int, input().split()))

a_l.sort()
b_l.sort()
c_l.sort()

ans = 0
for i in range(n):
    index_1 = bs.bisect_right(b_l,a_l[i])
    for j in range(index_1,n):
        index_2 = bs.bisect_right(c_l,b_l[j])
        ans += (n-index_2)
print(ans)


# Optimized solution
import bisect as bs

n = int(eval(input()))

a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))
c_l = list(map(int, input().split()))

a_l.sort()
b_l.sort()
c_l.sort()

ans = 0
for b in b_l:
    ans += bs.bisect_left(a_l,b) * (n-bs.bisect_right(c_l,b))
print(ans)


'''
以下の方法だと、N*logN*logN
for i in range(n):
    index_1 = bs.bisect_right(b_l,a_l[i])
    for j in range(index_1,n):
        index_2 = bs.bisect_right(c_l,b_l[j])
        ans += (n-index_2)
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 = sorted(a)
b = sorted(b)
c = sorted(c)

# x以上のイテレータを
def lower_bound(arr , x):
    l = 0
    r = len(c)
    for j in range(100):
        mid = (l + r) // 2
        # print(l , r , mid)
        if x <= arr[mid]:
            r = mid
        else:
            l = mid
    return r


count = 0
for i in range(n):
    a_count = lower_bound(a , b[i])
    c_count = len(c) - lower_bound(c , b[i] + 1)
    count += a_count * c_count

print(count)


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

# x以上のイテレータを
def lower_bound(arr , x):
    l = 0
    r = len(c)
    for j in range(30):
        mid = (l + r) // 2
        # print(l , r , mid)
        if x <= arr[mid]:
            r = mid
        else:
            l = mid
    return r


count = 0
for i in range(n):
    a_count = lower_bound(a , b[i])
    c_count = len(c) - lower_bound(c , b[i] + 1)
    count += a_count * c_count

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


def binary_search(k, x):
    index = bisect.bisect_right(k, x)
    if index == len(k):
        return False
    else:
        # index + 1個している
        return index + 1


ans = 0
for up in a:
    indexed_b = binary_search(b, up)
    b_cnt = n - (indexed_b - 1)
    if b_cnt > len(b):
        break
    for middle in b[indexed_b-1:]:
        indexed_c = binary_search(c, middle)
        c_cnt = n - (indexed_c - 1)
        ans += c_cnt

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


def binary_upper(k, x):
    return len(k) - bisect.bisect_right(k, x)


def binary_lower(k, x):
    return bisect.bisect_left(k, x)


ans = 0

for middle in b:
    cnt_a = binary_lower(a, middle)
    cnt_c = binary_upper(c, middle)
    ans += cnt_a * cnt_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 i in a:
	x = bisect.bisect_right(b,i)
	for j in b[x:]:
		y = bisect.bisect_right(c,j)
		cnt += n-y
	b = b[x:]
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()
cnt = 0

for i in b:
	x = bisect.bisect_left(a,i)
	y = bisect.bisect_right(c,i)
	cnt += x*(n-y)
print (cnt)
# Original solution
import bisect
n = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()

ans = 0
for i in range(n):
  canB = bisect.bisect_right(B, A[i])
  if canB == n:
    continue
  else:
    for j in range(canB, n):
      canC = bisect.bisect_right(C, B[j])
      ans += (n - canC)
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):
  canA = bisect.bisect_left(A, B[i])
  canC = bisect.bisect_right(C, B[i])
  ans += (canA)*(n-canC)
print(ans)
# Original solution
import bisect
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()] )

result = 0
for c in C:
    B_sub = B[:bisect.bisect_left(B,c)]
    for b in B_sub:
        result += bisect.bisect_left(A,b)

print(result)

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

b_count = []
pre_b = 0
for b in B:
    current_count = bisect.bisect_left(A,b)
    b_count.append(pre_b + current_count)
    pre_b += current_count

result = 0
for c in C:
    index = bisect.bisect_left(B,c)
    if index == 0:
        continue
    result += b_count[index-1]
    
print(result)
# Original solution
def main():
    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()

    ans = 0
    left = 0
    for a in A:
        right = left
        while left < N and a >= B[left]:
            left += 1
        if N <= left:
            break
        for b in B[left:]:
            while right < N and b >= C[right]:
                right += 1
            if N <= right:
                break
            ans += N-right
    print(ans)


if __name__ == '__main__':
    main()


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

    def is_ok1(mid, S, K):
        if K <= S[mid]:
            return True
        else:
            return False

    def is_ok2(mid, S, K):
        if K < S[mid]:
            return True
        else:
            return False

    def binary_search_meguru(S, K, is_ok):
        left = -1
        right = N
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid, S, K):
                right = mid
            else:
                left = mid
        return right

    ans = 0
    for b in B:
        a = binary_search_meguru(A, b, is_ok1)
        c = binary_search_meguru(C, b, is_ok2)
        ans += a * (N-c)
    print(ans)


if __name__ == '__main__':
    main()
# Original solution
def I(): return int(eval(input()))
def LI(): return list(map(int,input().split()))
def MI(): return list(map(int,input().split()))
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

def isOK(index,key,li):
    if li[index] >= key:
        #不等号にイコールを入れないとokはliの中でkey以下の数字がいくつあるかを表し、
        #ここの不等号にイコールを入れると
        #okはliの中でkey未満の数字がいくつあるかを表すようになる
        return True
    else:
        return False
def binary_search(key,li):
    ng = -1
    ok = len(li)
    while abs(ok - ng) > 1:
        mid = ok + ng //2
        if isOK(mid,key,li):
            ok = mid
        else:
            ng = mid
    return ok
    #liはsortしておくことに注意


def isOK2(index,key,li):
    if li[index] > key:
        #不等号にイコールを入れないとokはliの中でkey以下の数字がいくつあるかを表し、
        #ここの不等号にイコールを入れると
        #okはliの中でkey未満の数字がいくつあるかを表すようになる
        return True
    else:
        return False
def binary_search2(key,li):
    ng = -1
    ok = len(li)
    while abs(ok - ng) > 1:
        mid = ok + ng //2
        if isOK2(mid,key,li):
            ok = mid
        else:
            ng = mid
    return ok
    #liはsortしておくことに注意
n = I()
a_li = sorted(LI())
b_li = sorted(LI())
c_li= sorted(LI())
ans = 0
for i in range(n):
    B = b_li[i]
    k = n - binary_search2(B,c_li)
    l = binary_search(B,a_li)
    ans += k*l
print(ans)


# Optimized solution
import bisect

def I(): return int(eval(input()))
def LI(): return list(map(int,input().split()))
def MI(): return list(map(int,input().split()))
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！
n = I()
a_li = sorted(LI())
b_li = sorted(LI())
c_li= sorted(LI())
ans = 0
for i in range(n):
  B = b_li[i]
  k = n - bisect.bisect_right(c_li,B)
  l = bisect.bisect_left(a_li,B)
  ans += k*l
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()]
c=[int(i) for i in input().split()]
a.sort()
b.sort()
c.sort()
s=bisect.bisect_left(a,b[-1])
l=bisect.bisect_right(c,b[0])
cnt=0
ab=[]
for B in b:
    for A in a[:s+1]:
        if B>A:
            ab+=[B]
ans=0
for AB in ab:
    for C in c[l:]:
        if AB<C:
            ans+=1
print(ans)

# Optimized solution
import bisect
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()])
ans=0
for B in b:
    m=bisect.bisect_left(a,B)
    l=bisect.bisect_right(c,B)
    ans+=m*(n-l)
print(ans)
# Original solution
n = int(eval(input()))
ai = []
bi = []
ci = []
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(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

for i in range(0,n):
    cnt = 0
    for j in range(0,n):
        if a[i] >= b[j]:
            break
        cnt += 1
    ai.append(cnt)

for i in range(0,n):
    cnt = 0
    for j in range(0,n):
        if b[i] >= c[j]:
            break
        cnt += 1
    bi.append(cnt)

ans = 0
for i in range(0,n):
    if ai[i] > 0:
        for j in range(0,ai[i]):
            ans += bi[j]

print(ans)



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

bmul = [0]*(n+1)
ci = 0

for bi in range(n):
    while ci != n and c[ci] <= b[bi]:
        ci += 1
    bmul[bi] = n-ci
for i in range(n):
    bmul[n-i-1] += bmul[n-i]
bi = 0
ai = 0
ret = 0
for ai in range(n):
    while bi != n and b[bi] <= a[ai]:
        bi += 1
    ret += bmul[bi]
print(ret)
# Original solution
#ABC077-C
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):
    b=B[i]
    if A[-1]<b:
        a_comb=N
    elif A[0]>=b:
        a_comb=0
    elif A[0]<b and A[1]>=b:
        a_comb=1
    else:
        p=N//2
        while True:
            if A[p]<b and A[p+1]>=b:
                a_comb=p+1
                break
            elif A[p]<b and A[p+1]<b:
                p=(N+p)//2
                continue
            elif A[p]>=b:
                p=(p+1)//2
                continue
    if C[0]>b:
        c_comb=N
    elif C[-1]<=b:
        c_comb=0
    elif C[-1]>b and C[-2]<=b:
        c_comb=1
    else:
        p=N//2
        while True:
            if C[p]>b and C[p-1]<=b:
                c_comb=N-p
                break
            elif C[p]>b and C[p-1]>b:
                p=(p+1)//2
                continue
            elif C[p]<=b:
                p=(N+p)//2
                continue
    ans+=a_comb*c_comb
print(ans)

# Optimized solution
#ABC077-C
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):
    b=B[i]
    left=0
    right=N-1
    if A[-1]<b:
        a_comb=N
    elif A[0]>=b:
        a_comb=0
    elif A[0]<b and A[1]>=b:
        a_comb=1
    else:
        a_comb=0
        while left<=right:
            mid=(left+right)//2
            if A[mid]<b and A[mid+1]>=b:
                a_comb=mid+1
                break
            elif A[mid]<b and A[mid+1]<b:
                left=mid+1
            elif A[mid]>=b:
                right=mid-1

    left=0
    right=N-1
    if C[0]>b:
        c_comb=N
    elif C[-1]<=b:
        c_comb=0
    elif C[-1]>b and C[-2]<=b:
        c_comb=1
    else:
        c_comb=0
        while left<=right:
            mid=(left+right)//2
            if C[mid]>b and C[mid-1]<=b:
                c_comb=N-mid
                break
            elif C[mid]>b and C[mid-1]>b:
                right=mid-1
            elif C[mid]<=b:
                left=mid+1
    ans+=a_comb*c_comb
print(ans)
# Original solution
# -*- coding: utf-8 -*-

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


Ac, Cc = [0]*n, [0]*n
Ap, Cp = 0, 0

for i in range(n):
    index = bisect.bisect_left(A[Ap:], B[i])
    Ac[i], Ap = index + Ap, index + Ap
    index = bisect.bisect_right(C[Cp:], B[i])
    Cc[i], Cp = n - index - Cp, index + Cp


count = 0
for i in range(n):
    count += Ac[i]*Cc[i]

print(count)


# Optimized solution
# -*- coding: utf-8 -*-
 
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()
 
Ac, Cc = [0]*n, [0]*n
# Ap, Cp = 0, 0
 
for i in range(n):
    Ac[i] = bisect.bisect_left(A, B[i])#[Ap:], B[i])
    # Ac[i], Ap = index + Ap, index + Ap
    Cc[i] = n - bisect.bisect_right(C, B[i])#[Cp:], B[i])
    # Cc[i], Cp = n - index - Cp, index + Cp
 
 
count = 0
for i in range(n):
    count += Ac[i]*Cc[i]
 
print(count)
# Original solution
# -*- coding: utf-8 -*-
 
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()
 
Ac, Cc = [0]*n, [0]*n
# Ap, Cp = 0, 0
 
for i in range(n):
    Ac[i] = bisect.bisect_left(A, B[i])#[Ap:], B[i])
    # Ac[i], Ap = index + Ap, index + Ap
    Cc[i] = n - bisect.bisect_right(C, B[i])#[Cp:], B[i])
    # Cc[i], Cp = n - index - Cp, index + Cp
 
 
count = 0
for i in range(n):
    count += Ac[i]*Cc[i]
 
print(count)

# 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(C, b)) for b in B])))
# Original solution
import sys
input = sys.stdin.readline

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()
count = [0]*N
answer = 0
z = 0

for i in range(N):
    if B[0] >= C[N-i-1]:
        break
    z += 1
count[0] = z
for i in range(1, N):
    x = z
    for j in range(z):
        if B[i] < C[N-z+j]:
            break
        else:
            x -= 1
    count[i] = x
y = 0
for i in range(N):
    if A[0] >= B[N-i-1]:
        break
    answer += count[N-i-1]
    y += 1

for i in range(1, N):

    for j in range(y):
        if A[i] >= B[N-j-1]:
            break
        answer += count[N-j-1]
#print(count)
print(answer)

# Optimized solution
import sys
input = sys.stdin.readline
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
B = list(map(int, input().split()))
B.sort(reverse=True)
C = list(map(int, input().split()))
C.sort(reverse=True)
count = [0]*N
answer = 0
z = 0
for i in range(N):
    if B[N-1] >= C[i]:
        break
    z += 1
count[N-1] = z
for i in range(1, N):
    k=z
    for j in range(k):
        if B[N-1-i] < C[k-1-j]:
            break
        else:
            z -= 1      
    count[N-1-i] = z
sum_matrix = [0]*(N+1)
y = 0
for i in range(N):
    sum_matrix[i+1] = sum_matrix[i] + count[i]
for i in range(N):
    if A[N-1] >= B[i]:
        break
    answer += count[i]
    y += 1
for i in range(1, N):
    x = y
    for j in range(x):
        if A[N-1-i] < B[x-1-j]:
            break        
        y -= 1
    answer += sum_matrix[y]
print(answer)
# Original solution
import bisect
n=int(eval(input()))
A=sorted(list(map(int,input().split())))
B=list(map(int,input().split()))
C=sorted(list(map(int,input().split())))
lb,lc=len(B),len(C)
ans=0
for b in range(lb):
  ma = bisect.bisect_left(A, B[b])
  mc = lc-bisect.bisect_right(C, B[b])
  ans += ma*mc
print(ans)

# Optimized solution
import bisect
n=int(eval(input()))
A=sorted(list(map(int,input().split())))
B=list(map(int,input().split()))
C=sorted(list(map(int,input().split())))
lc=len(C)
ans=0
for b in B:
  ma = bisect.bisect_left(A, b)
  mc = lc-bisect.bisect_right(C, b)
  ans += ma*mc
print(ans)
# Original solution
import bisect

def main():
  n=int(eval(input()))
  A=sorted(list(map(int,input().split())))
  B=list(map(int,input().split()))
  C=sorted(list(map(int,input().split())))
  lc=len(C)
  ans=0
  for b in B:
    ma = bisect.bisect_left(A, b)
    mc = lc-bisect.bisect_right(C, b)
    ans += ma*mc
  print(ans)

if __name__ == "__main__":
    main()

# Optimized solution
import sys
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
def main():
  n=int(eval(input()))
  A=sorted(list(map(int,input().split())))
  B=list(map(int,input().split()))
  C=sorted(list(map(int,input().split())))
  lc=len(C)
  ans=0
  for b in B:
    ma = bisect_left(A, b)
    mc = lc-bisect_right(C, b)
    ans += ma*mc
  print(ans)

if __name__ == "__main__":
    main()
# Original solution
import bisect
n=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:
  ans+=(bisect.bisect_left(a,B))*(len(c)-(bisect.bisect_right(c,B)))
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 b:
  A=bisect.bisect_left(a,i)
  C=bisect.bisect(c,i)
  ans+=A*(n-C)
print(ans)
# Original solution
import bisect
N = int(eval(input()))
Alist = [int(x) for x in input().split()]
Blist = [int(x) for x in input().split()]
Clist = [int(x) for x in input().split()]

Alist.sort()
Blist.sort()
Clist.sort()

cache = []
result = 0
doneb = 0
donea = 0
for c in Clist:
    idxc = bisect.bisect_left(Blist, c)
    for i in range(0, idxc):
        b = Blist[i]
        idxb = bisect.bisect_left(Alist, b)
        result += idxb

print(result)

# Optimized solution
import bisect
N = int(eval(input()))
Alist = [int(x) for x in input().split()]
Blist = [int(x) for x in input().split()]
Clist = [int(x) for x in input().split()]

Alist.sort()
Blist.sort()
Clist.sort()

result = 0
for b in Blist:
    a = bisect.bisect_left(Alist, b)
    c = N - bisect.bisect_right(Clist, b)
    result += a*c

print(result)
# 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 up in a:
    tmp1 = bisect.bisect_right(b, up)
    for middle in b[tmp1:]:
        down = bisect.bisect_right(c, middle)
        ans += (n - down)
    
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 middle in b:
    tmp1 = bisect.bisect_left(a, middle)
    tmp2 = bisect.bisect_right(c, middle)
    ans += tmp1 * (n - tmp2)

print(ans)
# Original solution
import bisect

n = int(eval(input()))
a_li = list(map(int, input().split()))
b_li = list(map(int, input().split()))
c_li = list(map(int, input().split()))

b_li.sort()
c_li.sort()

check_li = [0]*(n+10)

for i in range(len(b_li)):
    s = bisect.bisect_right(c_li, b_li[i])
    check_li[i] = len(c_li[s:])

tmp = 0
for i in range(1, n+11):
    check_li[-i] = check_li[-i] + tmp
    tmp = check_li[-i]

ans = 0

for i in a_li:
    s = bisect.bisect_right(b_li, i)
    ans += check_li[s]

print(ans)

# Optimized solution
import bisect

n = int(eval(input()))
a_li = list(map(int, input().split()))
b_li = list(map(int, input().split()))
c_li = list(map(int, input().split()))

a_li.sort()
b_li.sort()
c_li.sort()

ans = 0

for i in b_li:
    s = bisect.bisect_right(c_li, i)
    s_num = n-s
    
    t = bisect.bisect_left(a_li, i)
    t_num = t
    
    ans += s_num * t_num

print(ans)
# Original solution
n = int(eval(input()))
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))
A_list = sorted(A_list)
B_list = sorted(B_list)
C_list = sorted(C_list)
cnt = 0

def is_ok(arg):
    return B_list[arg] > A_list[i]

def bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

def is_ok2(arg):
    return C_list[arg] > B_list[j]

def bisect2(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok2(mid):
            ok = mid
        else:
            ng = mid
    return ok

for i in range(n): #Aを決定
    #Aより大きいBを探す
    B_key = bisect(-1, len(B_list)-1)
    if A_list[i] < B_list[B_key]:
        for j in range(B_key, n):
            #Bより大きいCを探す
            C_key = bisect2(-1, len(C_list)-1)
            if B_list[j] < C_list[C_key]:
                cnt += n-C_key
            else:
                break
    else:
        break

print(cnt)


# Optimized solution
n = int(eval(input()))
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
C_list = list(map(int, input().split()))
A_list = sorted(A_list)
B_list = sorted(B_list)
C_list = sorted(C_list)
cnt = 0

def is_ok(arg): #　B　より小さい最大の　A
    return A_list[arg] < B_list[i]

def bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

def is_ok2(arg): #　B　より大きい最小の　A
    return C_list[arg] > B_list[i]

def bisect2(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok2(mid):
            ok = mid
        else:
            ng = mid
    return ok

for i in range(n): #Bを固定
    #Bより小さいAを探す
    A_key = bisect(len(A_list), 0)
    if A_list[A_key] < B_list[i]:
        #Bより大きいCを探す
        C_key = bisect2(-1, len(C_list)-1)
        if B_list[i] < C_list[C_key]:
            #print(A_key, i, C_key, A_list[A_key], B_list[i], C_list[C_key])
            cnt += (n-C_key)*(A_key+1)

print(cnt)
# Original solution
def main():
    N = int(eval(input()))
    A = list(map(int, input().split()))
    B = sorted(list(map(int, input().split())), reverse=True)
    C = sorted(list(map(int, input().split())))

    ans = 0
    for a in A:
        for b in B:
            if a >= b:
                break
            for i, c in enumerate(C):
                if c > b:
                    ans += N - i
                    break
    print(ans)


main()


# Optimized solution
import bisect


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

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


main()