P24940 [AtCoder] [ARC020B] Stripe Pattern
普及
题目描述

Problem Description

Takahashi, a primary school student, loves stripe patterns very much. Currently, he is looking at $n$ colored art paper sheets arranged in a straight line from left to right. Since Takahashi loves stripe patterns so much, he wants to repaint some of the paper sheets with new colors to make the entire arrangement look like a stripe pattern.

A stripe pattern is defined as using exactly two colors and having every paper sheet be a different color from its adjacent paper sheets.

Your task is to write a program that, given the number of paper sheets $n$ and the cost $c$ of repainting one paper sheet to a different color, outputs the minimum total cost required to achieve a stripe pattern. For convenience, each color is given as an integer from $1$ to $10$, and the available colors for repainting are also within this range.

Input Format

The input is given from the standard input in the following format:

$ n c $ $ a_1 $ $ a_2 $ : $ a_n $

  • The first line contains the integer $n\ (2\ ≦\ n\ ≦\ 100)$, representing the number of paper sheets, and the integer $c\ (1\ ≦\ c\ ≦\ 1000)$, representing the cost of repainting one paper sheet.
  • The next $n$ lines contain the colors of the already arranged paper sheets. The $i$-th line contains the integer $a_i\ (1\ ≦\ a_i\ ≦\ 10)$, representing the color of the $i$-th paper sheet from the left.

Output Format

Output the minimum total cost required to achieve a stripe pattern in one line. Ensure a newline at the end of the output.

Sample Input and Output

Sample Input #1

3 10
3
2
1

Sample Output #1

10

Sample Input #2

4 100
1
1
1
1

Sample Output #2

200

Sample Input #3

10 1000
1
2
3
4
5
6
7
8
9
10

Sample Output #3

8000

Notes/Hints

Sample Explanation 1

The colors painted are, from left to right, $3, 2, 1$. Repainting the first "3" to "1" results in $1, 2, 1$. Alternatively, repainting the third "1" to "3" results in $3, 2, 3$. Both cases achieve a stripe pattern, and each requires repainting one paper sheet, resulting in a total cost of $10$. Therefore, output $10$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 10 3 2 1
样例输出
10