luogu#P10957. 环路运输

环路运输

Problem Description

Along a circular road, there are NN warehouses evenly spaced, numbered from 11 to NN. The distance between warehouse ii and warehouse jj is defined as dist(i,j)=min(ij,Nij)dist(i,j)=\min(|i-j|,N-|i-j|), that is, the shorter one of the counterclockwise or clockwise distance from ii to jj.

Each warehouse stores some goods. The inventory of warehouse ii is AiA_i.

The cost to transport goods between warehouses ii and jj is Ai+Aj+dist(i,j)A_i+A_j+dist(i,j).

Find between which two warehouses the transport cost is the maximum.

Input Format

The first line contains an integer NN.

The second line contains NN integers A1ANA_1 \sim A_N.

Output Format

Output one integer, the maximum cost.

5
1 8 6 2 5
15

Hint

Constraints: 2N1062 \le N \le 10^6, 1Ai1071 \le A_i \le 10^7.

Translated by ChatGPT 5