import sys



read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60





def main():

    N, *ABC = list(map(int, read().split()))

    A = sorted(ABC[:N])

    B = sorted(ABC[N : 2 * N])

    C = sorted(ABC[2 * N : 3 * N])



    ans = 0

    for b in B:

        ok = N

        ng = -1

        while ok - ng > 1:

            mid = (ok + ng) // 2

            if A[mid] >= b:

                ok = mid

            else:

                ng = mid

        a_num = ok



        ok = N

        ng = -1

        while ok - ng > 1:

            mid = (ok + ng) // 2

            if C[mid] > b:

                ok = mid

            else:

                ng = mid

        c_num = N - ok



        ans += a_num * c_num



    print(ans)

    return





if __name__ == '__main__':

    main()

from sys import stdin

from bisect import bisect_right, bisect_left





def input():

    return stdin.readline().strip()





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



    ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B)

    print(ans)





if __name__ == "__main__":

    main()

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60


def main():
    N, *ABC = list(map(int, read().split()))
    A = sorted(ABC[:N])
    B = sorted(ABC[N : 2 * N])
    C = sorted(ABC[2 * N : 3 * N])
    ans = 0
    for b in B:
        ok = N
        ng = -1
        while ok - ng > 1:
            mid = (ok + ng) // 2
            if A[mid] >= b:
                ok = mid
            else:
                ng = mid
        a_num = ok
        ok = N
        ng = -1
        while ok - ng > 1:
            mid = (ok + ng) // 2
            if C[mid] > b:
                ok = mid
            else:
                ng = mid
        c_num = N - ok
        ans += a_num * c_num
    print(ans)
    return


if __name__ == "__main__":
    main()

from sys import stdin
from bisect import bisect_right, bisect_left


def input():
    return stdin.readline().strip()


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()
    ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B)
    print(ans)


if __name__ == "__main__":
    main()

-import sys +from sys import stdin +from bisect import bisect_right, bisect_left -read = sys.stdin.read -readline = sys.stdin.readline -readlines = sys.stdin.readlines -sys.setrecursionlimit(10**9) -INF = 1 << 60 + +def input(): +    return stdin.readline().strip() -    N, *ABC = list(map(int, read().split())) -    A = sorted(ABC[:N]) -    B = sorted(ABC[N : 2 * N]) -    C = sorted(ABC[2 * N : 3 * N]) -    ans = 0 -    for b in B: -        ok = N -        ng = -1 -        while ok - ng > 1: -            mid = (ok + ng) // 2 -            if A[mid] >= b: -                ok = mid -            else: -                ng = mid -        a_num = ok -        ok = N -        ng = -1 -        while ok - ng > 1: -            mid = (ok + ng) // 2 -            if C[mid] > b: -                ok = mid -            else: -                ng = mid -        c_num = N - ok -        ans += a_num * c_num +    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 = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B) -    return