CodeEff/ECCO huggingface dataset:
# Original solution
N=int(eval(input()))
s=sorted(list(map(int,input().split())))
t=sorted(list(map(int,input().split())),reverse=True)
u=sorted(list(map(int,input().split())),reverse=True)
ans=0
for j in range(N):
    tt=[]
    for k in range(N):
        if s[j]<t[k]:
            tt.append(t[k])
        else:
            break
    for ii in range(len(tt)):
        for jj in range(N):
            if tt[ii]<u[jj]:
                ans+=1
            else:
                break
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())))
ans=0
for i in b:
    aa=bisect.bisect_left(a,i)
    cc=N-bisect.bisect_right(c,i)
    ans+=aa*cc
print(ans)
# 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())))
ans=0
for i in b:
    aa=bisect.bisect_left(a,i)
    cc=N-bisect.bisect_right(c,i)
    ans+=aa*cc
print(ans)

# Optimized solution
import bisect
N=int(eval(input()))
s=[list(sorted(map(int,input().split()))) for i in range(3)]
t=[]
q=0
for i in s[1]:
    t.append(N-bisect.bisect_right(s[2],i))
for i in range(N):
    q+=bisect.bisect_left(s[0],s[1][i])*t[i]
print(q)
# Original solution
from bisect import bisect_left
N = int(eval(input()))
upper = sorted(list(map(int, input().split())))
middle = sorted(list(map(int, input().split())))
lower = list(map(int, input().split()))

ans = 0
for l in lower:
    idx = bisect_left(middle, l)
    if idx>=1:
        for m in middle[:idx]:
            idx2 = bisect_left(upper, m)
            ans += idx2
print(ans)

# Optimized solution
from bisect import bisect_left, bisect_right
N = int(eval(input()))
upper = sorted(list(map(int, input().split())))
middle = list(map(int, input().split()))
lower = sorted(list(map(int, input().split())))

ans = 0
for m in middle:
    idx_u = bisect_left(upper, m)
    idx_l = N-bisect_right(lower, m)
    ans += idx_u*idx_l
print(ans)
# Original solution
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""077-c"""

import sys
import pprint
import re

import itertools
pp = pprint.PrettyPrinter(indent=2)

def main():
    """Main function."""
    N = int(eval(input()))

    As = sorted(list(map(int, input().split(' '))))
    Bs = sorted(list(map(int, input().split(' '))))
    Cs = sorted(list(map(int, input().split(' '))))

    Bs_count = [len(list([c for c in Cs if b < c])) for b in Bs]
    As_count = [len(list([b for b in Bs if a < b])) for a in As]

    count = 0
    for c in As_count:
        if -1 * c == 0:
            break
        for c_ in Bs_count[-1 * c:]:
            count += c_

    print(count)


if __name__ == '__main__':
    sys.exit(main())

# Optimized solution
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""077-c"""

import sys
import pprint
import re
import itertools

import bisect

pp = pprint.PrettyPrinter(indent=2)

def main():
    """Main function."""
    N = int(eval(input()))

    As = sorted(list(map(int, input().split(' '))))
    Bs = list(map(int, input().split(' ')))
    Cs = sorted(list(map(int, input().split(' '))))

    count = 0
    for b in Bs:
        i = bisect.bisect_left(As, b)
        k = N - bisect.bisect_right(Cs, b)
        count += i * k

    print(count)

if __name__ == '__main__':
    sys.exit(main())
# Original solution
from bisect import bisect
import random


def binary_search(L, n, i, j):
    # print(L, n, i, j)
    low = i
    high = j

    while low <= high:
        mid = (low + high) //2
        guess = L[mid]
        # if guess == n:
            # return mid
        if guess > n:
            high = mid -1
        else:
            low = mid + 1
    # print(low)
    return low

N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
# N = 10 ** 5
# A = [random.randint(1, 10**9) for _ in range(N)]
# B = [random.randint(1, 10**9) for _ in range(N)]
# C = [random.randint(1, 10**9) for _ in range(N)]

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

ans = 0
i, j = 0, 0

A_ind = []
B_cum = [0]

for a in A:
    # i = binary_search(B, a, i, N-1)
    i = bisect(B, a)
    A_ind.append(i)

s = 0
for b in B:
    # j = binary_search(C, b, j, N-1)
    j = i = bisect(C, b)
    s += N-j
    B_cum.append(s)

for a in A_ind:
    ans += B_cum[-1] - B_cum[a]
print(ans)



