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 = -1

        ng = N

        while ng - ok > 1:

            mid = (ok + ng) // 2

            if A[mid] < b:

                ok = mid

            else:

                ng = mid

        a_num = ok + 1



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

import sys

from bisect import bisect_left, bisect_right



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 = ABC[N : 2 * N]

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



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



    print(ans)

    return





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 = -1
        ng = N
        while ng - ok > 1:
            mid = (ok + ng) // 2
            if A[mid] < b:
                ok = mid
            else:
                ng = mid
        a_num = ok + 1
        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()

import sys
from bisect import bisect_left, bisect_right

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 = ABC[N : 2 * N]
    C = sorted(ABC[2 * N : 3 * N])
    ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B)
    print(ans)
    return


if __name__ == "__main__":
    main()

+from bisect import bisect_left, bisect_right -    B = sorted(ABC[N : 2 * N]) +    B = ABC[N : 2 * N] -    ans = 0 -    for b in B: -        ok = -1 -        ng = N -        while ng - ok > 1: -            mid = (ok + ng) // 2 -            if A[mid] < b: -                ok = mid -            else: -                ng = mid -        a_num = ok + 1 -        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 +    ans = sum(bisect_left(A, b) * (N - bisect_right(C, b)) for b in B)