#include <bits/stdc++.h>

#include <unordered_map>
using namespace std;
#define all(v)           ((v).begin()), ((v).end())
#define sz size()
#define clr(v,d)         memset(v,d,sizeof(v))
#define rep(i, v)        for(int i=0;i<(v).sz;++i)
#define lp(i, n)         for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)     for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)     for(int i=(j);i>=(int)(n);--i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define sci(a)	scanf("%d",&a)
#define scii(a, b)	scanf("%d%d",&a, &b)
#define pri(a)	printf("%d\n",a)
#define prii(a, b)	printf("%d %d\n",a, b)
#define DB1(a)          std::cout<<#a<<"="<<(a)<<endl
#define DB2(a,b)        std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<endl
#define DB3(a,b,c)      std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<endl
#define DB4(a,b,c,d)    std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<endl
#define DB5(a,b,c,d,e)  std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<endl
typedef pair<int, int> pii;
typedef long long ll;
const ll  inf = 1000000000000000000LL;
const double EPS = 1e-9;
const ll mod = 1000000007ll;
#define PI acos(-1)

const int  maxn = (int)500 + 10;
ll pr[500500], prCnt, notPrime[500500], a[1000050];

ll n, A, B;
vector<ll> p;
ll ans;

void factorize(int t){
	for (ll j = 0; j < prCnt; j++) {
		if (t <= 1 || 1LL * pr[j] * pr[j] > t) break;
		if (t % pr[j] == 0) {
			while (t % pr[j] == 0) t /= pr[j];
			p.push_back(pr[j]);
		}
	}
	if (t > 1)
		p.push_back(t);
}

vector<ll> preCost, sufCost, sufCut;

ll solve(int prime){
	preCost.resize(n + 1);	sufCost.resize(n + 1); sufCut.resize(n + 1);
	preCost[0] = 0;	sufCost[n] = 0;
	for (int i = 0; i < n; i++)
		if (a[i] % prime == 0) preCost[i + 1] = preCost[i];
		else if ((a[i] - 1) % prime == 0 || (a[i] + 1) % prime == 0) preCost[i + 1] = min(inf,preCost[i] + B);
		else preCost[i] = inf;
	for (int i = n - 1; i >= 0;i--)
		if (a[i] % prime == 0) sufCost[i] = sufCost[i + 1];
		else if ((a[i] - 1) % prime == 0 || (a[i] + 1) % prime == 0) sufCost[i] = min(inf,sufCost[i + 1] + B);
		else sufCost[i] = inf;
	for (int i = n-1; i >= 0; i--)
		sufCut[i] = min(sufCost[i], sufCut[i+1] + A);
	ll ret = inf;
	for (int i = 0; i < n; i++)
		ret = min(ret, sufCost[i] + i*ll(A));
	for (int i = 1; i <= n; i++)
		ret = min(ret, preCost[i] + (n - i)*ll(A));
	for (int i = 1; i <= n; i++)
		ret = min(ret, preCost[i] + sufCut[i]);
	return ret;
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("CF.in", "rt", stdin);
#endif
	for (ll i = 2; i < 500500; i++) if (!notPrime[i]) {
		pr[prCnt++] = i;
		for (ll j = i*i; j < 500500; j += i)
			notPrime[j] = true;
	}
	scanf("%lld%lld%lld", &n, &A, &B);
	lp(i, n) scanf("%lld",a+i);
	for (int i = -1; i <= 1; i++) factorize(a[0] + i), factorize(a[n - 1] + i);
	sort(p.begin(), p.end());
	p.erase(unique(p.begin(), p.end()), p.end());
	ll ret = inf;
	for (auto pt : p)
		ret = min(ret, solve(pt));
	printf("%lld", ret);
}


#include <bits/stdc++.h>

#include <unordered_map>
using namespace std;
#define all(v)           ((v).begin()), ((v).end())
#define sz size()
#define clr(v,d)         memset(v,d,sizeof(v))
#define rep(i, v)        for(int i=0;i<(v).sz;++i)
#define lp(i, n)         for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)     for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)     for(int i=(j);i>=(int)(n);--i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define sci(a)	scanf("%d",&a)
#define scii(a, b)	scanf("%d%d",&a, &b)
#define pri(a)	printf("%d\n",a)
#define prii(a, b)	printf("%d %d\n",a, b)
#define DB1(a)          std::cout<<#a<<"="<<(a)<<endl
#define DB2(a,b)        std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<endl
#define DB3(a,b,c)      std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<endl
#define DB4(a,b,c,d)    std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<endl
#define DB5(a,b,c,d,e)  std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<endl
typedef pair<int, int> pii;
typedef long long ll;
const ll  inf = 1000000000000000000LL;
const double EPS = 1e-9;
const ll mod = 1000000007ll;
#define PI acos(-1)

const int  maxn = (int)500 + 10;
int pr[500500], prCnt, notPrime[500500], a[1000050];

int n, A, B;
vector<int> p;
int ans;

void factorize(int t){
	for (int j = 0; j < prCnt; j++) {
		if (t <= 1 || 1LL * pr[j] * pr[j] > t) break;
		if (t % pr[j] == 0) {
			while (t % pr[j] == 0) t /= pr[j];
			p.push_back(pr[j]);
		}
	}
	if (t > 1)
		p.push_back(t);
}

vector<ll> preCost, sufCost, preCut;

ll solve(int prime){
	preCost.resize(n + 1);	sufCost.resize(n + 1); preCut.resize(n + 1);
	preCost[0] = 0;	sufCost[n] = 0;
	for (int i = 0; i < n; i++)
		if (a[i] % prime == 0) preCost[i + 1] = preCost[i];
		else if ((a[i] - 1) % prime == 0 || (a[i] + 1) % prime == 0) preCost[i + 1] = preCost[i] + B;
		else preCost[i] = inf;
	for (int i = n - 1; i >= 0;i--)
		if (a[i] % prime == 0) sufCost[i] = sufCost[i + 1];
		else if ((a[i] - 1) % prime == 0 || (a[i] + 1) % prime == 0) sufCost[i] = sufCost[i + 1] + B;
		else sufCost[i] = inf;
	for (int i = 0; i < n; i++)
		preCut[i + 1] = min(preCost[i + 1], preCut[i] + A);
	ll ret = inf;
	for (int i = 0; i < n; i++)
		ret = min(ret, sufCost[i] + i*ll(A));
	for (int i = 1; i < n; i++)
		ret = min(ret, preCost[i] + (n - i)*ll(A));
	for (int i = 1; i < n; i++)
		ret = min(ret, sufCost[i] + preCut[i]);
	return ret;
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("CF.in", "rt", stdin);
#endif
	for (ll i = 2; i < 500500; i++) if (!notPrime[i]) {
		pr[prCnt++] = i;
		for (ll j = i*i; j < 500500; j += i)
			notPrime[j] = true;
	}
	sci(n), scii(A, B);
	lp(i, n) sci(a[i]);
	for (int i = -1; i <= 1; i++) factorize(a[0] + i), factorize(a[n - 1] + i);
	sort(p.begin(), p.end());
	p.erase(unique(p.begin(), p.end()), p.end());
	ll ret = inf;
	for (auto pt : p)
		ret = min(ret, solve(pt));
	printf("%lld", ret);
}


#include <bits/stdc++.h>

#include <unordered_map>
using namespace std;
#define all(v)           ((v).begin()), ((v).end())
#define sz size()
#define clr(v,d)         memset(v,d,sizeof(v))
#define rep(i, v)        for(int i=0;i<(v).sz;++i)
#define lp(i, n)         for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)     for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)     for(int i=(j);i>=(int)(n);--i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define sci(a)	scanf("%d",&a)
#define scii(a, b)	scanf("%d%d",&a, &b)
#define pri(a)	printf("%d\n",a)
#define prii(a, b)	printf("%d %d\n",a, b)
#define DB1(a)          std::cout<<#a<<"="<<(a)<<endl
#define DB2(a,b)        std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<endl
#define DB3(a,b,c)      std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<endl
#define DB4(a,b,c,d)    std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<endl
#define DB5(a,b,c,d,e)  std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<endl
typedef pair<int, int> pii;
typedef long long ll;
const ll  inf = 1000000000000000000LL;
const double EPS = 1e-9;
const ll mod = 1000000007ll;
#define PI acos(-1)

const int  maxn = (int)500 + 10;
ll pr[500500], prCnt, notPrime[500500], a[1000050];

ll n, A, B;
vector<ll> p;
ll ans;

void factorize(int t){
	for (ll j = 0; j < prCnt; j++) {
		if (t <= 1 || 1LL * pr[j] * pr[j] > t) break;
		if (t % pr[j] == 0) {
			while (t % pr[j] == 0) t /= pr[j];
			p.push_back(pr[j]);
		}
	}
	if (t > 1)
		p.push_back(t);
}

vector<ll> preCost, sufCost, preCut;

ll solve(int prime){
	preCost.resize(n + 1);	sufCost.resize(n + 1); preCut.resize(n + 1);
	preCost[0] = 0;	sufCost[n] = 0;
	for (int i = 0; i < n; i++)
		if (a[i] % prime == 0) preCost[i + 1] = preCost[i];
		else if ((a[i] - 1) % prime == 0 || (a[i] + 1) % prime == 0) preCost[i + 1] = preCost[i] + B;
		else preCost[i] = inf;
	for (int i = n - 1; i >= 0;i--)
		if (a[i] % prime == 0) sufCost[i] = sufCost[i + 1];
		else if ((a[i] - 1) % prime == 0 || (a[i] + 1) % prime == 0) sufCost[i] = sufCost[i + 1] + B;
		else sufCost[i] = inf;
	for (int i = 0; i < n; i++)
		preCut[i + 1] = min(preCost[i + 1], preCut[i] + A);
	ll ret = inf;
	for (int i = 0; i < n; i++)
		ret = min(ret, sufCost[i] + i*ll(A));
	for (int i = 1; i < n; i++)
		ret = min(ret, preCost[i] + (n - i)*ll(A));
	for (int i = 1; i < n; i++)
		ret = min(ret, sufCost[i] + preCut[i]);
	return ret;
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("CF.in", "rt", stdin);
#endif
	for (ll i = 2; i < 500500; i++) if (!notPrime[i]) {
		pr[prCnt++] = i;
		for (ll j = i*i; j < 500500; j += i)
			notPrime[j] = true;
	}
	scanf("%lld%lld%lld", &n, &A, &B);
	lp(i, n) scanf("%lld",a+i);
	for (int i = -1; i <= 1; i++) factorize(a[0] + i), factorize(a[n - 1] + i);
	sort(p.begin(), p.end());
	p.erase(unique(p.begin(), p.end()), p.end());
	ll ret = inf;
	for (auto pt : p)
		ret = min(ret, solve(pt));
	printf("%lld", ret);
}


#include <bits/stdc++.h>

#include <unordered_map>
using namespace std;
#define all(v)           ((v).begin()), ((v).end())
#define sz size()
#define clr(v,d)         memset(v,d,sizeof(v))
#define rep(i, v)        for(int i=0;i<(v).sz;++i)
#define lp(i, n)         for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)     for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)     for(int i=(j);i>=(int)(n);--i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define sci(a)	scanf("%d",&a)
#define scii(a, b)	scanf("%d%d",&a, &b)
#define pri(a)	printf("%d\n",a)
#define prii(a, b)	printf("%d %d\n",a, b)
#define DB1(a)          std::cout<<#a<<"="<<(a)<<endl
#define DB2(a,b)        std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<endl
#define DB3(a,b,c)      std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<endl
#define DB4(a,b,c,d)    std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<endl
#define DB5(a,b,c,d,e)  std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<endl
typedef pair<int, int> pii;
typedef long long ll;
const ll  inf = 1000000000000000000LL;
const double EPS = 1e-9;
const ll mod = 1000000007ll;
#define PI acos(-1)

const int  maxn = (int)500 + 10;
ll pr[500500], prCnt, notPrime[500500], a[1000050];

ll n, A, B;
vector<ll> p;
ll ans;

void factorize(ll t){
	for (ll j = 0; j < prCnt; j++) {
		if (t <= 1 || 1LL * pr[j] * pr[j] > t) break;
		if (t % pr[j] == 0) {
			while (t % pr[j] == 0) t /= pr[j];
			p.push_back(pr[j]);
		}
	}
	if (t > 1)
		p.push_back(t);
}

vector<ll> preCost, sufCost, sufCut;

ll solve(ll prime){
	preCost.resize(n + 1);	sufCost.resize(n + 1); sufCut.resize(n + 1);
	preCost[0] = 0;	sufCost[n] = 0;
	for (int i = 0; i < n; i++)
		if (a[i] % prime == 0) preCost[i + 1] = preCost[i];
		else if ((a[i] - 1) % prime == 0 || (a[i] + 1) % prime == 0) preCost[i + 1] = min(inf,preCost[i] + B);
		else preCost[i] = inf;
	for (int i = n - 1; i >= 0;i--)
		if (a[i] % prime == 0) sufCost[i] = sufCost[i + 1];
		else if ((a[i] - 1) % prime == 0 || (a[i] + 1) % prime == 0) sufCost[i] = min(inf,sufCost[i + 1] + B);
		else sufCost[i] = inf;
	for (int i = n-1; i >= 0; i--)
		sufCut[i] = min(sufCost[i], sufCut[i+1] + A);
	ll ret = inf;
	for (int i = 0; i < n; i++)
		ret = min(ret, sufCost[i] + i*ll(A));
	for (int i = 1; i <= n; i++)
		ret = min(ret, preCost[i] + (n - i)*ll(A));
	for (int i = 1; i <= n; i++)
		ret = min(ret, preCost[i] + sufCut[i]);
	return ret;
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("CF.in", "rt", stdin);
#endif
	for (ll i = 2; i < 500500; i++) if (!notPrime[i]) {
		pr[prCnt++] = i;
		for (ll j = i*i; j < 500500; j += i)
			notPrime[j] = true;
	}
	scanf("%lld%lld%lld", &n, &A, &B);
	lp(i, n) scanf("%lld",a+i);
	for (int i = -1; i <= 1; i++) factorize(a[0] + i), factorize(a[n - 1] + i);
	sort(p.begin(), p.end());
	p.erase(unique(p.begin(), p.end()), p.end());
	ll ret = inf;
	for (auto pt : p)
		ret = min(ret, solve(pt));
	printf("%lld", ret);
}


