#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e7+10;

vector<int> v1(MAXN), v2(MAXN), v3(MAXN), v4(MAXN);

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

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

	int temp = k, cur = t1;
	while(temp > 0) {
		v1[cur] = min(temp, n1);
		temp -= min(n1, temp);
		cur += t1;
	}

	int space = n2, rem = 0;

	for(int i = 1; i < MAXN; i++) {
		rem += v1[i];
		if(i > t2) {
			space += v2[i-t2];
			v3[i] = v2[i-t2];
		}
		v2[i] = min(rem, space);
		rem -= v2[i];
		space -= v2[i];
	}

	space = n3, rem = 0;
	int ans = 0;

	for(int i = 1; i < MAXN; i++) {
		rem += v3[i];
		if(i > t3) {
			space += v4[i-t3];
			//v5[i] = v4[i-t3];
			if(v4[i-t3] > 0) ans = i;
		}
		v4[i] = min(rem, space);
		rem -= v4[i];
		space -= v4[i];
	}

	cout << ans << '\n';

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 3e7+10;

vector<int> v2(MAXN), v3(MAXN);

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

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

	int temp = k, cur = t1;
	// while(temp > 0) {
	// 	v1[cur] = min(temp, n1);
	// 	temp -= min(n1, temp);
	// 	cur += t1;
	// }

	int space = n2, rem = 0;

	for(int i = 1; i < MAXN; i++) {
		if(i % t1 == 0) {
			rem += min(temp, n1);
			temp -= min(temp, n1);
		}
		if(i > t2) {
			space += v2[i-t2];
			v3[i] = v2[i-t2];
		}
		v2[i] = min(rem, space);
		rem -= v2[i];
		space -= v2[i];
	}

	space = n3, rem = 0;
	int ans = 0;

	for(int i = 1; i < MAXN; i++) {
		v2[i] = 0;
	}

	for(int i = 1; i < MAXN; i++) {
		rem += v3[i];
		if(i > t3) {
			space += v2[i-t3];
			if(v2[i-t3] > 0) ans = i;
		}
		v2[i] = min(rem, space);
		rem -= v2[i];
		space -= v2[i];
	}

	cout << ans << '\n';

	return 0;
}


/*...................bismillahir rahmanir rahim.....................*/
#include<bits/stdc++.h>

#define m_p make_pair
#define PB push_back
#define FF first
#define SS second
#define PII pair<int,int>
#define PSS pair<string,string>
#define MX 1000007
#define MOD 1000000007
#define SI(a)({ ;scanf("%d",&a);a;})
#define SII(a,b) scanf("%d%d",&a,&b)
#define SC(a)({ ;scanf("%c",&a);a;})
#define SL(a)({ ;scanf("%lld",&a);a;})
#define SD(a)({ ;scanf("%lf",&a);a;})
#define FI freopen("input.txt","r+",stdin);
#define FO freopen("output.txt","w+",stdout);
using namespace std;

typedef long long LL;

/*............start.............*/
// int Set(int n,int pos){ return n | (1<<pos); }
// int Reset(int n,int pos){ return n=n & ~(1<<pos); }
// bool check(int n,int pos){ return (bool)(n & (1<<pos)); }

void solve()
{
    int k,n1,n2,n3,t1,t2,t3;
    cin>>k>>n1>>n2>>n3>>t1>>t2>>t3;
    int timee=0;
    int k1,k2,k3;
    k1=k2=k3=0;
    int n=k;
    queue<int> pq1,pq2,pq3;
    while( k3<n )
    {
        while(!pq1.empty() && timee==pq1.front() )
        {
            k1++;
            pq1.pop();
        }
        while(!pq2.empty() && timee==pq2.front() )
        {
            k2++;
            pq2.pop();
        }
        while(!pq3.empty() && timee==pq3.front() )
        {
            k3++;
            pq3.pop();
        }
        while(k>0 && pq1.size()<n1)
        {
            k--;
            pq1.push(timee+t1);
        }
        while(k1>0 && pq2.size()<n2)
        {
            k1--;
            pq2.push(timee+t2);
        }
        while(k2>0 && pq3.size()<n3)
        {
            k2--;
            pq3.push(timee+t3);
        }
        int x=INT_MAX;
        if(!pq1.empty()) x=min(x,pq1.front());
        if(!pq2.empty()) x=min(x,pq2.front());
        if(!pq3.empty()) x=min(x,pq3.front());
        if(k3<n)timee=x;
    }
    cout<<timee<<endl;
}

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

    int q=1;
    // cin>>q;
    // SI(q);
    for(int kase=1;kase<=q;kase++)
    {
        //cout<<"Case "<<kase<<": ";
        // printf("Case %d:\n",kase );
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
int d[10001]={0},k,n,m,o,t,u,v;
cin>>k>>n>>m>>o>>t>>u>>v;
for(int i=1;i<=k;i++){
i>n?d[i]=max(d[i],d[i-n]+t):0;
i>m?d[i]=max(d[i],d[i-m]+u):0;
i>o?d[i]=max(d[i],d[i-o]+v):0;
}
cout<<d[k]+t+u+v;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t(1);
    while(t--){
        int dp[10010]={0};
        int k , n[3] , t[3];
        cin>>k;
        for(int i = 0 ; i < 3 ; i++)cin>>n[i];
        for(int i = 0 ; i < 3 ; i++)cin>>t[i];
        for(int i = 0 ; i < 3 ; i++)
            for(int j = 0 ; j < k ; j++)
                dp[j]=max(dp[j],(j-n[i]<0)?0:dp[j-n[i]])+t[i];
        sort(dp , dp+10010);
        cout<<dp[10009]<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll  long long
#define pb  push_back
#define vi  vector<int>
#define vvi vector<vi >
#define all(x) x.begin(), x.end()
#define ld long double

int k, n[3], t[3], e[3], T[3], res = 0;
set<pair<int, int> > s[3];

int main() {
    ios_base::sync_with_stdio(false);
    cin >> k;
    for (int i = 0; i < 3; ++i)
        cin >> n[i];
    for (int i = 0; i < 3; ++i)
        cin >> t[i];

    for (int i = 0; i < 3; ++i)
        for (int j = 0; j < n[i]; ++j)
            s[i].insert({0, j});

    for (int o = 0; o < k; ++o) {
        for (int i = 0; i < 3; ++i) {
            e[i] = s[i].begin()->second;
            T[i] = s[i].begin()->first;
            s[i].erase(s[i].begin());
        }
        int tt = max({T[0], T[1] - t[0], T[2] - t[0] - t[1]});
        T[0] = tt + t[0];
        T[1] = tt + t[0] + t[1];
        T[2] = tt + t[0] + t[1] + t[2];
        res = T[2];
        for (int i = 0; i < 3; ++i)
            s[i].insert({T[i], e[i]});
    }
    cout << res;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
priority_queue<int>w, d, f;
int main()
{
    int k, n1, n2, n3, t1, t2, t3, cnt= 0, res;
    scanf("%d %d %d %d %d %d %d", &k, &n1, &n2, &n3, &t1, &t2, &t3);
    for(int i=0; cnt<k; i++)
    {
        while(!f.empty() && cnt<k && (-f.top()+t3)==i)
        f.pop(), cnt++, res= i;
        while(!d.empty() && f.size()<n3 && (-d.top()+t2)<=i)
        f.push(-i), d.pop();
        while(!w.empty() && d.size()<n2 && (-w.top()+t1)<=i)
        d.push(-i), w.pop();
        while(w.size()<n1)w.push(-i);
    }
    printf("%d\n", res);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
//#define pf push_front
#define pff pop_front
#define pbb pop_back
#define fr first
#define sc second
int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0},dxx[8]={0,0,1,1,1,-1,-1,-1},dyy[8]={1,-1,0,1,-1,0,1,-1};
//914836017997511610
int main()
{ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int k,n1,n2,n3,t1,t2,t3;
cin>>k>>n1>>n2>>n3>>t1>>t2>>t3;
//n2=min(n1,n2);
//n3=min(n3,n2);
//int tot=t1+t2+t3;
//int m1=min(n1,min(n2,n3));

deque<int> q1,q2,q3;
//int ans=0,curt1=0,curt2=0,curt3=0;
int val=0;
//int it=m1;

//int f1=0,f2=0,f3=0;

//int val=max(f1,max(f2-t1,f3-t1-t2));
/*if(n1==1)
	val=max(val,t1);
if(n2==1)
	val=max(val,t2);
if(n3==1)
	val=max(val,t3);*/
int temp=val;
//q1.pb(0);q2.pb(t1);q3.pb(t1+t2);

//int cnt=0;
while(k--)
{
	//if(n1==q1.size())
	//	q1.pff();
	//cout<<"cnt"<<++cnt<<"val"<<val<<endl;
	q1.pb(val);
	if(n1==q1.size())
		{temp=q1.front()+t1;
			//cout<<temp<<"ok"<<k<<"k"<<q1.front()<<endl;
			q1.pff();//cout<<"ss"<<q1.size()<<"-->"<<q1.front()<<endl;
		}

	q2.pb(val+t1);
	if(n2==q2.size())
		{temp=max(temp,q2.front()+t2-t1);//cout<<temp<<"fine"<<k<<"k"<<endl;
	q2.pff();//commented this line in the previous answer
}
	q3.pb(val+t2+t1);
	if(n3==q3.size())
	{
		temp=max(temp,q3.front()+t3-t1-t2);//cout<<"temp"<<temp<<"k"<<k<<endl;
		q3.pff();
	}

	if(k>0)
	{val=temp;
	temp=val;}
	//cout<<"val"<<val<<endl;
}
cout<<val+t1+t2+t3;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
//#define pf push_front
#define pff pop_front
#define pbb pop_back
#define fr first
#define sc second
int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0},dxx[8]={0,0,1,1,1,-1,-1,-1},dyy[8]={1,-1,0,1,-1,0,1,-1};
//914836017997511610
int main()
{ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int k,n1,n2,n3,t1,t2,t3;
cin>>k>>n1>>n2>>n3>>t1>>t2>>t3;
//n2=min(n1,n2);
//n3=min(n3,n2);
//int tot=t1+t2+t3;
//int m1=min(n1,min(n2,n3));

deque<int> q1,q2,q3;
//int ans=0,curt1=0,curt2=0,curt3=0;
int val=0;
//int it=m1;

//int f1=0,f2=0,f3=0;

//int val=max(f1,max(f2-t1,f3-t1-t2));
/*if(n1==1)
	val=max(val,t1);
if(n2==1)
	val=max(val,t2);
if(n3==1)
	val=max(val,t3);*/
int temp=val;
//q1.pb(0);q2.pb(t1);q3.pb(t1+t2);

//int cnt=0;
while(k--)
{
	//if(n1==q1.size())
	//	q1.pff();
	//cout<<"cnt"<<++cnt<<"val"<<val<<endl;
	q1.pb(val);
	if(n1==q1.size())
		{temp=q1.front()+t1;
			//cout<<temp<<"ok"<<k<<"k"<<q1.front()<<endl;
			q1.pff();//cout<<"ss"<<q1.size()<<"-->"<<q1.front()<<endl;
		}

	q2.pb(val+t1);
	if(n2==q2.size())
		{temp=max(temp,q2.front()-t1+t2);//cout<<temp<<"fine"<<k<<"k"<<endl;q2.pff();
}
	q3.pb(val+t2+t1);
	if(n3==q3.size())
	{
		temp=max(temp,q3.front()-t1-t2+t3);//cout<<"temp"<<temp<<"k"<<k<<endl;
		q3.pff();
	}

	if(k>0)
	{val=temp;
	temp=val;}
	//cout<<"val"<<val<<endl;
}
cout<<val+t1+t2+t3;
return 0;
}


#include <functional>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <deque>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <sstream>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <iostream>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<db,db> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

typedef set<int> si;
typedef set<ll> sl;
typedef set<db> sd;
typedef set<str> ss;
typedef set<pi> spi;
typedef set<pl> spl;
typedef set<pd> spd;

#define mp make_pair
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define forr(i,a,b) for (int i = (a); i < (b); i++)
#define ford(i,a,b) for (int i = (a)-1; i >= (b); i--)
#define trav(a,x) for (auto& a: x)

const ll MOD = 1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
bool sortcol(const vl& v1, const vl& v2) {return v1[1] < v2[1];}

template<class T> bool ckmin(T& a, const T& b) {
	return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0; }
int pct(int x) { return __builtin_popcount(x); }
int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x))
int cdiv(int a, int b) { return a/b+!(a<0||a%b == 0); } // division of a by b rounded up, assumes b > 0
int fstTrue(function<bool(int)> f, int lo, int hi) {
	hi ++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true
		int mid = (lo+hi)/2;
		f(mid) ? hi = mid : lo = mid+1;
	}
	return lo;
}

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))

