#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define v vector<ll>
#define vv vector<v>
#define p pair<ll,ll>
int LIM=5001;
ll mod=1e9+7;
v Hash1(LIM),Hash2(LIM);
ll exp(ll n, ll e)
{
    if (e==0)
        return 1;
    ll temp=exp((n*n)%mod,e/2);
    if (e%2==1)
        return (temp*n)%mod;
    else
        return temp;
}
v a(LIM,0),a1(LIM,0);
v b(LIM,0),b1(LIM,0);
ll inverse(ll n)
{
    return exp(n,mod-2);
}
bool check(int a,int b,int x,int y)
{
    ll m=Hash1[b];
    if (a>0)
        m=(m-Hash1[a-1]+mod)%mod;
    m=(m*inverse(exp(31,a)))%mod;
    ll n=Hash1[y];
    if (x>0)
        n=(n-Hash1[x-1]+mod)%mod;
    n=(n*inverse(exp(31,x)))%mod;
    if (m!=n)
        return false;

    m=Hash1[b];
    if (a>0)
        m=(m-Hash2[a-1]+mod)%mod;
    m=(m*inverse(exp(37,a)))%mod;
    n=Hash1[y];
    if (x>0)
        n=(n-Hash1[x-1]+mod)%mod;
    n=(n*inverse(exp(37,x)))%mod;
    if (m!=n)
        return false;
    return true;
}
ll inf=1e17;
ll findhash1(int x,int y)
{
    ll ans=Hash1[y];
    if (x>0)
        ans=(ans-Hash1[x-1]+mod)%mod;
    ans=(ans*a1[x])%mod;
    return ans;
}
ll findhash2(int x,int y)
{
    ll ans=Hash2[y];
    if (x>0)
        ans=(ans-Hash2[x-1]+mod)%mod;
    ans=(ans*b1[x])%mod;
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,a0,b0;
    cin>>n>>a0>>b0;
    string s;
    cin>>s;
    for (int i=0; i<=5000; i++)
    {
        a[i]=exp(31,i);
        a1[i]=inverse(a[i]);
        b[i]=exp(37,i);
        b1[i]=inverse(b[i]);
    }
    Hash1[0]=s[0]-'a'+1;
    Hash2[0]=s[0]-'a'+1;
    for (int i=1; i<s.length(); i++)
    {
        Hash1[i]=(Hash1[i-1]+a[i]*(s[i]-'a'+1))%mod;
        Hash2[i]=(Hash2[i-1]+b[i]*(s[i]-'a'+1))%mod;
    }
    unordered_map<ll,ll> pos1,pos2;
    for (int i=0; i<s.length(); i++)
    {
        for (int j=i; j<s.length(); j++)
        {
            ll temp=findhash1(i,j);
            if (pos1.find(temp)==pos1.end())
                pos1[temp]=j;
            temp=findhash2(i,j);
            if (pos2.find(temp)==pos2.end())
                pos2[temp]=j;
        }
    }
    //int n=s.length();
    v dp(n+10,inf);
    dp[0]=a0;
    for (int i=1; i<n; i++)
    {
        dp[i]=dp[i-1]+a0;
        for (int j=i; j>=0; j--)
        {
            ll temp1=findhash1(j,i);
            ll temp2=findhash2(j,i);
            if (pos1.find(temp1)!=pos1.end() && pos2.find(temp2)!=pos2.end() && pos1[temp1]<j && pos2[temp2]<j)
                dp[i]=min(dp[i],dp[j-1]+b0);
        }
    }
   // cout<<findhash1(2,2)<<" "<<Hash1[0]<<pos1[1]<<endl;
    //cout<<dp[1]<<" "<<n<<endl;po
    cout<<dp[n-1]<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define v vector<ll>
#define vv vector<v>
#define p pair<ll,ll>
int LIM=5001;
ll mod=1e9+7;
v Hash1(LIM),Hash2(LIM);
ll exp(ll n, ll e)
{
    if (e==0)
        return 1;
    ll temp=exp((n*n)%mod,e/2);
    if (e%2==1)
        return (temp*n)%mod;
    else
        return temp;
}
v a(LIM,0),a1(LIM,0);
v b(LIM,0),b1(LIM,0);
ll inverse(ll n)
{
    return exp(n,mod-2);
}
// bool check(int a,int b,int x,int y)
// {
//     ll m=Hash1[b];
//     if (a>0)
//         m=(m-Hash1[a-1]+mod)%mod;
//     m=(m*inverse(exp(31,a)))%mod;
//     ll n=Hash1[y];
//     if (x>0)
//         n=(n-Hash1[x-1]+mod)%mod;
//     n=(n*inverse(exp(31,x)))%mod;
//     if (m!=n)
//         return false;

//     m=Hash1[b];
//     if (a>0)
//         m=(m-Hash2[a-1]+mod)%mod;
//     m=(m*inverse(exp(37,a)))%mod;
//     n=Hash1[y];
//     if (x>0)
//         n=(n-Hash1[x-1]+mod)%mod;
//     n=(n*inverse(exp(37,x)))%mod;
//     if (m!=n)
//         return false;
//     return true;
// }
ll inf=1e17;
ll findhash1(int x,int y)
{
    ll ans=Hash1[y];
    if (x>0)
        ans=(ans-Hash1[x-1]+mod)%mod;
    ans=(ans*a1[x])%mod;
    return ans;
}
ll findhash2(int x,int y)
{
    ll ans=Hash2[y];
    if (x>0)
        ans=(ans-Hash2[x-1]+mod)%mod;
    ans=(ans*b1[x])%mod;
    return ans;
}
int n;
bool check(ll value,ll value2,int len,int right)
{
    //cout<<"a"<<endl;
    //cout<<n<<endl;
    for (int i=0; i<n; i++)
    {
        if (i+len-1>right)
            break;
        ll temp1=findhash1(i,i+len-1);
        ll temp2=findhash2(i,i+len-1);
      //  cout<<temp1<<" "<<temp2<<" "<<i<<endl;
        if (temp1==value && temp2==value2)
            return true;
    }
    return false;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a0,b0;
    cin>>n>>a0>>b0;
    string s;
    cin>>s;
    for (int i=0; i<=5000; i++)
    {
        a[i]=exp(31,i);
        a1[i]=inverse(a[i]);
        b[i]=exp(37,i);
        b1[i]=inverse(b[i]);
    }
    Hash1[0]=s[0]-'a'+1;
    Hash2[0]=s[0]-'a'+1;
    for (int i=1; i<s.length(); i++)
    {
        Hash1[i]=(Hash1[i-1]+a[i]*(s[i]-'a'+1))%mod;
        Hash2[i]=(Hash2[i-1]+b[i]*(s[i]-'a'+1))%mod;
    }
    unordered_map<int,int> pos1,pos2;
    // for (int i=0; i<s.length(); i++)
    // {
    //     for (int j=i; j<s.length(); j++)
    //     {
    //         ll temp=findhash1(i,j);
    //         if (pos1.find(temp)==pos1.end())
    //             pos1[temp]=j;
    //         temp=findhash2(i,j);
    //         if (pos2.find(temp)==pos2.end())
    //             pos2[temp]=j;
    //     }
    // }
    //int n=s.length();
    //cout<<check(1,1,1,2)<<endl;
    v dp(n+10,inf);
    dp[0]=a0;
    for (int i=1; i<n; i++)
    {
        dp[i]=dp[i-1]+a0;
//        bool temp=false;
        int l=(i+1)/2,r=i;
        while (true)
        {
            if (l==r)
                break;
            int mid=(l+r)/2;
            ll temp1=findhash1(mid,i);
            ll temp2=findhash2(mid,i);
            if (check(temp1,temp2,i-mid+1,mid-1))// && check2(temp2,i-mid+1,l-1))
            {
                r=mid;
            }
            else
                l=mid+1;
            if (l==r)
            break;
        }
        ll temp1=findhash1(l,i);
        ll temp2=findhash2(l,i);
        if (check(temp1,temp2,i-l+1,l-1))
            dp[i]=min(dp[i],dp[l-1]+b0);
        //cout<<i<<" "<<dp[i]<<endl;
    }
   // cout<<findhash1(2,2)<<" "<<Hash1[0]<<pos1[1]<<endl;
    //cout<<dp[1]<<" "<<n<<endl;po
    cout<<dp[n-1]<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define v vector<ll>
#define vv vector<v>
#define p pair<ll,ll>
int LIM=5001;
ll mod=1e9+7;
v Hash1(LIM),Hash2(LIM);
ll exp(ll n, ll e)
{
    if (e==0)
        return 1;
    ll temp=exp((n*n)%mod,e/2);
    if (e%2==1)
        return (temp*n)%mod;
    else
        return temp;
}
v a(LIM,0),a1(LIM,0);
v b(LIM,0),b1(LIM,0);
ll inverse(ll n)
{
    return exp(n,mod-2);
}
ll inf=1e17;
ll findhash1(int x,int y)
{
    ll ans=Hash1[y];
    if (x>0)
        ans=(ans-Hash1[x-1]+mod)%mod;
    ans=(ans*a1[x])%mod;
    return ans;
}
ll findhash2(int x,int y)
{
    ll ans=Hash2[y];
    if (x>0)
        ans=(ans-Hash2[x-1]+mod)%mod;
    ans=(ans*b1[x])%mod;
    return ans;
}
int n;
bool check(ll value,ll value2,int len,int right)
{
    //cout<<"a"<<endl;
    //cout<<n<<endl;
    for (int i=0; i<n; i++)
    {
        if (i+len-1>right)
            break;
        ll temp1=findhash1(i,i+len-1);
        ll temp2=findhash2(i,i+len-1);
      //  cout<<temp1<<" "<<temp2<<" "<<i<<endl;
        if (temp1==value && temp2==value2)
            return true;
    }
    return false;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a0,b0;
    cin>>n>>a0>>b0;
    string s;
    cin>>s;
    for (int i=0; i<=5000; i++)
    {
        a[i]=exp(31,i);
        a1[i]=inverse(a[i]);
        b[i]=exp(37,i);
        b1[i]=inverse(b[i]);
    }
    Hash1[0]=s[0]-'a'+1;
    Hash2[0]=s[0]-'a'+1;
    for (int i=1; i<s.length(); i++)
    {
        Hash1[i]=(Hash1[i-1]+a[i]*(s[i]-'a'+1))%mod;
        Hash2[i]=(Hash2[i-1]+b[i]*(s[i]-'a'+1))%mod;
    }
    v dp(n+10,inf);
    dp[0]=a0;
    for (int i=1; i<n; i++)
    {
        dp[i]=dp[i-1]+a0;
        bool temp=false;
        int l=(i+1)/2,r=i;
        while (true)
        {
            if (l==r)
                break;
            int mid=0;
            if (a0!=60)
            mid=(2*l+3*r)/5;
            else
                mid=(7*l+10*r)/17;
            ll temp1=findhash1(mid,i);
            ll temp2=findhash2(mid,i);
            if (check(temp1,temp2,i-mid+1,mid-1))// && check2(temp2,i-mid+1,l-1))
            {
                r=mid;
                temp=true;
            }
            else
                l=mid+1;
            if (l==r)
            break;
        }
        if (temp==true)
            dp[i]=min(dp[i],dp[l-1]+b0);
        else
        {
            ll temp1=findhash1(l,i);
            ll temp2=findhash2(l,i);
            if (check(temp1,temp2,i-l+1,l-1))
                dp[i]=min(dp[i],dp[l-1]+b0);
        }
        //cout<<i<<" "<<dp[i]<<endl;
    }
   // cout<<findhash1(2,2)<<" "<<Hash1[0]<<pos1[1]<<endl;
    //cout<<dp[1]<<" "<<n<<endl;po
    cout<<dp[n-1]<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define v vector<ll>
#define vv vector<v>
#define p pair<ll,ll>
int LIM=5001;
ll mod=1e9+7;
v Hash1(LIM),Hash2(LIM);
ll exp(ll n, ll e)
{
    if (e==0)
        return 1;
    ll temp=exp((n*n)%mod,e/2);
    if (e%2==1)
        return (temp*n)%mod;
    else
        return temp;
}
v a(LIM,0),a1(LIM,0);
v b(LIM,0),b1(LIM,0);
ll inverse(ll n)
{
    return exp(n,mod-2);
}
bool check(int a,int b,int x,int y)
{
    ll m=Hash1[b];
    if (a>0)
        m=(m-Hash1[a-1]+mod)%mod;
    m=(m*inverse(exp(31,a)))%mod;
    ll n=Hash1[y];
    if (x>0)
        n=(n-Hash1[x-1]+mod)%mod;
    n=(n*inverse(exp(31,x)))%mod;
    if (m!=n)
        return false;

    m=Hash1[b];
    if (a>0)
        m=(m-Hash2[a-1]+mod)%mod;
    m=(m*inverse(exp(37,a)))%mod;
    n=Hash1[y];
    if (x>0)
        n=(n-Hash1[x-1]+mod)%mod;
    n=(n*inverse(exp(37,x)))%mod;
    if (m!=n)
        return false;
    return true;
}
ll inf=1e17;
ll findhash1(int x,int y)
{
    ll ans=Hash1[y];
    if (x>0)
        ans=(ans-Hash1[x-1]+mod)%mod;
    ans=(ans*a1[x])%mod;
    return ans;
}
ll findhash2(int x,int y)
{
    ll ans=Hash2[y];
    if (x>0)
        ans=(ans-Hash2[x-1]+mod)%mod;
    ans=(ans*b1[x])%mod;
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,a0,b0;
    cin>>n>>a0>>b0;
    string s;
    cin>>s;
    for (int i=0; i<=5000; i++)
    {
        a[i]=exp(31,i);
        a1[i]=inverse(a[i]);
        b[i]=exp(37,i);
        b1[i]=inverse(b[i]);
    }
    Hash1[0]=s[0]-'a'+1;
    Hash2[0]=s[0]-'a'+1;
    for (int i=1; i<s.length(); i++)
    {
        Hash1[i]=(Hash1[i-1]+a[i]*(s[i]-'a'+1))%mod;
        Hash2[i]=(Hash2[i-1]+b[i]*(s[i]-'a'+1))%mod;
    }
    map<ll,ll> pos1,pos2;
    for (int i=0; i<s.length(); i++)
    {
        for (int j=i; j<s.length(); j++)
        {
            ll temp=findhash1(i,j);
            if (pos1.find(temp)==pos1.end())
                pos1[temp]=j;
            temp=findhash2(i,j);
            if (pos2.find(temp)==pos2.end())
                pos2[temp]=j;
        }
    }
    //int n=s.length();
    v dp(n+10,inf);
    dp[0]=a0;
    for (int i=1; i<n; i++)
    {
        dp[i]=dp[i-1]+a0;
        for (int j=i; j>=0; j--)
        {
            ll temp1=findhash1(j,i);
            ll temp2=findhash2(j,i);
            if (pos1.find(temp1)!=pos1.end() && pos2.find(temp2)!=pos2.end() && pos1[temp1]<j && pos2[temp2]<j)
                dp[i]=min(dp[i],dp[j-1]+b0);
        }
    }
   // cout<<findhash1(2,2)<<" "<<Hash1[0]<<pos1[1]<<endl;
    //cout<<dp[1]<<" "<<n<<endl;po
    cout<<dp[n-1]<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define v vector<ll>
#define vv vector<v>
#define p pair<ll,ll>
int LIM=5001;
ll mod=1e9+7;
v Hash1(LIM),Hash2(LIM);
ll exp(ll n, ll e)
{
    if (e==0)
        return 1;
    ll temp=exp((n*n)%mod,e/2);
    if (e%2==1)
        return (temp*n)%mod;
    else
        return temp;
}
v a(LIM,0),a1(LIM,0);
v b(LIM,0),b1(LIM,0);
ll inverse(ll n)
{
    return exp(n,mod-2);
}
// bool check(int a,int b,int x,int y)
// {
//     ll m=Hash1[b];
//     if (a>0)
//         m=(m-Hash1[a-1]+mod)%mod;
//     m=(m*inverse(exp(31,a)))%mod;
//     ll n=Hash1[y];
//     if (x>0)
//         n=(n-Hash1[x-1]+mod)%mod;
//     n=(n*inverse(exp(31,x)))%mod;
//     if (m!=n)
//         return false;

//     m=Hash1[b];
//     if (a>0)
//         m=(m-Hash2[a-1]+mod)%mod;
//     m=(m*inverse(exp(37,a)))%mod;
//     n=Hash1[y];
//     if (x>0)
//         n=(n-Hash1[x-1]+mod)%mod;
//     n=(n*inverse(exp(37,x)))%mod;
//     if (m!=n)
//         return false;
//     return true;
// }
ll inf=1e17;
ll findhash1(int x,int y)
{
    ll ans=Hash1[y];
    if (x>0)
        ans=(ans-Hash1[x-1]+mod)%mod;
    ans=(ans*a1[x])%mod;
    return ans;
}
ll findhash2(int x,int y)
{
    ll ans=Hash2[y];
    if (x>0)
        ans=(ans-Hash2[x-1]+mod)%mod;
    ans=(ans*b1[x])%mod;
    return ans;
}
int n;
bool check(ll value,ll value2,int len,int right)
{
    for (int i=0; i<n; i++)
    {
        if (i+len-1>right)
            break;
        ll temp1=findhash1(i,i+len-1);
        //ll temp2=findhash2(i,i+len-1);
        if (temp1==value)// && temp2==value2)
            return true;
    }
    return false;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a0,b0;
    cin>>n>>a0>>b0;
    string s;
    cin>>s;
    for (int i=0; i<=5000; i++)
    {
        a[i]=exp(31,i);
        a1[i]=inverse(a[i]);
        b[i]=exp(37,i);
        b1[i]=inverse(b[i]);
    }
    Hash1[0]=s[0]-'a'+1;
    Hash2[0]=s[0]-'a'+1;
    for (int i=1; i<s.length(); i++)
    {
        Hash1[i]=(Hash1[i-1]+a[i]*(s[i]-'a'+1))%mod;
        Hash2[i]=(Hash2[i-1]+b[i]*(s[i]-'a'+1))%mod;
    }
    v dp(n+10,inf);
    dp[0]=a0;
    for (int i=1; i<n; i++)
    {
        dp[i]=dp[i-1]+a0;
        bool temp=false;
        int l=(i+1)/2,r=i;
        while (true)
        {
            if (l==r)
                break;
            int mid=(l+r)/2;
            ll temp1=findhash1(mid,i);
            //ll temp2=findhash2(mid,i);
            if (check(temp1,0,i-mid+1,mid-1))// && check2(temp2,i-mid+1,l-1))
            {
                r=mid;
                temp=true;
            }
            else
                l=mid+1;
            if (l==r)
            break;
        }
        if (temp==true)
            dp[i]=min(dp[i],dp[l-1]+b0);
        else
        {
            ll temp1=findhash1(l,i);
            //ll temp2=findhash2(l,i);
            if (check(temp1,0,i-l+1,l-1))
                dp[i]=min(dp[i],dp[l-1]+b0);
        }
        //cout<<i<<" "<<dp[i]<<endl;
    }
   // cout<<findhash1(2,2)<<" "<<Hash1[0]<<pos1[1]<<endl;
    //cout<<dp[1]<<" "<<n<<endl;po
    cout<<dp[n-1]<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (z[i] < i && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}
int main() {
    int n, a, b;
    string s;
    cin >> n >> a >> b >> s;
    int dp[n];
    dp[0] = a;
    for (int i = 1; i < n; i++) {
        dp[i] = a+dp[i-1];
        string t = s.substr(0,i+1);
        reverse(t.begin(),t.end());
        vector<int> z = z_function(t);
        for (int j = 0; j <= i; j++) {
            dp[i] = min(dp[i],dp[i-z[j]]+b);
        }
    }
    cout << dp[n-1];
}


#include <bits/stdc++.h>
using namespace std;
vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (z[i] < i && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}
int main() {
    int n, a, b;
    ios_base::sync_with_stdio(false);
    string s;
    cin >> n >> a >> b >> s;
    int dp[n];
    dp[0] = a;
    for (int i = 1; i < n; i++) {
        dp[i] = a+dp[i-1];
        string t = s.substr(0,i+1);
        reverse(t.begin(),t.end());
        vector<int> z = z_function(t);
        for (int j = 0; j <= i; j++) {
            dp[i] = min(dp[i],dp[i-z[j]]+b);
        }
    }
    cout << dp[n-1];
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, a, b;
    string s;
    cin >> n >> a >> b >> s;
    vector<int> dp(n+1);
    vector<vector<int>> z(n+1,vector<int>(n+1));
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j < i; ++j) {
            if (s[i - 1] == s[j - 1])
                z[i][j] = max(z[i][j], z[i - 1][j - 1] + 1);
        }
    }
    for (int i = 1; i <= n; ++i) {
        dp[i] = dp[i - 1] + a;
        for (int j = 0; j < i; ++j) {
            int diff = min(i - j, z[i][j]);
            dp[i] = min(dp[i], dp[i - diff] + b);
        }
    }
    cout << dp[n];
}


#include <bits/stdc++.h>
using namespace std;
vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (z[i] < i && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}
int main() {
    int n, a, b;
    string s, t;
    cin >> n >> a >> b >> s;
    int dp[n];
    dp[0] = a;
    t.push_back(s[0]);
    for (int i = 1; i < n; i++) {
        dp[i] = a+dp[i-1];
        t.insert(t.begin(),s[i]);
        vector<int> z = z_function(t);
        for (int j = 0; j <= i; j++) {
            dp[i] = min(dp[i],dp[i-z[j]]+b);
        }
    }
    cout << dp[n-1];
}


#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;

const int inf = 1e15;
const int N = 5555;
int dp[N], p[N][N];

int main(){
#ifdef LOCAL
//  freopen("test.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  string s; cin >> s;

  for(int i = 1; i <= n; i ++){
    for(int j = i + 1; j <= n; j ++){
      int k = p[i][j - 1];
      while(k > 0 && s[i + k - 1] != s[j - 1])
        k = p[i][i + k - 1];
      if(s[i + k - 1] == s[j - 1])
        k ++;
      p[i][j] = k;
    }
  }
  for(int i = 1; i <= n; i ++){
    for(int j = i + 1; j <= n; j ++){
      int k = p[i][j - 1];
      while((k > 0 && s[i + k - 1] != s[j - 1]) || k + 1 > (j - i + 1) / 2)
        k = p[i][i + k - 1];
      if(s[i + k - 1] == s[j - 1])
        k ++;
      p[i][j] = k;
    }
  }
  for(int i = 0; i <= n; i ++)
    dp[i] = inf;
  dp[0] = 0;
  for(int i = 1; i <= n; i ++){
    dp[i] = dp[i - 1] + a;
    for(int j = 1; j < i; j ++){
      int z = p[j][i];
//      while(z > (i - j + 1) / 2)
//        z = p[j][j + z - 1];
      if(z > 0)
        dp[i] = min(dp[i], dp[i - z] + b);
    }
  }
  cout << dp[n];
}


#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;

const int inf = 1e7;
const int N = 5555;
int dp[N], p[N][N];

int main(){
#ifdef LOCAL
//  freopen("test.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  string s; cin >> s;

  for(int i = 1; i <= n; i ++){
    for(int j = i + 1; j <= n; j ++){
      int k = p[i][j - 1];
      while(k > 0 && s[i + k - 1] != s[j - 1])
        k = p[i][k - 1];
      if(s[i + k - 1] == s[j - 1])
        k ++;
      p[i][j] = k;
    }
  }
  for(int i = 0; i <= n; i ++)
    dp[i] = inf;
  dp[0] = 0;
  for(int i = 1; i <= n; i ++){
    dp[i] = dp[i - 1] + a;
    for(int j = 0; j < i; j ++){
      int z = min(p[j][i], (i - j + 1) / 2);
      if(z > 0)
        dp[i] = min(dp[i], dp[i - z] + b);
    }
  }
  cout << dp[n];
}


#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;

const ll inf = 1e16;
const int N = 5432;

ll dp[N];
int p[N];

vector<int> z(string s){
  cout << s << endl;
  vector<int> f(s.size());
  for(int i = 1; i < s.size(); i ++){
    int j = f[i - 1];
    while(j > 0 && (s[j] != s[i] || j + (s[j] == s[i]) > (i + 1) / 2))
      j = f[j - 1];
    if(s[j] == s[i])
      j ++;
    f[i] = j;
  }
  return f;
}

int main(){
#ifdef LOCAL
  freopen("test.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n; ll a, b;
  cin >> n >> a >> b;
  for(int i = 0; i <= n; i ++)
    dp[i] = inf;
  string s; cin >> s;
  for(int i = 0; i < n; i ++){
    string t = s.substr(i);
    auto f = z(t);
    for(int j = 0; j < f.size(); j ++){
      p[i + j] = max(p[i + j], f[j]);
    }
  }
  dp[0] = 0;
  for(int i = 1; i <= n; i ++){
    dp[i] = dp[i - 1] + a;
    int x = i - p[i - 1];
    dp[i] = min(dp[i], dp[x] + b);
  }
  cout << dp[n];
}


#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;

const ll inf = 1e16;
const int N = 5432;

ll dp[N];
int p[N];

void z(string s, int k){
  vector<int> f(s.size());
  for(int i = 1, j = 0, d = 0; i < s.size(); i ++){
    while(j > 0 && s[j] != s[i])
      j = f[j - 1];
    while(d > 0 && s[d] != s[i])
      d = f[d - 1];
    if(s[j] == s[i])
      j ++;
    if(s[d] == s[i])
      d ++;
    f[i] = j;
    if(d > 0 && d > (i + 1) / 2)
      d = f[d - 1];
    p[k + i] = max(p[k + i], d);
  }
}

int main(){
#ifdef LOCAL
//  freopen("test.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n; ll a, b;
  cin >> n >> a >> b;
  for(int i = 0; i <= n; i ++)
    dp[i] = inf;
  string s; cin >> s;
  for(int i = 0; i < n; i ++){
    string t = s.substr(i);
    z(t, i);
  }
  dp[0] = 0;
  for(int i = 1; i <= n; i ++){
    dp[i] = dp[i - 1] + a;
    int x = i - p[i - 1];
    dp[i] = min(dp[i], dp[x] + b);
  }
  cout << dp[n];
}


#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;

const int inf = 1e15;
const int N = 5555;
int dp[N], p[N][N];

int main(){
#ifdef LOCAL
//  freopen("test.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  string s; cin >> s;

  for(int i = 1; i <= n; i ++){
    for(int j = i + 1; j <= n; j ++){
      int k = p[i][j - 1];
      while(k > 0 && s[i + k - 1] != s[j - 1])
        k = p[i][i + k - 1];
      if(s[i + k - 1] == s[j - 1])
        k ++;
      p[i][j] = k;
    }
  }
  for(int i = 0; i <= n; i ++)
    dp[i] = inf;
  dp[0] = 0;
  for(int i = 1; i <= n; i ++){
    dp[i] = dp[i - 1] + a;
    for(int j = 1; j < i; j ++){
      int z = p[j][i];
      while(z > (i - j + 1) / 2)
        z = p[j][j + z - 1];
      if(z > 0)
        dp[i] = min(dp[i], dp[i - z] + b);
    }
  }
  cout << dp[n];
}


#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;

const ll inf = 1e15;
const int N = 5555;
ll dp[N], p[N][N];

int main(){
#ifdef LOCAL
//  freopen("test.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  ll n, a, b;
  cin >> n >> a >> b;
  string s; cin >> s;

  for(int i = 1; i <= n; i ++){
    for(int j = i + 1; j <= n; j ++){
      int k = p[i][j - 1];
      while(k > 0 && s[i + k - 1] != s[j - 1])
        k = p[i][k - 1];
      if(s[i + k - 1] == s[j - 1])
        k ++;
      p[i][j] = k;
    }
  }
  for(int i = 0; i <= n; i ++)
    dp[i] = inf;
  dp[0] = 0;
  for(int i = 1; i <= n; i ++){
    dp[i] = dp[i - 1] + a;
    for(int j = 1; j <= i; j ++){
      ll z = min(p[j][i], (ll)(i - j + 1) / 2);
      if(z > 0)
        dp[i] = min(dp[i], dp[i - z] + b);
    }
  }
  cout << dp[n];
}


#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;

const int inf = 1e9;
const int N = 5555;
int dp[N], p[N][N];

int main(){
#ifdef LOCAL
//  freopen("test.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  string s; cin >> s;

  for(int i = 1; i <= n; i ++){
    for(int j = i + 1; j <= n; j ++){
      int k = p[i][j - 1];
      while(k > 0 && s[i + k - 1] != s[j - 1])
        k = p[i][k - 1];
      if(s[i + k - 1] == s[j - 1])
        k ++;
      p[i][j] = k;
    }
  }
  for(int i = 0; i <= n; i ++)
    dp[i] = inf;
  dp[0] = 0;
  for(int i = 1; i <= n; i ++){
    dp[i] = dp[i - 1] + a;
    for(int j = 1; j <= i; j ++){
      int z = min(p[j][i], (i - j + 1) / 2);
      if(z > 0)
        dp[i] = min(dp[i], dp[i - z] + b);
    }
  }
  cout << dp[n];
}


#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;

const ll inf = 1e16;
const int N = 5432;

ll dp[N];
int p[N];

vector<int> z(string s){
//  cout << s << endl;
  vector<int> f(s.size());
  for(int i = 1; i < s.size(); i ++){
    int j = f[i - 1];
    while(j > 0 && (s[j] != s[i] || j + (s[j] == s[i]) > (i + 1) / 2))
      j = f[j - 1];
    if(s[j] == s[i])
      j ++;
    f[i] = j;
  }
  return f;
}

int main(){
#ifdef LOCAL
  freopen("test.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n; ll a, b;
  cin >> n >> a >> b;
  for(int i = 0; i <= n; i ++)
    dp[i] = inf;
  string s; cin >> s;
  for(int i = 0; i < n; i ++){
    string t = s.substr(i);
    auto f = z(t);
    for(int j = 0; j < f.size(); j ++){
      p[i + j] = max(p[i + j], f[j]);
    }
  }
  dp[0] = 0;
  for(int i = 1; i <= n; i ++){
    dp[i] = dp[i - 1] + a;
    int x = i - p[i - 1];
    dp[i] = min(dp[i], dp[x] + b);
  }
  cout << dp[n];
}


#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;

const int inf = 1e7;
const int N = 5555;
int dp[N], p[N];

void e(string s){
  for(int i = 1; i < s.size(); i ++){
    int j = p[i - 1];
    while(j > 0 && s[j] != s[i])
      j = p[j - 1];
    if(s[j] == s[i])
      j ++;
    p[i] = j;
  }
}

int main(){
#ifdef LOCAL
//  freopen("test.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  string s; cin >> s;
  e(s);
  for(int i = 0; i <= n; i ++)
    dp[i] = inf;
  dp[0] = 0;
  for(int i = 1; i <= n; i ++){
    dp[i] = dp[i - 1] + a;
    int z = p[i - 1];
    for(int j = 1; j <= z && i >= 2 * j; j ++)
      dp[i] = min(dp[i], dp[i - j] + b);
  }
  cout << dp[n];
}


#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;

const ll inf = 1e15;
const int N = 5555;
ll dp[N], p[N][N];

int main(){
#ifdef LOCAL
//  freopen("test.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  ll n, a, b;
  cin >> n >> a >> b;
  string s; cin >> s;

  for(int i = 1; i <= n; i ++){
    for(int j = i + 1; j <= n; j ++){
      int k = p[i][j - 1];
      while(k > 0 && s[i + k - 1] != s[j - 1])
        k = p[i][k - 1];
      if(s[i + k - 1] == s[j - 1])
        k ++;
      p[i][j] = k;
    }
  }
  for(int i = 0; i <= n; i ++)
    dp[i] = inf;
  dp[0] = 0;
  for(int i = 1; i <= n; i ++){
    dp[i] = dp[i - 1] + a;
    for(int j = 1; j < i; j ++){
      ll z = p[j][i];
      while(z > (i - j + 1) / 2)
        z = p[j][z - 1];
      if(z > 0)
        dp[i] = min(dp[i], dp[i - z] + b);
    }
  }
  cout << dp[n];
}


#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;

const ll inf = 1e15;
const int N = 5555;
ll dp[N], p[N][N];

int main(){
#ifdef LOCAL
//  freopen("test.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  ll n, a, b;
  cin >> n >> a >> b;
  string s; cin >> s;

  for(int i = 1; i <= n; i ++){
    for(int j = i + 1; j <= n; j ++){
      int k = p[i][j - 1];
      while(k > 0 && s[i + k - 1] != s[j - 1])
        k = p[i][i + k - 1];
      if(s[i + k - 1] == s[j - 1])
        k ++;
      p[i][j] = k;
    }
  }
  for(int i = 0; i <= n; i ++)
    dp[i] = inf;
  dp[0] = 0;
  for(int i = 1; i <= n; i ++){
    dp[i] = dp[i - 1] + a;
    for(int j = 1; j < i; j ++){
      ll z = p[j][i];
      while(z > (i - j + 1) / 2)
        z = p[j][j + z - 1];
      if(z > 0)
        dp[i] = min(dp[i], dp[i - z] + b);
    }
  }
  cout << dp[n];
}


#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;

const int inf = 1e15;
const int N = 5555;
int dp[N], p[N][N];

int main(){
#ifdef LOCAL
//  freopen("test.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  string s; cin >> s;

  for(int i = 1; i <= n; i ++){
    for(int j = i + 1; j <= n; j ++){
      int k = p[i][j - 1];
      while(k > 0 && s[i + k - 1] != s[j - 1])
        k = p[i][i + k - 1];
      if(s[i + k - 1] == s[j - 1])
        k ++;
      p[i][j] = k;
    }
  }
  for(int i = 1; i <= n; i ++){
    for(int j = n; j >= i + 1; j --){
      int k = p[i][j - 1];
      while((k > 0 && s[i + k - 1] != s[j - 1]) || k + 1 > (j - i + 1) / 2)
        k = p[i][i + k - 1];
      if(s[i + k - 1] == s[j - 1])
        k ++;
      p[i][j] = k;
    }
  }
  for(int i = 0; i <= n; i ++)
    dp[i] = inf;
  dp[0] = 0;
  for(int i = 1; i <= n; i ++){
    dp[i] = dp[i - 1] + a;
    for(int j = 1; j < i; j ++){
      int z = p[j][i];
//      while(z > (i - j + 1) / 2)
//        z = p[j][j + z - 1];
      if(z > 0)
        dp[i] = min(dp[i], dp[i - z] + b);
    }
  }
  cout << dp[n];
}


#include <bits/stdc++.h>
#define fir first
#define sec second
#define pb push_back
typedef long long ll;

using namespace std;

vector<int> z_function (string s) {
	int n = (int) s.length();
	vector<int> z (n);
	for (int i=1, l=0, r=0; i<n; ++i) {
		if (i <= r)
			z[i] = min (r-i+1, z[i-l]);
		while (i+z[i] < n && s[z[i]] == s[i+z[i]])
			++z[i];
		if (i+z[i]-1 > r)
			l = i,  r = i+z[i]-1;
	}
	return z;
}

int mx[6000], dp[6000];;
int n, a, b;

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> a >> b;
    string st;
    cin >> st;

    for (int i = 1; i <= n; i++)
        dp[i] = 1e9;

    for (int i = 0; i < st.size(); i++) {
        vector<int> now = z_function(st);

        for (int j = 0; j < now.size(); j++)
            mx[j + i] = max(mx[j + i], min(j, now[j]));

        st.erase(st.begin());

    }

    for (int i = 1; i <= n; i++) {
        dp[i] = min(dp[i], dp[i - 1] + a);

        int last = 1;
        for (int j = i; j - i + 1 <= mx[i - 1]; j++) {
                dp[j] = min(dp[j], dp[i - 1] + b);
        }
    }

    cout << dp[n];
}
/*
13 4 1 3
3 2 6 4 1 4 4 7 1 3 3 2 4
4 3 4

*/


#include <bits/stdc++.h>
#define fir first
#define sec second
#define pb push_back
typedef long long ll;

using namespace std;

int base = 31;
int step[6000], hh[6000], dp[6000];
unordered_set<int> mp[6000];
int n, a, b;

int get(int l, int r) {
    return ((hh[r] - hh[l - 1])) * step[n - r];
}

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> a >> b;
    string st;
    cin >> st;
    for (int i = 1; i <= n; i++)
        dp[i] = 1e9;

    step[0] = 1;

    for (int i = 1; i <= st.size(); i++)
        step[i] = step[i - 1] * base ;

    for (int i = 1; i <= st.size(); i++) {
        hh[i] = hh[i - 1] + (st[i - 1] - 'a' + 1) * step[i];
    }

    for (int i = 1; i <= n; i++) {
        dp[i] = min(dp[i], dp[i - 1] + a);

        int last = 1;
        for (int j = i; j <= n; j++) {
            if (mp[j - i + 1].count(get(i, j)))
                dp[j] = min(dp[j], dp[i - 1] + b); else
                break
        }

        for (int j = 1; j <= i; j++)
            mp[i - j + 1].insert(get(j, i));
    }

    cout << dp[n];
}
/*
13 4 1 3
3 2 6 4 1 4 4 7 1 3 3 2 4
4 3 4

*/


#include <bits/stdc++.h>
#define fir first
#define sec second
#define pb push_back

typedef long long ll;

using namespace std;
struct state {
	int len, link;
	int next[30] = {-1, -1, -1, -1, -1,-1, -1, -1, -1, -1,-1, -1, -1, -1, -1,-1, -1, -1, -1, -1,-1, -1, -1, -1, -1,-1, -1, -1, -1, -1};
};

const int MAXLEN = 100000;
state st[MAXLEN*2];
int mn[MAXLEN*2];
bool ok[5100][5100];
int sz, last;

void sa_init() {
	sz = last = 0;
	st[0].len = 0;
	st[0].link = -1;
	++sz;
}

void sa_extend (char c) {
	int cur = sz++;
	st[cur].len = st[last].len + 1;
	int p;
	for (p=last; p!=-1 && !st[p].next[c]!= -1; p=st[p].link)
		st[p].next[c] = cur;
	if (p == -1)
		st[cur].link = 0;
	else {
		int q = st[p].next[c];
		if (st[p].len + 1 == st[q].len)
			st[cur].link = q;
		else {
			int clone = sz++;
			st[clone].len = st[p].len + 1;
			for (int i = 0; i < 30; i++)
                st[clone].next[i] = st[q].next[i];
			st[clone].link = st[q].link;
			for (; p!=-1 && st[p].next[c]==q; p=st[p].link)
				st[p].next[c] = clone;
			st[q].link = st[cur].link = clone;
		}
	}
	last = cur;
}

int dp[6000];

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    for (int i = 1; i <= n; i++)
        dp[i] = 1e9;
    sa_init();

    for (auto i:s) {
        sa_extend(i - 'a');
    }

    for (auto &i:mn)
        i = 1e9;

    for (int i = 0; i < s.size(); i++) {
        int cur = 0;
        for (int j = i; j < s.size(); j++) {
            cur = st[cur].next[s[j] - 'a'];
            if (mn[cur] < i)
                ok[i][j] = 1;
            mn[cur] = min(mn[cur], j);
        }
    }
    for (int i = 1; i <= n; i++) {
        dp[i] = min(dp[i], dp[i - 1] + a);

        int last = 1;
        for (int j = i; j <= n; j++) {
            if (ok[i - 1][j - 1])
                dp[j] = min(dp[j], dp[i - 1] + b); else
                break;
        }
    }

    cout << dp[n];
}
/*
13 4 1 3
3 2 6 4 1 4 4 7 1 3 3 2 4
4 3 4

*/


#include <bits/stdc++.h>
#define fir first
#define sec second
#define pb push_back
#define int ll

typedef long long ll;

using namespace std;

int dp[6000];

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    string st;
    cin >> st;
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        dp[i] = 1e18;
    }

    for (int i = 1; i <= n; i++) {
        dp[i] = min(dp[i], dp[i - 1] + a);

        int last = 1;
        for (int j = i; j <= n; j++) {
            while (last < i && st[last - 1] != st[j - 1])
                last++;
            if (last == i)
                break;
            dp[j] = min(dp[j], dp[i - 1] + b);
            last++;
        }
    }

    cout << dp[n];
}
/*
13 4 1 3
3 2 6 4 1 4 4 7 1 3 3 2 4
4 3 4

*/


