Sum of Characteristics
시간 제한4초메모리 제한2048 MB
무작위 배열에서 모든 구간에 대해 모든 인덱스 쌍의 max(a_i+j, a_j+i) 최솟값을 더한 값을 구한다.
문제
You are given an array consisting of random integers from to . For its subsegment , the characteristic is the value
Your task is to calculate
입력
The first line contains an integer (), the number of test cases. The test cases follow.
The first line of each test case contains an integer , the size of the array (). The next line contains the array itself: integers from to , picked uniformly and independently by a pseudorandom number generator.
The sum of over all test cases does not exceed .
출력
For each test case, output a line with a single integer: the sum of characteristics over all the subsegments.