#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 <= 10000000; i++) { ll cur = Y * i, curd = -B * i; if (curd <= T) { ll d = T - curd; ll q = d / A; ans = min(ans, cur + q * X + d % A); } } cout << ans << '\n'; return 0; }