The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.  He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i.  To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.  How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
def main():
    from bisect import bisect_left
    n, *abc = map(int, open(0).read().split())
    a, b, c = abc[:n], abc[n:2 * n], abc[2 * n:]
    a, b, c = sorted(a), sorted(b), sorted(c)
    ans = 0
    for i in c:
        j = bisect_left(b, i)
        for k in b[:j]:
            l = bisect_left(a, k)
            ans += l
            print(i, j, l)
    print(ans)


if __name__ == '__main__':
    main()

def main():
    from bisect import bisect_left, bisect_right
    n, *abc = map(int, open(0).read().split())
    a, b, c = abc[:n], abc[n:2 * n], abc[2 * n:]
    a, b, c = sorted(a), sorted(b), sorted(c)
    ans = 0
    for i in b:
        j = bisect_left(a, i)
        k = n - bisect_right(c, i)
        ans += j * k

    print(ans)


if __name__ == '__main__':
    main()
