#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); ll T,X,A,Y,B; cin >> T >> X >> A >> Y >> B; if(T < 0) { swap(X, Y); swap(A, B); } ll ans = numeric_limits::max(); for(ll x = 0; x <= ll(1e7); x++) { ll y = (A * x - T + B - 1) / B; ll z = T - (A * x - B * y); if(0 <= y && 0 <= z) ans = min(ans, X * x + Y * y + z); y = (A * x - T) / B; z = T - (A * x - B * y); if(0 <= y && 0 <= z) ans = min(ans, X * x + Y * y + z); } cout << ans << endl; }