#include<bits/stdc++.h>
using namespace std;
#define ff                first
#define brn                "\n"
#define ss                second
#define mk                make_pair
#define int               long long
#define pb                push_back
#define ps(x,y)           fixed<<setprecision(y)<<x
#define w(x)              int x; cin>>x; while(x--)
#define FOR(i,a,b)        for(int i=(a);i<(b);i++)
#define ROF(i,a,b)        for(int i=(a);i>=(b);i--)
#define so(a,n)           sort(a,a+n)
#define rso(a,n)          sort(a,a+n),reverse(a,a+n)
#define all(v)            (v).begin(),(v).end()
#define sz                size();
#define p_sieve           1000007
const int                 maxn = 1e3 + 5;
#define mod               1000000009;
const int                 p = 1000000009;

// int used[200005];
// vector<int>v[200005];
// vector<int>vec;
// int ar[200005];
// int ans;
// void dfs(int n)
// {
//     used[n]=1;
//     vec.pb(n);
//     ans++;
//     for(auto i:v[n])
//     {
//       if(used[i]==0)dfs(i);
//     }
// }
// for( int i = 0 ; i < ( 1 << n ) ; ++ i ) {    // for each subset, O(2^n)
//         for ( int j = 0; j < n ; ++ j ) {       // check membership, O(n)
//             if ( ( i & ( 1 << j ) ) ! = 0 )    // test if bit ‘j’ is turned on in subset ‘i’?
//                 results[i] += s [j] ;          // if yes, process ‘j’
//         }
//     }
// }

//#########################---------code starts from here------------##################################################
// check for n==1 and <= and >= please.............

void solve()
{
  int n,m;cin>>n>>m;
  int maxi=max(n,m);
  int mini=min(n,m);
  int val=(maxi/mini);
  if(val+2>=(maxi-(val+2)))cout<<"Finite\n";
  else cout<<"Infinite\n";
}
//########################---------code ends here------------------########################################################
int32_t main()
{
  w(t)
  solve();
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while (t--) {
       int a, b;
       cin >> a >> b;
       vector <pair <int, int> > v(1e4+1);
       v[0].first = 0;
       v[0].second = 1;
       for (int i=1; i<=1e4; i++) {
           v[i].first = i;
           v[i].second = 0;
           if (v[i].first % a == 0 && v[i-a].second == 1 && i >= a) {
               v[i].second = 1;
           }
           if (v[i].first % b == 0 && v[i-b].second == 1 && i >= b) {
               v[i].second = 1;
           }
       }
       int i = 1;
       bool c = false;
       while (i <= 1e4) {
           if (v[i].second == 1 && v[i-1].second == 1) {
               cout << "Finite" << endl;
               c = true;
               break;
           }
           i++;
       }
       if (c == true) {
           continue;
       }
       cout << "Infinite" << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while (t--) {
       int a, b;
       cin >> a >> b;
       if (a%2 == 0 && b%2 == 0) {
           cout << "Infinite" << endl;
           continue;
       }
       vector <pair <int, int> > v(1e4+1);
       v[0].first = 0;
       v[0].second = 1;
       for (int i=1; i<=1e4; i++) {
           v[i].first = i;
           v[i].second = 0;
           if (v[i].first % a == 0 && v[i-a].second == 1 && i >= a) {
               v[i].second = 1;
           }
           if (v[i].first % b == 0 && v[i-b].second == 1 && i >= b) {
               v[i].second = 1;
           }
       }
       int i = 1;
       bool c = false;
       while (i <= 1e4) {
           if (v[i].second == 1 && v[i-1].second == 1) {
               cout << "Finite" << endl;
               c = true;
               break;
           }
           i++;
       }
       if (c == true) {
           continue;
       }
       cout << "Infinite" << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while (t--) {
       int a, b;
       cin >> a >> b;
       vector <pair <int, int> > v(1e4+1);
       v[0].first = 0;
       v[0].second = 1;
       for (int i=1; i<=1e4; i++) {
           v[i].first = i;
           v[i].second = 0;
           if (v[i].first % a == 0) {
               v[i].second = 1;
           }
           if (v[i].first % b == 0) {
               v[i].second = 1;
           }
       }
       int i = 1;
       bool c = false;
       while (i <= 1e4) {
           if (v[i].second == 1 && v[i-1].second == 1) {
               cout << "Finite" << endl;
               c = true;
               break;
           }
           i++;
       }
       if (c == true) {
           continue;
       }
       cout << "Infinite" << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while (t--) {
       int a, b;
       cin >> a >> b;
       vector <pair <int, int> > v(1e4+1);
       v[0].first = 0;
       v[0].second = 1;
       for (int i=1; i<=1e4; i++) {
           v[i].first = i;
           v[i].second = 0;
           if (v[i].first % a == 0 && v[i-a].second == 1) {
               v[i].second = 1;
           }
           if (v[i].first % b == 0 && v[i-b].second == 1) {
               v[i].second = 1;
           }
       }
       int i = 1;
       bool c = false;
       while (i <= 1e4) {
           if (v[i].second == 1 && v[i-1].second == 1) {
               cout << "Finite" << endl;
               c = true;
               break;
           }
           i++;
       }
       if (c == true) {
           continue;
       }
       cout << "Infinite" << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while (t--) {
        int a, b;
        cin >> a >> b;
        if (__gcd(a, b) == 1) {
            cout << "Finite" << endl;
        } else {
            cout << "Infinite" << endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#include<vector>
#include <algorithm>
#include<sstream>
#include<string>
#include<queue>
#define int long long
#define float long double
using namespace std;
 signed main()
{
  ios_base::sync_with_stdio(false);
  int t;
  cin>>t;
  while(t--)
  {
      int a,b;
      cin>>a>>b;
      int x=min(a,b),y=max(a,b);
      if(x==1)
        cout<<"finite"<<endl;
      else{
      if(y%x!=0)
        cout<<"finite"<<endl;
      else
      cout<<"infinite"<<endl;
      }
  }
}


#include<bits/stdc++.h>
#include<vector>
#include <algorithm>
#include<sstream>
#include<string>
#include<queue>
#define int long long
#define float long double
using namespace std;
 signed main()
{
  ios_base::sync_with_stdio(false);
  int t;
  cin>>t;
  while(t--)
  {
      int a,b;
      cin>>a>>b;
      int x=min(a,b),y=max(a,b);
      if(x==1)
        cout<<"finite"<<endl;
     else
     {
         if(__gcd(x,y)>1)
            cout<<"infinite"<<endl;
         else
            cout<<"finite"<<endl;
     }
  }
}


#include<bits/stdc++.h>
#include<vector>
#include <algorithm>
#include<sstream>
#include<string>
#include<queue>
#define int long long
#define float long double
using namespace std;
 signed main()
{
  ios_base::sync_with_stdio(false);
  int t;
  cin>>t;
  while(t--)
  {
      int a,b;
      cin>>a>>b;
      int x=min(a,b),y=max(a,b);
      if(x==1)
        cout<<"finite"<<endl;
     else if(x==y)
        cout<<"infinite"<<endl;
      else{
      if(y%(y-x)==0&&x%(y-x)==0)
        cout<<"infinite"<<endl;
      else
      cout<<"finite"<<endl;
      }
  }
}


#include<bits/stdc++.h>
#include<vector>
#include <algorithm>
#include<sstream>
#include<string>
#include<queue>
#define int long long
#define float long double
using namespace std;
 signed main()
{
  ios_base::sync_with_stdio(false);
  int t;
  cin>>t;
  while(t--)
  {
      int a,b;
      cin>>a>>b;
      int x=min(a,b),y=max(a,b);
      if(y-x>=x)
        cout<<"finite"<<endl;
      else
      cout<<"infinite"<<endl;
  }
}


#include<bits/stdc++.h>
#include<vector>
#include <algorithm>
#include<sstream>
#include<string>
#include<queue>
#define int long long
#define float long double
using namespace std;
 signed main()
{
  ios_base::sync_with_stdio(false);
  int t;
  cin>>t;
  while(t--)
  {
      int a,b;
      cin>>a>>b;
      int x=min(a,b),y=max(a,b);
      if(y-x>x)
        cout<<"finite"<<endl;
      else
      cout<<"infinite"<<endl;
  }
}


#include<bits/stdc++.h>
#include<vector>
#include <algorithm>
#include<sstream>
#include<string>
#include<queue>
#define int long long
#define float long double
using namespace std;
 signed main()
{
  ios_base::sync_with_stdio(false);
  int t;
  cin>>t;
  while(t--)
  {
      int a,b;
      cin>>a>>b;
      int x=min(a,b),y=max(a,b);
      if(y-x>x||x==1)
        cout<<"finite"<<endl;
      else
      cout<<"infinite"<<endl;
  }
}


#include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    int main()
    {
        ll t;
        cin>>t;
        while(t--)
        {

        ll n,m;
        cin>>n>>m;

        n=min(n,m);

        if(n*2<=10) cout<<"Finite"<<endl;
        else cout<<"Infinite"<<endl;
        }

    }


 #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    int main()
    {
        ll t;
        cin>>t;
        while(t--)
        {

        ll n,m;
        cin>>n>>m;

        n=min(n,m);

        if(n<=5) cout<<"Finite"<<endl;
        else cout<<"Infinite"<<endl;
        }

    }


#include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    int main()
    {
        ll t;
        cin>>t;
        while(t--)
        {

        ll n,m;
        cin>>n>>m;

        n=min(n,m);

        if(n*2<10) cout<<"Finite"<<endl;
        else cout<<"Infinite"<<endl;
        }

    }


#include<bits/stdc++.h>

using namespace std;
#define           ff                first
#define           ss                second
#define           PF                printf
#define           pb                push_back
#define           nl                printf("\n");
#define           toDecimal(s,base) stoi(s,nullptr,base)
#define           pf(x)             printf("%d",x)
#define           iin(x)            scanf("%d",&x)
#define           din(x)            scanf("%lf",&x)
#define           lin(x)            scanf("%lld",&x)
#define           pfl(x)            printf("%lld",x)
#define           all(x)            x.begin(),x.end()
#define           rall(x)           x.rbegin(),x.rend()
#define           file_in           freopen("input.txt", "r", stdin)
#define           file_out          freopen("output.txt", "w", stdout)
#define           show(x)           for(auto it : x) cout << it << " "
#define           first_set(x)      __builtin_ffs(x)
#define           lead_zero(x)      __builtin_clz(x)
#define           trail_zero(x)      __builtin_ctz(x)
#define           set_bits(x)      __builtin_popcount(x)
#define           ERAGE(x)         x.erase(unique(all(x)),x.end())
bool pas = false;

int main(){
     int tc = 1;
     iin(tc);
     while(tc--){
           int a,b;
           iin(a);
           iin(b);
            if(__gcd(a,b) == 1) cout << "Finite\n";
            else cout << "Infinite\n";

     }
}
 /*****************************************************
 *   Duplicate line 	Ctr + D                       *
 *   Swap line above 	Ctr + T                       *
 *   Line cut	      Ctr + L                       *
 *   Line comment       Ctr + Shift + c               *
 *   Line delete	      Ctr + Shift + L               *
 *   move line          Alt+up/down                   *
 *****************************************************/
 /*****************************************************
 *     tie(a,b,c) = mt(1,2,3); // assign              *
 *     tie(a,b) = mt(b,a); // swap(a,b)               *
 *     tuple<int, int, int, char> t (3, 4, 5, 'g');   *
 *     int a, b;                                     *
 *     tie(b, ignore, a, ignore) = t;                *
 *****************************************************/


#include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    int main()
    {
        ll t;
        cin>>t;
        while(t--)
        {

        ll n,m,cnt=0;
        cin>>n>>m;
        m+=n;
        n=min(n,m);
        m-=n;

        if(__gcd(m,n)==1) cout<<"Finite"<<endl;
        else cout<<"Infinite"<<endl;
        }

    }


 #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    int main()
    {
        ll t;
        cin>>t;
        while(t--)
        {

        ll n,m;
        cin>>n>>m;

        n=min(n,m);

        if(n<=10 && __gcd(n,m)==1) cout<<"Finite"<<endl;
        else cout<<"Infinite"<<endl;
        }

    }


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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin >> t;

    while(t--)
    {
        int a,b,ok=1;
        cin >> a >> b;

        for(int i=1;i<=10;i++)
        {
            if(i%a==0)
            {
                ok++;
            }
            else if(i%b==0)
            {
                ok++;
            }
            else if(i%(a+b)==0)
            {
                ok++;
            }
        }
        if(ok>5)
        {
            cout << "finite" << endl;
        }
        else
        {
            cout << "Infinite" << endl;
        }
    }

}


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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long int t;
    cin >> t;

    while(t--)
    {
        int a,b,ok=1;
        cin >> a >> b;

        for(int i=1;i<=10;i++)
        {
            if(i%a==0)
            {
                ok++;
            }
            else if(i%b==0)
            {
                ok++;
            }
            else if(i%(a+b)==0)
            {
                ok++;
            }
        }
        if(ok>5)
        {
            cout << "finite" << endl;
        }
        else
        {
            cout << "Infinite" << endl;
        }
    }

}


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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long int t;
    cin >> t;

    while(t--)
    {
        int a,b,ok=0;
        cin >> a >> b;

        for(int i=1;i<=10;i++)
        {
            if(i%a==0)
            {

            }
            else if(i%b==0)
            {

            }
            else if(i%(a+b)==0)
            {

            }
            else
            {
                ok++;
            }
            // cout << ok << " ";
        }
        if(ok>5)
        {
            cout << "Infinite" << endl;
        }
        else
        {
            cout << "finite" << endl;
        }
    }

}


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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long int t;
    cin >> t;

    while(t--)
    {
        int a,b;
        cin >> a >> b;

        if(__gcd(a,b)==1)
        {
            cout << "finite" << endl;
        }
        else
        {
            cout << "Infinite" << endl;
        }
    }

}


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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long int t;
    cin >> t;

    while(t--)
    {
        int a,b,ok=0;
        cin >> a >> b;

        for(int i=1;i<=10;i++)
        {
            if(i%a==0)
            {

            }
            else if(i%b==0)
            {

            }
            else if(i%(a+b)==0)
            {

            }
            else
            {
                ok++;
            }
            // cout << ok << " ";
        }
        if(ok>5)
        {
            cout << "finite" << endl;
        }
        else
        {
            cout << "Infinite" << endl;
        }
    }

}


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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long int t;
    cin >> t;

    while(t--)
    {
        int a,b,ok=0;
        cin >> a >> b;

        for(int i=1;i<=10;i++)
        {
            if(i%a==0)
            {

            }
            else if(i%b==0)
            {

            }
            else if(i%(a+b)==0)
            {

            }
            else
            {
                ok++;
            }
            cout << ok << " ";
        }
        if(ok>5)
        {
            cout << "Infinite" << endl;
        }
        else
        {
            cout << "finite" << endl;
        }
    }

}


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

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int x,y;
        cin>>x>>y;
        int temp = x>y?x:y;
        x= x<y?x:y;
        y=temp;
        if(x==1)
        {
            cout<<"Finite\n";
            continue;
        }
        int flag=1;
        for(int i = 2;i<=x;i++)
        {
            if(x%i==0&&y%i==0)
            {
                cout<<"Infinite\n";
                flag=0;
                break;
            }
        }
        if(flag==1)
        {
            cout<<"Finite\n";
        }
    }
    return 0;
}


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

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int x,y;
        cin>>x>>y;
        int temp = x>y?x:y;
        x= x<y?x:y;
        y=temp;
        if(x==1||y==1||(y-x-1)%x==0)
        {
            cout<<"Finite\n";
        }
        else
        {
            cout<<"Infinite\n";
        }
    }
    return 0;
}


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

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int x,y;
        cin>>x>>y;
        int temp = x>y?x:y;
        x= x<y?x:y;
        y=temp;
        int count = 0;
        int a[100000] = {0};
        a[0]=1;
        int flag=0;
        for(int i=1;i<100000;i++)
        {
            if(count==y+1||count==x+1)
            {
                flag=1;
                break;
            }
            if(i>=x&&(a[i-x])==1)
            {
                a[i]=1;
                count++;
            }
            else if(i>=y&&(a[i-y])==1)
            {
                a[i]=1;
                count++;
            }
            else
            {
                a[i]=0;
                count=0;
            }

        }
        if(flag==1)
        {
            cout<<"Finite\n";
        }
        else
        {
            cout<<"Infinite\n";
        }
    }
    return 0;
}


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

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int x,y;
        cin>>x>>y;
        int temp = x>y?x:y;
        x= x<y?x:y;
        y=temp;
        if(x==1||y==1||(y-x)==x+1)
        {
            cout<<"Finite\n";
        }
        else
        {
            cout<<"Infinite\n";
        }
    }
    return 0;
}


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

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int x,y;
        cin>>x>>y;
        int temp = x>y?x:y;
        x= x<y?x:y;
        y=temp;
        int count = 0;
        int a[100000] = {0};
        a[0]=1;
        int flag=0;
        for(int i=1;i<100000;i++)
        {
            if(count==y+1)
            {
                flag=1;
                break;
            }
            if(i>=x&&(a[i-x])==1)
            {
                a[i]=1;
                count++;
            }
            else if(i>=y&&(a[i-y])==1)
            {
                a[i]=1;
                count++;
            }
            else
            {
                a[i]=0;
                count=0;
            }

        }
        if(flag==1)
        {
            cout<<"Finite\n";
        }
        else
        {
            cout<<"Infinite\n";
        }
    }
    return 0;
}


