PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000230. Cân bằng các đống đá (Balanced Stone Heaps)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Cân bằng các đống đá (Balanced Stone Heaps)

Balanced Stone Heaps

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn piles with initial sizes hih_i. Process piles 3,4,…,n3,4,\ldots,n in this increasing order, exactly once.

For pile ii, choose a nonnegative integer dd with 3d3d not exceeding its current size. Move dd stones to pile i−1i-1 and 2d2d to pile i−2i-2, removing 3d3d stones from pile ii. Choosing d=0d=0 is allowed.

Maximize the size of the smallest pile after all operations.

Input

  • The first line contains nn.
  • The next line contains nn integers h1,…,hnh_1,\ldots,h_n.

Output

Print the maximum achievable minimum pile size.

Subtasks

  • Subtask 1 (20 points): 3≤n≤203\le n\le 20; 1≤hi≤1091\le h_i\le 10^9.
  • Subtask 2 (30 points): 3≤n≤20003\le n\le 2000; 1≤hi≤1091\le h_i\le 10^9.
  • Subtask 3 (50 points): 3≤n≤2000003\le n\le 200000; 1≤hi≤1091\le h_i\le 10^9.

Examples

Input

4
1 2 10 100

Output

7

Explanation

Move d=3d=3 from pile 33 to get [7,5,1,100][7,5,1,100]. Then move d=6d=6 from pile 44 to get [7,17,7,82][7,17,7,82], so every pile has at least 77 stones. A minimum of 88 is impossible under the one-pass operation order; the answer is 77.