PivotOJ

Heating Up

시간 제한: 3000ms메모리 제한: 1024MB출처: NWERC 2021BOJ 23774

문제

Jonas just entered his first chilli-eating contest. He is presented with a pizza consisting of nn slices, numbered from 11 to nn, each containing a selection of chilli peppers. Initially slices ii and i+1i+1 are adjacent on the plate (where 1i<n1 \leq i < n), and so are slices 11 and nn. According to the contest rules only one slice can be consumed at a time, and the slice must be finished in its entirety before a new slice is started. Jonas is allowed to pick any slice to eat first, but after that he is only allowed to eat slices that have at most one remaining adjacent slice.

The spiciness of each slice is measured in Scoville Heat Units (SHU). Jonas has a certain spiciness tolerance, also measured in SHU, which corresponds to the spiciness of the spiciest slice that Jonas can tolerate eating. He has also noticed that, after eating a slice of kk SHU, his tolerance immediately increases by kk.

In order to win the contest, Jonas would like to finish all the slices of his pizza. Help him determine the minimum initial spiciness tolerance necessary to do so while abiding by the contest rules.

입력

The input consists of:

  • One line with an integer nn (3n51053 \le n \le 5 \cdot 10^{5}), the number of pizza slices.
  • One line with nn integers s1,s2,,sns_{1}, s_{2}, \ldots, s_{n} (0si10130 \le s_{i} \le 10^{13}), where sis_i is the spiciness of the iith slice in SHU.

출력

Output the minimum initial spiciness tolerance in SHU that Jonas needs in order to be able to eat all slices of the pizza.

예제

예제 1

입력
5
5 0 10 6 1
출력
4

예제 2

입력
7
20 23 7 2 3 7 1
출력
2
코드를 제출하려면 로그인하세요.