#import<bits/stdc++.h>
using namespace std;main(){int a,b,q;cin>>q;while(q--){cin>>a>>b;cout<<(__gcd(a,b)==1?"Finite\n":"Infinite\n");}}


#import<iostream>
using namespace std;main(){int a,b,q;cin>>q;while(q--){cin>>a>>b;cout<<(__gcd(a,b)==1?"Finite\n":"Infinite\n");}}


#include <iostream>
#include <map>
#include <algorithm>
#include <set>
#include <vector>
#include <string.h>
#include <math.h>
#define ll long long
#define INF 1000000005
using namespace std;
ll n;
char arr[1000006];

int main()
{  int t;
   cin>>t;
   while(t--){
        int a,b;
        cin>>a>>b;
        if(a>=b)swap(a,b);
        int x=b-a;
        if(x>=a)cout<<"FINITE"<<endl;
        else
            cout<<"INFINITE"<<endl;
   }
return 0;}


#include <iostream>
#include <map>
#include <algorithm>
#include <set>
#include <vector>
#include <string.h>
#include <math.h>
#define ll long long
#define INF 1000000005
using namespace std;
ll n;
char arr[1000006];

int main()
{  int t;
   cin>>t;
   while(t--){
        int a,b;
        cin>>a>>b;
        if(a>=b)swap(a,b);
        ll x=a*b;
        bool chk=true;
        while(x>=b){
            x--;
            if(x%a==0 && x%b==0){
                chk=false;
                break;
            }
        }
        if(chk)cout<<"FINITE"<<endl;
        else
            cout<<"INFINITE"<<endl;
   }
return 0;}


#include <iostream>
#include <map>
#include <algorithm>
#include <set>
#include <vector>
#include <string.h>
#include <math.h>
#define ll long long
#define INF 1000000005
using namespace std;
ll n;
char arr[10006];

int main()
{  int t;
   cin>>t;
   while(t--){
        int a,b;
        cin>>a>>b;
   for(int i=0;i<=10000;i++)arr[i]='b';
        arr[0]='w';
        int cnt_w=1;
        int x=min(a,b);
        x++;
        bool chk=false;
        for(int i=1;i<=10000;i++){
            if(i>=a){
             if(arr[i-a]=='w')arr[i]='w';
            }
            if(i>=b){
             if(arr[i-b]=='w')arr[i]='w';
            }
            if(arr[i]=='w')cnt_w++;
            else
                cnt_w=0;
            if(cnt_w>=x){
                chk=true;
                break;
            }}
     if(chk)cout<<"FINITE"<<endl;
     else
        cout<<"INFINITE"<<endl;
   }
return 0;}


#include <iostream>
#include <map>
#include <algorithm>
#include <set>
#include <vector>
#include <string.h>
#include <math.h>
#define ll long long
#define INF 1000000005
using namespace std;
ll n;
char arr[1000006];

int main()
{  int t;
   cin>>t;
   while(t--){
        int a,b;
        cin>>a>>b;
        if(a>=b)swap(a,b);
        ll x=a*b;
        bool chk=true;
        x-=b;
        while(x>=b){
            if(x%a==0 && x%b==0){
                chk=false;
                break;
            }
             x-=b;
        }
        if(chk)cout<<"FINITE"<<endl;
        else
            cout<<"INFINITE"<<endl;
   }
return 0;}


#include <iostream>
#include <map>
#include <algorithm>
#include <set>
#include <vector>
#include <string.h>
#include <math.h>
#define ll long long
#define INF 1000000005
using namespace std;
ll n;
char arr[1000006];

int main()
{  int t;
   cin>>t;
   while(t--){
        int a,b;
        cin>>a>>b;
   for(int i=0;i<=1000000;i++)arr[i]='b';
        arr[0]='w';
        int cnt_w=1;
        int x=min(a,b);
        x++;
        bool chk=false;
        for(int i=1;i<=1000000;i++){
            if(i>=a){
             if(arr[i-a]=='w')arr[i]='w';
            }
            if(i>=b){
             if(arr[i-b]=='w')arr[i]='w';
            }
            if(arr[i]=='w')cnt_w++;
            else
                cnt_w=0;
            if(cnt_w>=x){
                chk=true;
                break;
            }}
     //cout<<cnt_w<<endl;
     if(chk)cout<<"FINITE"<<endl;
     else
        cout<<"INFINITE"<<endl;
   }
return 0;}


#include <bits/stdc++.h>

using namespace std;

vector<int> generatePrimes() {

    const int nmax = int(1e9) + 50;
    int k = (int)sqrt(nmax);
    vector<int> primes;
    vector<bool> p(k + 1);
    for (int i = 2; i <= k; i++) {
        if (!p[i]) {
            primes.push_back(i);
            for (int j = i + i; j <= k; j += i) {
                p[j] = 1;
            }
        }
    }

    return primes;
}

int main() {

    int n, a, b;
    cin >> n >> a >> b;
    vector<int> primes = generatePrimes();
    vector< tuple<int, int, int> > v;
    for (int i = 0; i < n; i++) {
        int y;
        cin >> y;
        for (int k = -1; k < 2; k++) {
            int x = y + k;
            int kk = abs(k);
            for (int j = 0; primes[j] * primes[j] <= x; j++) {
                if (x % primes[j] == 0) {
                    while (x % primes[j] == 0) x /= primes[j];
                    v.push_back(make_tuple(primes[j], i, kk));
                }
            }
            if (x > 1) {
                v.push_back(make_tuple(x, i, kk));
            }
        }
    }

    long long ans = 1LL << 60;
    sort(begin(v), end(v));

    vector<int> c(2 * n);
    while (!v.empty()) {
        fill(begin(c), end(c), 2);
        int p = get<0>(v.back());
        cerr << "p : " << p << "\n";
        while (!v.empty() and get<0>(v.back()) == p) {
            int xx, i, j;
            tie(xx, i, j) = v.back();
            v.pop_back();
            c[i] = min(c[i], j);
            c[i + n] = c[i];
        }
//        for (int i = 0; i < 2 * n; i++) cerr << c[i] << " "; cerr << "\n";
        int num = 0, s = 0;
        for (int i = 0; i < 2 * n; i++) {
            if (c[i] == 2) {
                        num = s = 0;
            } else {
                num++;
                s += c[i];
            }
        while (num > n) {
                    s -= c[i - num];
                    num--;
                }

            if (num > 0) {
                ans = min(ans, 1LL * (n - num) * a + 1LL * b * s);
            }
        }

        while (num > n) {
            s -= c[2 * n - num];
            num--;
        }

        if (num > 0) {
            ans = min(ans, 1LL * (n - num) * a + 1LL * b * s);
            ans = min(ans, 1LL * (n - num) * a + 1LL * b * s);
        }
    }

    cout << ans;
}


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

vector<int> generatePrimes() {
    const int nmax = int(2e9);
    int k = (int)sqrt(nmax);
    vector<int> primes;
    vector<bool> p(k + 1);
    for (int i = 2; i <= k; i++) {
        if (!p[i]) {
            primes.push_back(i);
            for (int j = i + i; j <= k; j += i) {
                p[j] = 1;
            }
        }
    }

    return primes;
}

