#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];
		}

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

		ll suffix_sum = 0LL;
		for (int i = n; i > 0; i--) {
			suffix_sum += cost[i];
			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;
}


#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;
		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;
}


#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]);

	// 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];
		}

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

		ll suffix_sum = 0LL;
		for (int i = n; i > 0; i--) {
			suffix_sum += cost[i];
			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;
}


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

typedef long long ll;

const int N = 100100;
const ll inf = 1000000000000000000L;

int arr[N];
ll prefix[N], cost[N], suffix[N];
set<int> factors;
set<int>::iterator it;

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

int main() {

	int n, a, b, p;
	scanf("%d %d %d", &n, &a, &b);

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

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

	pf(arr[1]);
	pf(arr[n]);

	ll ans = inf;
	for (it = factors.begin(); it != factors.end(); ++it) {
		int p = *it;
		prefix[0] = 0LL;
		for (int i = 1; i <= n; i++) {
			if (arr[i] % p == 0)
				cost[i] = 0LL;
			else if ((arr[i] + 1) % p == 0 || (arr[i] - 1) % p == 0)
				cost[i] = (ll) b;
			else
				cost[i] = inf;

			prefix[i] = prefix[i - 1] + cost[i];
			if (prefix[i] > inf)
				prefix[i] = inf;
		}

		prefix[0] = inf;
		suffix[n + 1] = 0LL;

		ll suffix_sum = 0LL;
		for (int i = n; i > 0; i--) {
			suffix_sum += cost[i];
			if (suffix_sum > inf)
				suffix_sum = inf;
			suffix[i] = min(a + suffix[i + 1], suffix_sum);
		}

		ans = min(ans, suffix[1]);
		for (int i = 2; i <= n; i++) {
			ans = min(ans, prefix[i-1] + suffix[i]);
		}
	}

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


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

typedef long long ll;

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

ll arr[N], prefix[N], cost[N], suffix[N];
set<int> factors;
set<int>::iterator it;

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

int main() {

	int n, a, b, p;
	scanf("%d %d %d", &n, &a, &b);

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

	pf(arr[1]);
	pf(arr[n]);

	ll ans = inf;
	for (it = factors.begin(); it != factors.end(); ++it) {
		int p = *it;
		prefix[0] = 0LL;
		for (int i = 1; i <= n; i++) {
			if (arr[i] % p == 0)
				cost[i] = 0LL;
			else if ((arr[i] + 1) % p == 0 || (arr[i] - 1) % p == 0)
				cost[i] = (ll) b;
			else
				cost[i] = inf;

			prefix[i] = prefix[i - 1] + cost[i];
			if (prefix[i] > inf)
				prefix[i] = inf;
		}

		prefix[0] = inf;
		suffix[n + 1] = 0LL;

		ll suffix_sum = 0LL;
		for (int i = n; i > 0; i--) {
			suffix_sum += cost[i];
			if (suffix_sum > inf)
				suffix_sum = inf;
			suffix[i] = min(a + suffix[i + 1], suffix_sum);
		}

		ans = min(ans, suffix[1]);
		for (int i = 2; i <= n; i++) {
			ans = min(ans, prefix[i-1] + suffix[i]);
		}
	}

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


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

typedef long long ll;

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

int arr[N];
ll prefix[N], cost[N], suffix[N];
set<int> factors;
set<int>::iterator it;

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

int main() {

	int n, a, b, p;
	scanf("%d %d %d", &n, &a, &b);

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

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

	pf(arr[1]);
	pf(arr[n]);

	ll ans = inf;
	for (it = factors.begin(); it != factors.end(); ++it) {
		int p = *it;
		prefix[0] = 0LL;
		for (int i = 1; i <= n; i++) {
			if (arr[i] % p == 0)
				cost[i] = 0LL;
			else if ((arr[i] + 1) % p == 0 || (arr[i] - 1) % p == 0)
				cost[i] = (ll) b;
			else
				cost[i] = inf;

			prefix[i] = prefix[i - 1] + cost[i];
			if (prefix[i] > inf)
				prefix[i] = inf;
		}

		prefix[0] = inf;
		suffix[n + 1] = 0LL;

		ll suffix_sum = 0LL;
		for (int i = n; i > 0; i--) {
			suffix_sum += cost[i];
			if (suffix_sum > inf)
				suffix_sum = inf;
			suffix[i] = min(a + suffix[i + 1], suffix_sum);
		}

		ans = min(ans, suffix[1]);
		for (int i = 2; i <= n; i++) {
			ans = min(ans, prefix[i-1] + suffix[i]);
		}
	}

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


#include <bits/stdc++.h>
#define X first
#define Y second
#define psb push_back
#define pob pop_back
#define mp make_pair
#define ll long long
#define scand(n) scanf("%d",&n)
#define scanld(n) scanf("%lld",&n)
#define printd(n) printf("%d\n",n)
#define printld(n) printf("%lld\n",n)
#define all(x) x.begin(),x.end()
#define SET( arr, val) memset(arr,val,sizeof(arr))
#define ITR iterator
#define SZ(arr) arr.size()
#define FOR( i, L, U ) for(int i=(int)L ; i<(int)U ; ++i )
#define FORI( i, L, U ) for(int i=(int)L ; i<=(int)U ; ++i )
#define FORD( i, U, L ) for(int i=(int)U ; i>=(int)L ; --i )
#define Tcases(t) int t;cin>>t;while(t--)

using namespace std;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

vi arr;
vector<vl> dp;      //dp[i][0]=min value when no removal done yet
                    //d[i][1]=min value when segment to be removed is active
                    //d[i][2]=min value when segment to be removed has ended

int n,a,b;
unordered_set<int> hsh;
vi primes;
ll inf=1234567890123456;

void chck(int x){
    if(x%2==0){
        if(!hsh.count(2))
            hsh.insert(2);
        while(x%2==0)
            x>>=1;
    }
    for(int i=3;i*i<=x;i+=2)
        if(x%i==0){
            if(!hsh.count(i)){
                hsh.insert(i);
                primes.psb(i);
            }
            while(x%i==0)
                x/=i;
        }
    if(x!=1 && !hsh.count(x)){
        hsh.insert(x);
        primes.psb(x);
    }
}

void init(){
    for(int ele:arr){
        chck(ele-1);
        chck(ele);
        chck(ele+1);
    }
}

int main() {
	//ios_base::sync_with_stdio(false);
	//cin>>n>>a>>b;
	scand(n);
	scand(a);
	scand(b);
	arr.resize(n);
	FOR(i,0,n)
        scand(arr[i]);
        //cin>>arr[i];
	init();
	dp.resize(n,vl(3));
	ll ans=inf;

	for(int p:primes){
        if(arr[0]%p==0)
            dp[0][0]=0;
        else if((arr[0]+1)%p==0||(arr[0]-1)%p==0)
            dp[0][0]=b;
        else
            dp[0][0]=inf;

        dp[0][1]=a;
        dp[0][2]=a;

        FOR(i,1,n){
            if(arr[i]%p==0){
                dp[i][0]=dp[i-1][0];
                dp[i][1]=min(dp[i-1][0],dp[i-1][1])+a;
                dp[i][2]=min(dp[i][1],dp[i-1][2]);
            }
            else if((arr[i]-1)%p==0 || (arr[i]+1)%p==0){
                dp[i][0]=dp[i-1][0]+b;
                dp[i][1]=min(dp[i-1][0],dp[i-1][1])+a;
                dp[i][2]=min(dp[i][1],dp[i-1][2]+b);
            }
            else{
                dp[i][0]=inf;
                dp[i][1]=min(dp[i-1][0],dp[i-1][1])+a;
                dp[i][2]=dp[i][1];
            }
        }
        ans=min(ans,min(dp[n-1][0],dp[n-1][2]));
	}
	//cout<<ans;
	printld(ans);
	return 0;
}


#include <bits/stdc++.h>
#define X first
#define Y second
#define psb push_back
#define pob pop_back
#define mp make_pair
#define ll long long
#define scand(n) scanf("%d",&n)
#define scanld(n) scanf("%lld",&n)
#define printd(n) printf("%d\n",n)
#define printld(n) printf("%lld\n",n)
#define all(x) x.begin(),x.end()
#define SET( arr, val) memset(arr,val,sizeof(arr))
#define ITR iterator
#define SZ(arr) arr.size()
#define FOR( i, L, U ) for(int i=(int)L ; i<(int)U ; ++i )
#define FORI( i, L, U ) for(int i=(int)L ; i<=(int)U ; ++i )
#define FORD( i, U, L ) for(int i=(int)U ; i>=(int)L ; --i )
#define Tcases(t) int t;cin>>t;while(t--)

using namespace std;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

vi arr;
vector<vl> dp;      //dp[i][0]=min value when no removal done yet
                    //d[i][1]=min value when segment to be removed is active
                    //d[i][2]=min value when segment to be removed has ended

int n,a,b;
unordered_set<int> hsh;
vi primes;
ll inf=1234567890123456;

void chck(int x){
    for(int i=2;i*i<=x;i++)
        if(x%i==0){
            if(!hsh.count(i)){
                hsh.insert(i);
                primes.psb(i);
            }
            while(x%i==0)
                x/=i;
        }
    if(x!=1 && !hsh.count(x)){
        hsh.insert(x);
        primes.psb(x);
    }
}

void init(){
    for(int ele:arr){
        chck(ele-1);
        chck(ele);
        chck(ele+1);
    }
}

int main() {
	ios_base::sync_with_stdio(false);
	cin>>n>>a>>b;
	arr.resize(n);
	FOR(i,0,n)
        cin>>arr[i];
	init();
	dp.resize(n,vl(3));
	ll ans=inf;

	for(int p:primes){
        if(arr[0]%p==0)
            dp[0][0]=0;
        else if((arr[0]+1)%p==0||(arr[0]-1)%p==0)
            dp[0][0]=b;
        else
            dp[0][0]=inf;

        dp[0][1]=a;
        dp[0][2]=a;

        FOR(i,1,n){
            if(arr[i]%p==0){
                dp[i][0]=dp[i-1][0];
                dp[i][1]=min(dp[i-1][0],dp[i-1][1])+a;
                dp[i][2]=min(dp[i][1],dp[i-1][2]);
            }
            else if((arr[i]-1)%p==0 || (arr[i]+1)%p==0){
                dp[i][0]=dp[i-1][0]+b;
                dp[i][1]=min(dp[i-1][0],dp[i-1][1])+a;
                dp[i][2]=min(dp[i][1],dp[i-1][2]+b);
            }
            else{
                dp[i][0]=inf;
                dp[i][1]=min(dp[i-1][0],dp[i-1][1])+a;
                dp[i][2]=dp[i][1];
            }
        }
        ans=min(ans,min(dp[n-1][0],dp[n-1][2]));
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
#define X first
#define Y second
#define psb push_back
#define pob pop_back
#define mp make_pair
#define ll long long
#define scand(n) scanf("%d",&n)
#define scanld(n) scanf("%lld",&n)
#define printd(n) printf("%d\n",n)
#define printld(n) printf("%lld\n",n)
#define all(x) x.begin(),x.end()
#define SET( arr, val) memset(arr,val,sizeof(arr))
#define ITR iterator
#define SZ(arr) arr.size()
#define FOR( i, L, U ) for(int i=(int)L ; i<(int)U ; ++i )
#define FORI( i, L, U ) for(int i=(int)L ; i<=(int)U ; ++i )
#define FORD( i, U, L ) for(int i=(int)U ; i>=(int)L ; --i )
#define Tcases(t) int t;cin>>t;while(t--)

using namespace std;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

int arr[1000005];
ll dp[1000005][3];      //dp[i][0]=min value when no removal done yet
                    //d[i][1]=min value when segment to be removed is active
                    //d[i][2]=min value when segment to be removed has ended

int n,a,b;
set<int> hsh;
vi primes;
ll inf=1e16;

void chck(int x){
    if(x%2==0){
        if(!hsh.count(2)){
            hsh.insert(2);
            primes.psb(2);
        }
        while(x%2==0)
            x>>=1;
    }
    for(int i=3;i*i<=x;i+=2)
        if(x%i==0){
            if(!hsh.count(i)){
                hsh.insert(i);
                primes.psb(i);
            }
            while(x%i==0)
                x/=i;
        }
    if(x!=1 && !hsh.count(x)){
        hsh.insert(x);
        primes.psb(x);
    }
}

void init(){
    FOR(i,0,n){
        chck(arr[i]-1);
        chck(arr[i]);
        chck(arr[i]+1);
    }
}

int main() {
	//ios_base::sync_with_stdio(false);
	//cin>>n>>a>>b;
	scand(n);
	scand(a);
	scand(b);
//	arr.resize(n);
	FOR(i,0,n)
        scand(arr[i]);
        //cin>>arr[i];
	init();
//	dp.resize(n,vl(3));
	ll ans=inf;

	for(int p:primes){
  //      cout<<"p "<<p<<endl;
        if(arr[0]%p==0)
            dp[0][0]=0;
        else if((arr[0]+1)%p==0||(arr[0]-1)%p==0)
            dp[0][0]=b;
        else
            dp[0][0]=inf;

        dp[0][1]=a;
        dp[0][2]=a;

        FOR(i,1,n){
            if(arr[i]%p==0){
                dp[i][0]=dp[i-1][0];
                dp[i][1]=min(dp[i-1][0],dp[i-1][1])+a;
                dp[i][2]=min(dp[i][1],dp[i-1][2]);
            }
            else if((arr[i]-1)%p==0 || (arr[i]+1)%p==0){
                dp[i][0]=dp[i-1][0]+b;
                dp[i][1]=min(dp[i-1][0],dp[i-1][1])+a;
                dp[i][2]=min(dp[i][1],dp[i-1][2]+b);
            }
            else{
                dp[i][0]=inf;
                dp[i][1]=min(dp[i-1][0],dp[i-1][1])+a;
                dp[i][2]=dp[i][1];
            }
        }
        ans=min(ans,min(dp[n-1][0],dp[n-1][2]));
	}
	//cout<<ans;
	printld(ans);
	return 0;
}


#include <bits/stdc++.h>
#define X first
#define Y second
#define psb push_back
#define pob pop_back
#define mp make_pair
#define ll long long
#define scand(n) scanf("%d",&n)
#define scanld(n) scanf("%lld",&n)
#define printd(n) printf("%d\n",n)
#define printld(n) printf("%lld\n",n)
#define all(x) x.begin(),x.end()
#define SET( arr, val) memset(arr,val,sizeof(arr))
#define ITR iterator
#define SZ(arr) arr.size()
#define FOR( i, L, U ) for(int i=(int)L ; i<(int)U ; ++i )
#define FORI( i, L, U ) for(int i=(int)L ; i<=(int)U ; ++i )
#define FORD( i, U, L ) for(int i=(int)U ; i>=(int)L ; --i )
#define Tcases(t) int t;cin>>t;while(t--)

using namespace std;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

int arr[1000005];
ll dp[1000005][3];      //dp[i][0]=min value when no removal done yet
                    //d[i][1]=min value when segment to be removed is active
                    //d[i][2]=min value when segment to be removed has ended

int n,a,b;
set<int> hsh;
vi primes;
ll inf=1e16;

void chck(int x){
    if(x%2==0){
        if(!hsh.count(2)){
            hsh.insert(2);
            primes.psb(2);
        }
        while(x%2==0)
            x>>=1;
    }
    for(int i=3;i*i<=x;i+=2)
        if(x%i==0){
            if(!hsh.count(i)){
                hsh.insert(i);
                primes.psb(i);
            }
            while(x%i==0)
                x/=i;
        }
    if(x!=1 && !hsh.count(x)){
        hsh.insert(x);
        primes.psb(x);
    }
}

void init(){

        chck(arr[0]-1);
        chck(arr[0]);
        chck(arr[0]+1);

        chck(arr[n-1]-1);
        chck(arr[n-1]);
        chck(arr[n-1]+1);

}

int main() {
	//ios_base::sync_with_stdio(false);
	//cin>>n>>a>>b;
	scand(n);
	scand(a);
	scand(b);
//	arr.resize(n);
	FOR(i,0,n)
        scand(arr[i]);
        //cin>>arr[i];
	init();
//	dp.resize(n,vl(3));
	ll ans=inf;

	for(int p:primes){
  //      cout<<"p "<<p<<endl;
        if(arr[0]%p==0)
            dp[0][0]=0;
        else if((arr[0]+1)%p==0||(arr[0]-1)%p==0)
            dp[0][0]=b;
        else
            dp[0][0]=inf;

        dp[0][1]=a;
        dp[0][2]=a;

        FOR(i,1,n){
            if(arr[i]%p==0){
                dp[i][0]=dp[i-1][0];
                dp[i][1]=min(dp[i-1][0],dp[i-1][1])+a;
                dp[i][2]=min(dp[i][1],dp[i-1][2]);
            }
            else if((arr[i]-1)%p==0 || (arr[i]+1)%p==0){
                dp[i][0]=dp[i-1][0]+b;
                dp[i][1]=min(dp[i-1][0],dp[i-1][1])+a;
                dp[i][2]=min(dp[i][1],dp[i-1][2]+b);
            }
            else{
                dp[i][0]=inf;
                dp[i][1]=min(dp[i-1][0],dp[i-1][1])+a;
                dp[i][2]=dp[i][1];
            }
        }
        ans=min(ans,min(dp[n-1][0],dp[n-1][2]));
	}
	//cout<<ans;
	printld(ans);
	return 0;
}


#include <bits/stdc++.h>
#define X first
#define Y second
#define psb push_back
#define pob pop_back
#define mp make_pair
#define ll long long
#define scand(n) scanf("%d",&n)
#define scanld(n) scanf("%lld",&n)
#define printd(n) printf("%d\n",n)
#define printld(n) printf("%lld\n",n)
#define all(x) x.begin(),x.end()
#define SET( arr, val) memset(arr,val,sizeof(arr))
#define ITR iterator
#define SZ(arr) arr.size()
#define FOR( i, L, U ) for(int i=(int)L ; i<(int)U ; ++i )
#define FORI( i, L, U ) for(int i=(int)L ; i<=(int)U ; ++i )
#define FORD( i, U, L ) for(int i=(int)U ; i>=(int)L ; --i )
#define Tcases(t) int t;cin>>t;while(t--)

using namespace std;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

vi arr;
vector<vl> dp;      //dp[i][0]=min value when no removal done yet
                    //d[i][1]=min value when segment to be removed is active
                    //d[i][2]=min value when segment to be removed has ended

int n,a,b;
set<int> primes;
ll inf=1234567890123456;

void chck(int x){
    for(int i=2;i*i<=x;i++)
        if(x%i==0){
            primes.insert(i);
            while(x%i==0)
                x/=i;
        }
    if(x!=1)
        primes.insert(x);
}

void init(){
    for(int ele:arr){
        chck(ele-1);
        chck(ele);
        chck(ele+1);
    }
}

int main() {
	ios_base::sync_with_stdio(false);
	cin>>n>>a>>b;
	arr.resize(n);
	FOR(i,0,n)
        cin>>arr[i];
	init();
	dp.resize(n,vl(3));
	ll ans=inf;

	for(int p:primes){
        if(arr[0]%p==0)
            dp[0][0]=0;
        else if((arr[0]+1)%p==0||(arr[0]-1)%p==0)
            dp[0][0]=b;
        else
            dp[0][0]=inf;

        dp[0][1]=a;
        dp[0][2]=a;

        FOR(i,1,n){
            if(arr[i]%p==0){
                dp[i][0]=dp[i-1][0];
                dp[i][1]=min(dp[i-1][0],dp[i-1][1])+a;
                dp[i][2]=min(dp[i][1],dp[i-1][2]);
            }
            else if((arr[i]-1)%p==0 || (arr[i]+1)%p==0){
                dp[i][0]=dp[i-1][0]+b;
                dp[i][1]=min(dp[i-1][0],dp[i-1][1])+a;
                dp[i][2]=min(dp[i][1],dp[i-1][2]+b);
            }
            else{
                dp[i][0]=inf;
                dp[i][1]=min(dp[i-1][0],dp[i-1][1])+a;
                dp[i][2]=dp[i][1];
            }
        }
        ans=min(ans,min(dp[n-1][0],dp[n-1][2]));
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
#define X first
#define Y second
#define psb push_back
#define pob pop_back
#define mp make_pair
#define ll long long
#define scand(n) scanf("%d",&n)
#define scanld(n) scanf("%lld",&n)
#define printd(n) printf("%d\n",n)
#define printld(n) printf("%lld\n",n)
#define all(x) x.begin(),x.end()
#define SET( arr, val) memset(arr,val,sizeof(arr))
#define ITR iterator
#define SZ(arr) arr.size()
#define FOR( i, L, U ) for(int i=(int)L ; i<(int)U ; ++i )
#define FORI( i, L, U ) for(int i=(int)L ; i<=(int)U ; ++i )
#define FORD( i, U, L ) for(int i=(int)U ; i>=(int)L ; --i )
#define Tcases(t) int t;cin>>t;while(t--)

using namespace std;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

vi arr;
vector<vl> dp;      //dp[i][0]=min value when no removal done yet
                    //d[i][1]=min value when segment to be removed is active
                    //d[i][2]=min value when segment to be removed has ended

int n,a,b;
unordered_set<int> hsh;
vi primes;
ll inf=1234567890123456;

void chck(int x){
    if(x%2==0){
        if(!hsh.count(2)){
            hsh.insert(2);
            primes.psb(2);
        }
        while(x%2==0)
            x>>=1;
    }
    for(int i=3;i*i<=x;i+=2)
        if(x%i==0){
            if(!hsh.count(i)){
                hsh.insert(i);
                primes.psb(i);
            }
            while(x%i==0)
                x/=i;
        }
    if(x!=1 && !hsh.count(x)){
        hsh.insert(x);
        primes.psb(x);
    }
}

void init(){
    for(int ele:arr){
        chck(ele-1);
        chck(ele);
        chck(ele+1);
    }
}

int main() {
	//ios_base::sync_with_stdio(false);
	//cin>>n>>a>>b;
	scand(n);
	scand(a);
	scand(b);
	arr.resize(n);
	FOR(i,0,n)
        scand(arr[i]);
        //cin>>arr[i];
	init();
	dp.resize(n,vl(3));
	ll ans=inf;

	for(int p:primes){
        if(arr[0]%p==0)
            dp[0][0]=0;
        else if((arr[0]+1)%p==0||(arr[0]-1)%p==0)
            dp[0][0]=b;
        else
            dp[0][0]=inf;

        dp[0][1]=a;
        dp[0][2]=a;

        FOR(i,1,n){
            if(arr[i]%p==0){
                dp[i][0]=dp[i-1][0];
                dp[i][1]=min(dp[i-1][0],dp[i-1][1])+a;
                dp[i][2]=min(dp[i][1],dp[i-1][2]);
            }
            else if((arr[i]-1)%p==0 || (arr[i]+1)%p==0){
                dp[i][0]=dp[i-1][0]+b;
                dp[i][1]=min(dp[i-1][0],dp[i-1][1])+a;
                dp[i][2]=min(dp[i][1],dp[i-1][2]+b);
            }
            else{
                dp[i][0]=inf;
                dp[i][1]=min(dp[i-1][0],dp[i-1][1])+a;
                dp[i][2]=dp[i][1];
            }
        }
        ans=min(ans,min(dp[n-1][0],dp[n-1][2]));
	}
	//cout<<ans;
	printld(ans);
	return 0;
}


#include <bits/stdc++.h>
#define X first
#define Y second
#define psb push_back
#define pob pop_back
#define mp make_pair
#define ll long long
#define scand(n) scanf("%d",&n)
#define scanld(n) scanf("%lld",&n)
#define printd(n) printf("%d\n",n)
#define printld(n) printf("%lld\n",n)
#define all(x) x.begin(),x.end()
#define SET( arr, val) memset(arr,val,sizeof(arr))
#define ITR iterator
#define SZ(arr) arr.size()
#define FOR( i, L, U ) for(int i=(int)L ; i<(int)U ; ++i )
#define FORI( i, L, U ) for(int i=(int)L ; i<=(int)U ; ++i )
#define FORD( i, U, L ) for(int i=(int)U ; i>=(int)L ; --i )
#define Tcases(t) int t;cin>>t;while(t--)

using namespace std;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

vi arr;
vector<vl> dp;      //dp[i][0]=min value when no removal done yet
                    //d[i][1]=min value when segment to be removed is active
                    //d[i][2]=min value when segment to be removed has ended

int n,a,b;
unordered_set<int> hsh;
vi primes;
ll inf=1234567890123456;

void chck(int x){
    for(int i=2;i*i<=x;i++)
        if(x%i==0){
            if(!hsh.count(i)){
                hsh.insert(i);
                primes.psb(i);
            }
            while(x%i==0)
                x/=i;
        }
    if(x!=1 && !hsh.count(x)){
        hsh.insert(x);
        primes.psb(x);
    }
}

void init(){
    for(int ele:arr){
        chck(ele-1);
        chck(ele);
        chck(ele+1);
    }
}

int main() {
	//ios_base::sync_with_stdio(false);
	//cin>>n>>a>>b;
	scand(n);
	scand(a);
	scand(b);
	arr.resize(n);
	FOR(i,0,n)
        scand(arr[i]);
        //cin>>arr[i];
	init();
	dp.resize(n,vl(3));
	ll ans=inf;

	for(int p:primes){
        if(arr[0]%p==0)
            dp[0][0]=0;
        else if((arr[0]+1)%p==0||(arr[0]-1)%p==0)
            dp[0][0]=b;
        else
            dp[0][0]=inf;

        dp[0][1]=a;
        dp[0][2]=a;

        FOR(i,1,n){
            if(arr[i]%p==0){
                dp[i][0]=dp[i-1][0];
                dp[i][1]=min(dp[i-1][0],dp[i-1][1])+a;
                dp[i][2]=min(dp[i][1],dp[i-1][2]);
            }
            else if((arr[i]-1)%p==0 || (arr[i]+1)%p==0){
                dp[i][0]=dp[i-1][0]+b;
                dp[i][1]=min(dp[i-1][0],dp[i-1][1])+a;
                dp[i][2]=min(dp[i][1],dp[i-1][2]+b);
            }
            else{
                dp[i][0]=inf;
                dp[i][1]=min(dp[i-1][0],dp[i-1][1])+a;
                dp[i][2]=dp[i][1];
            }
        }
        ans=min(ans,min(dp[n-1][0],dp[n-1][2]));
	}
	//cout<<ans;
	printld(ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int lmt = 1000009;
ll dp[4][lmt];
int A[lmt];
int n;
ll a, b;
ll inf = 1LL<<62;
bool isprime[lmt];
vector<int> primes;
vector<int> vec;

void sieve(){
    memset(isprime, true, sizeof(primes));
    int mx = 1000000;
    for(int i = 2; i*i <= mx; i++){
        if(isprime[i]){
            for(int j = 2*i; j <= mx; j+=i)
                isprime[j] = false;
        }
    }
    for(int i = 2; i <= mx; i++)
        if(isprime[i]) primes.push_back(i);
}

void getprime(int x){
    for(int i = 0; (i < primes.size()) && (x > 1); i++){
        if(x%primes[i] == 0){
            vec.push_back(primes[i]);
            while(x%primes[i] == 0)
                x /= primes[i];
        }
    }
    if(x > 1)
        vec.push_back(x);
}

void solve(){
    ll ans = inf;
    for(int pr = 0; pr < vec.size(); pr++){
        int p = vec[pr];
        //cout<<p<<" : \n";
        for(int i = 0; i < n; i++){
            if(i == 0){
                if(A[i]%p == 0)
                    dp[0][i] = dp[2][i] = 0;
                else if(((A[i] + 1)%p == 0)  || ((A[i] - 1)%p == 0))
                    dp[0][i] = dp[2][i] = a;
                else
                    dp[0][i] = dp[2][i] = inf;
                dp[1][i] = b;
                //cout<<dp[0][i]<<" "<<dp[1][i]<<" "<<dp[2][i]<<endl;
                continue;
            }
            if(A[i]%p == 0){
                dp[0][i] = dp[0][i - 1];
                dp[2][i] = min(dp[2][i -1], dp[1][i - 1]);
                dp[1][i] = min(dp[1][i - 1], dp[0][i - 1]) + b;
            }
            else if(((A[i] + 1)%p == 0)  || ((A[i] - 1)%p == 0)){
                dp[0][i] = dp[0][i - 1] + a;
                dp[2][i] = min(dp[2][i - 1], dp[1][i -1]) + a;
                dp[1][i] = min(dp[1][i - 1], dp[0][i - 1]) + b;
            }
            else{
                dp[0][i] = inf;
                dp[2][i] = inf;
                dp[1][i] = min(dp[1][i - 1], dp[0][i - 1]) + b;
            }
            //cout<<dp[0][i]<<" "<<dp[1][i]<<" "<<dp[2][i]<<endl;
        }
        for(int k = 0; k < 3; k++)
            ans = min(ans, dp[k][n - 1]);
    }
    printf("%lld\n",ans);
}

int main(){
    sieve();
    scanf("%d%lld%lld",&n,&b,&a);
    for(int i = 0; i < n; i++)
        scanf("%d",&A[i]);

    for(int i = -1; i <= 1; i++){
        getprime(A[0] + i);
        getprime(A[n - 1] + i);
    }
    set<int> st(vec.begin(), vec.end());
    vec.assign(st.begin(), st.end());
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int lmt = 1000009;
ll dp[4][lmt];
int A[lmt];
int n;
ll a, b;
ll inf = 1LL<<60;
bool isprime[lmt];
vector<int> primes;
vector<int> vec;

void sieve(){
    memset(isprime, true, sizeof(primes));
    int mx = 1000000;
    for(int i = 2; i*i <= mx; i++){
        if(isprime[i]){
            for(int j = 2*i; j <= mx; j+=i)
                isprime[j] = false;
        }
    }
    for(int i = 2; i <= mx; i++)
        if(isprime[i]) primes.push_back(i);
}

void getprime(int x){
    for(int i = 0; (i < primes.size()) && (x > 1); i++){
        if(x%primes[i] == 0){
            vec.push_back(primes[i]);
            while(x%primes[i] == 0)
                x /= primes[i];
        }
    }
    if(x > 1)
        vec.push_back(x);
}

void solve(){
    ll ans = inf;
    for(int pr = 0; pr < vec.size(); pr++){
        int p = vec[pr];
        for(int i = 0; i < n; i++){
            if(i == 0){
                if(A[i]%p == 0)
                    dp[0][i] = dp[0][i] = 0;
                else if(((A[i] + 1)%p == 0)  || ((A[i] - 1)%p == 0))
                    dp[0][i] = dp[0][i] = a;
                else
                    dp[0][i] = dp[0][i] = inf;
                dp[1][i] = b;
                continue;
            }
            if(A[i]%p == 0){
                dp[0][i] = dp[0][i - 1];
                dp[2][i] = min(dp[2][i -1], dp[1][i - 1]);
                dp[1][i] = min(dp[1][i - 1], dp[0][i - 1]) + b;
            }
            else if(((A[i] + 1)%p == 0)  || ((A[i] - 1)%p == 0)){
                dp[0][i] = dp[0][i - 1] + a;
                dp[2][i] = min(dp[2][i - 1], dp[1][i -1]) + a;
                dp[1][i] = min(dp[1][i - 1], dp[0][i - 1]) + b;
            }
            else{
                dp[0][i] = inf;
                dp[2][i] = inf;
                dp[1][i] = min(dp[1][i - 1], dp[0][i - 1]) + b;
            }
        }
        for(int k = 0; k < 3; k++)
            ans = min(ans, dp[k][n - 1]);
    }
    printf("%lld\n",ans);
}

int main(){
    sieve();
    scanf("%d%lld%lld",&n,&b,&a);
    for(int i = 0; i < n; i++)
        scanf("%d",&A[i]);

    for(int i = -1; i <= 1; i++){
        getprime(A[0] + i);
        getprime(A[n - 1] + i);
    }
    set<int> st(vec.begin(), vec.end());
    vec.assign(st.begin(), st.end());
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int lmt = 1000009;

ll dp[4][lmt];
int A[lmt];
int n;
ll a, b;
ll inf = 1LL<<60;
bool isprime[lmt];
vector<int> primes;
vector<int> vec;

void sieve(){
    memset(isprime, true, sizeof(primes));
    int mx = 1000000;
    for(int i = 2; i*i <= mx; i++){
        if(isprime[i]){
            for(int j = 2*i; j <= mx; j+=i)
                isprime[j] = false;
        }
    }
    for(int i = 2; i <= mx; i++)
        if(isprime[i]) primes.push_back(i);
}

void getprime(int x){
    for(int i = 0; (i < primes.size()) && (x > 1); i++){
        if(x%primes[i] == 0){
            //cout<<primes[i]<<endl;
            vec.push_back(primes[i]);
            while(x%primes[i] == 0)
                x /= primes[i];
        }
    }
    if(x > 1)
        vec.push_back(x);
}

void solve(){
    ll ans = inf;
    for(int pr = 0; pr < vec.size(); pr++){
        int p = vec[pr];
        //cout<<p<<" : \n";
        for(int i = 0; i < n; i++){
            if(i == 0){
                if(A[i]%p == 0){
                    dp[0][i] = 0;
                    dp[1][i] = b;
                }
                else if(((A[i] + 1)%p == 0)  || ((A[i] - 1)%p == 0)){
                    dp[0][i] = a;
                    dp[1][i] = b;
                }
                dp[2][i] = dp[3][i] = inf;
                //cout<<dp[0][i]<<" "<<dp[1][i]<<" "<<dp[2][i]<<" "<<dp[3][i]<<endl;
                continue;
            }
            if(A[i]%p == 0){
                dp[0][i] = dp[0][i - 1];
                dp[3][i] = min({dp[3][i - 1], dp[2][i -1], dp[1][i - 1]});
                dp[1][i] = dp[0][i - 1] + b;
                dp[2][i] = min(dp[2][i - 1], dp[1][i - 1]) + b;
            }
            else if(((A[i] + 1)%p == 0)  || ((A[i] - 1)%p == 0)){
                dp[0][i] = dp[0][i - 1] + a;
                dp[3][i] = min({dp[3][i - 1], dp[2][i - 1], dp[1][i -1]}) + a;
                dp[1][i] = dp[0][i - 1] + b;
                dp[2][i] = min(dp[2][i - 1], dp[1][i - 1]) + b;
            }
            else{
                dp[0][i] = inf;
                dp[3][i] = inf;
                dp[1][i] = dp[0][i - 1] + b;
                dp[2][i] = min(dp[2][i - 1], dp[1][i - 1]) + b;
            }
            //cout<<dp[0][i]<<" "<<dp[1][i]<<" "<<dp[2][i]<<" "<<dp[3][i]<<endl;
        }
        ////cout<<"for : "<<p<<"\n";
        for(int k = 0; k < 4; k++){
            ////cout<<dp[k][n-1]<<" ";
            ans = min(ans, dp[k][n - 1]);
        }
        //cout<<"\n";
    }
    printf("%lld\n",ans);
}

int main(){
    sieve();
    getprime(1000000000);
    scanf("%d%lld%lld",&n,&b,&a);
    for(int i = 0; i < n; i++)
        scanf("%d",&A[i]);

    for(int i = -1; i <= 1; i++){
        getprime(A[0] + i);
        getprime(A[n - 1] + i);
    }
    set<int> st(vec.begin(), vec.end());
    vec.assign(st.begin(), st.end());
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int lmt = 1000009;

ll dp[4][lmt];
int A[lmt];
int n;
ll a, b;
ll inf = 1LL<<60;
bool isprime[lmt];
vector<int> primes;
vector<int> vec;

void sieve(){
    memset(isprime, true, sizeof(primes));
    int mx = 1000000;
    for(int i = 2; i*i <= mx; i++){
        if(isprime[i]){
            for(int j = 2*i; j <= mx; j+=i)
                isprime[j] = false;
        }
    }
    for(int i = 2; i <= mx; i++)
        if(isprime[i]) primes.push_back(i);
}

void getprime(int x){
    for(int i = 0; (i < primes.size()) && (x > 1); i++){
        if(x%primes[i] == 0){
            //cout<<primes[i]<<endl;
            vec.push_back(primes[i]);
            while(x%primes[i] == 0)
                x /= primes[i];
        }
    }
    if(x > 1)
        vec.push_back(x);
}

void solve(){
    ll ans = inf;
    for(int pr = 0; pr < vec.size(); pr++){
        int p = vec[pr];
        //cout<<p<<" : \n";
        for(int i = 0; i < n; i++){
            if(i == 0){
                if(A[i]%p == 0){
                    dp[0][i] = 0;
                    dp[1][i] = b;
                }
                else if(((A[i] + 1)%p == 0)  || ((A[i] - 1)%p == 0)){
                    dp[0][i] = a;
                    dp[1][i] = b;
                }
                dp[2][i] = dp[3][i] = inf;
                //cout<<dp[0][i]<<" "<<dp[1][i]<<" "<<dp[2][i]<<" "<<dp[3][i]<<endl;
                continue;
            }
            if(A[i]%p == 0){
                dp[0][i] = dp[0][i - 1];
                dp[3][i] = min({dp[3][i - 1], dp[2][i -1], dp[1][i - 1]});
                dp[1][i] = dp[0][i] + b;
                dp[2][i] = min(dp[2][i - 1], dp[1][i - 1]) + b;
            }
            else if(((A[i] + 1)%p == 0)  || ((A[i] - 1)%p == 0)){
                dp[0][i] = dp[0][i - 1] + a;
                dp[3][i] = min({dp[3][i - 1], dp[2][i - 1], dp[1][i -1]}) + a;
                dp[1][i] = dp[0][i - 1] + b;
                dp[2][i] = min(dp[2][i - 1], dp[1][i - 1]) + b;
            }
            else{
                dp[0][i] = inf;
                dp[3][i] = inf;
                dp[1][i] = dp[0][i - 1] + b;
                dp[2][i] = min(dp[2][i - 1], dp[1][i - 1]) + b;
            }
            //cout<<dp[0][i]<<" "<<dp[1][i]<<" "<<dp[2][i]<<" "<<dp[3][i]<<endl;
        }
        ////cout<<"for : "<<p<<"\n";
        for(int k = 0; k < 4; k++){
            ////cout<<dp[k][n-1]<<" ";
            ans = min(ans, dp[k][n - 1]);
        }
        //cout<<"\n";
    }
    printf("%lld\n",ans);
}

int main(){
    sieve();
    scanf("%d%lld%lld",&n,&b,&a);
    for(int i = 0; i < n; i++)
        scanf("%d",&A[i]);

    for(int i = -1; i <= 1; i++){
        getprime(A[0] + i);
        getprime(A[n - 1] + i);
    }
    set<int> st(vec.begin(), vec.end());
    vec.assign(st.begin(), st.end());
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int lmt = 1000009;

ll dp[4][lmt];
int A[lmt];
int n;
ll a, b;
ll inf = 1LL<<60;
bool isprime[lmt];
vector<int> primes;
vector<int> vec;

void sieve(){
    memset(isprime, true, sizeof(primes));
    int mx = 1000000;
    for(int i = 2; i*i <= mx; i++){
        if(isprime[i]){
            for(int j = 2*i; j <= mx; j+=i)
                isprime[j] = false;
        }
    }
    for(int i = 2; i <= mx; i++)
        if(isprime[i]) primes.push_back(i);
}

void getprime(int x){
    for(int i = 0; (i < primes.size()) && (x > 1); i++){
        if(x%primes[i] == 0){
            vec.push_back(primes[i]);
            while(x%primes[i] == 0)
                x /= primes[i];
        }
    }
    if(x > 1)
        vec.push_back(x);
}

void solve(){
    ll ans = inf;
    for(int pr = 0; pr < vec.size(); pr++){
        int p = vec[pr];
        for(int i = 0; i < n; i++){
            if(i == 0){
                if(A[i]%p == 0)
                    dp[0][i] = 0;
                else if(((A[i] + 1)%p == 0)  || ((A[i] - 1)%p == 0))
                    dp[0][i] = a;
                else
                    dp[0][i] = inf;
                dp[1][i] = b;
                dp[2][i] = dp[3][i] = inf;
                continue;
            }
            if(A[i]%p == 0){
                dp[0][i] = dp[0][i - 1];
                dp[3][i] = min({dp[3][i - 1], dp[2][i -1], dp[1][i - 1]});
                dp[1][i] = dp[0][i - 1] + b;
                dp[2][i] = min(dp[2][i - 1], dp[1][i - 1]) + b;
            }
            else if(((A[i] + 1)%p == 0)  || ((A[i] - 1)%p == 0)){
                dp[0][i] = dp[0][i - 1] + a;
                dp[3][i] = min({dp[3][i - 1], dp[2][i - 1], dp[1][i -1]}) + a;
                dp[1][i] = dp[0][i - 1] + b;
                dp[2][i] = min(dp[2][i - 1], dp[1][i - 1]) + b;
            }
            else{
                dp[0][i] = inf;
                dp[3][i] = inf;
                dp[1][i] = dp[0][i - 1] + b;
                dp[2][i] = min(dp[2][i - 1], dp[1][i - 1]) + b;
            }
        }
        for(int k = 0; k < 4; k++){
            ans = min(ans, dp[k][n - 1]);
        }
    }
    printf("%lld\n",ans);
}

int main(){
    sieve();
    scanf("%d%lld%lld",&n,&b,&a);
    for(int i = 0; i < n; i++)
        scanf("%d",&A[i]);

    for(int i = -1; i <= 1; i++){
        getprime(A[0] + i);
        getprime(A[n - 1] + i);
    }
    set<int> st(vec.begin(), vec.end());
    vec.assign(st.begin(), st.end());
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int lmt = 1000009;

ll dp[30][4][lmt];
int A[lmt];
int n;
ll a, b;
ll inf = 1LL<<60;
bool isprime[lmt];
vector<int> primes;
vector<int> vec;

void sieve(){
    memset(isprime, true, sizeof(primes));
    int mx = 1000000;
    for(int i = 2; i*i <= mx; i++){
        if(isprime[i]){
            for(int j = 2*i; j <= mx; j+=i)
                isprime[j] = false;
        }
    }
    for(int i = 2; i <= mx; i++)
        if(isprime[i]) primes.push_back(i);
}

void getprime(int x){
    for(int i = 0; (i < primes.size()) && (x > 1); i++){
        if(x%primes[i] == 0){
            //cout<<primes[i]<<endl;
            vec.push_back(primes[i]);
            while(x%primes[i] == 0)
                x /= primes[i];
        }
    }
    if(x > 1)
        vec.push_back(x);
}

void solve(){
    ll ans = inf;
    for(int pr = 0; pr < vec.size(); pr++){
        int p = vec[pr];
        //cout<<p<<" : \n";
        for(int i = 0; i < n; i++){
            if(i == 0){
                if(A[i]%p == 0){
                    dp[p][0][i] = 0;
                    dp[p][1][i] = b;
                }
                else if(((A[i] + 1)%p == 0)  || ((A[i] - 1)%p == 0)){
                    dp[p][0][i] = a;
                    dp[p][1][i] = b;
                }
                dp[p][2][i] = dp[p][3][i] = inf;
                //cout<<dp[p][0][i]<<" "<<dp[p][1][i]<<" "<<dp[p][2][i]<<" "<<dp[p][3][i]<<endl;
                continue;
            }
            if(A[i]%p == 0){
                dp[p][0][i] = dp[p][0][i - 1];
                dp[p][3][i] = min({dp[p][3][i - 1], dp[p][2][i -1], dp[p][1][i - 1]});
                dp[p][1][i] = dp[p][0][i] + b;
                dp[p][2][i] = min(dp[p][2][i - 1], dp[p][1][i - 1]) + b;
            }
            else if(((A[i] + 1)%p == 0)  || ((A[i] - 1)%p == 0)){
                dp[p][0][i] = dp[p][0][i - 1] + a;
                dp[p][3][i] = min({dp[p][3][i - 1], dp[p][2][i - 1], dp[p][1][i -1]}) + a;
                dp[p][1][i] = dp[p][0][i - 1] + b;
                dp[p][2][i] = min(dp[p][2][i - 1], dp[p][1][i - 1]) + b;
            }
            else{
                dp[p][0][i] = inf;
                dp[p][3][i] = inf;
                dp[p][1][i] = dp[p][0][i - 1] + b;
                dp[p][2][i] = min(dp[p][2][i - 1], dp[p][1][i - 1]) + b;
            }
            //cout<<dp[p][0][i]<<" "<<dp[p][1][i]<<" "<<dp[p][2][i]<<" "<<dp[p][3][i]<<endl;
        }
        ////cout<<"for : "<<p<<"\n";
        for(int k = 0; k < 4; k++){
            ////cout<<dp[p][k][n-1]<<" ";
            ans = min(ans, dp[p][k][n - 1]);
        }
        //cout<<"\n";
    }
    printf("%lld\n",ans);
}

int main(){
    sieve();
    scanf("%d%lld%lld",&n,&b,&a);
    for(int i = 0; i < n; i++)
        scanf("%d",&A[i]);

    for(int i = -1; i <= 1; i++){
        getprime(A[0] + i);
        getprime(A[n - 1] + i);
    }
    set<int> st(vec.begin(), vec.end());
    vec.assign(st.begin(), st.end());
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int lmt = 1000009;

ll dp[4][lmt];
int A[lmt];
int n;
ll a, b;
ll inf = 1LL<<60;
vector<int> primes;
vector<int> vec;

void sieve(){
    int mx = 100000;
    bool isprime[mx];
    memset(isprime, true, sizeof(isprime));
    for(int i = 2; i*i <= mx; i++){
        if(isprime[i]){
            for(int j = 2*i; j <= mx; j+=i)
                isprime[j] = false;
        }
    }
    for(int i = 2; i <= mx; i++)
        if(isprime[i]) primes.push_back(i);
}

void getprime(int x){
    for(int i = 0; (i < primes.size()); i++){
        if(x%primes[i] == 0){
            vec.push_back(primes[i]);
            while(x%primes[i] == 0)
                x /= primes[i];
        }
    }
    if(x > 1)
        vec.push_back(x);
}

void solve(){
    ll ans = inf;
    for(int pr = 0; pr < vec.size(); pr++){
        int p = vec[pr];
        for(int i = 0; i < n; i++){
            if(i == 0){
                if(A[i]%p == 0)
                    dp[0][i] = 0;
                else if(((A[i] + 1)%p == 0)  || ((A[i] - 1)%p == 0))
                    dp[0][i] = a;
                else
                    dp[0][i] = inf;
                dp[1][i] = b;
                dp[2][i] = dp[3][i] = inf;
                continue;
            }
            if(A[i]%p == 0){
                dp[0][i] = dp[0][i - 1];
                dp[3][i] = min({dp[3][i - 1], dp[2][i -1], dp[1][i - 1]});
                dp[1][i] = dp[0][i - 1] + b;
                dp[2][i] = min(dp[2][i - 1], dp[1][i - 1]) + b;
            }
            else if(((A[i] + 1)%p == 0)  || ((A[i] - 1)%p == 0)){
                dp[0][i] = dp[0][i - 1] + a;
                dp[3][i] = min({dp[3][i - 1], dp[2][i - 1], dp[1][i -1]}) + a;
                dp[1][i] = dp[0][i - 1] + b;
                dp[2][i] = min(dp[2][i - 1], dp[1][i - 1]) + b;
            }
            else{
                dp[0][i] = inf;
                dp[3][i] = inf;
                dp[1][i] = dp[0][i - 1] + b;
                dp[2][i] = min(dp[2][i - 1], dp[1][i - 1]) + b;
            }
        }
        for(int k = 0; k < 4; k++){
            ans = min(ans, dp[k][n - 1]);
        }
    }
    printf("%lld\n",ans);
}

int main(){
    sieve();
    scanf("%d%lld%lld",&n,&b,&a);
    for(int i = 0; i < n; i++)
        scanf("%d",&A[i]);

    for(int i = -1; i <= 1; i++){
        getprime(A[0] + i);
        getprime(A[n - 1] + i);
    }
    set<int> st(vec.begin(), vec.end());
    vec.assign(st.begin(), st.end());
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int lmt = 1000009;
ll dp[4][lmt];
int A[lmt];
int n;
ll a, b;
ll inf = 1LL<<60;
bool isprime[lmt];
vector<int> primes;
vector<int> vec;

void sieve(){
    memset(isprime, true, sizeof(primes));
    int mx = 1000000;
    for(int i = 2; i*i <= mx; i++){
        if(isprime[i]){
            for(int j = 2*i; j <= mx; j+=i)
                isprime[j] = false;
        }
    }
    for(int i = 2; i <= mx; i++)
        if(isprime[i]) primes.push_back(i);
}

void getprime(int x){
    for(int i = 0; (i < primes.size()) && (x > 1); i++){
        if(x%primes[i] == 0){
            vec.push_back(primes[i]);
            while(x%primes[i] == 0)
                x /= primes[i];
        }
    }
    if(x > 1)
        vec.push_back(x);
}

void solve(){
    ll ans = inf;
    for(int pr = 0; pr < vec.size(); pr++){
        int p = vec[pr];
        for(int i = 0; i < n; i++){
            if(i == 0){
                if(A[i]%p == 0)
                    dp[0][i] = 0;
                else if(((A[i] + 1)%p == 0)  || ((A[i] - 1)%p == 0))
                    dp[0][i] = a;
                else
                    dp[0][i] = inf;
                dp[1][i] = b;
                dp[2][i] = inf;
                continue;
            }
            if(A[i]%p == 0){
                dp[0][i] = dp[0][i - 1];
                dp[2][i] = min(dp[2][i -1], dp[1][i - 1]);
                dp[1][i] = min(dp[1][i - 1], dp[0][i - 1]) + b;
            }
            else if(((A[i] + 1)%p == 0)  || ((A[i] - 1)%p == 0)){
                dp[0][i] = dp[0][i - 1] + a;
                dp[2][i] = min(dp[2][i - 1], dp[1][i -1]) + a;
                dp[1][i] = min(dp[1][i - 1], dp[0][i - 1]) + b;
            }
            else{
                dp[0][i] = inf;
                dp[2][i] = inf;
                dp[1][i] = min(dp[1][i - 1], dp[0][i - 1]) + b;
            }
        }
        for(int k = 0; k < 3; k++)
            ans = min(ans, dp[k][n - 1]);
    }
    printf("%lld\n",ans);
}

int main(){
    sieve();
    scanf("%d%lld%lld",&n,&b,&a);
    for(int i = 0; i < n; i++)
        scanf("%d",&A[i]);

    for(int i = -1; i <= 1; i++){
        getprime(A[0] + i);
        getprime(A[n - 1] + i);
    }
    set<int> st(vec.begin(), vec.end());
    vec.assign(st.begin(), st.end());
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int lmt = 1000009;
ll dp[4][lmt];
int A[lmt];
int n;
ll a, b;
ll inf = 1LL<<60;
bool isprime[lmt];
vector<int> primes;
vector<int> vec;

void sieve(){
    memset(isprime, true, sizeof(primes));
    int mx = 1000000;
    for(int i = 2; i*i <= mx; i++){
        if(isprime[i]){
            for(int j = 2*i; j <= mx; j+=i)
                isprime[j] = false;
        }
    }
    for(int i = 2; i <= mx; i++)
        if(isprime[i]) primes.push_back(i);
}

void getprime(int x){
    for(int i = 0; (i < primes.size()) && (x > 1); i++){
        if(x%primes[i] == 0){
            vec.push_back(primes[i]);
            while(x%primes[i] == 0)
                x /= primes[i];
        }
    }
    if(x > 1)
        vec.push_back(x);
}

void solve(){
    ll ans = inf;
    for(int pr = 0; pr < vec.size(); pr++){
        int p = vec[pr];
        for(int i = 0; i < n; i++){
            if(i == 0){
                if(A[i]%p == 0)
                    dp[0][i] = 0;
                else if(((A[i] + 1)%p == 0)  || ((A[i] - 1)%p == 0))
                    dp[0][i] = a;
                else
                    dp[0][i] = inf;
                dp[1][i] = b;
                dp[2][i] = b;
                dp[3][i] = inf;
                continue;
            }
            if(A[i]%p == 0){
                dp[0][i] = dp[0][i - 1];
                dp[3][i] = min({dp[3][i - 1], dp[2][i -1], dp[1][i - 1]});
                dp[1][i] = dp[0][i - 1] + b;
                dp[2][i] = min(dp[2][i - 1], dp[1][i - 1]) + b;
            }
            else if(((A[i] + 1)%p == 0)  || ((A[i] - 1)%p == 0)){
                dp[0][i] = dp[0][i - 1] + a;
                dp[3][i] = min({dp[3][i - 1], dp[2][i - 1], dp[1][i -1]}) + a;
                dp[1][i] = dp[0][i - 1] + b;
                dp[2][i] = min(dp[2][i - 1], dp[1][i - 1]) + b;
            }
            else{
                dp[0][i] = inf;
                dp[3][i] = inf;
                dp[1][i] = dp[0][i - 1] + b;
                dp[2][i] = min(dp[2][i - 1], dp[1][i - 1]) + b;
            }
        }
        for(int k = 0; k < 4; k++)
            ans = min(ans, dp[k][n - 1]);
    }
    printf("%lld\n",ans);
}

int main(){
    sieve();
    scanf("%d%lld%lld",&n,&b,&a);
    for(int i = 0; i < n; i++)
        scanf("%d",&A[i]);

    for(int i = -1; i <= 1; i++){
        getprime(A[0] + i);
        getprime(A[n - 1] + i);
    }
    set<int> st(vec.begin(), vec.end());
    vec.assign(st.begin(), st.end());
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int lmt = 1000009;
ll dp[4][lmt];
int A[lmt];
int n;
ll a, b;
ll inf = 1LL<<60;
bool isprime[lmt];
vector<int> primes;
vector<int> vec;

void sieve(){
    memset(isprime, true, sizeof(primes));
    int mx = 1000000;
    for(int i = 2; i*i <= mx; i++){
        if(isprime[i]){
            for(int j = 2*i; j <= mx; j+=i)
                isprime[j] = false;
        }
    }
    for(int i = 2; i <= mx; i++)
        if(isprime[i]) primes.push_back(i);
}

void getprime(int x){
    for(int i = 0; (i < primes.size()) && (x > 1); i++){
        if(x%primes[i] == 0){
            vec.push_back(primes[i]);
            while(x%primes[i] == 0)
                x /= primes[i];
        }
    }
    if(x > 1)
        vec.push_back(x);
}

void solve(){
    ll ans = inf;
    for(int pr = 0; pr < vec.size(); pr++){
        int p = vec[pr];
        //cout<<p<<" : \n";
        for(int i = 0; i < n; i++){
            if(i == 0){
                if(A[i]%p == 0)
                    dp[0][i] = dp[2][i] = 0;
                else if(((A[i] + 1)%p == 0)  || ((A[i] - 1)%p == 0))
                    dp[0][i] = dp[2][i] = a;
                else
                    dp[0][i] = dp[2][i] = inf;
                dp[1][i] = b;
                //cout<<dp[0][i]<<" "<<dp[1][i]<<" "<<dp[2][i]<<endl;
                continue;
            }
            if(A[i]%p == 0){
                dp[0][i] = dp[0][i - 1];
                dp[2][i] = min(dp[2][i -1], dp[1][i - 1]);
                dp[1][i] = min(dp[1][i - 1], dp[0][i - 1]) + b;
            }
            else if(((A[i] + 1)%p == 0)  || ((A[i] - 1)%p == 0)){
                dp[0][i] = dp[0][i - 1] + a;
                dp[2][i] = min(dp[2][i - 1], dp[1][i -1]) + a;
                dp[1][i] = min(dp[1][i - 1], dp[0][i - 1]) + b;
            }
            else{
                dp[0][i] = inf;
                dp[2][i] = inf;
                dp[1][i] = min(dp[1][i - 1], dp[0][i - 1]) + b;
            }
            //cout<<dp[0][i]<<" "<<dp[1][i]<<" "<<dp[2][i]<<endl;
        }
        for(int k = 0; k < 3; k++)
            ans = min(ans, dp[k][n - 1]);
    }
    printf("%lld\n",ans);
}

int main(){
    sieve();
    scanf("%d%lld%lld",&n,&b,&a);
    for(int i = 0; i < n; i++)
        scanf("%d",&A[i]);

    for(int i = -1; i <= 1; i++){
        getprime(A[0] + i);
        getprime(A[n - 1] + i);
    }
    set<int> st(vec.begin(), vec.end());
    vec.assign(st.begin(), st.end());
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int lmt = 1000009;
ll dp[4][lmt];
int A[lmt];
int n;
ll a, b;
ll inf = 1LL<<62;
bool isprime[lmt];
vector<int> primes;
vector<int> vec;

void sieve(){
    memset(isprime, true, sizeof(primes));
    int mx = 1000000;
    for(int i = 2; i*i <= mx; i++){
        if(isprime[i]){
            for(int j = 2*i; j <= mx; j+=i)
                isprime[j] = false;
        }
    }
    for(int i = 2; i <= mx; i++)
        if(isprime[i]) primes.push_back(i);
}

void getprime(int x){
    for(int i = 2; i*i <= x; i++){
        if(x%i == 0){
            vec.push_back(i);
            while(x%i == 0)
                x /= i;
        }
    }
    if(x > 1)
        vec.push_back(x);
}

void solve(){
    ll ans = inf;
    for(int pr = 0; pr < vec.size(); pr++){
        int p = vec[pr];
        //cout<<p<<" : \n";
        for(int i = 0; i < n; i++){
            if(i == 0){
                if(A[i]%p == 0)
                    dp[0][i] = dp[2][i] = 0;
                else if(((A[i] + 1)%p == 0)  || ((A[i] - 1)%p == 0))
                    dp[0][i] = dp[2][i] = a;
                else
                    dp[0][i] = dp[2][i] = inf;
                dp[1][i] = b;
                //cout<<dp[0][i]<<" "<<dp[1][i]<<" "<<dp[2][i]<<endl;
                continue;
            }
            if(A[i]%p == 0){
                dp[0][i] = dp[0][i - 1];
                dp[2][i] = min(dp[2][i -1], dp[1][i - 1]);
                dp[1][i] = min(dp[1][i - 1], dp[0][i - 1]) + b;
            }
            else if(((A[i] + 1)%p == 0)  || ((A[i] - 1)%p == 0)){
                dp[0][i] = dp[0][i - 1] + a;
                dp[2][i] = min(dp[2][i - 1], dp[1][i -1]) + a;
                dp[1][i] = min(dp[1][i - 1], dp[0][i - 1]) + b;
            }
            else{
                dp[0][i] = inf;
                dp[2][i] = inf;
                dp[1][i] = min(dp[1][i - 1], dp[0][i - 1]) + b;
            }
            //cout<<dp[0][i]<<" "<<dp[1][i]<<" "<<dp[2][i]<<endl;
        }
        for(int k = 0; k < 3; k++)
            ans = min(ans, dp[k][n - 1]);
    }
    printf("%lld\n",ans);
}

int main(){
    //sieve();
    scanf("%d%lld%lld",&n,&b,&a);
    for(int i = 0; i < n; i++)
        scanf("%d",&A[i]);

    for(int i = -1; i <= 1; i++){
        getprime(A[0] + i);
        getprime(A[n - 1] + i);
    }
    set<int> st(vec.begin(), vec.end());
    vec.assign(st.begin(), st.end());
    solve();
    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_set>

using namespace std;

const int nMax = 1000005;
const long long INF = (1LL << 60);

int n, a, b;
int v[nMax];

inline bool CanChange(int i, int d)
{
    return ((v[i]+1) % d == 0) || ((v[i]-1) % d == 0);
}

unordered_set<int> viz;

const int started = 0;
const int finished = 1;
const int not_started = 2;
long long dp[3][nMax];

long long SolveGCD(int d) //consideram d ca fiind divizor pt toate
{
    if(viz.find(d) != viz.end())
        return INF;
    viz.insert(d);

    dp[started][1] = dp[finished][1] = a;
    if(v[1] % d == 0)
        dp[not_started][1] = 0;
    else
        dp[not_started][1] = b;
    for(int i = 2; i <= n; ++i)
    {
        if(v[i] % d == 0)
        {
            dp[started][i] = min(dp[started][i-1], dp[not_started][i-1]) + a;
            dp[finished][i] = min(dp[finished][i-1], dp[started][i]);
            dp[not_started][i] = dp[not_started][i-1];
        }
        else
        {
            dp[started][i] = min(dp[started][i-1], dp[not_started][i-1]) + a;
            if(CanChange(i, d))
            {
                dp[finished][i] = min(dp[finished][i-1] + b, dp[started][i]);
                dp[not_started][i] = dp[not_started][i-1] + b;
            }
            else
            {
                dp[finished][i] = dp[started][i];
                dp[not_started][i] = INF;
            }
        }
    }
    return min(dp[started][n], min(dp[finished][n], dp[not_started][n]));
}

long long SolveWith(int x) //pastram elementul x
{
    long long ret = INF;
    int i, t = x;
    for(i = 2; i * i <= t; ++i)
        if(x % i == 0)
        {
            ret = min(ret, SolveGCD(i));
            ret = min(ret, SolveGCD(x / i));
            while(x % i == 0)
                x /= i;
        }
    if(x != 1)
        ret = min(ret, SolveGCD(x));
    return ret;
}

int main()
{
    cin >> n >> a >> b;
    for(int i = 1; i <= n; ++i)
        cin >> v[i];
    long long rasp = SolveWith(v[1]);
   /* rasp = min(rasp, SolveWith(v[n]));
    v[1]++;
    rasp = min(rasp, SolveWith(v[1]) + b);
    v[1] -= 2;
    rasp = min(rasp, SolveWith(v[1]) + b);
    v[1]++;

    v[n]++;
    rasp = min(rasp, SolveWith(v[n]) + b);
    v[n] -= 2;
    rasp = min(rasp, SolveWith(v[n]) + b);
    v[n]++;*/

    cout << rasp;
    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_set>

using namespace std;

const int nMax = 1000005;
const long long INF = (1LL << 60);

int n, a, b;
int v[nMax];

inline bool CanChange(int i, int d)
{
    return ((v[i]+1) % d == 0) || ((v[i]-1) % d == 0);
}

unordered_set<int> viz;

const int started = 0;
const int finished = 1;
const int not_started = 2;
long long dp[3][nMax];

long long SolveGCD(int d) //consideram d ca fiind divizor pt toate
{
    if(viz.find(d) != viz.end())
        return INF;
    viz.insert(d);

    dp[started][1] = dp[finished][1] = a;
    if(v[1] % d == 0)
        dp[not_started][1] = 0;
    else
        dp[not_started][1] = CanChange(1, d) ? b : INF;
    for(int i = 2; i <= n; ++i)
    {
        if(v[i] % d == 0)
        {
            dp[started][i] = min(dp[started][i-1], dp[not_started][i-1]) + a;
            dp[finished][i] = min(dp[finished][i-1], dp[started][i]);
            dp[not_started][i] = dp[not_started][i-1];
        }
        else
        {
            dp[started][i] = min(dp[started][i-1], dp[not_started][i-1]) + a;
            if(CanChange(i, d))
            {
                dp[finished][i] = min(dp[finished][i-1] + b, dp[started][i]);
                dp[not_started][i] = dp[not_started][i-1] + b;
            }
            else
            {
                dp[finished][i] = dp[started][i];
                dp[not_started][i] = INF;
            }
        }
    }
    return min(dp[started][n], min(dp[finished][n], dp[not_started][n]));
}

long long SolveWith(int x) //pastram elementul x
{
    long long ret = INF;
    int i;
    for(i = 2; i * i <= x; ++i)
        if(x % i == 0)
        {
            ret = min(ret, SolveGCD(i));
            ret = min(ret, SolveGCD(x / i));
            while(x % i == 0)
                x /= i;
        }
    if(x != 1)
        ret = min(ret, SolveGCD(x));
    return ret;
}

int main()
{
    cin >> n >> a >> b;
    for(int i = 1; i <= n; ++i)
        cin >> v[i];
    long long rasp = SolveWith(v[1]);
    rasp = min(rasp, SolveWith(v[n]));
    v[1]++;
    rasp = min(rasp, SolveWith(v[1]) + b);
    v[1] -= 2;
    rasp = min(rasp, SolveWith(v[1]) + b);
    v[1]++;

    v[n]++;
    rasp = min(rasp, SolveWith(v[n]) + b);
    v[n] -= 2;
    rasp = min(rasp, SolveWith(v[n]) + b);
    v[n]++;

    cout << rasp;
    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_set>

using namespace std;

const int nMax = 1000005;
const long long INF = (1LL << 60);

int n, a, b;
int v[nMax];

inline bool CanChange(int i, int d)
{
    return ((v[i]+1) % d == 0) || ((v[i]-1) % d == 0);
}

unordered_set<int> viz;

const int started = 0;
const int finished = 1;
const int not_started = 2;
long long dp[3][nMax];

long long SolveGCD(int d) //consideram d ca fiind divizor pt toate
{
    if(viz.find(d) != viz.end())
        return INF;
    viz.insert(d);

    dp[started][1] = dp[finished][1] = a;
    if(v[1] % d == 0)
        dp[not_started][1] = 0;
    else
        dp[not_started][1] = b;
    for(int i = 2; i <= n; ++i)
    {
        if(v[i] % d == 0)
        {
            dp[started][i] = min(dp[started][i-1], dp[not_started][i-1]) + a;
            dp[finished][i] = min(dp[finished][i-1], dp[started][i]);
            dp[not_started][i] = dp[not_started][i-1];
        }
        else
        {
            dp[started][i] = min(dp[started][i-1], dp[not_started][i-1]) + a;
            if(CanChange(i, d))
            {
                dp[finished][i] = min(dp[finished][i-1] + b, dp[started][i]);
                dp[not_started][i] = dp[not_started][i-1] + b;
            }
            else
            {
                dp[finished][i] = dp[started][i];
                dp[not_started][i] = INF;
            }
        }
    }
    return min(dp[started][n], min(dp[finished][n], dp[not_started][n]));
}

long long SolveWith(int x) //pastram elementul x
{
    long long ret = INF;
    int i, t = x;
    for(i = 2; i * i <= t; ++i)
        if(x % i == 0)
        {
            ret = min(ret, SolveGCD(i));
            ret = min(ret, SolveGCD(x / i));
            while(x % i == 0)
                x /= i;
        }
    if(x != 1)
        ret = min(ret, SolveGCD(x));
    return ret;
}

int main()
{
    cin >> n >> a >> b;
    for(int i = 1; i <= n; ++i)
        cin >> v[i];
    long long rasp = SolveWith(v[1]);
    rasp = min(rasp, SolveWith(v[n]));
    v[1]++;
    rasp = min(rasp, SolveWith(v[1]) + b);
    v[1] -= 2;
    rasp = min(rasp, SolveWith(v[1]) + b);
    v[1]++;

    v[n]++;
    rasp = min(rasp, SolveWith(v[n]) + b);
    v[n] -= 2;
    rasp = min(rasp, SolveWith(v[n]) + b);
    v[n]++;

    cout << rasp;
    return 0;
}


#include <iostream>
#include <vector>
#include <unordered_set>

using namespace std;

const int nMax = 1000005;
const long long INF = (1LL << 60);

int n, a, b;
int v[nMax];

inline bool CanChange(int i, int d)
{
    return ((v[i]+1) % d == 0) || ((v[i]-1) % d == 0);
}

unordered_set<int> viz;

const int started = 0;
const int finished = 1;
const int not_started = 2;
long long dp[3][nMax];

long long SolveGCD(int d) //consideram d ca fiind divizor pt toate
{
    if(viz.find(d) != viz.end())
        return INF;
    viz.insert(d);

    dp[started][1] = dp[finished][1] = a;
    if(v[1] % d == 0)
        dp[not_started][1] = 0;
    else
        dp[not_started][1] = b;
    for(int i = 2; i <= n; ++i)
    {
        if(v[i] % d == 0)
        {
            dp[started][i] = min(dp[started][i-1], dp[not_started][i-1]) + a;
            dp[finished][i] = min(dp[finished][i-1], dp[started][i]);
            dp[not_started][i] = dp[not_started][i-1];
        }
        else
        {
            dp[started][i] = min(dp[started][i-1], dp[not_started][i-1]) + a;
            if(CanChange(i, d))
            {
                dp[finished][i] = min(dp[finished][i-1] + b, dp[started][i]);
                dp[not_started][i] = dp[not_started][i-1] + b;
            }
            else
            {
                dp[finished][i] = dp[started][i];
                dp[not_started][i] = INF;
            }
        }
    }
    return min(dp[started][n], min(dp[finished][n], dp[not_started][n]));
}

long long SolveWith(int x) //pastram elementul x
{
    long long ret = INF;
    int i;
    for(i = 2; i * i <= x; ++i)
        if(x % i == 0)
        {
            ret = min(ret, SolveGCD(i));
            ret = min(ret, SolveGCD(x / i));
            while(x % i == 0)
                x /= i;
        }
    if(x != 1)
        ret = min(ret, SolveGCD(x));
    return ret;
}

int main()
{
    cin >> n >> a >> b;
    for(int i = 1; i <= n; ++i)
        cin >> v[i];
    long long rasp = SolveWith(v[1]);
    rasp = min(rasp, SolveWith(v[n]));
    v[1]++;
    rasp = min(rasp, SolveWith(v[1]) + b);
    v[1] -= 2;
    rasp = min(rasp, SolveWith(v[1]) + b);
    v[1]++;

    v[n]++;
    rasp = min(rasp, SolveWith(v[n]) + b);
    v[n] -= 2;
    rasp = min(rasp, SolveWith(v[n]) + b);
    v[n]++;

    cout << rasp;
    return 0;
}


#include <bits/stdc++.h>

//#define fin cin
//#define fout cout

#define F first
#define S second

using namespace std;

const int Nmax = 1e6 + 10;
const int Dmax = 1e5 + 10;

long long ans;

int n , A , B , i;
int a[Nmax];
long long costL[Nmax] , costR[Nmax];

bool b[Dmax] , L[Nmax] , R[Nmax];

vector < int > allD;

void CIUCIUr(int n)
{
    int i , j;
    for (i = 2; i * i <= n; ++i)
        if (!b[i])
            for (j = i << 1; j <= n; j += i) b[j] = 1;

    for (i = 2; i <= n; ++i)
        if (!b[i]) allD.push_back(i);
}

vector < int > getDivs(int x)
{
    vector < int > v; v.clear();

    for (auto &d : allD)
    {
        if (d * d > x) break;
        if (x % d == 0)
        {
            v.push_back(d);
            while (x % d == 0) x /= d;
        }
    }

    if (x > 1) v.push_back(x);
    return v;
}

void try_(int d)
{
    int i , j;
    long long bst = 0LL;

    for (i = 1; i <= n; ++i)
    {
        L[i] = 1; costL[i] = costL[i-1];
        if (a[i] % d == 0) L[i] = 0;
        else if ((a[i] - 1) % d == 0) L[i] = 0, costL[i] += 1LL * B;
        else if ((a[i] + 1) % d == 0) L[i] = 0, costL[i] += 1LL * B;
    }

    for (i = n; i ; --i)
    {
        R[i] = 1; costR[i] = costR[i+1];
        if (a[i] % d == 0) R[i] = 0;
        else if ((a[i] - 1) % d == 0) R[i] = 0, costR[i] += 1LL * B;
        else if ((a[i] + 1) % d == 0) R[i] = 0, costR[i] += 1LL * B;
    }

    for (i = 1; i <= n; ++i) L[i] |= L[i-1];
    for (i = n; i ; --i) R[i] |= R[i+1];

    for (i = 1; i <= n + 1; ++i)
    {
        if (!R[i])
            ans = min(ans , 1LL * costR[i] + 1LL * (i - 1) * A - 1LL * bst);
        if (!L[i])
            bst = max(bst , 1LL * i * A - 1LL * costL[i]);
    }

}

void solve(vector < int > v)
{
    for (auto & it : v)
    {
        memset(L , 0 , sizeof(L));
        memset(R , 0 , sizeof(R));
        try_(it);
    }
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif // ONLINE_JUDGE

    /*
    #ifndef ONLINE_JUDGE
    ifstream fin("input.in");
    ofstream fout("output.out");
    #endif // ONLINE_JUDGE
    */

    scanf("%d %d %d", &n, &A, &B);
    for (i = 1; i <= n; ++i)
        scanf("%d", a + i);

    CIUCIUr(1e5);

    ans = LLONG_MAX;
    for (i = -1; i <= 1; ++i)
    {
        solve(getDivs(a[1]+i));
        solve(getDivs(a[n]+i));
    }

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

    return 0;
}


#include <bits/stdc++.h>

//#define fin cin
//#define fout cout

#define F first
#define S second

using namespace std;

const int Nmax = 1e6 + 10;
const int Dmax = 1e5 + 10;

long long ans;

int n , A , B , i;
int a[Nmax] , costL[Nmax] , costR[Nmax];

bool b[Dmax] , L[Nmax] , R[Nmax];

vector < int > allD;

void CIUCIUr(int n)
{
    int i , j;
    for (i = 2; i * i <= n; ++i)
        if (!b[i])
            for (j = i << 1; j <= n; j += i) b[j] = 1;

    for (i = 2; i <= n; ++i)
        if (!b[i]) allD.push_back(i);
}

vector < int > getDivs(int x)
{
    vector < int > v; v.clear();

    for (auto &d : allD)
    {
        if (d * d > x) break;
        if (x % d == 0)
        {
            v.push_back(d);
            while (x % d == 0) x /= d;
        }
    }

    if (x > 1) v.push_back(x);
    return v;
}

void try_(int d)
{
    int i , j , bst = 0;

    for (i = 1; i <= n; ++i)
    {
        L[i] = 1; costL[i] = costL[i-1];
        if (a[i] % d == 0) L[i] = 0;
        else if ((a[i] - 1) % d == 0) L[i] = 0, costL[i] += B;
        else if ((a[i] + 1) % d == 0) L[i] = 0, costL[i] += B;
    }

    for (i = n; i ; --i)
    {
        R[i] = 1; costR[i] = costR[i+1];
        if (a[i] % d == 0) R[i] = 0;
        else if ((a[i] - 1) % d == 0) R[i] = 0, costR[i] += B;
        else if ((a[i] + 1) % d == 0) R[i] = 0, costR[i] += B;
    }

    for (i = 1; i <= n; ++i) L[i] |= L[i-1];
    for (i = n; i ; --i) R[i] |= R[i+1];

    for (i = 1; i <= n + 1; ++i)
    {
        if (!R[i])
            ans = min(ans , 1LL * costR[i] + (i - 1) * A - bst);
        if (!L[i])
            bst = max(bst , i * A - costL[i]);
    }

}

void solve(vector < int > v)
{
    for (auto & it : v)
    {
        memset(L , 0 , sizeof(L));
        memset(R , 0 , sizeof(R));
        try_(it);
    }
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif // ONLINE_JUDGE

    /*
    #ifndef ONLINE_JUDGE
    ifstream fin("input.in");
    ofstream fout("output.out");
    #endif // ONLINE_JUDGE
    */

    scanf("%d %d %d", &n, &A, &B);
    for (i = 1; i <= n; ++i)
        scanf("%d", a + i);

    CIUCIUr(1e5);

    ans = LLONG_MAX;
    for (i = -1; i <= 1; ++i)
    {
        solve(getDivs(a[1]+i));
        solve(getDivs(a[n]+i));
    }

    printf("%d\n", ans);

    return 0;
}


#include <bits/stdc++.h>

//#define fin cin
//#define fout cout

#define F first
#define S second

using namespace std;

const int Nmax = 1e6 + 10;
const int Dmax = 1e5 + 10;

long long ans;

int n , A , B , i;
int a[Nmax];
long long costL[Nmax] , costR[Nmax];

bool b[Dmax] , L[Nmax] , R[Nmax];

vector < int > allD;

void CIUCIUr(int n)
{
    int i , j;
    for (i = 2; i * i <= n; ++i)
        if (!b[i])
            for (j = i << 1; j <= n; j += i) b[j] = 1;

    for (i = 2; i <= n; ++i)
        if (!b[i]) allD.push_back(i);
}

vector < int > getDivs(int x)
{
    vector < int > v; v.clear();

    for (auto &d : allD)
    {
        if (d * d > x) break;
        if (x % d == 0)
        {
            v.push_back(d);
            while (x % d == 0) x /= d;
        }
    }

    if (x > 1) v.push_back(x);
    return v;
}

void try_(int d)
{
    int i , j;
    long long bst = 0LL;

    for (i = 1; i <= n; ++i)
    {
        L[i] = 1; costL[i] = costL[i-1];
        if (a[i] % d == 0) L[i] = 0;
        else if ((a[i] - 1) % d == 0) L[i] = 0, costL[i] += 1LL * B;
        else if ((a[i] + 1) % d == 0) L[i] = 0, costL[i] += 1LL * B;
    }

    for (i = n; i ; --i)
    {
        R[i] = 1; costR[i] = costR[i+1];
        if (a[i] % d == 0) R[i] = 0;
        else if ((a[i] - 1) % d == 0) R[i] = 0, costR[i] += 1LL * B;
        else if ((a[i] + 1) % d == 0) R[i] = 0, costR[i] += 1LL * B;
    }

    for (i = 1; i <= n; ++i) L[i] |= L[i-1];
    for (i = n; i ; --i) R[i] |= R[i+1];

    for (i = 1; i <= n + 1; ++i)
    {
        if (!R[i])
            ans = min(ans , 1LL * costR[i] + 1LL * (i - 1) * A - bst);
        if (!L[i])
            bst = max(bst , 1LL * i * A - 1LL * costL[i]);
    }

}

void solve(vector < int > v)
{
    for (auto & it : v)
    {
        memset(L , 0 , sizeof(L));
        memset(R , 0 , sizeof(R));
        try_(it);
    }
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif // ONLINE_JUDGE

    /*
    #ifndef ONLINE_JUDGE
    ifstream fin("input.in");
    ofstream fout("output.out");
    #endif // ONLINE_JUDGE
    */

    scanf("%d %d %d", &n, &A, &B);
    for (i = 1; i <= n; ++i)
        scanf("%d", a + i);

    CIUCIUr(1e5);

    ans = LLONG_MAX;
    for (i = -1; i <= 1; ++i)
    {
        solve(getDivs(a[1]+i));
        solve(getDivs(a[n]+i));
    }

    printf("%d\n", ans);

    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <cmath>
#include <algorithm>
#include <string>
#define PI acos(-1)
#define eps 1e-8
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)
using namespace std;

const int maxn = 1e6+100;
typedef long long LL;
const LL mod = 1000000007;

int a[maxn*4];
int num[maxn];
int n, aa, bb;
int tmp;
LL ans = mod*mod;

int gcd(int a, int b)
{
    return b == 0 ? a : gcd(b, a%b);
}

void pushup(int o)
{
    int x = a[o*2], y = a[o*2+1];
    if(x && y) a[o] = gcd(x, y);
    else if(x) a[o] = x;
    else a[o] = y;
}

int pr, pv;
void update(int o=1, int L=1, int R=n)
{
    int M = (L+R) / 2;
    if(L == R){
        a[o] = pv;
        return;
    }
    if(pr <= M)update(o*2, L, M);
    if(pr > M)update(o*2+1, M+1, R);
    pushup(o);
}

int qv;

int querryl(int o=1, int L=1, int R=n)
{
    int M = (L+R) / 2;
    if(L == R)return L;
    int x = a[o*2], y = a[o*2+1];
    if(gcd(x, qv) == 1)return querryl(o*2, L, M);
    else return querryl(o*2+1, M+1, R);
}

int querryr(int o=1, int L=1, int R=n)
{
    int M = (L+R)/2;
    if(L == R)return L;
    int x = a[o*2], y = a[o*2+1];
    if(gcd(y, qv) == 1)return querryr(o*2+1, M+1, R);
    else return querryr(o*2, L, M);
}

void solve()
{
    LL ret;
    if(gcd(a[1], qv) != 1)ret = 0;
    else ret = (LL)(querryr(1, 1, n) - querryl(1, 1, n) + 1) * (LL)aa;
    ans = min(ans, ret+tmp);
}

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //ios::sync_with_stdio(false);
    cin >> n >> aa >> bb;
    for(int i = 1; i <= n; i++){
        cin >> num[i];
        pr = i; pv = num[i];
        update(1, 1, n);
    }
    qv = num[1];tmp = 0;solve();
    if(ans == 0){
        cout << ans << endl;
        return 0;
    }
    tmp = bb;
    int ll = querryl(), rr = querryr();
    pr = ll, pv = num[ll]-1;update();solve();
    pv = num[ll]+1;update();solve();
    pr = rr, pv = num[rr]-1;update();solve();
    pv = num[rr]+1;update();solve();

    qv = num[n];tmp = 0;solve();
    if(ans == 0){
        cout << ans << endl;
        return 0;
    }
    tmp = bb;
    ll = querryl(), rr = querryr();
    pr = ll, pv = num[ll]-1;update();solve();
    pv = num[ll]+1;update();solve();
    pr = rr, pv = num[rr]-1;update();solve();
    pv = num[rr]+1;update();solve();
    cout << ans << endl;
    return 0;
}


n=int(input())
for i in range(2,n):
    if n//i>1:
        m=i
print(m)
s=str()
if m%i==0:
    for i in range(m):
        s+=str(n//m)+' '
else:
    for i in range(m-1):
        s+=str(n//m)+' '
    s+=str(n//m+1)
print(s)


n=int(input())
if n<=2:
    print(0)
else:
    for i in range(2,n):
        if n//i>1:
            m=i
    print(m)
    s=str()
    if n%m==0:
        for i in range(m):
            s+=str(n//m)+' '
    else:
        for i in range(m-1):
            s+=str(n//m)+' '
        s+=str(n//m+1)
    print(s)


n=int(input())
if n<=3:
    print(1)
    print(n)
else:
    for i in range(2,n):
        if n//i>1:
            m=i
    print(m)
    s=str()
    if n%m==0:
        for i in range(m):
            s+=str(n//m)+' '
    else:
        for i in range(m-1):
            s+=str(n//m)+' '
        s+=str(n//m+1)
    print(s)


n=int(input())
if n==2:
    print(1)
    print(2)
else:
    for i in range(2,n):
        if n//i>1:
            m=i
    print(m)
    s=str()
    if n%m==0:
        for i in range(m):
            s+=str(n//m)+' '
    else:
        for i in range(m-1):
            s+=str(n//m)+' '
        s+=str(n//m+1)
    print(s)


x=int(input())
if x%2==0:
    print(x//2)
    aas='2 '
    a='2'
    ans=aas*(x//2-1)+a
    print(ans)
else:
    yo=x-3
    aas='2 '
    b='3'
    ans=aas*(yo//2)+b
    print(yo//2+1)
    print(ans)


x=int(input())
if x%2==0:
    print(x//2)
    aas='2 '
    a='2'
    ans=aas*(x//2-1)+a
    print(ans)
else:
    yo=x-3
    aas='2 '
    b='3'
    ans=aas*(yo//2)+b
    print(ans)


x=int(input())
if x%2==0:
    print(x//2)
    aas='2 '
    a='2'
    ans=aas*(x//2-1)+a
    print(ans)
else:
    yo=x-3
    aas='2 '
    b='3
    ans=aas*(yo//2)+b
    print(yo//2+1)
    print(ans)


x=int(input())
if x%2==0:
    print(x//2)
    aas='2 '
    a='2'
    ans=aas*(x//2-1)+a
    print(ans)
else:
    yo=x-3
    aas='2 '
    b='3
    ans=aas*(yo//2)+b
    print(ans)


n = eval(input())
prime = [2]
for k in range(3,n):
    flag = True
    for i in prime:
        if k%i == 0:
            flag = False
            break
        elif i*i>k:
            break
    if flag:
        prime.append(k)
ans = []
for i in prime:
    while True:
        if n<i or n-i == 1:
            break
        n -= i
        ans.append(i)
    if n == 0:
        break
print(len(ans))
for i in ans:
    print(i,end=" ")
print("")


n = eval(input())
if n%2 == 0:
    print(int(n/2))
    for i in range(int(n/2)):
        print(2,end=" ")
    print("")
else:
    print(n//2)
    for i in range(int(n/2)-1):
        print(2,end=" ")
    print(3)


n = eval(input())
ans = []
if n%2 == 0:
    print(n/2)
    for i in range(n/2):
        print(2,end=" ")
    print("")
else:
    print(n//2)
    for i in range(n//2-1):
        print(2,end=" ")
    print(3)


# -*- coding: utf-8 -*-
"""
Created on Mon Jul  6 23:08:37 2020

@author: pc612
"""
n = int(input())
if n%2 == 0:
    print(int(n/2))
    for _ in range(int(n/2)):print(2, end = ' ');
else:
    if n == 3:
        print(1)
        print(3)
    else:
        k = n-3
        print(int(k/2)+1)
        for _ in range(int(k/2)):
            print(2, end = ' ')
        print(3)


# -*- coding: utf-8 -*-
"""
Created on Mon Jul  6 23:08:37 2020

@author: pc612
"""
n = int(input())
if n%2 == 0:
    print(int(n/2))
    for _ in range(int(n/2)):print(2, end = ' ');
else:
    if n == 3:
        print(3)
    else:
        k = n-3
        print(int(k/2)+1)
        for _ in range(int(k/2)):
            print(2, end = ' ')
            print(3)


# -*- coding: utf-8 -*-
"""
Created on Mon Jul  6 23:08:37 2020

@author: pc612
"""
n = int(input())
if n%2 == 0:
    print(int(n/2))
    for _ in range(int(n/2)):print(2, end = ' ');
else:
    if n == 3:
        print(1)
        print(3)
    else:
        k = n-3
        print(int(k/2)+1)
        for _ in range(int(k/2)):
            print(2, end = ' ')
            print(3)


n=int(input())
start = 1
end = n
count=0
l,l2=[],[]
if n==2:
    print("1")
    print("2")
else:
    for val in range(start, end):
        if val > 1:
            for n1 in range(2, val):
                if (val % n1) == 0:
                    break
            else:
                l.append(val)

    s = sum(l)
    if (s == n):
        print(len(l))
        print(*l)
    else:
        for i in l:
            if (n % i == 0):
                for j in range((n // i)):
                    l2.append(i)
                break
        print(len(l2))
        print(*l2)


n=int(input())
print(n//2)
while n>3:
    print(2,end=" ")
    n-=2
print(n)


n=int(input())
start = 1
end = n
count=0
l,l2=[],[]
for val in range(start, end):
    if val > 1:
        for n1 in range(2, val):
            if (val % n1) == 0:
                break
        else:
            l.append(val)
            count+=1
print(count)
#print(l)
s=sum(l)
if(s==n):
    print(*l)
else:
    for i in l:
        if (n % i == 0):
            for j in range((n // i)):
                print(i,end=" ")
            break


n=int(input())
start = 1
end = n
count=0
l,l2=[],[]
if n==2:
    print("1")
    print("2")
elif(n==3):
    print("1")
    print("3")
else:
    for val in range(start, end):
        if val > 1:
            for n1 in range(2, val):
                if (val % n1) == 0:
                    break
            else:
                l.append(val)

    s = sum(l)
    if (s == n):
        print(len(l))
        print(*l)
    else:
        for i in l:
            if (n % i == 0):
                for j in range((n // i)):
                    l2.append(i)
                break
        print(len(l2))
        print(*l2)


n = int(input())
temp = n
while(temp!=0):
    if(temp%2==0):
        print("2", end=" ")
        temp -= 2
    else:
        print("3", end=" ")
        temp -= 3


n = int(input())
temp = n
while(temp!=0):
    if(temp%3==0):
        print("3", end=" ")
        temp -= 3
    else:
        print("2", end=" ")
        temp -= 2


n = int(input())
temp = n
print(n//2)
while(temp!=0):
    if(temp%3==0):
        print("3", end=" ")
        temp -= 3
    else:
        print("2", end=" ")
        temp -= 2


n = int(input())
temp = n
print(n//2)
while(temp!=0):
    if(temp%2!=0):
        print("3", end=" ")
        temp -= 3
    else:
        print("2", end=" ")
        temp -= 2


x = int(input())
if x<4:
	print(x)
elif x%2 == 0:
	for i in range(x//2):
		print(2, end = " ")
else:
	if x<9:
		if x == 5:
			print(2,3)
		if x == 7:
			print(2,2,3)
		pass
	else:
		c = x-9
		for i in range(c//2):
			print(2, end = " ")
		print(3,3,3)


x = int(input())
if x<4:
	print(1)
	print(x)
elif x%2 == 0:
	print(x//2)
	for i in range(x//2):
		print(2, end = " ")
else:
	print(x//2)
	for i in range(x//2-1):
		print(2, end = " ")
	print(3)


x = int(input())
if x<4:
	print(1)
	print(x)
elif x%2 == 0:
	print(x//2)
	for i in range(x//2):
		print(2, end = " ")
else:
	if x<9:
		if x == 5:
			print(2)
			print(2,3)
		if x == 7:
			print(3)
			print(2,2,3)
		pass
	else:
		c = x-9
		print(c//2+4)
		for i in range(c//2):
			print(2, end = " ")

		print(2,3,3,3)


x = int(input())
if x<4:
	print(1)
	print(x)
elif x%2 == 0:
	print(x//2)
	for i in range(x//2):
		print(2, end = " ")
else:
	if x<9:
		if x == 5:
			print(2)
			print(2,3)
		if x == 7:
			print(3)
			print(2,2,3)
		pass
	else:
		c = x-9
		print(3+c//2)
		for i in range(c//2):
			print(2, end = " ")
		print(3,3,3)


x = int(input())
if x<4:
	print(1)
	print(x)
elif x%2 == 0:
	print(x//2)
	for i in range(x//2):
		print(2, end = " ")
else:
	if x<9:
		if x == 5:
			print(2)
			print(2,3)
		if x == 7:
			print(3)
			print(2,2,3)
		pass
	else:
		c = x-9
		print(c//2+4)
		for i in range(c//2):
			print(2, end = " ")

		print(3,3,3)


n = gets.chomp.to_i

ans = []
if n.even?
  ans = [2] * (n / 2)
else
  ans = [2] * (n / 2 - 1) + [3]
end
puts ans.length
puts ans.join(" ")


n = gets.to_i

if(n%2==0)
    puts n/2
    (n/2).times{print 2.to_s + " "}
else
    puts (n-1)/2
    ((n/2)-1).times{print 2.to_s + " "}
    print 3.to_s

end


n = gets.to_i
ans = n / 2
puts ans
if (n % 2 == 1)
    print 3, " "
    n -= 3
end

(0...n / 2).each do
    print 2, " "
end


n = gets.to_i

if (n % 2 == 1)
    print 3, " "
    n -= 3
end

(0...n / 2).each do
    print 2, " "
end


n = gets.to_i
if n.even?
  k = n/2
  puts k
  puts ([2] * k).join(" ")
else
  k = 1
  n -= 3
  ps = [3]
  k += n/2
  ps << ([2] * (k-1))
  puts k
  puts ps.join(" ")
end


given_number = gets.chomp.to_i

k = given_number / 2

md = given_number % 2
ary = [2]
if md == 1
  ary *= k - 1
  ary << 3
else
  ary *= k
end

puts ary.join(' ')


given_number = gets.chomp.to_i

k = given_number / 2

md = given_number % 2
ary = [2]
if md == 1
  ary *= k - 1
  ary << 3
else
  ary *= k
end

puts k
puts ary.join(' ')


n = gets.to_i
count3 = n%2
count2 = n/2 - count3
puts count2 + count3
(1..count2).each do
  print 2, ' '
end
print count3==1? 3 : ''


n = gets.to_i
count3 = n%2
count2 = n/2 - count3
(1..count2).each do
  print 2, ' '
end
print count3==1? 3 : ''


require 'prime'
require 'set'
a=["","","1\n2","1\n3","2\n2 2","2\n2 3"]
n=gets.to_i

if n<6 then
	puts a[n]
else
	if n%2==0 then
		puts n/2
		(n/2).times{|i|
			print " " if i>0
			print "2"
		}
		print "\n"
	else
		d=n-3
		puts d/2+1
		(d/2).times{|i|
			print " " if i>0
			print "2"
		}
		print " 3\n"
	end
end


require 'prime'
require 'set'
a=["","","1\n2","1\n3","2\n2 2","2\n2 3"]
x=Prime.each(10**5).to_a
y=SortedSet.new(x)
n=gets.to_i

if n<6 then
	puts a[n]
elsif y.member?(n) then
	puts "1\n#{n}"
else
	ok=false
	x.size.times{|i|
		i.upto(x.size-1){|j|
			t=n-x[i]-x[j]
			break if t<x[j]

			if (t==0) || y.member?(t) then
				if t==0 then
					puts 2
					puts [x[i],x[j]]*" "
				else
					puts 3
					puts [x[i],x[j],t]*" "
				end
				ok=true
				break
			end
		}
		break if ok==true
	}
end


n=gets.to_i
if n==3
    puts "1\n3"
elsif n.even?
    puts n/2
    puts ([2]*(n/2))*' '
else
    puts n/2
    puts (([2]*(n/2-1))<<3)*' '
end


# coding: utf-8

# if __FILE__ == $0
# end

n = gets.to_i # n >= 2 and n <= 100_000
was_odd = n.odd?
ans_len = 0
if was_odd
    ans_len += 1
    n -= 3
end

ans_len += n / 2

puts ans_len
if was_odd
    print "3 "
end
(n/2).times {
    print "2 "
}
puts ""


class Memo
  attr_reader(:i)
  def initialize(i, state)
    @i =i
    @state = state
  end

  def yes!
    @state = true
  end

  def no!
    @state = false
  end

  def yes?
    @state
  end

  def to_s
    "#{@i} => #{@state}"
  end
end
class Sieve
  attr_reader(:n)
  def initialize(n)
    @n = n
    @memo = Array.new(n + 100){|i| Memo.new(i, true)}
    @run = false
  end

  def run!
    return if @run
    @run = true
    @memo[0].yes!
    @memo[1].yes!
    @memo[2].yes!
    @memo.drop(2).each do |m|
      if(m.yes?)
        start = m.i * m.i
        start.step(@n + 1, m.i) do |i|
          @memo[i].no!
        end
      end
    end
  end

  def primes
    @primes ||= run!.select{|m| m.yes? }
  end

  def prime_values
    @prime_values ||= primes.map(&:i)
  end

  def get_data
    run!
    @memo
  end
end

def main
  g = gets.strip.to_i
  n = g / 2
  puts n
  if(g % 2 == 0)
    puts Array.new(n){ 2 }.join(" ")
  else
    x = Array.new(n - 1){ 2 }
    x << 3
    puts x.join(" ")
  end
end

main


n = gets.chomp.to_i

if n%2 == 0
	puts n/2
	print "2 " * (n/2)
else
	if n == 3
		puts 1
		print 3
	else
		puts n/2
		print "2 " * ((n/2)-1)
		print 3
	end
end


#!/usr/bin/env ruby
n=gets.chomp.to_i
if n&1==0 then
  puts "#{n/2}"
  (n/2).times do
    print "2 "
  end
else puts "#{n/2 }"
  print "3 "
  ((n/2)-1).times do
    print "2 "
  end
end


n = gets.to_i
if n % 2 == 0 then
	puts n / 2
	puts "2 " * (n / 2 - 1) + "2"
else
	puts n / 2
	puts "2 " * (n / 2 - 1) + "3"
end


n = gets.to_i

result = Array.new(n.div(2)-1, 2)
result << (n.even? ? 2 : 3)

puts result.size
puts result.join(' ')


k = gets.chomp.to_i
n = k / 2
out = ["2"] * n
out += ["3"] if k.odd?
puts out.size
puts out.join(" ")


k = gets.chomp.to_i
n = k / 2
out = ["2"] * n
if k.odd?
	out.pop
	out += ["3"]
end
puts out.size
puts out.join(" ")


number = gets.strip.to_i
even = false

even = true if number % 2 == 0

if even
  output = ''
  (number/2).times { output << '2 ' }
  puts number/2
  puts output.strip
else
  if number == 3
    puts 1
    puts number
  else
    balance = number - 3
    output = ''
    (balance/2).times { output << '2 ' }
    output << '3'
    puts(balance/2 + 1)
    puts output
  end
end


n = input()

print n // 2

if n % 2 == 1:
        print 3,
        n -= 3

for i in xrange(n / 2):
        print 2,


import sys

n = int(sys.stdin.readline())
a=[]
while n>3:
   n-=2
   a.append('2')
if n==3:
   a.append('3')
elif n==2:
   a.append('2')

s=''
for x in a:
  s+=x+' '
s=s.strip()

print len(a)
print s


import sys

n = int(sys.stdin.readline())
a=[]
while n>3:
   n-=2
   a.append('2')
if n==3:
   a.append('3')
elif n==2:
   a.append('2')

s=''
for x in a:
  s+=x+' '
s=s.strip()

print len(x)
print s


n = int(raw_input())
print n / 2
cla = []
for i in range(n / 2):
	cla.append(2)
if n % 2 != 0:
	cla.remove(2)
	cla.append(3)
cla = map(str, cla)
print ' '.join(cla)


n = raw_input()
n = int(n)
remainder = n % 2
shang = n // 2

if remainder == 0:
    print shang
    while shang > 0:
        shang -= 1
        print "2",
else:
    print shang
    while shang > 1:
        shang -= 1
        print "2",
    print "3"


# -*- coding: utf-8 -*-

def solve(x):
    print (x / 2)
    for i in range(x/2-1):
        print 2,
    if x % 2:
        print 3
    else:
        print 2

def main():
    a = int(raw_input())
    solve(a)

if __name__ == '__main__':
    main()


import sys, os

n = int(input())
if n % 2:
    ans = ['2' for i in range((n - 3) // 2)] + ['3']
    print len(ans)
    print ' '.join(ans)
else:
    ans = ['2' for i in range(n // 2)]
    print len(ans)
    print ' '.join(ans)


import sys, os

n = int(input())
if n % 2:
    ans = ['2' for i in range((n - 3) // 2)] + ['3']
    print ' '.join(ans)
else:
    ans = ['2' for i in range(n // 2)]
    print ' '.join(ans)


n=input()

if n%2==0:
    x=n/2
    print x
    li=[]
    for i in range(1,x+1):
        li=li+['2']
    delimiter=' '
    s=delimiter.join(li)
    print s

else:
    x=n/2
    print x
    li=[]
    for i in range(1,x):
        li=li+['2']
    li=li+['3']
    delimiter=' '
    s=delimiter.join(li)
    print s


n=input()

if n%2==0:
    x=n/2
    print x
    #li=[]
    s=''
    for i in range(1,x+1):
        s=s+' '+'2'

   #     li=li+['2']
 #   delimiter=' '
  #  s=delimiter.join(li)
    print s[1:]

else:
    x=n/2
    print x
    s=''
    #li=[]
    for i in range(1,x):
        s=s+' '+'2'
     #   li=li+['2']
    #li=li+['3']
    s=s+' '+'3'

    #delimiter=' '
    #s=delimiter.join(li)
    print s[1:]


#!/usr/bin/env python
#-*- coding: utf-8 -*-

from collections import defaultdict
from math import factorial as f
from fractions import gcd as g

n = int (raw_input ())
if n <= 3:
    print "1"
    print n
else:
    print n / 2
    while n > 3:
        print "2",
        n -= 2
    print n


n=input()

if n%2==0:
	ans1= n/2
	ans2= '2 '* ans1
else:
	ans1= n/2
	ans2= ('2 '* (ans1-1))+ '3'
print ans1
print ans2


N  = int(input())
if N % 2 == 0:
    print N / 2
    for i in range(1, N/2 + 1):
        print 2,
else:
    print (N - 3)/2 + 1
    for i in range(1, (N - 3)/2 + 1):
        print 2,
    print 3


#!/usr/bin/python

n = int(raw_input())

if n%2==0:
	print n/2
	while n:
		print "2",
		n -= 2
else:
	x = n/2 - 1
	print x+1
	while x:
		print "2",
		x -= 1
	print "3"


#!/usr/bin/python

n = int(raw_input())

if n%2==0:
	while n:
		print "2",
		n -= 2
else:
	x = n/2 - 1
	while x:
		print "2",
		x -= 1
	print "3"


number = input()

if number % 2 == 0:
    count = number / 2

    print count

    for i in range(1, count + 1):
        print "%i" % 2,
else:
    count = number / 2

    print count

    for i in range(1, count):
        print "%i" % 2,

    if count != 0:
        print 3


def bechhold(number):
    if number % 2 == 0:
        count = number / 2

        print count

        for i in range(1, count + 1):
            print "%i" % 2,
    else:
        count = number / 2

        print count

        for i in range(1, count):
            print "%i" % 2,

        print 3


n =int(input())
print n/2
resul = ""
while n>3:
	resul = resul + "2 "
	n = n - 2
resul = resul + str(n)
print resul


n =int(input())
print n/2
resul = ""
while n>3:
	resul = resul + "2 "
	n = n - 2
resul = resul + "3"
print resul


n =int(input())
print n/2
resul = ""
while n>3:
	resul = resul + "2 "
	n = n - 2
if(n%2 == 0):
	resul = resul + "2"
else:
	resul = resul + "3"
print resul


n=int(raw_input())
nums=[]

if n%2!=0:
    for i in range((n/2)-1):
        nums.append(2)
    nums.append(3)
else:
    for i in range(n/2):
        nums.append(2)

print len(nums)
num=''
for i in nums:
    num+=str(i)+' '
print num


n=int(raw_input())
nums=[]

if n%2==0:
    for i in range((n/2)-1):
        nums.append(2)
    nums.append(3)
else:
    for i in range(n/2):
        nums.append(2)

print len(nums)
num=''
for i in nums:
    num+=str(i)+' '
print num


def IsPrime(n):
    if n==0 or n==1 or n%2==0:
        return False
    if n==2:
        return True
    for i in range(2,n):
        if n%i==0:
            break
    if i==n-1 and n%i!=0:
        return True
    else:
        return False

n=int(raw_input())
nums=[]

for i in range(n/2):
    nums.append(2)

summ=(2*(n/2))+(n%2)
q=n/2
rem=n%2
i=1

while True and n%2!=0:
    #print rem,summ,q
    if summ==n and IsPrime(rem):
        nums.append(rem)
        break
    nums.remove(2)
    rem=2*i+n%2
    q-=1
    summ=(2*q)+(rem)
    i+=1

print len(nums)
num=''
for i in nums:
    num+=str(i)+' '
print num


n = int(input())
arr=[]
if n%2==0:
  arr=[2]*(n/2)
else:
  arr=[2]*((n/2)-1)+[3]
print len(arr)
print(' '.join(map(str,arr)))


n=int(raw_input())
a=[2]*(n/2)
if n%2==1: a[len(a)-1]=3
print " ".join(map(str,a))


n=int(raw_input())
a=[2]*(n/2)
if n%2==1: a[len(a)-1]=3
print len(a)
print " ".join(map(str,a))


n=int(raw_input())

print(n/2)
res=""
i=0

if n%2==0:
    while i<n/2:
        res+="2 "
        i+=1
else:
    while i<n/2-1:
        res+="2 "
        i+=1
    res+="3 "
print(res[:len(res)-1])


n = int(input())

twos = 0
threes = 0

if n % 2 == 0:
	twos = n/2
else:
	threes = 1
	twos = (n-3)/2

print twos+threes
for i in xrange(twos):
	print 2,
for i in xrange(threes):
	print 3,


n=int(raw_input())
print n/2
if n%2==0:
    for i in xrange(0,n/2):
        print 2
else:
    for i in xrange(0,n/2-1):
        print 2
    print 3


n=int(raw_input())
arr=[]
if n%2!=0:
    arr.append(3)
    n-=3
while n!=0:
    n-=2
    arr.append(2)

print len(arr)
print ' '.join(str(i) for i in arr)


prime=[1]*(100011)
prime[0]=0
prime[1]=0
for i in xrange(2,100011):
    if prime[i]==1:
        for j in xrange(i*2,100011,i):
            prime[j]=0

n=int(raw_input())
arr=[]
x=100011
for i in xrange(0,x):
    if prime[i]==1:
        flag=1
        while n>=i:
            if prime[n-i]==1:
                arr.append(i)
                n-=i
                flag=0
                break
            n-=i
            arr.append(i)
        if flag==0:
            arr.append(n)
            break
print ' '.join(str(i) for i in arr)


prime=[1]*(100011)
prime[0]=0
prime[1]=0
for i in xrange(2,100011):
    if prime[i]==1:
        for j in xrange(i*2,100011,i):
            prime[j]=0

n=int(raw_input())
arr=[]
x=100011
for i in xrange(0,x):
    if prime[i]==1:
        flag=1
        while n>=i:
            if prime[n-i]==1:
                arr.append(i)
                n-=i
                flag=0
                break
            n-=i
            arr.append(i)
        if flag==0:
            arr.append(n)
            break
print len(arr)
print ' '.join(str(i) for i in arr)


n = eval(input())

while n > 0:
	if(n % 2 > 0):
		print(3,' ')
		n -= 3
	else:
		print(2,' ')


// In the name of God
// Code by: mrMaster

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int MN = 1e6 + 10;

int base;
vector<bool>v;
int odd , even;
int n,q;
int res[MN];

void input()
{
	scanf("%d%d" , &n , &q);
	int mod , x;
	for(int i=0;i<q;++i){
		scanf("%d" , &mod);
		if(mod == 1){
			scanf("%d" , &x);
			base = (base - x + 2*n)%n;
		}else
			v.push_back(base&1);
	}
}

void prep()
{
	for(int i=0;i<v.size();++i){
		if(v[i] == (i&1))
			++even;
		else
			--even;
	}
	for(int i=0;i<v.size();++i){
		if(v[i] == ((i+1)&1))
			++odd;
		else
			--odd;
	}
}

void output()
{
	int t;
	for(int i=0;i<n;++i){
		t = (base + i + 2*n)%n;
		if(t&1)
			res[(t+odd+2*MN*n)%n] = t;
		else
			res[(t+even+2*MN*n)%n] = t;
	}
	for(int i=0;i<n;++i){
		t = (base + i + 2*n)%n;
		printf("%d ", res[t]+1);
	}
	printf("\n");
}

main()
{
	input();
	prep();
	output();
	return 0;
}


// In the name of God
// Code by: mrMaster

#include <bits/stdc++.h>

using namespace std;

int base;
vector<bool>v;
int odd , even;
int n,q;

void input()
{
	cin >>n >> q;
	int mod , x;
	for(int i=0;i<q;++i){
		cin >> mod;
		if(mod == 1){
			cin >> x;
			base = (base - x + 3*n)%n;
		}else
			v.push_back(base&1);
	}
}

void prep()
{
	for(int i=0;i<v.size();++i){
		if(v[i] == (i&1))
			++even;
		else
			--even;
	}
	for(int i=0;i<v.size();++i){
		if(v[i] == ((i+1)&1))
			++odd;
		else
			--odd;
	}
}

void output()
{
	for(int i=0;i<n;++i){
		int t = (base + i + 3*n)%n;
		if(t&1)
			cout << (t+odd+3*n)%n+1 << ' ';
		else
			cout << (t+even+3*n)%n+1 << ' ';
	}
	cout << endl;
}

int main()
{
	input();
	prep();
	output();
	return 0;
}


// In the name of God
// Code by: mrMaster

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define boost ios_base :: sync_with_stdio(false)

const int MN = 1e6 + 10;

int base;
vector<bool>v;
int odd , even;
int n,q;
int res[MN];

void input()
{
	boost;
	cin >> n >> q;
	int mod , x;
	for(int i=0;i<q;++i){
		cin >> mod;
		if(mod == 1){
			cin >> x;
			base = (base - x + 2*n)%n;
		}else
			v.push_back(base&1);
	}
}

void prep()
{
	for(int i=0;i<v.size();++i){
		if(v[i] == (i&1))
			++even;
		else
			--even;
	}
	for(int i=0;i<v.size();++i){
		if(v[i] == ((i+1)&1))
			++odd;
		else
			--odd;
	}
}

void output()
{
	boost;
	int t;
	for(int i=0;i<n;++i){
		t = (base + i + 2*n)%n;
		if(t&1)
			res[(t+odd+2*MN*n)%n] = t;
		else
			res[(t+even+2*MN*n)%n] = t;
	}
	for(int i=0;i<n;++i){
		t = (base + i + 2*n)%n;
		cout << res[t]+1 << ' ';
	}
	cout << endl;
}

main()
{
	input();
	prep();
	output();
	return 0;
}


// In the name of God
// Code by: mrMaster

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int MN = 1e6 + 10;

int base;
vector<bool>v;
int odd , even;
int n,q;
int res[MN];

void input()
{
	ios_base :: sync_with_stdio(false) , cin.tie(0);
	cin >>n >> q;
	int mod , x;
	for(int i=0;i<q;++i){
		cin >> mod;
		if(mod == 1){
			cin >> x;
			base = (base - x + 2*n)%n;
		}else
			v.push_back(base&1);
	}
}

void prep()
{
	for(int i=0;i<v.size();++i){
		if(v[i] == (i&1))
			++even;
		else
			--even;
	}
	for(int i=0;i<v.size();++i){
		if(v[i] == ((i+1)&1))
			++odd;
		else
			--odd;
	}
}

void output()
{
	ios_base :: sync_with_stdio(false) , cout.tie(0);
	int t;
	for(int i=0;i<n;++i){
		t = (base + i + 2*n)%n;
		if(t&1)
			res[(t+odd+2*MN*n)%n] = t;
		else
			res[(t+even+2*MN*n)%n] = t;
	}
	for(int i=0;i<n;++i){
		t = (base + i + 2*n)%n;
		cout << res[t]+1 << ' ';
	}
	cout << endl;
}

main()
{
	input();
	prep();
	output();
	return 0;
}


// In the name of God
// Code by: mrMaster

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int MN = 1e6 + 10;

int base;
vector<bool>v;
int odd , even;
int n,q;
int res[MN];

void input()
{
	ios_base :: sync_with_stdio(false) , cin.tie(0);
	cin >>n >> q;
	int mod , x;
	for(int i=0;i<q;++i){
		cin >> mod;
		if(mod == 1){
			cin >> x;
			base = (base - x + 2*n)%n;
		}else
			v.push_back(base&1);
	}
}

void prep()
{
	for(int i=0;i<v.size();++i){
		if(v[i] == (i&1))
			++even;
		else
			--even;
	}
	for(int i=0;i<v.size();++i){
		if(v[i] == ((i+1)&1))
			++odd;
		else
			--odd;
	}
}

void output()
{
	ios_base :: sync_with_stdio(false) , cout.tie(0);
	for(int i=0;i<n;++i){
		int t = (base + i + 2*n)%n;
		if(t&1)
			res[(t+odd+2*MN*n)%n] = t;
		else
			res[(t+even+2*MN*n)%n] = t;
	}
	for(int i=0;i<n;++i){
		int t = (base + i + 2*n)%n;
		cout << res[t]+1 << ' ';
	}
	cout << endl;
}

main()
{
	input();
	prep();
	output();
	return 0;
}