CodeEff/ECCO huggingface dataset:
# Original solution
#!/usr/bin/env python3
#ABC77 C

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 a:
    s = 0
    x = bisect.bisect_right(b,i)
    for j in b[x:]:
        y = bisect.bisect_right(c,j)
        ans += n-y
print(ans)


# Optimized solution
#!/usr/bin/env python3
#ABC77 C

import bisect
n = int(eval(input()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for i in b:
    x = bisect.bisect_left(a,i)
    y = bisect.bisect_right(c,i)
    ans += x*(n-y)
print(ans)
# Original solution
import sys
from bisect import bisect_right, bisect_left
from functools import reduce
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))
    C = list(map(int, readline().split()))
    A.sort()
    B.sort()
    C.sort()
    ans = 0
    for i in range(N):
        top = bisect_left(A, B[i])
        bottom = bisect_right(C, B[i])
        if top>0 and bottom != N:
            ans += top*(N-bottom)
    print(ans)
if __name__ == '__main__':
    main()

# Optimized solution
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from bisect import bisect_right, bisect_left
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))
    C = list(map(int, readline().split()))

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


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

    print(ans)

if __name__ == '__main__':
    main()
# Original solution
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.sort()
B.sort()
C.sort()
B += [10 ** 9 + 1] + [0]    # B[-1] = 0, B[N] = 10**9 + 1となるようにする
C += [10 ** 9 + 1] + [0]    # C[-1] = 0, C[N] = 10**9 + 1となるようにする

# For each j = 0, 1, ..., N-1,
# find k such that B[j] < C[k] and (C[k-1] <= B[j] or k = 0)
# Let K[j] = k for such k.
# If such k doesn't exist, let K[j] := N
K = [0] * N

for j in range(N):
    ng = -1 # C[ng] <= B[j]
    ok = N  # B[j] < C[ok]
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if B[j] < C[mid]:
            ok = mid
        else:
            ng = mid
    K[j] = ok

# Let
# f[j] := B[j]より大きいC[k]の数 + B[j + 1]より大きいC[k]の数
#           ... + B[N-1]より大きいC[k]の数
f = [0] * (N - 1) + [N - K[N - 1]]
for j in range(N - 2, -1, -1):
    f[j] = f[j + 1] + N - K[j]

ans = 0
for i in range(N):
    # find j such that B[j - 1] <= A[i] < B[j]
    ng = -1  # B[ng] <= A[i]
    ok = N   # A[i] < B[ok]
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if A[i] < B[mid]:
            ok = mid
        else:
            ng = mid
    if ok >= N: continue
    # 0 <= ok <= N - 1
    ans += f[ok]

print(ans)

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

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

print(ans)
# Original solution
import bisect

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

    ans = 0

    b_list.sort()
    c_list.sort()

    for i in range(n):
        tob_insert_num = a_list[i]
        tob_insert_index = bisect.bisect_right(b_list, tob_insert_num)
        for j in range(tob_insert_index,n):
            toc_insert_num = b_list[j]
            toc_insert_index = bisect.bisect_right(c_list, toc_insert_num)
            ans += n - toc_insert_index

    print(ans)

if __name__ == '__main__':
    main()

# Optimized solution
import bisect

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

    ans = 0

    a_list.sort()
    c_list.sort()

    for i in range(n):
        toa_insert_index = bisect.bisect_left(a_list, b_list[i])
        toc_insert_index = bisect.bisect_right(c_list, b_list[i])
        ans += toa_insert_index * ( n - toc_insert_index )

    print(ans)

if __name__ == '__main__':
    main()
# Original solution
# -*- coding: utf-8 -*-
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

N = int(eval(input()))
An = list(map(int, input().split()))
Bn = list(map(int, input().split()))
Cn = list(map(int, input().split()))

An.sort()
Bn.sort()
Cn.sort()
#
# print(An)
# print(Bn)
# print(Cn)
#B
B_cnt = []
j = 0
for i in range(N):
    while j < N:
        if Bn[i] < Cn[j]:
            B_cnt.append(N - j)
            break
        else:
            j += 1
# print(B_cnt)

A_cnt = 0
j = 0
for i in range(N):
    while j < N:
        if An[i] < Bn[j]:
            for cnt in B_cnt[j:]:
                A_cnt += cnt
            break
        else:
            j += 1

print(A_cnt)



# Optimized solution
# -*- coding: utf-8 -*-
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

N = int(eval(input()))
An = list(map(int, input().split()))
Bn = list(map(int, input().split()))
Cn = list(map(int, input().split()))

An.sort()
Bn.sort()
Cn.sort()

# print(An)
# print(Bn)
# print(Cn)

