## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

## Tokitsukaze and Strange Inequality Codeforces Solution | Codeforces Problem Solution 2022

C. Tokitsukaze and Strange Inequality
time limit per test
1.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Tokitsukaze has a permutation $p$ of length $n$. Recall that a permutation $p$ of length $n$ is a sequence ${p}_{1},{p}_{2},\dots ,{p}_{n}$ consisting of $n$ distinct integers, each of which from $1$ to $n$ ($1\le {p}_{i}\le n$).

She wants to know how many different indices tuples $\left[a,b,c,d\right]$ ($1\le a) in this permutation satisfy the following two inequalities:

${p}_{a}<{p}_{c}$ and ${p}_{b}>{p}_{d}$.

Note that two tuples $\left[{a}_{1},{b}_{1},{c}_{1},{d}_{1}\right]$ and $\left[{a}_{2},{b}_{2},{c}_{2},{d}_{2}\right]$ are considered to be different if ${a}_{1}\ne {a}_{2}$ or ${b}_{1}\ne {b}_{2}$ or ${c}_{1}\ne {c}_{2}$ or ${d}_{1}\ne {d}_{2}$.

Input

The first line contains one integer $t$ ($1\le t\le 1000$) — the number of test cases. Each test case consists of two lines.

[Solution] Tokitsukaze and Good 01-String

Tokitsukaze and Two Colorful Tapes Codeforces Solution

Tokitsukaze and Permutations Codeforces Solution

The first line contains a single integer $n$ ($4\le n\le 5000$) — the length of permutation $p$.

The second line contains $n$ integers ${p}_{1},{p}_{2},\dots ,{p}_{n}$ ($1\le {p}_{i}\le n$) — the permutation $p$.

It is guaranteed that the sum of $n$ over all test cases does not exceed $5000$.

Output

For each test case, print a single integer — the number of different $\left[a,b,c,d\right]$ tuples.