There are two 100-story buildings, called A and B. (In this problem, the ground floor is called the first floor.)
For each i = 1,\dots, 100, the i-th floor of A and that of B are connected by a corridor.
Also, for each i = 1,\dots, 99, there is a corridor that connects the (i+1)-th floor of A and the i-th floor of B.
You can traverse each of those corridors in both directions, and it takes you x minutes to get to the other end.
Additionally, both of the buildings have staircases. For each i = 1,\dots, 99, a staircase connects the i-th and (i+1)-th floors of a building, and you need y minutes to get to an adjacent floor by taking the stairs.
Find the minimum time needed to reach the b-th floor of B from the a-th floor of A.

-----Constraints-----
 - 1 \leq a,b,x,y \leq 100
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
a b x y

-----Output-----
Print the minimum time needed to reach the b-th floor of B from the a-th floor of A.

-----Sample Input-----
2 1 1 5

-----Sample Output-----
1

There is a corridor that directly connects the 2-nd floor of A and the 1-st floor of B, so you can travel between them in 1 minute.
This is the fastest way to get there, since taking the stairs just once costs you 5 minutes.

Difficulty: interview

Starter code:

Solutions:
a,b,x,y = map(int, input().split())
y=min(y,2*x)

if a==b or a==b+1:
    print(x)
    return

ans=x+abs(a-b)*y
if a>b:
    ans-=y
print(ans)

import heapq
a,b,x,y = map(int,input().split())
G = {}
for i in range(1,101):
    G[(0,i)]=[]
    if i-1>=1:
        G[(0,i)].append((0,i-1,y))
        G[(0,i)].append((1,i-1,x))
    if i+1<=100:
        G[(0,i)].append((0,i+1,y))
    G[(0,i)].append((1,i,x))
    G[(1,i)]=[]
    if i-1>=1:
        G[(1,i)].append((1,i-1,y))
    if i+1<=100:
        G[(1,i)].append((1,i+1,y))
        G[(1,i)].append((0,i+1,x))
    G[(1,i)].append((0,i,x))
dist = {}
INFTY = 30000
for i in range(1,101):
    dist[(0,i)]=INFTY
    dist[(1,i)]=INFTY
hist = {}
for i in range(1,101):
    hist[(0,i)]=0
    hist[(1,i)]=0
heap = [(0,(0,a))]
dist[(0,a)]=0
hist[(0,a)]=1
while heap:
    d,x = heapq.heappop(heap)
    if dist[x]<d:continue
    hist[x]=1
    for i,j,dy in G[x]:
        y = (i,j)
        if hist[y]==0 and dist[y]>d+dy:
            dist[y]=d+dy
            heapq.heappush(heap,(d+dy,y))
print(dist[(1,b)])

a, b, x, y = list(map(int, input().split()))
print((abs((b - a) * 2 + 1) // 2 * min(x * 2, y) + x))


a, b, x, y = list(map(int, input().split()))
diff = a - b
if diff == 0:
    print(x)
elif diff > 0:
    print((min(x + (abs(diff) - 1) * y, (abs(diff) * 2 - 1) * x)))
else:
    print((min(x + (abs(diff)) * y, (abs(diff) * 2 + 1) * x)))
# 4 -> 1
# 4a -> 3b -> 3a -> 2b -> 2a -> 1b
# 4a -> 3b -> 2b -> 1b
# 1 -> 4
# 1a -> 1b -> 2a -> 2b -> 3a -> 3b -> 4a -> 4b
# 1a -> 1b -> 2b -> 3b -> 4b


import heapq
a,b,x,y=list(map(int,input().split()))
dist=[10**30 for i in range(200)]
G=[[] for i in range(200)]
a-=1;b-=1;b+=100
for i in range(99):
    G[i].append((i+1,y))
    G[i+1].append((i,y))
    G[i+100].append((i+1+100,y))
    G[i+1+100].append((i+100,y))
for i in range(100):
    G[i].append((i+100,x))
    G[i+100].append((i,x))
for i in range(99):
    G[i+1].append((i+100,x))
    G[i+100].append((i+1,x))
dist[a]=0
q=[]
heapq.heappush(q,(0,a))
while(q):
    d,r=heapq.heappop(q)
    if dist[r]<d:
        continue
    for p,cost in G[r]:
        if dist[p]>dist[r]+cost:
            dist[p]=dist[r]+cost
            heapq.heappush(q,(dist[p],p))
print((dist[b]))


a,b,x,y = map(int,input().split())
print(x+min(2*x,y)*(abs(a-b)-(a>b)))

a,b,x,y = map(int, input().split())
a,b = a-1, b-1
g = [[] for _ in range(200)]
for i in range(100):
    g[i].append((x, 100+i))
    g[100+i].append((x, i))
for i in range(99):
    g[i+1].append((x, 100+i))
    g[100+i].append((x, i+1))
for i in range(99):
    g[i].append((y, i+1))
    g[i+1].append((y, i))
for i in range(99):
    g[i+100].append((y, i+1+100))
    g[i+1+100].append((y, i+100))

import heapq
INF = 10**18
def dijkstra_heap(s, edge):
    n = len(edge)
    d = [INF] * n
    used = [True] * n #True: not used
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v],e[1]))
    return d

