시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 2048 MB111100.000%

문제

You are given an array $a$ consisting of $n$ random integers from $1$ to $n$. For its subsegment $[\ell, r]$, the characteristic is the value $$C(\ell, r) = \min\limits_{\ell \le i < j \le r} \max(a_i + j, a_j + i)\text{.}$$

Your task is to calculate $$\sum\limits_{\ell = 1}^n \sum_{r = \ell + 1}^n C(\ell, r)\text{.}$$

입력

The first line contains an integer $t$ ($1 \le t \le 3 \cdot 10^5$), the number of test cases. The test cases follow.

The first line of each test case contains an integer $n$, the size of the array ($1 \le n \le 3 \cdot 10^5$). The next line contains the array itself: $n$ integers from $1$ to $n$, picked uniformly and independently by a pseudorandom number generator.

The sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.

출력

For each test case, output a line with a single integer: the sum of characteristics over all the subsegments.

예제 입력 1

3
2
2 1
5
3 5 4 1 4
6
1 4 6 1 6 3

예제 출력 1

4
72
112