Problem:
Score : 300 points

Problem Statement

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.

Constraints

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9(1\leq i\leq N)

1 \leq B_i \leq 10^9(1\leq i\leq N)

1 \leq C_i \leq 10^9(1\leq i\leq N)

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N

Output

Print the number of different altars that Ringo can build.

Sample Input 1

2
1 5
2 4
3 6

Sample Output 1

3

The following three altars can be built:

Upper: 1-st part, Middle: 1-st part, Lower: 1-st part

Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part

Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part

Sample Input 2

3
1 1 1
2 2 2
3 3 3

Sample Output 2

27

Sample Input 3

6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288

Sample Output 3

87

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;

namespace debug
{
    class Program
    {
        static void Main(string[] args)
        {
            ProgramC a = new ProgramC();
            a.main();

        }
    }

    //ABC077
    class ProgramA
    {
        public void main()
        {
            string s1 = Console.ReadLine();
            string s2 = Console.ReadLine();

            if (s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0])
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
        }
    }

    class ProgramB
    {
        public void main()
        {
            long n = long.Parse(Console.ReadLine());
            for (long i = 1; i < 100000; i++)
            {
                if (i * i > n)
                {
                    Console.WriteLine((i - 1) * (i - 1));
                    return;
                }

            }
        }
    }

    //ABC162
    class ProgramC
    {
        public void main()
        {
            int n = int.Parse(Console.ReadLine());
            long[] a = new long[n];
            long[] b = new long[n];
            long[] c = new long[n];

            string[] s1 = Console.ReadLine().Split(' ');
            string[] s2 = Console.ReadLine().Split(' ');
            string[] s3 = Console.ReadLine().Split(' ');

            for (int i = 0; i < n; i++)
            {
                a[i] = long.Parse(s1[i]);
                b[i] = long.Parse(s2[i]);
                c[i] = long.Parse(s3[i]);
            }

            if (n == 1)
            {
                if (a[0] < b[0] && b[0] < c[0])
                    Console.WriteLine(1);
                else
                    Console.WriteLine(0);
                return;
            }

            //ソートする
            Array.Sort(a);
            Array.Sort(b);
            Array.Sort(c);
            long ans = 0;

            for (int i = 0; i < n; i++)
            {
                //aの二分探索(bより小さいものを探す）
                long ans1 = 0;

                if (a[0] > b[i])
                    continue;


                long min = 0;
                long max = n - 1;

                if (a[n - 1] < b[i])
                {
                    ans1 = n;
                }
                else
                {
                    do
                    {
                        long temp = (max + min) / 2;
                        if (a[temp] < b[i])
                            min = temp;
                        else
                            max = temp;

                    }while (min + 1 != max) ;
                    ans1 = min + 1;
                }

                //cの二分探索（bより大きいものを探す）
                long ans2 = 0;

                if (c[n - 1] < b[i])
                    continue;

                if (c[0] > b[i])
                {
                    ans2 = n;
                }
                else
                {
                    min = 0;
                    max = n - 1;

                    do
                    {
                        long temp = (max + min) / 2;
                        if (c[temp] <= b[i])
                            min = temp;
                        else
                            max = temp;

                    }while(min + 1 != max);
                    ans2 = n - min - 1;
                }
                //答えを足す
                ans += ans1 * ans2;

            }

            Console.WriteLine(ans);
        }
    }



    class ProgramD
    {
        static long[] dp;
        static long[] p;
        public void main()
        {
            string[] s = Console.ReadLine().Split(' ');
            long n = long.Parse(s[0]);
            long x = long.Parse(s[1]);

            //あらかじめ層の数とパティの数は数えておく
            dp = new long[n + 1];
            p = new long[n + 1];
            dp[0] = 1;
            p[0] = 1;
            for (int i = 0; i < n; i++)
            {
                dp[i + 1] = 3 + 2 * dp[i];
                p[i + 1] = 1 + 2 * p[i];
            }

            Console.WriteLine(dfs(n, x));
        }

        /*再帰関数で把握（レベルnのバーガーの下からx番目までにあるパティの数)*/
        static long dfs(long n, long x)
        {
            if (n == 0)
            {
                if (x >= 1)
                    return 1;
                else
                    return 0;
            }
            else if (x <= 1 + dp[n - 1])
                return dfs(n - 1, x - 1);
            else
                return p[n - 1] + 1 + dfs(n - 1, x - 2 - dp[n - 1]);

        }
    }


}