题目描述
Problem Description
You are playing a game.
There are $ N $ enemies lined up in a row, and the health of the $ i $-th enemy from the front is $ H_i $.
You use a variable $ T $ initialized to $ 0 $, and repeat the following action until the health of all enemies is $ 0 $ or below.
- Increment $ T $ by $ 1 $. Then, attack the foremost enemy with health $ 1 $ or more. If $ T $ is a multiple of $ 3 $, the enemy's health decreases by $ 3 $, otherwise it decreases by $ 1 $.
Find the value of $ T $ when the health of all enemies is $ 0 $ or below.
Input Format
The input is given from the standard input in the following format.
$ N $ $ H_1 $ $ H_2 $ $\ldots$ $ H_N $
Output Format
Output the answer.
Sample Input and Output
Sample Input #1
3
6 2 2
Sample Output #1
8
Sample Input #2
9
1 12 123 1234 12345 123456 1234567 12345678 123456789
Sample Output #2
82304529
Sample Input #3
5
1000000000 1000000000 1000000000 1000000000 1000000000
Sample Output #3
3000000000
Notes/Hints
Constraints
- $1 \leq N \leq 2 \times 10^5$
- $1 \leq H_i \leq 10^9$
- All inputs are integers
Sample Explanation 1
The actions are performed as follows.
- $ T=1 $. Attack the 1st enemy, its health becomes $ 6-1=5 $.
- $ T=2 $. Attack the 1st enemy, its health becomes $ 5-1=4 $.
- $ T=3 $. Attack the 1st enemy, its health becomes $ 4-3=1 $.
- $ T=4 $. Attack the 1st enemy, its health becomes $ 1-1=0 $.
- $ T=5 $. Attack the 2nd enemy, its health becomes $ 2-1=1 $.
- $ T=6 $. Attack the 2nd enemy, its health becomes $ 1-3=-2 $.
- $ T=7 $. Attack the 3rd enemy, its health becomes $ 2-1=1 $.
- $ T=8 $. Attack the 3rd enemy, its health becomes $ 1-1=0 $.
Sample Explanation 3
Be careful of overflow.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分