Social running

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

You and a few friends are running together once a week around Lund. You all agree that it is boring and also dangerous to run on your own rather than running with others. Therefore you and your friends decide to minimize the distance that anyone needs to run on their own.

You are NN friends, who live in NN different locations numbered 00 through N1N-1. Everyone will run exactly one lap going through all the locations in cyclic order (if you live in location ii, you run ii+1(modN)N10i1(modN)ii\rightarrow i+1\pmod{N}\rightarrow\ldots\rightarrow N-1\rightarrow 0\rightarrow\ldots\rightarrow i-1\pmod{N}\rightarrow i. Someone starts the run, then everyone joins the run as the group comes, runs exactly one lap and stops when the group comes back to their house.

Given that an optimal person starts the run, what is the minimal total distance that anyone has to run on their own? In the above example, an optimal choice would be to start the run at location 33. Then the first runner has to run the leg from 3 to 0 alone, and it is easily checked that your friend living in location 2 also will be running alone from 1 to 2, for a total solitary distance of 44.

입력

The first line of the input contains the number of friends in the group, NN (2N102\leq N\leq 10). It is followed by NN lines where the ii-th line contains a single integer, the distance from location ii to location i+1(modN)i+1\pmod{N}. Each distance is between 11 and 10410^4.

출력

The output consists of a single integer, the minimal total distance anyone has to run on their own, given that the optimal person starts the run.