#P3137. [USACO16FEB] Circular Barn S
[USACO16FEB] Circular Barn S
Description
As an enthusiast of modern architecture, Farmer John built a new circular barn. Inside the barn, rooms are arranged in a ring (), numbered in clockwise order . Each room has doors to its two adjacent rooms, as well as a door to the outside.
FJ has cows, and his goal is to have exactly one cow in each room. Unfortunately, the cows are currently scattered arbitrarily: room contains cows. It is guaranteed that .
FJ decides to solve this by letting some cows move clockwise through rooms to their designated positions. If a cow passes through doors, it expends energy. You need to compute the minimal possible total energy expended by all cows.
Input Format
The first line contains an integer . The next lines each contain one integer , where the -th line contains .
Output Format
Output the minimal total energy expended by all cows.
10
1
0
0
2
0
0
1
2
2
2
33
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号