# Optimized solution
from bisect import bisect_left, bisect_right
# import random


N = int(eval(input()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
# N = 10 ** 5
# A = [random.randint(1, 10**9) for _ in range(N)]
# B = [random.randint(1, 10**9) for _ in range(N)]
# C = [random.randint(1, 10**9) for _ in range(N)]

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

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

print(ans)
# Original solution
from bisect import bisect_right

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

cnt = [0] * N
for i in range(N):
    cnt[i] = N - bisect_right(C, B[i])
    
res = 0
for i in range(N):
    idx = bisect_right(B, A[i])
    if idx < N:
        res += sum(cnt[idx:])
print(res)


# Optimized solution
from bisect import bisect_right

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

cnt = [0] * N
for i in range(N):
    cnt[i] = N - bisect_right(C, B[i])

cumsum = [0] * (N + 1)
for i in range(N):
    cumsum[i + 1] = cumsum[i] + cnt[N - i - 1]
    
res = 0
for i in range(N):
    res += cumsum[N - bisect_right(B, A[i])]
print(res)
# Original solution
def main():
    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()

    bb = [0 for _ in range(N)]
    for i,b in enumerate(B):
        for c in C[::-1]:
            if c > b:
                bb[i]+=1
            else: 
                break
    count = 0
    for a in A:
        for i,b in enumerate(B[::-1]):
            if b > a:
                count += bb[-i-1]
            else:
                break
    return count

print((main()))


# Optimized solution
def main():
    N = int(eval(input()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    A.sort()
    B.sort()
    C.sort()

    count = 0
    Ai = -1
    Ci = -1
    for i in range(N):
        if Ai<N-1:
            while A[Ai+1]<B[i]:
                Ai += 1
                if Ai == N-1:
                    break
        if Ci<N-1:
            while C[Ci+1]<=B[i]:
                Ci += 1
                if Ci==N-1:
                    break
        count += (Ai+1) * (N-(Ci+1))

    return count

if __name__ == '__main__':
    print((main()))
# Original solution
# def binary_search(lst):
#     pass


import bisect


n = int(eval(input()))
lst_A = list(map(int, input().split()))
lst_B = list(map(int, input().split()))
lst_C = list(map(int, input().split()))
lst_A.sort()
lst_B.sort()
lst_C.sort()


ans = 0
for b in lst_B:
    ia = bisect.bisect_left(lst_A, b)
    ic = bisect.bisect_right(lst_C, b)
    na = len(lst_A[:ia])
    nc = len(lst_C[ic:])
    ans += na * nc


print(ans)

# Optimized solution
import bisect


n = int(eval(input()))
lst_A = list(map(int, input().split()))
lst_B = list(map(int, input().split()))
lst_C = list(map(int, input().split()))
lst_A.sort()
lst_B.sort()
lst_C.sort()


ans = 0
for b in lst_B:
    na = bisect.bisect_left(lst_A, b)
    nc = n - bisect.bisect_right(lst_C, b)
    ans += na * nc


print(ans)
# Original solution
import bisect


n = int(eval(input()))
lst_A = list(map(int, input().split()))
lst_B = list(map(int, input().split()))
lst_C = list(map(int, input().split()))
lst_A.sort()
lst_B.sort()
lst_C.sort()


ans = 0
for b in lst_B:
    na = bisect.bisect_left(lst_A, b)
    nc = n - bisect.bisect_right(lst_C, b)
    ans += na * nc


print(ans)

# Optimized solution
from bisect import bisect_left, bisect_right


n = int(eval(input()))
lst_A = sorted(map(int, input().split()))
lst_B = sorted(map(int, input().split()))
lst_C = sorted(map(int, input().split()))


ans = 0
for b in lst_B:
    na = bisect_left(lst_A, b)
    nc = n - bisect_right(lst_C, b)
    ans += na * nc


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

Clen = len(C)

total = 0

for i in A:
    Bmin = bisect.bisect_right(B, i)
    for j in B[Bmin :]:
        total += Clen - bisect.bisect_right(C, j)

print(total)

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

total = 0

for b in B:
    i = N - bisect.bisect_right(C, b)
    j = bisect.bisect_left(A, b)
    total += i * j

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

Bcon = [0] * N
res = 0
p = 0
for n in range(N):
    while p <= N - 1 and B[n] > A[p]:
        p += 1
    Bcon[n] = p

p = 0
for n in range(N):
    while p <= N - 1 and C[n] > B[p]:
        p += 1
    res += sum(Bcon[:p])
    
print(res)

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

Bcon = [0] * (N + 1)
res = 0
p = 0
for n in range(N):
    while p <= N - 1 and B[n] > A[p]:
        p += 1
    Bcon[n + 1] = p + Bcon[n]
    
p = 0
for n in range(N):
    while p <= N - 1 and C[n] > B[p]:
        p += 1
    res += Bcon[p]
    
print(res)
# Original solution
from bisect import bisect
from itertools import accumulate
def main():
    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()
    ainb = [bisect(b, ea) for ea in a]
    bc = [n - bisect(c, eb) for eb in b]
    bcaccum = tuple(accumulate(bc))
    tr = 0
    for eainb in ainb:
        if eainb != 0:
            tr += bcaccum[eainb - 1]
    r = bcaccum[-1] * n - tr

    print(r)

if __name__ == '__main__':
    main()


# Optimized solution
import sys
read = sys.stdin.read
#readlines = sys.stdin.readlines
from bisect import bisect, bisect_left
from itertools import accumulate
def main():
    data = list(map(int, read().split()))
    n = data[0]
    a = data[1:n + 1]
    b = data[n + 1: n * 2 + 1]
    c = data[n * 2 + 1:]
    a.sort()
    b.sort()
    c.sort()
    b2 = [bisect_left(a, be) for be in b]
    b2a = list(accumulate(b2))
    b2a = [0] + b2a
    ans = sum([b2a[bisect_left(b, ce)] for ce in c])
    print(ans)

if __name__ == '__main__':
    main()
# Original solution
#ABC077C
N=int(eval(input()))
#大きい順に# 並べる
A=sorted(list(map(int,input().split())), reverse=True)
B=sorted(list(map(int,input().split())), reverse=True)
C=sorted(list(map(int,input().split())), reverse=True)
#あるBの下にいくつCが入るか数える
C_under_B=[0]*N     #i番目のBの下に入るCの数
for i in range(N):
    if i > 0:
        if B[i] == B[i-1]:
            C_under_B[i]=C_under_B[i-1]
            continue
    for j in range(N):
        if C[j]>B[i]:
            C_under_B[i]+=1
        else:       #C[j+1]>C[j]>B[i]なので検討を中止する
            break
#あるAの下にいくつBが入るか数える
B_under_A=[0]*N     #i番目のBの下に入るCの数
for i in range(N):
    if i > 0:
        if A[i] == A[i-1]:
            B_under_A[i]=B_under_A[i-1]
            continue
    for j in range(N):
        if B[j]>A[i]:
            B_under_A[i]+=1
        else:       #B[j+1]>B[j]>A[i]なので検討を中止する
            break
#あるAのもとに入るBのもとに入るCを数える
C_under_B_under_A=[0]*N
for i in range(N):
    C_under_B_under_A[i]=sum([C_under_B[j] for j in range(B_under_A[i])])
#出力
print((sum(C_under_B_under_A)))


# Optimized solution
#ABC077C 解説を見て自作
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())))
#あるBの下にいくつCが入るか数える
C_under_B=[0]*N     #i番目のBの下に入るCの数
for i in range(N):
    C_under_B[i]=N-bisect.bisect_right(C,B[i])
#あるBの上にいくつAが乗るか数える
A_on_B=[0]*N     #i番目のBの上に乗るAの数
for i in range(N):
    A_on_B[i]=bisect.bisect_left(A,B[i])
#あるBの上下におけるものを数えて出力
ans=0
for i in range(N):
    ans+=C_under_B[i]*A_on_B[i]
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()

count = 0
for i in range(n):
    b = bisect.bisect(B,A[i])
    for j in range(b,n):
        c = bisect.bisect(C,B[j])
        count += n-c

print(count)

# Optimized solution
import bisect

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

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

count = 0

for i in range(n):
    a = bisect.bisect_left(A,B[i])
    c = bisect.bisect_right(C,B[i])
    count += a*(n-c)
    
print(count)
# Original solution
import bisect

n = int(eval(input()))
al = sorted(list(map(int, input().split())))
bl = sorted(list(map(int, input().split())))
cl = sorted(list(map(int, input().split())))

a_len = len(al)
b_len = len(bl)
c_len = len(cl)

ans = 0
for a in al:
    b_index = bisect.bisect_right(bl, a)
    if b_index >= b_len:
        break
    tmp_bl = bl[b_index:]
    for b in tmp_bl:
        c_index = bisect.bisect_right(cl, b)
        if c_index >= c_len:
            break
        ans += c_len - c_index
        # print(f'a:{a}, b_index:{b_index}, c_index:{c_index}, ans:{ans}')

print(ans)


# Optimized solution
import bisect

n = int(eval(input()))
al = sorted(list(map(int, input().split())))
bl = sorted(list(map(int, input().split())))
cl = sorted(list(map(int, input().split())))
ans = 0

for b in bl:
    i = bisect.bisect_left(al, b)
    j = bisect.bisect_right(cl, b)
    ans += i*(n-j)

print(ans)
# Original solution
import bisect

n = int(eval(input()))

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

ans = 0

for a in A:
  i = bisect.bisect_right(B, a)
  for b in B[i:]:
    j = bisect.bisect_right(C, b)
    ans += n-j
    
print(ans)

# Optimized solution
import bisect

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

ans = 0
for b in B:
  a_ind = bisect.bisect_left(A, b)
  c_ind = bisect.bisect_right(C, b)
  ans += a_ind*(n-c_ind)
  
print(ans)
# Original solution
def main():
    n = int(eval(input()))
    a = [int(s) for s in input().split()]
    b = [int(s) for s in input().split()]
    c = [int(s) for s in input().split()]
    print((solve(n, a, b, c)))

def solve(n, a, b, c):
    d = [c, b, a]
    dp = []
    dp.append([1 for _ in range(n)])
    dp.append([0 for _ in range(n)])
    dp.append([0 for _ in range(n)])

    for i in range(1, 3):
        for j in range(n):
            dp[i][j] = sum(dp[i-1][k] for k in range(n) if d[i-1][k] > d[i][j])

    return sum(dp[2])


def ilen(it):
    c = 0
    for _ in it:
        c += 1
    return c

main()


# Optimized solution
import bisect

def main():
    n = int(eval(input()))
    a = sorted([int(s) for s in input().split()])
    b = sorted([int(s) for s in input().split()])
    c = sorted([int(s) for s in input().split()])
    print((solve(n, a, b, c)))

def solve(n, a, b, c):
    d = [c, b, a]
    dp = []
    dp.append([n - i for i in range(n)])
    dp.append([0 for _ in range(n)])
    dp.append([0 for _ in range(n)])

    for i in range(1, 3):
        for j in reversed(list(range(n))):
            k = bisect.bisect(d[i-1], d[i][j])
            if k == n:
                continue

            dp[i][j] = dp[i-1][k]
            if j != n - 1:
                dp[i][j] += dp[i][j+1]

    return dp[2][0]


def ilen(it):
    c = 0
    for _ in it:
        c += 1
    return c

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


"""
minnum以上で最小の数のindexを返す。無いときはlen(List)を返す
計算量log(len(List))

def bts(List,minnum,under=0):
    if List[0]>=minnum:
        return under
    if List[-1]<minnum:
        return len(List)+under
    i = int(len(List)/2)
    if List[i]>=minnum and List[i-1]<minnum:
        return i + under
    if List[i]<minnum:
        return bts(List[i+1:],minnum,under+i+1)
    return bts(List[:i],minnum,under)

"""

def binary_search(list, item):
    if list[0]>=item:
        return 0
    if list[-1]<item:
        return len(list)

    low = 0
    high = len(list) - 1

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

    return None

res = 0
for i in range(N):
    b = B[i]
    a = binary_search(A,b)
    c = N - binary_search(C,b+1)
    res += a*c

print(res)


# Optimized solution
import bisect
n=int(eval(input()))
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
cl=list(map(int,input().split()))

al.sort()
bl.sort()
cl.sort()

ans=0
for b in bl:
    ac=bisect.bisect_right(al,b-1)
    cc=n-bisect.bisect_left(cl,b+1)
    ans+=ac*cc
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())))
neo_b = [[] for _ in range(n)]
ans = 0
for i in range(n):
  neo_b[i] = bisect.bisect_left(a,b[i])