// ifstream cin("");
// ofstream cout("");

const int mxN = 2e5;
int q = 1, k, n1, n2, n3, t1, t2, t3, x, a, b, c;
priority_queue<int, vi, greater<int>> pq1, pq2, pq3;

void solve() {
	cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;
	forr(i,0,n3) pq3.push(t3);
	forr(i,0,n2) pq2.push(t3+t2);
	forr(i,0,n1) pq1.push(t3+t2+t1);
	forr(i,0,k) {
		a = pq1.top(); pq1.pop();
		b = pq2.top(); pq2.pop();
		c = pq3.top(); pq3.pop();
		x = max({a,b,c});
		pq1.push(x+t1);
		pq2.push(x+t2);
		pq3.push(x+t3);
	}
	cout << x << "\n";
}

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

	// cin >> q;
	while(q--) {
		solve();
	}
}


/* -*- coding: utf-8 -*-
 *
 * 0452D.cc: D. Washer, Dryer, Folder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

typedef queue<int> qi;

/* global variables */

/* subroutines */

/* main */

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

  int k, n0, n1, n2, t0, t1, t2;
  scanf("%d%d%d%d%d%d%d", &k, &n0, &n1, &n2, &t0, &t1, &t2);

  int t01 = t0 + t1;
  int t012 = t01 + t2;

  qi q0, q1, q2;
  for (int i = 0; i < n0; i++) q0.push(0);
  for (int i = 0; i < n1; i++) q1.push(0);
  for (int i = 0; i < n2; i++) q2.push(0);

  int ft = 0;
  while (k--) {
    int r0 = q0.front(); q0.pop();
    int r1 = q1.front(); q1.pop();
    int r2 = q2.front(); q2.pop();

    int s = max(max(r2 - t1, r1) - t0, r0);
    q0.push(s + t0);
    q1.push(s + t01);
    q2.push(s + t012);
    ft = s + t012;
  }

  printf("%d\n", ft);
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
const long double EPS = 1e-14;
const int maxn = 100500;
const int mod = 1e9 + 7;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int k, a, b, c, ta, tb, tc;
    cin >> k >> a >> b >> c >> ta >> tb >> tc;
    set < pair < int, int > > n1, n2, n3;
    for(int i = 0 ; i < a ; ++i) n1.insert({0, i});
    for(int i = 0 ; i < b ; ++i) n2.insert({0, i});
    for(int i = 0 ; i < c ; ++i) n3.insert({0, i});
    int ans = 0;
    for(int i = 0 ; i < k ; ++i){
        auto x = *n1.begin(); n1.erase(x);
        auto y = *n2.begin(); n2.erase(y);
        auto z = *n3.begin(); n3.erase(z);
        int ad = x.first + ta;
        x.first = ad; n1.insert(x);
        ad = max(ad + tb, y.first + tb);
        y.first = ad; n2.insert(y);
        ad = max(ad + tc, z.first + tc);
        z.first = ad; n3.insert(z);
        ans = max(ans, ad);
    }
    cout << ans << '\n';
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define fi first
#define se second
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // order_of_key
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 3000000 , mod = 1000000009;
#define PI 3.14159265
int main()
{
    fastio;
    int k,n1,n2,n3,t1,t2,t3;
    cin>>k>>n1>>n2>>n3>>t1>>t2>>t3;

    deque<int>x,y,z;
    for(int i=0;i<n1;i++)x.pb(0);
    for(int i=0;i<n2;i++)y.pb(0);
    for(int i=0;i<n3;i++)z.pb(0);
    ll ans = 0;
    for(int i=0;i<k;i++)
    {
        int t = max(max(z.front()-t2,y.front())-t1,x.front());
        //trace2(i,t);
        if(t<0)t = 0;
        x.pop_front();
        x.pb(t+t1);
        y.pop_front();
        y.pb(t+t1+t2);
        z.pop_front();
        z.pb(t+t1+t2+t3);
        ans = t + t1 + t2 + t3;
    }
    cout<<ans<<endl;
    return 0;
}


// TechProcess.cpp: ���������� ����� ����� ��� ����������� ����������.
//

#include <tchar.h>
#include <iostream>

int getMaxWorkTime(int * schedule, int length)
{
	int res = schedule[0];

	for(int i = 1; i < length; ++i)
	{
		if(schedule[i] > res)
		{
			res = schedule[i];
		}
	}

	return res;
}

int getMinWorkTime(int * schedule, int length, int min = 0)
{
	bool found = false;
	int res = min;

	for(int i = 0; i < length; ++i)
	{
		if((!found || schedule[i] < res) && schedule[i] >= min)
		{
			res = schedule[i];
			found = true;
		}
	}

	return res;
}

void orderMech(int * schedule, int length, int time)
{
	int currentMin = getMinWorkTime(schedule, length);
	bool added = false;

	for(int i = 0; i < length && !added; ++i)
	{
		if(schedule[i] == currentMin)
		{
			schedule[i] += time;
			added = true;
		}
	}
}

void updateTime(int * schedule, int length, int timePassed)
{
	for(int i = 0; i < length; ++i)
	{
		schedule[i] = schedule[i] - timePassed > 0 ? schedule[i] - timePassed : 0;
	}
}

int getNumberOfFreeUnits(int * schedule, int length, int time)
{
	int res = 0;

	for(int i = 0; i < length; ++i)
	{
		int val = schedule[i];
		if(val <= time)
		{
			++res;
		}
	}

	return res;
}

int _tmain(int argc, _TCHAR* argv[])
{
	int k, wash, dry, iron, washT, dryT, ironT;

	std::cin >> k >> wash >> dry >> iron >> washT >> dryT >> ironT;

	int * washSchedule = new int[wash];
	int * drySchedule = new int[dry];
	int * ironSchedule = new int[iron];

	for(int i = 0; i < wash; ++i)
	{
		washSchedule[i] = 0;
	}

	for(int i = 0; i < dry; ++i)
	{
		drySchedule[i] = 0;
	}

	for(int i = 0; i < iron; ++i)
	{
		ironSchedule[i] = 0;
	}

	int time = 0;

	while(k > 0)
	{
		int washDelay = getMinWorkTime(washSchedule, wash);
		int dryDelay = getMinWorkTime(drySchedule, dry);
		int ironDelay = getMinWorkTime(ironSchedule, iron);

		if(washDelay == 0 && dryDelay <= washT && ironDelay <= washT + dryT)
		{
			--k;

			orderMech(washSchedule, wash, washT);
			orderMech(drySchedule, dry, washT - dryDelay + dryT);
			orderMech(ironSchedule, iron, washT + dryT - ironDelay + ironT);
		}
		else
		{
			int change;
			if(washDelay > 0)
			{
				change = washDelay;

				time += change;

				updateTime(washSchedule, wash, change);
				updateTime(drySchedule, dry, change);
				updateTime(ironSchedule, iron, change);
			}
			else
			{
				change = dryDelay - washT > ironDelay - (washT + dryT) ?
					dryDelay - washT : ironDelay - (washT + dryT);

				time += change;

				updateTime(washSchedule, wash, change);
				updateTime(drySchedule, dry, change);
				updateTime(ironSchedule, iron, change);
			}
		}
	}

	int maxWashTime = getMaxWorkTime(washSchedule, wash);
	int maxDryTime = getMaxWorkTime(drySchedule, dry);
	int maxIronTime = getMaxWorkTime(ironSchedule, iron);

	int maxTime = maxWashTime > maxDryTime ? maxWashTime : maxDryTime;
	maxTime = maxIronTime > maxTime ? maxIronTime : maxTime;

	time += maxTime;

	std::cout << time;

	delete[] washSchedule;
	delete[] drySchedule;
	delete[] ironSchedule;

	return 0;
}


// TechProcess.cpp: ���������� ����� ����� ��� ����������� ����������.
//

#include <tchar.h>
#include <iostream>

int getMaxWorkTime(int * schedule, int length)
{
	int res = schedule[0];

	for(int i = 1; i < length; ++i)
	{
		if(schedule[i] > res)
		{
			res = schedule[i];
		}
	}

	return res;
}

int getMinWorkTime(int * schedule, int length, int min = 0)
{
	bool found = false;
	int res = min;

	for(int i = 0; i < length; ++i)
	{
		if((!found || schedule[i] < res) && schedule[i] >= min)
		{
			res = schedule[i];
			found = true;
		}
	}

	return res;
}

void orderMech(int * schedule, int length, int time)
{
	int currentMin = getMinWorkTime(schedule, length);
	bool added = false;

	for(int i = 0; i < length && !added; ++i)
	{
		if(schedule[i] == currentMin)
		{
			schedule[i] += time;
			added = true;
		}
	}
}

void updateTime(int * schedule, int length, int timePassed)
{
	for(int i = 0; i < length; ++i)
	{
		schedule[i] = schedule[i] - timePassed > 0 ? schedule[i] - timePassed : 0;
	}
}

int getNumberOfFreeUnits(int * schedule, int length, int time)
{
	int res = 0;

	for(int i = 0; i < length; ++i)
	{
		int val = schedule[i];
		if(val <= time)
		{
			++res;
		}
	}

	return res;
}

