

Time Limit: 3 sec / Memory Limit: 1024 MB
配点 : 点
問題文
半径で切って 等分された円形のケーキがあります。
各ピースには時計回りに の番号が付けられています。また、 なる整数 についてピース をピース とも呼ぶこととします。
はじめ、すべてのピースの色は色 です。
あなたは、以下の操作を好きな回数行うことができます。
- なる整数 を選ぶ。 なる各整数 に対してピース の色を色 に変更する。この操作にはコストが かかる。
なるすべての整数 に対してピース の色を色 にするために必要なコストの合計の最小値を求めてください。
制約
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
出力
答えを出力せよ。
入力例 1Copy
6 1 4 2 1 2 5 1 2 3 4 5 6
出力例 1Copy
20
ピース の色が色 であるとします。はじめ、 です。
として操作を行うと となります。
として操作を行うと となります。
として操作を行うと となります。
として操作を行うと となります。
として操作を行うと となります。
このとき、コストの合計は となります。
入力例 2Copy
5 1 2 3 4 5 1000000000 1000000000 1000000000 1000000000 1000000000
出力例 2Copy
5000000005
入力例 3Copy
8 2 3 3 1 2 1 3 1 3 4 1 2 5 3 1 2
出力例 3Copy
23
Score : points
Problem Statement
There is a circular cake that has been cut into equal slices by its radii.
Each piece is labeled with an integer from to in clockwise order, and for each integer with , the piece is also referred to as piece .
Initially, every piece’s color is color .
You can perform the following operation any number of times:
- Choose integers , , and such that . For each integer with , change the color of piece to color . The cost of this operation is .
You want each piece (for ) to have color . Find the minimum total cost of operations needed to achieve this.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1Copy
6 1 4 2 1 2 5 1 2 3 4 5 6
Sample Output 1Copy
20
Let denote the color of piece . Initially, .
Performing an operation with changes to .
Performing an operation with changes to .
Performing an operation with changes to .
Performing an operation with changes to .
Performing an operation with changes to .
In this case, the total cost is .
Sample Input 2Copy
5 1 2 3 4 5 1000000000 1000000000 1000000000 1000000000 1000000000
Sample Output 2Copy
5000000005
Sample Input 3Copy
8 2 3 3 1 2 1 3 1 3 4 1 2 5 3 1 2
Sample Output 3Copy
23