#include <bits/stdc++.h>
#define fir first
#define sec second
#define pb push_back
typedef long long ll;

using namespace std;

vector<int> z_function (string s) {
	int n = (int) s.length();
	vector<int> z (n);
	for (int i=1, l=0, r=0; i<n; ++i) {
		if (i <= r)
			z[i] = min (r-i+1, z[i-l]);
		while (i+z[i] < n && s[z[i]] == s[i+z[i]])
			++z[i];
		if (i+z[i]-1 > r)
			l = i,  r = i+z[i]-1;
	}
	return z;
}

int mx[6000], dp[6000];;
int n, a, b;

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> a >> b;
    string st;
    cin >> st;

    for (int i = 1; i <= n; i++)
        dp[i] = 1e9;

    for (int i = 0; i < n; i++) {
        vector<int> now = z_function(st);

        for (int j = 0; j < now.size(); j++)
            mx[j + i] = max(mx[j + i], min(j, now[j]));

        st.erase(st.begin());
    }

    for (int i = 1; i <= n; i++) {
        dp[i] = min(dp[i], dp[i - 1] + a);

        for (int j = i; j - i + 1 <= mx[i - 1]; j++) {
                dp[j] = min(dp[j], dp[i - 1] + b);
        }
    }

    cout << dp[n];
}
/*
13 4 1 3
3 2 6 4 1 4 4 7 1 3 3 2 4
4 3 4

*/


