QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100

#6249. Array Game

Statistics

Faraz has participated in a game, but he is not very interested in it. The game is described as follows: Faraz is faced with two sequences $a_1, a_2, \dots, a_n$ and $b_1, b_2, \dots, b_n$, where all $a_i$ are positive and all $b_i$ are initially zero. In each step of the game, Faraz chooses an arbitrary index $i$ ($1 \le i \le n$) and adds or subtracts $a_i$ from $b_i$. That is, he sets $b_i \leftarrow b_i + a_i$ or $b_i \leftarrow b_i - a_i$.

The goal of the game is to make the sequence $b$ strictly increasing after a number of steps. That is, we must have $b_1 < b_2 < \dots < b_n$.

Faraz, who is not interested, wants to reach the goal in the minimum number of steps. Since he does not even have the patience to do this himself, he has asked you what this minimum number of steps is.

Input

The first line contains the integer $n$, which represents the length of the two sequences $a$ and $b$.

The second line contains $n$ integers, which represent the sequence $a_1, a_2, \dots, a_n$ in order.

Output

Print the minimum number of steps required for Faraz's game on a single line.

Constraints

  • $1 \le n \le 5000$
  • $1 \le a_i \le 10^9$

Examples

Input 1

5
1 2 3 4 5

Output 1

4

Input 2

7
1 2 1 2 1 2 1

Output 2

10

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.