1 #include<iostream>
2 #include<algorithm>
3 #include<cstdio>
4 #include<cstring>
5 #include<cmath>
6 #include<cstdlib>
7 #include<vector>
8 using namespace std;
9 typedef long long ll;
10 typedef long double ld;
11 typedef pair<int,int> pr;
12 const double pi=acos(-1);
13 #define rep(i,a,n) for(int i=a;i<=n;i++)
14 #define per(i,n,a) for(int i=n;i>=a;i--)
15 #define Rep(i,u) for(int i=head[u];i;i=Next[i])
16 #define clr(a) memset(a,0,sizeof(a))
17 #define pb push_back
18 #define mp make_pair
19 #define fi first
20 #define sc second
21 #define pq priority_queue
22 #define pqb priority_queue <int, vector<int>, less<int> >
23 #define pqs priority_queue <int, vector<int>, greater<int> >
24 #define vec vector
25 ld eps=1e-9;
26 ll pp=1000000007;
27 ll mo(ll a,ll pp){if(a>=0 && a<pp)return a;a%=pp;if(a<0)a+=pp;return a;}
28 ll powmod(ll a,ll b,ll pp){ll ans=1;for(;b;b>>=1,a=mo(a*a,pp))if(b&1)ans=mo(ans*a,pp);return ans;}
29 void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
30 //void add(int x,int y,int z){ v[++e]=y; next[e]=head[x]; head[x]=e; cost[e]=z; }
31 int dx[5]={0,-1,1,0,0},dy[5]={0,0,0,-1,1};
32 ll read(){ ll ans=0; char last=‘ ‘,ch=getchar();
33 while(ch<‘0‘ || ch>‘9‘)last=ch,ch=getchar();
34 while(ch>=‘0‘ && ch<=‘9‘)ans=ans*10+ch-‘0‘,ch=getchar();
35 if(last==‘-‘)ans=-ans; return ans;
36 }
37 const int inf=1<<30,N=100005;
38 ll dp[N],sum[N];
39 char ch[N];
40 int f[N][26],l,r,n,Q[N],a,b,c,d;
41 int jud(int j,int k,int i){
42 return (((dp[j]-dp[k]+a*sum[j]*sum[j]-a*sum[k]*sum[k])>=(2*a*(sum[j]-sum[k])*sum[i])));
43 }
44 int jud_(int j,int k,int i){
45 return ((dp[j]-dp[k]+a*sum[j]*sum[j]-a*sum[k]*sum[k])*(2*a*(sum[k]-sum[i]))>=(dp[k]-dp[i]+a*sum[k]*sum[k]-a*sum[i]*sum[i])*(2*a*(sum[j]-sum[k])));
46 }
47 long double G(int j,int k){
48 return ((1.0*(dp[j]-dp[k]+a*sum[j]*sum[j]-a*sum[k]*sum[k]))/(2*a*(sum[j]-sum[k])));
49 }
50 int check(int i,int j){
51 int Max=-inf;
52 for (int i_=0;i_<26;i_++){
53 int c=f[j][i_]-f[i][i_];
54 Max=max(Max,c);
55 }
56 return ((Max>=l) && (Max<=r));
57 }
58 void Init(){
59 for (int i=1;i<=n;i++)
60 for (int j=0;j<26;j++){
61 f[i][j]=f[i-1][j]+((ch[i]-‘a‘)==j);
62 }
63 for (int i=1;i<=n;i++) dp[i]=inf; dp[0]=0;
64 }
65 int main(){
66 n=read(); a=read(),b=read(),c=read(),d=read(); l=read(),r=read();
67 scanf("%s",ch+1);
68 for (int i=1;i<=n;i++){
69 int t=read(); sum[i]=sum[i-1]+t;
70 }
71 if (l>r){
72 Init(); int h=1,t=1; Q[h]=0;
73 for (int i=1;i<=n;i++){
74 while (t-h>0 && jud(Q[h],Q[h+1],i)) h++;
75 int j=Q[h];
76 dp[i]=dp[j]+1LL*a*(sum[i]-sum[j])*(sum[i]-sum[j])+b;
77 while (t-h>0 && jud_(Q[t-1],Q[t],i)) t--;
78 Q[++t]=i;
79 printf("%lld\n",dp[i]);
80 }
81 }
82 else cout<<"FUCK"<<endl;
83 return 0;
84 }