CF623B.Array GCD

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given array aia_{i} of length nn . You may consecutively apply two operations to this array:

  • remove some subsegment (continuous subsequence) of length m<nm<n and pay for it mam·a coins;
  • change some elements of the array by at most 11 , and pay bb 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 11 . 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 11 .

输入格式

The first line of the input contains integers nn , aa and bb ( 1<=n<=1000000,0<=a,b<=1091<=n<=1000000,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 nn integers aia_{i} ( 2<=ai<=1092<=a_{i}<=10^{9} ) — elements of the array.

输出格式

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 11 .

输入输出样例

  • 输入#1

    3 1 4
    4 2 3
    

    输出#1

    1
    
  • 输入#2

    5 3 2
    5 17 13 5 6
    

    输出#2

    8
    
  • 输入#3

    8 3 4
    3 7 5 4 3 12 9 4
    

    输出#3

    13
    

说明/提示

In the first sample the optimal way is to remove number 33 and pay 11 coin for it.

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

首页