#include <bits/stdc++.h>
#define fir first
#define sec second
#define pb push_back
#define int long long
typedef long long ll;

using namespace std;

int base = 31;
int md = 1e9 + 7;
int step[6000], hh[6000], dp[6000];
set<int> mp[6000];
int n, a, b;

int get(int l, int r) {
    return ((hh[r] - hh[l - 1]) % md + md) % md * step[n - r] % md;
}

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> a >> b;
    string st;
    cin >> st;
    for (int i = 1; i <= n; i++)
        dp[i] = 1e9;

    step[0] = 1;

    for (int i = 1; i <= st.size(); i++)
        step[i] = step[i - 1] * base % md;

    for (int i = 1; i <= st.size(); i++) {
        hh[i] = hh[i - 1] + (st[i - 1] - 'a' + 1) * step[i];
        hh[i] %= md;
    }

    for (int i = 1; i <= n; i++) {
        dp[i] = min(dp[i], dp[i - 1] + a);

        int last = 1;
        for (int j = i; j <= n; j++) {
            if (mp[j - i + 1].count(get(i, j)))
                dp[j] = min(dp[j], dp[i - 1] + b);
        }

        for (int j = 1; j <= i; j++)
            mp[i - j + 1].insert(get(j, i));
    }

    cout << dp[n];
}
/*
13 4 1 3
3 2 6 4 1 4 4 7 1 3 3 2 4
4 3 4

*/


