/* In the name of God */
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <bitset>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <map>
#include <numeric>
#include <limits>
#include <limits.h>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#include <random>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
#define PB push_back
#define POP pop_back
#define MP make_pair
#define all(a) (a).begin(), (a).end()
#define endl '\n'
#define dbg(x) cerr << '[' << #x << ": " << x << "]\n"
#define dbg2(x, y) cerr << '[' << #x << ": " << x << ", " << #y << ": " << y << "]\n"
#define Yes cout << "Yes\n"
#define YES cout << "YES\n"
#define No cout << "No\n"
#define NO cout << "NO\n"
const ll INF = (ll)2e18 + 1386;
const ld EPS = 0.000000000000001;
const int MOD = 1e9 + 7;
inline int mod_add(int a, int b){ int res = a + b; return (res >= MOD? res - MOD : res); }
inline int mod_neg(int a, int b){ int res = (abs(a - b) < MOD? a - b : (a - b) % MOD); return (res < 0? res + MOD : res); }
inline int mod_mlt(int a, int b){ return (1ll * a * b % MOD); }
inline string intToString(ll a){ char x[100]; sprintf(x, "%lld", a); string s = x; return s; }
inline ll stringToInt(string s){ ll res; char x[100]; strcpy(x, s.c_str()); sscanf(x, "%lld", &res); return res; }
inline void fileIO(string i, string o){ freopen(i.c_str(), "r", stdin); freopen(o.c_str(), "w", stdout); }
const int MAXN = 1e6 + 16;
int n, A, B, a[MAXN];
ll dp[MAXN][3];
void init(){
for (int i = 1; i <= n; i++){
dp[i][0] = dp[i][1] = dp[i][2] = INF;
}
}
VI primes(int x){
int tmp = x;
VI res;
for (int i = 2; i * i <= x; i++){
if (tmp % i == 0){
while (tmp % i == 0) tmp /= i;
res.PB(i);
}
}
if (tmp > 1) res.PB(tmp);
return res;
}
bool check(int x, int p){
return ((x - 1) % p == 0 || x % p == 0 || (x + 1) % p == 0);
}
ll ansfor(int p){
dp[1][0] = 0;
if (a[1] % p) dp[1][0] = B;
for (int i = 2; i <= n; i++){
bool ck = check(a[i], p);
if (ck) dp[i][0] = min(dp[i][0], dp[i - 1][0] + B * (a[i] % p != 0)); // oops! was boolean :(
dp[i][1] = min(dp[i][1], min(dp[i - 1][0], dp[i - 1][1]) + A);
if (ck) dp[i][2] = min(dp[i][2], min(dp[i - 1][1], dp[i - 1][2]) + B * (a[i] % p != 0));
}
return min({dp[n][0], dp[n][1], dp[n][2]});
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> A >> B;
for (int i = 1; i <= n; i++){
cin >> a[i];
}
ll ans = INF;
for (int it = 0; it < 2; it++){
for (int delta = -1; delta <= 1; delta++){
for (int p : primes(a[1] + delta)){
init();
ans = min(ans, ansfor(p));
}
}
reverse(a + 1, a + n + 1);
}
cout << ans;
return 0;
}
952A - Quirky Quantifiers | 451B - Sort the Array |
1505H - L BREAK into program | 171E - MYSTERIOUS LANGUAGE |
630D - Hexagons | 1690D - Black and White Stripe |
1688D - The Enchanted Forest | 1674C - Infinite Replacement |
712A - Memory and Crow | 1676C - Most Similar Words |
1681A - Game with Cards | 151C - Win or Freeze |
1585A - Life of a Flower | 1662A - Organizing SWERC |
466C - Number of Ways | 1146A - Love "A" |
1618D - Array and Operations | 1255A - Changing Volume |
1710C - XOR Triangle | 415C - Mashmokh and Numbers |
8A - Train and Peter | 591A - Wizards' Duel |
1703G - Good Key Bad Key | 1705A - Mark the Photographer |
1707A - Doremy's IQ | 1706B - Making Towers |
1325B - CopyCopyCopyCopyCopy | 1649C - Weird Sum |
1324B - Yet Another Palindrome Problem | 525A - Vitaliy and Pie |