#include #include #include using namespace std; using ll = long long; int main(){ int t; cin >> t; int x, a; cin >> x >> a; int y, b; cin >> y >> b; ll ans = 1LL << 60; for(int i = 0; i < 10000010; i++){ ll res = 0; ll t1 = t; res += 1LL*y*i; t1 += 1LL*b*i; if(t1 < 0) continue; ll c1 = t1/a; res += x*c1; res += t1-a*c1; ans = min(ans, res); } cout << ans << endl; return 0; }