# include "stdio.h"
# include "algorithm"
# define int long long
int step,dis,n,d,a,b,ans,top,las;
int cpp(){
freopen("mountain.in","r",stdin);
freopen("mountain.out","w",stdout);
scanf("%lld%lld%lld%lld",&n,&d,&a,&b);
n--;top=std::max(a,b);
dis=std::abs(a-b);
if(dis%d==0) step=dis/d;
else step=dis/d+1;
if(dis%d==0) las=0;
else las=d-dis%d;
ans+=(n-step)%2*las;
ans+=(n-step)/2*d;
ans+=top;
printf("%lld",ans);
}int start=cpp();
signed main(){;}