#include using namespace std; #define REP(i,n) for(int i=0;i P; int main(void){ int i; cin.tie(0); ios_base::sync_with_stdio(false); ll T,X,A,Y,B; cin >> T >> X >> A >> Y >> B; ll mn=1e18; for(i=0;i<=1e7;i++){ ll x=T+B*i; if(x<0) continue; ll j=x/A; ll r=x%A; mn=min(mn,r+X*j+Y*i); } cout << mn << endl; return 0; }