#include < bits/stdc++.h >
using namespace std ;
#define int long long
template < class T > inline void read(T & res )
{
char c ;T flag = 1 ;
while((c = getchar()) < ' 0 ' ||c > ' 9 ' )if(c == ' - ' )flag =- 1 ;res =c - ' 0 ' ;
while((c = getchar()) >= ' 0 ' &&c <= ' 9 ' )res =res * 10 +c - ' 0 ' ;res *=flag ;
}
const int MAXN = 2 e 3 + 5 ;
const int inf = 0x 3f3f3f3f ;
int N ;
struct Edge {
int to , val , cost ;
Edge *next , *ops ;
Edge( int to , int val , int cost , Edge * next ): to(to ), val(val ), cost(cost ), next(next ){}
};
Edge * head [MAXN << 1 ];
void BuildGraph( int u , int v , int w , int c ) {
head [u ] = new Edge(v , w , c , head [u ]);
head [v ] = new Edge(u , 0 , -c , head [v ]);
head [u ]-> ops = head [v ]; head [v ]-> ops = head [u ];
}
namespace zkw {
int s , t , ans , res ;
int dis [MAXN << 1 ];
bool vis [MAXN << 1 ];
bool Spfa() {
memset(vis , false , sizeof vis );
memset(dis , 0x 3f , sizeof dis );
deque <int> q ;
q .push_back(s );
vis [s ] = true ; dis [s ] = 0 ;
while ( ! q .empty()) {
int u = q .front(); q .pop_front(); vis [u ] = false ;
for (Edge *e = head [u ]; e ; e = e -> next ) {
int v = e -> to ;
if ( e -> val > 0 && dis [u ] + e -> cost < dis [v ]) {
dis [v ] = dis [u ] + e -> cost ;
if ( ! vis [v ]) {
vis [v ] = true ;
if ( ! q .empty() && dis [v ] < dis [ q .front()]) q .push_front(v );
else q .push_back(v );
}
}
}
}
return dis [t ] < inf ;
}
int Dfs( int u , int flow ) {
if (u == t ) {
vis [u ] = true ;
res += flow ;
return flow ;
}
int used = 0 ; vis [u ] = true ;
for (Edge *e = head [u ]; e ; e = e -> next ) { //当前弧就不加了
int v = e -> to ;
if (( ! vis [v ] || v == t ) && e -> val && dis [u ] + e -> cost == dis [v ]) {
int mi = Dfs(v , min( e -> val , flow - used ));
if (mi ) {
e -> val -= mi ;
e -> ops -> val += mi ;
ans += e -> cost * mi ;
used += mi ;
}
if (used == flow ) break;
}
}
return used ;
}
void Work() {
res = 0 ; ans = 0 ;
while (Spfa()) {
vis [t ] = true ;
while ( vis [t ]) {
memset(vis , false , sizeof vis );
Dfs(s , inf );
}
}
}
}
signed main() {
read(N );
zkw :: s = 0 ; zkw :: t = N * 2 + 1 ;
int s = 0 , t = 2 * N + 1 ;
for ( int i = 1 ; i <= N ; ++i ) {
int x ; read(x );
BuildGraph(s , i , x , 0 );
BuildGraph(i + N , t , x , 0 );
}
int p , m , f , n , S ;
read(p ); read(m ); read(f ); read(n ); read(S );
for ( int i = 1 ; i <= N ; ++i ) {
BuildGraph(s , i + N , inf , p );
if(i + m <= N )
BuildGraph(i , i + N + m , inf , f );
if(i + n <= N )
BuildGraph(i , i + N + n , inf , S );
if(i + 1 <= N )
BuildGraph(i , i + 1 , inf , 0 );
}
zkw :: Work();
cout << zkw :: ans << endl ;
return 0 ;
}