QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓

#11101. Love Theory

Statistiques

Hello, and welcome to the warm-up session of the 10th China Collegiate Programming Contest Finals. Little Blue Fish has prepared some fresh and delicious stories for everyone and hopes to share them with you all. Of course, no matter how much Little Blue Fish wants to say, the first thing to do is to introduce himself. Therefore, Little Blue Fish wants to present his latest techniques at the Symposium on Theory of Loving (STOL).

Little Blue Fish wants to play a game with his idol. In this game, the idol has a sequence of integers $x_1, x_2, \dots, x_n$. Initially, all values of $x_i$ are $0$. The idol can perform the following operations any number of times:

  • Choose an integer $k$ ($1 \le k \le n$). Then, for all $1 \le i \le k$, increase $x_i$ by $1$. The cost of this operation is $k$.
  • Choose an integer $k$ ($1 \le k \le n$). Then, for all $n - k + 1 \le i \le n$, increase $x_i$ by $1$. The cost of this operation is $k$.

Little Blue Fish also has $n$ integers $y_1, y_2, \dots, y_n$. He hopes the idol will perform a series of operations such that $x_i \ge y_i$ holds for every $1 \le i \le n$.

This task is too simple for the idol. So he knows the minimum cost required to reach the goal. Therefore, your task is to write a program to calculate the minimum cost.

Input

The first line contains an integer $T$ ($1 \le T \le 10^5$), representing the number of test cases.

For each test case, the first line contains an integer $n$ ($1 \le n \le 10^6$).

The next line contains $n$ non-negative integers $y_1, y_2, \dots, y_n$ ($0 \le y_i \le 10^9$).

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

Output

For each test case, output a single integer representing the answer.

Examples

Input 1

3
5
1 1 1 1 1
10
0 0 0 0 1000000000 0 0 0 0 0
13
1 1 4 5 1 4 1 9 1 9 8 1 0

Output 1

5
5000000000
76

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.