# B
C_cnt = []
C_sum = 0
j = 0
for i in range(N):
    while j < N:
        if Bn[i] < Cn[j]:
            C_cnt.append(N - j)
            C_sum += N - j
            break
        else:
            j += 1


B_cnt = []
temp_sum = 0
for cnt in C_cnt:
    B_cnt.append(C_sum - temp_sum)
    temp_sum += cnt

A_cnt = 0
j = 0
for i in range(N):
    while j < N:
        if An[i] < Bn[j]:
            if j < len(B_cnt):
                A_cnt += B_cnt[j]
            break
        else:
            j += 1

# print(C_cnt)
# print(B_cnt)
print(A_cnt)
# Original solution
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#from bisect import insort_left
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
#import itertools
#import heapq
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()
from bisect import bisect_left
ans = 0
for i in range(N):
    a = A[i]
    indb = bisect_left(B,a+1)
    if indb == N:
        continue
    for j in range(indb,N):
        b = B[j]
        indc = bisect_left(C,b+1)
        ans += N-indc
print(ans)
  

# Optimized solution
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#from bisect import insort_left
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
#import itertools
#import heapq
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()
from bisect import bisect_left
ans = 0
for i in range(N):
    b = B[i]
    inda = bisect_left(A,b)
    indc = bisect_left(C,b+1)
    ans += (N-indc)*inda
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(" ")))
m = 0

A.sort()
B.sort()
C.sort(reverse=True)

for j in B:
    for i in range(N):
        if A[i] >= j:
            break
        if A[N-1] < j:
            i = N
    for k in range(N):
        if j >= C[k]:
            break
        if j < C[N-1]:
            k = N
    m =  m + i * k

print(m)

# 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()
C.reverse()
 
ans = 0
ai = 0
ci = N-1
for b in B:
    while ai < N and A[ai] < b:
        ai += 1
    while ci >= 0 and C[ci] <= b:
        ci -= 1
    ans += ai * (ci+1)
 
print(ans)
# Original solution
import bisect
N=int(eval(input()))
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))
alist.sort()
blist.sort()
clist.sort()

answer=0
for bi in range(N):
  ai=bisect.bisect_left(alist,blist[bi])  
  ci=bisect.bisect(clist,blist[bi])  
  #print(ai,bi,ci)
  answer+=ai*(N-ci)

print(answer)

# Optimized solution
import bisect
N=int(eval(input()))
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))
alist.sort()
blist.sort()
clist.sort()

answer=0
ai,ci=0,0
for bi in range(N):
  while(ai<N and alist[ai]<blist[bi]):
    ai+=1
  while(ci<N and blist[bi]>=clist[ci]):
    ci+=1
  #print(ai,bi,ci)
  answer+=ai*(N-ci)

print(answer)
# Original solution
N = int(eval(input()))
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
A2=sorted(A)
B2=sorted(B)
C2=sorted(C)
ans = 0
sum = 0
t =0
b = 0
for i in range(N):
    a = A2[i]
    low = 0
    high = N-1
    while True:
        t = (low + high) // 2
        if B2[t] <= a:
            if t == N-1:
                b = False
                break
            elif B2[t] <= a <B2[t+1]:
                b = B2[t+1]
                t = t + 1
                break
            else:
                low = t+1
                continue
        elif B2[t] > a:
            if t == 0:
                b = B2[0]
                break
            elif B2[t] > a >= B2[t-1]:
                b = B2[t]
                break
            else:
                high = t - 1
                continue
    if b != False:
        for j in range(t,N):
            b = B2[j]
            low = 0
            high = N - 1
            while True:
                #print(a, b)
                t = (low + high) // 2
                if C2[t] <= b:
                    if t == N-1:
                        ans = 0
                        break
                    elif C2[t] <= b < C2[t + 1]:
                        c = C2[t + 1]
                        ans = N - t - 1
                        break
                    else:
                        low = t + 1
                        continue
                elif C2[t] > b:
                    if t == 0:
                        ans = N
                        break
                    elif C2[t] > b >= C2[t - 1]:
                        c = C2[t]
                        ans = N - t
                        break
                    else:
                        high = t - 1
                        continue
                #print("ans={}".format(ans))
            sum += ans

print(sum)


# Optimized solution
N = int(eval(input()))
A = list(int(i) for i in input().split())
B = list(int(i) for i in input().split())
C = list(int(i) for i in input().split())
A.sort()
B.sort()
C.sort()
sum = 0
for j in range(N):
    low = low2 = 0
    high = high2 = N
    b = B[j]
    mid = mid2 = 0
    #print(b)
    while(high>low):
        mid = (high + low)//2
        if b > A[mid]:
            low = mid +1
        else:
            high = mid
    acount = low
    while (high2>low2):
        mid2 = (high2 + low2)//2
        if b < C[mid2]:
            high2 = mid2
        else:
            low2 = mid2 + 1
    ccount=N-low2
    sum += acount*ccount