d = dijkstra_heap(a, g)
print(d[b+100])

import math
a, b, x, y = list(map(int, input().split()))

w = abs((2 * b) + 1 - (2 * a))
print((math.floor(w/2) * min(2 * x, y) + x))



a,b,x,y = map(int,input().split())
d = abs(2*b+1-2*a)
Yd = min([2*x,y])
print(d//2*Yd+x)

a, b, x, y = map(int, input().split())

dif = a-b
elv = min(2*x, y)

if dif > 0:
    ans = (dif-1)*elv + x
else:
    ans = -dif*elv + x

print(ans)

a, b, x, y = map(int, input().split())
y = min(y, 2*x)
if a == b:
    print(x)
elif a > b:
    print(y*(a-b-1)+x)
elif a < b:
    print(y*(b-a)+x)

a,b,x,y=list(map(int, input().split()))
if a>b:
    print((x+abs(a-b-1)*min(2*x,y)))
elif a<b:
    print((x+abs(a-b)*min(2*x,y)))
elif a==b:
    print(x)


a,b,x,y = map(int, input().split())
y = min(y, 2*x)
d = abs(2*b + 1 - 2*a)
ans = y * (d//2) + x
print(ans)

a,b,x,y = map(int, input().split())
a,b = a-1, b-1
g = [[] for _ in range(200)]
for i in range(100):
    g[i].append((x, 100+i))
    g[100+i].append((x, i))
for i in range(99):
    g[i+1].append((x, 100+i))
    g[100+i].append((x, i+1))
for i in range(99):
    g[i].append((y, i+1))
    g[i+1].append((y, i))
for i in range(99):
    g[i+100].append((y, i+1+100))
    g[i+1+100].append((y, i+100))

import heapq
INF = 10**18
def dijkstra_heap(s, edge):
    n = len(edge)
    d = [INF] * n
    used = [True] * n #True: not used
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v],e[1]))
    return d

d = dijkstra_heap(a, g)
print(d[b+100])

from sys import stdin
pin=stdin.readline
from heapq import heapify,heappop,heappush
INF=1000000000000000000
V=0
G=[[] for _ in [0]*100000]
d=[INF]*100000

def dijkstra(s):
  que=[]
  heapify(que)
  d[s]=0
  heappush(que,[0,s])
  while que:
    p=heappop(que)
    v=p[1]
    if d[v]<p[0]:
      continue
    for i in range(len(G[v])):
      e=G[v][i]
      if d[e[0]]>d[v]+e[1]:
        d[e[0]]=d[v]+e[1]
        heappush(que,[d[e[0]],e[0]])
  return

def main():
  a,b,x,y=map(int,pin().split())
  V=200
  a-=1
  b-=1
  for i in range(100):
    G[i].append([i+100,x])
    G[i+100].append([i,x])
  for i in range(99):
    G[i+1].append([i+100,x])
    G[i+100].append([i+1,x])
  for i in range(99):
    G[i+1].append([i,y])
    G[i].append([i+1,y])
    G[i+101].append([i+100,y])
    G[i+100].append([i+101,y])
  dijkstra(a)
  print(d[b+100])
  return

main()

a,b,x,y=list(map(int,input().split()))
if a==b:
    print(x)
elif b>a:
    print((min(x+(b-a)*y,(x+(b-a)*2*x))))
else:
    print((min((a-b-1)*y+x,((a-b)*2-1)*x)))


a, b, x_yoko, y_tate = list(map(int, input().split()))

if (a == b):
    ans = x_yoko
elif (a > b):
    up = (a - b) * 2 * x_yoko - x_yoko
    cross = (a - b-1) * y_tate + x_yoko
    ans = min(up, cross)
else:
    up = (b - a) * y_tate + x_yoko
    cross = (b - a) * 2 * x_yoko + x_yoko
    ans = min(up, cross)

print(ans)


def LI():
    return list(map(int, input().split()))


a, b, x, y = LI()
ans = abs(a-b)*y+x
if a > b:
    ans -= y
if a == b or a == b+1:
    rouka = x
elif a < b:
    rouka = x
    rouka += (b-a)*x*2
else:
    a -= 1
    rouka = x
    rouka += (a-b)*x*2
ans = min(ans, rouka)
print(ans)


from sys import stdin, setrecursionlimit
import bisect, collections, copy, heapq, itertools, math, string
setrecursionlimit(10**8)

INF = float("inf")
MOD = 1000000007


def input():
    return stdin.readline().strip()



def main():

    
    a, b, x, y = list(map(int, input().split()))
    ans = abs(2*b+1-2*a)//2*min(2*x, y) + x

    print(ans)














    return

def __starting_point():
    main()

__starting_point()

a, b, x, y = map(int, input().split())
if b - a > 0:
    d = b - a
    print(min(x+d*y, d*2*x+x))
elif b - a < 0:
    d = a - b
    print(min((d-1)*y+x, d*2*x-x))
