#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; int main(){ ll T, ans=1e18, x, a, y, b; cin >> T; cin >> x >> a >> y >> b; if (T >= 0){ for (ll i=0; i<=1e7; i++){ if (a*i-T >= 0){ ll j = (a*i-T+b-1)/b; ans = min(ans, x*i+y*j+T-(a*i-b*j)); } else ans = min(ans, x*i+T-a*i); } } else{ for (int i=0; i<=1e7; i++){ if (T < -b*i) continue; ll j = (T+b*i)/a; ans = min(ans, y*i+x*j+T+b*i-a*j); } } cout << ans << endl; return 0; }