print(sum)
# Original solution
import bisect as bis

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):
    top = a[i]
    for j in range(n):
        mid = b[j]
        if top >= mid:
            continue
        k = bis.bisect_right(c, mid)
        ans += n - k

print(ans)

# Optimized solution
import bisect as bis

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_e in b:
    n_top = bis.bisect_left(a, b_e)
    n_bottom = n - bis.bisect_right(c, b_e)
    ans += n_top * n_bottom

print(ans)
# Original solution
#!/usr/bin/env python3
def main():
    from bisect import bisect

    N = int(eval(input()))
    A = sorted([int(x) for x in input().split()])
    B = sorted([int(x) for x in input().split()])
    C = sorted([int(x) for x in input().split()])

    lst = [N - bisect(C, b) for b in B]
    ans = 0
    for a in A:
        ans += sum(lst[bisect(B, a):])
    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
def main():
    from bisect import bisect

    N = int(eval(input()))
    A = sorted([int(x) for x in input().split()])
    B = sorted([int(x) for x in input().split()])
    C = sorted([int(x) for x in input().split()])

    lst = [N - bisect(C, b) for b in B]
    lst = lst[::-1]
    tmp_lst = [lst[0]]
    for i in lst[1:]:
        tmp_lst.append(i + tmp_lst[-1])
    tmp_lst = tmp_lst[::-1]

    ans = 0
    for a in A:
        res = bisect(B, a)
        ans += tmp_lst[res] if res < N else 0
    print(ans)


if __name__ == '__main__':
    main()
# Original solution
#!/usr/bin/env python3
def main():
    from bisect import bisect

    N = int(eval(input()))
    A = sorted([int(x) for x in input().split()])
    B = sorted([int(x) for x in input().split()])
    C = sorted([int(x) for x in input().split()])

    lst = [N - bisect(C, b) for b in B]
    lst = lst[::-1]
    tmp_lst = [lst[0]]
    for i in lst[1:]:
        tmp_lst.append(i + tmp_lst[-1])
    tmp_lst = tmp_lst[::-1]

    ans = 0
    for a in A:
        res = bisect(B, a)
        ans += tmp_lst[res] if res < N else 0
    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
def main():
    from bisect import bisect, bisect_left

    N = int(eval(input()))
    A = sorted([int(x) for x in input().split()])
    B = sorted([int(x) for x in input().split()])
    C = sorted([int(x) for x in input().split()])

    print((sum([bisect_left(A, b) * (N - bisect(C, b)) for b in B])))


if __name__ == '__main__':
    main()
# 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(reverse=True)
# B.sort(reverse=True)
# C.sort(reverse=True)
# C.append(-1)
a_count = [0 for i in range(N)]
b_count = [0 for i in range(N)]
# i, j = 0, 0
# while i < N:
#     if B[i] >= C[j]:
#         b_count[i] = j
#         i += 1
#     else:
#         j += 1
for i in range(N):
    for j in range(N):
        if B[i] < C[j]:
            b_count[i] += 1
for i in range(N):
    for j in range(N):
        if A[i] < B[j]:
            a_count[i] += b_count[j]
print((sum(a_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.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
c_cnt = [1 for i in range(N)]

def count(A, B, b_cnt):
    B.append(-1)
    a_cnt = [0 for i in range(N)]
    i, j = 0, 0
    while i < N:
        if A[i] < B[j]:
            a_cnt[i] += b_cnt[j]
            j += 1
        else:
            i += 1
            if 1 <= i < N:
                a_cnt[i] = a_cnt[i-1]
    return a_cnt

b_cnt = count(B, C, c_cnt)
a_cnt = count(A, B, b_cnt)
print((sum(a_cnt)))
# Original solution
from bisect import bisect_right
import sys
input = sys.stdin.readline
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(N):
    a = A[i]
    bb = bisect_right(B, a)
    if bb == N + 1:
        continue
    for j in range(bb, N):
        b = B[j]
        cc = bisect_right(C, b)
        if cc == N + 1:
            continue
        ans += (N - cc)
print(ans)


# Optimized solution
from bisect import bisect_right, bisect_left
import sys
input = sys.stdin.readline
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 j in range(N):
    b = B[j]
    i = bisect_left(A, b)
    k = bisect_right(C, b)
    ans += i * (N - k)
print(ans)
# Original solution
import bisect

eval(input())
A=[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 a in A:
  for b in B[bisect.bisect_right(B,a):]:
    ans+=len(C[bisect.bisect_right(C,b):])

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:
  ans+=bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b))

print(ans)
# Original solution
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__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())))
    count = 0

    # See:
    # https://img.atcoder.jp/arc084/editorial.pdf
    # https://docs.python.jp/3/library/bisect.html
    from bisect import bisect_left
    from bisect import bisect_right

    for number in b:
        high = bisect_left(a, number)
        low = bisect_right(c, number)
        count += len(a[:high]) * len(c[low:])

    print(count)