#include <bits/stdc++.h>
#define fir first
#define sec second
#define pb push_back
typedef long long ll;

using namespace std;

int base = 31;
int step[6000], hh[6000], dp[6000];
unordered_set<int> mp[6000];
int n, a, b;

int get(int l, int r) {
    return ((hh[r] - hh[l - 1])) * step[n - r];
}

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> a >> b;
    string st;
    cin >> st;
    for (int i = 1; i <= n; i++)
        dp[i] = 1e9;

    step[0] = 1;

    for (int i = 1; i <= st.size(); i++)
        step[i] = step[i - 1] * base ;

    for (int i = 1; i <= st.size(); i++) {
        hh[i] = hh[i - 1] + (st[i - 1] - 'a' + 1) * step[i];
    }

    for (int i = 1; i <= n; i++) {
        dp[i] = min(dp[i], dp[i - 1] + a);

        int last = 1;
        for (int j = i; j <= n; j++) {
            if (mp[j - i + 1].count(get(i, j)))
                dp[j] = min(dp[j], dp[i - 1] + b);
        }

        for (int j = 1; j <= i; j++)
            mp[i - j + 1].insert(get(j, i));
    }

    cout << dp[n];
}
/*
13 4 1 3
3 2 6 4 1 4 4 7 1 3 3 2 4
4 3 4

*/


#include <bits/stdc++.h>
#define fir first
#define sec second
#define pb push_back

typedef long long ll;

using namespace std;

int base = 31;
int md = 1e9 + 7;
int step[6000], hh[6000], dp[6000];
unordered_set<int> mp[6000];
int n, a, b;

int get(int l, int r) {
    return ((hh[r] - hh[l - 1]) % md + md) % md * step[n - r] % md;
}

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> a >> b;
    string st;
    cin >> st;
    for (int i = 1; i <= n; i++)
        dp[i] = 1e9;

    step[0] = 1;

    for (int i = 1; i <= st.size(); i++)
        step[i] = step[i - 1] * base % md;

    for (int i = 1; i <= st.size(); i++) {
        hh[i] = hh[i - 1] + (st[i - 1] - 'a' + 1) * step[i];
        hh[i] %= md;
    }

    for (int i = 1; i <= n; i++) {
        dp[i] = min(dp[i], dp[i - 1] + a);

        int last = 1;
        for (int j = i; j <= n; j++) {
            if (mp[j - i + 1].count(get(i, j)))
                dp[j] = min(dp[j], dp[i - 1] + b); else
                break;
        }

        for (int j = 1; j <= i; j++)
            mp[i - j + 1].insert(get(j, i));
    }

    cout << dp[n];
}
/*
13 4 1 3
3 2 6 4 1 4 4 7 1 3 3 2 4
4 3 4

*/


#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ll long long
#define x first
#define y second
#define pp pair<int, int>
#define MOD 1000000007
#define NN 1000005
#define lim 400000
using namespace std;
int i,j,n,m,a,b,c,d,op,mini,mij,ls,ld,ul,timp,k,maxl,rasp;
int dp[NN];
vector<int> v[30];
string s;
int main()
{
    fast;
    #ifndef ONLINE_JUDGE
    ifstream cin(".in");
    #endif
    cin >> n >> a >> b;
    cin >> s;
    dp[0] = a;
    v[ s[0] - 'a' ].push_back(0);
    for(int i = 1; i < n; i++)
        dp[i] = 1e9;
    for(int i = 1; i < n; i++)
    {
        int poz = -1;
        dp[i] = min(dp[i], dp[i-1] + a);
        j = i;
        while(j < n)
        {
            c = s[j] - 'a';
            if(v[c].size() == 0 || *v[c].rbegin() <= poz)
                break;
            poz = *upper_bound(v[c].begin(), v[c].end(), poz);
            dp[j] = min(dp[j], dp[i - 1] + b);
            j++;
        }
        v[ s[i] - 'a' ].push_back(i);
    }
    cout << dp[n - 1];
}


#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ll long long
#define x first
#define y second
#define pp pair<int, int>
#define MOD 1000000007
#define NN 1000005
#define lim 400000
using namespace std;
int i,j,n,m,a,b,c,d,op,mini,mij,ls,ld,ul,timp,k,maxl,rasp;
int dp[NN];
int h1 = 29;
int h2 = 37;
int m1 = 1008157;
int m2 = 104723;
vector<int> has[1008158];
string s;
int main()
{
    fast;
    #ifndef ONLINE_JUDGE
    ifstream cin(".in");
    #endif
    long long c,d;
    cin >> n >> a >> b;
    cin >> s;
    dp[0] = a;
    for(int i = 1; i < n; i++)
        dp[i] = 1e9;
    has[s[0] - 'a' + 1].push_back( s[0] - 'a' + 1);
    for(int i = 1; i < n; i++)
    {
        j = i;
        c = 0;
        d = 0;
        dp[i] = min(dp[i], dp[i - 1] + a);
        while(j < n)
        {
            c = (c*h1 + s[j] - 'a' + 1) % m1;
            d = (d*h2 + s[j] - 'a' + 1) % m2;
            int ok = 0;
            for(int x = 0; x < has[c].size(); x++)
                if(has[c][x] == d)
                {
                    ok = 1;
                    break;
                }
            if(ok == 0)
                break;
            dp[j] = min(dp[j], dp[i - 1] + b);
            j++;
        }
        c = 0;
        d = 0;
        long long hh1 = 1,hh2 = 1;
        for(j = i; j >= 0; j--)
        {
            c = (c + (s[j] - 'a' + 1) * hh1) % m1;
            d = (d + (s[j] - 'a' + 1) * hh2) % m2;
            hh1 = hh1 * h1 % m1;
            hh2 = hh2 * h2 % m2;
            has[c].push_back(d);

        }
    }
    cout << dp[n - 1];
}


#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ll long long
#define x first
#define y second
#define pp pair<int, int>
#define MOD 1000000007
#define NN 1000005
#define lim 400000
using namespace std;
int i,j,n,m,a,b,c,d,op,mini,mij,ls,ld,ul,timp,k,maxl,rasp;
int dp[NN];
vector<int> v[30];
int h1 = 31;
int h2 = 37;
int m1 = 1000000007;
int m2 = 179424793;
set<pair<int,int> > myset;
string s;
int main()
{
    fast;
    #ifndef ONLINE_JUDGE
    ifstream cin(".in");
    #endif
    long long c,d;
    cin >> n >> a >> b;
    cin >> s;
    dp[0] = a;
    v[ s[0] - 'a' ].push_back(0);
    for(int i = 1; i < n; i++)
        dp[i] = 1e9;
    myset.insert({s[0] - 'a' + 1, s[0] - 'a' + 1});
    for(int i = 1; i < n; i++)
    {
        j = i;
        c = 0;
        d = 0;
        dp[i] = min(dp[i], dp[i - 1] + a);
        while(j < n)
        {
            c = (c*h1 + s[j] - 'a' + 1) % m1;
            d = (d*h2 + s[j] - 'a' + 1) % m2;
            if(myset.find({c,d}) == myset.end())
                break;
            dp[j] = min(dp[j], dp[i - 1] + b);
            j++;
        }
        c = 0;
        d = 0;
        long long hh1 = 1,hh2 = 1;
        for(j = i; j >= 0; j--)
        {
            c = (c + (s[j] - 'a' + 1) * hh1) % m1;
            d = (d + (s[j] - 'a' + 1) * hh2) % m2;
            hh1 = hh1 * h1 % m1;
            hh2 = hh2 * h2 % m2;
            myset.insert({c,d});
        }
    }
    cout << dp[n - 1];
}


#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ll long long
#define x first
#define y second
#define pp pair<int, int>
#define MOD 1000000007
#define NN 1000005
#define lim 400000
using namespace std;
int i,j,n,m,a,b,c,d,op,mini,mij,ls,ld,ul,timp,k,maxl,rasp;
int dp[NN];
vector<int> v[30];
string s;
int main()
{
    fast;
    #ifndef ONLINE_JUDGE
    ifstream cin(".in");
    #endif
    cin >> n >> a >> b;
    cin >> s;
    dp[0] = a;
    v[ s[0] - 'a' ].push_back(0);
    for(int i = 1; i < n; i++)
        dp[i] = 1e9;
    for(int i = 1; i < n; i++)
    {
        int poz = -1;
        j = i;
        while(j < n)
        {
            c = s[j] - 'a';
            if(v[c].size() == 0 || *v[c].rbegin() <= poz)
                break;
            poz = *upper_bound(v[c].begin(), v[c].end(), poz);
            dp[j] = min(dp[j], dp[i - 1] + b);
            j++;
        }
        if(j == i)
            dp[i] = min(dp[i], dp[i-1] + a);
        v[ s[i] - 'a' ].push_back(i);
    }
    cout << dp[n - 1];
}


#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ll long long
#define x first
#define y second
#define pp pair<int, int>
#define MOD 1000000007
#define NN 1000005
#define lim 400000
using namespace std;
int i,j,n,m,a,b,c,d,op,mini,mij,ls,ld,ul,timp,k,maxl,rasp;
int dp[NN];
vector<int> v[30];
int h1 = 31;
int h2 = 37;
int m1 = 1000000007;
int m2 = 179424793;
set<pair<int,int> > myset;
string s;
int main()
{
    fast;
    #ifndef ONLINE_JUDGE
    ifstream cin(".in");
    #endif
    long long c,d;
    cin >> n >> a >> b;
    cin >> s;
    dp[0] = a;
    v[ s[0] - 'a' ].push_back(0);
    for(int i = 1; i < n; i++)
        dp[i] = 1e9;
    myset.insert({s[0] - 'a' + 1, s[0] - 'a' + 1});
    for(int i = 1; i < n; i++)
    {
        j = i;
        c = 0;
        d = 0;
        dp[i] = min(dp[i], dp[i - 1] + a);
        while(j < n)
        {
            c = (c*h1 + s[j] - 'a' + 1) % m1;
            d = (d*h2 + s[j] - 'a' + 1) % m2;
            if(myset.find({c,d}) == myset.end())
                break;
            dp[j] = min(dp[j], dp[i - 1] + b);
            j++;
        }
        c = 0;
        d = 0;
        for(j = 0; j <= i; j++)
        {
            c = (c*h1 + s[j] - 'a' + 1) % m1;
            d = (d*h2 + s[j] - 'a' + 1) % m2;
            myset.insert({c,d});
        }
    }
    cout << dp[n - 1];
}