#include <bits/stdc++.h>

#include <unordered_map>
using namespace std;
#define all(v)           ((v).begin()), ((v).end())
#define sz size()
#define clr(v,d)         memset(v,d,sizeof(v))
#define rep(i, v)        for(int i=0;i<(v).sz;++i)
#define lp(i, n)         for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)     for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)     for(int i=(j);i>=(int)(n);--i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define sci(a)	scanf("%d",&a)
#define scii(a, b)	scanf("%d%d",&a, &b)
#define pri(a)	printf("%d\n",a)
#define prii(a, b)	printf("%d %d\n",a, b)
#define DB1(a)          std::cout<<#a<<"="<<(a)<<endl
#define DB2(a,b)        std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<endl
#define DB3(a,b,c)      std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<endl
#define DB4(a,b,c,d)    std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<endl
#define DB5(a,b,c,d,e)  std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<endl
typedef pair<int, int> pii;
typedef long long ll;
const ll  inf = 1000000000000000000LL;
const double EPS = 1e-9;
const ll mod = 1000000007ll;
#define PI acos(-1)

const int  maxn = (int)500 + 10;
ll pr[500500], prCnt, notPrime[500500], a[1000050];

ll n, A, B;
vector<ll> p;
ll ans;

void factorize(int t){
	for (ll j = 0; j < prCnt; j++) {
		if (t <= 1 || 1LL * pr[j] * pr[j] > t) break;
		if (t % pr[j] == 0) {
			while (t % pr[j] == 0) t /= pr[j];
			p.push_back(pr[j]);
		}
	}
	if (t > 1)
		p.push_back(t);
}

vector<ll> preCost, sufCost, sufCut;

ll solve(int prime){
	preCost.resize(n + 1);	sufCost.resize(n + 1); sufCut.resize(n + 1);
	preCost[0] = 0;	sufCost[n] = 0;
	for (int i = 0; i < n; i++)
		if (a[i] % prime == 0) preCost[i + 1] = preCost[i];
		else if ((a[i] - 1) % prime == 0 || (a[i] + 1) % prime == 0) preCost[i + 1] = preCost[i] + B;
		else preCost[i] = inf;
	for (int i = n - 1; i >= 0;i--)
		if (a[i] % prime == 0) sufCost[i] = sufCost[i + 1];
		else if ((a[i] - 1) % prime == 0 || (a[i] + 1) % prime == 0) sufCost[i] = sufCost[i + 1] + B;
		else sufCost[i] = inf;
	for (int i = n-1; i >= 0; i--)
		sufCut[i] = min(sufCost[i], sufCut[i+1] + A);
	ll ret = inf;
	for (int i = 0; i < n; i++)
		ret = min(ret, sufCost[i] + i*ll(A));
	for (int i = 1; i < n; i++)
		ret = min(ret, preCost[i] + (n - i)*ll(A));
	for (int i = 1; i <= n; i++)
		ret = min(ret, preCost[i] + sufCut[i]);
	return ret;
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("CF.in", "rt", stdin);
#endif
	for (ll i = 2; i < 500500; i++) if (!notPrime[i]) {
		pr[prCnt++] = i;
		for (ll j = i*i; j < 500500; j += i)
			notPrime[j] = true;
	}
	scanf("%lld%lld%lld", &n, &A, &B);
	lp(i, n) scanf("%lld",a+i);
	for (int i = -1; i <= 1; i++) factorize(a[0] + i), factorize(a[n - 1] + i);
	sort(p.begin(), p.end());
	p.erase(unique(p.begin(), p.end()), p.end());
	ll ret = inf;
	for (auto pt : p)
		ret = min(ret, solve(pt));
	printf("%lld", ret);
}


#include <bits/stdc++.h>

#include <unordered_map>
using namespace std;
#define all(v)           ((v).begin()), ((v).end())
#define sz size()
#define clr(v,d)         memset(v,d,sizeof(v))
#define rep(i, v)        for(int i=0;i<(v).sz;++i)
#define lp(i, n)         for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)     for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)     for(int i=(j);i>=(int)(n);--i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define sci(a)	scanf("%d",&a)
#define scii(a, b)	scanf("%d%d",&a, &b)
#define pri(a)	printf("%d\n",a)
#define prii(a, b)	printf("%d %d\n",a, b)
#define DB1(a)          std::cout<<#a<<"="<<(a)<<endl
#define DB2(a,b)        std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<endl
#define DB3(a,b,c)      std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<endl
#define DB4(a,b,c,d)    std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<endl
#define DB5(a,b,c,d,e)  std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<endl
typedef pair<int, int> pii;
typedef long long ll;
const ll  inf = 1000000000000000000LL;
const double EPS = 1e-9;
const ll mod = 1000000007ll;
#define PI acos(-1)

const int  maxn = (int)500 + 10;
ll pr[500500], prCnt, notPrime[500500], a[1000050];

ll n, A, B;
vector<ll> p;
ll ans;

void factorize(ll t){
	for (ll j = 0; j < prCnt; j++) {
		if (t <= 1 || 1LL * pr[j] * pr[j] > t) break;
		if (t % pr[j] == 0) {
			while (t % pr[j] == 0) t /= pr[j];
			p.push_back(pr[j]);
		}
	}
	if (t > 1)
		p.push_back(t);
}

vector<ll> preCost, sufCost, sufCut;

ll solve(ll prime){
	preCost.resize(n + 1);	sufCost.resize(n + 1); sufCut.resize(n + 1);
	preCost[0] = 0;	sufCost[n] = 0;
	for (int i = 0; i < n; i++)
		if (a[i] % prime == 0) preCost[i + 1] = preCost[i];
		else if ((a[i] - 1) % prime == 0 || (a[i] + 1) % prime == 0) preCost[i + 1] = min(inf,preCost[i] + B);
		else preCost[i+1] = inf;
	for (int i = n - 1; i >= 0;i--)
		if (a[i] % prime == 0) sufCost[i] = sufCost[i + 1];
		else if ((a[i] - 1) % prime == 0 || (a[i] + 1) % prime == 0) sufCost[i] = min(inf,sufCost[i + 1] + B);
		else sufCost[i] = inf;
	for (int i = n-1; i >= 0; i--)
		sufCut[i] = min(sufCost[i], sufCut[i+1] + A);
	ll ret = inf;
	for (int i = 0; i < n; i++)
		ret = min(ret, sufCost[i] + i*ll(A));
	for (int i = 1; i <= n; i++)
		ret = min(ret, preCost[i] + (n - i)*ll(A));
	for (int i = 1; i <= n; i++)
		ret = min(ret, preCost[i] + sufCut[i]);
	return ret;
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("CF.in", "rt", stdin);
#endif
	for (ll i = 2; i < 500500; i++) if (!notPrime[i]) {
		pr[prCnt++] = i;
		for (ll j = i*i; j < 500500; j += i)
			notPrime[j] = true;
	}
	scanf("%lld%lld%lld", &n, &A, &B);
	lp(i, n) scanf("%lld",a+i);
	for (int i = -1; i <= 1; i++) factorize(a[0] + i), factorize(a[n - 1] + i);
	sort(p.begin(), p.end());
	p.erase(unique(p.begin(), p.end()), p.end());
	ll ret = inf;
	for (auto pt : p)
		ret = min(ret, solve(pt));
	printf("%lld", ret);
}


#include <bits/stdc++.h>

#include <unordered_map>
using namespace std;
#define all(v)           ((v).begin()), ((v).end())
#define sz size()
#define clr(v,d)         memset(v,d,sizeof(v))
#define rep(i, v)        for(int i=0;i<(v).sz;++i)
#define lp(i, n)         for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)     for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)     for(int i=(j);i>=(int)(n);--i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define sci(a)	scanf("%d",&a)
#define scii(a, b)	scanf("%d%d",&a, &b)
#define pri(a)	printf("%d\n",a)
#define prii(a, b)	printf("%d %d\n",a, b)
#define DB1(a)          std::cout<<#a<<"="<<(a)<<endl
#define DB2(a,b)        std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<endl
#define DB3(a,b,c)      std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<endl
#define DB4(a,b,c,d)    std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<endl
#define DB5(a,b,c,d,e)  std::cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<endl
typedef pair<int, int> pii;
typedef long long ll;
const ll  inf = 1000000000000000000LL;
const double EPS = 1e-9;
const ll mod = 1000000007ll;
#define PI acos(-1)

const int  maxn = (int)500 + 10;
ll pr[500500], prCnt, notPrime[500500], a[1000050];

ll n, A, B;
vector<ll> p;
ll ans;

void factorize(ll x)
{
	for (ll i = 2; i*i <= x; i++) {
		if (x%i == 0) {
			p.push_back(i);
			while (x%i == 0)
				x /= i;
		}
	}
	if (x != 1)
		p.push_back(x);
}
vector<ll> preCost, sufCost, sufCut;

