#P6170. [USACO16FEB] Circular Barn G
[USACO16FEB] Circular Barn G
Description
As a fan of modern architecture, Farmer John built a new circular barn. Inside the barn there are rooms arranged in a ring (), numbered in clockwise order. Each room has doors to its left and right neighboring rooms, and also a door leading outside.
Now FJ has cows, and his goal is to have exactly one cow in each room. Unfortunately, the cows are currently in random rooms: room contains cows. It is guaranteed that .
FJ decides to solve this problem as follows: he will have some cows move clockwise, passing through some rooms to reach their assigned positions. If a cow passes through doors, the energy it uses is . You need to help FJ compute the minimum possible total energy used by all cows.
Input Format
The first line contains an integer . The next lines each contain an integer on line .
Output Format
Output the minimum total energy used by all cows.
10
1
0
0
2
0
0
1
2
2
2
33
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号