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) x>z ?[x+d(y,1),z+d(y,s+1)].min: x+d(y,1) end p d(c,1)+w