#include using namespace std; int main() { long long T, X, A, Y, B; cin >> T >> X >> A >> Y >> B; long long ans = (T/A)*X + T%A; long long now = T - T%A; for(int i = 0; i < 2*(1e7); ++i) { now += A; long long wait = T - (now - ((now-T-1)/B+1)*B); ans = min(ans, (now/A)*X + (now-(T-wait))/B*Y + wait); } cout << ans << endl; }