n,A,B,w,*c=`dd`.split.map &:to_i def d c,s x,*y,z=*c,B*s-A c[1]||(return [x,z].min) return x+d(y,1)if x<=z return z+d(y,s+1)if x-z>B*2 [x+d(y,1),z+d(y,s+1)].min end p d(c,1)+w