#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 ny = (-t - 1) / b + 1; t += b * ny; base += y * ny; } ll ans = 1e18; for (ll ny = 0; ny < x; ny++) {//yの回数 ll now = - b * ny; ll nx = (t - now) / a; ll res = y * ny + x * nx + (t - now - a * nx); ans = min(ans, res); } cout << ans + base << endl; return 0; }