else:
    print(x)

s = list(map(int,input().split()))
a = s[0]
b = s[1]
x = s[2]
y = s[3]

if a == b:
    print(x)
elif a < b:
    print(min(x+(b-a)*y,((b-a)*2+1)*x))
else:
    print(min(((a-b)*2-1)*x,x+(a-b-1)*y))

a, b, x, y = map(int, input().split())
 
ans = x + abs(b - a)*y
ans = min(ans, abs(b - a)*x + abs(b - a + 1)*x)
 
if a > b:
    ans = min(ans, x + abs(a - b - 1)*y)
    ans = min(ans, abs(a - b)*x*2)
 
print(ans)

a,b,x,y = list(map(int,input().split()))

if a== b:
    print(x)
elif a<b:
    ans = min(y,2*x)*(b-a)+x
    print(ans)
else:
    ans = min(y,2*x)*(a-b-1)+x
    print(ans)

    


a, b, x, y = map(int, input().split())
S = min(2*x, y)
if a < b:
    print((b-a)*S+x)
elif a == b:
    print(x)
else:
    print((a-b-1)*S+x)

# 階段の使用回数で全探索してみる
a, b, x, y = list(map(int, input().split()))
if a == b:
    print(x)
    return
ans = 10 ** 10
dif = abs(a - b)
for step in range(dif + 1):
    if a < b:
        hollway = 2 * (dif - step) + 1  # 廊下を使う回数
    else:
        hollway = max(2 * (dif - step) - 1, 0)  # dif==stepのとき0未満になっちゃう
    ans = min(ans, x * hollway + y * step)
print(ans)



def resolve():
#====input code===
    a,b,x,y = map(int, input().split())
    if b>=a:
        print((b-a)*min(2*x,y)+x)
    else:
        print((a-b-1)*min(2*x,y)+x)
#================
resolve()

import collections
import heapq


