#if !__INCLUDE_LEVEL__ #include __FILE__ signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll T, X, A, Y, B; cin >> T >> X >> A >> Y >> B; if (T > 0) { if (X >= A) { cout << T << "\n"; return 0; } ll TT = T % A; ll ans = T / A * X; cerr << ans << "\n"; ll add_cost = TT; REP(i, 1e7) { if (i == 0) continue; ll cost = X * i; if ((A * i - TT) % B == 0) { cost += Y * (A * i - TT) / B; } else { cost += Y * ((A * i - TT) / B + 1) + ((A * i - TT) % B); } add_cost = min(add_cost, cost); } cout << ans + add_cost << "\n"; } else { if (T % B == 0) { cout << T / B * Y << "\n"; return 0; } T *= -1; ll TT = (T / B + 1) * B - T; ll ans = (T / B + 1) * Y; cerr << (T / B + 1) * B << "\n"; ll add_cost = TT; REP(i, 1e7) { // if (i == 0) // continue; if (TT + B * i < A) continue; ll cost = Y * i; if ((B * i + TT) % A == 0) { cost += X * (B * i + TT) / A; } else { cost += X * (B * i + TT) / A + ((B * i + TT) % A); } add_cost = min(add_cost, cost); } cout << ans + add_cost << "\n"; } return 0; } //====================temp==================== #else #include using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define RREP(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define REPITR(itr, ARRAY) \ for (auto itr = (ARRAY).begin(); itr != (ARRAY).end(); ++itr) #define RREPITR(itr, ARRAY) \ for (auto itr = (ARRAY).rbegin(); itr != (ARRAY).rend(); ++itr) #define ALL(n) (n).begin(), (n).end() using ll = long long; using ull = unsigned long long; //#define int long long template struct edge { int to; T cost; edge() {} edge(int to, T cost): to(to), cost(cost) {} }; #endif