#include using namespace std; typedef long long ll; int main(void) { ll N,D,T,K; cin >> N >> D; ll to[N],ky[N]; cin >> T >> K; to[0] = T; ky[0] = K - D; for (int i=1; i> T >> K; to[i] = max(to[i-1] + T, ky[i-1] + T - D); ky[i] = max(to[i-1] + K - D, ky[i-1] + K); } cout << max(to[N-1], ky[N-1]) << endl; return 0; }