#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ll long long
#define x first
#define y second
#define pp pair<int, int>
#define MOD 1000000007
#define NN 1000005
#define lim 400000
using namespace std;
int i,j,n,m,a,b,c,d,op,mini,mij,ls,ld,ul,timp,k,maxl,rasp;
int dp[NN];
int h1 = 31;
int h2 = 37;
int m1 = 104729;
int m2 = 104723;
vector<int> has[104735];
string s;
int main()
{
    fast;
    #ifndef ONLINE_JUDGE
    ifstream cin(".in");
    #endif
    long long c,d;
    cin >> n >> a >> b;
    cin >> s;
    dp[0] = a;
    for(int i = 1; i < n; i++)
        dp[i] = 1e9;
    has[s[0] - 'a' + 1].push_back( s[0] - 'a' + 1);
    for(int i = 1; i < n; i++)
    {
        j = i;
        c = 0;
        d = 0;
        dp[i] = min(dp[i], dp[i - 1] + a);
        while(j < n)
        {
            c = (c*h1 + s[j] - 'a' + 1) % m1;
            d = (d*h2 + s[j] - 'a' + 1) % m2;
            int ok = 0;
            for(int x = 0; x < has[c].size(); x++)
                if(has[c][x] == d)
                {
                    ok = 1;
                    break;
                }
            if(ok == 0)
                break;
            dp[j] = min(dp[j], dp[i - 1] + b);
            j++;
        }
        c = 0;
        d = 0;
        long long hh1 = 1,hh2 = 1;
        for(j = i; j >= 0; j--)
        {
            c = (c + (s[j] - 'a' + 1) * hh1) % m1;
            d = (d + (s[j] - 'a' + 1) * hh2) % m2;
            hh1 = hh1 * h1 % m1;
            hh2 = hh2 * h2 % m2;
            has[c].push_back(d);

        }
    }
    cout << dp[n - 1];
}


#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ll long long
#define x first
#define y second
#define pp pair<int, int>
#define MOD 1000000007
#define NN 1000005
#define lim 400000
using namespace std;
int i,j,n,m,a,b,c,d,op,mini,mij,ls,ld,ul,timp,k,maxl,rasp;
int dp[NN];
int h1 = 29;
int h2 = 37;
int m1 = 104729;
int m2 = 104723;
vector<int> has[104735];
string s;
int main()
{
    fast;
    #ifndef ONLINE_JUDGE
    ifstream cin(".in");
    #endif
    long long c,d;
    cin >> n >> a >> b;
    cin >> s;
    dp[0] = a;
    for(int i = 1; i < n; i++)
        dp[i] = 1e9;
    has[s[0] - 'a' + 1].push_back( s[0] - 'a' + 1);
    for(int i = 1; i < n; i++)
    {
        j = i;
        c = 0;
        d = 0;
        dp[i] = min(dp[i], dp[i - 1] + a);
        while(j < n)
        {
            c = (c*h1 + s[j] - 'a' + 1) % m1;
            d = (d*h2 + s[j] - 'a' + 1) % m2;
            int ok = 0;
            for(int x = 0; x < has[c].size(); x++)
                if(has[c][x] == d)
                {
                    ok = 1;
                    break;
                }
            if(ok == 0)
                break;
            dp[j] = min(dp[j], dp[i - 1] + b);
            j++;
        }
        c = 0;
        d = 0;
        long long hh1 = 1,hh2 = 1;
        for(j = i; j >= 0; j--)
        {
            c = (c + (s[j] - 'a' + 1) * hh1) % m1;
            d = (d + (s[j] - 'a' + 1) * hh2) % m2;
            hh1 = hh1 * h1 % m1;
            hh2 = hh2 * h2 % m2;
            has[c].push_back(d);

        }
    }
    cout << dp[n - 1];
}


// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int mod = 1e9 + 7;

const int N = 5001;
const int base = 27;

int n, a, b;
string s;
set<int> seen;
int good[N][N];
vector<int> hashs[N];
int dp[N];
int bp[N];

int main()
{
  cin >> n >> a >> b;
  cin >> s;
  for(int i = 0 ; i < n ; i++){
    int cur_hash = 0;
    for(int j = i ; j < n ; j++){
      int c = s[j] - 'a' + 1;
      cur_hash = (1LL * cur_hash * base % mod + c) % mod;
      if(seen.find(cur_hash) == seen.end())
        break;
      good[i][j] = 1;
    }
    int c = s[i] - 'a' + 1;
    seen.insert(c);
    hashs[i].pb(c);
    if(i > 0)
      for(int k = 0 ; k < sz(hashs[i - 1]) ; k++){
        int new_hash = hashs[i - 1][k];
        new_hash = (1LL * new_hash * base % mod + c) % mod;
        seen.insert(new_hash);
        hashs[i].pb(new_hash);
      }
//    for(int j = 0 ; j < sz(hashs[i]) ; j++)
//      cout << hashs[i][j] << " ";
//    cout << endl;
  }
//  for(int i = 0 ; i < n ; i++){
//    for(int j = i ; j < n ; j++)
//      cout << good[i][j] << " ";
//    cout << endl;
//  }
  for(int i = 1 ; i <= n ; i++){
    dp[i] = a + dp[i - 1];
    for(int j = i ; j > 0 ; j--){
      if(good[j - 1][i - 1])
        dp[i] = min(dp[i], b + dp[j - 1]);
    }
  }
  cout << dp[n] << endl;
	return 0;
}


// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int mod = 1e9 + 7;

const int N = 5001;
const int C = 26;

struct node{
  vector<int> child;
  node(){
    child.resize(C);
    for(int i = 0 ; i < C ; i++)
      child[i] = -1;
  }
};

int n, a, b;
string s;
vector<node> trie;
int good[N][N];
vector<int> pos[N];
int dp[N];

int insert_char(int cur, int c)
{
  if(trie[cur].child[c] == -1){
    trie[cur].child[c] = sz(trie);
    trie.push_back(node());
  }
  return trie[cur].child[c];
}

int main()
{
  cin >> n >> a >> b;
  cin >> s;
  trie.pb(node());
  for(int i = 0 ; i < n ; i++){
    int cur = 0;
    for(int j = i ; j < n ; j++){
      int c = s[j] - 'a';
      if(trie[cur].child[c] == -1)
        break;
      good[i][j] = 1;
      cur = trie[cur].child[c];
    }
    int new_pos = insert_char(0, s[i] - 'a');
    pos[i].pb(new_pos);
    if(i > 0)
      for(auto p : pos[i - 1]){
        int new_pos = insert_char(p, s[i] - 'a');
        pos[i].pb(new_pos);
      }
  }
//  for(int i = 0 ; i < n ; i++){
//    for(int j = i ; j < n ; j++)
//      cout << good[i][j] << " ";
//    cout << endl;
//  }
  for(int i = 1 ; i <= n ; i++){
    dp[i] = a + dp[i - 1];
    for(int j = i ; j > 0 ; j--){
      if(good[j - 1][i - 1])
        dp[i] = min(dp[i], b + dp[j - 1]);
    }
  }
  cout << dp[n] << endl;
	return 0;
}


// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int mod = 1e9 + 7;

const int N = 5001;
const int C = 26;

struct node{
  int child[C];
  node(){
    for(int i = 0 ; i < C ; i++)
      child[i] = -1;
  }
};

int n, a, b;
string s;
vector<node> trie;
bool good[N][N];
vector<int> pos[N];
int dp[N];

int insert_char(int cur, int c)
{
  if(trie[cur].child[c] == -1){
    trie[cur].child[c] = sz(trie);
    trie.push_back(node());
  }
  return trie[cur].child[c];
}

int solve(int i)
{
  if(i >= n)
    return 0;
  int& r = dp[i];
  if(r != -1)
    return r;
  r = a + solve(i + 1);
  for(int j = i ; j < n ; j++)
    if(good[i][j])
      r = min(r, b + solve(j + 1));
  return r;
}

int main()
{
  cin >> n >> a >> b;
  cin >> s;
  trie.pb(node());
  for(int i = 0 ; i < n ; i++){
    int cur = 0;
    for(int j = i ; j < n ; j++){
      int c = s[j] - 'a';
      if(trie[cur].child[c] == -1)
        break;
      good[i][j] = 1;
      cur = trie[cur].child[c];
    }
    int new_pos = insert_char(0, s[i] - 'a');
    pos[i].pb(new_pos);
    if(i > 0)
      for(auto p : pos[i - 1]){
        int new_pos = insert_char(p, s[i] - 'a');
        pos[i].pb(new_pos);
      }
  }
//  for(int i = 0 ; i < n ; i++){
//    for(int j = i ; j < n ; j++)
//      cout << good[i][j] << " ";
//    cout << endl;
//  }
  memset(dp, -1, sizeof dp);
  cout << solve(0) << endl;
	return 0;
}


// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int mod = 1e9 + 7;

const int N = 5001;
const int base = 27;

int n, a, b;
string s;
int good[N][N];
int h[N][N];
int dp[N];

int main()
{
  cin >> n >> a >> b;
  cin >> s;
  for(int i = 0 ; i < n ; i++){
    h[i][i] = s[i] - 'a' + 1;
    for(int j = i + 1 ; j < n ; j++){
      int c = s[j] - 'a' + 1;
      h[i][j] = (1LL * h[i][j - 1] * base + c) % mod;
    }
  }
  // j + len < i
  // len < i - j
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < i ; j++){
      int best = -1;
      int l = i, r = min(2 * i - j, n - 1);
      while(l <= r){
        int mid = (l + r) / 2;
        int len = mid - i;
        if(h[i][i + len] == h[j][j + len]){
          best = mid;
          l = mid + 1;
        }else{
          r = mid - 1;
        }
      }
//      cout << i << " " << j << " " << best << endl;
      if(best > -1){
        for(int j = i ; j <= best ; j++)
          good[i][j] = 1;
      }
    }
  }
//  for(int i = 0 ; i < n ; i++){
//    for(int j = i ; j < n ; j++)
//      cout << good[i][j] << " ";
//    cout << endl;
//  }
  for(int i = 1 ; i <= n ; i++){
    dp[i] = a + dp[i - 1];
    for(int j = i ; j > 0 ; j--){
      if(good[j - 1][i - 1])
        dp[i] = min(dp[i], b + dp[j - 1]);
    }
  }
  cout << dp[n] << endl;
  return 0;
}


// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int mod = 1e9 + 7;

const int N = 5005;
const int C = 26;

struct node{
  int child[C];
  node(){
    for(int i = 0 ; i < C ; i++)
      child[i] = -1;
  }
};

int n, a, b;
string s;
vector<node> trie;
int good[N][N];
vector<int> pos[N];
int dp[N];

int insert_char(int cur, int c)
{
  if(trie[cur].child[c] == -1){
    trie[cur].child[c] = sz(trie);
    trie.push_back(node());
  }
  return trie[cur].child[c];
}

int solve(int i)
{
  if(i >= n)
    return 0;
  int& r = dp[i];
  if(r != -1)
    return r;
  r = a + solve(i + 1);
  for(int j = i ; j < n ; j++)
    if(good[i][j])
      r = min(r, b + solve(j + 1));
  return r;
}

int main()
{
  cin >> n >> a >> b;
  cin >> s;
  trie.pb(node());
  for(int i = 0 ; i < n ; i++){
    int cur = 0;
    for(int j = i ; j < n ; j++){
      int c = s[j] - 'a';
      if(trie[cur].child[c] == -1)
        break;
      good[i][j] = 1;
      cur = trie[cur].child[c];
    }
    int new_pos = insert_char(0, s[i] - 'a');
    pos[i].pb(new_pos);
    if(i > 0)
      for(auto p : pos[i - 1]){
        int new_pos = insert_char(p, s[i] - 'a');
        pos[i].pb(new_pos);
      }
  }
//  for(int i = 0 ; i < n ; i++){
//    for(int j = i ; j < n ; j++)
//      cout << good[i][j] << " ";
//    cout << endl;
//  }
  memset(dp, -1, sizeof dp);
  cout << solve(0) << endl;
	return 0;
}


// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int mod = 1e9 + 7;

const int N = 5001;
const int base = 27;

int n, a, b;
string s;
int good[N][N];
int h[N][N];
int dp[N];

int main()
{
  cin >> n >> a >> b;
  cin >> s;
  for(int i = 0 ; i < n ; i++){
    h[i][i] = s[i] - 'a' + 1;
    for(int j = i + 1 ; j < n ; j++){
      int c = s[j] - 'a' + 1;
      h[i][j] = (1LL * h[i][j - 1] * base + c) % mod;
    }
  }
  // j + len < i
  // len < i - j
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < i ; j++){
      int best = -1;
      int l = i, r = 2 * i - j;
      while(l <= r){
        int mid = (l + r) / 2;
        int len = mid - i;
        if(h[i][i + len] == h[j][j + len]){
          best = mid;
          l = mid + 1;
        }else{
          r = mid - 1;
        }
      }
//      cout << i << " " << j << " " << best << endl;
      if(best > -1){
        for(int j = i ; j <= best ; j++)
          good[i][j] = 1;
      }
    }
  }