class Dijkstra:
    def __init__(self):
        self.e = collections.defaultdict(list)

    def add(self, u, v, d):
        self.e[u].append([v, d])
        self.e[v].append([u, d])

    def delete(self, u, v):
        self.e[u] = [_ for _ in self.e[u] if _[0] != v]
        self.e[v] = [_ for _ in self.e[v] if _[0] != u]

    def search(self, s):
        """
        :param s: 始点
        :return: 始点から各点までの最短経路
        """
        d = collections.defaultdict(lambda: float('inf'))
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True

            for uv, ud in self.e[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd:
                    d[uv] = vd
                    heapq.heappush(q, (vd, uv))

        return d

A,B,X,Y = map(int, input().split())
graph = Dijkstra()
for i in range(1,101):
    graph.add(i,100+i,X)
for i in range(1,100):
    graph.add(i+1,100+i,X)
for i in range(1,100):
    graph.add(i,i+1,Y)
    graph.add(100+i,100+i+1,Y)
SA = graph.search(A)
print(SA[B+100])

# arc109a

a, b, x, y = list(map(int, input().split()))

ida = a * 2
idb = b * 2 + 1
diff = abs(ida - idb)
ans = 0
if 2 * x <= y:
    ans = diff * x
else:
    ans= x + (diff // 2) * y

print(ans)

a, b, x, y = list(map(int, input().split()))
if a == b:
    print(x)
if a < b:
    dif = b - a
    print((min(
        # b階まで階段
        dif * y + x,
        # 全部廊下
        dif * 2 * x + x)))
if a > b:
    dif = a - b
    print((min(
        # 廊下だけ
        (2 * dif - 1) * x,
        # 大体階段
        (dif-1) * y + x
    )))


a, b, x, y = map(int, input().split())
S = min(2*x, y)
if a < b:
    print((b-a)*S+x)
elif a == b:
    print(x)
else:
    print((a-b-1)*S+x)

import math

a,b,x,y = map(int, input().split())

t = min(2*x,y)

d = abs(2*b+1-2*a)

print(math.floor(d/2)*t + x)

a,b,x,y = map(int,input().split())
if(a==b):
  print(x)
elif(a>b):
  if(2*x>y):
    print(x+(a-b-1)*y)
  else:
    print(2*x*(a-b-1)+x)
else:
  if(2*x>y):
    print((b-a)*y+x)
  else:
    print(2*(b-a)*x+x)

ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
ips = lambda:input().split()
import collections
import math
import itertools
import heapq as hq
import sys
ceil = math.ceil
gcd = math.gcd
RL = sys.stdin.readline
INF=10**15
def ceilab(a,b):
    return (a+b-1)//b
a,b,x,y = ma()
if y>2*x:y=2*x
if a==b:
    print(x)
elif a>b:
    print((a-b-1)*y+x)
else:
    print((b-a)*y+x)


a,b,x,y=map(int,input().split())
if a==b:
    print(x)
elif a<b:
    ans1=(b-a)*y+x
    ans2=(b-a)*x*2+x
    print(min(ans1,ans2))
else:
    ans1=(a-b-1)*y+x
    ans2=(a-b-1)*x*2+x
    #print(ans1,ans2)
    print(min(ans1,ans2))

a,b,x,y = list(map(int,input().split()))
num = a - b
if num == 0:
    print(x)
elif num < 0:
    num = abs(num)
    ans = x
    if num * y > num * (x * 2):
        print((ans + (num * (x * 2))))
    else:
        print((ans + (num * y)))
else:
    num -= 1
    ans = x
    if num == 0:
        print(ans)
    else:
        if num * y > num * (x*2):
            print((ans + (num * (x*2))))
        else:
            print((ans + (num * y)))


#n = int(input())
a, b, x, y = list(map(int, input().split()))
#al = list(map(int,input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#s=[list(map(int,input().split())) for i in range(n)]

if a == b:
    ans = x
else:
    dif = abs(a-b)
    if a < b:
        ans = x+min(2*x, y)*dif
    else:
        ans = x+min(2*x, y)*(dif-1)
print(ans)


a, b, x, y = map(int, input().split())

if a < b:
  print(x + min(2 * x, y) * (b - a))
elif a == b:
  print(x)
else:
  print(x + min(2 * x, y) * (a - b - 1))

a, b, x, y = list(map(int, input().split()))
z = min(2 * x, y)
if a <= b:
    print((x + z * (b - a)))
else:
    print((x + z * (a - b - 1)))



a,b,x,y = [int(hoge) for hoge in input().split()]
#階段 y分
#ろうか x分
stair = min(y,2*x)
isle = x
ans = 0
if a>b:
    #くだり
    #Aのb+1階に行く + x分
    ans = (a-b-1)*stair + isle
else:
    #のぼり
    #真横に行って階段で登るしか無い
    ans = (b-a)*stair + isle
print(ans)

a,b,x,y = map(int,input().split())
ans = 0
if a == b:
  ans = x
if a > b:
  ans = min(x+(a-b-1)*y,x*(2*a-2*b-1))
if a < b:
  ans = min(x+y*(b-a),x*(2*b-2*a+1))
print(ans)

a, b, x, y = map(int, input().split())

if a > b:
    tmp = x + (a - b - 1) * y
    tmp2 = (a - b) * x + (a - b - 1) * x
    print(min(tmp, tmp2))
elif a == b:
    print(x)
else:
    tmp = x + (b - a) * y
    tmp2 = (b - a) * x + (b - a + 1) * x
    print(min(tmp, tmp2))

a,b,x,y = list(map(int,input().split()))
now=a

if b<a:
  print((min((a-b-1)*y+x,x*(a-b-1)+x*(a-b))))
elif b==a:
  print(x)
else:
  print((min(x+y*(b-a),2*x*(b-a)+x)))


a, b, x, y = map(int, input().split())
a, b = a-1, b-1
m = up = min(2*x, y)
if a <= b:
    print(x + m*(b-a))
else:
    print(x + m*(a-b-1))

a,b,x,y=map(int,input().split())
if b > a:
  print((b-a)*min(2*x,y)+x)
elif b < a:
  print((a-b-1)*min(2*x,y)+x)
else:
  print(x)

def solve(a, b, x, y):
    if b < a:
        return x + (a-b-1)*min(2*x, y)
    else:
        return x + (b-a)*min(2*x, y)

a, b, x, y = list(map(int, input().split()))
print((solve(a, b, x, y)))


def __starting_point():

    a,b,x,y = list(map(int,input().split()))

    ans = 0

    #階の差分
    ud_sbn = abs(a-b)
    #上るか下るか
    up = False
    if a-b<0:
        up=True

    #同じ階ならば
    if ud_sbn == 0:
        ans = x
    else:
        if up:
            u1 = ((ud_sbn+1)*2-1)*x
            u2 = x+(ud_sbn)*y
            ans = min(u1,u2)
        else:
            d1 = (ud_sbn*2-1)*x
            d2 = x+(ud_sbn-1)*y
            ans = min(d1,d2)
    print(ans)


__starting_point()



from functools import reduce
from operator import mul
from collections import Counter
from collections import deque
from itertools import accumulate
from queue import Queue
from queue import PriorityQueue as pq
from heapq import heapreplace
from heapq import heapify
from heapq import heappushpop
from heapq import heappop
from heapq import heappush
import heapq
import time
import random
import bisect
import itertools
import collections
from fractions import Fraction
import fractions
import string
import math
import operator
import functools
import copy
import array
import re
import sys
sys.setrecursionlimit(500000)


input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def warizan(a, b):
    return a // b, a % b


# from fractions import gcd
# from math import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))


# def coprimize(p, q):
#     common = gcd(p, q)
#     return (p // common, q // common)


# def find_gcd(list_l):
#     x = reduce(gcd, list_l)
#     return x


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, list(range(n, n - r, -1)), 1)
    denom = reduce(mul, list(range(1, r + 1)), 1)
    return numer // denom


mod = 1000000007


def combinations_count_mod(n, r):
    r = min(r, n - r)
    numer = reduce(lambda x, y: x * y % mod, list(range(n, n - r, -1)), 1)
    denom = pow(reduce(lambda x, y: x * y % mod, list(range(1, r + 1)), 1), mod - 2, mod)
    return numer * denom % mod


# def solve():


a, b, x, y = list(map(int, input().strip().split()))
h = abs(a - b)
if a < b:
    temp1 = y * (h) + x
    temp2 = 2 * x * h + x
    eprint('temp1,temp2 ', end=':\n')
    eprint(temp1, temp2)
    print(min(temp1, temp2))
elif a == b:
    print(x)
else:
    temp1 = (h - 1) * y + x
    temp2 = 2 * x * (h - 1) + x
    eprint('temp1,temp2 ', end=':\n')
    eprint(temp1, temp2)
    print(min(temp1, temp2))


a,b,x,y=list(map(int,input().split()))
vertical=min(2*x,y)
d=abs(a-b)
if a>b:
  ans=(d-1)*vertical+x
else:
  ans=d*vertical+x
print(ans)


# import sys
# input = sys.stdin.readline
import math
import copy
import bisect
from itertools import accumulate
from collections import Counter, defaultdict, deque
def mp():return map(int,input().split())
def lmp():return list(map(int,input().split()))
def ceil(U,V):return (U+V-1)//V
def modf1(N,MOD):return (N-1)%MOD+1

a,b,x,y = mp()
u = x*2
if a == b:
    print(x)
elif a > b:
    sa = a-b-1
    print(min(sa*u+x, sa*y+x))
else:
    sa = b-a
    print(min(x+sa*y, sa*u+x))

from collections import defaultdict
from sys import stdin

input = stdin.readline

def solve():

    a,b,x,y = map(int,input().split())
    d = abs(a - b)
    if d == 0:
        print(x)
        return

    elif a < b:
        print(d * y + x if y <= 2 * x else d * 2*x + x)
        return
    else:
        print((d-1) * y + x if y <= 2 * x else d * x * 2 - x)

def __starting_point():
    solve()
__starting_point()

a,b,x,y = [int(i) for i in input().split()]

if a==b:
    print(x)
elif a < b:
    if 2*x > y:
        print(((b-a)*y + x))
    else:
        print((2*(b-a)*x + x))
else:
    if 2*x > y:
        print(((a-b-1)*y + x))
    else:
        print((2*(a-b)*x - x))


a,b,x,y=map(int,input().split())
if a>b:
  print(min(x+(a-b-1)*y,(2*(a-b)-1)*x))
else:
  print(min(x+(b-a)*y,(2*(b-a)+1)*x))

import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

a, b, x, y = mapint()

if a>b:
    n = a-b
    print(min((n-1)*y+x, (x*2)*n-x))
else:
    n = b-a
    print(min(n*y+x, (x*2)*n+x))

a, b, x, y = map(int, input().split())

if a > b:
    ans = min(((a - b)*2 - 1)*x, (a - b - 1)*y + x)
elif a == b:
    ans = x
else:
    ans = min(((b - a)*2 + 1)*x, (b - a)*y + x)

print(ans)

import sys
from functools import reduce

zz=1
 
sys.setrecursionlimit(10**5)
if zz:
	input=sys.stdin.readline
else:	
	sys.stdin=open('input.txt', 'r')
	sys.stdout=open('all.txt','w')
di=[[-1,0],[1,0],[0,1],[0,-1]]

def fori(n):
	return [fi() for i in range(n)]	
def inc(d,c,x=1):
	d[c]=d[c]+x if c in d else x
def ii():
	return input().rstrip()	
def li():
	return [int(xx) for xx in input().split()]
def fli():
	return [float(x) for x in input().split()]	
def comp(a,b):
	if(a>b):
		return 2
	return 2 if a==b else 0		
def gi():	
	return [xx for xx in input().split()]
def gtc(tc,ans):
	print(("Case #"+str(tc)+":",ans))	
def cil(n,m):
	return n//m+int(n%m>0)	
def fi():
	return int(input())
def pro(a): 
	return reduce(lambda a,b:a*b,a)		
def swap(a,i,j): 
	a[i],a[j]=a[j],a[i]	
def si():
	return list(input().rstrip())	
def mi():
	return 	list(map(int,input().split()))			
def gh():
	sys.stdout.flush()
def isvalid(i,j,n,m):
	return 0<=i<n and 0<=j<m 
def bo(i):
	return ord(i)-ord('a')	
def graph(n,m):
	for i in range(m):
		x,y=mi()
		a[x].append(y)
		a[y].append(x)


t=1
uu=t


while t>0:
	t-=1
	a,b,x,y=mi()
	y=min(y,2*x)
	if a>b:
		print(((a-b-1)*y+x))
	else:
		print(((b-a)*y+x))	



a, b, x, y = map(int, input().split())
S = min(2*x, y)
if a < b:
    print((b-a)*S+x)
elif a == b:
    print(x)
else:
    print((a-b-1)*S+x)


#標準入力
s = list(map(int, input().split()))

a = int(s[0])
b = int(s[1])
x = int(s[2])
y = int(s[3])

move_withoutstep_1 = 9999999999
move_withoutstep_2 = 9999999999

#階段移動を使わない場合の移動時間
# a > bの時
if a > b:
    move_withoutstep_1 = ((a-b)-1)*x + (a-b)*x
#a < bの時
elif a <= b:
    move_withoutstep_2 = ((b-a)+1)*x + (b-a)*x


#階段移動を使う場合の移動時間
move_upstairs = 9999999999
move_downstairs = 9999999999

if a < b:
    move_upstairs = (b-a)*y + x
elif a > b:
    #最後の下りはななめ移動（廊下を使った移動）の方が早いので、それを考慮して階段移動の回数を1回分減らす。
    #x+yよりもxの方が小さいのは条件より自明。
    move_downstairs = (a-b-1)*y + x

#print(move_withoutstep_1,move_withoutstep_2,move_upstairs,move_downstairs,move_downstairs_2)
print((min(move_withoutstep_1,move_withoutstep_2,move_upstairs,move_downstairs)))


a,b,x,y = map(int,input().split())

ans = 0

if a > b:
    if 2*x > y:
        ans = (a-b-1)*y+x
    else:
        ans = (a-b)*x*2-x
else:
    if 2*x > y:
        ans = (b-a)*y+x
    else:
        ans = (b-a)*x*2+x
print(ans)

#ARC109 A

a, b, x, y = list(map(int,input().split()))

ans,c,d = 0,0,0

if a == b:
    ans = x
elif a > b:
    c = x+(a-b-1)*y
    d = (a-b)*2*x - x
    ans = min(c,d)
else:
    c = (b-a)*2*x + x
    d = (b-a)*y + x
    ans = min(c,d)
    
print(ans)

#ワーシャルフロイド法 O(Nの3乗)。N <= 300くらいで解ける。
a,b,x,y = map(int,input().split())
g = [[10**8 for _ in range(200)] for i in range(200)]
#g[i][j]=aのi階からbのj階までの最短時間
for i in range(200):
    g[i][i] = 0
#A_iを0-indexの(0 ～99 ) B_iを0-indexの(100～199)で考える
for i in range(100):
    g[i][i+100]=x
    g[i+100][i]=x
for i in range(99):
    g[i+1][i+100] = x
    g[i+100][i+1] = x
for i in range(99):
    g[i+1][i]=y
    g[i][i+1]=y
for i in range(99):
    g[i+101][i+100]=y
    g[i+100][i+101]=y
#ワーシャルフロイド法
def warchall_floyd(n):
    for i in range(n):
        #経由する頂点
        for j in range(n):
          #始点
            for k in range(n):
            #終点
                g[j][k] = min(g[j][k],g[j][i]+g[i][k])

warchall_floyd(200)
print(g[a-1][100+b-1])

a, b, x, y=map(int, input().split())

if b>a:
  route_x=x+2*x*(b-a)
  route_y=x+y*(b-a)

elif a==b:
  route_x=x
  route_y=x+y

else:
  route_x=x+2*x*(a-b-1)
  route_y=x+y*(a-b-1)

answer=min(route_x, route_y)
print(answer)

a, b, x, y = list(map(int, input().split()))
if a == b:
    ans = x
elif a < b:
    ans = x + (b - a) * min(x * 2, y)
else:
    ans = x + (a - b - 1) * min(x * 2, y)

print(ans)


a,b,c,d = map(int,input().split())


if a == b:
    print(c)
    return

if a < b:
    print(min(c+d*(b-a), c+2*c*(b-a)))
else:
    print(min(c+d*(a-b-1), c+2*c*(a-b-1)))

a, b, x, y = list(map(int, input().split()))
if a == b:
    print(x)
else:
    res = 100000000000000000
    # sloap
    if a != 1:
        aa = a - 1
        tmp = x
        tmp += y * (aa-b)
        res = min(res, tmp)
    # ro-ka
    tmp = x
    tmp += y * abs(a - b)
    res = min(res, tmp)

    if a == b:
        res = min(x, res)
    elif a > b:
        res = min(res, x * (abs(a - b) * 2 - 1))
    elif a < b:
        res = min(res, x * (abs(a-b) * 2 + 1) )

    print(res)



a,b,x,y = map(int,input().split())
if b>a:
    ans = x + (b-a)*min(2*x,y)
elif b<a:
    ans = x + (a-b-1)*min(2*x,y)
else:
    ans = x 
print(ans)

a,b,x,y=map(int,input().split())
if a==b:print(x)
if a>b:print(min(x+(a-b-1)*y,x+(a-b-1)*2*x))
if a<b:print(min(x+(b-a)*y,(2*(b-a)+1)*x))

a, b, x, y = map(int, input().split())
v = min(y, 2 * x)

if a == b:
    print(x)
    return

v = min(2 * x, y)
if a > b:
    ans = v * (a - b - 1) + x
else:
    ans = v * (b - a) + x
print(ans)

a,b,x,y = list(map(int,input().split()))
if a == b:
  print(x)
  return

if a > b:
  h = a-b
  if y*(h-1) >= 2*x*(h-1):
    print((2*x*(h-1) + x))
    return
  else:
    print((y*(h-1) + x))
    return
else:
  h = b-a
  if y >= 2*x:
    print((2*x*h+x))
    return
  else:
    print((y*h+x))
    return




import math
from functools import reduce


def readGenerator():
    while True:
        tokens = input().split(' ')
        for t in tokens:
            yield t


reader = readGenerator()


def readWord():
    return next(reader)


def readInt():
    return int(next(reader))


def readFloat():
    return float(next(reader))


def readLine():
    return input()


def fib(n, f1, f2, i):
    if n <= f1:
        return i
    return fib(n, f2, f1 + f2, i + 1)


def bin(a, num):
    left = 0
    right = len(a) - 1
    while (right - left) > 1:
        mid = (right + left) // 2
        if a[mid] < num:
            left = mid
        else:
            right = mid

    return a[left] == num or a[right] == num


def lcm(x, y):
    tmp = x
    while (tmp % y) != 0:
        tmp += x
    return tmp


def createGraph(x, y):
    g = []
    for i in range(200):
        g.append([])

    for i in range(100):
        g[i].append((i + 100, y))
        g[i + 100].append((i, y))
        if i > 0:
            g[i].append((i - 1, x))
            g[100 + i].append((i + 99, x))
            g[i].append((i + 99, y))
            g[99 + i].append((i, y))
        if i < 99:
            g[i].append((i + 1, x))
            g[100 + i].append((i + 101, x))

    return g


def solve(a, b, y, x):
    g = createGraph(x, y)

    d = [10 ** 10] * 200
    d[a] = 0

    v = [False] * 200

    for _ in range(200):
        vi = -1
        mn = 10 ** 10
        for j in range(200):
            if d[j] < mn and not v[j]:
                vi = j
                mn = d[j]

        for (dest, t) in g[vi]:
            d[dest] = min(d[dest], d[vi] + t)

        v[vi] = True

    return d[b]


#t = readInt()
#for _ in range(t):
a, b, x, y = [readInt() for _ in range(4)]
print((solve(a - 1, b + 99, x, y)))


import sys
import math
import re
import random
import itertools
import bisect
from copy import copy
from collections import deque,Counter,defaultdict
from decimal import Decimal
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9

a,b,x,y = map(int,input().split())
num = abs(a-b)
if a > b:
    print(min(x*(num*2-1),x+y*(num-1)))
elif a == b:
    print(x)
else:
    print(min(x*(num*2+1),x+y*num))

import sys

# A - Hands
a, b, x, y = map(int, input().split())
ans = 0

if a == b:
  ans = x
elif a < b:
  move1 = (b-a) * x * 2 + x
  move2 = (b-a)*y + x

  ans = min(move1, move2)
else:
  move1 = (a-b)*x*2 - x
  move2 = (a-b)*y + x

  ans = min(move1, move2)

  move3 = (a-b-1)*y + x
  ans = min(ans, move3)

print(ans)

#!/usr/bin/env python
#-*- coding: utf-8 -*-

def __starting_point():
    a, b, x, y = list(map(int, input().split()))
    y = min(y, 2*x)
    print((x+min(abs(a-b), abs(a-1-b))*y))

__starting_point()

a,b,x,y=map(int,input().split())
if a<=b:
  print(min(x+y*(b-a),x*((b-a)*2+1)))
else:
  print(min(x+y*(a-b-1),x*((a-b)*2-1)))

a,b,x,y = map(int,input().split())
hoge = max(b-a,a-b-1)
print(min(hoge*x*2,hoge*y)+x)

import math
import numpy as np
import sys
input = sys.stdin.readline

def main():
    a, b, x, y = list(map(int,input().split()))
    if(b>a):
        d = b-a
        t1=y*d+x
        t2=2*x*d+x
        print(min(t1, t2))
    elif(a==b):print(x)
    else:
        d=a-b
        t1=y*(d-1)+x
        t2=2*x*(d-1)+x
        print(min(t1, t2))

main()

a,b,x,y=map(int,input().split())
if a==b:
    ans=x
elif a<b:
    ans=min(x+(b-a)*y,x*((b-a)*2+1))
else:
    ans=x+min((a-b-1)*y,2*(a-b-1)*x)
print(ans)

a, b, x, y = list(map(int, input().split()))

#using staircase:
if b < a:
    d1 = abs(b+1 - a)*y + x
    d2 = (abs(b-a)*2 - 1)*x
else:
    d1 = abs(b - a) * y + x
    d2 = (abs(b-a)*2 + 1)*x
#using corridors only
#a10->b9->a9->b8..
print((min(d1, d2)))


a,b,x,y=map(int,input().split())
vertical=min(2*x,y)
d=abs(a-b)
if a>b:
  ans=(d-1)*vertical+x
else:
  ans=d*vertical+x
print(ans)

a, b, x, y = list(map(int, input().split()))
if 2 * x >= y:
    if a <= b:
        print((x + y * (b - a)))
    else:
        print((x + y * (a - 1 - b)))
else:
    if a <= b:
        print((x + 2 * x * (b - a)))
    else:
        print((x + 2 * x * (a - 1 - b)))



a,b,x,y=map(int,input().split())
if a>b:
  print((a-b-1)*min(2*x,y)+x)
else:
  print((b-a)*min(2*x,y)+x)

a,b,x,y=[int(x) for x in input().split()]
if 2*x>=y:
    if b>=a:
        print(x+(b-a)*y)
    else:
        print(x+(a-b-1)*y)
else:
    if b>=a:
        print(2*x*(b-a)+x)
    else:
        print(2*x*(a-b-1)+x)

a,b,x,y = map(int, input().split())
z = min(x*2, y)
d = abs(b*2-a*2+1)//2
print(d*z + x)

A, B, X, Y = map(int, input().split())
x = A*2
y = B*2+1
l = abs(y-x)
o = X
t = min(X*2, Y)
ans = l//2*t + l%2*o
print(ans)

a,b,x,y = map(int,input().split())
t = 0
if a > b:
  c = (a-1) -b
else:
  c = b - a
t += x
if x*2 < y:
  t += c*x*2
else:
  t += c*y
print(t)

a,b,x,y = list(map(int,input().split()))

ans = x
if a==b:
    print(ans)
elif a>b:
    print((ans + (a-1-b)*min(2*x,y)))
else:
    print((ans + (b-a)*min(2*x,y)))


a, b, x, y = list(map(int, input().split()))
d = abs(2*b+1-2*a)
print(((d//2)*min(2*x, y)+x))


a, b, x, y = map(int, input().split())
ans = 0

if a > b:
    a1 = x + y * (a - b - 1)
    a2 = x * (2 * (a - b) - 1)
else:
    a1 = x + y * (b - a)
    a2 = x * (2 * (b - a) + 1)
ans = min(a1, a2)
print(ans)

n=100
a,b,x,y=list(map(int,input().split()))
dpa=[-1]*(n+1)
dpb=[-1]*(n+1)
dpa[a]=0
dpb[a]=x

for ii in range(a,n):
  dpb[ii]=dpa[ii]+x
  dpa[ii+1]=min(dpa[ii]+y,dpb[ii]+x)

dpb[n]=min(dpa[n]+x,dpb[n-1]+y)

for ii in range(a,1,-1):
  dpb[ii-1]=dpa[ii]+x
  dpa[ii-1]=min(dpa[ii]+y,dpb[ii-1]+x)

#print(dpa)
#print(dpb)
print((dpb[b]))


# A - Hands
# https://atcoder.jp/contests/arc109/tasks/arc109_a

a, b, x, y = list(map(int, input().split()))

if a > b:
    if y >= 2 * x:
        ans = abs(a - b - 1) * 2 * x + x
    else:
        ans = abs(a - b - 1) * y + x
else:
    if y >= 2 * x:
        ans = abs(a - b) * 2 * x + x
    else:
        ans = abs(a - b) * y + x

print(ans)


import sys

a,b,x,y = map(int, input().split())

diff = a - b
if diff == 1 or diff == 0:
    print(x)
    return

if diff < 0:
    diff = -diff
    p1 = x + y * diff
    p2 = (2 * diff * x) + x
else:
    p1 = x + y * (diff - 1)
    p2 = (diff * x) + x * (diff - 1)

print(min(p1, p2))

a, b, x, y = map(int, input().split())

if a == b:
  print(x)
elif a < b:
  if (b - a) * y + x < ((b - a) * 2 + 1) * x:
    print((b - a) * y + x)
  else:
    print(((b - a) * 2 + 1) * x)
else:
  if ((a - b) * 2 - 1) * x < (a - b - 1) * y + x:
    print(((a - b) * 2 - 1) * x)
  else:
    print((a - b - 1) * y + x)

A, B, X, Y = map(int, input().split())

if A == B:
	print(X)
elif A > B:
	if 2*X < Y:
		print(2*X*(A-B-1)+X)
	else:
		print(Y*(A-B-1)+X)
else:
	if 2*X < Y:
		print(2*X*(B-A)+X)
	else:
		print(Y*(B-A)+X)

def resolve():
    #n=int(input())
    #a,b=map(int,input().split())
    #x=list(map(int,input().split()))
    #a=[list(map(lambda x:int(x)%2,input().split())) for _ in range(h)]
    a,b,x,y=map(int,input().split())
    if b>=a:
        print((b-a)*min(2*x,y)+x)
    else:
        print((a-b-1)*min(2*x,y)+x)

def __starting_point():
    resolve()
__starting_point()

a, b, x, y = list(map(int, input().split()))
if b>a:
    use_x=x+2*x*(b-a)
    use_y=x+y*(b-a)
elif a == b:
    use_x=x
    use_y=x+y
else:
    use_x=x+2*x*(a-b-1)
    use_y=x+y*(a-b-1)
print((min(use_x,use_y)))


a,b,x,y=map(int,input().split())
cnt1=min(abs(a-b-1),abs(a-b))*y+x
cnt2=min(abs(a-b-1),abs(a-b))*2*x+x

print(min(cnt1, cnt2))