import sys



import numba as nb

import numpy as np



input = sys.stdin.readline





@nb.njit("i8(i8[:],i8)", cache=True)

def binary_search(a, key):

    """Meguru type binary search"""

    ng = -1

    ok = len(a)



    def is_ok(a, key, idx):

        if a[idx] > key:

            return True

        else:

            return False



    while (abs(ok - ng) > 1):

        mid = (ok + ng) // 2

        if is_ok(a, key, mid):

            ok = mid

        else:

            ng = mid



    return ok





@nb.njit("i8(i8,i8[:],i8[:],i8[:])", cache=True)

def solve(N, A, B, C):

    A.sort()

    B.sort()

    C.sort()



    BC = np.zeros(shape=N + 1, dtype=np.int64)

    for i in range(N):

        BC[i] = N - binary_search(C, B[i])



    ans = 0

    for a in A:

        idx = binary_search(B, a)

        ans += np.sum(BC[idx:])



    return ans





def main():

    N = int(eval(input()))

    A = np.array(input().split(), dtype=np.int64)

    B = np.array(input().split(), dtype=np.int64)

    C = np.array(input().split(), dtype=np.int64)



    ans = solve(N, A, B, C)

    print(ans)





if __name__ == "__main__":

    main()

import sys

from bisect import bisect_left, bisect_right



input = sys.stdin.readline





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

    for b in B:

        n_a = bisect_left(A, b)

        n_c = N - bisect_right(C, b)

        ans += n_a * n_c



    print(ans)





if __name__ == "__main__":

    main()

import sys
import numba as nb
import numpy as np

input = sys.stdin.readline


@nb.njit("i8(i8[:],i8)", cache=True)
def binary_search(a, key):
    """Meguru type binary search"""
    ng = -1
    ok = len(a)

    def is_ok(a, key, idx):
        if a[idx] > key:
            return True
        else:
            return False

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


@nb.njit("i8(i8,i8[:],i8[:],i8[:])", cache=True)
def solve(N, A, B, C):
    A.sort()
    B.sort()
    C.sort()
    BC = np.zeros(shape=N + 1, dtype=np.int64)
    for i in range(N):
        BC[i] = N - binary_search(C, B[i])
    ans = 0
    for a in A:
        idx = binary_search(B, a)
        ans += np.sum(BC[idx:])
    return ans


def main():
    N = int(eval(input()))
    A = np.array(input().split(), dtype=np.int64)
    B = np.array(input().split(), dtype=np.int64)
    C = np.array(input().split(), dtype=np.int64)
    ans = solve(N, A, B, C)
    print(ans)


if __name__ == "__main__":
    main()

import sys
from bisect import bisect_left, bisect_right

input = sys.stdin.readline


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


if __name__ == "__main__":
    main()

-import numba as nb -import numpy as np +from bisect import bisect_left, bisect_right -@nb.njit("i8(i8[:],i8)", cache=True) -def binary_search(a, key): -    """Meguru type binary search""" -    ng = -1 -    ok = len(a) - -    def is_ok(a, key, idx): -        if a[idx] > key: -            return True -        else: -            return False - -    while abs(ok - ng) > 1: -        mid = (ok + ng) // 2 -        if is_ok(a, key, mid): -            ok = mid -        else: -            ng = mid -    return ok - - -@nb.njit("i8(i8,i8[:],i8[:],i8[:])", cache=True) -def solve(N, A, B, C): +def main(): +    N = int(eval(input())) +    A = list(map(int, input().split())) +    B = list(map(int, input().split())) +    C = list(map(int, input().split())) -    BC = np.zeros(shape=N + 1, dtype=np.int64) -    for i in range(N): -        BC[i] = N - binary_search(C, B[i]) -    for a in A: -        idx = binary_search(B, a) -        ans += np.sum(BC[idx:]) -    return ans - - -def main(): -    N = int(eval(input())) -    A = np.array(input().split(), dtype=np.int64) -    B = np.array(input().split(), dtype=np.int64) -    C = np.array(input().split(), dtype=np.int64) -    ans = solve(N, A, B, C) +    for b in B: +        n_a = bisect_left(A, b) +        n_c = N - bisect_right(C, b) +        ans += n_a * n_c