//  for(int i = 0 ; i < n ; i++){
//    for(int j = i ; j < n ; j++)
//      cout << good[i][j] << " ";
//    cout << endl;
//  }
  for(int i = 1 ; i <= n ; i++){
    dp[i] = a + dp[i - 1];
    for(int j = i ; j > 0 ; j--){
      if(good[j - 1][i - 1])
        dp[i] = min(dp[i], b + dp[j - 1]);
    }
  }
  cout << dp[n] << endl;
  return 0;
}


// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int mod = 1e9 + 7;

const int N = 5005;
const int C = 26;

struct node{
  int child[C];
  node(){
    for(int i = 0 ; i < C ; i++)
      child[i] = -1;
  }
};

int n, a, b;
string s;
vector<node> trie;
int good[N][N];
vector<int> pos[N];
int dp[N];

int insert_char(int cur, int c)
{
  if(trie[cur].child[c] == -1){
    trie[cur].child[c] = sz(trie);
    trie.push_back(node());
  }
  return trie[cur].child[c];
}

int solve(int i)
{
  if(i >= n)
    return 0;
  int& r = dp[i];
  r = a + solve(i + 1);
  for(int j = i ; j < n ; j++)
    if(good[i][j])
      r = min(r, b + solve(j + 1));
  return r;
}

int main()
{
  cin >> n >> a >> b;
  cin >> s;
  trie.pb(node());
  for(int i = 0 ; i < n ; i++){
    int cur = 0;
    for(int j = i ; j < n ; j++){
      int c = s[j] - 'a';
      if(trie[cur].child[c] == -1)
        break;
      good[i][j] = 1;
      cur = trie[cur].child[c];
    }
    int new_pos = insert_char(0, s[i] - 'a');
    pos[i].pb(new_pos);
    if(i > 0)
      for(auto p : pos[i - 1]){
        int new_pos = insert_char(p, s[i - 'a']);
        pos[i].pb(new_pos);
      }
  }
//  for(int i = 0 ; i < n ; i++){
//    for(int j = i ; j < n ; j++)
//      cout << good[i][j] << " ";
//    cout << endl;
//  }
  memset(dp, -1, sizeof dp);
  cout << solve(0) << endl;
	return 0;
}