int _tmain(int argc, _TCHAR* argv[])
{
	int k, wash, dry, iron, washT, dryT, ironT;

	std::cin >> k >> wash >> dry >> iron >> washT >> dryT >> ironT;

	int * washSchedule = new int[wash];
	int * drySchedule = new int[dry];
	int * ironSchedule = new int[iron];

	for(int i = 0; i < wash; ++i)
	{
		washSchedule[i] = 0;
	}

	for(int i = 0; i < dry; ++i)
	{
		drySchedule[i] = 0;
	}

	for(int i = 0; i < iron; ++i)
	{
		ironSchedule[i] = 0;
	}

	int time = 0;

	while(k > 0)
	{
		int washDelay = getMinWorkTime(washSchedule, wash);
		int dryDelay = getMinWorkTime(drySchedule, dry);
		int ironDelay = getMinWorkTime(ironSchedule, iron);

		if(washDelay == 0 && dryDelay <= washT && ironDelay <= washT + dryT)
		{
			--k;

			orderMech(washSchedule, wash, washT);
			orderMech(drySchedule, dry, washT - dryDelay + dryT);
			orderMech(ironSchedule, dry, washT + dryT - ironDelay + ironT);
		}
		else
		{
			int change;
			if(washDelay > 0)
			{
				change = washDelay;

				time += change;

				updateTime(washSchedule, wash, change);
				updateTime(drySchedule, dry, change);
				updateTime(ironSchedule, iron, change);
			}
			else
			{
				change = dryDelay - washT > ironDelay - (washT + dryT) ?
					dryDelay - washT : ironDelay - (washT + dryT);

				time += change;

				updateTime(washSchedule, wash, change);
				updateTime(drySchedule, dry, change);
				updateTime(ironSchedule, iron, change);
			}
		}
	}

	int maxWashTime = getMaxWorkTime(washSchedule, wash);
	int maxDryTime = getMaxWorkTime(drySchedule, dry);
	int maxIronTime = getMaxWorkTime(ironSchedule, iron);

	int maxTime = maxWashTime > maxDryTime ? maxWashTime : maxDryTime;
	maxTime = maxIronTime > maxTime ? maxIronTime : maxTime;

	time += maxTime;

	std::cout << time;

	delete[] washSchedule;
	delete[] drySchedule;
	delete[] ironSchedule;

	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

typedef long long ll;

int main()
{
    int k, n1, n2, n3;
    ll t1, t2, t3;
    cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;
    int b1 = 0, b2 = 0, b3 = 0;
    int r1 = k, r2 = 0, r3 = 0;

    multimap<ll, int> events;
    for (int i = 0; i < n1; ++i)
    {
        events.insert(make_pair(t1, 0));
    }
    b1 = n1;

    while(events.size())
    {
        multimap<ll, int>::iterator it = events.begin();
        if (it->second == 0)
        {
            if (b2 < n2)
            {
                events.insert(make_pair(it->first + t2, 1));
                ++b2;
                events.insert(make_pair(it->first + t1, 0));
            }
            else
            {
                ++r2;
            }
        }
        if (it->second == 1)
        {
            if (b3 < n3)
            {
                events.insert(make_pair(it->first + t3, 2));
                ++b3;
                --b2;
            }
            else
                ++r3;
            if (b2 < n2 && r2 != 0)
            {
                events.insert(make_pair(it->first + t2, 1));
                --r2;
                --b1;
                ++b2;
            }
            if (b1 < n1)
            {
                events.insert(make_pair(it->first + t1, 0));
                ++b1;
            }
        }
        if (it->second == 2)
        {
            --k;
            if (r3 != 0)
            {
                events.insert(make_pair(it->first + t3, 2));
                --r3;
                --b2;
                if (r2 != 0)
                {
                    events.insert(make_pair(it->first + t2, 1));
                    --r2;
                    --b1;
                    ++b2;
                }
                if (b1 < n1)
                {
                    events.insert(make_pair(it->first + t1, 0));
                    ++b1;
                }
            }
            else
                --b3;
        }
        if (k == 0)
        {
            cout << it->first;
            break;
        }
        events.erase(it);
    }
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#pragma warning( disable : 4244 4267 4018 4996 4800 )
//#pragma comment( linker, "/stack:10000000" )
using namespace std;
typedef vector< int > vi; typedef vector< vector< int > > vvi; typedef vector< string > vs; typedef vector< double > vd;
typedef vector< vd > vvd; typedef long long ll; typedef vector< ll > vll; typedef vector< vll > vvll; typedef pair< int, int > pii;
#define all( v ) (v).begin( ), (v).end( )

#ifdef LOCAL
ifstream in( "d.in" );
#else
istream & in = cin;
#endif
ostream & out = cout;

int pop(multiset<int> & s) {
    multiset<int>::iterator it = s.begin();
    int res = *it;
    s.erase(it);
    return res;
}

int back(multiset<int> const & s) {
    multiset<int>::iterator it = s.end();
    --it;
    return *it;
}

int main() {
    int k, n1, n2, n3, t1, t2, t3;
    in >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;
    multiset<int> s1, s2, s3;
    for (int i = 0; i < n1; ++i) s1.insert(0);
    for (int i = 0; i < n2; ++i) s2.insert(0);
    for (int i = 0; i < n3; ++i) s3.insert(0);
    for (int i = 0; i < k; ++i) {
        int x1 = pop(s1) + t1;
        int x2 = max(pop(s2), x1) + t2;
        int x3 = max(pop(s3), x2) + t3;
        s1.insert(x1);
        s2.insert(x2);
        s3.insert(x3);
    }
    int res = back(s3);
    out << res;
    return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#pragma warning( disable : 4244 4267 4018 4996 4800 )
//#pragma comment( linker, "/stack:10000000" )
using namespace std;
typedef vector< int > vi; typedef vector< vector< int > > vvi; typedef vector< string > vs; typedef vector< double > vd;
typedef vector< vd > vvd; typedef long long ll; typedef vector< ll > vll; typedef vector< vll > vvll; typedef pair< int, int > pii;
#define all( v ) (v).begin( ), (v).end( )

#ifdef LOCAL
ifstream in( "d.in" );
#else
istream & in = cin;
#endif
ostream & out = cout;

int pop(multiset<int> & s) {
    multiset<int>::iterator it = s.begin();
    int res = *it;
    s.erase(it);
    return res;
}

int back(multiset<int> const & s) {
    multiset<int>::iterator it = s.end();
    --it;
    return *it;
}

int main() {
    int k, n1, n2, n3, t1, t2, t3;
    in >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;
    multiset<int> s1, s2, s3;
    for (int i = 0; i < n1; ++i) s1.insert(i);
    for (int i = 0; i < n2; ++i) s2.insert(i);
    for (int i = 0; i < n3; ++i) s3.insert(i);
    for (int i = 0; i < k; ++i) {
        int x1 = pop(s1) + t1;
        int x2 = max(pop(s2), x1) + t2;
        int x3 = max(pop(s3), x2) + t3;
        s1.insert(x1);
        s2.insert(x2);
        s3.insert(x3);
    }
    int res = max(back(s1), max(back(s2), back(s3)));
    out << res;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdint>

using namespace std;

uint32_t main()
{
	uint32_t k, n1, n2, n3, t1, t2, t3;
	cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;

	vector< uint32_t > wash( n1 );
	vector< uint32_t > spin( n2 );
	vector< uint32_t > drying( n3 );

	uint32_t t = 0;
	while( k )
	{
		while( true )
		{
START_LOAD:
			for( auto w = wash.begin(); w != wash.end(); w++ )
			{
				if( t >= *w )
				{
					for( auto s = spin.begin(); s != spin.end(); s++ )
					{
						if( t + t1 >= *s )
						{
							for( auto d = drying.begin(); d != drying.end(); d++ )
							{
								if( t + t1 + t2 >= *d )
								{
									k--;
									*w = t + t1;
									*s = t + t1 + t2;
									*d = t + t1 + t2 + t3;
									goto START_LOAD;
								}
							}
						}
					}
				}
			}
			break;
		}

		sort( wash.begin(), wash.end() );
		sort( spin.begin(), spin.end() );
		sort( drying.begin(), drying.end() );

		uint32_t tw = wash.front() - t;
		uint32_t ts = spin.front() - t;
		if( ts >= t1 )
		{
			ts -= t1;
		}
		uint32_t td = drying.front() - t;
		if( td >= t1 + t2 )
		{
			td -= t1 + t2;
		}

		t += max( 1u, min( tw, min( ts, td ) ) );
	}

	uint32_t max_time = 0;
	for( auto d = drying.begin(); d != drying.end(); d++ )
	{
		if( *d > max_time )
		{
			max_time = *d;
		}
	}
	cout << max_time;

	return EXIT_SUCCESS;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdint>

using namespace std;

uint32_t main()
{
	uint32_t k, n1, n2, n3, t1, t2, t3;
	cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;

	vector< uint32_t > wash( n1 );
	vector< uint32_t > spin( n2 );
	vector< uint32_t > drying( n3 );

	uint32_t t = 0;
	while( k )
	{
		while( true )
		{
START_LOAD:
			for( auto w = wash.begin(); w != wash.end(); w++ )
			{
				if( t >= *w )
				{
					for( auto s = spin.begin(); s != spin.end(); s++ )
					{
						if( t + t1 >= *s )
						{
							for( auto d = drying.begin(); d != drying.end(); d++ )
							{
								if( t + t1 + t2 >= *d )
								{
									k--;
									*w = t + t1;
									*s = t + t1 + t2;
									*d = t + t1 + t2 + t3;
									goto START_LOAD;
								}
							}
						}
					}
				}
			}
			break;
		}

		t++;
	}

	uint32_t max_time = 0;
	for( auto d = drying.begin(); d != drying.end(); d++ )
	{
		if( *d > max_time )
		{
			max_time = *d;
		}
	}
	cout << max_time;

	return EXIT_SUCCESS;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdint>

using namespace std;

uint32_t main()
{
	uint32_t k, n1, n2, n3, t1, t2, t3;
	cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;

	vector< uint32_t > wash( n1 );
	vector< uint32_t > spin( n2 );
	vector< uint32_t > drying( n3 );

	uint32_t t = 0;
	while( k )
	{
		while( true )
		{
START_LOAD:
			for( auto w = wash.begin(); w != wash.end(); w++ )
			{
				if( t >= *w )
				{
					for( auto s = spin.begin(); s != spin.end(); s++ )
					{
						if( t + t1 >= *s )
						{
							for( auto d = drying.begin(); d != drying.end(); d++ )
							{
								if( t + t1 + t2 >= *d )
								{
									k--;
									*w = t + t1;
									*s = t + t1 + t2;
									*d = t + t1 + t2 + t3;
									if( !k )
									{
										goto FINISH;
									}
									goto START_LOAD;
								}
							}
						}
					}
				}
			}
			break;
		}

		t++;
	}

FINISH:
	uint32_t max_time = 0;
	for( auto d = drying.begin(); d != drying.end(); d++ )
	{
		if( *d > max_time )
		{
			max_time = *d;
		}
	}
	cout << max_time;

	return EXIT_SUCCESS;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <cstdint>

using namespace std;

uint32_t main()
{
	uint32_t k, n1, n2, n3, t1, t2, t3;
	cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;

	priority_queue< uint32_t, vector< uint32_t >, greater< uint32_t > > wash;
	for( uint32_t i = 0; i < n1; i++ )
	{
		wash.push( 0 );
	}

	priority_queue< uint32_t, vector< uint32_t >, greater< uint32_t > > spin;
	for( uint32_t i = 0; i < n2; i++ )
	{
		spin.push( 0 );
	}

	priority_queue< uint32_t, vector< uint32_t >, greater< uint32_t > > drying;
	for( uint32_t i = 0; i < n3; i++ )
	{
		drying.push( 0 );
	}

	uint32_t t = 0;
	while( k )
	{
		while( true )
		{
			uint32_t d = drying.top();
			if( t + t1 + t2 >= d )
			{
				uint32_t s = spin.top();
				if( t + t1 >= s )
				{
					uint32_t w = wash.top();
					if( t >= w )
					{
						wash.pop();
						wash.push( t + t1 );

						spin.pop();
						spin.push( t + t1 + t2 );

						drying.pop();
						drying.push( t + t1 + t2 + t3 );

						k--;
						if( !k )
						{
							goto FINISH;
						}
						continue;
					}
				}
			}

			break;
		}

		int32_t td = (int32_t)drying.top() - (int32_t)( t + t1 + t2 );
		if( td > 0 )
		{
			t += (uint32_t)td;
		}
		else
		{
			int32_t ts = (int32_t)spin.top() - (int32_t)( t + t1 );
			if( ts > 0 )
			{
				t += (uint32_t)ts;
			}
			else
			{
				int32_t tw = (int32_t)wash.top() - (int32_t)t;
				t += (uint32_t)max( 1, tw );
			}
		}
	}

FINISH:
	while( drying.size() > 1 )
	{
		drying.pop();
	}
	cout << drying.top();

	return EXIT_SUCCESS;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <limits>
using namespace std;

// Types
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int,int> ipair;
const double pi=acos(-1.0);
const double eps=1e-11;

// Generic
#define SIZE(X) ((int)(X.size()))
#define LENGTH(X) ((int)(X.length()))
#define MP(X,Y) make_pair(X,Y)
#define FORD(i, a, b) for(int i=(a); i<(b); i++)
#define FORS(i, a) for(int i=(0); i<SIZE(a); i++)
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
template<class T> inline T sqr(T x){return x*x;}

// Bit manipulation
template<class T> void setbit(T& v, int position)    { v |= (T)1 << position; }
template<class T> void unsetbit(T& v, int position)  { v &= ~((T)1 << position); }
template<class T> void togglebit(T& v, int position) { v ^= (T)1 << position; }
template<class T> bool isbit(T v, int position) { return (v & ((T)1 << position)) != 0; }
template<class T> inline int countbit(T n){return (n==0)?0:(1+countbit(n&(n-1)));}

// Input / Output
string ReadToEndLine(istream& s) { string sLine; getline(s, sLine); return sLine; }
char gStr[1024];
// sprintf_s(gStr, "%d", );

struct Runner
{
	Runner(istream& in, ostream& out) : mIn(in), mOut(out) {}
	void Run();
	istream& mIn; ostream& mOut;
};

void Runner::Run()
{
	int K;
	vector<int> N(3);
	vector<int> T(3);
	mIn >> K >> N[0] >> N[1] >> N[2] >> T[0] >> T[1] >> T[2];

	int Need = K;
	set<int> Times;
	Times.insert(0);
	deque<pair<int, int>> Q; // Count, time
	int now;
	while(!Times.empty() && Need > 0)
	{
		now = *Times.begin();
		Times.erase(Times.begin());

		while(!Q.empty() && Q.front().second + T[0]+T[1]+T[2] <= now)
			Q.pop_front();

		int n0 = N[0], n1 = N[1], n2 = N[2];
		FORS(i, Q)
		{
			int cnt = Q[i].first;
			int start = Q[i].second;
			int elapse = now-start;

			if(elapse <T[0])
				n0-=cnt;
			if(elapse < T[1])
				n1-=cnt;
			if(elapse < T[2])
				n2-=cnt;
		}

		int can = max(0, min(n0, min(n1, n2)));
		if(can == 0)
			continue;

		can = min(can, Need);
		Need-=can;
		Q.push_back(MP(can, now));
		Times.insert(now+T[0]);
		Times.insert(now+T[1]);
		Times.insert(now+T[2]);
	}
	mOut << Q.back().second+T[0]+T[1]+T[2];
}

#ifndef LOCAL
int main()
{
	Runner runner(cin, cout);
	runner.Run();
	return 0;
}
#endif

#ifdef LOCAL // Local testing. Nothing solution related

bool checkCase(const vector<string>& ok, const vector<string>& my)
{
	bool bSuccess = ok.size() == my.size();
	if(bSuccess)
	{
		for(size_t i=0; i<ok.size(); ++i)
			if(ok[i] != my[i])
				bSuccess = false;
	}

	cout << (bSuccess ? "Passed" : "Failed") << endl;
	if(!bSuccess)
	{
		bool newLine = ok.size() != 1 || my.size() != 1;
		cout << "expected: "; if(newLine) { cout << endl; }
		for(size_t i=0; i<ok.size(); ++i) { cout << ok[i] << endl; }
		cout << "actual  : "; if(newLine) { cout << endl; }
		for(size_t i=0; i<my.size(); ++i) { cout << my[i] << endl; }
	}
	return bSuccess;
}

vector<string> readFile(istream& s)
{
	vector<string> res; string str;
	while (s && !s.eof())
	{
		getline(s, str);
		if(str.find("--case") == 0)
			break;
		res.push_back(str);
	}
	if(res.size() > 0 && res.back().empty())
		res.resize(res.size()-1);
	return res;
}

vector<string> readFile(const string str)
{
	istringstream ssStr(str);
	return readFile(ssStr);
}

string joinLines(const vector<string>& lines)
{
	ostringstream res;
	for(size_t i=0; i<lines.size(); ++i)
		res << lines[i] << endl;
	return res.str();
}

void main(int argc, char *argv[])
{
	string pathToFiles = __FILE__;
	pathToFiles.resize(pathToFiles.size() - 4);
	ifstream sIn(pathToFiles + ".in.txt");
	ifstream sOk(pathToFiles + ".ok.txt");
	ofstream sMy(pathToFiles + ".my.txt");

	int index = 0; bool bPassed = true;
	while(sIn)
	{
		++index;
		vector<string> aIn(readFile(sIn)), aOk(readFile(sOk));
		istringstream ssIn(joinLines(aIn));
		ostringstream ssMy;

		cout << "Case " << index << ": ... ";
		Runner runner(ssIn, ssMy);
		runner.Run();

		vector<string> aMy(readFile(ssMy.str()));
		if(!checkCase(aOk, aMy))
			bPassed = false;
		if(index > 1)
			sMy << "--case " << index << endl;
		sMy << joinLines(aMy).c_str();
	}
	cout << "Tests: " << (bPassed ? "Passed" : "Failed") << endl;
	getchar();
}
#endif	// LOCAL


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <limits>
using namespace std;

// Types
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int,int> ipair;
const double pi=acos(-1.0);
const double eps=1e-11;

// Generic
#define SIZE(X) ((int)(X.size()))
#define LENGTH(X) ((int)(X.length()))
#define MP(X,Y) make_pair(X,Y)
#define FORD(i, a, b) for(int i=(a); i<(b); i++)
#define FORS(i, a) for(int i=(0); i<SIZE(a); i++)
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
template<class T> inline T sqr(T x){return x*x;}

// Bit manipulation
template<class T> void setbit(T& v, int position)    { v |= (T)1 << position; }
template<class T> void unsetbit(T& v, int position)  { v &= ~((T)1 << position); }
template<class T> void togglebit(T& v, int position) { v ^= (T)1 << position; }
template<class T> bool isbit(T v, int position) { return (v & ((T)1 << position)) != 0; }
template<class T> inline int countbit(T n){return (n==0)?0:(1+countbit(n&(n-1)));}

// Input / Output
string ReadToEndLine(istream& s) { string sLine; getline(s, sLine); return sLine; }
char gStr[1024];
// sprintf_s(gStr, "%d", );

struct Runner
{
	Runner(istream& in, ostream& out) : mIn(in), mOut(out) {}
	void Run();
	istream& mIn; ostream& mOut;
};

void Runner::Run()
{
	int K;
	vector<int> N(3);
	vector<int> T(3);
	mIn >> K >> N[0] >> N[1] >> N[2] >> T[0] >> T[1] >> T[2];

	int Need = K;
	set<int> Times;
	Times.insert(0);
	deque<pair<int, int>> Q; // Count, time
	int now;
	while(!Times.empty())
	{
		now = *Times.begin();
		Times.erase(Times.begin());

		if(Need == 0)
			continue;

		int n0 = N[0], n1 = N[1], n2 = N[2];
		FORS(i, Q)
		{
			int cnt = Q[i].first;
			int start = Q[i].second;
			int elapse = now-start;

			if(elapse <T[0])
				n0-=cnt;
			if(elapse < T[1])
				n1-=cnt;
			if(elapse < T[2])
				n1-=cnt;
		}

		int can = max(0, min(n0, min(n1, n2)));
		if(can == 0)
			continue;

		can = min(can, Need);
		Need-=can;
		Q.push_back(MP(can, now));
		Times.insert(now+T[0]);
		Times.insert(now+T[1]);
		Times.insert(now+T[2]);
	}
	mOut << Q.back().second+T[0]+T[1]+T[2];
}

#ifndef LOCAL
int main()
{
	Runner runner(cin, cout);
	runner.Run();
	return 0;
}
#endif

#ifdef LOCAL // Local testing. Nothing solution related

bool checkCase(const vector<string>& ok, const vector<string>& my)
{
	bool bSuccess = ok.size() == my.size();
	if(bSuccess)
	{
		for(size_t i=0; i<ok.size(); ++i)
			if(ok[i] != my[i])
				bSuccess = false;
	}

	cout << (bSuccess ? "Passed" : "Failed") << endl;
	if(!bSuccess)
	{
		bool newLine = ok.size() != 1 || my.size() != 1;
		cout << "expected: "; if(newLine) { cout << endl; }
		for(size_t i=0; i<ok.size(); ++i) { cout << ok[i] << endl; }
		cout << "actual  : "; if(newLine) { cout << endl; }
		for(size_t i=0; i<my.size(); ++i) { cout << my[i] << endl; }
	}
	return bSuccess;
}

vector<string> readFile(istream& s)
{
	vector<string> res; string str;
	while (s && !s.eof())
	{
		getline(s, str);
		if(str.find("--case") == 0)
			break;
		res.push_back(str);
	}
	if(res.size() > 0 && res.back().empty())
		res.resize(res.size()-1);
	return res;
}

vector<string> readFile(const string str)
{
	istringstream ssStr(str);
	return readFile(ssStr);
}

string joinLines(const vector<string>& lines)
{
	ostringstream res;
	for(size_t i=0; i<lines.size(); ++i)
		res << lines[i] << endl;
	return res.str();
}

void main(int argc, char *argv[])
{
	string pathToFiles = __FILE__;
	pathToFiles.resize(pathToFiles.size() - 4);
	ifstream sIn(pathToFiles + ".in.txt");
	ifstream sOk(pathToFiles + ".ok.txt");
	ofstream sMy(pathToFiles + ".my.txt");

	int index = 0; bool bPassed = true;
	while(sIn)
	{
		++index;
		vector<string> aIn(readFile(sIn)), aOk(readFile(sOk));
		istringstream ssIn(joinLines(aIn));
		ostringstream ssMy;

		cout << "Case " << index << ": ... ";
		Runner runner(ssIn, ssMy);
		runner.Run();

		vector<string> aMy(readFile(ssMy.str()));
		if(!checkCase(aOk, aMy))
			bPassed = false;
		if(index > 1)
			sMy << "--case " << index << endl;
		sMy << joinLines(aMy).c_str();
	}
	cout << "Tests: " << (bPassed ? "Passed" : "Failed") << endl;
	getchar();
}
#endif	// LOCAL


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <limits>
using namespace std;

// Types
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int,int> ipair;
const double pi=acos(-1.0);
const double eps=1e-11;

// Generic
#define SIZE(X) ((int)(X.size()))
#define LENGTH(X) ((int)(X.length()))
#define MP(X,Y) make_pair(X,Y)
#define FORD(i, a, b) for(int i=(a); i<(b); i++)
#define FORS(i, a) for(int i=(0); i<SIZE(a); i++)
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
template<class T> inline T sqr(T x){return x*x;}

// Bit manipulation
template<class T> void setbit(T& v, int position)    { v |= (T)1 << position; }
template<class T> void unsetbit(T& v, int position)  { v &= ~((T)1 << position); }
template<class T> void togglebit(T& v, int position) { v ^= (T)1 << position; }
template<class T> bool isbit(T v, int position) { return (v & ((T)1 << position)) != 0; }
template<class T> inline int countbit(T n){return (n==0)?0:(1+countbit(n&(n-1)));}

// Input / Output
string ReadToEndLine(istream& s) { string sLine; getline(s, sLine); return sLine; }
char gStr[1024];
// sprintf_s(gStr, "%d", );

struct Runner
{
	Runner(istream& in, ostream& out) : mIn(in), mOut(out) {}
	void Run();
	istream& mIn; ostream& mOut;
};

void Runner::Run()
{
	int K;
	vector<int> N(3);
	vector<int> T(3);
	mIn >> K >> N[0] >> N[1] >> N[2] >> T[0] >> T[1] >> T[2];

	int Need = K;
	set<int> Times;
	Times.insert(0);
	deque<pair<int, int>> Q; // Count, time
	int now;
	while(!Times.empty() && Need > 0)
	{
		now = *Times.begin();
		Times.erase(Times.begin());

		int n0 = N[0], n1 = N[1], n2 = N[2];
		FORS(i, Q)
		{
			int cnt = Q[i].first;
			int start = Q[i].second;
			int elapse = now-start;

			if(elapse <T[0])
				n0-=cnt;
			if(elapse < T[1])
				n1-=cnt;
			if(elapse < T[2])
				n2-=cnt;
		}

		int can = max(0, min(n0, min(n1, n2)));
		if(can == 0)
			continue;

		can = min(can, Need);
		Need-=can;
		Q.push_back(MP(can, now));
		Times.insert(now+T[0]);
		Times.insert(now+T[1]);
		Times.insert(now+T[2]);
	}
	mOut << Q.back().second+T[0]+T[1]+T[2];
}

#ifndef LOCAL
int main()
{
	Runner runner(cin, cout);
	runner.Run();
	return 0;
}
#endif

#ifdef LOCAL // Local testing. Nothing solution related

bool checkCase(const vector<string>& ok, const vector<string>& my)
{
	bool bSuccess = ok.size() == my.size();
	if(bSuccess)
	{
		for(size_t i=0; i<ok.size(); ++i)
			if(ok[i] != my[i])
				bSuccess = false;
	}

	cout << (bSuccess ? "Passed" : "Failed") << endl;
	if(!bSuccess)
	{
		bool newLine = ok.size() != 1 || my.size() != 1;
		cout << "expected: "; if(newLine) { cout << endl; }
		for(size_t i=0; i<ok.size(); ++i) { cout << ok[i] << endl; }
		cout << "actual  : "; if(newLine) { cout << endl; }
		for(size_t i=0; i<my.size(); ++i) { cout << my[i] << endl; }
	}
	return bSuccess;
}

vector<string> readFile(istream& s)
{
	vector<string> res; string str;
	while (s && !s.eof())
	{
		getline(s, str);
		if(str.find("--case") == 0)
			break;
		res.push_back(str);
	}
	if(res.size() > 0 && res.back().empty())
		res.resize(res.size()-1);
	return res;
}

vector<string> readFile(const string str)
{
	istringstream ssStr(str);
	return readFile(ssStr);
}

string joinLines(const vector<string>& lines)
{
	ostringstream res;
	for(size_t i=0; i<lines.size(); ++i)
		res << lines[i] << endl;
	return res.str();
}

void main(int argc, char *argv[])
{
	string pathToFiles = __FILE__;
	pathToFiles.resize(pathToFiles.size() - 4);
	ifstream sIn(pathToFiles + ".in.txt");
	ifstream sOk(pathToFiles + ".ok.txt");
	ofstream sMy(pathToFiles + ".my.txt");

	int index = 0; bool bPassed = true;
	while(sIn)
	{
		++index;
		vector<string> aIn(readFile(sIn)), aOk(readFile(sOk));
		istringstream ssIn(joinLines(aIn));
		ostringstream ssMy;

		cout << "Case " << index << ": ... ";
		Runner runner(ssIn, ssMy);
		runner.Run();

		vector<string> aMy(readFile(ssMy.str()));
		if(!checkCase(aOk, aMy))
			bPassed = false;
		if(index > 1)
			sMy << "--case " << index << endl;
		sMy << joinLines(aMy).c_str();
	}
	cout << "Tests: " << (bPassed ? "Passed" : "Failed") << endl;
	getchar();
}
#endif	// LOCAL


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <limits>
using namespace std;

// Types
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int,int> ipair;
const double pi=acos(-1.0);
const double eps=1e-11;

// Generic
#define SIZE(X) ((int)(X.size()))
#define LENGTH(X) ((int)(X.length()))
#define MP(X,Y) make_pair(X,Y)
#define FORD(i, a, b) for(int i=(a); i<(b); i++)
#define FORS(i, a) for(int i=(0); i<SIZE(a); i++)
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
template<class T> inline T sqr(T x){return x*x;}

// Bit manipulation
template<class T> void setbit(T& v, int position)    { v |= (T)1 << position; }
template<class T> void unsetbit(T& v, int position)  { v &= ~((T)1 << position); }
template<class T> void togglebit(T& v, int position) { v ^= (T)1 << position; }
template<class T> bool isbit(T v, int position) { return (v & ((T)1 << position)) != 0; }
template<class T> inline int countbit(T n){return (n==0)?0:(1+countbit(n&(n-1)));}

// Input / Output
string ReadToEndLine(istream& s) { string sLine; getline(s, sLine); return sLine; }
char gStr[1024];
// sprintf_s(gStr, "%d", );

struct Runner
{
	Runner(istream& in, ostream& out) : mIn(in), mOut(out) {}
	void Run();
	istream& mIn; ostream& mOut;
};

void Runner::Run()
{
	int K;
	vector<int> N(3);
	vector<int> T(3);
	mIn >> K >> N[0] >> N[1] >> N[2] >> T[0] >> T[1] >> T[2];

	int Need = K;
	set<int> Times;
	Times.insert(0);
	deque<pair<int, int>> Q; // Count, time
	int now;
	while(!Times.empty() && Need > 0)
	{
		now = *Times.begin();
		Times.erase(Times.begin());

		while(Q.front().second + T[0]+T[1]+T[2] <= now)
			Q.pop_front();

		int n0 = N[0], n1 = N[1], n2 = N[2];
		FORS(i, Q)
		{
			int cnt = Q[i].first;
			int start = Q[i].second;
			int elapse = now-start;

			if(elapse <T[0])
				n0-=cnt;
			if(elapse < T[1])
				n1-=cnt;
			if(elapse < T[2])
				n2-=cnt;
		}

		int can = max(0, min(n0, min(n1, n2)));
		if(can == 0)
			continue;

		can = min(can, Need);
		Need-=can;
		Q.push_back(MP(can, now));
		Times.insert(now+T[0]);
		Times.insert(now+T[1]);
		Times.insert(now+T[2]);
	}
	mOut << Q.back().second+T[0]+T[1]+T[2];
}

#ifndef LOCAL
int main()
{
	Runner runner(cin, cout);
	runner.Run();
	return 0;
}
#endif

#ifdef LOCAL // Local testing. Nothing solution related

bool checkCase(const vector<string>& ok, const vector<string>& my)
{
	bool bSuccess = ok.size() == my.size();
	if(bSuccess)
	{
		for(size_t i=0; i<ok.size(); ++i)
			if(ok[i] != my[i])
				bSuccess = false;
	}

	cout << (bSuccess ? "Passed" : "Failed") << endl;
	if(!bSuccess)
	{
		bool newLine = ok.size() != 1 || my.size() != 1;
		cout << "expected: "; if(newLine) { cout << endl; }
		for(size_t i=0; i<ok.size(); ++i) { cout << ok[i] << endl; }
		cout << "actual  : "; if(newLine) { cout << endl; }
		for(size_t i=0; i<my.size(); ++i) { cout << my[i] << endl; }
	}
	return bSuccess;
}

vector<string> readFile(istream& s)
{
	vector<string> res; string str;
	while (s && !s.eof())
	{
		getline(s, str);
		if(str.find("--case") == 0)
			break;
		res.push_back(str);
	}
	if(res.size() > 0 && res.back().empty())
		res.resize(res.size()-1);
	return res;
}

vector<string> readFile(const string str)
{
	istringstream ssStr(str);
	return readFile(ssStr);
}

string joinLines(const vector<string>& lines)
{
	ostringstream res;
	for(size_t i=0; i<lines.size(); ++i)
		res << lines[i] << endl;
	return res.str();
}

void main(int argc, char *argv[])
{
	string pathToFiles = __FILE__;
	pathToFiles.resize(pathToFiles.size() - 4);
	ifstream sIn(pathToFiles + ".in.txt");
	ifstream sOk(pathToFiles + ".ok.txt");
	ofstream sMy(pathToFiles + ".my.txt");

	int index = 0; bool bPassed = true;
	while(sIn)
	{
		++index;
		vector<string> aIn(readFile(sIn)), aOk(readFile(sOk));
		istringstream ssIn(joinLines(aIn));
		ostringstream ssMy;

		cout << "Case " << index << ": ... ";
		Runner runner(ssIn, ssMy);
		runner.Run();

		vector<string> aMy(readFile(ssMy.str()));
		if(!checkCase(aOk, aMy))
			bPassed = false;
		if(index > 1)
			sMy << "--case " << index << endl;
		sMy << joinLines(aMy).c_str();
	}
	cout << "Tests: " << (bPassed ? "Passed" : "Failed") << endl;
	getchar();
}
#endif	// LOCAL


//#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <map>
#include <set>
#include <queue>
#include <memory.h>
#include <time.h>
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <cassert>
#include <climits>
#include <deque>
#include <limits>
#define sz(x) int((x).size())
#define FOR(i,a,b) for(ll(i) = (a); (i) <= (b); ++(i))
#define ROF(i,a,b) for(ll(i) = (a); (i) >= (b); --(i))
#define rep(i,n) for (int(i) = 0; (i) < (n); ++(i))
#define fe(i,a) for (ll(i) = 0; (i) < int((a).size()); ++(i))
#define C(a) memset((a),0,sizeof(a))
#define pb push_back
#define ppb pop_back
#define all(c) (c).begin(), (c).end()
#define sqr(a) (a)*(a)
#define mp(a,b) make_pair((a), (b))
#define X first
#define Y second
#define file freopen("input.txt","r",stdin)
#define file2 freopen("output.txt", "w",stdout)
#define text freopen("input.txt","r",stdin); freopen("output.txt", "w",stdout)
using namespace std;
typedef vector<int> vint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define y1 vamdlsfmvldf
const int mod = (int)1e9 + 7;
const int inf = (int)(1e9);
const int N = 100005;
int k, t[3], n[3];
int res = 0;
multiset<int> S[3];
int main(void){
    cin >> k >> n[0] >> n[1] >> n[2] >> t[0] >> t[1] >> t[2];
    rep(i, n[0]) S[0].insert(0);
    rep(i, n[1]) S[1].insert(0);
    rep(i, n[2]) S[2].insert(0);
    rep(i, k){
        int mx = 0;
        int add = 0;
        rep(j, 3){
            mx = max(mx, (*S[j].begin()) - add);
            add += t[j];
        }
        rep(j, 3){
            mx += t[j];
            S[j].erase(S[j].begin());
            S[j].insert(mx);
        }
    }
    cout << (*S[2].rbegin()) << endl;
    return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <memory.h>

using namespace std;

#pragma comment(linker, "/STACK:128000000")

typedef pair<int, int> pii;
typedef long long int64;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

int n;
int a, b, c;
int64 x, y, z;

vector <int64> A;

inline void run(vector <int64> &A, int m, int64 t)
{
    priority_queue < int64, vector<int64>, greater<int64> > Q;
    for (int i = 0; i < m; ++i)
        Q.push(0LL);
    for (int i = 0; i < n; ++i)
    {
        int64 cur = Q.top();
        Q.pop();
        int64 T = max(cur, A[i]);
        Q.push(T + t);
        A[i] = T + t;
    }
}

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

    cin >> n >> a >> b >> c >> x >> y >> z;

    for (int i = 0; i < n; ++i)
        A.push_back(0);

    run(A, a, x);
    run(A, b, y);
    run(A, c, z);

    cout << A[n - 1] << endl;

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:16777216")
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))

#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
#define Pi 3.14159265358979
#define M_PI acos(-1.0)

typedef long long Int;
typedef unsigned long long UINT;
typedef vector <int> VI;
typedef pair <int, int> PII;

const int INF = 1000000000;
const int MAX = 1024;
const int MAX2 = 7000;
const int BASE = 1000000000;

int k;
int n1, n2, n3;
int t1, t2, t3;
multiset<int> S1;
multiset<int> S2;
multiset<int> S3;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
    #endif

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

    FOR (i,0,n1)
        S1.insert(-INF);
    FOR (i,0,n2)
        S2.insert(-INF);
    FOR (i,0,n3)
        S3.insert(-INF);

    int cur = 0;
    int last = 0;
    FOR (i,0,k)
    {
        int v1 = *S1.begin();
        int v2 = *S2.begin();
        int v3 = *S3.begin();
        int t = -INF;
        t = max(t, v1);
        t = max(t, v2-t1);
        t = max(t, v3-t1-t2);
        t = max(t, cur);
        cur = t;
        S1.erase(S1.begin());
        S1.insert(t+t1);
        S2.erase(S2.begin());
        S2.insert(t+t1+t2);
        S3.erase(S3.begin());
        S3.insert(t+t1+t2+t3);
    }
    printf("%d\n", cur+t1+t2+t3);

    return 0;
}


#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <fstream>
#include <string>
#include <cmath>
#include <queue>
#include <ctime>
#include <functional>
#include <hash_set>

using namespace std;

#define INF 1000000
#define MX 1000

int indx_min(vector<int>& a)
{
	int mn = a[0], indx = 0;
	for(int i = 1; i < a.size(); i++)
		if(a[i] < mn)
		{
			mn = a[i];
			indx = i;
		}
	return indx;
}

int main()
{
	//freopen("INPUT.TXT","r",stdin); freopen("OUTPUT.TXT","w",stdout);
	int k, t1, t2, t3, n1, n2, n3;
	cin>>k>>n1>>n2>>n3>>t1>>t2>>t3;
	vector<int> a1(n1, 0), a2(n2, 0), a3(n3, 0);
	int res = 0;
	while(k--)
	{
		int indx1 = indx_min(a1), indx2 = indx_min(a2), indx3 = indx_min(a3);
		int start2 = max(a2[indx2], a3[indx3] - t2);
		int start1 = max(a1[indx1], start2 - t1);
		a1[indx1] = start1 + t1;
		a2[indx2] = a1[indx1] + t2;
		a3[indx3] = a2[indx2] + t3;
		res = max(res, a3[indx3]);
	}
	cout<<res<<endl;
}


#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int dat[11000000][3];
int n[3], t[3];
int main()
{
	int num;
	scanf("%d", &num);
	scanf("%d%d%d%d%d%d", &n[0], &n[1], &n[2], &t[0], &t[1], &t[2]);
	int pt = 0;
	for (int i = 0; i < num; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			for (int k = 0; k < t[j]; k++)dat[pt + k][j]++;
		}
		for (;;)
		{
			bool f = false;
			for (int k = 0; k < 3; k++)
			{
				if (dat[pt][k] == n[k])
				{
					pt++;
					f = true;
					break;
				}
			}
			if (!f)break;
		}
	}
	int maxi = 0;
	for (int i = 0; i < 11000000; i++)
	{
		if (dat[i][0])maxi = max(maxi, i + 1);
		if (dat[i][1])maxi = max(maxi, i + 1 + t[0]);
		if (dat[i][2])maxi = max(maxi, i + 1 + t[0] + t[1]);
	}
	printf("%d\n", maxi);
}


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

typedef long long ll;
typedef pair<int, int> P;

int N;
int bit1[11000001], bit2[11000001], bit3[11000001];

int sum(int bit[], int i) {
	int res = 0;
	while (i > 0) {
		res += bit[i];
		i -= i & -i;
	}
	return res;
}

void add(int bit[], int i, int x) {
	while (i <= 11000000) {
		bit[i] += x;
		i += i & -i;
	}
}

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);
	int t = 1;
	for (; k > 0; k--) {
		int lb = t - 1, ub = 10000000;
		while (ub - lb > 1) {
			int mid = (lb + ub) / 2;
			if (sum(bit1, mid) < n1 && sum(bit2, mid + t1) < n2 && sum(bit3, mid + t1 + t2) < n3)
				ub = mid;
			else
				lb = mid;
		}
		t = ub;
		add(bit1, t, 1);
		add(bit1, t + t1, -1);
		add(bit2, t + t1, 1);
		add(bit2, t + t1 + t2, -1);
		add(bit3, t + t1 + t2, 1);
		add(bit3, t + t1 + t2 + t3, -1);
	}
	printf("%d\n", t + t1 + t2 + t3 - 1);
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:128000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>

using namespace std;
#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const long double PI = 3.14159265358979323846;
const long double gammama = 0.57721566490153286060;
//const long double eps = 1e-5;
const int INF = 1000 * 1000 * 1000;
//const int N = 1000 * 1000 * 1000 + 10;
const int mod = 1000 * 1000 * 1000 + 7;

int main() {
	//ios_base::sync_with_stdio(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int k, n1, n2, n3, t1, t2, t3;
	cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;
	queue<int> q1, q2, q3;
	int t = 0;
	for (int i = 0; i < k; ++i) {
		if (q1.size() == n1) {
			t = max(t, q1.front());
			q1.pop();
		}
		if (q2.size() == n2) {
			t = max(t, q2.front() - t1);
			q2.pop();
		}
		if (q3.size() == n3) {
			t = max(t, q3.front() - t1 - t2);
			q3.pop();
		}
		q1.push(t + t1);
		q2.push(t + t1 + t2);
		q3.push(t + t1 + t2 + t3);
	}
	cout << q3.back() << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <utility>

using namespace std;

enum {MAXN = 100050};

#define pb push_back

long long k, n[3], t[3];
set <pair <long long, long long> > m[3];

int main()
{
    cin >> k >> n[0] >> n[1] >> n[2] >> t[0] >> t[1] >> t[2];
    long long time, nk = k;

    for (time = 0; time <= k * (t[0] + t[1] + t[2]); time++) {
        while(m[2].size() > 0 && m[2].begin()->first <= time)
            m[2].erase(*m[2].begin());
        while (m[2].size() < n[2] && m[1].size() > 0 && m[1].begin()->first <= time) {
                m[2].insert(make_pair(time + t[2], m[1].begin()->second));
                m[1].erase(*m[1].begin());

        }
        while (m[1].size() < n[1] && m[0].size() > 0 && m[0].begin()->first <= time) {
                m[1].insert(make_pair(time + t[1], m[0].begin()->second));
                m[0].erase(*m[0].begin());
        }
        while (nk > 0 && m[0].size() < n[0]) {
            m[0].insert(make_pair(time + t[0], nk));
            nk--;
        }
        if (nk == 0 && m[0].size() == 0 && m[1].size() == 0 && m[2].size() == 0)
            break;
    }
    cout << time;
    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <utility>

using namespace std;

enum {MAXN = 100050};

#define pb push_back

long long k, n[3], t[3];
set <pair <long long, long long> > m[3];

int main()
{
    cin >> k >> n[0] >> n[1] >> n[2] >> t[0] >> t[1] >> t[2];
    long long time, nk = k;

    for (time = 0; time <= k * (t[0] + t[1] + t[2]); time++) {
        while(m[2].size() > 0 && m[2].begin()->first <= time)
            m[2].erase(*m[2].rbegin());
        while (m[2].size() < n[2] && m[1].size() > 0 && m[1].begin()->first <= time) {
                m[2].insert(make_pair(time + t[2], m[1].begin()->second));
                m[1].erase(*m[1].begin());

        }
        while (m[1].size() < n[1] && m[0].size() > 0 && m[0].begin()->first <= time) {
                m[1].insert(make_pair(time + t[1], m[0].begin()->second));
                m[0].erase(*m[0].begin());
        }
        while (nk > 0 && m[0].size() < n[0]) {
            m[0].insert(make_pair(time + t[0], nk));
            nk--;
        }
        if (nk == 0 && m[0].size() == 0 && m[1].size() == 0 && m[2].size() == 0)
            break;
    }
    cout << time;
    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <utility>

using namespace std;

enum {MAXN = 100050};

#define pb push_back

int k, n[3], t[3];
set <pair <int, int> > m[3];

int main()
{
	cin >> k >> n[0] >> n[1] >> n[2] >> t[0] >> t[1] >> t[2];
	int time, nk = k;

	for (time = 0; time <= k * (t[0] + t[1] + t[2]); time++) {
		while(m[2].size() > 0 && m[2].begin()->first <= time)
			m[2].erase(*m[2].rbegin());
		while (m[2].size() < n[2] && m[1].size() > 0 && m[1].begin()->first <= time) {
				m[2].insert(make_pair(time + t[2], m[1].begin()->second));
				m[1].erase(*m[1].begin());

		}
		while (m[1].size() < n[1] && m[0].size() > 0 && m[0].begin()->first <= time) {
				m[1].insert(make_pair(time + t[1], m[0].begin()->second));
				m[0].erase(*m[0].begin());
		}
		while (nk > 0 && m[0].size() < n[0]) {
			m[0].insert(make_pair(time + t[0], nk));
			nk--;
		}
		if (nk == 0 && m[0].size() == 0 && m[1].size() == 0 && m[2].size() == 0)
			break;
	}
	cout << time;
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
//#pragma comment(linker, "/STACK:200000000")

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <limits>
#include <cassert>
#include <ctime>
#include <list>
#include <bitset>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <complex>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

template<typename T> inline T Abs(T a){ return a>0 ? a : -a; }
template<typename T> inline T sqr(T a){ return a*a; }
template<typename T> inline void relaxMin(T &a,T b){ if (b<a) a=b; }
template<typename T> inline void relaxMax(T &a,T b){ if (b>a) a=b; }

#define _(a,val) memset(a,val,sizeof a);
#define REP(i, a, b) for(int i(a),_bb(b); i < _bb; ++i)
//#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define REPD(i, a, b) for(int i = (b) - 1; i >= a; --i)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()

const int INF = (int)1E9;
//const int INF = INT_MAX/2-1;
const long double EPS = 1E-6;
const long double PI = 3.1415926535897932384626433832795;
#define y1 idfgoseincdjkg
typedef vector<int> vint;
typedef pair<int,int> pii;

#undef assert
#define assert(expr){if (!(expr)) { ++*(char*)0; } }

set<pii> q1,q2,q3;
int t1[1000],t2[1000],t3[1000];

void solve(){
	int k,n1,n2,n3,dt1,dt2,dt3;
	cin>>k>>n1>>n2>>n3>>dt1>>dt2>>dt3;

	REP(i,0,n1) q1.insert(mp(t1[i],i));
	REP(i,0,n2) q2.insert(mp(t2[i],i));
	REP(i,0,n3) q3.insert(mp(t3[i],i));

	int ans = 0;

	REP(w,0,k){
		pii qt1 = *q1.begin(); q1.erase(q1.begin());
		pii qt2 = *q2.begin(); q2.erase(q2.begin());
		pii qt3 = *q3.begin(); q3.erase(q3.begin());
		int te = dt3 + max(qt3.first,max(qt2.first+dt2,qt1.first+dt2+dt1));
		ans=max(ans,te);
		t1[qt1.second] = max(0,te - dt2 - dt3);
		t2[qt2.second] = max(0,te - dt3);
		t3[qt3.second] = max(0,te);
		q1.insert(mp(t1[qt1.second],qt1.second));
		q2.insert(mp(t2[qt2.second],qt2.second));
		q3.insert(mp(t3[qt3.second],qt3.second));
	}
	cout<<ans<<endl;
}

#define TASK ""
int main(){
	//freopen("input.txt", "wt", stdout);
	//freopen("input.txt", "wt", stdin);
#ifdef acm
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
	freopen("error.txt", "wt", stderr);
#else
	//freopen("input.txt", "rt", stdin);
	//freopen("output.txt", "wt", stdout);
	//freopen(TASK".in", "rt", stdin);
	//freopen(TASK".out", "wt", stdout);
#endif
	//srand(time(0));
	//srand(0xA1B2C3D4);

	solve();

#ifdef acm
	//printf("\n\n\n\n\n%.3lf\n", clock()*1e-3);
#endif
	return 0;
}


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

#define MAXN 1002
int tm1[MAXN], tm2[MAXN], tm3[MAXN], n, k1, k2, k3, t1, t2, t3;

int calc()
{
    int i;
    int tmp;

    for(i=1;i<=n;i++)
    {
        tmp = (i>k1)?tm1[i-k1]:0;
        tm1[i] = tmp + t1;
    }
    for(i=1;i<=n;i++)
    {
        tmp = (i>k2)?tm2[i-k2]:0;
        tm2[i] = max(tmp, tm1[i]) + t2;
    }
    for(i=1;i<=n;i++)
    {
        tmp = (i>k3)?tm3[i-k3]:0;
        tm3[i] = max(tmp, tm2[i]) + t3;
    }
    return tm3[n];
}

int main()
{
    while(scanf("%d%d%d%d%d%d%d",&n,&k1,&k2,&k3,&t1,&t2,&t3)!=EOF)
    {
        printf("%d\n",calc());
    }
    return 0;
}


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

#define MAXN 10005
int tm1[MAXN], tm2[MAXN], tm3[MAXN], n, k1, k2, k3, t1, t2, t3;

int calc()
{
    int i;
    int tmp;

    for(i=1;i<=n;i++)
    {
        tmp = (i>k1)?tm1[i-k1]:0;
        tm1[i] = tmp + t1;
    }
    for(i=1;i<=n;i++)
    {
        tmp = (i>k2)?tm2[i-k2]:0;
        tm2[i] = max(tmp, tm1[i]) + t2;
    }
    for(i=1;i<=n;i++)
    {
        tmp = (i>k3)?tm3[i-k3]:0;
        tm3[i] = max(tmp, tm2[i]) + t3;
    }
    return tm3[n];
}

int main()
{
    while(scanf("%d%d%d%d%d%d%d",&n,&k1,&k2,&k3,&t1,&t2,&t3)!=EOF)
    {
        printf("%d\n",calc());
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
using namespace std;
typedef long long Int;
int n[3],t[3],k;
int dp[10005];
int main()
{
	scanf("%d",&k);
	for(int i=0;i<3;i++)scanf("%d",n+i);
	for(int i=0;i<3;i++)scanf("%d",t+i);
	for(int i=1;i<=k;i++)
        for(int j=0;j<3;j++)
           if(i>n[j])
           	  dp[i]=max(dp[i],dp[i-n[j]]+t[j]);
    printf("%d\n",dp[k]+t[0]+t[1]+t[2]);
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
using namespace std;
typedef long long Int;
int n[3],t[3],k;
int dp[3],cnt[3];
int main()
{
	scanf("%d",&k);
	for(int i=0;i<3;i++)scanf("%d",n+i);
	for(int i=0;i<3;i++)scanf("%d",t+i);
	for(int i=1;i<=k;i++)
    {
    	cnt[0]++;
    	if(cnt[0]>n[0])
		{
		  dp[0]+=t[0];
		  cnt[0]=1;
	    }
	    for(int j=1;j<3;j++)
	    {
	    	int temp=dp[j-1]+t[j-1];
	    	if(temp>dp[j]){cnt[j]=1;dp[j]=temp;}
	    	else
	    	{
	    		dp[j]=dp[j-1]+t[j-1];
	    		cnt[j]++;
	    		if(cnt[j]>n[j])
	    		{
	    			cnt[j]=1;
	    			dp[j]+=t[j];
				}
			}
		}

	}printf("%d\n",dp[2]+t[2]);
}


#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1000000007;
const int N = 1e5 + 10;
priority_queue<int,vector<int>, greater<int>> q1, q2, q3;
vector<int> v;
int main()
{
    //freopen("input.txt", "r", stdin);
    int k;
    int n1, n2, n3;
    int t1, t2, t3;
    cin >> k;
    cin >> n1 >> n2 >> n3;
    cin >> t1 >> t2 >> t3;
    v.resize(k,0);
    for (int i = 0; i < k; i++)
    {
        if (q1.size() < n1) q1.push(v[i] + t1), v[i] = v[i] + t1;
        else
        {
            int x = q1.top();
            q1.pop();
            if (x < v[i]) q1.push(v[i] + t1), v[i] += t1;
            else q1.push(x + t1), v[i] = x+t1;
        }
    }
    for (int i = 0; i < k; i++)
    {
        if (q2.size() < n2) q2.push(v[i] + t2), v[i] = v[i] + t2;
        else
        {
            int x = q2.top();
            q2.pop();
            if (x < v[i]) q2.push(v[i] + t2), v[i] += t2;
            else q2.push(x + t2), v[i] = x+t2;
        }
    }
    for (int i = 0; i < k; i++)
    {
        if (q3.size() < n3) q3.push(v[i] + t3), v[i] = v[i] + t3;
        else
        {
            int x = q3.top();
            q3.pop();
            if (x < v[i]) q3.push(v[i] + t3), v[i] += t3;
            else q3.push(x + t3), v[i] = x+t3;
        }
    }
    int ans = 0;
    for (int i = 0; i < v.size(); i++) ans = max(ans, v[i]);
    cout << ans << endl;
    return 0;
}


										/* in the name of Allah */
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <list>
#include <map>
#include <set>

using namespace std;

#define uint unsigned int
#define int64 long long
#define P pair<int, int>
#define Pss pair<string, string>
#define PLL pair<int64, int64>
#define Inf 1000000
#define Mod 1000000007LL

int k, n[3], t[3];
priority_queue <int> q[3];

int main(){
	cin >> k;
	for(int i = 0; i < 3; i++){
		cin >> n[i];
		for(int j = 0; j < n[i]; j++)
			q[i].push(0);
	}
	for(int i = 0; i < 3; i++)
		cin >> t[i];
	int res = 0;
	for(int i = 0; i < k; i++){
		int t2 = -q[2].top();
		q[2].pop();
		int t1 = max(t2 - t[1], -q[1].top());
		q[1].pop();
		int t0 = max(t1 - t[0], -q[0].top());
		q[0].pop();

		q[0].push(-(t0 + t[0]));
		q[1].push(-(t0 + t[0] + t[1]));
		q[2].push(-(t0 + t[0] + t[1] + t[2]));
		res = t0 + t[0] + t[1] + t[2];
	}
	cout << res << endl;
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <complex>
#include <ctime>
#include <iomanip>
#include <cassert>
#include <sstream>
#include <iterator>

using namespace std;

#define file "file"
#define mp make_pair
#define pb push_back
#define xx real()
#define yy imag()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef complex<double> point;

void solve(){
	int k,n1,n2,n3,t1,t2,t3;
	cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;
	set<pair<ll,int> > q1,q2,q3;
	int cur = 0;
	for(int i = 0;i < n1;i++){
		q1.insert(mp(0ll,i));
	}
	for(int i = 0;i < n2;i++){
		q2.insert(mp(0ll,i));
	}
	for(int i = 0;i < n3;i++){
		q3.insert(mp(0ll,i));
	}
	ll mx = 0;
	for(int i = 0;i < k;i++){
		pair<ll,int> p1 = *q1.begin();
		pair<ll,int> p2 = *q2.begin();
		pair<ll,int> p3 = *q3.begin();
		q1.erase(q1.begin());
		q2.erase(q2.begin());
		q3.erase(q3.begin());
		ll v1 = p1.first,v2 = p2.first,v3 = p3.first;
		v2 = max(v1 + t1,v2);
		v3 = max(v2 + t2,v3);
		mx = max(mx,v3 + t3);
		q1.insert(mp(v1 + t1,p1.second));
		q2.insert(mp(v2 + t2,p2.second));
		q3.insert(mp(v3 + t3,p3.second));
	}
	cout << mx;
}

int main()
{
	//assert(freopen(file".in","r",stdin)); assert(freopen(file".out","w",stdout));
	#ifndef ONLINE_JUDGE
	assert(freopen("input.txt","r",stdin));
	assert(freopen("output.txt","w",stdout));
	#endif
	int t = 1;
	while(t--){
		solve();
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

struct pr
{
    int tp, tm;
    pr(int tpe = 0, int tme = 0) : tp(tpe), tm(tme){}

    bool operator<(const pr& p) const
    {
        return tm > p.tm;
    }
};

int main()
{
    int k, nw, nd, ni, tw, td, ti;
    scanf("%d%d%d%d%d%d%d", &k, &nw, &nd, &ni, &tw, &td, &ti);

    priority_queue<pr> q;
    int ww = k, dd = 0, ii = 0;
    int aw = nw, ad = nd, ai = ni;
    int mx = 0;
    while (ww > 0 && aw > 0)
    {
        ww--, aw--;
        q.push(pr(0, tw));
    }
    while(!q.empty())
    {
        int tm = q.top().tm;
        while(!q.empty() && q.top().tm == tm)
        {
            //cerr<<q.top().tp<<" "<<q.top().tm<<endl;
            if(q.top().tp == 0)
                dd++, aw++;
            else if(q.top().tp == 1)
                ii++, ad++;
            else if(q.top().tp == 2)
                ai++;
            q.pop();
        }
        while(ww > 0 && aw > 0)
        {
            ww--, aw--;
            q.push(pr(0, tm + tw));
        }
        while(dd > 0 && ad > 0)
        {
            dd--, ad--;
            q.push(pr(1, tm + td));
        }
        while(ii > 0 && ai > 0)
        {
            ii--, ai--;
            q.push(pr(2, tm + ti));
        }
        mx = tm;
    }

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

    return 0;
}


#include <cassert>
#include <cstdio>
#include <math.h>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <queue>

using namespace std;
#define _CRT_SECURE_NO_WARNINGS
#define M_PI       3.14159265358979323846
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int (i) = (a); (i) < (b); ++(i))
#define FORE(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define y1 wrddsds
#define LL long long
#define MAXN 1000
#define MOD 1000000009L

int k, n1, n2, n3, t1, t2, t3;
int a[MAXN], b[MAXN], c[MAXN];

int findMinIndex(int a[MAXN], int cnt, int constraint){
	int min = INT_MAX;
	int mini = -1;
	FOR(i, 0, cnt){
		if (a[i] < min){
			min = a[i];
			mini = i;
		}
	}
	return mini;
}

int main() {
	cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;
	int time = 0;
	FOR(i, 0, k) {
		int index1 = findMinIndex(a, n1, 0);
		int index2 = findMinIndex(b, n2, 0);
		int index3 = findMinIndex(c, n3, 0);

		int time = a[index1];
		if (time + t1 < b[index2])
			time = b[index2] - t1;
		if (time + t1 + t2 < c[index3])
			time = c[index3] - t2 - t1;
		//cout << "start time is " << time << endl;
		a[index1] = time + t1;
		b[index2] = time + t1 + t2;
		c[index3] = time + t1 + t2 + t3;
	}
	cout << *std::max_element(c, c + n3) << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

const int SZ = (int)3e7 + 10;
int cnt[SZ];
int n[3], t[3], sum[3];

int main()
{
	int k;
	cin >> k;
	for (int i = 0; i < 3; i++)
		cin >> n[i];
	for (int i = 0; i < 3; i++)
		cin >> t[i];
	for (int i = 0; i < 3; i++)
		sum[i] = 0;

	for (int tme = 0;; tme++)
	{
		int mn = k;
		for (int s = 0; s < 3; s++)
		{
			mn = min(mn, n[s] - sum[s]);
		}
		cnt[tme] = mn;
		k -= mn;
		if (k == 0)
		{
			printf("%d", tme + t[0] + t[1] + t[2]);
			return 0;
		}
		for (int s = 0; s < 3; s++)
		{
			sum[s] += mn;
			if (tme - t[s] + 1 >= 0)
				sum[s] -= cnt[tme - t[s] + 1];
		}
	}

	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>

using namespace std;

int n, m;

int main()
{
    //freopen("input.txt","r",stdin);
    int k, n1, n2, n3, t1, t2, t3;
    cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;

    multiset<long long> ot, free_gl, free_ot, gl;

    long long t = 0;
    long long ost = k;
    for(;ost>0;)
    {
        for(int i=1; i<=n1 && ost>0; i++)
        {
            ot.insert(t + t1);
            ost--;
        }
        t += t1;
    }

    for(int i=0; i<n2 && ot.size()>0; i++)
    {
        long long f = (*ot.begin());
        ot.erase(ot.begin());
        free_ot.insert(f);
    }

    while(!ot.empty())
    {
        long long f = *ot.begin();
        long long s = *free_ot.begin();

        free_ot.erase(free_ot.begin());
        ot.erase(ot.begin());

        gl.insert(s + t2);
        free_ot.insert(max(s + t2, f));
    }

    while(!free_ot.empty())
    {
        long long f = *free_ot.begin();
        free_ot.erase(free_ot.begin());
        gl.insert(f + t2);
    }

    for(int i=0; i<n3 && gl.size() > 0; i++)
    {
        long long f = *gl.begin();
        gl.erase(gl.begin());
        free_gl.insert(f);
    }

    while(!gl.empty())
    {
        long long f = *gl.begin();
        long long s = *free_gl.begin();

        free_gl.erase(free_gl.begin());
        gl.erase(gl.begin());

        free_gl.insert(max(s + t3, f));
    }

    long long ans = 0;
    while(!free_gl.empty())
    {
        long long f = *free_gl.begin() + t3;
        free_gl.erase(free_gl.begin());
        ans = max(ans, f);
    }

    cout << ans;

    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>

using namespace std;

int n, m;

int main()
{
    //freopen("input.txt","r",stdin);
    int k, n1, n2, n3, t1, t2, t3;
    cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;

    multiset<long long> ot, free_gl, free_ot, gl;

    long long t = 0;
    long long ost = k;
    for(;ost>0;)
    {
        for(int i=1; i<=n1 && ost>0; i++)
        {
            ot.insert(t + t1);
            ost--;
        }
        t += t1;
    }

    for(int i=0; i<n2; i++)
    {
        long long f = (*ot.begin());
        ot.erase(ot.begin());
        free_ot.insert(f);
    }

    while(!ot.empty())
    {
        long long f = *ot.begin();
        long long s = *free_ot.begin();

        free_ot.erase(free_ot.begin());
        ot.erase(ot.begin());

        gl.insert(s + t2);
        free_ot.insert(max(s + t2, f));
    }

    while(!free_ot.empty())
    {
        long long f = *free_ot.begin();
        free_ot.erase(free_ot.begin());
        gl.insert(f + t2);
    }

    for(int i=0; i<n3; i++)
    {
        long long f = *gl.begin();
        gl.erase(gl.begin());
        free_gl.insert(f);
    }

    while(!gl.empty())
    {
        long long f = *gl.begin();
        long long s = *free_gl.begin();

        free_gl.erase(free_gl.begin());
        gl.erase(gl.begin());

        free_gl.insert(max(s + t3, f));
    }

    long long ans = 0;
    while(!free_gl.empty())
    {
        long long f = *free_gl.begin() + t3;
        free_gl.erase(free_gl.begin());
        ans = max(ans, f);
    }

    cout << ans;

    return 0;
}


#include<iostream>

using namespace std;

int main()
{

    int k, n1, n2, n3, t1, t2, t3;
    int dp[1000000];

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

     for(int i=0;i<k;i++)
     {

     if(i>=n1)
        dp[i]=max(dp[i],dp[i-n1]+t1);
     if(i>=n2)
        dp[i]=max(dp[i],dp[i-n2]+t2);
     if(i>=n3)
        dp[i]=max(dp[i],dp[i-n3]+t3);

     }

    cout << dp[k-1]+t1+t2+t3;

    return 0 ;
}


#include <iostream>
#include <queue>
#include <vector>
#include <math.h>

using namespace std;

class compare {
public:
	bool operator() (int a, int b) {
		return a > b;
	}

};

void main() {
	priority_queue<int, vector<int>, compare > washer;
	priority_queue<int, vector<int>, compare > drier;
	priority_queue<int, vector<int>, compare > planer;

	int k, n1,n2,n3, t1,t2,t3;
	cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;
	for (int i = 0; i < n1; ++i) {
		washer.push(0);
	}
	for (int i = 0; i < n2; ++i) {
		drier.push(0);
	}
	for (int i = 0; i < n3; ++i) {
		planer.push(0);
	}
	int current = 0;
	int m1,m2,m3;
	while (k > 0) {
		m1 = washer.top();
		m2 = drier.top();
		m3 = planer.top();
		int newtime = max(current,
					  max(m1,
				      max(m2 - t1,
						  m3 - t1 - t2)));
		m1 = newtime + t1;
		m2 = newtime + t1 + t2;
		m3 = newtime + t1 + t2 + t3;

		washer.pop();
		drier.pop();
		planer.pop();

		washer.push(m1);
		drier.push(m2);
		planer.push(m3);

		current = newtime;
		--k;
	}
	int maxtime = current;
	while (!planer.empty()) {
		maxtime = max(maxtime, planer.top());
		planer.pop();
	}

	cout << maxtime;

//	system("pause");

}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef long double ld;
const int size = 1007;
const ll modulo = 1000000007;
const ll oo = 2e18;
const double EPS = 1e-12;
const double PI = acos(-1.0);

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll k, n1, n2, n3, h1, h2, h3;
	cin >> k >> n1 >> n2 >> n3 >> h1 >> h2 >> h3;
	multiset<ll> s1, s2, s3;
	while (n1--) s1.insert(0);
	while (n2--) s2.insert(0);
	while (n3--) s3.insert(0);
	ll ans = 0;
	while (k--)
	{
		ll g1 = *(s1.begin()), g2 = *(s2.begin()), g3 = *(s3.begin());
		g2 -= h1; g3 -= h1 + h2;
		ll g = max(g1, max(g2, g3));
		s1.erase(s1.begin()); s2.erase(s2.begin()); s3.erase(s3.begin());
		s1.insert(g + h1); s2.insert(g + h1 + h2); s3.insert(g + h1 + h2 + h3);
		ans = max(ans, g + h1 + h2 + h3);
	}
	cout << ans << endl;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define pi 3.141592653589793238462643383279502884197169399375105820974944592307816406286

typedef long long ll;	// Use "%I64d" as placeholder with printf and scanf.
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef priority_queue<int, vector<int>, greater<int>> min_heap_i;
typedef priority_queue<int, vector<int>, less<int>> max_heap_i;
typedef priority_queue<ll, vector<ll>, greater<ll>> min_heap_ll;
typedef priority_queue<ll, vector<ll>, less<ll>> max_heap_ll;

#define f(i, n) for(ll i=0; i<n; ++i)
#define fi(i, n, j) for(ll i=j; i<n; ++i)
#define pb push_back
#define ins insert
#define mp make_pair
#define all(container) container.begin(), container.end()
#define allr(container) container.rbegin(), container.rend()
#define tr(container, it) for (decltype(container.begin()) it = container.begin(); it != container.end(); it++)
#define trr(container, it) for (decltype(container.rbegin()) it = container.rbegin(); it != container.rend(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container),element) != container.end())
#define dist(a, b) sqrtl(powl(long double(a.first - b.first), 2) + powl(long double(a.second - b.second), 2))

#ifdef _CODE_SOURCE
double start_time, end_time;
#endif

// useful functions
void my_return(ll code)
{
#ifdef _CODE_SOURCE
	end_time = clock();
	printf("\nTime = %.3f seconds\n", (end_time - start_time) / CLOCKS_PER_SEC);
#endif
	exit(code);
}

ll gcd(ll a, ll b)
{
	return b ? gcd(b, a % b) : a;
}

ll my_exp(ll a, ll b)
{
	if (b == 0)
	{
		return 1;
	}
	else
	{
		ll temp = my_exp(a, b / 2);
		temp *= temp;
		if (b % 2 == 1)
		{
			temp *= a;
		}
		return temp;
	}
}

// Program classes and structs

// Program functions

int main()
{
#ifdef _CODE_SOURCE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	start_time = clock();
#endif
	//Program Code
	ll k, n1, n2, n3, t1, t2, t3;
	cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3;
	deque<ll> m1(n1, 0), m2(n2, 0), m3(n3, 0);
	f(i, k)
	{
		ll curr = m3.front(); m3.pop_front();
		curr = max(curr - t2, m2.front()); m2.pop_front();
		curr = max(curr - t1, m1.front()); m1.pop_front();
		m1.push_back(curr + t1);
		m2.push_back(curr + t1 + t2);
		m3.push_back(curr + t1 + t2 + t3);
	}
	ll ans = m3.back();
	cout << ans;
	my_return(0);
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,max=0,i,j,value;
	cin>>n;
	vector <int> v(n,0);
	for(i=0;i<n;i++){
		cin>>v[i];
		if(i!=0){
			v[i]+=v[i-1];
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<=i;j++){
			if(v[i]>(100*(i+1))){
			//	cout<<"cd\n";
				value=i+1;
				if(value>max){
					max=value;
				}
				break;
			}
			if((v[i]-v[j])>(100*(i-j+1))){
			//	cout<<"fv\n";
				value=(i-j+1);
				if(value>max){
					max=value;
				}
				break;
			}
		}
	}
	cout<<max<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,max=0,i,j,value;
	cin>>n;
	vector <int> v(n,0);
	for(i=0;i<n;i++){
		cin>>v[i];
		if(i!=0){
			v[i]+=v[i-1];
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<=i;j++){
			if(v[i]>(100*(i+1))){
				value=i+1;
				if(value>max){
					max=value;
				}
				break;
			}
			if((v[i]-v[j])>(100*(i-j+1))){
				value=(i-j+2);
				if(value>max){
					max=value;
				}
				break;
			}
		}
	}
	cout<<max<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,mx=0,i,j,value;
	cin>>n;
	vector <int> v(n,0);
	for(i=1;i<=n;i++){
		cin>>v[i];
		v[i]+=v[i-1];
	}
	for(i=1;i<=n;i++){
		for(j=0;j<i;j++){
			if((v[i]-v[j])>(100*(i-j))){
				mx=max(mx,i-j);
				break;
			}
		}
	}
	cout<<mx<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,mx=0,i,j,value;
	cin>>n;
	vector <int> v(n+1,0);
	for(i=1;i<=n;i++){
		cin>>v[i];
		v[i]+=v[i-1];
	}
	for(i=1;i<=n;i++){
		for(j=0;j<i;j++){
			if((v[i]-v[j])>(100*(i-j))){
				mx=max(mx,i-j);
				break;
			}
		}
	}
	cout<<mx<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    long long q=1;//cin>>q;
    while(q--){
        long long tot(0),n,k;cin>>n;long long arr[n],sum[n];
        for(int i=0;i<n;i++){cin>>arr[i];if(i!=0){sum[i]=sum[i-1]+arr[i];}else sum[i]=arr[i];}
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                k=(sum[j]-sum[i]+arr[i])/100;
                if((sum[j]-sum[i]+arr[i])%100==0) k--;
                tot=max(tot,k);
            }
        }
        cout<<tot<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    long long q=1;//cin>>q;
    while(q--){
        long long tot(0),n,k(0);cin>>n;long long arr[n],sum[n];
        for(int i=0;i<n;i++){cin>>arr[i];if(i!=0){sum[i]=sum[i-1]+arr[i];}else sum[i]=arr[i];}
        for(int i=0;i<n;i++){
            for(int j=i;j<n;j++){
                if((sum[j]-sum[i]+arr[i])>(j-i+1)*100) k=(j-i+1);
                tot=max(tot,k);
            }
        }
        cout<<tot<<endl;
    }
}


#include<bits/stdc++.h>

#define ll long long

using namespace std;

const int INF = 10e9, N = 10e6;

const ll LINF = 10e18;

int mx, l, c[5555], cnt;

bool used[5555][5555];

int main()
{
	int n;
	cin >> n;
	for(int i = 1 ; i <= n ; i++)
	{
		cin >> c[i];
	}
	for(int i = 1 ; i <= n ; i++)
	{
		for(int j = i ; j <= n ; j++)
		{
			if(used[i][j])
				continue;
			for(int h = i ; h <= j ; h++)
			{
				cnt += c[h];
				l++;
			}
			if(cnt > 100 * l)
			{
				mx = max(mx, l);
			}
			cnt = 0;
			l = 0;
			used[i][j] = 1;
		}
	}
	cout << mx;
}


#include<bits/stdc++.h>

#define ll long long

using namespace std;

int mx, l, c[5555], cnt, ans;

int main()
{
	int n;
	cin >> n;
	for(int i = 1 ; i <= n ; i++)
	{
		cin >> c[i];
	}
	for(int i = 1 ; i <= n ; i++)
	{
		for(int h = i ; h <= n ; h++)
		{
			l++;
			cnt += c[h];
			if(cnt > 100 * l)
			{
				mx = max(mx, l);
			}
		}
		cnt = 0;
		l = 0;
	}
	cout << mx;
}


#include<bits/stdc++.h>

#define ll long long

using namespace std;

const int INF = 10e9, N = 10e6;

const ll LINF = 10e18;

int mx, l, c[5555], cnt, ans;

int main()
{
	int n;
	cin >> n;
	for(int i = 1 ; i <= n ; i++)
	{
		cin >> c[i];
	}
	for(int i = 1 ; i <= n ; i++)
	{
		for(int h = i ; h <= n ; h++)
		{
			l++;
			cnt += c[h];
			if(cnt > 100 * l)
			{
				mx = max(mx, l);
			}
			else if(cnt < 100 * l)
			{
				break;
			}
		}
		cnt = 0;
		l = 0;
	}
	cout << mx;
}


#include<bits/stdc++.h>

#define ll long long

using namespace std;

const int INF = 10e9, N = 10e6;

const ll LINF = 10e18;

int mx, l, c[5555], cnt;

int main()
{
	int n;
	cin >> n;
	for(int i = 1 ; i <= n ; i++)
	{
		cin >> c[i];
	}
	for(int i = 1 ; i <= n ; i++)
	{
		for(int j = i ; j <= n ; j++)
		{
			for(int h = i ; h <= j ; h++)
			{
				cnt += c[h];
				l++;
			}
			if(cnt > 100 * l)
			{
				mx = max(mx, l);
			}
			cnt = 0;
			l = 0;
		}
	}
	cout << mx;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 5e3+10;
int mm[N];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        cin>>mm[i];
        mm[i]+=mm[i-1];
    }
    int ans=0;
    for(int i=1;i<=n;++i)
    {
        for(int j=i;j<=n;++j)
        {
            if(mm[j]-mm[j-i]>i*100)ans=i;
        }
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,x;
    cin>>n;
    int c=0;
    int s=0;
    for(int i=0;i<n;++i)
    {
        cin>>x;
        s+=x;
    }
    cout<<(s/100)-(s%100==0);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,x;
    cin>>n;
    int c=0;
    for(int i=0;i<n;++i)
    {
        cin>>x;
        c+=(x/100);
    }
    cout<<c<<endl;
    return 0;
}


 #include<bits/stdc++.h>
using  namespace std;
#define  ll                       long long
#define  pb                       push_back
#define  lb                       lower_bound
#define  ub                       upper_bound
#define  fr                       first
#define  sc                       second
#define  memset( a, b )           memset( a, b , sizeof(a) )
#define  PI                       3.1415926535
#define  mod                        1000000007
#define  rep( i , n )            for( i=0 ; i<n; i++ )
#define  int_max                 1000000000000000000

  ll t ,d , ct  , q, ans ,l ,m , r ,n , mx, mn , i, j, k ,x , y , z , s  ;

 char ch;                  string ss = "" ,  str = "" ;

    map<ll,ll>mp   ;                   set< ll >st ;

    // bool vis[200003] ;                vector< ll >v[200003];

   ll a[200003] , b[200003] ;

int main(){

       ios_base::sync_with_stdio ( false) ,
       cin.tie(nullptr ),cout.tie( nullptr );

// cin>>t ; while( t-- ) {

      s = k = d = l  = mx =m = mn = r= q =i=j = z= x= y =ct =ans = 0;

cin>>n ; rep(i ,n) cin>>a[i] ;

ans = -1 ;

for(i= 0 ;i<n; i++){
s = 0 ;
for(j = i; j<n; j++)
{
 s += a[j] ;
 if(s > 100*(j - i +1))
   mx = max(mx , j-i + 1) ;

}

}

cout<<mx ;

return 0;
}


 #include<bits/stdc++.h>
using  namespace std;
#define  ll                       long long
#define  pb                       push_back
#define  lb                       lower_bound
#define  ub                       upper_bound
#define  fr                       first
#define  sc                       second
#define  memset( a, b )           memset( a, b , sizeof(a) )
#define  PI                       3.1415926535
#define  mod                        1000000007
#define  rep( i , n )            for( i=0 ; i<n; i++ )
#define  int_max                 1000000000000000000

  ll t ,d , ct  , q, ans ,l ,m , r ,n , mx, mn , i, j, k ,x , y , z , s  ;

 char ch;                  string ss = "" ,  str = "" ;

    map<ll,ll>mp   ;                   set< ll >st ;

    // bool vis[200003] ;                vector< ll >v[200003];

   ll a[200003] , b[200003] ;

int main(){

       ios_base::sync_with_stdio ( false) ,
       cin.tie(nullptr ),cout.tie( nullptr );

// cin>>t ; while( t-- ) {

      s = k = d = l  = mx =m = mn = r= q =i=j = z= x= y =ct =ans = 0;

cin>>n ; rep(i ,n) cin>>a[i] ;

ans = -1 ;

for(i= -1 ;i<n-1; i++){
s = 0 ;
for(j = i+1; j<n; j++)
{
 s += a[i] ;
 if(s > 100*(j - i))
   mx = max(mx , j-i) ;

}

}

cout<<mx ;

return 0;
}


 #include<bits/stdc++.h>
using  namespace std;
#define  ll                       long long
#define  pb                       push_back
#define  lb                       lower_bound
#define  ub                       upper_bound
#define  fr                       first
#define  sc                       second
#define  memset( a, b )           memset( a, b , sizeof(a) )
#define  PI                       3.1415926535
#define  mod                        1000000007
#define  rep( i , n )            for( i=0 ; i<n; i++ )
#define  int_max                 1000000000000000000

  ll t ,d , ct  , q, ans ,l ,m , r ,n , mx, mn , i, j, k ,x , y , z , s  ;

 char ch;                  string ss = "" ,  str = "" ;

    map<ll,ll>mp   ;                   set< ll >st ;

    // bool vis[200003] ;                vector< ll >v[200003];

   ll a[200003] , b[200003] ;

int main(){

       ios_base::sync_with_stdio ( false) ,
       cin.tie(nullptr ),cout.tie( nullptr );

// cin>>t ; while( t-- ) {

      s = k = d = l  = mx =m = mn = r= q =i=j = z= x= y =ct =ans = 0;

cin>>n ; rep(i ,n) cin>>a[i] ;

ans = -1 ;

for(i= -1 ;i<n-1; i++){
s = 0 ;
for(j = i+1; j<n; j++)
{
 s += a[i] ;
 if(s > 100*(j - i +1))
   mx = max(mx , j-i + 1) ;

}

}

cout<<mx ;

return 0;
}