#P2381. 圆圆舞蹈

圆圆舞蹈

Description

Grandma Xiong’s cows have formed a circle in clockwise order. Because they lack strict training, the gaps between adjacent cows are unequal.

The cows want to know how far apart the farthest pair of cows are. The distance from cow AA to cow BB is defined as the shorter of the clockwise path and the counterclockwise path from AA to BB. Given the distances between adjacent cows, please compute the maximum distance between any two cows.

Input Format

The first line contains an integer NN, the number of cows, 2N1052\le N\le 10^5.

The next NN lines each contain one integer. For i=2,,Ni=2,\ldots,N, line ii contains did_i, the clockwise distance from cow i1i-1 to cow ii, where 1di23111\le d_i\le 2^{31}-1, and the sum of all distances is 2311\le 2^{31}-1.

Line N+1N+1 contains the clockwise distance from cow NN to cow 11.

Output Format

Output one line containing the maximum distance.

5
1
2
3
4
5

7

Hint

Translated by ChatGPT 5