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) end p d(c,1)+w