for i in range(n):
  ans += sum(neo_b[:bisect.bisect_left(b,c[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):
  ans += bisect.bisect_left(a,b[i])*(n-bisect.bisect_right(c,b[i]))
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()))
ans = 0

for a in A:
    for b in B:
        for c in C:
            if a < b < c:
                ans += 1
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 n in range(N):
    i = bisect.bisect_left(A,B[n])
    j = len(C) - bisect.bisect_right(C,B[n])
    ans += i * j
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()
bans = []
last = 0
for bi in range(n):
  bnow = b[bi]
  for ci in range(last,n):
    if c[ci] > bnow:
      bans.append([bnow,n-ci])
      last = ci
      break
  else:
    bans.append([bnow,0])
bsun = 0
for bi in range(n):
  bsun += bans[n-1-bi][1]
  bans[n-1-bi].append(bsun)
ans = 0
last = 0
for ai in range(n):
  anow = a[ai]
  for bi in range(last,n):
    if bans[bi][0] > anow:
      ans += bans[bi][2]
      last = bi
      break
#print(bans)
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()
bans = []
for bi in range(n):
  bnow = b[bi]
  here = bisect.bisect_right(c,bnow)
  bans.append([bnow,n-here])
bsun = 0
for bi in range(n):
  bsun += bans[n-1-bi][1]
  bans[n-1-bi].append(bsun)
ans = 0
for ai in range(n):
  anow = a[ai]
  here = bisect.bisect_right(b,anow)
  if here != n:
    ans += bans[here][2]
#print(bans)
print(ans)
# Original 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())))

def check_a(a_num, b_num):
    res = False
    if a_num < b_num:
        res = True
    return res

def check_c(c_num, b_num):
    res = False
    if b_num < c_num:
        res = True
    return res

ans = 0
cnt_a = 0
cnt_c = 0
for bi in range(len(b)):
    left = 0
    right = len(a)-1
    if check_a(a[0], b[bi]) is False:
        cnt_a = 0
    elif check_a(a[-1], b[bi]) is True:
        cnt_a = len(a)
    else:
        while right-left > 1:
            mid = (left + right) // 2
            if check_a(a[mid], b[bi]):
                left = mid
            else:
                right = mid
        cnt_a = left + 1

    left = 0
    right = len(c) - 1
    if check_c(c[0], b[bi]) is True:
        cnt_c = len(c)
    elif check_c(c[-1], b[bi]) is False:
        cnt_c = 0
    else:
        while right - left > 1:
            mid = (left + right) // 2
            if check_c(c[mid], b[bi]):
                right = mid
            else:
                left = mid
        cnt_c = len(c) - right
    ans += cnt_a * cnt_c
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()))

