#include <bits/stdc++.h>
using namespace std;
int main()
{
long long a, c, p, q, r, x, temp = 0;
cin >> a >> c >> p >> q >> r >> x;
if (a < c)
{
if ((c - a) * p >= x)
{
cout << a + (x / p);
return 0;
}
else
{
x -= (c - a) * p;
temp = c;
if (q >= x)
{
cout << temp - 1;
return 0;
}
else
{
x -= q;
temp += x / r;
cout << temp;
return 0;
}
}
}
else if (a == c)
{
if (q >= x)
{
cout << temp - 1;
return 0;
}
else
{
x -= q;
temp = c;
temp += x / r;
cout << temp - 1;
return 0;
}
}
else
{
temp = a;
temp += x / r;
cout << temp - 1;
}
return 0;
}
WA: 4 5 10