#include using namespace std; #ifdef _RUTHEN #include #else #define show(...) true #endif using ll = long long; #define rep(i, n) for (int i = 0; i < (n); i++) template using V = vector; int main() { ios::sync_with_stdio(false); cin.tie(0); ll T, X, A, Y, B; cin >> T >> X >> A >> Y >> B; ll ans = 1LL << 60; for (int i = 0; i <= 100000000; i++) { ll cur = X * i, curd = A * i; if (curd <= T) { ans = min(ans, cur + T - curd); } else { // curd > T ll d = curd - T; ll q = (d + B - 1) / B; ll r = q * B - d; ans = min(ans, cur + q * Y + r); } } cout << ans << '\n'; return 0; }