cnt = [0] * len(b)
a = sorted(a)
c = sorted(c)

for i in range(len(b)):
    target = b[i]

    # decide a cnt
    l = 0
    r = len(a) - 1
    if a[l] >= target:
        cnt[i] += 0
    elif a[r] < target: 
        cnt[i] += len(a)
    else:
        while r - l > 1:
            mid = (l + r) // 2
            if a[mid] >= target:
                r = mid
            else:
                l = mid
        cnt[i] += l + 1

    # decide c cnt
    l = 0
    r = len(c) - 1
    if c[l] > target:
        cnt[i] *= len(c)
    elif c[r] <= target: 
        cnt[i] *= 0
    else:
        while r - l > 1:
            mid = (l + r) // 2
            if c[mid] > target:
                r = mid
            else:
                l = mid
        cnt[i] *= len(c) - (l + 1)
print((sum(cnt)))
# 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(" "))))

count = 0
for i in b:
  #print((a[:bisect.bisect(a, i - 1)]), i, c[bisect.bisect_left(c, i + 1):]) 
  count += len(a[:bisect.bisect(a, i - 1):]) * len(a[bisect.bisect_right(c, i):]) 
print(count)

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

count = 0
for i in b:
  #print((a[:bisect.bisect_right(a, i - 1)]), i, c[bisect.bisect_left(c, i + 1):]) 
  #print(bisect.bisect_right(a, i - 1), i, (n - bisect.bisect_left(c, i + 1)) ) 
  count += bisect.bisect_right(a, i - 1) * (n - bisect.bisect_left(c, i + 1)) 
print(count)
# Original solution
#!/usr/bin python3
# -*- coding: utf-8 -*-

from bisect import bisect_left, bisect_right

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

    ret = 0
    for a in A:
        ib = bisect_right(B,a)
        for b in B[ib:]:
            ic = bisect_right(C,b)
            ret += N - ic
    print(ret)

if __name__ == '__main__':
    main()

# Optimized solution
#!/usr/bin python3
# -*- coding: utf-8 -*-

from bisect import bisect_left, bisect_right

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

    ret = 0
    for b in B:
        ia = bisect_left(A,b)
        ic = bisect_right(C,b)
        ret += ia*(N-ic)
    print(ret)

if __name__ == '__main__':
    main()