Sequence II

Time Limit: 2500ms
Memory Limit: 32768KB
This problem will be judged on HDU. Original ID: 5147
64-bit integer IO format: %I64d      Java class name: Main

Description

Long long ago, there is a sequence A with length n. All numbers in this sequence is no smaller than 1 and no bigger than n, and all numbers are different in this sequence.
Please calculate how many quad (a,b,c,d) satisfy:
1. $1\leq a < b < c < d \leq n$
2. $A_{a} < A_{b}$
3. $A_{c} < A_{d}$

Input

The first line contains a single integer T, indicating the number of test cases.
Each test case begins with a line contains an integer n.
The next line follows n integers $A_{1},A_{2}, \ldots, A_{n}$.

[Technical Specification]
1 <= T <= 100
1 <= n <= 50000
1 <= $A_{i}$ <= n

Output

For each case output one line contains a integer,the number of quad.

Sample Input

1
5
1 3 2 4 5

Sample Output

4

Source

Language: 
Theme: 
Share Code? 

Powered by NB231 | Current Style: .