#include using namespace std; using ll = long long; int main () { ll t, x, a, y, b; cin >> t >> x >> a >> y >> b; ll ans = 0; if (t < 0) { ll s = (-t + b - 1) / b; ans = s * y; t = s * b + t; } ans += (t / a) * x; t %= a; for (ll i = 1; i < t; i ++) { ll s = i * x; ll t2 = i * a - t; ll pk = ((t2 + b - 1) / b); s += pk * y; t2 = pk * b - t2; if (s >= t) { break; } ans = min(ans, s + t2); } cout << ans << endl; }