Array GCD

Delete one contiguous block and change at most one element by 1 each, so the remaining array has gcd greater than 1, at minimum cost.

Hard8Number theoryGreedyDynamic programmingImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

You are given an array of NN integers a1,a2,,aNa_1, a_2, \dots, a_N. You can apply two kinds of operations to this array.

  1. Delete a contiguous block of length mm from the array.
  2. Add 1 to a number aia_i in the array, or subtract 1 from it.

Operation 1 can be used at most once in total, and operation 2 can be used at most once on each number. When you use operation 1, 1m<N1 \le m < N must hold, so you cannot delete the whole array.

Operation 1 costs m×Am \times A, and each use of operation 2 costs BB. After every operation is done, the greatest common divisor of the remaining array has to be greater than 1. Write a program that finds the minimum cost needed for this.

Input

The first line contains NN, AA, and BB. (1N10000001 \le N \le 1\,000\,000, 1A,B1091 \le A, B \le 10^9)

The second line contains the numbers in the array, a1,a2,,aNa_1, a_2, \dots, a_N. (2ai1092 \le a_i \le 10^9)

Output

Print the minimum cost that makes the greatest common divisor of the array greater than 1 on the first line.

Hint

In the first example, deleting the third number with operation 1 gives the minimum cost.

In the second example, deleting the second number through the third number with operation 1 and then lowering the fifth number by 1 with operation 2 gives the minimum cost.