#include #include using namespace std; using namespace atcoder; #define rep(i,n) for(int i=0;i<(n);i++) #define per(i,n) for(int i=(n)-1;i>=0;i--) #define all(x) x.begin(),x.end() typedef long long ll; //using mint = modint; using mint = modint998244353; //using mint = modint1000000007; using P = pair; const ll INF=1LL<<60, dx[]={0,1,0,-1},dy[]={1,0,-1,0}; template inline bool chmin(T& a,const T&b) {if(a>b){a=b; return 1;} return 0;} template inline bool chmax(T& a,const T&b) {if(a> T; cin >> X >> A; cin >> Y >> B; map mp; priority_queue,vector>, greater>> q; q.push({1ll,0ll}); while(!mp[T]) { auto [cost,now]=q.top(); q.pop(); //cout << "##" << cost << " " << now << endl; if(!mp[now]) { mp[now]=cost; if(!mp[now+1]) q.push({cost+1,now+1}); if(!mp[now+A]) q.push({cost+X,now+A}); if(!mp[now-B]) q.push({cost+Y,now-B}); } } cout << mp[T]-1 << endl; return 0; }