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 PHP7 (7.0.15) (judge verdict: Accepted)

<?php

// define('DEBUG', true);
define('DEBUG', false);

$ans = 0;

fscanf(STDIN, "%d", $N);
$A = explode(" ", trim(fgets(STDIN)));
$B = explode(" ", trim(fgets(STDIN)));
$C = explode(" ", trim(fgets(STDIN)));

$sumA = array();
$sumB = array();
$sumC = array();

foreach ($A as $v) {
    $sumA[$v]++;
}
foreach ($B as $v) {
    $sumB[$v]++;
}
foreach ($C as $v) {
    $sumC[$v]++;
}

// var_dump($sumA);
// var_dump($sumB);
// var_dump($sumC);

ksort($sumA);
ksort($sumB);
krsort($sumC);

// var_dump($sumA);
// var_dump($sumB);
// var_dump($sumC);
// exit;

$tmp = 0;
foreach ($sumA as $k => $v) {
    $tmp += $v;
    $sumA[$k] = $tmp;
}
$tmp = 0;
foreach ($sumC as $k => $v) {
    $tmp += $v;
    $sumC[$k] = $tmp;
}

if (DEBUG) var_dump($sumA);
if (DEBUG) var_dump($sumB);
ksort($sumC);
if (DEBUG) var_dump($sumC);


$keyA = array_keys($sumA);
$keyB = array_keys($sumB);
$keyC = array_keys($sumC);

$curA = 0;
$curC = 0;
foreach ($sumB as $k => $v) {
    if (DEBUG) echo "B:{$k} {$v}\n";

    if ($keyA[$curA] >= $k) {
        $mulA = 0;
    } else {
        while (count($keyA) > $curA+1 && $keyA[$curA+1] < $k) {
            if ($curA > count($keyA)) {
                break;
            }
            $curA++;
        }
        $mulA = $sumA[$keyA[$curA]];
    }
    if (DEBUG) echo " A:{$keyA[$curA]} {$sumA[$keyA[$curA]]} mulA:{$mulA}\n";

    $mulC = $sumC[$keyC[$curC]];
    while ($keyC[$curC] <= $k) {
        $curC++;
        if ($curC > count($keyC)) {
            $mulC = 0;
            break;
        }
        $mulC = $sumC[$keyC[$curC]];
    }
    if (DEBUG) echo " C:{$keyC[$curC]} {$sumC[$keyC[$curC]]} mulC:{$mulC}\n";

    $ans += $v * $mulA * $mulC;
}

echo $ans . PHP_EOL;

exit;


foreach ($keyA as $idxA => $A) {
    foreach ($keyB as $idxB => $B) {
        echo "{$keyA[$idxA]} >= {$keyB[$idxB]}\n"; 
        if ($keyA[$idxA] >= $keyB[$idxB]) continue;
        foreach ($keyC as $idxC => $C) {
            echo "{$keyB[$idxB]} >= {$keyC[$idxC]}\n"; 
            if ($keyB[$idxB] >= $keyC[$idxC]) continue;
            echo "{$keyA[$idxA]}[{$sumA[$keyA[$idxA]]}] {$keyB[$idxB]}[{$sumB[$keyB[$idxB]]}] {$keyC[$idxC]}[{$sumC[$keyC[$idxC]]}]\n";
        }
    }
}


exit("END\n");

fscanf(STDIN, "%s", $c);
$a = array();
foreach (range(1, 4) as $x) $a[$x] = substr_count($c, $x);
echo max($a), " ", min($a), "\n";