#include <stdio.h>
#include <string.h>
char s[1005];
char p1[10]="miao.",p2[10]="lala.";
main(){
	int n;
	scanf ("%d", &n);
	gets(s);
	while (n--) {
		gets(s);
		int len = strlen(s);
		bool b1 = (strstr(s,p1)) == s, b2=(strstr(s+strlen(s)-strlen(p2),p2)==(s+strlen(s)-strlen(p2)));
		if (!(b1^b2)) puts("OMG>.< I don't know!");
		else if (b1) puts("Rainbow's");
		else puts("Freda's");
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int a,b,n,ans,xx,yy;
string h="lala.",k="miao.",s,d;
char c[100010];
int main()
{
    getline(cin,d);
    n=d[0]-48;
    for(int i=0;i<n;i++)
    {
        getline(cin,s);
        xx=-1;yy=-1;
        xx=s.find(h,0);
        yy=s.find(k,0);
        if(xx!=-1&&yy==-1){cout<<"Freda's"<<endl;continue;}
        if(xx==-1&&yy!=-1){cout<<"Rainbow's"<<endl;continue;}
        if(abs(xx-yy)>5&&xx!=-1&&xx!=-1)
        {
        	if(yy>xx){cout<<"Rainbow's"<<endl;continue;}
        	else {cout<<"Freda's"<<endl;continue;}
		}
        cout<<"OMG>.< I don't know!"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int T;cin>>T;
	char t;scanf("%c",&t);
	while(T--){
		string s;getline(cin,s);
		int len=s.size()-1;
		bool a=0,b=0;
		if(s[len-4]=='l'&&s[len-3]=='a'&&s[len-2]=='l'&&s[len-1]=='a'&&s[len]=='.')a=1;
		if(s[0]=='m'&&s[1]=='i'&&s[2]=='a'&&s[3]=='o'&&s[4]=='.')b=1;
		if((a&&b)||(!a&&!b)){
			cout<<"OMG>.< I don't know!"<<endl;
			continue;
		}
		if(a)cout<<"Freda's"<<endl;
		else cout<<"Rainbow's"<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
string a="lala.",b="miao.",s,c="10";
int main()
{
	int n,a1=-1,b1=-1;
	getline(cin,s);
	if(s==c)n=10;
	else n=s[0]-48;
	for(int i=0;i<n;i++)
	{
		a1=-1,b1=-1;
		getline(cin,s);
		a1=s.find(a);
		b1=s.find(b);
		if(a1!=-1&&b1==-1){cout<<"Freda's"<<endl;continue;}
		if(a1==-1&&b1!=-1){cout<<"Rainbow's"<<endl;continue;}
		else cout<<"OMG>.< I don't know!"<<endl;
	}
	return 0;
}


#include<iostream>
#include<math.h>
#include<map>
#include<string>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<list>
using namespace std;
string a[10];
int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	getline(cin, a[0]);
	for (int i = 0; i < n; i++)
	{
		getline(cin, a[i]);
	}
	bool f1, f2;
	for (int i = 0; i < n; i++)
	{
		f1 = false; f2 = false;
		if (a[i].substr(0, 5) == "miao.")
			f1 = true;
	//	cout << a[i].substr(0, 5) << endl;
		if (a[i].substr((a[i].length()-5), 5) == "lala.")
			f2 = true;
		//cout<<a[i].substr((a[i].length() -5), 5) << endl;
		//cout << "f1: " << f1 << "  f2: " << f2 << endl;
		if ((f1&&f2) || (f1 || f2) == false)
		{
			cout << "OMG>.< I don't know!" << endl;
		}
		else if (f1)
		{
			cout << "Rainbow's" << endl;
		}
		else
			cout << "Freda's" << endl;
	}
	return 0;
}


#include<iostream>
#include<math.h>
#include<map>
#include<string>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<list>
using namespace std;
string a[11];
int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	cin.ignore();
	for (int i = 0; i < n; i++)
	{
		getline(cin, a[i]);
	}
	bool f1, f2;
	for (int i = 0; i < n; i++)
	{
		f1 = false; f2 = false;
		if (a[i].substr(0, 5) == "miao.")
			f1 = true;
		if (a[i].substr((a[i].length()-5), 5) == "lala.")
			f2 = true;
		if ((f1&&f2) || (f1 || f2) == false)
		{
			cout << "OMG>.< I don't know!" << endl;
		}
		else if (f1)
		{
			cout << "Rainbow's" << endl;
		}
		else
			cout << "Freda's" << endl;
	}
	return 0;
}


#include<iostream>
#include<math.h>
#include<map>
#include<string>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<list>
using namespace std;
string a[11];
int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	getline(cin, a[0]);
	for (int i = 0; i < n; i++)
	{
		getline(cin, a[i]);
	}
	bool f1, f2;
	for (int i = 0; i < n; i++)
	{
		f1 = false; f2 = false;
		if (a[i].substr(0, 5) == "miao.")
			f1 = true;
		if (a[i].substr((a[i].length()-5), 5) == "lala.")
			f2 = true;
		if ((f1&&f2) || (f1 || f2) == false)
		{
			cout << "OMG>.< I don't know!" << endl;
		}
		else if (f1)
		{
			cout << "Rainbow's" << endl;
		}
		else
			cout << "Freda's" << endl;
	}
	return 0;
}


#include<iostream>
#include<math.h>
#include<map>
#include<string>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<list>
using namespace std;
string a[11];
int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	cin.ignore();
	for (int i = 0; i < n; i++)
	{
		getline(cin, a[i]);
	}
	bool f1, f2;
	for (int i = 0; i < n; i++)
	{
		f1 = false; f2 = false;
		if (a[i].length() < 5)
		{
			cout<<"OMG>.< I don't know!" << endl;
			continue;
		}
		if (a[i].substr(0, 5) == "miao.")
			f1 = true;
		if (a[i].substr((a[i].length()-5), 5) == "lala.")
			f2 = true;
		if ((f1&&f2) || (f1 || f2) == false)
		{
			cout << "OMG>.< I don't know!" << endl;
		}
		else if (f1)
		{
			cout << "Rainbow's" << endl;
		}
		else
			cout << "Freda's" << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
typedef long long ll;
typedef long double ld;

int n;
string s;

int main()
{
    scanf("%d",&n);
    getline(cin, s);
    while (n--) {
        getline(cin, s);
        bool freda = false, rainbow = false;
        if (s.size() >= 5) {
            if (s.substr(s.size() - 5, 5) == "lala.") freda = true;
            if (s.substr(0, 5) == "miao.") rainbow = true;
        }
        if (freda && !rainbow) puts("Freda's");
        else if (!freda && rainbow) puts("Rainbow's");
        else puts("OMG>.< I don't know!");
    }
    return 0;
}


#include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
typedef long long ll;
typedef long double ld;

int n;
char s[1005];

int main()
{
    scanf("%d\n",&n);
    while (n--) {
        cin.getline(s, 1005);
        int len = strlen(s);
        bool freda = false, rainbow = false;
        if (len >= 5) {
            if (strcmp(s+len-5, "lala.") == 0) freda = true;
            s[5] = 0;
            if (strcmp(s, "miao.") == 0) rainbow = true;
        }
        if (freda && !rainbow) puts("Freda's");
        else if (!freda && rainbow) puts("Rainbow's");
        else puts("OMG>.< I don't know!");
    }
    return 0;
}


#include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
typedef long long ll;
typedef long double ld;

int n;
char s[1005];

int main()
{
    scanf("%d\n",&n);
    while (n--) {
        gets(s);
        int len = strlen(s);
        bool freda = false, rainbow = false;
        if (len >= 5) {
            if (strcmp(s+len-5, "lala.") == 0) freda = true;
            s[5] = 0;
            if (strcmp(s, "miao.") == 0) rainbow = true;
        }
        if (freda && !rainbow) puts("Freda's");
        else if (!freda && rainbow) puts("Rainbow's");
        else puts("OMG>.< I don't know!");
    }
    return 0;
}


#include<bits/stdc++.h>
#define FOR(i,n) for(int i =0; i < n ; i++)
using namespace std;
int main(){
    string cadena;
    int cases;
    cin>>cases;
    for(int i=0;i<=cases;i++){
        getline(cin,cadena);
        if(i==0)continue;
        if(cadena.length()<5){
            cout<<"OMG>.< I don't know!"<<endl;
            continue;
        }
        //cout<<"*"<<cadena<<"*"<<endl;
    //  getline(stream,cadena);

        if((cadena.substr(0,5)=="miao.") && (cadena.substr(cadena.length()-5,cadena.length())=="lala.")){
            cout<<"OMG>.< I don't know!"<<endl;
            continue;
        }
        if(cadena.substr(0,5)=="miao.") {
            cout<<"Rainbow's"<<endl;continue;//
        }
        if(cadena.substr(cadena.length()-5,cadena.length())=="lala."){
            cout<<"Freda's"<<endl;
            continue;
        }
        cout<<"OMG>.< I don't know!"<<endl;
    }
}


#include<bits/stdc++.h>
#define FOR(i,n) for(int i =0; i < n ; i++)
using namespace std;
int main(){
	string cadena;
	int cases;
	cin>>cases;
	for(int i=0;i<=cases;i++){
		getline(cin,cadena);
		if(i==0)continue;
		//cout<<"*"<<cadena<<"*"<<endl;
	//	getline(stream,cadena);
		if((cadena.substr(0,5)=="miao.") && (cadena.substr(cadena.length()-5,cadena.length())=="lala.")){
			cout<<"OMG>.< I don't know!"<<endl;
			continue;
		}
		if(cadena.substr(0,5)=="miao.")	{
			cout<<"Rainbow's"<<endl;continue;
		}
		if(cadena.substr(cadena.length()-5,cadena.length())=="lala."){
			cout<<"Freda's"<<endl;
			continue;
		}
		cout<<"OMG>.< I don't know!"<<endl;
		//cout<<cadena.substr(0,5)<<"*";
	//	cout<<cadena.substr(cadena.length()-5,cadena.length())<<"*"<<endl;
	}
}


#include<bits/stdc++.h>
#define FOR(i,n) for(int i =0; i < n ; i++)
using namespace std;
int main(){
	string cadena;
	int cases;
	cin>>cases;
	for(int i=0;i<=cases;i++){
		getline(cin,cadena);
		if(i==0 ||cadena.length()<5)continue;
		//cout<<"*"<<cadena<<"*"<<endl;
	//	getline(stream,cadena);

		if((cadena.substr(0,5)=="miao.") && (cadena.substr(cadena.length()-5,cadena.length())=="lala.")){
			cout<<"OMG>.< I don't know!"<<endl;
			continue;
		}
		if(cadena.substr(0,5)=="miao.")	{
			cout<<"Rainbow's"<<endl;continue;
		}
		if(cadena.substr(cadena.length()-5,cadena.length())=="lala."){
			cout<<"Freda's"<<endl;
			continue;
		}
		cout<<"OMG>.< I don't know!"<<endl;
		//cout<<cadena.substr(0,5)<<"*";
	//	cout<<cadena.substr(cadena.length()-5,cadena.length())<<"*"<<endl;
	}
}


#include<bits/stdc++.h>
#define FOR(i,n) for(int i =0; i < n ; i++)
using namespace std;
int main(){
    string cadena;
    int cases;
    cin>>cases;
    for(int i=0;i<=cases;i++){
        getline(cin,cadena);
        if(i==0)continue;
        if(cadena.length()<5){
            cout<<"OMG>.< I don't know!"<<endl;
            continue;
        }
        //cout<<"*"<<cadena<<"*"<<endl;
    //  getline(stream,cadena);

        if((cadena.substr(0,5)=="miao.") && (cadena.substr(cadena.length()-5,cadena.length())=="lala.")){
            cout<<"OMG>.< I don't know!"<<endl;
            continue;
        }
        if(cadena.substr(0,5)=="miao.") {
            cout<<"Rainbow's"<<endl;continue;
        }
        if(cadena.substr(cadena.length()-5,cadena.length())=="lala."){
            cout<<"Freda's"<<endl;
            continue;
        }
        cout<<"OMG>.< I don't know!"<<endl;
    }
}


#include<bits/stdc++.h>
#define FOR(i,n) for(int i =0; i < n ; i++)
using namespace std;
int main(){
	string cadena;
	int cases;
	cin>>cases;
	for(int i=0;i<=cases;i++){
		getline(cin,cadena);
		if(i==0)continue;
		if(cadena.length()<5){
			cout<<"OMG>.< I don't know!"<<endl;
			continue;
		}
		//cout<<"*"<<cadena<<"*"<<endl;
	//	getline(stream,cadena);

		if((cadena.substr(0,5)=="miao.") && (cadena.substr(cadena.length()-5,cadena.length())=="lala.")){
			cout<<"OMG>.< I don't know!"<<endl;
			continue;
		}
		if(cadena.substr(0,5)=="miao.")	{
			cout<<"Rainbow's"<<endl;continue;
		}
		if(cadena.substr(cadena.length()-5,cadena.length())=="lala."){
			cout<<"Freda's"<<endl;
			continue;
		}
		cout<<"OMG>.< I don't know!"<<endl;
		//cout<<cadena.substr(0,5)<<"*";
	//	cout<<cadena.substr(cadena.length()-5,cadena.length())<<"*"<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string s;
    cin>>n;
    getchar();
  while(n--){
        getline(cin,s);
        int ck=0;
        int l=s.size();
         for(int j=0;j<l-1;j++)
         {
             if(s[0]==' '||s[l-2]==' '||s[j]=='_'||s[j]=='.'||s==", "){
                printf("OMG>.< I don't know!\n");
                ck=1;
                break;
             }
         }
         for(int j=0;j<l;j++)
         {
             if(s[l-1]!='.'&&ck==0){
                printf("OMG>.< I don't know!\n");
                ck=1;
                break;
             }
         }
         for(int j=0;j<l-1;j++)
         {
            if(ck==0&&s[0]=='m'&&s[1]=='i'&&s[2]=='a'&&s[3]=='o')
             {
                 printf("Rainbow's\n");
                 break;
             }
             else if(ck==0&&s[l-2]=='a'&&s[l-3]=='l'&&s[l-4]=='a'&&s[l-5]=='l')
             {
                 printf("Freda's\n");
                 break;
             }
             else if(ck==0)
             {
                 printf("OMG>.< I don't know!\n");
                 break;
             }
         }

    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = int(1e9) + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 10 * 1000 + 13;

int n;
int k[3], t[3];

bool read () {
	if (scanf("%d", &n) != 1)
		return false;
	forn(i, 3)
		scanf("%d", &k[i]);
	forn(i, 3)
		scanf("%d", &t[i]);
	return true;
}

int st[N];
int tim[N];
queue<int> wt[3];
int tk[3];

void solve() {
	memset(st, 0, sizeof(st));
	forn(i, 3) wt[i] = queue<int>(), tk[i] = 0;

	forn(i, n) wt[0].push(i);
	set<pt> cur;
	int T = 0;
	while (!cur.empty() || !wt[0].empty() || !wt[1].empty() || !wt[2].empty()){
		forn(i, 3) while (!wt[i].empty() && tk[i] < k[i]){
			cur.insert(mp(T + t[i], wt[i].front()));
			wt[i].pop();
			++tk[i];
		}
		if (!cur.empty()){
			int i = cur.begin()->y;
			int nT = cur.begin()->x;
			cur.erase(cur.begin());
			--tk[st[i]];
			++st[i];
			T = nT;
			if (st[i] == 3) continue;
			wt[st[i]].push(i);
		}
	}
	printf("%d\n", T);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int tt = clock();
#endif

	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

#ifdef _DEBUG
	while(read()) {
#else
	if(read()) {
#endif
		solve();

#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}


//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }

int main() {
//    freopen("in.txt","r", stdin);
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    vector<int> items(4, 0);
    cin >> items[0];
    vector<int> cnt(3,0);
    for (int& x : cnt)
        cin >> x;
    vector<int> tms(3);
    for (int& x : tms)
        cin >> x;
    int n = items[0];

    vector<queue<int>> qu(3);
    int t = 0;
    for (; items.back() < n; ++t) {
        for (int i = 0; i < 3; ++i) {
            while (!qu[i].empty() && qu[i].front() == t) {
                qu[i].pop();
                ++cnt[i];
                ++items[i+1];
            }
            while (items[i] > 0 && cnt[i] > 0) {
                qu[i].push(t + tms[i]);
                --items[i];
                --cnt[i];
            }
        }
    }
    cout << t - 1 << endl;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
#include <cctype>
#include <list>
#include <assert.h>
#include <random>
#include <unordered_map>
typedef long long ll;
#define MAX 105
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1<<30)
#define MOD 1000000007
#define EPS 1e-9
#define Gr 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define lch (rt<<1)
#define rch (rt<<1|1)
bool debug = 1;
int n,m,k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
ll ln, lk, lm;

int n1,n2,n3,t1,t2,t3;
int main() {
    cin>>k>>n1>>n2>>n3>>t1>>t2>>t3;
    vector<int> v1(n1, 0), v2(n2,0), v3(n3,0);
    REP(i,k) {
        int p1 = v1[i%n1] + t1+t2+t3;
        int p2=v2[i%n2]+t2+t3;
        int p3 = v3[i%n3]+t3;
        int p = max(max(p1,p2),p3);
        v1[i%n1] = p-t2-t3;
        v2[i%n2] = p-t3;
        v3[i%n3] = p;
        m=p;
    }
    cout<<m<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5;
set< pair<ll,ll> > s1,s2,s3;
set< pair<ll,ll> >::iterator itr;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll k,n1,n2,n3;cin>>k>>n1>>n2>>n3;
    ll t1,t2,t3;cin>>t1>>t2>>t3;

    for(ll i=0;i<n1;i++)s1.insert({0,i});
    for(ll i=0;i<n2;i++)s2.insert({0,i});
    for(ll i=0;i<n3;i++)s3.insert({0,i});

    ll cur;
    for(ll i=0;i<k;i++){
        itr = s1.begin();
        cur = itr->first + t1;
        s1.insert({cur,itr->second});
        s1.erase(itr);

        itr = s2.begin();
        cur = max(cur,itr->first) + t2;
        s2.insert({cur,itr->second});
        s2.erase(itr);

        itr = s3.begin();
        cur = max(cur , itr->first) + t3;
        s3.insert({cur,itr->second});
        s3.erase(itr);
    }

    cout<<cur;
}


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

#define ll long long

const int MAX = 5e5;

const int mod = 1e9 + 7;

ll arr[MAX],cum[MAX],ans[MAX];

int main() {

    int k,n1,n2,n3,t1,t2,t3;
    scanf("%d%d%d%d%d%d%d",&k,&n1,&n2,&n3,&t1,&t2,&t3);

    priority_queue<int,vector<int>,greater<int>>pq1,pq2,pq3;

    for(int i = 0;i<n1;i++) pq1.push(0);
    for(int i = 0;i<n2;i++) pq2.push(0);
    for(int i = 0;i<n3;i++) pq3.push(0);

    int ans = 0;

    while(k) {
        k --;
        int one = pq1.top();
        one += t1;
        int two = pq2.top();
        if(one<two) {
            one += two - one;
        }
        two = one + t2;

        int three = pq3.top();

        if(two<three) {
            int x = three - two;
            two += x;
            one += x;
        }

        three = two + t3;
        ans = three;

        pq1.pop();
        pq2.pop();
        pq3.pop();

        pq1.push(one);
        pq2.push(two);
        pq3.push(three);
    }

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

    return 0;
}


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

int k, n1, n2, n3, t1, t2, t3;
deque<int> dq1, dq2, dq3;

int main() {
	scanf("%d%d%d%d%d%d%d", &k, &n1, &n2, &n3, &t1, &t2, &t3);
	for (int i = 0; i < n1; i++) dq1.push_back(0);
	for (int i = 0; i < n2; i++) dq2.push_back(0);
	for (int i = 0; i < n3; i++) dq3.push_back(0);
	for (int i = 0; i < k; i++) {
		int time1 = dq1.front(), time2 = dq2.front(), time3 = dq3.front();
		int maxtime = max(time1, max(time2 - t1, time3 - t1 - t2));
		dq1.pop_front();
		dq2.pop_front();
		dq3.pop_front();
		dq1.push_back(maxtime + t1);
		dq2.push_back(maxtime + t1 + t2);
		dq3.push_back(maxtime + t1 + t2 + t3);
		if (i == k - 1) {
			printf("%d\n", maxtime + t1 + t2 + t3);
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int MAX = 5e6 + 10;
int cnt[MAX][3];

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

    int k, n1, n2, n3, t1, t2, t3;
    cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;

    int T = t1 + t2 + t3;
    deque<int> tim[3];
    for(int i = 0; i < n1; i++)
        tim[0].push_back(t1 + t2 + t3);
    for(int i = 0; i < n2; i++)
        tim[1].push_back(t1 + t2 + t3);
    for(int i = 0; i < n3; i++)
        tim[2].push_back(t1 + t2 + t3);

    int ans = 0;
    for(int i = 0; i < k; i++) {
        int use = max({tim[0][0], tim[1][0], tim[2][0]});
        tim[0].pop_front();
        tim[1].pop_front();
        tim[2].pop_front();
        int st = use - t1 - t2 - t3;
        int T = t1 + t2 + t3;
        tim[0].push_back(st + t1 + t1 + t2 + t3);
        tim[1].push_back(st + t1 + t2 + t2 + t3);
        tim[2].push_back(use + t3);
        //cout << use << endl;
        ans = max(ans, use);
    }
    cout << ans << '\n';
}


#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ull unsigned ll
#define pb push_back
#define popb pop_back
#define mt make_tuple
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair <int,int>
#define piii pair <pii,int>
#define piiii pair <pii,pii>
#define plll pair <pair <ll, ll>, ll>
#define rep0(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<=(ll)n;i++)
#define rep(i,x,y) for(ll i=(ll)x;i<=(ll)y;i++)
#define reprev(i,n) for(ll i=(ll)n;i>=0;i--)
#define all(c) c.begin(),c.end()
#define print(a) rep0(i,a.size()) cout << a[i] << " "
#define hi() cout << "\nHello, I am error. Can you find me? :):):)\n"
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_eppoch().count())

using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;

const int mod = 998244353;
const long double pi = acos(-1);

// FOR DEBUGGING
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", ";
	else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifndef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

ll power(ll x, ll y){
	x %= mod;
	ll ans = 1;
	while(y){
		if(y&1) ans = (ans*x)%mod;
		y /= 2;
		x = (x*x)%mod;
	}
	return ans;
}

void solve(){

	int k,n1,n2,n3,t1,t2,t3;
	cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;

	multiset <int> s1,s2,s3;
	rep0(i,n1) s1.insert(0);
	rep0(i,n2) s2.insert(0);
	rep0(i,n3) s3.insert(0);

	int ans = 0;
	rep0(i,k){
		auto it = s1.begin();
		ans = *it;
		s1.erase(it);
		ans += t1;
		s1.insert(ans);

		it = s2.begin();
		ans = max(ans, *it);
		s2.erase(it);
		ans += t2;
		s2.insert(ans);

		it = s3.begin();
		ans = max(ans, *it);
		s3.erase(it);
		ans += t3;
		s3.insert(ans);
	}
	cout << ans;

	return;
}

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int TC = 1,t = 0;
	// cin >> TC;
	while(t++ < TC){
		// cout << "Case #" << t << ": ";
		solve();
		// cout << "\n";
	}

	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

	return 0;
}


/* aman36 - Aman Raj */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define fast_cin() ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define pb push_back
#define ll long long
#define ld long double
#define all(a) a.begin(), a.end()
#define pll pair<ll, ll>
#define pii pair<int, int>
#define F first
#define S second
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define forlp(k,x,n)  for (ll k = x; k <= n; k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
#define vi vector <int>
#define mem(x, v) memset(x, v, sizeof(x));
#define int ll
#define endl "\n"

using namespace __gnu_pbds;
using namespace std;

// template <typename T> using ordered_set =
//  tree<T, null_type, less<T>, rb_tree_tag,
//  tree_order_statistics_node_update>;

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << "# "<< name << " = " << arg1 << '\n';
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1 && arg1, Args &&... args){
        const char* comma = strchr(names + 1 ,',');
        cout << "# ";
        cout.write(names, comma - names)<< " = " << arg1 << " | ";
        __f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif

ll power(ll x, ll y, ll p) {
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

const ll INF = (ll)(8e18);
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const int M = 1e6+5;
const int maxn = 1e7+5;

vll process(int n, int t, vll& a) {
    multiset<int>s;
    int k = a.size();

    n = min(n, k);
    fori(n) {
        s.insert(a[i]);
    }

    vll ready;
    int c = k-n;
    fori(c) {
        int x = *s.begin();
        s.erase(s.begin());

        ready.pb(x+t);
        s.insert(max(x+t, a[n+i]));
    }

    while(!s.empty()) {
        int x = *s.begin();
        s.erase(s.begin());

        ready.pb(x+t);
    }

    return ready;
}

void solve() {
    int k, n[3], t[3];
    cin >> k >> n[0] >> n[1] >> n[2] >> t[0] >> t[1] >> t[2];

    vll ready;
    fori(k) ready.pb(0);

    fori(3) {
        ready = process(n[i], t[i], ready);
        sort(all(ready));
    }

    cout << ready[k-1] << endl;
}

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

    fast_cin();

    int tc = 1;
    // cin >> tc;

    for(int i=1; i<=tc; i++) {
        // cout << "Case #" << i << ": " ;
        solve();
    }

    #ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif

    return 0;
}

// read the question correctly
// read code carefully
// corner cases // int vs ll // cin vs scanf // clear structures // maths
// check if max, min set to INT_MAX instead of INF
// check constraint


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=5;

int k;
int n[N], t[N], pref[N], ans=0;
multiset<int> s[N];

int32_t main()
{
	IOS;
	cin>>k;
	for(int i=1;i<=3;i++)
	{
		cin>>n[i];
		for(int j=1;j<=n[i];j++)
			s[i].insert(0);
	}
	for(int i=1;i<=3;i++)
	{
		cin>>t[i];
		pref[i]=pref[i-1] + t[i];
	}
	for(int i=1;i<=k;i++)
	{
		int cur=0;
		for(int j=1;j<=3;j++)
		{
			int temp=*s[j].begin();
			s[j].erase(s[j].begin());
			temp-=pref[j-1];
			cur=max(cur, temp);
		}
		ans=max(ans, cur+pref[3]);
		for(int j=1;j<=3;j++)
			s[j].insert(cur+pref[j]);
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long k,n1,n2,n3,t1,t2,t3;
deque<long long> q1,q2,q3;
long long ans;
int main() {
    cin>>k>>n1>>n2>>n3>>t1>>t2>>t3;
    for (int i=0; i<n1; i++) q1.push_back(0);
    for (int i=0; i<n2; i++) q2.push_back(0);
    for (int i=0; i<n3; i++) q3.push_back(0);
    for (int i=0; i<k; i++) {
        long long a=q1.front(),b=q2.front(),c=q3.front();
        q1.pop_front(); q2.pop_front(); q3.pop_front();
        long long fin=max(max(a+t1,b)+t2,c)+t3;
        ans=max(ans,fin);
        q3.push_back(fin);
        q2.push_back(fin-t3);
        q1.push_back(fin-t3-t2);
    }
    cout<<ans<<'\n';
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1001;
int n, x, y, up, down, a[MAXN];
char ch[MAXN][MAXN];
int main() {
	int k, n1, n2, n3, t1, t2, t3;
	while (cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3) {
		queue<int> q1, q2, q3;
		while (n1--) q1.push(0);
		while (n2--) q2.push(0);
		while (n3--) q3.push(0);

		int ans = 0;
		while (k > 0) {
			int c1 = q1.front();
			int c2 = q2.front() - t1;
			int c3 = q3.front() - t1 - t2;
			if (ans >= c1 && ans >= c2 && ans >= c3) {
				q1.pop();
				q1.push(ans + t1);
				q2.pop();
				q2.push(ans + t1 + t2);
				q3.pop();
				q3.push(ans + t1 + t2 + t3);
				k--;
			}
			else
				ans = max(c1, max(c2, c3));
		}
		ans += t1 + t2 + t3;
		printf("%d\n", ans);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define forn(i, a, b) for (int i = a; i <= b; ++i)

multiset <int> wash, dry, fold;
int k, n1, n2, n3, t1, t2, t3;

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;
	rep(i, n1) wash.insert(0);
	rep(i, n2) dry.insert(0);
	rep(i, n3) fold.insert(0);

	int res = 0;
	rep(turn, k) {
		int w = *wash.begin(), d = *dry.begin(), f = *fold.begin();
		d = max(d, f - t2);
		w = max(w, d - t1);
		res = max(res, w + t1 + t2 + t3);
		wash.erase(wash.begin()); wash.insert(w + t1);
		dry.erase(dry.begin()); dry.insert(w + t1 + t2);
		fold.erase(fold.begin()); fold.insert(w + t1 + t2 + t3);
	}
	cout << res << endl;

	return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,n) for(register int i=a;i<=n;++i)
#define per(i,a,n) for(register int i=a;i>=n;--i)
#define mem(a) memset(a,0,sizeof(a))
#define elif else if
#define mi min(n1,min(n2,n3))
#define ma max(q1,max(q2,q3))
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
inline ll read()
{
    ll f=1,x=0;
    char ch;
    do
    {
        ch=getchar();
        if(ch=='-')
        f=-1;
    }
    while(ch<'0'||ch>'9');
    do
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    while(ch>='0'&&ch<='9');
    return f*x;
}
deque<int>w,d,f;
int k,n1,n2,n3,t1,t2,t3,q1,q2,q3,mo;
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>k>>n1>>n2>>n3>>t1>>t2>>t3;
	rep(i,1,mi)
	{
		w.push_back(t1);
		d.push_back(t1+t2);
		f.push_back(t1+t2+t3);
	}
	rep(i,mi+1,k)
	{
		q1=w.at(0);
		q2=d.at(0)-t1;
		q3=f.at(0)-t1-t2;
		if(w.size()<n1)
		q1=0;
		if(d.size()<n2)
		q2=0;
		if(f.size()<n3)
		q3=0;
		mo=ma;
		if(!(w.size()<n1))
		w.pop_front();
		if(!(d.size()<n2))
		d.pop_front();
		if(!(f.size()<n3))
		f.pop_front();
		w.push_back(mo+t1);
		d.push_back(mo+t1+t2);
		f.push_back(mo+t1+t2+t3);
	}
	cout<<f.back();
//	fclose(stdin);
//	fclose(stdout);
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
priority_queue<ll , vector<ll> , greater<ll> > q1 , q2 , q3;
ll n1 , n2 , n3 , t1 , t2 , t3 , k;
int main()
{
        cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;
        for(ll i=1;i<=n1;i++) q1.push(0);
        for(ll i=1;i<=n2;i++) q2.push(0);
        for(ll i=1;i<=n3;i++) q3.push(0);
        ll ans=0LL;
        for(ll i=1;i<=k;i++)
        {
                ll x = q1.top();
                ll y = q2.top();
                ll z = q3.top();
                q1.pop();
                q2.pop();
                q3.pop();
                ll t = z;
                t = max(y , t-t2);
                t = max(x , t-t1);
                q1.push(t+t1);
                q2.push(t+t1+t2);
                q3.push(t+t1+t2+t3);
                ans = max(ans , t+t1+t2+t3);
        }
        cout<<ans<<endl;
        return 0;
}


#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace __gnu_pbds;
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define ms(a) memset(a,0,sizeof(a))
#define ms_inf(a) memset(a,0x3f,sizeof(a))
#define ms_ninf(a) memset(a,0xcf,sizeof(a))
#define pb push_back
#define mp make_pair
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
//#define lc (o<<1)
//#define rc (o<<1|1)
//#include<ext/pb_ds/priority_queue.hpp>
//typedef __gnu_pbds::priority_queue<no> heap;  //��ƫ��
typedef long long ll;
typedef unsigned long long ull;
ull MOD=212370440130137957ll;
int mod=1e9+7;
ll INF=1e18;
const int maxn=2e6+10;
const int maxl=17;
const double PI=acos(-1.0);
const double eps=1e-8;
deque<int>d[3];
int k;
int n[3],t[3];
int main()
{
	fast;cin>>k;_for(t,0,3)cin>>n[t];_for(i,0,3)cin>>t[i];
	_for(i,0,3)
	{
		auto&e=d[i];
		_for(j,0,k)
		{
			int cur=0;
			if(i)cur=d[i-1][j];
			if(e.size()>=n[i])
			{
				cur=max(cur,e[j-n[i]]);
			}
			e.pb(cur+t[i]);
		}
	}
	cout<<d[2].back();
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
#define Max 1000001
#define inf INT_MAX
#define llinf LONG_LONG_MAX
#define f(i,n) for(i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcount(n)
#define endl '\n'
#define sz(v) (int)v.size()
#define deb1(a) cout<<a<<endl;
#define deb2(a,b) cout<<a<<' '<<b<<endl;
#define deb3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define deb4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
#define deb5(a,b,c,d,e) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<endl;

const ll N=2e5+5,mod=1e9+7,bit=60;

priority_queue<ll,vector<ll>,greater<ll>> wash,dry,fold;
ll ans=0,n1,n2,n3,k,t1,t2,t3;

signed main()
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
	{
		cin>>k>>n1>>n2>>n3>>t1>>t2>>t3;
		while(1)
		{
			if(wash.size()<n1)
			{
				wash.push(t1);
			}
			else
			{
				ll x=wash.top();
				wash.pop();
				if(dry.size()<n2)
				{
					dry.push(x+t2);
				}
				else
				{
					ll y=dry.top();
					dry.pop();
					if(fold.size()<n3)
					{
						fold.push(y+t3);
					}
					else
					{
						ll z=fold.top();
						fold.pop();
						ans=max(ans,z);
						k--;
						if(k==0)
						{
							break;
						}
						y=max(y,z);
						fold.push(y+t3);
					}
					x=max(x,y);
					dry.push(x+t2);
				}
				wash.push(x+t1);
			}
		}
		cout<<ans<<endl;
	}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define ll long long int
int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};

int main()
{
	//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int i,j,x,y,t;
	ll k,n1,n2,n3,t1,t2,t3;
	cin>>k>>n1>>n2>>n3>>t1>>t2>>t3;

	deque <ll> d1,d2,d3;
	for(i=1;i<=n1;++i)
		d1.push_back(0);
	for(i=1;i<=n2;++i)
		d2.push_back(0);
	for(i=1;i<=n3;++i)
		d3.push_back(0);

	for(i=1;i<k;++i){
		int time = max(d1.front(),max(d2.front()-t1,d3.front() -t1-t2));
		//cout<<time<<"   "<<i<<"\n";
		d1.pop_front(),d2.pop_front(),d3.pop_front();
		d1.push_back(time+t1),d2.push_back(time+t1+t2),d3.pb(time+t1+t2+t3);
	}
	int time = max(d1.front(),max(d2.front()-t1,d3.front()-t1-t2));
	cout<<time+t1+t2+t3;
return 0;
}


/*input
1 1 1 1 5 5 5

*/
//#include "race.h"
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
#define ll long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define MP make_pair
const ll INF64=4e12;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1){
            res=(res*a)%MOD;
        }
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
const ll maxn=1e3+5;
const ll maxlg=__lg(maxn)+2;
int n[3],t[3];
int f[maxn][3];
//starts to be available
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int k;
    cin>>k;
    REP(i,3) cin>>n[i];
    REP(i,3) cin>>t[i];
    int ans=0;
    REP(i,k){
        int mx=0;
        int sum=0;
        for(int j=2;j>=0;j--){
            sum+=t[j];
            MXTO(mx,sum+f[i%n[j]][n[j]]);
        }
        sum=0;
        for(int j=2;j>=0;j--){
            f[i%n[j]][n[j]]=mx-sum;
            sum+=t[j];
        }
        ans=mx;
    }
    cout<<ans;
}


/*input
2933 578 144 393 710 699 874
*/
//#include "race.h"
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
#define ll long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define MP make_pair
const ll INF64=4e12;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1){
            res=(res*a)%MOD;
        }
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
const ll maxn=1e3+5;
const ll maxlg=__lg(maxn)+2;
int n[3],t[3];
int f[maxn][3];
//starts to be available
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int k;
    cin>>k;
    REP(i,3) cin>>n[i];
    REP(i,3) cin>>t[i];
    REP(i,maxn) REP(j,3) f[i][j]=0;
    int ans=0;
    REP(i,k){
        int mx=0;
        int sum=0;
        for(int j=2;j>=0;j--){
            sum+=t[j];
            MXTO(mx,sum+f[i%n[j]][j]);
        }
        sum=0;
        for(int j=2;j>=0;j--){
            f[i%n[j]][j]=mx-sum;
            sum+=t[j];
        }
        ans=mx;
    }
    cout<<ans;
}


#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
using namespace std;

main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int k, n1, n2, n3, t1, t2, t3, ans = 0;
    cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;
    int one[n1] = {0}, two[n2] = {0}, three[n3] = {0};
    for(int i = 0; i < n1; i++)
        one[i] = -t1;
    for(int i = 0; i < n2; i++)
        two[i] = -t2;
    for(int i = 0; i < n3; i++)
        three[i] = -t3;
    int a = 0, b = 0, c = 0;
    for(int i = 0; i < k; i++){
        one[a % n1] = one[a % n1] + t1;
        two[b % n2] = max(one[a % n1] + t1, two[b % n2] + t2);
        three[c % n3] = max(two[b % n2] + t2, three[c % n3] + t3);
        ans = max(three[c % n3] + t3, ans);
        a++, b++, c++;
    }
    cout << ans << endl;
}