# Optimized solution
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__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())))
    count = 0

    # See:
    # https://img.atcoder.jp/arc084/editorial.pdf
    # https://docs.python.jp/3/library/bisect.html
    # https://beta.atcoder.jp/contests/abc077/submissions/1740764
    from bisect import bisect_left
    from bisect import bisect_right

    for number in b:
        a_count = bisect_left(a, number)
        c_count = n - bisect_right(c, number)
        count += a_count * c_count

    print(count)
# Original solution
# -*- coding: utf-8 -*-


def main():
    from bisect import bisect_left
    from bisect import bisect_right

    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 bi in b:
        less = bisect_left(a, bi)
        greater = n - bisect_right(c, bi)
        ans += less * greater

    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
# -*- coding: utf-8 -*-


def main():
    from bisect import bisect_left
    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())))
    ans = 0

    for bi in b:
        less = bisect_left(a, bi)
        greater = n - bisect_right(c, bi)
        ans += less * greater

    print(ans)


if __name__ == '__main__':
    main()
# 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())))

A_B = []
B_C = []
total = 0

for a in A:
    k = bisect.bisect_right(B, a)
    l = N - k
    A_B.append(l)

for b in B:
    k = bisect.bisect_right(C, b)
    l = N - k
    B_C.append(l)

for n in range(N):
    total += sum(B_C[N-A_B[n]:])

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

A_B = []
B_C = []
total = 0

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

print(total)
# Original solution
#!/usr/bin/python

# AtCoder Beginner Contest 077
# C - Snuke Festival

from sys import stdin

def solve(As, Bs, Cs):
    # Bs :: [(b, # of bottom parts > b)]
    Bs = [(b, sum([1 for c in Cs if c > b])) for b in Bs]
    # As :: [# of mid & bottom parts > a]
    As = [sum([b[1] for b in Bs if b[0] > a]) for a in As]
    return sum(As)

N = int(stdin.readline())
As = [int(w) for w in stdin.readline().split()]
Bs = [int(w) for w in stdin.readline().split()]
Cs = [int(w) for w in stdin.readline().split()]
if len(As) != N or len(Bs) != N or len(Cs) != N: raise
print((solve(As, Bs, Cs)))

# Optimized solution
#!/usr/bin/python

# AtCoder Beginner Contest 077
# C - Snuke Festival

from sys import stdin

def solve(As, Bs, Cs):
    As.sort()
    Bs.sort()
    Cs.sort()
    # Bs :: [(b, # of bottom parts > b)]
    # Bs = [(b, sum([1 for c in Cs if c > b])) for b in Bs]
    j = 0
    for i in range(len(Bs)):
        while j < len(Cs) and Bs[i] >= Cs[j]: j += 1
        Bs[i] = (Bs[i], len(Cs) - j)
    # Accumulate Bs[][1]
    for i in range(len(Bs) - 1, 0, -1):
        Bs[i-1] = (Bs[i-1][0], Bs[i-1][1] + Bs[i][1])
    # As :: [# of mid & bottom parts > a]
    # As = [sum([b[1] for b in Bs if b[0] > a]) for a in As]
    j = 0
    for i in range(len(As)):
        while j < len(Bs) and As[i] >= Bs[j][0]: j += 1
        As[i] = Bs[j][1] if j < len(Bs) else 0
    return sum(As)

N = int(stdin.readline())  # <= 1e+5
As = [int(w) for w in stdin.readline().split()]
Bs = [int(w) for w in stdin.readline().split()]
Cs = [int(w) for w in stdin.readline().split()]
if len(As) != N or len(Bs) != N or len(Cs) != N: raise
print((solve(As, Bs, Cs)))
# Original solution
import bisect
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(eval(input()))
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return eval(input())
def LS(): return input().split()


def main():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    a.sort()
    b.sort()
    c.sort()
    ans = 0
    for bi in b:
        a_ind = bisect.bisect_left(a, bi)
        a_oks = a[:a_ind]
        c_ind = bisect.bisect_right(c, bi)
        c_oks = c[c_ind:]
        ans += len(a_oks) * len(c_oks)
    print(ans)


main()


# Optimized solution
import bisect
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(eval(input()))
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return eval(input())
def LS(): return input().split()


def main():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    a.sort()
    b.sort()
    c.sort()
    ans = 0
    for bi in b:
        num_a = bisect.bisect_left(a, bi)
        num_c = n - bisect.bisect_right(c, bi)
        ans += num_a * num_c
    print(ans)


main()