ll solve(int n, ll a, const vector<ll> &c, vector<ll>& S) {

    ll sum = 0;
    for (int i = 1; i <= n; i++) {
        sum += c[i - 1];
        S[i] = S[i - 1] + c[i - 1] - a;
    }

    ll ans = sum;
    ll b = S[n];
    for (int i = n - 1; i >= 0; i--) {
        ans = min(ans, sum + S[i] - b);
        b = max(b, S[i]);
    }
    return ans;
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    vector<int> primes = generatePrimes();
    vector<int> vv(n);
    unordered_set<int> s;
    for (int i = 0; i < n; i++) {
        cin >> vv[i];
    }
    for (int y : vector<int>{vv[0], vv[n - 1]}) {
        for (int k = -1; k < 2; k++) {
            int x = y + k;
            for (int j = 0; primes[j] * primes[j] <= x; j++) {
                if (x % primes[j] == 0) {
                    while (x % primes[j] == 0) x /= primes[j];
                    s.insert(primes[j]);
                }
            }
            if (x > 1) {
                s.insert(x);
            }
        }
    }

    long long ans = 1LL << 60;
    vector<ll> c(n);
    vector<ll> S(n + 1);
    for (const int& p : s) {
        for (int i = 0; i < n; i++) {
           if (vv[i] % p == 0) c[i] = 0;
           else
            if ((vv[i] - 1) % p == 0 or (vv[i] + 1) % p == 0) c[i] = b;
            else
                c[i] = 1LL << 34;
        }
        ll num = solve(n, a, c, S);
        ans = min(ans, num);
    }

    cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

vector<int> generatePrimes() {

    const int nmax = int(2e9) + 50;
    int k = (int)sqrt(nmax);
    vector<int> primes;
    vector<bool> p(k + 1);
    for (int i = 2; i <= k; i++) {
        if (!p[i]) {
            primes.push_back(i);
            for (int j = i + i; j <= k; j += i) {
                p[j] = 1;
            }
        }
    }

    return primes;
}
#define ll long long
long long solve(int N, ll a, vector<ll> &c) {
    vector<vector<long long>> cost(3, vector<long long>(N));
	cost[0][0] = cost[2][0] = c[0];
	cost[1][0] = a;
	for (int i = 1; i < N; ++i) {
		cost[0][i] = cost[0][i - 1] + c[i];
		cost[1][i] = a + min(cost[0][i - 1], cost[1][i - 1]);
		cost[2][i] = min(cost[2][i - 1], cost[1][i - 1]) + c[i];
	    for (int k = 0; k < 3; k++) cost[k][i] = min(cost[k][i], 1LL << 50);
    }
    return min(cost[0][N-1], min(cost[1][N-1], cost[2][N-1]));
}
int main() {

    int n, a, b;
    cin >> n >> a >> b;
    vector<int> primes = generatePrimes();
    vector<int> v;
    vector<int> vv(n);
    for (int i = 0; i < n; i++) {
        int y;
        cin >> y;
        vv[i] = y;
        for (int k = -1; k < 2; k++) {
            int x = y + k;
            for (int j = 0; primes[j] * primes[j] <= x; j++) {
                if (x % primes[j] == 0) {
                    while (x % primes[j] == 0) x /= primes[j];
                    v.push_back(primes[j]);
                }
            }
            if (x > 1) {
                v.push_back(x);
            }
        }
    }

    long long ans = 1LL << 60;
    sort(begin(v), end(v));
    v.erase(unique(begin(v), end(v)), end(v));
    vector<long long> c(n);
    deque<int> d;
    while (!v.empty()) {
        int p = v.back(); v.pop_back();
        fill(begin(c), end(c), 1LL << 50);
        for (int i = 0; i < n; i++) {
           if (vv[i] % p == 0) c[i] = 0;
           else
            if ((vv[i] - 1) % p == 0 or (vv[i] + 1) % p == 0) c[i] = b;

        }
        ans = min(ans, solve(n, a, c));

    }

    cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

vector<int> generatePrimes() {
    const int nmax = int(2e9);
    int k = (int)sqrt(nmax);
    vector<int> primes;
    vector<bool> p(k + 1);
    for (int i = 2; i <= k; i++) {
        if (!p[i]) {
            primes.push_back(i);
            for (int j = i + i; j <= k; j += i) {
                p[j] = 1;
            }
        }
    }

    return primes;
}
#define ll long long
long long solve(int N, ll a, vector<ll> &c, vector< vector<ll> >& cost) {
	cost[0][0] = cost[2][0] = c[0];
	cost[1][0] = a;
	for (int i = 1; i < N; ++i) {
		cost[0][i] = cost[0][i - 1] + c[i];
		cost[1][i] = a + min(cost[0][i - 1], cost[1][i - 1]);
		cost[2][i] = min(cost[2][i - 1], cost[1][i - 1]) + c[i];
	    for (int k = 0; k < 3; k++) cost[k][i] = min(cost[k][i], 1LL << 50);
    }
    return min(cost[0][N-1], min(cost[1][N-1], cost[2][N-1]));
}
int main() {

    int n, a, b;
    cin >> n >> a >> b;
    vector<int> primes = generatePrimes();
    vector<int> vv(n);
    unordered_set<int> s;
    for (int i = 0; i < n; i++) {
        cin >> vv[i];
    }
    for (int y : vector<int>{vv[0], vv[n - 1]}) {
        for (int k = -1; k < 2; k++) {
            int x = y + k;
            for (int j = 0; primes[j] * primes[j] <= x; j++) {
                if (x % primes[j] == 0) {
                    while (x % primes[j] == 0) x /= primes[j];
                    s.insert(primes[j]);
                }
            }
            if (x > 1) {
                s.insert(x);
            }
        }
    }

    long long ans = 1LL << 60;
    vector<long long> c(n);
    vector<vector<long long>> cost(3, vector<long long>(n));
    for (const int& p : s) {
        for (int i = 0; i < n; i++) {
           if (vv[i] % p == 0) c[i] = 0;
           else
            if ((vv[i] - 1) % p == 0 or (vv[i] + 1) % p == 0) c[i] = b;
            else
                c[i] = 1LL << 40;
        }
        ans = min(ans, solve(n, a, c, cost));

    }

    cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

vector<int> generatePrimes() {
    const int nmax = int(2e9);
    int k = (int)sqrt(nmax);
    vector<int> primes;
    vector<bool> p(k + 1);
    for (int i = 2; i <= k; i++) {
        if (!p[i]) {
            primes.push_back(i);
            for (int j = i + i; j <= k; j += i) {
                p[j] = 1;
            }
        }
    }

    return primes;
}
#define ll long long
long long solve(int N, ll a, vector<ll> &c, vector< vector<ll> >& cost) {
	cost[0][0] = cost[2][0] = c[0];
	cost[1][0] = a;
	for (int i = 1; i < N; ++i) {
		cost[0][i] = cost[0][i - 1] + c[i];
		cost[1][i] = a + min(cost[0][i - 1], cost[1][i - 1]);
		cost[2][i] = min(cost[2][i - 1], cost[1][i - 1]) + c[i];
	    for (int k = 0; k < 3; k++) cost[k][i] = min(cost[k][i], 1LL << 50);
    }
    return min(cost[0][N-1], min(cost[1][N-1], cost[2][N-1]));
}
int main() {

    int n, a, b;
    cin >> n >> a >> b;
    vector<int> primes = generatePrimes();
    vector<int> v;
    vector<int> vv(n);
    for (int i = 0; i < n; i++) {
        int y;
        cin >> y;
        vv[i] = y;
        if (i != 0 and i != n - 1) continue;
        for (int k = -1; k < 2; k++) {
            int x = y + k;
            for (int j = 0; primes[j] * primes[j] <= x; j++) {
                if (x % primes[j] == 0) {
                    while (x % primes[j] == 0) x /= primes[j];
                    v.push_back(primes[j]);
                }
            }
            if (x > 1) {
                v.push_back(x);
            }
        }
    }

    long long ans = 1LL << 60;
    sort(begin(v), end(v));
    v.erase(unique(begin(v), end(v)), end(v));
    vector<long long> c(n);

    vector<vector<long long>> cost(3, vector<long long>(n));
    for (int& p : v) {
        for (int i = 0; i < n; i++) {
           if (vv[i] % p == 0) c[i] = 0;
           else
            if ((vv[i] - 1) % p == 0 or (vv[i] + 1) % p == 0) c[i] = b;
            else
                c[i] = 1LL << 40;
        }
        ans = min(ans, solve(n, a, c, cost));

    }

    cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

vector<int> generatePrimes() {

    const int nmax = int(1e9) + 50;
    int k = (int)sqrt(nmax);
    vector<int> primes;
    vector<bool> p(k + 1);
    for (int i = 2; i <= k; i++) {
        if (!p[i]) {
            primes.push_back(i);
            for (int j = i + i; j <= k; j += i) {
                p[j] = 1;
            }
        }
    }

    return primes;
}

int main() {

    int n, a, b;
    cin >> n >> a >> b;
    vector<int> primes = generatePrimes();
    vector< tuple<int, int, int> > v;
    for (int i = 0; i < n; i++) {
        int y;
        cin >> y;
        for (int k = -1; k < 2; k++) {
            int x = y + k;
            int kk = abs(k);
            for (int j = 0; primes[j] * primes[j] <= x; j++) {
                if (x % primes[j] == 0) {
                    while (x % primes[j] == 0) x /= primes[j];
                    v.push_back(make_tuple(primes[j], i, kk));
                }
            }
            if (x > 1) {
                v.push_back(make_tuple(x, i, kk));
            }
        }
    }

    long long ans = 1LL << 60;
    sort(begin(v), end(v));

    vector<int> c(2 * n);
    while (!v.empty()) {
        fill(begin(c), end(c), 2);
        int p = get<0>(v.back());
        while (!v.empty() and get<0>(v.back()) == p) {
            int xx, i, j;
            tie(xx, i, j) = v.back();
            v.pop_back();
            c[i] = min(c[i], j);
            c[i + n] = c[i];
        }
//        for (int i = 0; i < 2 * n; i++) cerr << c[i] << " "; cerr << "\n";
        int num = 0, s = 0;
        for (int i = 0; i < 2 * n; i++) {
            if (c[i] == 2) {
                        num = s = 0;
            } else {
                num++;
                s += c[i];
            }
        while (num > n) {
                    s -= c[i - num];
                    num--;
                }

            if (num > 0) {
                ans = min(ans, 1LL * (n - num) * a + 1LL * b * s);
            }
        }

        while (num > n) {
            s -= c[2 * n - num];
            num--;
        }

        if (num > 0) {
            ans = min(ans, 1LL * (n - num) * a + 1LL * b * s);
            ans = min(ans, 1LL * (n - num) * a + 1LL * b * s);
        }
    }

    cout << ans;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

vector<int> generatePrimes() {
    const int nmax = int(2e9);
    int k = (int)sqrt(nmax);
    vector<int> primes;
    vector<bool> p(k + 1);
    for (int i = 2; i <= k; i++) {
        if (!p[i]) {
            primes.push_back(i);
            for (int j = i + i; j <= k; j += i) {
                p[j] = 1;
            }
        }
    }

    return primes;
}

int main() {

    int n, a, b;
    cin >> n >> a >> b;
    vector<int> primes = generatePrimes();
    vector<int> vv(n);
    unordered_set<int> s;
    for (int i = 0; i < n; i++) {
        cin >> vv[i];
    }
    for (int y : vector<int>{vv[0], vv[n - 1]}) {
        for (int k = -1; k < 2; k++) {
            int x = y + k;
            for (int j = 0; primes[j] * primes[j] <= x; j++) {
                if (x % primes[j] == 0) {
                    while (x % primes[j] == 0) x /= primes[j];
                    s.insert(primes[j]);
                }
            }
            if (x > 1) {
                s.insert(x);
            }
        }
    }

    long long ans = 1LL << 60;
    vector<vector<long long>> cost(3, vector<long long>(n));
    auto getCost = [&](int i, int p) -> long long {
        int& x = vv[i];
        if (x % p == 0)
            return 0;
        if ((x - 1) % p == 0 or (x + 1) % p == 0)
            return b;
        return 1LL << 40;
    };
    long long c;
    for (const int& p : s) {
        cost[0][0] = cost[2][0] = getCost(0, p);
        cost[1][0] = a;
        for (int i = 1; i < n; i++) {
            c = getCost(i, p);
            cost[0][i] = cost[0][i - 1] + c;
            cost[1][i] = a + min(cost[0][i - 1], cost[1][i - 1]);
            cost[2][i] = min(cost[2][i - 1], cost[1][i - 1]) + c;
            for (int k = 0; k < 3; k++) cost[k][i] = min(cost[k][i], 1LL << 40);
        }
        ans = min(ans, min(cost[0][n-1], min(cost[1][n-1], cost[2][n-1])));
    }
    cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

vector<int> generatePrimes() {

    const int nmax = int(1e9);
    int k = (int)sqrt(nmax);
    vector<int> primes;
    vector<bool> p(k + 1);
    for (int i = 2; i <= k; i++) {
        if (!p[i]) {
            primes.push_back(i);
            for (int j = i + i; j <= k; j += i) {
                p[j] = 1;
            }
        }
    }

    return primes;
}
#define ll long long
long long solve(int N, ll a, vector<ll> &c) {
    vector<vector<long long>> cost(3, vector<long long>(N));
	cost[0][0] = cost[2][0] = c[0];
	cost[1][0] = a;
	for (int i = 1; i < N; ++i) {
		cost[0][i] = cost[0][i - 1] + c[i];
		cost[1][i] = a + min(cost[0][i - 1], cost[1][i - 1]);
		cost[2][i] = min(cost[2][i - 1], cost[1][i - 1]) + c[i];
	    for (int k = 0; k < 3; k++) cost[k][i] = min(cost[k][i], 1LL << 50);
    }
    return min(cost[0][N-1], min(cost[1][N-1], cost[2][N-1]));
}
int main() {

    int n, a, b;
    cin >> n >> a >> b;
    vector<int> primes = generatePrimes();
    vector<int> v;
    vector<int> vv(n);
    for (int i = 0; i < n; i++) {
        int y;
        cin >> y;
        vv[i] = y;
        if (i != 0 and i != n - 1) continue;
        for (int k = -1; k < 2; k++) {
            int x = y + k;
            for (int j = 0; primes[j] * primes[j] <= x; j++) {
                if (x % primes[j] == 0) {
                    while (x % primes[j] == 0) x /= primes[j];
                    v.push_back(primes[j]);
                }
            }
            if (x > 1) {
                v.push_back(x);
            }
        }
    }

    long long ans = 1LL << 60;
    sort(begin(v), end(v));
    v.erase(unique(begin(v), end(v)), end(v));
    vector<long long> c(n);
    for (int& p : v) {
        fill(begin(c), end(c), 1LL << 50);
        for (int i = 0; i < n; i++) {
           if (vv[i] % p == 0) c[i] = 0;
           else
            if ((vv[i] - 1) % p == 0 or (vv[i] + 1) % p == 0) c[i] = b;

        }
        ans = min(ans, solve(n, a, c));

    }

    cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

vector<int> generatePrimes() {

    const int nmax = int(1e9);
    int k = (int)sqrt(nmax);
    vector<int> primes;
    vector<bool> p(k + 1);
    for (int i = 2; i <= k; i++) {
        if (!p[i]) {
            primes.push_back(i);
            for (int j = i + i; j <= k; j += i) {
                p[j] = 1;
            }
        }
    }

    return primes;
}
#define ll long long
long long solve(int N, ll a, vector<ll> &c, vector< vector<ll> >& cost) {
	cost[0][0] = cost[2][0] = c[0];
	cost[1][0] = a;
	for (int i = 1; i < N; ++i) {
		cost[0][i] = cost[0][i - 1] + c[i];
		cost[1][i] = a + min(cost[0][i - 1], cost[1][i - 1]);
		cost[2][i] = min(cost[2][i - 1], cost[1][i - 1]) + c[i];
	    for (int k = 0; k < 3; k++) cost[k][i] = min(cost[k][i], 1LL << 50);
    }
    return min(cost[0][N-1], min(cost[1][N-1], cost[2][N-1]));
}
int main() {

    int n, a, b;
    cin >> n >> a >> b;
    vector<int> primes = generatePrimes();
    vector<int> v;
    vector<int> vv(n);
    for (int i = 0; i < n; i++) {
        int y;
        cin >> y;
        vv[i] = y;
        if (i != 0 and i != n - 1) continue;
        for (int k = -1; k < 2; k++) {
            int x = y + k;
            for (int j = 0; primes[j] * primes[j] <= x; j++) {
                if (x % primes[j] == 0) {
                    while (x % primes[j] == 0) x /= primes[j];
                    v.push_back(primes[j]);
                }
            }
            if (x > 1) {
                v.push_back(x);
            }
        }
    }

    long long ans = 1LL << 60;
    sort(begin(v), end(v));
    v.erase(unique(begin(v), end(v)), end(v));
    vector<long long> c(n);

    vector<vector<long long>> cost(3, vector<long long>(n));
    for (int& p : v) {
        for (int i = 0; i < n; i++) {
           if (vv[i] % p == 0) c[i] = 0;
           else
            if ((vv[i] - 1) % p == 0 or (vv[i] + 1) % p == 0) c[i] = b;
            else
                c[i] = 1LL << 40;
        }
        ans = min(ans, solve(n, a, c, cost));

    }

    cout << ans;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

vector<int> generatePrimes() {
    const int nmax = int(2e9);
    int k = (int)sqrt(nmax);
    vector<int> primes;
    vector<bool> p(k + 1);
    for (int i = 2; i <= k; i++) {
        if (!p[i]) {
            primes.push_back(i);
            for (int j = i + i; j <= k; j += i) {
                p[j] = 1;
            }
        }
    }

    return primes;
}

int main() {

    int n;
    long long a, b;
    cin >> n >> a >> b;
    vector<int> primes = generatePrimes();
    vector<int> vv(n);
    unordered_set<int> s;
    for (int i = 0; i < n; i++) {
        cin >> vv[i];
    }
    for (int y : vector<int>{vv[0], vv[n - 1]}) {
        for (int k = -1; k < 2; k++) {
            int x = y + k;
            for (int j = 0; primes[j] * primes[j] <= x; j++) {
                if (x % primes[j] == 0) {
                    while (x % primes[j] == 0) x /= primes[j];
                    s.insert(primes[j]);
                }
            }
            if (x > 1) {
                s.insert(x);
            }
        }
    }

    long long ans = 1LL << 60, c;
    vector<vector<long long>> cost(3, vector<long long>(n));
    auto getCost = [&](int i, int p) -> long long {
        int& x = vv[i];
        if (x % p == 0)
            return 0;
        if ((x - 1) % p == 0 or (x + 1) % p == 0)
            return b;
        return 1LL << 40;
    };

    for (const int& p : s) {
        cost[0][0] = cost[2][0] = getCost(0, p);
        cost[1][0] = a;
        for (int i = 1; i < n; i++) {
            c = getCost(i, p);
            cost[0][i] = cost[0][i - 1] + c;
            cost[1][i] = a + min(cost[0][i - 1], cost[1][i - 1]);
            cost[2][i] = min(cost[2][i - 1], cost[1][i - 1]) + c;
            for (int k = 0; k < 3; k++) cost[k][i] = min(cost[k][i], 1LL << 40);
        }
        ans = min(ans, min(cost[0][n-1], min(cost[1][n-1], cost[2][n-1])));
    }
    cout << ans;
}


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

vector<int> generatePrimes() {
    const int nmax = int(2e9);
    int k = (int)sqrt(nmax);
    vector<int> primes;
    vector<bool> p(k + 1);
    for (int i = 2; i <= k; i++) {
        if (!p[i]) {
            primes.push_back(i);
            for (int j = i + i; j <= k; j += i) {
                p[j] = 1;
            }
        }
    }

    return primes;
}

ll solve(int n, ll a, const vector<ll> &c, vector<ll>& S) {

    ll sum = 0;
    for (int i = 1; i <= n; i++) {
        sum += c[i - 1];
        S[i] = S[i - 1] + c[i - 1] - a;
    }

    ll ans = sum;
    ll b = S[n];
    for (int i = n - 1; i >= 0; i--) {
        ans = min(ans, sum + S[i] - b);
        b = max(b, S[i]);
    }
    return ans;
}

int main() {
    int n, a, b;
    ios::sync_with_stdio(0);
    cin >> n >> a >> b;
    vector<int> primes = generatePrimes();
    vector<int> vv(n);
    unordered_set<int> s;
    for (int i = 0; i < n; i++) {
        cin >> vv[i];
    }
    for (int y : vector<int>{vv[0], vv[n - 1]}) {
        for (int k = -1; k < 2; k++) {
            int x = y + k;
            for (int j = 0; primes[j] * primes[j] <= x; j++) {
                if (x % primes[j] == 0) {
                    while (x % primes[j] == 0) x /= primes[j];
                    s.insert(primes[j]);
                }
            }
            if (x > 1) {
                s.insert(x);
            }
        }
    }

    long long ans = 1LL << 60;
    vector<ll> c(n);
    vector<ll> S(n + 1);
    for (const int& p : s) {
        for (int i = 0; i < n; i++) {
           if (vv[i] % p == 0) c[i] = 0;
           else
            if ((vv[i] - 1) % p == 0 or (vv[i] + 1) % p == 0) c[i] = b;
            else
                c[i] = 1LL << 34;
        }
        ll num = solve(n, a, c, S);
        ans = min(ans, num);
    }

    cout << ans;
}


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

vector<int> generatePrimes() {
    const int nmax = int(2e9);
    int k = (int)sqrt(nmax);
    vector<int> primes;
    vector<bool> p(k + 1);
    for (int i = 2; i <= k; i++) {
        if (!p[i]) {
            primes.push_back(i);
            for (int j = i + i; j <= k; j += i) {
                p[j] = 1;
            }
        }
    }

    return primes;
}

ll solve(int n, ll a, const vector<ll> &c, vector<ll>& S) {
    ll ans = numeric_limits<ll>::max();
    ll sum = 0;
    for (int i = 1; i <= n; i++) {
        sum += c[i - 1];
        S[i] = S[i - 1] + c[i - 1] - a;
    }

    ll b = S[n];
    for (int i = n - 1; i >= 0; i--) {
        ans = min(ans, sum + S[i] - b);
        b = max(b, S[i]);
    }
    return ans;
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    vector<int> primes = generatePrimes();
    vector<int> vv(n);
    unordered_set<int> s;
    for (int i = 0; i < n; i++) {
        cin >> vv[i];
    }
    for (int y : vector<int>{vv[0], vv[n - 1]}) {
        for (int k = -1; k < 2; k++) {
            int x = y + k;
            for (int j = 0; primes[j] * primes[j] <= x; j++) {
                if (x % primes[j] == 0) {
                    while (x % primes[j] == 0) x /= primes[j];
                    s.insert(primes[j]);
                }
            }
            if (x > 1) {
                s.insert(x);
            }
        }
    }

    long long ans = 1LL << 60;
    vector<ll> c(n);
    vector<ll> S(n + 1);
    for (const int& p : s) {
        for (int i = 0; i < n; i++) {
           if (vv[i] % p == 0) c[i] = 0;
           else
            if ((vv[i] - 1) % p == 0 or (vv[i] + 1) % p == 0) c[i] = b;
            else
                c[i] = 1LL << 32;
        }
        ll num = solve(n, a, c, S);
        ans = min(ans, num);
    }

    cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

vector<int> generatePrimes() {

    const int nmax = int(1e9);
    int k = (int)sqrt(nmax);
    vector<int> primes;
    vector<bool> p(k + 1);
    for (int i = 2; i <= k; i++) {
        if (!p[i]) {
            primes.push_back(i);
            for (int j = i + i; j <= k; j += i) {
                p[j] = 1;
            }
        }
    }

    return primes;
}
#define ll long long
long long solve(int N, ll a, vector<ll> &c, vector< vector<ll> >& cost) {
	cost[0][0] = cost[2][0] = c[0];
	cost[1][0] = a;
	for (int i = 1; i < N; ++i) {
		cost[0][i] = cost[0][i - 1] + c[i];
		cost[1][i] = a + min(cost[0][i - 1], cost[1][i - 1]);
		cost[2][i] = min(cost[2][i - 1], cost[1][i - 1]) + c[i];
	    for (int k = 0; k < 3; k++) cost[k][i] = min(cost[k][i], 1LL << 50);
    }
    return min(cost[0][N-1], min(cost[1][N-1], cost[2][N-1]));
}
int main() {

    int n, a, b;
    cin >> n >> a >> b;
    vector<int> primes = generatePrimes();
    vector<int> v;
    vector<int> vv(n);
    for (int i = 0; i < n; i++) {
        int y;
        cin >> y;
        vv[i] = y;
        if (i != 0 and i != n - 1) continue;
        for (int k = -1; k < 2; k++) {
            int x = y + k;
            for (int j = 0; primes[j] * primes[j] <= x; j++) {
                if (x % primes[j] == 0) {
                    while (x % primes[j] == 0) x /= primes[j];
                    v.push_back(primes[j]);
                }
            }
            if (x > 1) {
                v.push_back(x);
            }
        }
    }

    long long ans = 1LL << 60;
    sort(begin(v), end(v));
    v.erase(unique(begin(v), end(v)), end(v));
    vector<long long> c(n);

    vector<vector<long long>> cost(3, vector<long long>(n));
    for (int& p : v) {
        fill(begin(c), end(c), 1LL << 50);
        for (int i = 0; i < n; i++) {
           if (vv[i] % p == 0) c[i] = 0;
           else
            if ((vv[i] - 1) % p == 0 or (vv[i] + 1) % p == 0) c[i] = b;

        }
        ans = min(ans, solve(n, a, c, cost));

    }

    cout << ans;
}


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

vector<int> generatePrimes() {
    const int nmax = int(2e9);
    int k = (int)sqrt(nmax);
    vector<int> primes;
    vector<bool> p(k + 1);
    for (int i = 2; i <= k; i++) {
        if (!p[i]) {
            primes.push_back(i);
            for (int j = i + i; j <= k; j += i) {
                p[j] = 1;
            }
        }
    }

    return primes;
}

ll solve(int n, ll a, const vector<ll> &c, vector<ll>& S) {

    ll sum = 0;
    for (int i = 1; i <= n; i++) {
        sum += c[i - 1];
        S[i] = S[i - 1] + c[i - 1] - a;
    }

    ll ans = sum;
    ll b = S[n];
    for (int i = n - 1; i >= 0; i--) {
        ans = min(ans, sum + S[i] - b);
        b = max(b, S[i]);
    }
    return ans;
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    vector<int> primes = generatePrimes();
    vector<int> vv(n);
    unordered_set<int> s;
    for (int i = 0; i < n; i++) {
        cin >> vv[i];
    }
    for (int y : vector<int>{vv[0], vv[n - 1]}) {
        for (int k = -1; k < 2; k++) {
            int x = y + k;
            for (int j = 0; primes[j] * primes[j] <= x; j++) {
                if (x % primes[j] == 0) {
                    while (x % primes[j] == 0) x /= primes[j];
                    s.insert(primes[j]);
                }
            }
            if (x > 1) {
                s.insert(x);
            }
        }
    }

    long long ans = 1LL << 60;
    vector<ll> c(n);
    vector<ll> S(n + 1);
    for (const int& p : s) {
        for (int i = 0; i < n; i++) {
           if (vv[i] % p == 0) c[i] = 0;
           else
            if ((vv[i] - 1) % p == 0 or (vv[i] + 1) % p == 0) c[i] = b;
            else
                c[i] = 1LL << 32;
        }
        ll num = solve(n, a, c, S);
        ans = min(ans, num);
    }

    cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

vector<int> generatePrimes() {

    const int nmax = int(1e9) + 50;
    int k = (int)sqrt(nmax);
    vector<int> primes;
    vector<bool> p(k + 1);
    for (int i = 2; i <= k; i++) {
        if (!p[i]) {
            primes.push_back(i);
            for (int j = i + i; j <= k; j += i) {
                p[j] = 1;
            }
        }
    }

    return primes;
}

int main() {

    int n, a, b;
    cin >> n >> a >> b;
    vector<int> primes = generatePrimes();
    vector< tuple<int, int, int> > v;
    for (int i = 0; i < n; i++) {
        int y;
        cin >> y;
        for (int k = -1; k < 2; k++) {
            int x = y + k;
            int kk = abs(k);
            for (int j = 0; primes[j] * primes[j] <= x; j++) {
                if (x % primes[j] == 0) {
                    while (x % primes[j] == 0) x /= primes[j];
                    v.push_back(make_tuple(primes[j], i, kk));
                }
            }
            if (x > 1) {
                v.push_back(make_tuple(x, i, kk));
            }
        }
    }

    long long ans = 1LL << 60;
    sort(begin(v), end(v));

    vector<long long> c(2 * n + 1);
    deque<int> d;
    while (!v.empty()) {
        fill(begin(c), end(c), 1LL << 34);
        int p = get<0>(v.back());
        while (!v.empty() and get<0>(v.back()) == p) {
            int xx, i, j;
            tie(xx, i, j) = v.back();
            v.pop_back();
            c[i + 1] = min(c[1 + i], 1LL*j * b);
            c[i + n + 1] = c[1 +i];
        }
        d.clear();
        d.push_back(0);
        c[0] = -a;
        for (int i = 1; i <= 2 * n; i++) {
            c[i] = c[i] + c[i - 1] - a;
            ans = min(ans, c[i] - c[d.front()] + 1LL * n * a);
            if (i - n == d.front()) d.pop_front();
            while (!d.empty() and c[d.back()] <= c[i]) d.pop_back();
            d.push_back(i);
        }
    }

    cout << ans;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

vector<int> generatePrimes() {
    const int nmax = int(2e9);
    int k = (int)sqrt(nmax);
    vector<int> primes;
    vector<bool> p(k + 1);
    for (int i = 2; i <= k; i++) {
        if (!p[i]) {
            primes.push_back(i);
            for (int j = i + i; j <= k; j += i) {
                p[j] = 1;
            }
        }
    }

    return primes;
}

int main() {

    int n;
    long long, b;
    cin >> n >> a >> b;
    vector<int> primes = generatePrimes();
    vector<int> vv(n);
    unordered_set<int> s;
    for (int i = 0; i < n; i++) {
        cin >> vv[i];
    }
    for (int y : vector<int>{vv[0], vv[n - 1]}) {
        for (int k = -1; k < 2; k++) {
            int x = y + k;
            for (int j = 0; primes[j] * primes[j] <= x; j++) {
                if (x % primes[j] == 0) {
                    while (x % primes[j] == 0) x /= primes[j];
                    s.insert(primes[j]);
                }
            }
            if (x > 1) {
                s.insert(x);
            }
        }
    }

    long long ans = 1LL << 60, c;
    vector<vector<long long>> cost(3, vector<long long>(n));
    auto getCost = [&](int i, int p) -> long long {
        int& x = vv[i];
        if (x % p == 0)
            return 0;
        if ((x - 1) % p == 0 or (x + 1) % p == 0)
            return b;
        return 1LL << 40;
    };

    for (const int& p : s) {
        cost[0][0] = cost[2][0] = getCost(0, p);
        cost[1][0] = a;
        for (int i = 1; i < n; i++) {
            c = getCost(i, p);
            cost[0][i] = cost[0][i - 1] + c;
            cost[1][i] = a + min(cost[0][i - 1], cost[1][i - 1]);
            cost[2][i] = min(cost[2][i - 1], cost[1][i - 1]) + c;
            for (int k = 0; k < 3; k++) cost[k][i] = min(cost[k][i], 1LL << 40);
        }
        ans = min(ans, min(cost[0][n-1], min(cost[1][n-1], cost[2][n-1])));
    }
    cout << ans;
}


/********************************************
*                                           *
*    Solved By : Bir Bahadur Khatri(B'ru)   *
*      Be Positive,be Happy.                *
*                                           *
*********************************************/

#define ff first
#define D double
#define sz size()
#define ss second
#define PB push_back
#define SQR(n) (n*n)
#define CHR getchar()
#define NL printf("\n")
#include<bits/stdc++.h>
#define ULL unsigned LL
#define PI 2.0*acos(0.0)
#define LL long long int
#define S1(a) a=in<int>()
#define SL1(a) a=in<LL>()
#define Max(a,b) ((a>b)?a:b)
#define Min(a,b) ((a<b)?a:b)
#define all(a) a.begin(),a.end()
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
#define SL2(a,b) a=in<LL>(),b=in<LL>()
#define F(i,a,b) for(int i=a;i<b; i++)
#define S2(a,b) a=in<int>(),b=in<int>()
#define R(i,a,b) for(int i=a-1;i>=b; i--)
#define BitCnt(a) __builtin_popcountll(a)
#define MEM(a,val) memset(a,val,sizeof(a))
#define SL3(a,b,c) a=in<LL>(),b=in<LL>(),c=in<LL>()
#define S3(a,b,c) a=in<int>(),b=in<int>(),c=in<int>()
#define cp printf("***** here here here here *****\n");
#define trace1(x)                cerr << #x << ": " << x << endl;
#define InpOut freopen("A.in","r",stdin),freopen("A1.out","w",stdout)
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;

using namespace std;
template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template<typename T>inline T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T>inline T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
template<typename T>inline T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}
long long Bigmod(long long base, long long power, long long MOD){long long ret=1;while(power){if(power & 1)ret=(ret*base)%MOD;base=(base*base)%MOD;power>>=1;}return ret;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
long long ModInverse(long long number, long long MOD){return Bigmod(number, MOD-2, MOD);}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}
int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }

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

#define MD1 1000000007ULL
#define MD2 1000000009ULL
#define MD3 1000000021ULL
#define BS1 10000019ULL
#define BS2 10000079ULL
#define BS3 10000103ULL
#define PUL pair<ULL,ULL>

///         0123456789
#define MX  100007
#define MOD 1000000007
#define INF 1e17
#define EPS 1e-9
/// ==========================================////

int a[MX*10+10];

bool prime[MX+9];
vector<int> prm;
void seive()
{
    prime[1]=true;
    int s=sqrt(MX);
    for(int i=2; i<=s; i++)
    {
        if(!prime[i])
        {
            for(int j=2*i; j<=MX; j+=i)
            {
                prime[j]=true;

            }
        }
    }
    F(i,2,MX+1) if(prime[i]==false) prm.PB(i);
}

int R,pm;
LL x,y;

LL dp[1000009][3];

LL Solve(int pos,int flg) {
    if(pos==R) {
        return 0;
    }

    LL &res=dp[pos][flg];
    if(res!=-1) return res;

    res=INF;

    if(!flg) {
        if(a[pos]%pm==0) {
            res=min(res,Solve(pos+1,flg));
        }
        res=min(res,Solve(pos+1,1)+x);
        if( (a[pos]-1)%pm==0 ||(a[pos]+1)%pm==0) {
            res=min(res,Solve(pos+1,flg)+y);
        }
    }
    else if(flg==1) {
        res=min(res,Solve(pos+1,flg)+x);
        if(a[pos]%pm==0) {
            res=min(res,Solve(pos+1,2));
        }
        if( (a[pos]-1)%pm==0 ||(a[pos]+1)%pm==0) {
            res=min(res,Solve(pos+1,2)+y);
        }
    }
    else {
        if(a[pos]%pm==0) {
            res=min(res,Solve(pos+1,2));
        }
        if( (a[pos]-1)%pm==0 ||(a[pos]+1)%pm==0) {
            res=min(res,Solve(pos+1,2)+y);
        }
    }
    return res;
}

LL ans;

void Dekhi(int val,int l,int r,int flg) {
    if(l>r) {
        ans=min(ans,0LL);
        return;
    }

    R=r+1;
    int n=val;
    int sq=sqrt(n);

    vector<int> nw;

    for(int i=0;i<prm.sz&&prm[i]<=sq;i++) {
        if(n%prm[i]==0) {
            while(n%prm[i]==0) {
                n/=prm[i];
            }
            sq=sqrt(n);
            nw.PB( prm[i] );
        }
    }
    if(n>1) {
        nw.PB(n);
    }

    for(int i=0;i<nw.sz;i++) {
        pm=nw[i];
        MEM(dp,-1);
        LL tp=Solve(l,0);
        if(flg) tp+=y;
        ans=min(ans,tp);
    }
}

int main()
{
    seive();
    int n;
    S1(n); SL2(x,y);

    for(int i=1;i<=n;i++) S1(a[i]);

    int Fst=a[1],Last=a[n];

    ans=1e17;

    Dekhi(Fst,2,n,0);
    Dekhi(Fst-1,2,n,1);
    Dekhi(Fst+1,2,n,1);

    Dekhi(Last,1,n-1,0);
    Dekhi(Last+1,1,n-1,1);
    Dekhi(Last-1,1,n-1,1);

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

    return 0;
}

/*

7 46 23

47 17 90 30 39 6 63

*/

///============= Thank You ===================///


/********************************************
*                                           *
*    Solved By : Bir Bahadur Khatri(B'ru)   *
*      Be Positive,be Happy.                *
*                                           *
*********************************************/

#define ff first
#define D double
#define sz size()
#define ss second
#define PB push_back
#define SQR(n) (n*n)
#define CHR getchar()
#define NL printf("\n")
#include<bits/stdc++.h>
#define ULL unsigned LL
#define PI 2.0*acos(0.0)
#define LL long long int
#define S1(a) a=in<int>()
#define SL1(a) a=in<LL>()
#define Max(a,b) ((a>b)?a:b)
#define Min(a,b) ((a<b)?a:b)
#define all(a) a.begin(),a.end()
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
#define SL2(a,b) a=in<LL>(),b=in<LL>()
#define F(i,a,b) for(int i=a;i<b; i++)
#define S2(a,b) a=in<int>(),b=in<int>()
#define R(i,a,b) for(int i=a-1;i>=b; i--)
#define BitCnt(a) __builtin_popcountll(a)
#define MEM(a,val) memset(a,val,sizeof(a))
#define SL3(a,b,c) a=in<LL>(),b=in<LL>(),c=in<LL>()
#define S3(a,b,c) a=in<int>(),b=in<int>(),c=in<int>()
#define cp printf("***** here here here here *****\n");
#define trace1(x)                cerr << #x << ": " << x << endl;
#define InpOut freopen("A.in","r",stdin),freopen("A1.out","w",stdout)
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;

using namespace std;
template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template<typename T>inline T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T>inline T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
template<typename T>inline T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}
long long Bigmod(long long base, long long power, long long MOD){long long ret=1;while(power){if(power & 1)ret=(ret*base)%MOD;base=(base*base)%MOD;power>>=1;}return ret;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
long long ModInverse(long long number, long long MOD){return Bigmod(number, MOD-2, MOD);}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}
int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }

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

#define MD1 1000000007ULL
#define MD2 1000000009ULL
#define MD3 1000000021ULL
#define BS1 10000019ULL
#define BS2 10000079ULL
#define BS3 10000103ULL
#define PUL pair<ULL,ULL>

///         0123456789
#define MX  100007
#define MOD 1000000007
#define INF 1e17
#define EPS 1e-9
/// ==========================================////

int a[MX];

bool prime[MX+9];
vector<int> prm;
void seive()
{
    prime[1]=true;
    int s=sqrt(MX);
    for(int i=2; i<=s; i++)
    {
        if(!prime[i])
        {
            for(int j=2*i; j<=MX; j+=i)
            {
                prime[j]=true;

            }
        }
    }
    F(i,2,MX+1) if(prime[i]==false) prm.PB(i);
}

int R,pm;
LL x,y;

LL dp[100009][3];

LL Solve(int pos,int flg) {
    if(pos==R) {
        return 0;
    }

    LL &res=dp[pos][flg];
    if(res!=-1) return res;

    res=INF;

    if(!flg) {
        if(a[pos]%pm==0) {
            res=min(res,Solve(pos+1,flg));
        }
        res=min(res,Solve(pos+1,1)+x);
        if( (a[pos]-1)%pm==0 ||(a[pos]+1)%pm==0) {
            res=min(res,Solve(pos+1,flg)+y);
        }
    }
    else if(flg==1) {
        res=min(res,Solve(pos+1,flg)+x);
        if(a[pos]%pm==0) {
            res=min(res,Solve(pos+1,2));
        }
        if( (a[pos]-1)%pm==0 ||(a[pos]+1)%pm==0) {
            res=min(res,Solve(pos+1,2)+y);
        }
    }
    else {
        if(a[pos]%pm==0) {
            res=min(res,Solve(pos+1,2));
        }
        if( (a[pos]-1)%pm==0 ||(a[pos]+1)%pm==0) {
            res=min(res,Solve(pos+1,2)+y);
        }
    }
    return res;
}

LL ans;

void Dekhi(int val,int l,int r,int flg) {
    if(l>r) {
        ans=min(ans,0LL);
        return;
    }

    R=r+1;
    int n=val;
    int sq=sqrt(n);

    vector<int> nw;

    for(int i=0;i<prm.sz&&prm[i]<=sq;i++) {
        if(n%prm[i]==0) {
            while(n%prm[i]==0) {
                n/=prm[i];
            }
            sq=sqrt(n);
            nw.PB( prm[i] );
        }
    }
    if(n>1) {
        nw.PB(n);
    }

    for(int i=0;i<nw.sz;i++) {
        pm=nw[i];
        MEM(dp,-1);
        LL tp=Solve(l,0);
        if(flg) tp+=y;
        ans=min(ans,tp);
    }
}

int main()
{
    seive();
    int n;
    S1(n); SL2(x,y);

    for(int i=1;i<=n;i++) S1(a[i]);

    int Fst=a[1],Last=a[n];

    ans=1e17;

    Dekhi(Fst,2,n,0);
    Dekhi(Fst-1,2,n,1);
    Dekhi(Fst+1,2,n,1);

    Dekhi(Last,1,n-1,0);
    Dekhi(Last+1,1,n-1,1);
    Dekhi(Last-1,1,n-1,1);

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

    return 0;
}

/*

7 46 23

47 17 90 30 39 6 63

*/

///============= Thank You ===================///


/********************************************
*                                           *
*    Solved By : Bir Bahadur Khatri(B'ru)   *
*      Be Positive,be Happy.                *
*                                           *
*********************************************/

#define ff first
#define D double
#define sz size()
#define ss second
#define PB push_back
#define SQR(n) (n*n)
#define CHR getchar()
#define NL printf("\n")
#include<bits/stdc++.h>
#define ULL unsigned LL
#define PI 2.0*acos(0.0)
#define LL long long int
#define S1(a) a=in<int>()
#define SL1(a) a=in<LL>()
#define Max(a,b) ((a>b)?a:b)
#define Min(a,b) ((a<b)?a:b)
#define all(a) a.begin(),a.end()
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
#define SL2(a,b) a=in<LL>(),b=in<LL>()
#define F(i,a,b) for(int i=a;i<b; i++)
#define S2(a,b) a=in<int>(),b=in<int>()
#define R(i,a,b) for(int i=a-1;i>=b; i--)
#define BitCnt(a) __builtin_popcountll(a)
#define MEM(a,val) memset(a,val,sizeof(a))
#define SL3(a,b,c) a=in<LL>(),b=in<LL>(),c=in<LL>()
#define S3(a,b,c) a=in<int>(),b=in<int>(),c=in<int>()
#define cp printf("***** here here here here *****\n");
#define trace1(x)                cerr << #x << ": " << x << endl;
#define InpOut freopen("A.in","r",stdin),freopen("A1.out","w",stdout)
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;

using namespace std;
template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template<typename T>inline T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T>inline T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
template<typename T>inline T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}
long long Bigmod(long long base, long long power, long long MOD){long long ret=1;while(power){if(power & 1)ret=(ret*base)%MOD;base=(base*base)%MOD;power>>=1;}return ret;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
long long ModInverse(long long number, long long MOD){return Bigmod(number, MOD-2, MOD);}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}
int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }

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

#define MD1 1000000007ULL
#define MD2 1000000009ULL
#define MD3 1000000021ULL
#define BS1 10000019ULL
#define BS2 10000079ULL
#define BS3 10000103ULL
#define PUL pair<ULL,ULL>

///         0123456789
#define MX  100007
#define MOD 1000000007
#define INF 1e17
#define EPS 1e-9
/// ==========================================////

int a[MX];

bool prime[MX+9];
vector<int> prm;
void seive()
{
    prime[1]=true;
    int s=sqrt(MX);
    for(int i=2; i<=s; i++)
    {
        if(!prime[i])
        {
            for(int j=2*i; j<=MX; j+=i)
            {
                prime[j]=true;

            }
        }
    }
    F(i,2,MX+1) if(prime[i]==false) prm.PB(i);
}

int R,pm;
LL x,y;

LL dp[1000009][3];

LL Solve(int pos,int flg) {
    if(pos==R) {
        return 0;
    }

    LL &res=dp[pos][flg];
    if(res!=-1) return res;

    res=INF;

    if(!flg) {
        if(a[pos]%pm==0) {
            res=min(res,Solve(pos+1,flg));
        }
        res=min(res,Solve(pos+1,1)+x);
        if( (a[pos]-1)%pm==0 ||(a[pos]+1)%pm==0) {
            res=min(res,Solve(pos+1,flg)+y);
        }
    }
    else if(flg==1) {
        res=min(res,Solve(pos+1,flg)+x);
        if(a[pos]%pm==0) {
            res=min(res,Solve(pos+1,2));
        }
        if( (a[pos]-1)%pm==0 ||(a[pos]+1)%pm==0) {
            res=min(res,Solve(pos+1,2)+y);
        }
    }
    else {
        if(a[pos]%pm==0) {
            res=min(res,Solve(pos+1,2));
        }
        if( (a[pos]-1)%pm==0 ||(a[pos]+1)%pm==0) {
            res=min(res,Solve(pos+1,2)+y);
        }
    }
    return res;
}

LL ans;

void Dekhi(int val,int l,int r,int flg) {
    if(l>r) {
        ans=min(ans,0LL);
        return;
    }

    R=r+1;
    int n=val;
    int sq=sqrt(n);

    vector<int> nw;

    for(int i=0;i<prm.sz&&prm[i]<=sq;i++) {
        if(n%prm[i]==0) {
            while(n%prm[i]==0) {
                n/=prm[i];
            }
            sq=sqrt(n);
            nw.PB( prm[i] );
        }
    }
    if(n>1) {
        nw.PB(n);
    }

    for(int i=0;i<nw.sz;i++) {
        pm=nw[i];
        MEM(dp,-1);
        LL tp=Solve(l,0);
        if(flg) tp+=y;
        ans=min(ans,tp);
    }
}

int main()
{
    seive();
    int n;
    S1(n); SL2(x,y);

    for(int i=1;i<=n;i++) S1(a[i]);

    int Fst=a[1],Last=a[n];

    ans=1e17;

    Dekhi(Fst,2,n,0);
    Dekhi(Fst-1,2,n,1);
    Dekhi(Fst+1,2,n,1);

    Dekhi(Last,1,n-1,0);
    Dekhi(Last+1,1,n-1,1);
    Dekhi(Last-1,1,n-1,1);

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

    return 0;
}

/*

7 46 23

47 17 90 30 39 6 63

*/

///============= Thank You ===================///


/********************************************
*                                           *
*    Solved By : Bir Bahadur Khatri(B'ru)   *
*      Be Positive,be Happy.                *
*                                           *
*********************************************/

#define ff first
#define D double
#define sz size()
#define ss second
#define PB push_back
#define SQR(n) (n*n)
#define CHR getchar()
#define NL printf("\n")
#include<bits/stdc++.h>
#define ULL unsigned LL
#define PI 2.0*acos(0.0)
#define LL long long int
#define S1(a) a=in<int>()
#define SL1(a) a=in<LL>()
#define Max(a,b) ((a>b)?a:b)
#define Min(a,b) ((a<b)?a:b)
#define all(a) a.begin(),a.end()
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
#define SL2(a,b) a=in<LL>(),b=in<LL>()
#define F(i,a,b) for(int i=a;i<b; i++)
#define S2(a,b) a=in<int>(),b=in<int>()
#define R(i,a,b) for(int i=a-1;i>=b; i--)
#define BitCnt(a) __builtin_popcountll(a)
#define MEM(a,val) memset(a,val,sizeof(a))
#define SL3(a,b,c) a=in<LL>(),b=in<LL>(),c=in<LL>()
#define S3(a,b,c) a=in<int>(),b=in<int>(),c=in<int>()
#define cp printf("***** here here here here *****\n");
#define trace1(x)                cerr << #x << ": " << x << endl;
#define InpOut freopen("A.in","r",stdin),freopen("A1.out","w",stdout)
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;

using namespace std;
template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template<typename T>inline T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T>inline T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
template<typename T>inline T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}
long long Bigmod(long long base, long long power, long long MOD){long long ret=1;while(power){if(power & 1)ret=(ret*base)%MOD;base=(base*base)%MOD;power>>=1;}return ret;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
long long ModInverse(long long number, long long MOD){return Bigmod(number, MOD-2, MOD);}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}
int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }

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

#define MD1 1000000007ULL
#define MD2 1000000009ULL
#define MD3 1000000021ULL
#define BS1 10000019ULL
#define BS2 10000079ULL
#define BS3 10000103ULL
#define PUL pair<ULL,ULL>

///         0123456789
#define MX  100007
#define MOD 1000000007
#define INF 1e17
#define EPS 1e-9
/// ==========================================////

int a[MX];

bool prime[MX+9];
vector<int> prm;
void seive()
{
    prime[1]=true;
    int s=sqrt(MX);
    for(int i=2; i<=s; i++)
    {
        if(!prime[i])
        {
            for(int j=2*i; j<=MX; j+=i)
            {
                prime[j]=true;

            }
        }
    }
    F(i,2,MX+1) if(prime[i]==false) prm.PB(i);
}

int R,pm;
LL x,y;

LL dp[100009][3][2];

LL Solve(int pos,int flg,int f) {
    if(pos==R) {
        return 0;
    }

    LL &res=dp[pos][flg][f];
    if(res!=-1) return res;

    res=INF;

    if(!flg) {
        if(a[pos]%pm==0) {
            res=min(res,Solve(pos+1,flg,f));
        }
        res=min(res,Solve(pos+1,1,f)+x);
        if(!f) {
            if( (a[pos]-1)%pm==0 ||(a[pos]+1)%pm==0) {
                res=min(res,Solve(pos+1,flg,1)+y);
            }
        }
    }
    else if(flg==1) {
        res=min(res,Solve(pos+1,flg,f)+x);
        if(a[pos]%pm==0) {
            res=min(res,Solve(pos+1,2,f));
        }
        if(!f) {
            if( (a[pos]-1)%pm==0 ||(a[pos]+1)%pm==0) {
                res=min(res,Solve(pos+1,2,1)+y);
            }
        }
    }
    else {
        if(a[pos]%pm==0) {
            res=min(res,Solve(pos+1,2,f));
        }
        if(!f) {
            if( (a[pos]-1)%pm==0 ||(a[pos]+1)%pm==0) {
                res=min(res,Solve(pos+1,2,1)+y);
            }
        }
    }
    return res;
}

LL ans;

void Dekhi(int val,int l,int r,int flg) {
    if(l>r) {
        ans=min(ans,0LL);
        return;
    }

    R=r+1;
    int n=val;
    int sq=sqrt(n);

    vector<int> nw;

    for(int i=0;i<prm.sz&&prm[i]<=sq;i++) {
        if(n%prm[i]==0) {
            while(n%prm[i]==0) {
                n/=prm[i];
            }
            sq=sqrt(n);
            nw.PB( prm[i] );
        }
    }
    if(n>1) {
        nw.PB(n);
    }

    for(int i=0;i<nw.sz;i++) {
        pm=nw[i];
        MEM(dp,-1);
        LL tp=Solve(l,0,flg);
        if(flg) tp+=y;
        ans=min(ans,tp);
    }
}

int main()
{
    seive();
    int n;
    S1(n); SL2(x,y);

    for(int i=1;i<=n;i++) S1(a[i]);

    int Fst=a[1],Last=a[n];

    ans=1e17;

    Dekhi(Fst,2,n,0);
    Dekhi(Fst-1,2,n,1);
    Dekhi(Fst+1,2,n,1);

    Dekhi(Last,1,n-1,0);
    Dekhi(Last+1,1,n-1,1);
    Dekhi(Last-1,1,n-1,1);

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

    return 0;
}

///============= Thank You ===================///


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
using namespace std;

typedef long long LL;
const int maxn = 1E6 + 10;

map <int,bool> M;
LL n,a,b,num[maxn],f[maxn],g[maxn],mi[maxn],ans = 1E17;
bool flag;

void cal(LL x)
{
	int R;
	memset(f,0,sizeof(f));
	memset(g,0,sizeof(g));
	memset(mi,0,sizeof(mi));
	for (int i = 1; i <= n; i++) {
		LL sum;
		if (num[i] % x == 0) sum = 0;
		else if ((num[i]+1) % x == 0) sum = b;
		else if ((num[i]-1) % x == 0 && num[i]-1>0) sum = b;
		else {
			R = i;
			break;
		}
		f[i] = f[i-1] + sum;
		mi[i] = min(f[i]-1LL*a*1LL*i,mi[i-1]);
		if (i == n) ans = min(ans,f[i]);
	}

	if (R) for (int i = R; i <= n; i++) mi[i] = mi[i-1];

	LL MIN = 1LL*(n+1)*a;
	for (int i = n; i; i--) {
		ans = min(ans,MIN+mi[i]-a);
		LL sum;
		if (num[i] % x == 0 && num[i]) sum = 0;
		else if ((num[i]+1) % x == 0 && num[i]+1>0) sum = b;
		else if ((num[i]-1) % x == 0 && num[i]-1>0) sum = b;
		else break;
		g[i] = g[i+1]+sum;
		MIN = min(MIN,g[i]+1LL*a*1LL*i);
		ans = min(ans,MIN+mi[i-1]-a);
	}

}

LL ksm(LL a,LL x,LL y)
{
	if (x == 0) return 1;
	LL r = ksm(a,x/2,y);
	LL ret = r*r%y;
	if (ret == 1 && r != 1 && r != y-1) flag = 0;
	if (x&1) ret = ret*a%y;
	return ret;
}

bool M_B(LL x)
{
	for (int i = 1; i <= 10; i++) {
		flag = true;
		LL a = rand()%(x-1)+1;
		LL ret = ksm(a,x-1,x);
		if (ret != 1 || !flag) return false;
	}
	return true;
}

void solve(LL now)
{
	if (now <= 1) return;
	if (M_B(now) && !M[now]) cal(now),M[now] = 1;
	else {
		LL SQRT = sqrt(now);
		for (int i = 2; i <= SQRT; i++)
			if (now % i == 0)
				if (M_B(i) && !M[i])
					cal(i),M[i] = 1;
	}
}

int main()
{
	#ifdef YZY
		   freopen("yzy.txt","r",stdin);
	#endif

	cin >> n >> a >> b;
	for (int i = 1; i <= n; i++) scanf("%I64d",&num[i]);
	solve(num[1]);
	solve(num[1]-1);
	solve(num[1]+1);
	solve(num[n]);
	solve(num[n]-1);
	solve(num[n]+1);
	cout << ans;

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
using namespace std;

typedef long long LL;
const int maxn = 1E6 + 10;

map <int,bool> M;
LL n,a,b,num[maxn],f[maxn],g[maxn],mi[maxn],mi2[maxn],ans = 1E17;
bool flag;

void cal(LL x)
{
	int R = 0;
	memset(f,0,sizeof(f));
	memset(g,0,sizeof(g));
	memset(mi,0,sizeof(mi));
	for (int i = 0; i <= n+1; i++) mi2[i] = 1LL*(n+1)*a;
	for (int i = 1; i <= n; i++) {
		LL sum;
		if (num[i] % x == 0) sum = 0;
		else if ((num[i]+1) % x == 0) sum = b;
		else if ((num[i]-1) % x == 0 && num[i]-1>0) sum = b;
		else {
			R = i;
			break;
		}
		f[i] = f[i-1] + sum;
		mi[i] = min(f[i]-1LL*a*1LL*i,mi[i-1]);
		if (i == n) ans = min(ans,f[i]);
	}
	if (R) for (int i = R; i <= n; i++) mi[i] = mi[i-1];

	LL L = 0;
	for (int i = n; i; i--) {
		LL sum;
		if (num[i] % x == 0 && num[i]) sum = 0;
		else if ((num[i]+1) % x == 0 && num[i]+1>0) sum = b;
		else if ((num[i]-1) % x == 0 && num[i]-1>0) sum = b;
		else {
			L = i;
			break;
		}
		g[i] = g[i+1]+sum;
		mi2[i] = min(mi2[i+1],g[i]+1LL*a*1LL*i);
		if (i == 1) ans = min(ans,g[i]);
	}
	if (L) for (int i = L; i; i--) mi2[i] = mi2[i+1];

	for (int i = 1; i <= n+1; i++) ans = min(ans,mi[i-1]+mi2[i]-a);
}

LL ksm(LL a,LL x,LL y)
{
	if (x == 0) return 1;
	LL r = ksm(a,x/2,y);
	LL ret = r*r%y;
	if (ret == 1 && r != 1 && r != y-1) flag = 0;
	if (x&1) ret = ret*a%y;
	return ret;
}

bool M_B(LL x)
{
	for (int i = 1; i <= 10; i++) {
		flag = true;
		LL a = rand()%(x-1)+1;
		LL ret = ksm(a,x-1,x);
		if (ret != 1 || !flag) return false;
	}
	return true;
}

void solve(LL now)
{
	if (now <= 1) return;
	if (M_B(now) && !M[now]) cal(now),M[now] = 1;
	else {
		LL SQRT = sqrt(now);
		for (int i = 2; i <= SQRT; i++)
			if (now % i == 0)
				if (M_B(i) && !M[i])
					cal(i),M[i] = 1;
	}
}

int main()
{
	#ifdef YZY
		   freopen("yzy.txt","r",stdin);
	#endif

	cin >> n >> a >> b;
	for (int i = 1; i <= n; i++) scanf("%I64d",&num[i]);
	solve(num[1]);
	solve(num[1]-1);
	solve(num[1]+1);
	solve(num[n]);
	solve(num[n]-1);
	solve(num[n]+1);
	cout << ans;

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
using namespace std;

typedef long long LL;
const int maxn = 1E6 + 10;

map <int,bool> M;
LL n,a,b,num[maxn],f[maxn],g[maxn],mi[maxn],ans = 1E17;
bool flag;

void cal(LL x)
{
	int R = 0;
	memset(f,0,sizeof(f));
	memset(g,0,sizeof(g));
	memset(mi,0,sizeof(mi));
	for (int i = 1; i <= n; i++) {
		LL sum;
		if (num[i] % x == 0) sum = 0;
		else if ((num[i]+1) % x == 0) sum = b;
		else if ((num[i]-1) % x == 0 && num[i]-1>0) sum = b;
		else {
			R = i;
			break;
		}
		f[i] = f[i-1] + sum;
		mi[i] = min(f[i]-1LL*a*1LL*i,mi[i-1]);
		if (i == n) ans = min(ans,f[i]);
	}

	if (R) for (int i = R; i <= n; i++) mi[i] = mi[i-1];

	LL MIN = 1LL*(n+1)*a;
	for (int i = n; i; i--) {
		ans = min(ans,MIN+mi[i]-a);
		LL sum;
		if (num[i] % x == 0 && num[i]) sum = 0;
		else if ((num[i]+1) % x == 0 && num[i]+1>0) sum = b;
		else if ((num[i]-1) % x == 0 && num[i]-1>0) sum = b;
		else break;
		g[i] = g[i+1]+sum;
		MIN = min(MIN,g[i]+1LL*a*1LL*i);
		ans = min(ans,MIN+mi[i-1]-a);
	}

}

LL ksm(LL a,LL x,LL y)
{
	if (x == 0) return 1;
	LL r = ksm(a,x/2,y);
	LL ret = r*r%y;
	if (ret == 1 && r != 1 && r != y-1) flag = 0;
	if (x&1) ret = ret*a%y;
	return ret;
}

bool M_B(LL x)
{
	for (int i = 1; i <= 10; i++) {
		flag = true;
		LL a = rand()%(x-1)+1;
		LL ret = ksm(a,x-1,x);
		if (ret != 1 || !flag) return false;
	}
	return true;
}

void solve(LL now)
{
	if (now <= 1) return;
	if (M_B(now) && !M[now]) cal(now),M[now] = 1;
	else {
		LL SQRT = sqrt(now);
		for (int i = 2; i <= SQRT; i++)
			if (now % i == 0)
				if (M_B(i) && !M[i])
					cal(i),M[i] = 1;
	}
}

int main()
{
	#ifdef YZY
		   freopen("yzy.txt","r",stdin);
	#endif

	cin >> n >> a >> b;
	for (int i = 1; i <= n; i++) scanf("%I64d",&num[i]);
	solve(num[1]);
	solve(num[1]-1);
	solve(num[1]+1);
	solve(num[n]);
	solve(num[n]-1);
	solve(num[n]+1);
	cout << ans;

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;

typedef long long LL;
const int maxn = 1E6 + 10;

LL n,a,b,num[maxn],f[maxn],g[maxn],mi[maxn],ans = 1E17;
bool flag;

void cal(LL x)
{
	int R;
	for (int i = 1; i <= n; i++) {
		LL sum;
		if (num[i] % x == 0) sum = 0;
		else if ((num[i]+1) % x == 0 || (num[i]-1) % x == 0) sum = b;
		else {
			R = i;
			break;
		}
		f[i] = f[i-1] + sum;
		mi[i] = min(f[i]-1LL*a*1LL*i,mi[i-1]);
		if (i == n) ans = min(ans,f[i]);
	}

	if (R) for (int i = R; i <= n; i++) mi[i] = mi[i-1];

	LL MIN = 1LL*(n+1)*a;
	for (int i = n; i; i--) {
		ans = min(ans,MIN+mi[i]-a);
		LL sum;
		if (num[i] % x == 0) sum = 0;
		else if ((num[i]+1) % x == 0 || (num[i]-1) % x == 0) sum = b;
		else break;
		g[i] = g[i+1]+sum;
		MIN = min(MIN,g[i]+1LL*a*1LL*i);
		ans = min(ans,MIN+mi[i-1]-a);
	}

}

LL ksm(LL a,LL x,LL y)
{
	if (x == 0) return 1;
	LL r = ksm(a,x/2,y);
	LL ret = r*r%y;
	if (ret == 1 && r != 1 && r != y-1) flag = 0;
	if (x&1) ret = ret*a%y;
	return ret;
}

bool M_B(LL x)
{
	for (int i = 1; i <= 5; i++) {
		flag = true;
		LL a = rand()%(x-1)+1;
		LL ret = ksm(a,x-1,x);
		if (ret != 1 || !flag) return false;
	}
	return true;
}

void solve(LL now)
{
	if (now <= 1) return;
	if (M_B(now)) cal(now);
	else {
		LL SQRT = sqrt(now);
		for (int i = 2; i <= SQRT; i++)
			if (now % i == 0)
				if (M_B(i))
					cal(i);
	}
}

int main()
{
	#ifdef YZY
		   freopen("yzy.txt","r",stdin);
	#endif

	cin >> n >> a >> b;
	for (int i = 1; i <= n; i++) scanf("%I64d",&num[i]);
	solve(num[1]);
	solve(num[1]-1);
	solve(num[1]+1);
	solve(num[n]);
	solve(num[n]-1);
	solve(num[n]+1);
	cout << ans;

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
using namespace std;

typedef long long LL;
const int maxn = 1E6 + 10;

map <int,bool> M;
LL n,a,b,num[maxn],f[maxn],g[maxn],mi[maxn],mi2[maxn],ans = 1E17;
bool flag;

void cal(LL x)
{
	int R = 0;
	f[0] = mi[0] = g[n+1] = 0;
	mi2[n+1] = 1LL*(n+1)*a;
	for (int i = 1; i <= n; i++) {
		LL sum;
		if (num[i] % x == 0) sum = 0;
		else if ((num[i]+1) % x == 0) sum = b;
		else if ((num[i]-1) % x == 0 && num[i]-1>0) sum = b;
		else {
			R = i;
			break;
		}
		f[i] = f[i-1] + sum;
		mi[i] = min(f[i]-1LL*a*1LL*i,mi[i-1]);
		if (i == n) ans = min(ans,f[i]);
	}
	if (R) for (int i = R; i <= n; i++) mi[i] = mi[i-1];

	LL L = 0;
	for (int i = n; i; i--) {
		LL sum;
		if (num[i] % x == 0 && num[i]) sum = 0;
		else if ((num[i]+1) % x == 0 && num[i]+1>0) sum = b;
		else if ((num[i]-1) % x == 0 && num[i]-1>0) sum = b;
		else {
			L = i;
			break;
		}
		g[i] = g[i+1]+sum;
		mi2[i] = min(mi2[i+1],g[i]+1LL*a*1LL*i);
		if (i == 1) ans = min(ans,g[i]);
	}
	if (L) for (int i = L; i; i--) mi2[i] = mi2[i+1];

	for (int i = 1; i <= n+1; i++) ans = min(ans,mi[i-1]+mi2[i]-a);
}

LL ksm(LL a,LL x,LL y)
{
	if (x == 0) return 1;
	LL r = ksm(a,x/2,y);
	LL ret = r*r%y;
	if (ret == 1 && r != 1 && r != y-1) flag = 0;
	if (x&1) ret = ret*a%y;
	return ret;
}

bool M_B(LL x)
{
	for (int i = 1; i <= 10; i++) {
		flag = true;
		LL a = rand()%(x-1)+1;
		LL ret = ksm(a,x-1,x);
		if (ret != 1 || !flag) return false;
	}
	return true;
}

void solve(LL now)
{
	if (now <= 1) return;
	if (M_B(now) && !M[now])
		cal(now),M[now] = 1;
	else {
		LL SQRT = sqrt(now);
		for (int i = 2; i <= SQRT; i++)
			if (now % i == 0) {
				if (M_B(i) && !M[i])
					cal(i),M[i] = 1;
				LL j = now/i;
				if (M_B(j) && !M[j])
				 	cal(j),M[j] = 1;
			}
	}
}

int main()
{
	#ifdef YZY
		   freopen("yzy.txt","r",stdin);
	#endif

	cin >> n >> a >> b;
	for (int i = 1; i <= n; i++) scanf("%I64d",&num[i]);
	solve(num[1]);
	solve(num[1]-1);
	solve(num[1]+1);
	solve(num[n]);
	solve(num[n]-1);
	solve(num[n]+1);
	cout << ans;

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
using namespace std;

typedef long long LL;
const int maxn = 1E6 + 10;

map <int,bool> M;
LL n,a,b,num[maxn],f[maxn],g[maxn],mi[maxn],mi2[maxn],ans = 1E17;
bool flag;

void cal(LL x)
{
	int R = 0;
	f[0] = mi[0] = g[n+1] = 0;
	mi2[n+1] = 1LL*(n+1)*a;
	for (int i = 1; i <= n; i++) {
		LL sum;
		if (num[i] % x == 0) sum = 0;
		else if ((num[i]+1) % x == 0) sum = b;
		else if ((num[i]-1) % x == 0 && num[i]-1>0) sum = b;
		else {
			R = i;
			break;
		}
		f[i] = f[i-1] + sum;
		mi[i] = min(f[i]-1LL*a*1LL*i,mi[i-1]);
		if (i == n) ans = min(ans,f[i]);
	}
	if (R) for (int i = R; i <= n; i++) mi[i] = mi[i-1];

	LL L = 0;
	for (int i = n; i; i--) {
		LL sum;
		if (num[i] % x == 0 && num[i]) sum = 0;
		else if ((num[i]+1) % x == 0 && num[i]+1>0) sum = b;
		else if ((num[i]-1) % x == 0 && num[i]-1>0) sum = b;
		else {
			L = i;
			break;
		}
		g[i] = g[i+1]+sum;
		mi2[i] = min(mi2[i+1],g[i]+1LL*a*1LL*i);
		if (i == 1) ans = min(ans,g[i]);
	}
	if (L) for (int i = L; i; i--) mi2[i] = mi2[i+1];

	for (int i = 1; i <= n+1; i++) ans = min(ans,mi[i-1]+mi2[i]-a);
}

LL ksm(LL a,LL x,LL y)
{
	if (x == 0) return 1;
	LL r = ksm(a,x/2,y);
	LL ret = r*r%y;
	if (ret == 1 && r != 1 && r != y-1) flag = 0;
	if (x&1) ret = ret*a%y;
	return ret;
}

bool M_B(LL x)
{
	for (int i = 1; i <= 10; i++) {
		flag = true;
		LL a = rand()%(x-1)+1;
		LL ret = ksm(a,x-1,x);
		if (ret != 1 || !flag) return false;
	}
	return true;
}

void solve(LL now)
{
	if (now <= 1) return;
	if (M_B(now) && !M[now])
		cal(now),M[now] = 1;
	else {
		LL SQRT = sqrt(now);
		for (int i = 2; i <= SQRT; i++)
			if (now % i == 0)
				if (M_B(i) && !M[i])
					cal(i),M[i] = 1;
	}
}

int main()
{
	#ifdef YZY
		   freopen("yzy.txt","r",stdin);
	#endif

	cin >> n >> a >> b;
	for (int i = 1; i <= n; i++) scanf("%I64d",&num[i]);
	solve(num[1]);
	solve(num[1]-1);
	solve(num[1]+1);
	solve(num[n]);
	solve(num[n]-1);
	solve(num[n]+1);
	cout << ans;

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
using namespace std;

typedef long long LL;
const int maxn = 1E6 + 10;

map <int,bool> M;
LL n,a,b,num[maxn],f[maxn],g[maxn],mi[maxn],mi2[maxn],ans = 1E17;
bool flag;

void cal(LL x)
{
	int R = 0;
	f[0] = mi[0] = 0;
	mi2[n+1] = g[n+1] = 1LL*(n+1)*a;
	for (int i = 1; i <= n; i++) {
		LL sum;
		if (num[i] % x == 0) sum = 0;
		else if ((num[i]+1) % x == 0) sum = b;
		else if ((num[i]-1) % x == 0 && num[i]-1>0) sum = b;
		else {
			R = i;
			break;
		}
		f[i] = f[i-1] + sum;
		mi[i] = min(f[i]-1LL*a*1LL*i,mi[i-1]);
		if (i == n) ans = min(ans,f[i]);
	}
	if (R) for (int i = R; i <= n; i++) mi[i] = mi[i-1];

	LL L = 0;
	for (int i = n; i; i--) {
		LL sum;
		if (num[i] % x == 0 && num[i]) sum = 0;
		else if ((num[i]+1) % x == 0 && num[i]+1>0) sum = b;
		else if ((num[i]-1) % x == 0 && num[i]-1>0) sum = b;
		else {
			L = i;
			break;
		}
		g[i] = g[i+1]+sum;
		mi2[i] = min(mi2[i+1],g[i]+1LL*a*1LL*i);
		if (i == 1) ans = min(ans,g[i]);
	}
	if (L) for (int i = L; i; i--) mi2[i] = mi2[i+1];

	for (int i = 1; i <= n+1; i++) ans = min(ans,mi[i-1]+mi2[i]-a);
}

LL ksm(LL a,LL x,LL y)
{
	if (x == 0) return 1;
	LL r = ksm(a,x/2,y);
	LL ret = r*r%y;
	if (ret == 1 && r != 1 && r != y-1) flag = 0;
	if (x&1) ret = ret*a%y;
	return ret;
}

bool M_B(LL x)
{
	for (int i = 1; i <= 10; i++) {
		flag = true;
		LL a = rand()%(x-1)+1;
		LL ret = ksm(a,x-1,x);
		if (ret != 1 || !flag) return false;
	}
	return true;
}

void solve(LL now)
{
	if (now <= 1) return;
	if (M_B(now) && !M[now]) cal(now),M[now] = 1;
	else {
		LL SQRT = sqrt(now);
		for (int i = 2; i <= SQRT; i++)
			if (now % i == 0)
				if (M_B(i) && !M[i])
					cal(i),M[i] = 1;
	}
}

int main()
{
	#ifdef YZY
		   freopen("yzy.txt","r",stdin);
	#endif

	cin >> n >> a >> b;
	for (int i = 1; i <= n; i++) scanf("%I64d",&num[i]);
	solve(num[1]);
	solve(num[1]-1);
	solve(num[1]+1);
	solve(num[n]);
	solve(num[n]-1);
	solve(num[n]+1);
	cout << ans;

	return 0;
}


#include <bits/stdc++.h>

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

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

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

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

vector<ll> preCost, sufCost, sufCut;

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

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


#include <bits/stdc++.h>

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

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

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

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

vector<ll> preCost, sufCost, preCut;

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

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