ll solve(int prime){
	preCost.resize(n + 1);	sufCost.resize(n + 1); sufCut.resize(n + 1);
	preCost[0] = 0;	sufCost[n] = 0;
	for (int i = 0; i < n; i++)
		if (a[i] % prime == 0) preCost[i + 1] = preCost[i];
		else if ((a[i] - 1) % prime == 0 || (a[i] + 1) % prime == 0) preCost[i + 1] = min(inf,preCost[i] + B);
		else preCost[i] = inf;
	for (int i = n - 1; i >= 0;i--)
		if (a[i] % prime == 0) sufCost[i] = sufCost[i + 1];
		else if ((a[i] - 1) % prime == 0 || (a[i] + 1) % prime == 0) sufCost[i] = min(inf,sufCost[i + 1] + B);
		else sufCost[i] = inf;
	for (int i = n-1; i >= 0; i--)
		sufCut[i] = min(sufCost[i], sufCut[i+1] + A);
	ll ret = inf;
	for (int i = 0; i < n; i++)
		ret = min(ret, sufCost[i] + i*ll(A));
	for (int i = 1; i <= n; i++)
		ret = min(ret, preCost[i] + (n - i)*ll(A));
	for (int i = 1; i <= n; i++)
		ret = min(ret, preCost[i] + sufCut[i]);
	return ret;
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("CF.in", "rt", stdin);
#endif
	for (ll i = 2; i < 500500; i++) if (!notPrime[i]) {
		pr[prCnt++] = i;
		for (ll j = i*i; j < 500500; j += i)
			notPrime[j] = true;
	}
	scanf("%lld%lld%lld", &n, &A, &B);
	lp(i, n) scanf("%lld",a+i);
	for (int i = -1; i <= 1; i++) factorize(a[0] + i), factorize(a[n - 1] + i);
	sort(p.begin(), p.end());
	p.erase(unique(p.begin(), p.end()), p.end());
	ll ret = inf;
	for (auto pt : p)
		ret = min(ret, solve(pt));
	printf("%lld", ret);
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int n, *x;
ll a,b;

ll solve(int d){
    int* type = new int[n];
    vector<int> pos;
    for(int i=0; i<n; i++){
        if (x[i]%d==0)
            type[i] = 0;
        else if ((x[i]-1)%d==0 || (x[i]+1)%d==0 )
            type[i] = 1;
        else
            type[i] = 2;
        if (type[i]>0)
            pos.push_back(i);
    }
    if (pos.empty())
        return 0;

    if (pos.size()==1){
        if (type[pos[0]]==1)
            return min(a,b);
        else
            return a;
    }

    ll dd = 0, dl = 0;
    bool good = 1;
    vector<ll> left; left.resize(pos.size());
    for(int i=0; i<pos.size()-1; i++){
        if (type[pos[i]]==2)
            good = 0;
        if (type[pos[i]] == 1 && good)
            dd += -(pos[i+1]-pos[i])*a + b;
        dl = min(dl, dd);
        left[i] = dl;
    }
    if (type[pos.back()] == 1 && good)
    {
        dd += -a + b;
        dl = min(dl, dd);
        left[pos.size()-1] = dl;
    }

    dd = 0;
    ll dr = 0; good = 1;
    vector<ll> right; right.resize(pos.size());
    for(int i=pos.size()-1; i>0; i--){
        if (type[pos[i]] == 2)
            good = 0;
        if (type[pos[i]] == 1 && good)
            dd += -(pos[i]-pos[i-1])*a + b;
        dr = min(dr, dd);
        right[i] = dr;
    }
    if (type[pos[0]] == 1 && good)
    {
        dd += -a + b;
        dr = min(dr, dd);
        right[0] = dr;
    }

    ll cost = (pos.back()-pos[0]+1)*a;
    dd = right[1];
    //right[0] should be == left[pos.size()-1]
    right.push_back(0); right.push_back(0);
    for(int i=0; i<pos.size(); i++)
        dd = min(dd, left[i] + right[i+2]);
    cost += dd;
    //cost = min( cost , pos.size()*b);
    return cost;
}
int main(){
    //freopen("d:\\src\\CppProjects\\stdin","r",stdin);
    scanf("%d%I64d%I64d",&n,&a,&b);
    x = new int[n];
    for(int i=0; i<n; i++)
        scanf("%d",x+i);

    int y[6] = {x[0], x[0]-1, x[0]+1, x[n-1], x[n-1]-1, x[n-1]+1};
    sort(y, y+6);
    set<int> primes;
    for(int d = 2; d*d<= y[5]; d++){
        for(int i=0; i<6; i++)
            while (y[i]%d==0)
            {
                y[i]/=d;
                primes.insert(d);
            }
    }
    for(int i=0; i<6; i++)
        if (y[i]>1)
            primes.insert(y[i]);

    ll ssol = max(n*b,n*a)+10;
    for(int p : primes)
        ssol = min(ssol, solve(p));
    printf("%I64d",ssol);
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int n, *x;
ll a,b;

ll solve(int d){
    int* type = new int[n];
    vector<int> pos;
    for(int i=0; i<n; i++){
        if (x[i]%d==0)
            type[i] = 0;
        else if ((x[i]-1)%d==0 || (x[i]+1)%d==0 )
            type[i] = 1;
        else
            type[i] = 2;
        if (type[i]>0)
            pos.push_back(i);
    }
    if (pos.empty())
        return 0;

    if (pos.size()==1){
        if (type[pos[0]]==1)
            return min(a,b);
        else
            return a;
    }

    ll dd = 0, dl = 0;
    bool good = 1;
    vector<ll> left; left.resize(pos.size());
    for(int i=0; i<pos.size()-1; i++){
        if (type[pos[i]]==2)
            good = 0;
        if (type[pos[i]] == 1 && good)
            dd += -(pos[i+1]-pos[i])*a + b;
        dl = min(dl, dd);
        left[i] = dl;
    }
    if (type[pos.back()] == 1 && good)
    {
        dd += -a + b;
        dl = min(dl, dd);
        left[pos.size()-1] = dl;
    }

    dd = 0;
    ll dr = 0; good = 1;
    vector<ll> right; right.resize(pos.size());
    for(int i=pos.size()-1; i>0; i--){
        if (type[pos[i]] == 2)
            good = 0;
        if (type[pos[i]] == 1 && good)
            dd += -(pos[i]-pos[i-1])*a + b;
        dr = min(dr, dd);
        right[i] = dr;
    }
    if (type[pos[0]] == 1 && good)
    {
        dd += -a + b;
        dr = min(dr, dd);
        right[0] = dr;
    }

    ll cost = (pos.back()-pos[0]+1)*a;
    dd = min(right[1],left[pos.size()-1]);
    dd = min(dd, left[pos.size()-2]);
    //right[0] should be == left[pos.size()-1]
    for(int i=0; i<pos.size()-2; i++)
        dd = min(dd, left[i] + right[i+2]);
    cost += dd;
    //cost = min( cost , pos.size()*b);
    return cost;
}
int main(){
    //freopen("d:\\src\\CppProjects\\stdin","r",stdin);
    scanf("%d%I64d%I64d",&n,&a,&b);
    x = new int[n];
    for(int i=0; i<n; i++)
        scanf("%d",x+i);

    int y[6] = {x[0], x[0]-1, x[0]+1, x[n-1], x[n-1]-1, x[n-1]+1};
    sort(y, y+6);
    set<int> primes;
    for(int d = 2; d*d<= y[5]; d++){
        for(int i=0; i<6; i++)
            while (y[i]%d==0)
            {
                y[i]/=d;
                primes.insert(d);
            }
    }
    for(int i=0; i<6; i++)
        if (y[i]>1)
            primes.insert(y[i]);

    ll ssol = max(n*b,n*a)+10;
    for(int p : primes)
        ssol = min(ssol, solve(p));
    printf("%I64d",ssol);
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int n, *x;
ll a,b;

ll solve(int d){
    char* type = new char[n];
    vector<int> pos;
    for(int i=0; i<n; i++){
        if (x[i]%d==0)
            type[i] = 0;
        else if ((x[i]-1)%d==0 || (x[i]+1)%d==0 )
            type[i] = 1;
        else
            type[i] = 2;
        if (type[i]>0)
            pos.push_back(i);
    }
    if (pos.empty())
        return 0;

    if (pos.size()==1){
        if (type[pos[0]]==1)
            return min(a,b);
        else
            return a;
    }

    ll dd = 0, dl = 0;
    bool good = 1;
    vector<ll> left; left.resize(pos.size());
    for(int i=0; i<pos.size()-1; i++){
        if (type[pos[i]]==2)
            good = 0;
        if (type[pos[i]] == 1 && good)
            dd += -(pos[i+1]-pos[i])*a + b;
        dl = min(dl, dd);
        left[i] = dl;
    }
    if (type[pos.back()] == 1 && good)
    {
        dd += -a + b;
        dl = min(dl, dd);
        left[pos.size()-1] = dl;
    }

    dd = 0;
    ll dr = 0; good = 1;
    vector<ll> right; right.resize(pos.size());
    for(int i=pos.size()-1; i>0; i--){
        if (type[pos[i]] == 2)
            good = 0;
        if (type[pos[i]] == 1 && good)
            dd += -(pos[i]-pos[i-1])*a + b;
        dr = min(dr, dd);
        right[i] = dr;
    }
    if (type[pos[0]] == 1 && good)
    {
        dd += -a + b;
        dr = min(dr, dd);
        right[0] = dr;
    }

    ll cost = (pos.back()-pos[0]+1)*a;
    dd = min(0ll,right[1]);
    //right[0] should be == left[pos.size()-1]
    right.push_back(0); right.push_back(0);
    for(int i=0; i<pos.size(); i++)
        dd = min(dd, left[i] + right[i+2]);
    cost += dd;
    //cost = min( cost , pos.size()*b);
    delete[] type;
    return cost;
}
int main(){
    //freopen("d:\\src\\CppProjects\\stdin","r",stdin);
    scanf("%d%I64d%I64d",&n,&a,&b);
    x = new int[n];
    for(int i=0; i<n; i++)
        scanf("%d",x+i);

    int y[6] = {x[0], x[0]-1, x[0]+1, x[n-1], x[n-1]-1, x[n-1]+1};
    sort(y, y+6);
    set<int> primes;
    for(int d = 2; d*d<= y[5]; d++){ //O(sqrt(max(y))
        for(int i=0; i<6; i++)
            while (y[i]%d==0)
            {
                y[i]/=d;
                primes.insert(d);
            }
    }
    for(int i=0; i<6; i++)
        if (y[i]>1)
            primes.insert(y[i]);

    ll ssol = max(n*b,n*a)+10;
    for(int p : primes)
        ssol = min(ssol, solve(p));
    printf("%I64d",ssol);
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int n, *x;
ll a,b;

ll solve(int d){
    int* type = new int[n];
    vector<int> pos;
    for(int i=0; i<n; i++){
        if (x[i]%d==0)
            type[i] = 0;
        else if ((x[i]-1)%d==0 || (x[i]+1)%d==0 )
            type[i] = 1;
        else
            type[i] = 2;
        if (type[i]>0)
            pos.push_back(i);
    }
    if (pos.empty())
        return 0;

    ll dd = 0;
    ll dl = 0; int posl = 0;
    for(int i=0; i<pos.size()-1; i++){
        if (type[pos[i]] == 2) break;
        dd += -(pos[i+1]-pos[i])*a + b;
        if (dd<dl){
            dl = dd;
            posl = i;
        }
    }
    if (type[pos.back()] == 1)
    {
        dd += -a + b;
        if (dd<dl){
            dl = dd;
            posl = pos.size()-1;
        }
    }

    dd = 0;
    ll dr = 0; int posr = pos.size()-1;
    for(int i=pos.size()-1; i>0; i--){
        if (type[pos[i]] == 2) break;
        dd += -(pos[i]-pos[i-1])*a + b;
        if (dd<dr){
            dr = dd;
            posr = i;
        }
    }
    if (type[pos[0]] == 1)
    {
        dd += -a + b;
        if (dd<dr){
            dr = dd;
            posr = 0;
        }
    }

    ll cost = (pos.back()-pos[0]+1)*a;
    if (posr>posl+1)
        cost += dl + dr;
    else
        cost += min(dl, dr);
    //cost = min( cost , pos.size()*b);
    return cost;
}
int main(){
    //freopen("d:\\src\\CppProjects\\stdin","r",stdin);
    scanf("%d%I64d%I64d",&n,&a,&b);
    x = new int[n];
    for(int i=0; i<n; i++)
        scanf("%d",x+i);

    int y[6] = {x[0], x[0]-1, x[0]+1, x[n-1], x[n-1]-1, x[n-1]+1};
    sort(y, y+6);
    set<int> primes;
    for(int d = 2; d*d<= y[5]; d++){
        for(int i=0; i<6; i++)
            while (y[i]%d==0)
            {
                y[i]/=d;
                primes.insert(d);
            }
    }
    for(int i=0; i<6; i++)
        if (y[i]>1)
            primes.insert(y[i]);

    ll ssol = max(n*b,n*a)+10;
    for(int p : primes)
        ssol = min(ssol, solve(p));
    printf("%I64d",ssol);
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

template <class T> T sqr(T x) { return x*x; }

int gcd(int a, int b){
    if (b==0)
        return 0;
    int r = a%b;
    while(r){
        a = b;
        b = r;
        r = a%b;
    }
    return b;
}

bool valid[7][7];

int main(){
	//freopen("d:\\src\\CppProjects\\stdin","r",stdin);
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	int *x = new int[n+1];
	for(int i=1; i<=n; i++)
        scanf("%d",x+i);

    ll** dp = new ll *[n+1];
    for(int i=0;i<=n; i++)
        dp[i] = new ll [7];
    for(int i=0; i<1; i++)
        dp[0][i] = 0;

    int** gcds = new int *[n+1];
    for(int i=0;i<=n; i++)
        gcds[i] = new int [7];

    //before delete:
    //0 unchanged, 1 add one, 2 subtr one,
    //inside
    //3 delete,
    //after delete:
    //4 unchanged, 5 add one, 6 subtr one

    for(int i=0; i<7; i++)
        gcds[0][i] = 0;

    int cost[7] = { 0, b, b, a, 0, b, b};
    int mod[7] = { 0, 1, -1, 0, 0, 1, -1};
    const ll INF = max((ll)n*a, (ll)n*b)+10;

    for(int j=0; j<4; j++){
        valid[0][j] = 1;
        valid[1][j] = 1;
        valid[2][j] = 1;
    }
    for(int j=3; j<7; j++){
        valid[3][j] = 1;
    }
    for(int j=4; j<7; j++){
        valid[4][j] = 1;
        valid[5][j] = 1;
        valid[6][j] = 1;
    }

    const int K = 7; //states
    int d;
    for(int i=1; i<=n; i++){
        for(int k=0; k<K; k++)
            dp[i][k] = INF;
        for(int j=0; j<K; j++)
        {
            for(int k=0; k<K; k++){

                if (i==6 && k==4 && j==4){
                    int x = 1<<32;
                }
                if (valid[j][k]){
                    if (k==3)
                        d = gcds[i-1][j];
                    else
                        d = gcd(gcds[i-1][j], x[i]+mod[k]);
                    if (d!=1){
                        if (dp[i-1][j]+cost[k] < dp[i][k]){
                            gcds[i][k] = d;
                            dp[i][k] = dp[i-1][j]+cost[k];
                            printf("%d %d = %I64d\n", i, k, dp[i][k]);
                            //int x = 1<<10;
                        }
                    }
                }
            }
        }
    }

    //printf("\n");
    ll ssol = INF;
    for(int i=0; i<K; i++){
        ssol = min(ssol, dp[n][i]);
        //printf("%d %d = %d\n", n, i, dp[n][i]);
    }
    printf("%I64d",ssol);

	return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int n, *x;
ll a,b;

ll solve(int d){
    int* type = new int[n];
    vector<int> pos;
    for(int i=0; i<n; i++){
        if (x[i]%d==0)
            type[i] = 0;
        else if ((x[i]-1)%d==0 || (x[i]+1)%d==0 )
            type[i] = 1;
        else
            type[i] = 2;
        if (type[i]>0)
            pos.push_back(i);
    }
    if (pos.empty())
        return 0;

    if (pos.size()==1){
        if (type[pos[0]]==1)
            return min(a,b);
        else
            return a;
    }

    ll dd = 0, dl = 0;
    bool good = 1;
    vector<ll> left; left.resize(pos.size());
    for(int i=0; i<pos.size()-1; i++){
        if (type[pos[i]]==2)
            good = 0;
        if (type[pos[i]] == 1 && good)
            dd += -(pos[i+1]-pos[i])*a + b;
        dl = min(dl, dd);
        left[i] = dl;
    }
    if (type[pos.back()] == 1 && good)
    {
        dd += -a + b;
        dl = min(dl, dd);
        left[pos.size()-1] = dl;
    }

    dd = 0;
    ll dr = 0; good = 1;
    vector<ll> right; right.resize(pos.size());
    for(int i=pos.size()-1; i>0; i--){
        if (type[pos[i]] == 2)
            good = 0;
        if (type[pos[i]] == 1 && good)
            dd += -(pos[i]-pos[i-1])*a + b;
        dr = min(dr, dd);
        right[i] = dr;
    }
    if (type[pos[0]] == 1 && good)
    {
        dd += -a + b;
        dr = min(dr, dd);
        right[0] = dr;
    }

    ll cost = (pos.back()-pos[0]+1)*a;
    dd = min(right[1],left[pos.size()-1]);
    dd = min(dd, left[pos.size()-2]);
    //right[0] should be == left[pos.size()-1]
    for(int i=0; i<pos.size()-2; i++)
        dd = min(dd, left[i] + right[i+1]);
    cost += dd;
    //cost = min( cost , pos.size()*b);
    return cost;
}
int main(){
    //freopen("d:\\src\\CppProjects\\stdin","r",stdin);
    scanf("%d%I64d%I64d",&n,&a,&b);
    x = new int[n];
    for(int i=0; i<n; i++)
        scanf("%d",x+i);

    int y[6] = {x[0], x[0]-1, x[0]+1, x[n-1], x[n-1]-1, x[n-1]+1};
    sort(y, y+6);
    set<int> primes;
    for(int d = 2; d*d<= y[5]; d++){
        for(int i=0; i<6; i++)
            while (y[i]%d==0)
            {
                y[i]/=d;
                primes.insert(d);
            }
    }
    for(int i=0; i<6; i++)
        if (y[i]>1)
            primes.insert(y[i]);

    ll ssol = max(n*b,n*a)+10;
    for(int p : primes)
        ssol = min(ssol, solve(p));
    printf("%I64d",ssol);
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int n, *x;
ll a,b;

ll solve(int d){
    int* type = new int[n];
    vector<int> pos;
    for(int i=0; i<n; i++){
        if (x[i]%d==0)
            type[i] = 0;
        else if ((x[i]-1)%d==0 || (x[i]+1)%d==0 )
            type[i] = 1;
        else
            type[i] = 2;
        if (type[i]>0)
            pos.push_back(i);
    }
    if (pos.empty())
        return 0;

    if (pos.size()==1){
        if (type[pos[0]]==1)
            return min(a,b);
        else
            return a;
    }

    ll dd = 0, dl = 0;
    bool good = 1;
    vector<int> left; left.resize(pos.size());
    for(int i=0; i<pos.size()-1; i++){
        if (type[pos[i]]==2)
            good = 0;
        if (type[pos[i]] == 1 && good)
            dd += -(pos[i+1]-pos[i])*a + b;
        dl = min(dl, dd);
        left[i] = dl;
    }
    if (type[pos.back()] == 1 && good)
    {
        dd += -a + b;
        dl = min(dl, dd);
        left[pos.size()-1] = dl;
    }

    dd = 0;
    ll dr = 0; good = 1;
    vector<int> right; right.resize(pos.size());
    for(int i=pos.size()-1; i>0; i--){
        if (type[pos[i]] == 2)
            good = 0;
        if (type[pos[i]] == 1 && good)
            dd += -(pos[i]-pos[i-1])*a + b;
        dr = min(dr, dd);
        right[i] = dr;
    }
    if (type[pos[0]] == 1 && good)
    {
        dd += -a + b;
        dr = min(dr, dd);
        right[0] = dr;
    }

    ll cost = (pos.back()-pos[0]+1)*a;
    dd = min(right[1],left[pos.size()-1]);
    for(int i=0; i<pos.size()-2; i++)
        dd = min(dd, (ll)left[i] + right[i+2]);
    cost += dd;
    //cost = min( cost , pos.size()*b);
    return cost;
}
int main(){
    //freopen("d:\\src\\CppProjects\\stdin","r",stdin);
    scanf("%d%I64d%I64d",&n,&a,&b);
    x = new int[n];
    for(int i=0; i<n; i++)
        scanf("%d",x+i);

    int y[6] = {x[0], x[0]-1, x[0]+1, x[n-1], x[n-1]-1, x[n-1]+1};
    sort(y, y+6);
    set<int> primes;
    for(int d = 2; d*d<= y[5]; d++){
        for(int i=0; i<6; i++)
            while (y[i]%d==0)
            {
                y[i]/=d;
                primes.insert(d);
            }
    }
    for(int i=0; i<6; i++)
        if (y[i]>1)
            primes.insert(y[i]);

    ll ssol = max(n*b,n*a)+10;
    for(int p : primes)
        ssol = min(ssol, solve(p));
    printf("%I64d",ssol);
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int n, *x;
ll a,b;

ll solve(int d){
    int* type = new int[n];
    vector<int> pos;
    for(int i=0; i<n; i++){
        if (x[i]%d==0)
            type[i] = 0;
        else if ((x[i]-1)%d==0 || (x[i]+1)%d==0 )
            type[i] = 1;
        else
            type[i] = 2;
        if (type[i]>0)
            pos.push_back(i);
    }
    if (pos.empty())
        return 0;

    if (pos.size()==1){
        if (type[pos[0]]==1)
            return min(a,b);
        else
            return a;
    }

    ll dd = 0, dl = 0;
    bool good = 1;
    vector<ll> left; left.resize(pos.size());
    for(int i=0; i<pos.size()-1; i++){
        if (type[pos[i]]==2)
            good = 0;
        if (type[pos[i]] == 1 && good)
            dd += -(pos[i+1]-pos[i])*a + b;
        dl = min(dl, dd);
        left[i] = dl;
    }
    if (type[pos.back()] == 1 && good)
    {
        dd += -a + b;
        dl = min(dl, dd);
        left[pos.size()-1] = dl;
    }

    dd = 0;
    ll dr = 0; good = 1;
    vector<ll> right; right.resize(pos.size());
    for(int i=pos.size()-1; i>0; i--){
        if (type[pos[i]] == 2)
            good = 0;
        if (type[pos[i]] == 1 && good)
            dd += -(pos[i]-pos[i-1])*a + b;
        dr = min(dr, dd);
        right[i] = dr;
    }
    if (type[pos[0]] == 1 && good)
    {
        dd += -a + b;
        dr = min(dr, dd);
        right[0] = dr;
    }

    ll cost = (pos.back()-pos[0]+1)*a;
    dd = min(right[1],left[pos.size()-1]);
    for(int i=0; i<pos.size()-2; i++)
        dd = min(dd, left[i] + right[i+2]);
    cost += dd;
    //cost = min( cost , pos.size()*b);
    return cost;
}
int main(){
    //freopen("d:\\src\\CppProjects\\stdin","r",stdin);
    scanf("%d%I64d%I64d",&n,&a,&b);
    x = new int[n];
    for(int i=0; i<n; i++)
        scanf("%d",x+i);

    int y[6] = {x[0], x[0]-1, x[0]+1, x[n-1], x[n-1]-1, x[n-1]+1};
    sort(y, y+6);
    set<int> primes;
    for(int d = 2; d*d<= y[5]; d++){
        for(int i=0; i<6; i++)
            while (y[i]%d==0)
            {
                y[i]/=d;
                primes.insert(d);
            }
    }
    for(int i=0; i<6; i++)
        if (y[i]>1)
            primes.insert(y[i]);

    ll ssol = max(n*b,n*a)+10;
    for(int p : primes)
        ssol = min(ssol, solve(p));
    printf("%I64d",ssol);
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int n, *x;
ll a,b;

ll solve(int d){
    int* type = new int[n];
    vector<int> pos;
    for(int i=0; i<n; i++){
        if (x[i]%d==0)
            type[i] = 0;
        else if ((x[i]-1)%d==0 || (x[i]+1)%d==0 )
            type[i] = 1;
        else
            type[i] = 2;
        if (type[i]>0)
            pos.push_back(i);
    }
    if (pos.empty())
        return 0;

    if (pos.size()==1){
        if (type[pos[0]]==1)
            return min(a,b);
        else
            return a;
    }

    ll dd = 0, dl = 0;
    vector<int> left;
    for(int i=0; i<pos.size()-1; i++){
        if (type[pos[i]] == 1)
            dd += -(pos[i+1]-pos[i])*a + b;
        dl = min(dl, dd);
        left.push_back(dl);
    }
    if (type[pos.back()] == 1)
    {
        dd += -a + b;
        dl = min(dl, dd);
        left.push_back(dl);
    }

    dd = 0;
    ll dr = 0;
    vector<int> right; right.resize(pos.size());
    for(int i=pos.size()-1; i>0; i--){
        if (type[pos[i]] == 1)
            dd += -(pos[i]-pos[i-1])*a + b;
        dr = min(dr, dd);
        right[i] = dr;
    }
    if (type[pos[0]] == 1)
    {
        dd += -a + b;
        dr = min(dr, dd);
        right[0] = dr;
    }

    ll cost = (pos.back()-pos[0]+1)*a;
    dd = min(right[1],left[pos.size()-1]);
    for(int i=0; i<pos.size()-2; i++)
        dd = min(dd, (ll)left[i] + right[i+2]);
    cost += dd;
    //cost = min( cost , pos.size()*b);
    return cost;
}
int main(){
    //freopen("d:\\src\\CppProjects\\stdin","r",stdin);
    scanf("%d%I64d%I64d",&n,&a,&b);
    x = new int[n];
    for(int i=0; i<n; i++)
        scanf("%d",x+i);

    int y[6] = {x[0], x[0]-1, x[0]+1, x[n-1], x[n-1]-1, x[n-1]+1};
    sort(y, y+6);
    set<int> primes;
    for(int d = 2; d*d<= y[5]; d++){
        for(int i=0; i<6; i++)
            while (y[i]%d==0)
            {
                y[i]/=d;
                primes.insert(d);
            }
    }
    for(int i=0; i<6; i++)
        if (y[i]>1)
            primes.insert(y[i]);

    ll ssol = max(n*b,n*a)+10;
    for(int p : primes)
        ssol = min(ssol, solve(p));
    printf("%I64d",ssol);
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

template <class T> T sqr(T x) { return x*x; }

int gcd(int a, int b){
    if (b==0)
        return a;
    int r = a%b;
    while(r){
        a = b;
        b = r;
        r = a%b;
    }
    return b;
}

bool valid[7][7];

int main(){
	//freopen("d:\\src\\CppProjects\\stdin","r",stdin);
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	int *x = new int[n+1];
	for(int i=1; i<=n; i++)
        scanf("%d",x+i);

    ll** dp = new ll *[n+1];
    for(int i=0;i<=n; i++)
        dp[i] = new ll [7];
    for(int i=0; i<1; i++)
        dp[0][i] = 0;

    int** gcds = new int *[n+1];
    for(int i=0;i<=n; i++)
        gcds[i] = new int [7];

    //before delete:
    //0 unchanged, 1 add one, 2 subtr one,
    //inside
    //3 delete,
    //after delete:
    //4 unchanged, 5 add one, 6 subtr one

    for(int i=0; i<7; i++)
        gcds[0][i] = 0;

    int cost[7] = { 0, b, b, a, 0, b, b};
    int mod[7] = { 0, 1, -1, 0, 0, 1, -1};
    const ll INF = max((ll)n*a, (ll)n*b)+10;

    for(int j=0; j<4; j++){
        valid[0][j] = 1;
        valid[1][j] = 1;
        valid[2][j] = 1;
    }
    for(int j=3; j<7; j++){
        valid[3][j] = 1;
    }
    for(int j=4; j<7; j++){
        valid[4][j] = 1;
        valid[5][j] = 1;
        valid[6][j] = 1;
    }

    const int K = 7; //states
    int d;
    for(int i=1; i<=n; i++){
        for(int k=0; k<K; k++)
            dp[i][k] = INF;
        for(int j=0; j<K; j++)
        {
            for(int k=0; k<K; k++){

                if (i==6 && k==4 && j==4){
                    int x = 1<<32;
                }
                if (valid[j][k]){
                    if (k==3)
                        d = gcds[i-1][j];
                    else
                        d = gcd(gcds[i-1][j], x[i]+mod[k]);
                    if (d!=1){
                        if (dp[i-1][j]+cost[k] < dp[i][k]){
                            gcds[i][k] = d;
                            dp[i][k] = dp[i-1][j]+cost[k];
                            //printf("%d %d = %I64d\n", i, k, dp[i][k]);
                            //int x = 1<<10;
                        }
                    }
                }
            }
        }
    }

    //printf("\n");
    ll ssol = INF;
    for(int i=0; i<K; i++){
        ssol = min(ssol, dp[n][i]);
        //printf("%d %d = %d\n", n, i, dp[n][i]);
    }
    printf("%I64d",ssol);

	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

template <class T> T sqr(T x) { return x*x; }

int gcd(int a, int b){
    if (b==0)
        return 0;
    int r = a%b;
    while(r){
        a = b;
        b = r;
        r = a%b;
    }
    return b;
}

bool valid[7][7];

int main(){
	//freopen("d:\\src\\CppProjects\\stdin","r",stdin);
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	int *x = new int[n+1];
	for(int i=1; i<=n; i++)
        scanf("%d",x+i);

    ll** dp = new ll *[n+1];
    for(int i=0;i<=n; i++)
        dp[i] = new ll [7];
    for(int i=0; i<1; i++)
        dp[0][i] = 0;

    int** gcds = new int *[n+1];
    for(int i=0;i<=n; i++)
        gcds[i] = new int [7];

    //before delete:
    //0 unchanged, 1 add one, 2 subtr one,
    //inside
    //3 delete,
    //after delete:
    //4 unchanged, 5 add one, 6 subtr one

    for(int i=0; i<7; i++)
        gcds[0][i] = 0;

    int cost[7] = { 0, b, b, a, 0, b, b};
    int mod[7] = { 0, 1, -1, 0, 0, 1, -1};
    const ll INF = max((ll)n*a, (ll)n*b)+10;

    for(int j=0; j<4; j++){
        valid[0][j] = 1;
        valid[1][j] = 1;
        valid[2][j] = 1;
    }
    for(int j=3; j<7; j++){
        valid[3][j] = 1;
    }
    for(int j=4; j<7; j++){
        valid[4][j] = 1;
        valid[5][j] = 1;
        valid[6][j] = 1;
    }

    const int K = 7; //states
    int d;
    for(int i=1; i<=n; i++){
        for(int k=0; k<K; k++)
            dp[i][k] = INF;
        for(int j=0; j<K; j++)
        {
            for(int k=0; k<K; k++){

                if (i==6 && k==4 && j==4){
                    int x = 1<<32;
                }
                if (valid[j][k]){
                    if (k==3)
                        d = gcds[i-1][j];
                    else
                        d = gcd(gcds[i-1][j], x[i]+mod[k]);
                    if (d>1){
                        if (dp[i-1][j]+cost[k] < dp[i][k]){
                            gcds[i][k] = d;
                            dp[i][k] = dp[i-1][j]+cost[k];
                            //printf("%d %d = %I64d\n", i, k, dp[i][k]);
                            //int x = 1<<10;
                        }
                    }
                }
            }
        }
    }

    //printf("\n");
    ll ssol = INF;
    for(int i=0; i<K; i++){
        ssol = min(ssol, dp[n][i]);
        //printf("%d %d = %d\n", n, i, dp[n][i]);
    }
    printf("%I64d",ssol);

	return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int n, *x;
ll a,b;

ll solve(int d){
    int* type = new int[n];
    vector<int> pos;
    for(int i=0; i<n; i++){
        if (x[i]%d==0)
            type[i] = 0;
        else if ((x[i]-1)%d==0 || (x[i]+1)%d==0 )
            type[i] = 1;
        else
            type[i] = 2;
        if (type[i]>0)
            pos.push_back(i);
    }
    if (pos.empty())
        return 0;

    if (pos.size()==1){
        if (type[pos[0]]==1)
            return min(a,b);
        else
            return a;
    }

    ll dd = 0, dl = 0;
    bool good = 1;
    vector<ll> left; left.resize(pos.size());
    for(int i=0; i<pos.size()-1; i++){
        if (type[pos[i]]==2)
            good = 0;
        if (type[pos[i]] == 1 && good)
            dd += -(pos[i+1]-pos[i])*a + b;
        dl = min(dl, dd);
        left[i] = dl;
    }
    if (type[pos.back()] == 1 && good)
    {
        dd += -a + b;
        dl = min(dl, dd);
        left[pos.size()-1] = dl;
    }

    dd = 0;
    ll dr = 0; good = 1;
    vector<ll> right; right.resize(pos.size());
    for(int i=pos.size()-1; i>0; i--){
        if (type[pos[i]] == 2)
            good = 0;
        if (type[pos[i]] == 1 && good)
            dd += -(pos[i]-pos[i-1])*a + b;
        dr = min(dr, dd);
        right[i] = dr;
    }
    if (type[pos[0]] == 1 && good)
    {
        dd += -a + b;
        dr = min(dr, dd);
        right[0] = dr;
    }

    ll cost = (pos.back()-pos[0]+1)*a;
    dd = min(right[1],0);
    //right[0] should be == left[pos.size()-1]
    right.push_back(0); right.push_back(0);
    for(int i=0; i<pos.size(); i++)
        dd = min(dd, left[i] + right[i+2]);
    cost += dd;
    //cost = min( cost , pos.size()*b);
    return cost;
}
int main(){
    //freopen("d:\\src\\CppProjects\\stdin","r",stdin);
    scanf("%d%I64d%I64d",&n,&a,&b);
    x = new int[n];
    for(int i=0; i<n; i++)
        scanf("%d",x+i);

    int y[6] = {x[0], x[0]-1, x[0]+1, x[n-1], x[n-1]-1, x[n-1]+1};
    sort(y, y+6);
    set<int> primes;
    for(int d = 2; d*d<= y[5]; d++){
        for(int i=0; i<6; i++)
            while (y[i]%d==0)
            {
                y[i]/=d;
                primes.insert(d);
            }
    }
    for(int i=0; i<6; i++)
        if (y[i]>1)
            primes.insert(y[i]);

    ll ssol = max(n*b,n*a)+10;
    for(int p : primes)
        ssol = min(ssol, solve(p));
    printf("%I64d",ssol);
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int n, *x;
ll a,b;

ll solve(int d){
    int* type = new int[n];
    vector<int> pos;
    for(int i=0; i<n; i++){
        if (x[i]%d==0)
            type[i] = 0;
        else if ((x[i]-1)%d==0 || (x[i]+1)%d==0 )
            type[i] = 1;
        else
            type[i] = 2;
        if (type[i]>0)
            pos.push_back(i);
    }
    if (pos.empty())
        return 0;

    ll dd = 0;
    ll dl = 0; int posl = 0;
    for(int i=0; i<pos.size()-1; i++){
        if (type[pos[i]] == 2) break;
        dd += -(pos[i+1]-pos[i])*a + b;
        if (dd<dl){
            dl = dd;
            posl = i;
        }
    }
    if (type[pos.back()] == 1)
    {
        dd += -a + b;
        if (dd<dl){
            dl = dd;
            posl = pos.size()-1;
        }
    }

    dd = 0;
    ll dr = 0; int posr = pos.size()-1;
    for(int i=pos.size()-1; i>0; i--){
        if (type[pos[i]] == 2) break;
        dd += -(pos[i]-pos[i-1])*a + b;
        if (dd<dr){
            dr = dd;
            posr = i;
        }
    }
    if (type[pos[0]] == 1)
    {
        dd += -a + b;
        if (dd<dr){
            dr = dd;
            posr = 0;
        }
    }

    ll cost = (pos.back()-pos[0]+1)*a;
    if (posr>=posl+1)
        cost += dl + dr;
    else
        cost += min(dl, dr);
    //cost = min( cost , pos.size()*b);
    return cost;
}
int main(){
    //freopen("d:\\src\\CppProjects\\stdin","r",stdin);
    scanf("%d%I64d%I64d",&n,&a,&b);
    x = new int[n];
    for(int i=0; i<n; i++)
        scanf("%d",x+i);

    int y[6] = {x[0], x[0]-1, x[0]+1, x[n-1], x[n-1]-1, x[n-1]+1};
    sort(y, y+6);
    set<int> primes;
    for(int d = 2; d*d<= y[5]; d++){
        for(int i=0; i<6; i++)
            while (y[i]%d==0)
            {
                y[i]/=d;
                primes.insert(d);
            }
    }
    for(int i=0; i<6; i++)
        if (y[i]>1)
            primes.insert(y[i]);

    ll ssol = max(n*b,n*a)+10;
    for(int p : primes)
        ssol = min(ssol, solve(p));
    printf("%I64d",ssol);
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int n, *x;
ll a,b;

ll solve(int d){
    int* type = new int[n];
    vector<int> pos;
    for(int i=0; i<n; i++){
        if (x[i]%d==0)
            type[i] = 0;
        else if ((x[i]-1)%d==0 || (x[i]+1)%d==0 )
            type[i] = 1;
        else
            type[i] = 2;
        if (type[i]>0)
            pos.push_back(i);
    }
    if (pos.empty())
        return 0;

    ll dd = 0, dl = 0;
    vector<int> left;
    for(int i=0; i<pos.size()-1; i++){
        if (type[pos[i]] == 1)
            dd += -(pos[i+1]-pos[i])*a + b;
        dl = min(dl, dd);
        left.push_back(dl);
    }
    if (type[pos.back()] == 1)
    {
        dd += -a + b;
        dl = min(dl, dd);
        left.push_back(dl);
    }

    dd = 0;
    ll dr = 0;
    vector<int> right; right.resize(pos.size());
    for(int i=pos.size()-1; i>0; i--){
        if (type[pos[i]] == 1)
            dd += -(pos[i]-pos[i-1])*a + b;
        dr = min(dr, dd);
        right[i] = dr;
    }
    if (type[pos[0]] == 1)
    {
        dd += -a + b;
        dr = min(dr, dd);
        right[0] = dr;
    }

    ll cost = (pos.back()-pos[0]+1)*a;
    dd = min(right[1], left[pos.size()-1]);
    for(int i=0; i<pos.size()-2; i++)
        dd = min(dd, (ll)left[i] + right[i+2]);
    cost += dd;
    //cost = min( cost , pos.size()*b);
    return cost;
}
int main(){
    //freopen("d:\\src\\CppProjects\\stdin","r",stdin);
    scanf("%d%I64d%I64d",&n,&a,&b);
    x = new int[n];
    for(int i=0; i<n; i++)
        scanf("%d",x+i);

    int y[6] = {x[0], x[0]-1, x[0]+1, x[n-1], x[n-1]-1, x[n-1]+1};
    sort(y, y+6);
    set<int> primes;
    for(int d = 2; d*d<= y[5]; d++){
        for(int i=0; i<6; i++)
            while (y[i]%d==0)
            {
                y[i]/=d;
                primes.insert(d);
            }
    }
    for(int i=0; i<6; i++)
        if (y[i]>1)
            primes.insert(y[i]);

    ll ssol = max(n*b,n*a)+10;
    for(int p : primes)
        ssol = min(ssol, solve(p));
    printf("%I64d",ssol);
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int n, *x;
ll a,b;

ll solve(int d){
    char* type = new char[n];
    vector<int> pos;
    for(int i=0; i<n; i++){
        if (x[i]%d==0)
            type[i] = 0;
        else if ((x[i]-1)%d==0 || (x[i]+1)%d==0 )
            type[i] = 1;
        else
            type[i] = 2;
        if (type[i]>0)
            pos.push_back(i);
    }
    if (pos.empty())
        return 0;

    if (pos.size()==1){
        if (type[pos[0]]==1)
            return min(a,b);
        else
            return a;
    }

    ll dd = 0, dl = 0;
    bool good = 1;
    vector<ll> left; left.resize(pos.size());
    for(int i=0; i<pos.size()-1; i++){
        if (type[pos[i]]==2)
            good = 0;
        if (type[pos[i]] == 1 && good)
            dd += -(pos[i+1]-pos[i])*a + b;
        dl = min(dl, dd);
        left[i] = dl;
    }
    if (type[pos.back()] == 1 && good)
    {
        dd += -a + b;
        dl = min(dl, dd);
        left[pos.size()-1] = dl;
    }

    dd = 0;
    ll dr = 0; good = 1;
    vector<ll> right; right.resize(pos.size());
    for(int i=pos.size()-1; i>0; i--){
        if (type[pos[i]] == 2)
            good = 0;
        if (type[pos[i]] == 1 && good)
            dd += -(pos[i]-pos[i-1])*a + b;
        dr = min(dr, dd);
        right[i] = dr;
    }
    if (type[pos[0]] == 1 && good)
    {
        dd += -a + b;
        dr = min(dr, dd);
        right[0] = dr;
    }

    ll cost = (pos.back()-pos[0]+1)*a;
    dd = min(0ll,right[1]);
    //right[0] should be == left[pos.size()-1]
    right.push_back(0); right.push_back(0);
    for(int i=0; i<pos.size(); i++)
        dd = min(dd, left[i] + right[i+2]);
    cost += dd;
    //cost = min( cost , pos.size()*b);
    delete[] type;
    return cost;
}
int main(){
    //freopen("d:\\src\\CppProjects\\stdin","r",stdin);
    scanf("%d%I64d%I64d",&n,&a,&b);
    x = new int[n];
    for(int i=0; i<n; i++)
        scanf("%d",x+i);

    int y[6] = {x[0], x[0]-1, x[0]+1, x[n-1], x[n-1]-1, x[n-1]+1};
    ll pen[6] = {0, b, b, 0, b, b};

    ll ssol = max(n*b,n*a)+10;
    int* x0 = x; int n0 = n;
    for(int i=0; i<6; i++){
        if (i==1 || i==2)
        {
            n = n-1;
            x += 1;
        }
        else if (i==4 || i==5){
            n = n-1;
        }
        for(int d = 2; d*d<= y[i]; d++){
            if (y[i]%d==0)
                ssol = min(ssol, solve(d)+pen[i]);
            while(y[i]%d==0)
                y[i]/=d;
        }
        if (y[i]>1)
            ssol = min(ssol, solve(y[i])+pen[i]);

        n = n0;
        x = x0;
    }
    printf("%I64d",ssol);
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int n, *x;
ll a,b;
const ll INF = 1e16;

ll solve(int d){
    char* type = new char[n];
    vector<int> pos;
    for(int i=0; i<n; i++){
        if (x[i]%d==0)
            type[i] = 0;
        else if ((x[i]-1)%d==0 || (x[i]+1)%d==0 )
            type[i] = 1;
        else
            type[i] = 2;
        if (type[i]>0)
            pos.push_back(i);
    }
    if (pos.empty())
        return 0;

    if (pos.size()==1){
        if (type[pos[0]]==1)
            return min(a,b);
        else
            return a;
    }

    ll dd = 0, dl = 0;
    bool good = 1;
    vector<ll> left; left.resize(pos.size());
    for(int i=0; i<pos.size()-1; i++){
        if (type[pos[i]]==2)
            good = 0;
        if (type[pos[i]] == 1 && good)
            dd += -(pos[i+1]-pos[i])*a + b;
        dl = min(dl, dd);
        left[i] = dl;
    }
    if (type[pos.back()] == 1 && good)
    {
        dd += -a + b;
        dl = min(dl, dd);
        left[pos.size()-1] = dl;
    }

    dd = 0;
    ll dr = 0; good = 1;
    vector<ll> right; right.resize(pos.size());
    for(int i=pos.size()-1; i>0; i--){
        if (type[pos[i]] == 2)
            good = 0;
        if (type[pos[i]] == 1 && good)
            dd += -(pos[i]-pos[i-1])*a + b;
        dr = min(dr, dd);
        right[i] = dr;
    }
    if (type[pos[0]] == 1 && good)
    {
        dd += -a + b;
        dr = min(dr, dd);
        right[0] = dr;
    }

    ll cost = (pos.back()-pos[0]+1)*a;
    dd = min(0ll,right[1]);
    //right[0] should be == left[pos.size()-1]
    right.push_back(0); right.push_back(0);
    for(int i=0; i<pos.size(); i++)
        dd = min(dd, left[i] + right[i+2]);
    cost += dd;
    //cost = min( cost , pos.size()*b);
    delete[] type;
    return cost;
}

ll solve2(int r) {
	ll s1 = 0, s2 = 0, s3 = 0;
	for (int i = 0; i < n; ++i) {
		ll cost = INF;
		if (x[i] % r == 0) {
			cost = 0;
		} else if ((x[i] - 1) % r == 0 || (x[i] + 1) % r == 0) {
			cost = b;
		}
		s1 += cost, s2 += a, s3 += cost;
		s1 = min(s1, INF), s2 = min(s2, s1), s3 = min(s2, s3);
	}
	return s3;
}

int main(){
    //freopen("d:\\src\\CppProjects\\stdin","r",stdin);
    scanf("%d%I64d%I64d",&n,&a,&b);
    x = new int[n];
    for(int i=0; i<n; i++)
        scanf("%d",x+i);

    int y[6] = {x[0], x[0]-1, x[0]+1, x[n-1], x[n-1]-1, x[n-1]+1};
    ll pen[6] = {0, b, b, 0, b, b};

    ll ssol = max(n*b,n*a)+10;
    int* x0 = x; int n0 = n;
    for(int i=0; i<6; i++){
        if (i==1 || i==2)
        {
            n = n-1;
            x += 1;
        }
        else if (i==4 || i==5){
            n = n-1;
        }
        for(int d = 2; d*d<= y[i]; d++){
            if (y[i]%d==0)
                ssol = min(ssol, solve2(d)+pen[i]);
            while(y[i]%d==0)
                y[i]/=d;
        }
        if (y[i]>1)
            ssol = min(ssol, solve2(y[i])+pen[i]);

        n = n0;
        x = x0;
    }
    printf("%I64d",ssol);
}


#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

template <class T> T sqr(T x) { return x*x; }

int gcd(int a, int b){
    if (b==0)
        return 0;
    int r = a%b;
    while(r){
        a = b;
        b = r;
        r = a%b;
    }
    return b;
}

bool valid[7][7];

int main(){
	//freopen("d:\\src\\CppProjects\\stdin","r",stdin);
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	int *x = new int[n+1];
	for(int i=1; i<=n; i++)
        scanf("%d",x+i);

    ll** dp = new ll *[n+1];
    for(int i=0;i<=n; i++)
        dp[i] = new ll [7];
    for(int i=0; i<1; i++)
        dp[0][i] = 0;

    int** gcds = new int *[n+1];
    for(int i=0;i<=n; i++)
        gcds[i] = new int [7];

    //before delete:
    //0 unchanged, 1 add one, 2 subtr one,
    //inside
    //3 delete,
    //after delete:
    //4 unchanged, 5 add one, 6 subtr one

    for(int i=0; i<7; i++)
        gcds[0][i] = 0;

    int cost[7] = { 0, b, b, a, 0, b, b};
    int mod[7] = { 0, 1, -1, 0, 0, 1, -1};
    const ll INF = max((ll)n*a, (ll)n*b)+10;

    for(int j=0; j<4; j++){
        valid[0][j] = 1;
        valid[1][j] = 1;
        valid[2][j] = 1;
    }
    for(int j=3; j<7; j++){
        valid[3][j] = 1;
    }
    for(int j=4; j<7; j++){
        valid[4][j] = 1;
        valid[5][j] = 1;
        valid[6][j] = 1;
    }

    const int K = 7; //states
    int d;
    for(int i=1; i<=n; i++){
        for(int k=0; k<K; k++)
            dp[i][k] = INF;
        for(int j=0; j<K; j++)
        {
            for(int k=0; k<K; k++){

                if (i==6 && k==4 && j==4){
                    int x = 1<<32;
                }
                if (valid[j][k]){
                    if (k==3)
                        d = gcds[i-1][j];
                    else
                        d = gcd(gcds[i-1][j], x[i]+mod[k]);
                    if (d!=1){
                        if (dp[i-1][j]+cost[k] < dp[i][k]){
                            gcds[i][k] = d;
                            dp[i][k] = dp[i-1][j]+cost[k];
                            //printf("%d %d = %I64d\n", i, k, dp[i][k]);
                            //int x = 1<<10;
                        }
                    }
                }
            }
        }
    }

    //printf("\n");
    ll ssol = INF;
    for(int i=0; i<K; i++){
        ssol = min(ssol, dp[n][i]);
        //printf("%d %d = %d\n", n, i, dp[n][i]);
    }
    printf("%I64d",ssol);

	return 0;
}


#include <bits/stdc++.h>

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

using namespace std;

typedef long long int LLI;
typedef pair < int , int > PII;
typedef pair < LLI , LLI > PLL;

typedef vector < int > VI;
typedef vector < bool > VB;
typedef vector < PII > VP;
typedef vector < LLI > VL;
typedef vector < PLL > VPL;

typedef vector < VI > VVI;
typedef vector < VL > VVL;
typedef vector < VB > VVB;
typedef vector < VP > VVP;

#define MOD 1000000007

const int MAXS = 40 * 1000;
bool composite[MAXS];

void erato() {
  composite[0] = composite[1] = true;
  for (int i = 2; i < MAXS; i++) {
    if (!composite[i]) {
      for (int j = 2 * i; j < MAXS; j += i) {
        composite[j] = true;
      }
    }
  }
}

VI primes;

void factorize(int x) {
  for (int i = 2; i <= sqrt(x) + 1; i++) {
    if (!composite[i] && x % i == 0) {
      while (x % i) {
        x /= i;
      }
      primes.PB(i);
    }
  }
  if (x > 1) primes.PB(x);
}

/*************************************************************************/

const int MAXN = 1000009;

const LLI INF = 1000ll * 1000 * 1000 * 1000 * 1000 * 1000 + 9;

int state[MAXN];
LLI dp[3][MAXN];

int main()
{
    int n;
    LLI segm, red1;
    scanf("%d%I64d%I64d", &n, &segm, &red1);

    VI input(n);

    for (int i = 0; i < n; i++) {
      scanf("%d", &input[i]);
    }

    factorize(input[0]);
    factorize(input[0] - 1);
    factorize(input[0] + 1);

    factorize(input[n - 1]);
    factorize(input[n - 1] - 1);
    factorize(input[n - 1] + 1);

    sort(primes.begin(), primes.end());
    primes.resize(unique(primes.begin(), primes.end()) - primes.begin());

    const int YES = 0;
    const int NO = 1;
    const int MAYBE = 2;

    LLI result = INF;

    for (int p : primes) {
      for (int i = 0; i < n; i++) {
        state[i] = NO;
        if (LLI (input[i] + 1) * (input[i] - 1) % p == 0) state[i] = MAYBE;
        if (input[i] % p == 0) state[i] = YES;
      }

      dp[0][0] = dp[1][0] = dp[2][0] = INF;
      if (state[0] == YES) {
        dp[0][0] = 0;
      }
      if (state[0] == MAYBE) {
        dp[0][0] = red1;
      }

      for (int i = 1; i < n; i++) {
        dp[1][i] = min(dp[0][i-1], dp[1][i - 1]) + segm;
        if (state[i] == YES) {
          dp[0][i] = dp[0][i - 1];
          dp[2][i] = min(dp[1][i - 1], dp[2][i - 1]);
        }
        else if (state[i] == NO) {
          dp[0][i] = INF;
          dp[2][i] = INF;
        }
        else if (state[i] == MAYBE) {
          dp[0][i] = dp[0][i-1] + red1;
          dp[2][i] = dp[2][i -1] + red1;
        }

      }

      result = min({result, dp[0][n-1], dp[1][n-1], dp[2][n-1]});
    }

    printf("%I64d\n", result);

    return 0;
}

/*************************************************************************/


#include <bits/stdc++.h>

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

using namespace std;

typedef long long int LLI;
typedef pair < int , int > PII;
typedef pair < LLI , LLI > PLL;

typedef vector < int > VI;
typedef vector < bool > VB;
typedef vector < PII > VP;
typedef vector < LLI > VL;
typedef vector < PLL > VPL;

typedef vector < VI > VVI;
typedef vector < VL > VVL;
typedef vector < VB > VVB;
typedef vector < VP > VVP;

#define MOD 1000000007

const int MAXS = 40 * 1000;
bool composite[MAXS];

void erato() {
  composite[0] = composite[1] = true;
  for (int i = 2; i < MAXS; i++) {
    if (!composite[i]) {
      for (int j = 2 * i; j < MAXS; j += i) {
        composite[j] = true;
      }
    }
  }
}

VI primes;

void factorize(int x) {
  for (int i = 2; i <= sqrt(x) + 1; i++) {
    if (!composite[i] && x % i == 0) {
      while (x % i) {
        x /= i;
      }
      primes.PB(i);
    }
  }
  if (x > 1) primes.PB(x);
}

void createPrimes() {

}

/*************************************************************************/

const int MAXN = 1000009;

const LLI INF = 1000ll * 1000 * 1000 * 1000 * 1000 * 1000 + 9;

int state[MAXN];
LLI dp[3][MAXN];

int main()
{
    ios_base::sync_with_stdio(0);

    int n;
    LLI segm, red1;
    cin >> n >> segm >> red1;

    VI input(n);

    for (int i = 0; i < n; i++) {
      cin >> input[i];
    }

    factorize(input[0]);
    factorize(input[0] - 1);
    factorize(input[0] + 1);

    factorize(input[n - 1]);
    factorize(input[n - 1] - 1);
    factorize(input[n - 1] + 1);

    const int YES = 0;
    const int NO = 1;
    const int MAYBE = 2;

    LLI result = INF;

    for (int p : primes) {
      for (int i = 0; i < n; i++) {
        state[i] = NO;
        if ((input[i] + 1) % p == 0 || (input[i] - 1) % p == 0) state[i] = MAYBE;
        if (input[i] % p == 0) state[i] = YES;
      }

      dp[0][0] = dp[1][0] = dp[2][0] = INF;
      if (state[0] == YES) {
        dp[0][0] = 0;
      }
      if (state[0] == MAYBE) {
        dp[0][0] = red1;
      }

      for (int i = 1; i < n; i++) {
        if (state[i] == YES) {
          dp[0][i] = dp[0][i - 1];
          dp[1][i] = min(dp[0][i-1], dp[1][i - 1]) + segm;
          dp[2][i] = min(dp[1][i - 1], dp[2][i - 1]);
        }
        if (state[i] == NO) {
          dp[0][i] = INF;
          dp[1][i] = min(dp[1][i-1], dp[0][i - 1]) + segm;
          dp[2][i] = INF;
        }
        if (state[i] == MAYBE) {
          dp[0][i] = dp[0][i-1] + red1;
          dp[1][i] = min(dp[1][i - 1], dp[0][i - 1]) + segm;
          dp[2][i] = dp[2][i -1] + red1;
        }

      }

      result = min({result, dp[0][n-1], dp[1][n-1], dp[2][n-1]});
    }

    cout << result << endl;

    return 0;
}

/*************************************************************************/


#include <bits/stdc++.h>

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

using namespace std;

typedef long long int LLI;
typedef pair < int , int > PII;
typedef pair < LLI , LLI > PLL;

typedef vector < int > VI;
typedef vector < bool > VB;
typedef vector < PII > VP;
typedef vector < LLI > VL;
typedef vector < PLL > VPL;

typedef vector < VI > VVI;
typedef vector < VL > VVL;
typedef vector < VB > VVB;
typedef vector < VP > VVP;

#define MOD 1000000007

VI primes;

void factorize(int x) {
  for (int i = 2; i <= sqrt(x) + 1; i++) {
    if (x % i == 0) {
      while (x % i == 0) {
        x /= i;
      }
      primes.PB(i);
    }
  }
  if (x > 1) primes.PB(x);
}

/*************************************************************************/

const int MAXN = 1000009;

const LLI INF = 1000ll * 1000 * 1000 * 1000 * 1000 * 1000 + 9;

int state[MAXN];
LLI dp[3][MAXN];

int main()
{
    int n;
    LLI segm, red1;
    scanf("%d%I64d%I64d", &n, &segm, &red1);

    VI input(n);

    for (int i = 0; i < n; i++) {
      scanf("%d", &input[i]);
    }

    factorize(input[0]);
    factorize(input[0] - 1);
    factorize(input[0] + 1);

    factorize(input[n - 1]);
    factorize(input[n - 1] - 1);
    factorize(input[n - 1] + 1);

    sort(primes.begin(), primes.end());
    primes.resize(unique(primes.begin(), primes.end()) - primes.begin());

    const int YES = 0;
    const int NO = 1;
    const int MAYBE = 2;

    LLI result = INF;

    for (int p : primes) {
      for (int i = 0; i < n; i++) {
        state[i] = NO;
        if (LLI (input[i] + 1) * (input[i] - 1) % p == 0) state[i] = MAYBE;
        if (input[i] % p == 0) state[i] = YES;
      }

      dp[0][0] = dp[1][0] = dp[2][0] = INF;
      if (state[0] == YES) {
        dp[0][0] = 0;
      }
      if (state[0] == MAYBE) {
        dp[0][0] = red1;
      }

      for (int i = 1; i < n; i++) {
        dp[1][i] = min(dp[0][i-1], dp[1][i - 1]) + segm;
        if (state[i] == YES) {
          dp[0][i] = dp[0][i - 1];
          dp[2][i] = min({ dp[1][i - 1], dp[2][i - 1], i * segm });
        }
        else if (state[i] == NO) {
          dp[0][i] = INF;
          dp[2][i] = INF;
        }
        else if (state[i] == MAYBE) {
          dp[0][i] = dp[0][i-1] + red1;
          dp[2][i] = dp[2][i -1] + red1;
        }

      }

      result = min({result, dp[0][n-1], dp[1][n-1], dp[2][n-1]});
    }

    printf("%I64d\n", result);

    return 0;
}

/*************************************************************************/


#include <bits/stdc++.h>

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

using namespace std;

typedef long long int LLI;
typedef pair < int , int > PII;
typedef pair < LLI , LLI > PLL;

typedef vector < int > VI;
typedef vector < bool > VB;
typedef vector < PII > VP;
typedef vector < LLI > VL;
typedef vector < PLL > VPL;

typedef vector < VI > VVI;
typedef vector < VL > VVL;
typedef vector < VB > VVB;
typedef vector < VP > VVP;

#define MOD 1000000007

const int MAXS = 40 * 1000;
bool composite[MAXS];

VI primes;

void factorize(int x) {
  for (int i = 2; i <= sqrt(x) + 1; i++) {
    if (!composite[i] && x % i == 0) {
      while (x % i == 0) {
        x /= i;
      }
      primes.PB(i);
    }
  }
  if (x > 1) primes.PB(x);
}

/*************************************************************************/

const int MAXN = 1000009;

const LLI INF = 1000ll * 1000 * 1000 * 1000 * 1000 * 1000 + 9;

int state[MAXN];
LLI dp[3][MAXN];

int main()
{
    int n;
    LLI segm, red1;
    scanf("%d%I64d%I64d", &n, &segm, &red1);

    VI input(n);

    for (int i = 0; i < n; i++) {
      scanf("%d", &input[i]);
    }

    factorize(input[0]);
    factorize(input[0] - 1);
    factorize(input[0] + 1);

    factorize(input[n - 1]);
    factorize(input[n - 1] - 1);
    factorize(input[n - 1] + 1);

    sort(primes.begin(), primes.end());
    primes.resize(unique(primes.begin(), primes.end()) - primes.begin());

    const int YES = 0;
    const int NO = 1;
    const int MAYBE = 2;

    LLI result = INF;

    for (int p : primes) {
      for (int i = 0; i < n; i++) {
        state[i] = NO;
        if (LLI (input[i] + 1) * (input[i] - 1) % p == 0) state[i] = MAYBE;
        if (input[i] % p == 0) state[i] = YES;
      }

      dp[0][0] = dp[1][0] = dp[2][0] = INF;
      if (state[0] == YES) {
        dp[0][0] = 0;
      }
      if (state[0] == MAYBE) {
        dp[0][0] = red1;
      }

      for (int i = 1; i < n; i++) {
        dp[1][i] = min(dp[0][i-1], dp[1][i - 1]) + segm;
        if (state[i] == YES) {
          dp[0][i] = dp[0][i - 1];
          dp[2][i] = min(dp[1][i - 1], dp[2][i - 1]);
        }
        else if (state[i] == NO) {
          dp[0][i] = INF;
          dp[2][i] = INF;
        }
        else if (state[i] == MAYBE) {
          dp[0][i] = dp[0][i-1] + red1;
          dp[2][i] = dp[2][i -1] + red1;
        }

      }

      result = min({result, dp[0][n-1], dp[1][n-1], dp[2][n-1]});
    }

    printf("%I64d\n", result);

    return 0;
}

/*************************************************************************/


#include <bits/stdc++.h>

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

using namespace std;

typedef long long int LLI;
typedef pair < int , int > PII;
typedef pair < LLI , LLI > PLL;

typedef vector < int > VI;
typedef vector < bool > VB;
typedef vector < PII > VP;
typedef vector < LLI > VL;
typedef vector < PLL > VPL;

typedef vector < VI > VVI;
typedef vector < VL > VVL;
typedef vector < VB > VVB;
typedef vector < VP > VVP;

#define MOD 1000000007

const int MAXS = 40 * 1000;
bool composite[MAXS];

void erato() {
  composite[0] = composite[1] = true;
  for (int i = 2; i < MAXS; i++) {
    if (!composite[i]) {
      for (int j = 2 * i; j < MAXS; j += i) {
        composite[j] = true;
      }
    }
  }
}

VI primes;

void factorize(int x) {
  for (int i = 2; i <= sqrt(x) + 1; i++) {
    if (!composite[i] && x % i == 0) {
      while (x % i) {
        x /= i;
      }
      primes.PB(i);
    }
  }
  if (x > 1) primes.PB(x);
}

void createPrimes() {

}

/*************************************************************************/

const int MAXN = 1000009;

const LLI INF = 1000ll * 1000 * 1000 * 1000 * 1000 * 1000 + 9;

int state[MAXN];
LLI dp[3][MAXN];

int main()
{
    ios_base::sync_with_stdio(0);

    int n;
    LLI segm, red1;
    cin >> n >> segm >> red1;

    VI input(n);

    for (int i = 0; i < n; i++) {
      cin >> input[i];
    }

    factorize(input[0]);
    factorize(input[0] - 1);
    factorize(input[0] + 1);

    factorize(input[n - 1]);
    factorize(input[n - 1] - 1);
    factorize(input[n - 1] + 1);

    sort(primes.begin(), primes.end());
    primes.resize(unique(primes.begin(), primes.end()) - primes.begin());

    const int YES = 0;
    const int NO = 1;
    const int MAYBE = 2;

    LLI result = INF;

    for (int p : primes) {
      for (int i = 0; i < n; i++) {
        state[i] = NO;
        if ((input[i] + 1) % p == 0 || (input[i] - 1) % p == 0) state[i] = MAYBE;
        if (input[i] % p == 0) state[i] = YES;
      }

      dp[0][0] = dp[1][0] = dp[2][0] = INF;
      if (state[0] == YES) {
        dp[0][0] = 0;
      }
      if (state[0] == MAYBE) {
        dp[0][0] = red1;
      }

      for (int i = 1; i < n; i++) {
        if (state[i] == YES) {
          dp[0][i] = dp[0][i - 1];
          dp[1][i] = min(dp[0][i-1], dp[1][i - 1]) + segm;
          dp[2][i] = min(dp[1][i - 1], dp[2][i - 1]);
        }
        if (state[i] == NO) {
          dp[0][i] = INF;
          dp[1][i] = min(dp[1][i-1], dp[0][i - 1]) + segm;
          dp[2][i] = INF;
        }
        if (state[i] == MAYBE) {
          dp[0][i] = dp[0][i-1] + red1;
          dp[1][i] = min(dp[1][i - 1], dp[0][i - 1]) + segm;
          dp[2][i] = dp[2][i -1] + red1;
        }

      }

      result = min({result, dp[0][n-1], dp[1][n-1], dp[2][n-1]});
    }

    cout << result << endl;

    return 0;
}

/*************************************************************************/


# include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;

const ll maxN = ll(8e5);
const ll smaxN = ll(5e3);
const ll mmaxN = ll(3e4);
const ll lmaxN = ll(3e6);
const ll oo = ll(1e18);
const ll MOD = ll(1e9) + 7;
const ld EPS = 1e-10;
const ld PI = acos(0.0) * 2;
const ll dx[] = {-1, +0, +0, +1};
const ll dy[] = {+0, -1, +1, +0};

template < typename T >
T Sqr(T x) {
    return x * x;
}

template < class T >
ll Sz(T x) {
    return ll(x.size());
}

inline ll MultMod(ll a, ll b, ll mod) {
    if(b == 0)
        return 0;
    if(b % 2)
        return (MultMod(a, b - 1, mod) + a) % mod;
    return (MultMod(a, b / 2, mod) * 2) % mod;
}

inline ll ModPow(ll a, ll b, ll mod) {
    if(b == 0)
        return 1ll % mod;
    if(b == 1)
        return a % mod;
    if(b % 2)
        return MultMod(ModPow(a, b - 1, mod), a, mod) % mod;
    ll z = ModPow(a, b / 2, mod);
    return (MultMod(z, z, mod)) % mod;
}

void compress(vector < ll > &a){
    vector < ll > b(a);
    sort(b.begin(), b.end());
    b.erase(unique(b.begin(), b.end()), b.end());
    for(auto &i : a) i = lower_bound(b.begin(), b.end(), i) - b.begin() + 1;
}

inline bool Prime(ll x){
    if(x < 2)
        return 0;
    for(ll i = 2; i * i <= x; ++i)
        if(x % i == 0)
            return 0;
    return 1;
}

inline bool IsProbablePrime(ll x){
    return 1; // -> returns 1
}

const ll F = (ll)6e6;

ll n, ca, cb, ans = oo;
ll a[lmaxN], dp[lmaxN][4];

ll Solve(ll p){
    // 1 - Before
    // 2 - Begin
    // 3 - After
    dp[0][2] = oo;
    for(ll i = 1; i <= n; ++i){
        ll coef = (a[i] % p == 0 ? 0 : ((a[i] - 1) % p == 0 || (a[i] + 1) % p == 0 ? cb : oo));
        dp[i][1] = min(oo, dp[i - 1][1] + coef);
        dp[i][2] = min(dp[i - 1][1] + ca, dp[i - 1][2] + ca);
        dp[i][3] = min(dp[i - 1][3] + coef, min(dp[i - 1][2] + coef, dp[i - 1][1] + coef));
    }
    ll now = dp[n][3];
    for(ll i = 1; i <= n; ++i)
        now = min(now, dp[i][1] + ca * (n - i));
    return now;
}

main(){
    scanf("%lld %lld %lld", &n, &ca, &cb);
    for(ll i = 1; i <= n; ++i) scanf("%lld", &a[i]);
    vector < ll > pp = {a[1], a[1] + 1, a[1] - 1, a[n], a[n] + 1, a[n] - 1};
    for(auto i : pp){
        for(ll j = 2; j * j <= i; ++j){
            if(i % j == 0){
                while(i % j == 0)
                    i /= j;
                ans = min(ans, Solve(j));
            }
        }
        if(i > 1)
            ans = min(ans, Solve(i));
    }
    printf("%lld", ans);
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;

const ll maxN = ll(8e5);
const ll smaxN = ll(5e3);
const ll mmaxN = ll(3e4);
const ll lmaxN = ll(3e6);
const ll oo = ll(1e18);
const ll MOD = ll(1e9) + 7;
const ld EPS = 1e-10;
const ld PI = acos(0.0) * 2;
const ll dx[] = {-1, +0, +0, +1};
const ll dy[] = {+0, -1, +1, +0};

template < typename T >
T Sqr(T x) {
    return x * x;
}

template < class T >
ll Sz(T x) {
    return ll(x.size());
}

inline ll MultMod(ll a, ll b, ll mod) {
    if(b == 0)
        return 0;
    if(b % 2)
        return (MultMod(a, b - 1, mod) + a) % mod;
    return (MultMod(a, b / 2, mod) * 2) % mod;
}

inline ll ModPow(ll a, ll b, ll mod) {
    if(b == 0)
        return 1ll % mod;
    if(b == 1)
        return a % mod;
    if(b % 2)
        return MultMod(ModPow(a, b - 1, mod), a, mod) % mod;
    ll z = ModPow(a, b / 2, mod);
    return (MultMod(z, z, mod)) % mod;
}

void compress(vector < ll > &a){
    vector < ll > b(a);
    sort(b.begin(), b.end());
    b.erase(unique(b.begin(), b.end()), b.end());
    for(auto &i : a) i = lower_bound(b.begin(), b.end(), i) - b.begin() + 1;
}

inline bool Prime(ll x){
    if(x < 2)
        return 0;
    for(ll i = 2; i * i <= x; ++i)
        if(x % i == 0)
            return 0;
    return 1;
}

inline bool IsProbablePrime(ll x){
    return 1; // -> returns 1
}

const ll F = (ll)6e6;

ll n, ca, cb, ans = oo;
ll a[maxN], dp[maxN][4];

ll Solve(ll p){
    // 1 - Before
    // 2 - Begin
    // 3 - After
    dp[0][2] = oo;
    for(ll i = 1; i <= n; ++i){
        ll coef = (a[i] % p == 0 ? 0 : ((a[i] - 1) % p == 0 || (a[i] + 1) % p == 0 ? cb : oo));
        dp[i][1] = min(oo, dp[i - 1][1] + coef);
        dp[i][2] = min(dp[i - 1][1] + ca, dp[i - 1][2] + ca);
        dp[i][3] = min(dp[i - 1][3] + coef, min(dp[i - 1][2] + coef, dp[i - 1][1] + coef));
    }
    ll now = dp[n][3];
    for(ll i = 1; i <= n; ++i)
        now = min(now, dp[i][1] + ca * (n - i));
    return now;
}

main(){
    scanf("%lld %lld %lld", &n, &ca, &cb);
    for(ll i = 1; i <= n; ++i) scanf("%lld", &a[i]);
    vector < ll > pp = {a[1], a[1] + 1, a[1] - 1, a[n], a[n] + 1, a[n] - 1};
    for(auto i : pp){
        for(ll j = 2; j * j <= i; ++j){
            if(i % j == 0){
                while(i % j == 0)
                    i /= j;
                ans = min(ans, Solve(j));
            }
        }
        if(i > 1)
            ans = min(ans, Solve(i));
    }
    printf("%lld", ans);
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;

const ll maxN = ll(8e5);
const ll smaxN = ll(5e3);
const ll mmaxN = ll(3e4);
const ll lmaxN = ll(3e6);
const ll oo = ll(1e18);
const ll MOD = ll(1e9) + 7;
const ld EPS = 1e-10;
const ld PI = acos(0.0) * 2;
const ll dx[] = {-1, +0, +0, +1};
const ll dy[] = {+0, -1, +1, +0};

template < typename T >
T Sqr(T x) {
    return x * x;
}

template < class T >
ll Sz(T x) {
    return ll(x.size());
}

inline ll MultMod(ll a, ll b, ll mod) {
    if(b == 0)
        return 0;
    if(b % 2)
        return (MultMod(a, b - 1, mod) + a) % mod;
    return (MultMod(a, b / 2, mod) * 2) % mod;
}

inline ll ModPow(ll a, ll b, ll mod) {
    if(b == 0)
        return 1ll % mod;
    if(b == 1)
        return a % mod;
    if(b % 2)
        return MultMod(ModPow(a, b - 1, mod), a, mod) % mod;
    ll z = ModPow(a, b / 2, mod);
    return (MultMod(z, z, mod)) % mod;
}

void compress(vector < ll > &a){
    vector < ll > b(a);
    sort(b.begin(), b.end());
    b.erase(unique(b.begin(), b.end()), b.end());
    for(auto &i : a) i = lower_bound(b.begin(), b.end(), i) - b.begin() + 1;
}

inline bool Prime(ll x){
    if(x < 2)
        return 0;
    for(ll i = 2; i * i <= x; ++i)
        if(x % i == 0)
            return 0;
    return 1;
}

inline bool IsProbablePrime(ll x){
    return 1; // -> returns 1
}

const ll F = (ll)6e6;

ll n, ca, cb, ans = oo;
ll a[lmaxN], dp[lmaxN][4];

ll Solve(ll p){
    // 1 - Before
    // 2 - Begin
    // 3 - After
    for(ll i = 1; i <= n; ++i){
        ll coef = (a[i] % p == 0 ? 0 : ((a[i] - 1) % p == 0 || (a[i] + 1) % p == 0 ? cb : oo));
        dp[i][1] = min(oo, dp[i - 1][1] + coef);
        dp[i][2] = min(dp[i - 1][1] + ca, dp[i - 1][2] + ca);
        dp[i][3] = min(dp[i - 1][3] + coef, min(dp[i - 1][2] + coef, dp[i - 1][1] + coef));
    }
    ll now = dp[n][3];
    for(ll i = 1; i <= n; ++i)
        now = min(now, dp[i][1] + ca * (n - i));
    return now;
}

main(){
    scanf("%lld %lld %lld", &n, &ca, &cb);
    for(ll i = 1; i <= n; ++i) scanf("%lld", &a[i]);
    vector < ll > pp = {a[1], a[1] + 1, a[1] - 1, a[n], a[n] + 1, a[n] - 1};
    for(auto i : pp){
        for(ll j = 2; j * j <= i; ++j){
            if(i % j == 0){
                while(i % j == 0)
                    i /= j;
                ans = min(ans, Solve(j));
            }
        }
        if(i > 1)
            ans = min(ans, Solve(i));
    }
    printf("%lld", ans);
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;

const ll maxN = ll(8e5);
const ll smaxN = ll(5e3);
const ll mmaxN = ll(3e4);
const ll lmaxN = ll(3e6);
const ll oo = ll(1e18);
const ll MOD = ll(1e9) + 7;
const ld EPS = 1e-10;
const ld PI = acos(0.0) * 2;
const ll dx[] = {-1, +0, +0, +1};
const ll dy[] = {+0, -1, +1, +0};

template < typename T >
T Sqr(T x) {
    return x * x;
}

template < class T >
ll Sz(T x) {
    return ll(x.size());
}

inline ll MultMod(ll a, ll b, ll mod) {
    if(b == 0)
        return 0;
    if(b % 2)
        return (MultMod(a, b - 1, mod) + a) % mod;
    return (MultMod(a, b / 2, mod) * 2) % mod;
}

inline ll ModPow(ll a, ll b, ll mod) {
    if(b == 0)
        return 1ll % mod;
    if(b == 1)
        return a % mod;
    if(b % 2)
        return MultMod(ModPow(a, b - 1, mod), a, mod) % mod;
    ll z = ModPow(a, b / 2, mod);
    return (MultMod(z, z, mod)) % mod;
}

void compress(vector < ll > &a){
    vector < ll > b(a);
    sort(b.begin(), b.end());
    b.erase(unique(b.begin(), b.end()), b.end());
    for(auto &i : a) i = lower_bound(b.begin(), b.end(), i) - b.begin() + 1;
}

inline bool Prime(ll x){
    if(x < 2)
        return 0;
    for(ll i = 2; i * i <= x; ++i)
        if(x % i == 0)
            return 0;
    return 1;
}

inline bool IsProbablePrime(ll x){
    return 1; // -> returns 1
}

const ll F = (ll)6e6;

ll n, ca, cb, ans = oo;
ll a[maxN], dp[maxN][4];

ll Solve(ll p){
    // 1 - Before
    // 2 - Begin
    // 3 - After
    dp[0][2] = oo;
    for(ll i = 1; i <= n; ++i){
        ll coef = (a[i] % p == 0 ? 0 : ((a[i] - 1) % p == 0 || (a[i] + 1) % p == 0 ? cb : oo));
        dp[i][1] = dp[i - 1][1] + coef;
        dp[i][2] = min(dp[i - 1][1] + ca, dp[i - 1][2] + ca);
        dp[i][3] = min(dp[i - 1][3] + coef, min(dp[i - 1][2] + coef, dp[i - 1][1] + coef));
    }
    ll now = dp[n][3];
    for(ll i = 1; i <= n; ++i)
        now = min(now, dp[i][1] + ca * (n - i));
    return now;
}

main(){
    scanf("%lld %lld %lld", &n, &ca, &cb);
    for(ll i = 1; i <= n; ++i) scanf("%lld", &a[i]);
    vector < ll > pp = {a[1], a[1] + 1, a[1] - 1, a[n], a[n] + 1, a[n] - 1};
    for(auto i : pp){
        for(ll j = 2; j * j <= i; ++j){
            if(i % j == 0){
                while(i % j == 0)
                    i /= j;
                ans = min(ans, Solve(j));
            }
        }
        if(i > 1)
            ans = min(ans, Solve(i));
    }
    printf("%lld", ans);
    return 0;
}


//
//  Created by TaoSama on 2016-02-05
//  Copyright (c) 2016 TaoSama. All rights reserved.
//
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e6 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int n, A, B;
int a[N];
long long f[N], g[N];

long long gao(int p) {
    int pos = -1;
    for(int i = 1; i <= n; ++i) {
        if(a[i] % p == 0) g[i] = g[i - 1];
        else if((a[i] + 1) % p == 0 || (a[i] - 1) % p == 0)
            g[i] = g[i - 1] + B;
        else break;
        pos = i;
    }
    for(int i = 1; i <= n; ++i) {
        f[i] = f[i - 1] + A;
        if(i <= pos) f[i] = min(f[i], g[i]);
    }
    g[n + 1] = 0;
    long long ret = f[n];
    for(int i = n; i; --i) {
        if(a[i] % p == 0) g[i] = g[i + 1];
        else if((a[i] + 1) % p == 0 || (a[i] - 1) % p == 0)
            g[i] = g[i + 1] + B;
        else break;
        ret = min(ret, f[i - 1] + g[i]);
    }
    return ret;
}

int main() {
#ifdef LOCAL
    freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
//  freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);

    while(scanf("%d%d%d", &n, &A, &B) == 3) {
        for(int i = 1; i <= n; ++i) scanf("%d", a + i);
        int leave[] = {a[1], a[n]};
        long long ans = 1e18;
        for(int i = 0; i < 2; ++i) {
            for(int d = -1; d <= 1; ++d) {
                int x = leave[i] + d;
                for(int j = 2; j * j <= x; ++j) {
                    if(x % j == 0) {
                        ans = min(ans, gao(j));
                        while(x % j == 0) x /= j;
                    }
                }
                if(x > 1) ans = min(ans, gao(x));
            }
        }
        printf("%I64d\n", ans);
    }
    return 0;
}


//
//  Created by TaoSama on 2016-02-05
//  Copyright (c) 2016 TaoSama. All rights reserved.
//
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e6 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int n, A, B;
int a[N];
long long f[2][3]; //0->removed array, not started, 1->removing, 2->finished

inline void getMin(long long &x, long long y) {
    if(x > y) x = y;
}

int getCost(int i, int p) {
    if(a[i] % p == 0) return 0;
    else if((a[i] + 1) % p == 0 || (a[i] - 1) % p == 0) return B;
    return INF;
}

void see(int i, int s) {
    for(int j = 0; j < 3; ++j)
        printf("f[%d][%d]=%I64d\n", i, j, f[s][j]);
}

long long gao(int p) {
    int s = 0, cost = getCost(1, p);
    memset(f[s], 0x3f, sizeof f[s]);
    if(cost != INF) f[s][0] = f[s][2] = cost;
    f[s][1] = A;
//    if(p == 2) see(1, s);
    for(int i = 2; i <= n; ++i) {
        memset(f[!s], 0x3f, sizeof f[!s]);
        int cost = getCost(i, p);
        if(cost != INF) {
            getMin(f[!s][0], f[s][0] + cost);
            getMin(f[!s][2], f[s][2] + cost);
        }
        getMin(f[!s][1], f[s][0] + A); //start removing
        getMin(f[!s][1], f[s][1] + A); //removing
        getMin(f[!s][2], f[s][0] + A); //finish right away
        getMin(f[!s][2], f[s][1] + A); //finish removing
        s = !s;
//      if(p == 2) see(i, s);
    }
    long long ret = min(f[s][0], f[s][2]);
    return ret;
}

int main() {
#ifdef LOCAL
    freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
//  freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);

    while(scanf("%d%d%d", &n, &A, &B) == 3) {
        for(int i = 1; i <= n; ++i) scanf("%d", a + i);
        int leave[] = {a[1], a[n]};
        long long ans = 1e18;
        for(int i = 0; i < 2; ++i) {
            for(int d = -1; d <= 1; ++d) {
                int x = leave[i] + d;
                for(int j = 2; j * j <= x; ++j) {
                    if(x % j == 0) {
                        ans = min(ans, gao(j));
                        while(x % j == 0) x /= j;
                    }
                }
                if(x > 1) ans = min(ans, gao(x));
            }
        }
        printf("%I64d\n", ans);
//        return 0;
    }
    return 0;
}


//
//  Created by TaoSama on 2016-02-05
//  Copyright (c) 2016 TaoSama. All rights reserved.
//
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e6 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int n, A, B;
int a[N];
long long f[2][3]; //0->removed array, not started, 1->removing, 2->finished

inline void getMin(long long &x, long long y) {
    if(x > y) x = y;
}

int getCost(int i, int p) {
    if(a[i] % p == 0) return 0;
    else if((a[i] + 1) % p == 0 || (a[i] - 1) % p == 0) return B;
    return INF;
}

void see(int i, int s) {
    for(int j = 0; j < 3; ++j)
        printf("f[%d][%d]=%I64d\n", i, j, f[s][j]);
}

long long gao(int p) {
    int s = 0;
    memset(f[s], 0, sizeof f[s]);
    for(int i = 1; i <= n; ++i) {
        memset(f[!s], 0x3f, sizeof f[!s]);
        int cost = getCost(i, p);
        if(cost != INF) {
            getMin(f[!s][0], f[s][0] + cost);
            getMin(f[!s][2], f[s][2] + cost);
        }
        getMin(f[!s][1], f[s][0] + A); //start removing
        getMin(f[!s][1], f[s][1] + A); //removing
        getMin(f[!s][2], f[s][0] + A); //finish right away
        getMin(f[!s][2], f[s][1] + A); //finish removing
        s = !s;
//      if(p == 2) see(i, s);
    }
    return min(f[s][0], f[s][2]);
}

int main() {
#ifdef LOCAL
    freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
//  freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);

    while(scanf("%d%d%d", &n, &A, &B) == 3) {
        for(int i = 1; i <= n; ++i) scanf("%d", a + i);
        int leave[] = {a[1], a[n]};
        long long ans = 1e18;
        for(int i = 0; i < 2; ++i) {
            for(int d = -1; d <= 1; ++d) {
                int x = leave[i] + d;
                for(int j = 2; j * j <= x; ++j) {
                    if(x % j == 0) {
                        ans = min(ans, gao(j));
                        while(x % j == 0) x /= j;
                    }
                }
                if(x > 1) ans = min(ans, gao(x));
            }
        }
        printf("%I64d\n", ans);
        //        return 0;
    }
    return 0;
}


//
//  Created by TaoSama on 2016-02-05
//  Copyright (c) 2016 TaoSama. All rights reserved.
//
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e6 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int n, A, B;
int a[N];
long long f[2][3]; //0->removed array, not started, 1->removing, 2->finished

inline void getMin(long long &x, long long y) {
    if(x > y) x = y;
}

int getCost(int i, int p) {
    if(a[i] % p == 0) return 0;
    else if((a[i] + 1) % p == 0 || (a[i] - 1) % p == 0) return B;
    return INF;
}

void see(int i, int s) {
    for(int j = 0; j < 3; ++j)
        printf("f[%d][%d]=%I64d\n", i, j, f[s][j]);
}

long long gao(int p) {
    int s = 0, cost = getCost(1, p);
    memset(f[s], 0, sizeof f[s]);
//    if(p == 2) see(1, s);
    for(int i = i; i <= n; ++i) {
        memset(f[!s], 0x3f, sizeof f[!s]);
        int cost = getCost(i, p);
        if(cost != INF) {
            getMin(f[!s][0], f[s][0] + cost);
            getMin(f[!s][2], f[s][2] + cost);
        }
        getMin(f[!s][1], f[s][0] + A); //start removing
        getMin(f[!s][1], f[s][1] + A); //removing
        getMin(f[!s][2], f[s][0] + A); //finish right away
        getMin(f[!s][2], f[s][1] + A); //finish removing
        s = !s;
//      if(p == 2) see(i, s);
    }
    long long ret = min(f[s][0], f[s][2]);
    return ret;
}

int main() {
#ifdef LOCAL
    freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
//  freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);

    while(scanf("%d%d%d", &n, &A, &B) == 3) {
        for(int i = 1; i <= n; ++i) scanf("%d", a + i);
        int leave[] = {a[1], a[n]};
        long long ans = 1e18;
        for(int i = 0; i < 2; ++i) {
            for(int d = -1; d <= 1; ++d) {
                int x = leave[i] + d;
                for(int j = 2; j * j <= x; ++j) {
                    if(x % j == 0) {
                        ans = min(ans, gao(j));
                        while(x % j == 0) x /= j;
                    }
                }
                if(x > 1) ans = min(ans, gao(x));
            }
        }
        printf("%I64d\n", ans);
//        return 0;
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
using namespace std;

typedef long long ll;

const int N = 1000010;
const ll inf = 1000000000000000000LL;

int a[N];
ll prefix_cost[N], cost[N], suffix_cost[N];
set<int> factors;
set<int>::iterator it;

void pf(int x) {
	for (int j = x - 1; j <= x + 1; j++) {
		int d = j;
		for (int i = 2; i*i <= j; i++) {
			if (d % i == 0) {
				factors.insert(i);
				while (d % i == 0) d /= i;
			}
		}
		if (d != 1) factors.insert(d);
	}
}

int main() {

	int n, p, A, B;
	scanf("%d %d %d", &n, &A, &B);

	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);

	if (n == 1) {
		printf("0\n");
		return 0;
	}

	// prime factors
	pf(a[1]);
	pf(a[n]);

	ll ans = inf;
	for (it = factors.begin(); it != factors.end(); ++it) {
		prefix_cost[0] = 0LL;
		p = *it;

		//printf("prime %d\n", p);
		for (int i = 1; i <= n; i++) {
			if (a[i] % p == 0)
				cost[i] = 0LL;
			else if ((a[i] + 1) % p == 0 || (a[i] - 1) % p == 0)
				cost[i] = (ll) B;
			else
				cost[i] = inf;

			//printf("prefix_cost[%d] = %lld\n", i, cost[i]);
			prefix_cost[i] = prefix_cost[i - 1] + cost[i];
			if (prefix_cost[i] > inf)
				prefix_cost[i] = inf;
		}

		prefix_cost[0] = inf;
		suffix_cost[n + 1] = 0LL;

		ll suffix_sum = 0LL;
		ans = min((ll) a, prefix_cost[1]);
		for (int i = n; i > 0; i--) {
			suffix_sum += cost[i];
			if (suffix_sum > inf)
				suffix_sum = inf;
			suffix_cost[i] = min(A + suffix_cost[i + 1], suffix_sum);
			// Min(ans, prefix_cost[1 .. i-1] + suffix[i..n])
			// prefix_cost[1 .. i-1] = minimum B operations to correct this interval
			// suffix_cost[i .. n] = minimum A operation to correct some interval forward (at most one)
			ans = min(ans, prefix_cost[i - 1] + suffix_cost[i]);
		}
	}

	printf("%I64d\n", ans);
	return 0;
}