AIM Tech Round (Div. 2)
D
Array GCD
Codeforces
未评级
原题
← CE →
翻译中…

You are given array $*a*_{*i*}$ of length $*n*$. You may consecutively apply two operations to this array:

翻译中…
  • remove some subsegment (continuous subsequence) of length $*m* < *n*$ and pay for it $*m*·*a*$ coins;
  • change some elements of the array by at most $1$, and pay $*b*$ coins for each change.
翻译中…

Please note that each of operations may be applied at most once (and may be not applied at all) so you can remove only one segment and each number may be changed (increased or decreased) by at most $1$. Also note, that you are not allowed to delete the whole array.

翻译中…

Your goal is to calculate the minimum number of coins that you need to spend in order to make the greatest common divisor of the elements of the resulting array be greater than $1$.

翻译中…

Input

翻译中…

The first line of the input contains integers $*n*$, $*a*$ and $*b*$ ($1 ≤ *n* ≤ 1 000 000, 0 ≤ *a*, *b* ≤ 10^{9}$) — the length of the array, the cost of removing a single element in the first operation and the cost of changing an element, respectively.

翻译中…

The second line contains $*n*$ integers $*a*_{*i*}$ ($2 ≤ *a*_{*i*} ≤ 10^{9}$) — elements of the array.

翻译中…

Output

翻译中…

Print a single number — the minimum cost of changes needed to obtain an array, such that the greatest common divisor of all its elements is greater than $1$.

翻译中…

Note

翻译中…

In the first sample the optimal way is to remove number $3$ and pay $1$ coin for it.

翻译中…

In the second sample you need to remove a segment $[17, 13]$ and then decrease number $6$. The cost of these changes is equal to $2·3 + 2 = 8$ coins.

翻译中…

样例

Input #1
3 1 4
4 2 3
Output #1
1
InputCopy OutputCopy
Input #2
5 3 2
5 17 13 5 6
Output #2
8
InputCopy OutputCopy
Input #3
8 3 4
3 7 5 4 3 12 9 4
Output #3
13
InputCopy OutputCopy
题目信息
题号
624D
时间限制
3 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。