#include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) template using vi = vector; template using vii = vector>; template using viii = vector>; int main() { ll t, x, a, y, b; cin >> t >> x >> a >> y >> b; ll base = 0; if (t > 0) { ll nx = t / a; t -= a * nx; base += x * nx; } ll ans = 1e18; for (ll nx = 0; nx < y; nx++) {//xの回数 ll now = a * nx; ll res = x * nx; if (now <= t) res += t - now; else { ll ny = (now - t - 1) / b + 1; now -= b * ny; res += y * ny + t - now; } ans = min(ans, res); } cout << ans + base << endl; return 0; }