Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?


-----Input-----

The single line contains four space-separated integers n, m, a, b (1 ≤ n, m, a, b ≤ 1000) — the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket. 


-----Output-----

Print a single integer — the minimum sum in rubles that Ann will need to spend.


-----Examples-----
Input
6 2 1 2

Output
6

Input
5 2 2 3

Output
8



-----Note-----

In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets.

Difficulty: EASY
Tags: Implementation

Starter code:

Solutions:
(n, m, a, b) = map(int, input().split())
money = 0
resi = 0
if n % m == 0:
	money = min(n // m * b, a * n)
else:
	resi = n % m
	money = min(n // m * b + a * resi, n // m * b + b)
print(money)


import math
(n, m, a, b) = list(map(int, input().split()))
x = []
for i in range(0, n + 1):
	x.append(a * i + math.ceil((n - i) / m) * b)
print(min(x))


(n, m, a, b) = input().split(' ')
n = int(n)
m = int(m)
a = int(a)
b = int(b)
bonus_rides = int(n / m)
rest = int(n % m)
x = min(bonus_rides * b + rest * a, min(n * a, (bonus_rides + 1) * b))
print(int(x))


import math
(n, m, a, b) = map(int, input().split())
a1 = math.ceil(n / m) * b
a2 = n * a
a3 = n // m * b + n % m * a
print(min([a1, a2, a3]))


(n, m, a, b) = map(int, input().split())
if b / m >= a:
	print(a * n)
else:
	cost = 0
	cost += int(n / m) * b
	if n % m * a <= b:
		cost += n % m * a
	else:
		cost += b
	print(cost)


(n, m, a, b) = map(int, input().strip().split())
if m * a < b:
	print(n * a)
elif n % m * a > b:
	print((int(n / m) + 1) * b)
else:
	print(int(n / m) * b + n % m * a)


(n, m, a, b) = list(map(int, input().split()))
x = []
for i in range(0, n + 1):
	if n < i * m:
		x.append(b * i)
		break
	else:
		x.append(i * b + (n - i * m) * a)
print(min(x))


import sys
import math
import heapq
from collections import defaultdict, deque
input = sys.stdin.readline

def r():
	return int(input())

def rm():
	return map(int, input().split())

def rl():
	return list(map(int, input().split()))
(n, m, a, b) = rm()
cost1 = n * a
cost2 = math.inf
if m >= n:
	cost2 = b
else:
	c = n // m
	cost2 = b * c + min(b, n % m * a)
print(min(cost1, cost2))


from sys import stdin, stdout
inp = stdin.readline
out = stdout.write
(n, m, a, b) = map(int, inp().strip().split())
ans = min(n * a, n // m * b + min(b, n % m * a))
if n < m:
	ans = min(ans, b)
print(ans)


import math
(n, m, a, b) = map(int, input().split())
p1 = n * a
p2 = math.ceil(n / m) * b
p3 = n // m * b + n % m * a
print(min(p1, p2, p3))


import math
(n, m, a, b) = map(int, input().split())
if b / m >= a:
	print(n * a)
else:
	print(min(n // m * b + n % m * a, math.ceil(n / m) * b))


(n, m, a, b) = list((int(x) for x in input().split()))
res1 = 0
res2 = 0
p = n // m
res1 += p * b
if n % m != 0:
	if (n - m * p) * a < b:
		res1 += (n - m * p) * a
	else:
		res1 += b
res2 = n * a
print(min(res1, res2))


from math import *
(n, m, a, b) = [int(i) for i in input().split()]
if b / m < a:
	if n % m == 0:
		print(n // m * b)
	else:
		print(min(ceil(n / m) * b, (n - floor(n / m) * m) * a + floor(n / m) * b))
else:
	print(n * a)


from math import ceil
data = [int(x) for x in input().split()]
op1 = ceil(data[0] / data[1]) * data[3]
op2 = data[0] // data[1] * data[3] + data[0] % data[1] * data[2]
op3 = data[0] * data[2]
print(min(op1, op2, op3))


(n, m, a, b) = map(int, input().split(' '))
temp1 = 0
temp2 = 0
x = n // m
temp1 += x * b
if n % m != 0:
	if (n - x * m) * a < b:
		temp1 += (n - x * m) * a
	else:
		temp1 += b
temp2 = n * a
print(min(temp1, temp2))


arr = [0] * 99
arr = list(map(int, input().split()))
n = int(arr[0])
m = int(arr[1])
a = int(arr[2])
b = int(arr[3])
if m * a <= b:
	print(int(n * a))
else:
	print(int(n / m) * b + min(n % m * a, b))


(n, m, a, b) = map(int, input().split())
temp1 = n // m * b + (n - n // m * m) * a
if n % m == 0:
	temp2 = n // m * b
else:
	temp2 = (n // m + 1) * b
temp3 = n * a
ans = min(temp1, temp2, temp3)
print(ans)


(n, m, a, b) = map(int, input().split())
if a > b // m:
	print(b * (n // m) + min(n % m * a, b))
else:
	print(a * n)


(n, m, a, b) = map(int, input().split())
r = n % m
x = n // m
if m * a <= b:
	cost = n * a
else:
	cost = x * b + min(r * a, b)
print(cost)


(n, m, a, b) = input().split()
(n, m, a, b) = (int(n), int(m), int(a), int(b))
i = n // m
if n <= m:
	price = min(a * n, b)
else:
	price = min(a * (n - i * m) + i * b, a * n, (i + 1) * b)
print(price)


(n, m, a, b) = map(int, input().split())
if n % m > 0:
	x = 1
else:
	x = 0
print(min(n * a, n // m * b + n % m * a, n // m * b + x * b))


(n, m, a, b) = map(int, input().split())
sum1 = 0
cnt = 0
if a * m >= b:
	while cnt < n:
		cnt += m
		sum1 += b
	sum2 = sum1
	if cnt > n:
		cnt -= m
		sum1 -= b
		c = n - cnt
		sum1 += a * c
		cnt += c
	print(min(sum1, sum2))
else:
	sum1 += a * n
	print(sum1)


(n, m, a, b) = [int(i) for i in input().split()]
c = 0
import math
for i in range(0, math.ceil(n / m) + 1):
	cc = i * b + max(0, n - m * i) * a
	if cc < c or c == 0:
		c = cc
print(c)


n = input().split()
basic_cost = int(n[0]) * int(n[2])
if n[2] > n[3]:
	if int(n[0]) % int(n[1]) == 0:
		low_cost = int(n[0]) // int(n[1]) * int(n[3])
	else:
		low_cost = (int(n[0]) // int(n[1]) + 1) * int(n[3])
else:
	low_cost = int(n[0]) // int(n[1]) * int(n[3]) + int(n[0]) % int(n[1]) * int(n[2])
if int(n[0]) < int(n[1]) and int(n[0]) * int(n[2]) > int(n[3]):
	print(n[3])
	exit()
if basic_cost < low_cost:
	print(int(basic_cost))
else:
	print(int(low_cost))


(n, m, a, b) = [int(i) for i in input().split()]
print(min(n * a, n // m * b + (n - n // m * m) * a, ((n - 1) // m + 1) * b))


(n, m, a, b) = (int(i) for i in input().split())
if b >= a * m:
	print(n * a)
elif n % m == 0:
	print(n // m * b)
elif m > n and b < a * n:
	print(b)
elif a < b:
	print(n // m * b + (n - n // m * m) * a)
else:
	print(n // m * b + b)


n = list(map(int, input().split()))
z = n[0]
x = n[1]
v = n[2]
b = n[3]
m = min(z * v, -z // x * -b, z // x * b + z % x * v)
print(m)


x = input().split()
n = int(x[0])
m = int(x[1])
a = int(x[2])
b = int(x[3])
cost1 = a
cost2 = b / m
if cost1 <= cost2:
	print(n * a)
else:
	g = n // m * b
	rem = n % m
	d = rem * a
	if d > b:
		g += b
	else:
		g += d
	print(g)


(rides, pack_size, single_price, pack_price) = list(map(int, input().split()))
useful_pack = pack_price <= pack_size * single_price
if useful_pack:
	hibrid_cost = rides // pack_size * pack_price
	hibrid_cost += rides % pack_size * single_price
	pack_cost = rides // pack_size * pack_price
	if rides % pack_size != 0:
		pack_cost += pack_price
	cost = min(hibrid_cost, pack_cost)
else:
	cost = single_price * rides
print(cost)


(length, spe, oneway, costspe) = [int(x) for x in input().split()]
if oneway <= costspe / spe:
	print(oneway * length)
elif (length - spe * int(length / spe)) * oneway <= costspe:
	print(int(length / spe) * costspe + (length - spe * int(length / spe)) * oneway)
else:
	print((int(length / spe) + 1) * costspe)


(n, m, a, b) = [int(x) for x in input().split()]
if b / m >= a:
	print(n * a)
else:
	print(n // m * b + min(n % m * a, b))


(n, m, a, b) = map(int, input().split())
if m * a <= b:
	print(n * a)
else:
	rem = n % m
	c1 = n // m * b + (b if rem > 0 else 0)
	c2 = n // m * b + n % m * a
	fc = c1 if c1 < c2 else c2
	print(fc)


(totRides, specRides, aTicket, bTicket) = [int(x) for x in input().split()]
if specRides * aTicket < bTicket:
	Rubles = totRides * aTicket
else:
	Rubles = totRides // specRides * bTicket
	rem_Rides = totRides % specRides
	if bTicket > aTicket * rem_Rides:
		Rubles += aTicket * rem_Rides
	else:
		Rubles += bTicket
print(Rubles)


(n, m, a, b) = map(int, input().split())
c = n // m * b + n % m * a
d = n // m * b + b
e = n * a
print(min(c, d, e))


(n, m, a, b) = map(int, input().split())
if b >= a * m:
	answ = n * a
else:
	answ = n // m * b
	n -= n // m * m
	if a * n < b:
		answ += n * a
	else:
		answ += b
print(answ)


import math
(n, m, a, b) = map(int, input().split())
x = n // m * b
y = n % m * a
p = x + y
q = math.ceil(n / m) * b
r = n * a
print(min([p, q, r]))


[n, m, a, b] = [int(_) for _ in input().split()]
ans = 0
lis = [0 for _ in range(max(n, m) + 1)]
for i in range(1, m + 1):
	lis[i] = min(a * i, b)
for i in range(m + 1, n + 1):
	lis[i] = min(lis[i - m] + b, lis[i - 1] + a)
ans = lis[n]
print(ans)


def cheap_travel():
	(n, m, a, b) = map(int, input().split())
	if m * a <= b:
		print(n * a)
	else:
		v = min(n // m * b + n % m * a, (n // m + 1) * b)
		print(v)
cheap_travel()


(n, m, a, b) = map(int, input().split())
ans = 1000000000
for x in range(n + 1):
	for y in range(n + 1):
		if x + y * m >= n:
			ans = min(ans, a * x + b * y)
print(ans)


import math
(n, m, a, b) = map(int, input().split())
cost1 = n * a
cost2 = n // m * b + n % m * a
cost3 = math.ceil(n / m) * b
print(min(cost1, cost2, cost3))


q = list(map(int, input().split()))
w = []
if q[1] * q[2] > q[3]:
	w.append(q[0] % q[1] * q[2] + q[0] // q[1] * q[3])
	w.append((q[0] // q[1] + 1) * q[3])
	print(min(w))
else:
	print(q[0] * q[2])


(n, m, a, b) = map(int, input().split())
s1 = n * a
s2 = (n + m - 1) // m * b
s3 = n // m * b + n % m * a
print(min(s1, s2, s3))


t = list(map(int, input().split()))
n = t[0]
m = t[1]
a = t[2]
b = t[3]
if m * a > b:
	yo = n // m
	rem = n - yo * m
	price1 = yo * b + rem * a
	price2 = (yo + 1) * b
	print(min(price1, price2))
else:
	price = n * a
	print(price)


(n, m, a, b) = [int(i) for i in input().split()]
if a * m <= b:
	print(a * n)
elif int(n / m) * b + a * (n % m) < (int(n / m) + 1) * b:
	print(int(n / m) * b + a * (n % m))
else:
	print((int(n / m) + 1) * b)


x = list(map(int, input().split()))
n = x[0]
m = x[1]
a = x[2]
b = x[3]
lst = []
for i in range(0, n + 1):
	for j in range(0, n + 1):
		if i + m * j >= n:
			lst.append(a * i + j * b)
print(min(lst))


(n, m, a, b) = input().split()
n = int(n)
m = int(m)
a = int(a)
b = int(b)
res1 = 0
res2 = 0
p = int(n / m)
res1 += p * b
if n % m != 0:
	if (n - m * p) * a < b:
		res1 += (n - m * p) * a
	else:
		res1 += b
res2 = n * a
print(min(res1, res2))


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
alles = inlt()
anzahl = alles[0]
sticket_fahrten = alles[1]
kticket = alles[2]
ksticket = alles[3]
prize1 = 999999999
prize2 = 999999999
ende = 0
if ksticket / sticket_fahrten < kticket:
	asticket = anzahl / sticket_fahrten
	if round(asticket) == asticket:
		print(int(asticket * ksticket))
		ende = 1
	else:
		x = False
		i = 1
		asticket = anzahl / sticket_fahrten
		prize1 = math.ceil(asticket) * ksticket
		while x == False:
			anzahl -= 1
			asticket = anzahl / sticket_fahrten
			if round(asticket) == asticket:
				x = True
				prize2 = int(asticket * ksticket + i * kticket)
			elif anzahl == 0:
				x = True
				anzahl = alles[0]
				prize3 = int(anzahl * kticket)
			i += 1
else:
	print(int(anzahl * kticket))
	ende = 1
if prize1 >= prize2 and ende == 0:
	print(int(prize2))
elif prize1 < prize2 and ende == 0:
	print(int(prize1))


import sys
import math
import bisect

def solve(n, m, a, b):
	dp = [10 ** 9] * (n + m + 1)
	dp[0] = 0
	for i in range(1, n + m + 1):
		dp[i] = min(dp[i], dp[i - 1] + a)
		if i - m >= 0:
			dp[i] = min(dp[i], dp[i - m] + b)
	return min(dp[n:])

def main():
	(n, m, a, b) = map(int, input().split())
	ans = solve(n, m, a, b)
	print(ans)
main()


temp = input()
temp = temp.split(' ')
n = int(temp[0])
m = int(temp[1])
sc = int(temp[2])
mc = int(temp[3])
if mc / m < sc:
	sum = n // m * mc
	if n % m * sc >= mc:
		print(sum + mc)
	else:
		print(sum + n % m * sc)
else:
	print(n * sc)


(n, m, a, b) = map(int, input().split())
print(min(n * a, min(n // m * b + n % m * a, n // m * b + b)))


(n, m, a, b) = [int(n) for n in input().split()]
if b <= a * (n % m):
	cost = n // m * b + b
else:
	cost = n // m * b + n % m * a
for i in range(0, n + 1, m):
	c = i / m * b + (n - i) * a
	if c < cost:
		cost = c
print(int(cost))


(n, m, a, b) = map(int, input().split())
ans = 0
if b < m * a:
	temp = n % m
	ans += b * int(n / m)
	ans = ans + min(b, temp * a)
else:
	ans += n * a
print(ans)


(a, b, c, d) = map(int, input().split())
e = a % b * c + a // b * d
f = (a // b + 1) * d
g = a * c
if e > f:
	print(int(f))
elif g < e and g < f:
	print(int(g))
else:
	print(int(e))


(n, m, a, b) = map(int, input().split())
single = n * a
multiple = (n // m + (1 if n % m else 0)) * b
mul = n // m * b + (n - n // m * m) * a
print(min(single, multiple, mul))


from sys import stdin, stdout
import math
nmab = list(map(int, stdin.readline().split()))
n = nmab[0]
m = nmab[1]
a = nmab[2]
b = nmab[3]
prices = [0, 0, 0]
prices[0] = n * a
prices[1] = n // m * b + n % m * a
prices[2] = math.ceil(n / m) * b
stdout.write(str(min(prices)))


(n, m, a, b) = map(int, input().strip().split(' '))
sum1 = n * a
if n % m == 0:
	sum2 = n // m * b
elif n >= m:
	temp1 = (n // m + 1) * b
	temp2 = n // m * b + n % m * a
	sum2 = min(temp1, temp2)
elif n < m:
	sum2 = b
print(min(sum1, sum2))


total = input()
(amount_rides, abon_capacity, bilet_price, abon_price) = map(int, total.split())
if abon_capacity >= amount_rides and bilet_price * amount_rides > abon_price:
	print(abon_price)
else:
	bilet_cost = amount_rides * bilet_price
	amount_abon = amount_rides // abon_capacity
	amount_abon_cost = amount_abon * abon_price
	added_bilets_amount = amount_rides % abon_capacity
	added_bilets_cost = added_bilets_amount * bilet_price
	if added_bilets_cost > abon_price:
		added_bilets_cost = abon_price
	sum_for_abon = amount_abon_cost + added_bilets_cost
	if bilet_cost <= sum_for_abon:
		print(bilet_cost)
	else:
		print(sum_for_abon)


import math
(n, m, a, b) = map(int, input().split())
print(min(n * a, math.ceil(n / m) * b, math.floor(n / m) * b + n % m * a))


line = input().split()
n = int(line[0])
m = int(line[1])
a = int(line[2])
b = int(line[3])
if b / m > a:
	print(a * n)
else:
	p = 1
	if n % m == 0:
		p = 0
	f = b * (n // m + p)
	s = b * (n // m) + a * (n - m * (n // m))
	print(str(min(f, s)))


from math import *
(n, m, a, b) = input().split()
n = int(n)
m = int(m)
a = int(a)
b = int(b)
s1 = n * a
s2 = n // m * b + n % m * a
s3 = ceil(n / m) * b
print(min(s1, s2, s3))


[n, m, a, b] = [int(a) for a in input().split(' ')]
if a * m <= b:
	print(a * n)
elif n % m == 0:
	print(n // m * b)
else:
	subscription = n // m
	ans = subscription * b + (n - subscription * m) * a
	ans2 = subscription * b + b
	if ans < ans2:
		print(ans)
	else:
		print(ans2)


(n, m, a, b) = (int(i) for i in input().split())
if n % m == 0:
	print(min(n * a, n // m * b))
else:
	print(min(n * a, n // m * b + n % m * a, n // m * b + b))


import math
(n, m, a, b) = map(int, input().split())
price = []
price.append(n * a)
price.append(n // m * b + (n - n // m * m) * a)
price.append(math.ceil(n / m) * b)
print(min(price))


import math
n = input()
n = n.split()
m = int(n[1])
a = int(n[2])
b = int(n[3])
n = int(n[0])
if m * a > b:
	if n % m * a <= b:
		f = math.floor(n / m) * b + n % m * a
	else:
		f = math.ceil(n / m) * b
else:
	f = a * n
print(f)


from math import *
(n, m, a, b) = map(int, input().split())
print(min(n // m * b + n % m * a, n * a, n // m * b + b))


a = input().split()
l = []
for i in range(4):
	b = int(a[i])
	l.append(b)
c = l[0] * l[2]
p = []
if l[0] % l[1] == 0:
	d = l[0] // l[1] * l[3]
	p.append(d)
else:
	d = l[0] // l[1] * l[3] + l[0] % l[1] * l[2]
	e = (l[0] // l[1] + 1) * l[3]
	p.append(d)
	p.append(e)
p.append(c)
print(min(p))


info = input().split(' ')
(rides, abon_rides, cost, abon_cost) = (int(info[0]), int(info[1]), int(info[2]), int(info[3]))
if abon_rides * cost >= abon_cost:
	min_sum = rides // abon_rides * abon_cost
	if rides % abon_rides * cost < abon_cost:
		min_sum += rides % abon_rides * cost
	else:
		min_sum += abon_cost
else:
	min_sum = rides * cost
print(min_sum)


(n, m, a, b) = map(int, input().split())
k = min(b / m, a)
count = 0
if k == b / m:
	while n >= m:
		count += b
		n -= m
	if n < 0:
		n += m
		count -= b
	count += min(n % m * a, b)
if k == a:
	while n > 0:
		count += a
		n -= 1
print(count)


__author__ = 'Gleb'
(n, m, a, b) = input().split()
(n, m, a, b) = (int(n), int(m), int(a), int(b))
if a * m < b:
	print(a * n)
else:
	summ = int(n / m) * b
	n = n % m
	if a * n < b:
		print(summ + a * n)
	else:
		print(summ + b)


(n, m, a, b) = map(int, input().split())
r = 0
if b / m < a:
	temp = m
	k = n // m
	k1 = n % m
	p = min(k1 * a, b)
	print(p + k * b)
else:
	print(n * a)


(n, m, a, b) = [int(x) for x in input().split()]
z = n // m * b
w = b * m
if n <= m:
	x = n * a
	if b < x:
		print(b)
	else:
		print(x)
else:
	y1 = n // m * b + n % m * a
	y2 = n // m * b + b
	y3 = n * a
	menor = y3
	if menor > y2:
		menor = y2
		if menor > y1:
			menor = y1
	elif menor > y1:
		menor = y1
	print(menor)


(n, m, a, b) = map(int, input().split())
ans = 0
if m * a <= b:
	ans = n * a
	print(ans)
else:
	while n >= m:
		ans += b
		n = n - m
	if n != 0:
		if n * a > b:
			ans += b
		else:
			ans += n * a
	print(ans)


(n, m, a, b) = map(int, input().split())
if b / m >= a:
	print(n * a)
else:
	s = b * (n // m)
	if n // m == 0:
		if b < n * a:
			print(b)
		else:
			print(n * a)
	elif n - n // m * m > 0:
		if a < b:
			s += (n - n // m * m) * a
			if s < n * a:
				print(s)
			else:
				print(n * a)
		else:
			s += b
			if s < n * a:
				print(s)
			else:
				print(n * a)
	elif s < n * a:
		print(s)
	else:
		print(n * a)


x = [int(x) for x in input().split()]
n = x[0]
m = x[1]
a = x[2]
b = x[3]
y = [b, n % m * a]
if b / m < a:
	print(n // m * b + min(y))
else:
	print(n * a)


(n, m, a, b) = [int(x) for x in input().split()]
st = n // m
sum = (st + 1) * b if (n - st * m) * a > b else n * a + (m * a > b) * (st * (b - m * a))
print(sum)


def smaller(x, y):
	if x < y:
		return x
	return y
(N, M, A, B) = map(int, input().split())
dp = []
for i in range(0, N + 1):
	dp.append(-1)
dp[0] = 0
for i in range(0, N):
	if dp[i + 1] == -1:
		dp[i + 1] = dp[i] + A
	else:
		dp[i + 1] = smaller(dp[i + 1], dp[i] + A)
	if i + M <= N:
		if dp[i + M] == -1:
			dp[i + M] = dp[i] + B
		else:
			dp[i + M] = smaller(dp[i + M], dp[i] + B)
	elif dp[N] == -1:
		dp[N] = dp[i] + B
	else:
		dp[N] = smaller(dp[N], dp[i] + B)
print(dp[N])


import math

def solve(n, m, a, b):
	return min(n * a, n // m * b + n % m * a, (n // m + 1) * b)
(m, n, a, b) = list(map(int, input().split()))
result = solve(m, n, a, b)
print(result)


nn = list(map(int, input().rstrip().split()))
n = nn[0]
m = nn[1]
a = nn[2]
b = nn[3]
if a > b / m:
	cost = int(n / m) * b + n % m * a
	cost1 = int(n / m) * b + b
	cost = min(cost, cost1)
else:
	cost = n * a
print(int(cost))


l = list(map(int, input().split()))
k = []
n = l[0]
m = l[1]
a = l[2]
b = l[3]
s = n // m * b + b
res2 = n // m * b + n % m * a
res3 = n * a
k.append(s)
k.append(res2)
k.append(res3)
print(min(k))


(n, m, a, b) = map(int, input().split())
rides_from_one_ticket_price = n * a
rides_from_m_ticket_price = (n // m + 1) * b
count = 0
while n >= m:
	n -= m
	count += b
else:
	if n > 0:
		count += n * a
print(min(rides_from_one_ticket_price, rides_from_m_ticket_price, count))


import math

def cht(n, m, a, b):
	if m * a <= b:
		print(n * a)
		return
	else:
		print(n // m * b + min(n % m * a, b))
		return
t = input()
l = list(map(int, t.split(' ')))
cht(l[0], l[1], l[2], l[3])


import math
inp = lambda : list(map(int, input().split()))
(total, multi, onecost, multicost) = inp()
if multicost / multi < onecost:
	cost = 0
	while total >= multi:
		cost = cost + multicost
		total -= multi
	if total * onecost <= multicost:
		cost += total * onecost
	else:
		cost += multicost
	print(cost)
else:
	print(total * onecost)


mi = 1000000
(n, m, a, b) = map(int, input().split(' '))
for i in range(n + 1):
	for j in range(n + 1):
		if n <= i + m * j and mi > i * a + j * b:
			mi = i * a + j * b
print(mi)


def func(k):
	n = k[0]
	m = k[1]
	a = k[2]
	b = k[3]
	if m * a <= b:
		print(n * a)
	else:
		print(n // m * b + min(n % m * a, b))
k = list(map(int, input().split()))
func(k)


(num_rides, multi_rides, single_ticket, multi_ticket) = map(int, input().split())
single_more_efficient = single_ticket * multi_rides <= multi_ticket
if single_more_efficient:
	print(num_rides * single_ticket)
else:
	price_efficiency = multi_ticket // single_ticket
	spending = 0
	while num_rides >= multi_rides:
		num_rides -= multi_rides
		spending += multi_ticket
	if num_rides <= price_efficiency:
		spending += single_ticket * num_rides
	else:
		spending += multi_ticket
	print(spending)


(n, m, a, b) = map(int, input().split())
c = n * a
if n % m != 0:
	d = int(n // m * b + n % m * a)
	t = int((n // m + 1) * b)
	print(min(c, d, t))
else:
	r = int(n / m * b)
	print(min(c, r))


(n, m, a, b) = [int(i) for i in input().split()]
if b / m >= a:
	cost = n * a
else:
	c1 = n // m * b + n % m * a
	c2 = (int(n / m) + 1) * b
	cost = min(c1, c2)
print(cost)


line = input()
line = line.split()
n = int(line[0])
m = int(line[1])
a = int(line[2])
b = int(line[3])
flag = 0
if b >= m * a:
	flag = 1
if flag == 1:
	print(n * a)
else:
	nt = n // m
	sum = nt * b
	n = n - m * nt
	if n * a < b:
		sum = sum + n * a
	else:
		sum = sum + b
	print(sum)


(n, m, a, b) = map(int, input().split())
tn = n
cost = 0
if b / m < a:
	cost = max(n // m, 1) * b
	if n >= m:
		n = n % m
	else:
		n = 0
if n > 0:
	if b < a:
		cost += max(1, n // m) * b
	else:
		cost += n * a
print(min(a * tn, cost))


inp = input().split()
n = int(inp[0])
m = int(inp[1])
a = int(inp[2])
b = int(inp[3])
nob = 0
ans = 0
if b / m < a:
	while n - nob * m >= m:
		nob += 1
	ans = nob * b + (n - nob * m) * a
	if ans < (nob + 1) * b:
		ans = nob * b + (n - nob * m) * a
	else:
		ans = (nob + 1) * b
else:
	ans = n * a
print(ans)


(a, b, c, d) = list(map(int, input().split()))
r1 = 0
r2 = 0
s = a // b
r1 += s * d
if a % b != 0:
	if (a - b * s) * c < d:
		r1 += (a - b * s) * c
	else:
		r1 += d
r2 = a * c
print(min(r1, r2))


input_string = input()
inp = input_string.split(' ')
n = int(inp[0])
m = int(inp[1])
a = int(inp[2])
b = int(inp[3])
cost = 0
trips = 0
while trips <= n:
	cost += b
	trips += m
trips -= m
cost -= b
remaining = n - trips
cost += min(remaining * a, b)
print(min(cost, n * a))


(n, m, a, b) = [int(s) for s in input().rstrip().split(' ')]
dp = [0]
for i in range(1, n + 1):
	ans = a + dp[i - 1]
	if i - m <= 0:
		ans = min(ans, b)
	else:
		ans = min(ans, b + dp[i - m])
	dp.append(ans)
print(dp[n])


coN = 0
(n, m, a, b) = map(int, input().split())
if n < m:
	if n * a > b:
		print(b)
		exit()
coN += n // m * b
rem = n - n // m * m
if rem != 0:
	if a < b:
		coN += rem * a
	else:
		coN += b
tiN = 0
tiN = n // 1
print(min(tiN * a, coN))


(n, m, a, b) = map(int, input().split())
if a > b / m:
	if n % m * a < b:
		e = n // m * b + n % m * a
	else:
		e = n // m * b + b
else:
	e = n * a
print(e)


(a, b, x, y) = map(int, input().split(' '))
s = 0
r = 0
p = a // b
s += p * y
if a % b != 0:
	if (a - b * p) * x < y:
		s += (a - b * p) * x
	else:
		s += y
r = a * x
print(min(s, r))


[n, m, a, b] = [int(x) for x in input().split()]
if b / m >= a:
	fee = a * n
else:
	time = n // m
	fee = time * b
	left = min(n % m * a, b)
	fee += left
print(fee)


(n, m, a, b) = [float(i) for i in input().split()]
if n > m:
	if b / m <= a:
		if b > a:
			rubles = n // m * b + n % m * a
		else:
			rubles = n // m * b + (n % m > 0) * b
	else:
		rubles = n * a
elif a * n < b:
	rubles = a * n
else:
	rubles = b
print(int(rubles))


(n, m, a, b) = list(map(int, input().split()))
if n // m * b < n // m * m * a:
	x = n // m * b
else:
	x = n // m * m * a
if n % m != 0:
	if a * (n % m) < b:
		x += a * (n % m)
	else:
		x += b
print(x)


import math
(n, m, a, b) = map(int, input().split())
s1 = 0
s1 += n // m * b
s1 += n % m * a
s2 = int(math.ceil(float(n) / m) * b)
s3 = n * a
print(min(s1, s2, s3))


li = []
(n, m, a, b) = list(map(int, input().split()))
li.append((n // m + 1) * b if n % m != 0 else n // m * b)
li.append(n * a)
li.append(n // m * b + (n - n // m * m) * a)
print(min(li))


(n, m, a, b) = map(int, input().split())
if b / m < a:
	(d, r) = divmod(n, m)
	print(b * d + min(b, r * a))
else:
	print(n * a)


(n, m, a, b) = [int(x) for x in input().split()]
if m * a > b:
	left = n % m * a
	if left > b:
		ans = n // m * b + b
	else:
		ans = n // m * b + left
else:
	ans = n * a
print(ans)


(n, m, p1, pm) = map(int, input().split())
a = list()
count = 0
for i in range(n, -1, -1):
	if i + count * m >= n:
		a.append(i * p1 + count * pm)
	elif i + (count + 1) * m >= n:
		count = count + 1
		a.append(i * p1 + count * pm)
print(min(a))


(n, m, a, b) = input().split()
(n, m, a, b) = (int(n), int(m), int(a), int(b))
fac = n // m
fare = min(min((n - fac * m) * a, b) + fac * b, a * n)
print(fare)


(n, m, a, b) = [int(i) for i in input().split()]
if b / m >= a:
	s = a * n
	print(s)
else:
	s1 = n // m * b + n % m * a
	s2 = (n // m + 1) * b
	print(min(s1, s2))


(n, m, a, b) = map(int, input().split())
c = (n // m + 1) * b
d = n // m * b + n % m * a
if c < n * a or d < n * a:
	print(min(c, d))
else:
	print(n * a)


(n, m, a, b) = input().split()
n = int(n)
m = int(m)
a = int(a)
b = int(b)
total_price = 0
special_tickets = n // m
single_rides = n % m
if b < m * a:
	total_price += special_tickets * b
else:
	total_price += special_tickets * m * a
if single_rides * a < b:
	total_price += single_rides * a
else:
	total_price += b
print(total_price)


(n, m, pricen, pricem) = map(int, input().split())
if pricen * m > pricem:
	res = int(n / m) * pricem
	n %= m
	if n and n * pricen > pricem:
		res += pricem
	elif n:
		res += n * pricen
else:
	res = pricen * n
print(res)


(n, m, a, b) = map(int, input().split())
cost1 = 0
cost2 = 0
p = n // m
cost1 = p * b
if n % m != 0:
	if (n - m * p) * a < b:
		cost1 += (n - m * p) * a
	else:
		cost1 += b
cost2 = n * a
print(min(cost1, cost2))


l = list(map(int, input().split()))
(n, m, a, b) = l
prize = 0
if m * a > b:
	if n >= m:
		while n >= m:
			prize += b
			n -= m
		if n > 0:
			if n * a < b:
				prize += n * a
				n -= n
				print(prize)
			else:
				prize += b
				n -= m
				print(prize)
		else:
			print(prize)
	else:
		print(min(n * a, b))
else:
	print(n * a)


l = list(map(int, input().split()))
while [i in range(1, 1001) for i in l] != [True, True, True, True]:
	l = list(map(int, input().split()))
if l[3] / l[1] < l[2]:
	if l[0] % l[1] == 0:
		print(l[0] // l[1] * l[3])
	elif l[0] // l[1] * l[3] + l[0] % l[1] * l[2] <= (l[0] // l[1] + 1) * l[3]:
		print(l[0] // l[1] * l[3] + l[0] % l[1] * l[2])
	else:
		print((l[0] // l[1] + 1) * l[3])
else:
	print(l[0] * l[2])


def main():
	(n, m, a, b) = list(map(int, input().split(' ')))
	c = 0
	if b / m < a:
		c += n // m * b
		n %= m
	else:
		c += n * a
		n = 0
	if n != 0:
		c += min(n * a, b)
	print(c)

def __starting_point():
	main()
__starting_point()


(n, m, a, b) = [int(i) for i in input().split()]
if m * a <= b:
	print(n * a)
else:
	c = n % m
	if c == 0:
		print(n // m * b)
	if c != 0:
		d = a * c
		if d > b:
			print(b + n // m * b)
		else:
			print(d + n // m * b)


(n, m, a, b) = map(int, input().split())
x = n // m * b + n % m * a
y = n // m * b + b
z = n * a
if x <= y and x < z:
	print(x)
elif x >= y and y < z:
	print(y)
elif z > b and m > n:
	print(b)
else:
	print(z)


import math
(total_ride, special_ticket, ticket_price, special_price) = list(map(int, input().split()))
price1 = total_ride * ticket_price
rest = int(total_ride / special_ticket)
check = total_ride % special_ticket
if check > 0:
	price2 = special_price * rest + check * ticket_price
else:
	price2 = rest * special_price
rests = math.ceil(total_ride / special_ticket)
price3 = special_price * rests
print(min([price1, price2, price3]))


import sys
from random import choice, randint
inp = sys.stdin.readline
out = sys.stdout.write
flsh = sys.stdout.flush
sys.setrecursionlimit(10 ** 9)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def MI():
	return map(int, inp().strip().split())

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

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]

def LI_():
	return [int(x) - 1 for x in inp().strip().split()]

def LF():
	return [float(x) for x in inp().strip().split()]

def LS():
	return inp().strip().split()

def I():
	return int(inp().strip())

def F():
	return float(inp().strip())

def S():
	return inp().strip()

def pf(s):
	return out(s + '\n')

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	(n, m, a, b) = MI()
	if b / m >= a:
		pf(str(n * a))
	else:
		pf(str(min(n // m * b + n % m * a, n // m * b + b)))
main()


import math
(n, m, a, b) = [int(x) for x in input().split()]
if b / m > a:
	print(n * a)
elif b / m < a:
	print(n // m * b + min(n % m * a, b))
else:
	print(n * a)


(n, m, a, b) = map(int, input().split())
if m > n:
	m = n
if n * a <= n / m * b:
	print(n * a)
if n % m == 0 and n * a > n / m * b:
	print(n // m * b)
if n % m != 0 and n * a > n / m * b and (b > n % m * a):
	print(n // m * b + n % m * a)
if n % m != 0 and n * a > n / m * b and (b <= n % m * a):
	print(n // m * b + b)


(n, m, a, b) = map(int, input().split())
mm = n // m
cost1 = b * mm + (n - mm * m) * a
cost2 = n * a
cost3 = b * (mm + 1)
ans = min(cost1, cost2, cost3)
print(ans)


(n, m, a, b) = map(int, input().split())
if b / m < a:
	l = n // m * b
	n %= m
	if b < n * a:
		l += b
	else:
		l += a * n
else:
	l = a * n
print(l)


(n, m, a, b) = list(map(int, input().split()))
n_prev = n
ans = 0
if b / m >= a or (b / m < a and n * a <= b):
	print(n * a)
elif n * a > b and m > n:
	print(b)
elif b / m < a and n * a > b:
	i = 1
	while n > 2 * m:
		i += 1
		n -= m
	ans = i * b
	if a >= b and n != n_prev:
		ans += b
	elif a < b:
		while (n - m) * i > 0:
			ans += a
			n -= 1
	print(ans)


(m, n, a, b) = [int(i) for i in input().split()]
s1 = m * a
s2 = m // n * b + min(m % n * a, b)
print(min(s1, s2))


(n, m, a, b) = map(int, input().split())
(p, q) = divmod(n, m)
r1 = a * n
r2 = p * b + q * a
if q == 0:
	r3 = p * b
else:
	r3 = (p + 1) * b
print(min(r1, r2, r3))


(n, m, a, b) = tuple(map(int, input().split(' ')))
if m * a > b:
	cost = min(n // m * b + n % m * a, (n // m + 1) * b)
else:
	cost = n * a
print(cost)


(n, m, a, b) = map(int, input().split())
t = a * m
c = 0
x = n // m
n %= m
if b <= t:
	c = b * x
else:
	c = t * x
if n * a <= b:
	c += n * a
else:
	c += b
print(c)


import sys
(n, m, a, b) = map(int, input().split())
total = 0
if b / m < a:
	total += b * int(n // m)
	n = n % m
	temp = total
	total += a * n
	temp += b
	if temp < total:
		total = temp
else:
	total += a * n
print(total)


(n, m, a, b) = list(map(int, input().split()))
if float(a) < float(b) / m:
	ans = a * n
else:
	(n_big, rest) = divmod(n, m)
	ans = n_big * b + min(rest * a, b)
print(ans)


import math, sys
import heapq
from fractions import Fraction
from collections import Counter, defaultdict

def li():
	return list(map(int, sys.stdin.readline().split()))

def ls():
	return list(map(int, list(input())))

def la():
	return list(input())

def ii():
	return int(input())

def dic(x):
	return defaultdict(lambda : x)

def isPrime(n):
	i = 2
	if n == 1:
		return False
	while i <= int(math.sqrt(n)):
		if n % i == 0:
			return False
		i = i + 1
	return True

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def binarySearch(arr, x):
	(l, r) = (0, len(arr) - 1)
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return True
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return False
(n, m, a, b) = li()
ans = 0
if m * a > b:
	ans = n // m * b
	if n % m * a < b:
		ans += n % m * a
	else:
		ans += b
else:
	ans = n * a
print(ans)


(n, m, a, b) = map(int, input().split())
if n >= m:
	amt1 = n * a
	amt2 = 0
	x = 0
	while x < n:
		x += m
		amt2 += b
	if x == n:
		print(min(amt1, amt2))
	else:
		x -= m
		if a <= b:
			amt2 += a * (n - x) - b
		print(min(amt1, amt2))
else:
	print(min(n * a, b))


import sys
(n, m, a, b) = [int(x) for x in sys.stdin.readline().split()]
if b / m >= a:
	print(n * a)
else:
	res = b * (n // m)
	if n % m * a < b:
		res += n % m * a
	else:
		res += b
	print(res)


(n, m, a, b) = list(map(int, input().split()))
if b / m >= a:
	print(n * a)
elif n % m == 0:
	print(int(n / m * b))
else:
	print(min((int(n / m) + 1) * b, int(n / m) * b + n % m * a))


import sys
from math import ceil
input = sys.stdin.readline
(n, m, a, b) = map(int, input().split())
res = [0] * (n + 1)
if b <= a and m <= n:
	print(ceil(n / m) * b)
elif m > n:
	print(min(n * a, b))
else:
	for i in range(1, n + 1):
		if i - m >= 0:
			res[i] = min(res[i - 1] + a, res[i - m] + b)
		else:
			res[i] = res[i - 1] + a
	print(res[-1])


(n, m, a, b) = [int(i) for i in input().split()]
if m == 0:
	print(0)
else:
	bulk = n // m
	rest = n % m
	if b / m >= a:
		print(a * n)
	else:
		price = bulk * b
		price += min(b, rest * a)
		print(price)


(n, m, a, b) = map(int, input().split())
per = b / m
if a <= per:
	print(n * a)
else:
	runs = n // m
	special = runs * b
	print(min(special + b, special + (n - runs * m) * a))


(n, m, a, b) = input().split(' ')
n = int(n)
m = int(m)
a = int(a)
b = int(b)
if a * m > b:
	s1 = n // m
	s2 = n % m
	Sum1 = s1 * b + s2 * a
	Sum2 = (s1 + 1) * b
	Sum = min(Sum1, Sum2)
else:
	Sum = a * n
print(Sum)


s = list(map(int, input().split()))
n = s[0]
m = s[1]
a = s[2]
b = s[3]
d = []
if n % m == 0:
	if b < a * m:
		print(int(b * n / m))
	else:
		print(a * n)
elif m < n:
	if a * m < b:
		print(a * n)
	else:
		k = int(n / m)
		k = k * m
		l = n - k
		if l * a < b:
			res = int(n / m) * b + l * a
			print(res)
		else:
			res = int(n / m) * b + b
			print(res)
elif a * n > b:
	print(b)
else:
	print(a * n)


import math
(n, m, a, b) = map(int, input().split())
min_cost = n * a
for k in range(math.ceil(n / m)):
	cost = (n - k * m) * a + k * b
	if min_cost > cost:
		min_cost = cost
	if math.ceil(n / m) * b < min_cost:
		min_cost = math.ceil(n / m) * b
print(min_cost)


lst0 = input().split()
for x in range(len(lst0)):
	lst0[x] = int(lst0[x])
(n, m, a, b) = (lst0[0], lst0[1], lst0[2], lst0[3])
lst = []
lst.append(n * a)
lst.append((n // m + 1) * b)
lst.append(n // m * b + (n - n // m * m) * a)
print(min(lst))


(A, B, C, D) = input().split()
a = int(A)
b = int(B)
c = int(C)
d = int(D)
cost_trip = d / b
multi_trip = a // b
if cost_trip >= c:
	print(a * c)
elif a % b == 0:
	print(multi_trip * d)
else:
	z = a - multi_trip * b
	h = multi_trip * d + z * c
	i = (multi_trip + 1) * d
	if h > i:
		print(i)
	else:
		print(h)


(n, m, a, b) = map(int, input().split())
if b / m > a:
	print(n * a)
else:
	nofm = n // m
	n -= nofm * m
	if n * a > b:
		nofm += 1
		n = 0
	print(nofm * b + n * a)


(n, m, a, b) = map(int, input().split())
array = [0] + [1000001] * 2000
for i in range(1, n + m):
	if i % m == 0:
		array[i] = min(array[i - 1] + a, array[i - m] + b)
	else:
		array[i] = array[i - 1] + a
print(min(array[n], array[(int(n / m) + 1) * m]))


(n, m, a, b) = map(int, input().split())
print(min(n * a, min(max(0, n % m) * a, b) + n // m * b))


(n, m, a, b) = [int(x) for x in input().split()]
if m > n:
	if a * n < b:
		print(a * n)
	else:
		print(b)
elif b / m < a:
	if n % m == 0:
		print(b * (n // m))
	elif a < b:
		print(b * (n // m) + a * (n % m))
	else:
		print(b * (n // m) + b)
else:
	print(n * a)


(n, m, a, b) = input().split()
(n, m, a, b) = (int(n), int(m), int(a), int(b))
if m * a > b:
	r = n % m * a
	if r > b:
		print(int(n / m) * b + b)
	else:
		print(int(n / m) * b + r)
else:
	print(n * a)


(n, m, a, b) = map(int, input().split())
res = 0
t = 0
if m * a <= b:
	res = n * a
else:
	t = n // m
	n -= m * t
	res = t * b
	res += min(n * a, b)
print(res)


(n, m, a, b) = map(int, input().split(' '))
if m * a >= b:
	out = n // m * b
	if n % m * a >= b:
		out += b
	else:
		out += n % m * a
else:
	out = n * a
print(out)


(n, m, a, b) = list(map(int, input().split()))
q = n // m
r = n % m
s = m * a
smal1 = min(b, s)
smal2 = min(r * a, b)
ans = q * smal1 + smal2
print(ans)


from sys import exit
v = []
(n, m, a, b) = map(int, input().split())
if m * a <= b:
	p = n * a
	print(p)
else:
	p1 = n // m * b + b
	v.append(p1)
	p2 = n // m * b + n % m * a
	v.append(p2)
	print(min(v))


import sys
(n, m, a, b) = [int(x) for x in sys.stdin.readline().split()]
if b / float(m) < a:
	c = int(n / m) * b
	s = n % m
	if s * a > b:
		c += b
	else:
		c += s * a
	print(c)
else:
	print(n * a)


(n, m, a, b) = tuple((int(x) for x in input().split()))

def computeMin(n):
	if a <= b / m:
		return a * n
	else:
		return n // m * b + min(n % m * a, b)
print(computeMin(n))


def cheapTravel(n, m, a, b):
	if m * a <= b:
		return n * a
	else:
		return int(n / m) * b + min(n % m * a, b)
(no, spl, cNo, cSpl) = map(int, input().split())
print(cheapTravel(no, spl, cNo, cSpl))


def arr_inp():
	return [int(x) for x in stdin.readline().split()]
from sys import stdin
from math import ceil
(n, m, a, b) = arr_inp()
print(min(n // m * b + n % m * a, ceil(n / m) * b, a * n))


from math import ceil
X = list(map(int, input().split()))
print(min(X[0] * X[-2], ceil(X[0] / X[1]) * X[-1], X[0] // X[1] * X[-1] + (X[0] - X[0] // X[1] * X[1]) * X[-2]))


(n, m, a, b) = map(int, input().split())
per_ride_single = a
per_ride_multiple = b / m
if per_ride_single <= per_ride_multiple:
	rides = n * per_ride_single
else:
	left_rides = n % m
	rides = int(n / m) * b + min(left_rides * per_ride_single, b)
print(rides)


(n, m, a, b) = map(int, input().split())
c = [n * a]
i = 1
while True:
	if (n - m * i) * a >= 0:
		c.append(i * b + (n - m * i) * a)
		i += 1
	else:
		c.append(i * b)
		break
print(min(c))


def solve(n, m, a, b):
	dp = [None] * (n + 1)
	dp[0] = 0
	for i in range(1, n + 1):
		if i <= m:
			dp[i] = min(dp[i - 1] + a, b)
			continue
		dp[i] = min(dp[i - 1] + a, dp[i - m] + b)
	return dp[n]

def test():
	assert solve(6, 2, 1, 2) == 6
	assert solve(5, 2, 2, 3) == 8
(n, m, a, b) = [int(x) for x in input().split()]
print(solve(n, m, a, b))


S = input().split()
n = int(S[0])
m = int(S[1])
a = int(S[2])
b = int(S[3])
if a * m >= b:
	if n % m == 0:
		print(n // m * b)
	elif n % m * a < b:
		print(n // m * b + n % m * a)
	else:
		print(n // m * b + b)
else:
	print(a * n)


(n, m, a, b) = map(int, input().split())
if m * a <= b:
	print(n * a)
else:
	price = n // m * b
	n = n % m
	if n * a <= b:
		price += n * a
	else:
		price += b
	print(price)


s = input()
s = s.split()
s = [int(x) for x in s]
n = s[0]
m = s[1]
a = s[2]
b = s[3]
s = n // m * b + n % m * a
d = n // m * b + b
f = n * a
print(min(s, d, f))


s = [int(x) for x in input().split()]
(n, m, a, b) = (s[0], s[1], s[2], s[3])
q = []
y = b * (n // m) + a * (n % m)
q.append(y)
y = b * (n // m + 1)
q.append(y)
y = a * n
q.append(y)
print(min(q))


(n, m, a, b) = map(int, input().strip().split())
if n > m:
	ans = 0
	if b <= a:
		ans = n // m * b
		ans += int(n % m != 0) * b
	elif m * a > b:
		ans = n // m * b
		ans += n % m * a
	else:
		ans = n * a
	print(ans)
elif n * a > b:
	print(b)
else:
	print(n * a)


import math
(n, m, a, b) = map(int, input().strip().split())
ans = 0
if a * m > b:
	ans += n // m * b
	n %= m
else:
	ans += n * a
	n = 0
if n > 0:
	ans += min(b, n * a)
print(ans)


import math
num = input()
arr = []
count = 0
for i in range(0, len(num)):
	if num[i] == ' ':
		arr.append(int(num[count:i]))
		count = i + 1
	elif i == len(num) - 1:
		arr.append(int(num[count:len(num)]))
rides_no = arr[0]
ride_in_special = arr[1]
cost_of_single = arr[2]
cost_of_special = arr[3]
cost = 0
if math.ceil(cost_of_special / ride_in_special) <= cost_of_single:
	while rides_no > 0:
		if rides_no >= ride_in_special:
			rides_no -= ride_in_special
			cost += cost_of_special
		elif rides_no * cost_of_single > cost_of_special:
			cost += cost_of_special
			rides_no = 0
		else:
			cost += rides_no * cost_of_single
			rides_no = 0
else:
	cost = rides_no * cost_of_single
print(cost)


def solution():
	(n, m, a, b) = map(int, input().split())
	if m * a < b:
		print(n * a)
		return
	result = n // m * b
	n = n % m
	if n * a > b:
		result += b
	else:
		result += n * a
	print(result)
solution()


(n, m, a, b) = [int(x) for x in input().split()]
summ = 0
if b / m < a:
	if (n // m + 1) * b < n // m * b + n % m * a:
		print((n // m + 1) * b)
	else:
		print(n // m * b + n % m * a)
else:
	print(n * a)


(n, m, a, b) = [int(i) for i in input().split()]
import math
print(min(n * a, math.ceil(n / m) * b, n // m * b + n % m * a))


(n, m, a, b) = map(int, input().split())
res = min(n * a, n // m * b)
num = min(b, n % m * a)
print(res + num)


(n, m, a, b) = list(map(int, input().split()))
x = n * a
y = n // m * b + n % m * a
z = n // m * b + b
print(min(x, y, z))


(n, m, a, b) = map(int, input().split())
if b / m > a:
	print(n * a)
else:
	k = n // m
	ost = n % m
	if ost * a < b:
		print(k * b + ost * a)
	else:
		print((k + 1) * b)


import math
(n, m, a, b) = map(int, input().split())
sr = b / m
gr = a
if sr > gr:
	print(n * a)
else:
	cv = math.ceil(n / m)
	cost = cv * b
	cost = min(cost, (cv - 1) * b + (n - (cv - 1) * m) * a)
	print(cost)


import math
from collections import Counter

def get(f):
	return map(f, input().split())

def main():
	(n, m, a, b) = get(int)
	if b / m > a:
		print(n * a)
	else:
		card = math.floor(n / m)
		ticket = n % m
		print(min(card * b + ticket * a, (card + 1) * b))
main()


(n, m, a, b) = [int(i) for i in input().split()]
minim = n * a
i = 0
while n > 0:
	if n * a + b * i < minim:
		minim = n * a + b * i
	n -= m
	i += 1
if b * i < minim:
	minim = b * i
print(minim)


(n, m, a, b) = map(int, input().split())
z = n * a
if n // m == n / m:
	x = n // m * b
else:
	x = (n // m + 1) * b
y = n // m * b + n % m * a
print(min(y, z, x))


(n, m, a, b) = map(int, input().split(' '))
if n < m:
	if n * a > b:
		s = b
	else:
		s = n * a
elif b / m > a:
	s = n * a
elif b / m < a and n % m * a >= b:
	k = int(n / m) + 1
	s = k * b
else:
	s = int(n / m) * b + n % m * a
print(s)


inp = lambda : map(int, input().rstrip().split())
(n, m, a, b) = inp()
x = n // m
ans = min(n * a, x * b + a * (n - x * m), (x + 1) * b)
print(ans)


(n, m, a, b) = map(int, input().split())
if a * m > b:
	gr = n // m
	le = n % m
	if le * a <= b:
		s = le * a + gr * b
	if le * a > b:
		s = (gr + 1) * b
if a * m <= b:
	s = n * a
print(s)


def mult(n, m, a, b):
	d = min(n * a, n // m * b)
	c = min(b, n % m * a)
	return d + c
(n, m, a, b) = map(int, input().split(' '))
print(mult(n, m, a, b))


(n, m, a, b) = map(int, input().split())
ans = 1e+17
for i in range(0, 1001):
	cost = i * b + max(0, n - i * m) * a
	ans = min(ans, cost)
print(ans)


(n, m, a, b) = list((int(x) for x in input().split()))
if b / m >= a:
	print(n * a)
elif n % m * a > b:
	print((n // m + 1) * b)
else:
	print(n // m * b + n % m * a)


(n, m, a, b) = list(map(int, input().split()))
if b < a * m:
	partial = n // m * b
	rest = a * (n % m)
	if rest > b:
		print(partial + b)
	else:
		print(partial + rest)
else:
	print(n * a)


(n, m, a, b) = map(int, input().split())
p = n
t = n
s = 0
q = 0
l = 0
while n > 0:
	s = s + b
	n = n - m
while p > m:
	q = q + b
	p = p - m
while p > 0:
	q = q + a
	p = p - 1
while t > 0:
	l = l + a
	t = t - 1
print(min(q, s, l))


import math
(n, m, a, b) = list(map(int, input().split()))
(x, y) = (n // m, n % m)
if m <= n and b / m <= a:
	if b >= a:
		print(x * b + y * a)
	else:
		print(b * math.ceil(n / m))
else:
	print(min(n * a, b * math.ceil(n / m)))


from math import *
(n, m, a, b) = map(int, input().split())
if m > n:
	if b < a * n:
		ans = b
	else:
		ans = a * n
else:
	ans1 = ceil(n / m) * b
	f = floor(n / m)
	ans2 = (n - m * f) * a + f * b
	ans3 = n * a
	ans = min(ans1, ans2, ans3)
print(ans)


import math
(n, m, a, b) = map(int, input().split())
if a * m > b:
	k = math.floor(n / m)
	n -= m * k
	ans = k * b + n * a
	if ans > (k + 1) * b:
		ans = (k + 1) * b
	print(ans)
else:
	print(a * n)


(n, m, a, b) = map(int, input().split())
price = 0
total_sum = 0
if b / m < a:
	price = n // m * b
	tickets = n % m
	if a * tickets >= b:
		price += b
	else:
		price += a * tickets
else:
	price = a * n
print(price)


import math
t = input()
temp = t.split()
n = int(temp[0])
m = int(temp[1])
oneRidePrice = int(temp[2])
mRidePrice = int(temp[3])
mRideCheaper = False
if mRidePrice < m * oneRidePrice:
	mRideCheaper = True
if mRideCheaper == False:
	print(n * oneRidePrice)
else:
	divident = math.floor(n / m)
	mod = n % m
	cost1 = mRidePrice * divident + mod * oneRidePrice
	cost2 = (divident + 1) * mRidePrice
	costList = [cost1, cost2]
	print(min(costList))


(n, m, a, b) = map(int, input().split())
if n % m == 0:
	special_cost = n // m * b
elif n % m * a < b:
	special_cost = n // m * b + n % m * a
else:
	special_cost = (n // m + 1) * b
single_cost = n * a
print(min(special_cost, single_cost))


l = list(map(int, input().split()))
n = int(l[0])
m = int(l[1])
a = int(l[2])
b = int(l[3])
p = int(0)
if n > m:
	p = int(n / m)
	q = n % m
	if q == 0:
		if p * b <= a * n:
			print(p * b)
		else:
			print(a * n)
	elif p * b < (n - q) * a and q * a < b:
		print(p * b + q * a)
	elif p * b < (n - q) * a and q * a > b:
		print(p * b + b)
	else:
		print(p * a + q * a)
elif b <= a * n:
	print(b)
else:
	print(a * n)


(n, m, a, b) = map(int, input().split())
if b < a * m:
	resultado = n // m
	if n % m == 0:
		print(b * resultado)
	elif b < a * (n % m):
		print(b * (resultado + 1))
	else:
		print(b * resultado + a * (n % m))
else:
	print(a * n)


ans = 1000000000.0
(n, m, a, b) = map(int, input().strip().split(' '))
for i in range(n + 1):
	r = max(0, n - i * m)
	ans = min(ans, i * b + r * a)
print(ans)


(n, m, a, b) = map(int, input().split())
(num_te, num_tn) = (0, n)
menor = 1000000
for num_tn in range(0, n + 1):
	for num_te in range(0, n + 1):
		p1 = a * num_tn
		p2 = b * num_te
		if p1 + p2 < menor and num_te * m + num_tn >= n:
			menor = p1 + p2
print(menor)


(a, b, c, d) = map(int, input().strip().split())
q = a * c
h = 0
if a % b == 0:
	h = 1
	w = a // b * d
else:
	e = a // b * d + a % b * c
	r = (a // b + 1) * d
	if e > r:
		t = r
	elif r > e:
		t = e
	elif e == r:
		t = e
if h == 1:
	if q > w:
		print(w)
	else:
		print(q)
elif h == 0:
	if q > t:
		print(t)
	else:
		print(q)


import math
(n, m, a, b) = map(int, input().split())
min_sum = n // m * b + n % m * a
c = math.ceil(n / m) * b
d = n * a
res = min(min_sum, c, d)
print(res)


(n, m, a, b) = map(int, input().split())
p = n // m * b + n % m * a
q = -n // m * -b
r = n * a
print(min([p, q, r]))


(n, m, a, b) = list(map(int, input().split()))
cost = 0
u = b / m
if m > n and u * m < a * n:
	cost += int(u * m)
elif u < a and n % m == 0:
	cost += int(u * n)
elif u < a and n % m >= 1:
	if b < a:
		n += m - n % m
		cost += int(u * n)
	else:
		cost += int(u * (n - n % m) + a * (n % m))
else:
	cost += a * n
print(cost)


(n, m, a, b) = map(int, input().split())
y = n // m
x = n % m
print(min(a * n, b * (y + 1), a * x + b * y))


(n, m, a, b) = [int(__) for __ in input().strip().split()]
if b / m < a:
	print(n // m * b + min(n % m * a, b))
else:
	print(a * n)


(n, m, a, b) = input().split()
n = int(n)
m = int(m)
a = int(a)
b = int(b)
(price, temp_a, temb) = (0, 0, 0)
if m == 1 and a < b:
	price = n * a
elif m == 1 and b < a:
	price = n * b
elif m == 1 and b == a:
	price = n * a
elif m < n:
	if n % m == 0:
		temp_b = n // m * b
		temp_a = n * a
		if temp_a <= temp_b:
			price = temp_a
		else:
			price = temp_b
	elif n % m != 0:
		q = n // m
		z = n - q * m
		temp_a = a * z
		temp_b = q * b
		if b <= a:
			price = temp_b + b
		elif a < b:
			price = temp_a + temp_b
elif m > n:
	if b <= a * n:
		price = b
	else:
		price = a * n
print(price)


from math import floor, ceil

def main():
	(n, m, a, b) = map(int, input().split())
	ans = min(a * n, ceil(n / m) * b, floor(n / m) * b + a * (n - m * floor(n / m)))
	print(ans)
main()


(n, m, a, b) = map(int, input().split())
aweight = a
bweight = b / m
cost = 0
if m >= n:
	cost = min(b, a * n)
elif bweight <= aweight:
	cost = n // m * b + min(n % m * a, b)
else:
	cost = a * n
print(cost)


(n, m, a, b) = [int(x) for x in input().split()]
cost = 0
if b / m < a:
	mcnt = n // m
	cost = mcnt * b + min((n - m * mcnt) * a, b)
else:
	cost = a * n
print(cost)


(n, m, a, b) = input().split()
n = int(n)
m = int(m)
a = int(a)
b = int(b)
r = 0
s = 0
q = 0
q = n // m
r = n % m
if b * q + r * a <= a * n:
	s = q * b
	if r <= m and r * a > b:
		s = s + b
	else:
		s = s + r * a
else:
	s = a * n
print(s)


(n, m, a, b) = map(int, input().split())
r = m * a
s = b
if r == s or s > r:
	print(n * a)
elif m > n:
	if a * n > b:
		print(b)
	else:
		print(a * n)
elif n % m == 0:
	print(n // m * b)
else:
	k = n // m
	t = n - m * k
	x = (k + 1) * b
	y = k * b + a * t
	if x > y:
		print(y)
	else:
		print(x)


__author__ = 'Utena'
(n, m, a, b) = map(int, input().split())
t = 0
if m * a > b:
	t = n // m * b + min(n % m * a, b)
else:
	t = n * a
print(t)


a = input().split()
stop = int(a[0])
jump = int(a[1])
pr = int(a[2])
prj = int(a[3])
if prj / jump < pr:
	print(min(stop // jump * prj + stop % jump * pr, (stop // jump + 1) * prj))
else:
	print(stop * pr)


import math
(n, m, a, b) = map(int, input().split())
p = n // m
p1 = math.ceil(n / m)
q = n - p * m
ans = p * b + q * a
ans1 = p1 * b
ans = min(ans, ans1)
if b / m > a:
	print(n * a)
else:
	print(ans)


(n, m, a, b) = map(int, input().strip('\n').split())
cost = min(n * a, (n // m + 1) * b, n // m * b + n % m * a)
print(cost)


s = input()
s = s.split()
n = int(s[0])
m = int(s[1])
a = int(s[2])
b = int(s[3])
if m * a > b:
	if n % m * a > b:
		print((int(n / m) + 1) * b)
	else:
		print(int(n / m) * b + n % m * a)
else:
	print(n * a)


__author__ = 'sonerik'
import sys
inp = sys.stdin
(all_drives, abon_drives, ord_price, abon_price) = map(int, inp.readline().strip().split())
one_abon_price = abon_price / abon_drives
if one_abon_price < ord_price:
	abons = all_drives // abon_drives
	ords = all_drives % abon_drives
	if abon_price < ords * ord_price:
		abons += 1
		ords = 0
	print(abons * abon_price + ords * ord_price)
else:
	print(all_drives * ord_price)


import collections
import math
local = False
if local:
	file = open('B.txt', 'r')

def inp():
	if local:
		return file.readline().rstrip()
	else:
		return input().rstrip()

def ints():
	return [int(_) for _ in inp().split()]
(n, m, a, b) = ints()
if b / m > a:
	print(a * n)
else:
	ans = n // m * b
	ans += min(n % m * a, b)
	print(ans)


def cheap_travel():
	(n, m, a, b) = input().split()
	(n, m, a, b) = (int(n), int(m), int(a), int(b))
	one_ride = b / m
	amount = 0
	if a <= one_ride:
		amount = a * n
	elif a >= one_ride:
		z = int(n / m)
		n -= z * m
		try:
			one_o_ride = b / n
			if a >= one_o_ride:
				amount = z * b + b
			else:
				amount = z * b + n * a
		except ZeroDivisionError:
			amount = z * b
	print(amount)
cheap_travel()


import collections
import itertools
import sys
from collections import defaultdict, Counter
from math import sqrt, ceil
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def main():
	(n, m, a, b) = inlt()
	a1 = n // m * b + n % m * a
	a2 = n * a
	a3 = (n // m + 1) * b
	print(min([a1, a2, a3]))
main()


s = list(map(int, input().split()))
h = s[0] // s[1] * s[3] + s[0] % s[1] * s[2]
a = s[0] * s[2]
d = (s[0] + s[1]) // s[1] * s[3]
print(min(h, a, d))


(trips, special_trips, cost_1, cost_trip) = [int(i) for i in input().split()]
cost_1_final = trips * cost_1
cost_special_final = trips // special_trips * cost_trip + min(trips % special_trips * cost_1, cost_trip)
if cost_1_final < cost_special_final:
	print(cost_1_final)
else:
	print(cost_special_final)


(n, m, a, b) = map(int, input().split())
total = 0
if m * a <= b:
	z = n * a
else:
	z = int(n / m) * b + min(n % m * a, b)
print(int(z))


from __future__ import division, print_function
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from math import ceil, floor, log, sqrt, factorial, pow, pi

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def dfs(v, c):
	if visited[v]:
		if col[v] != c:
			print('-1')
			exit()
		return
	col[v] = c
	visited[v] = 1
	for i in graph[v]:
		dfs(i, c ^ 1)

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)
	print(l)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d.keys():
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = {}
	for i in range(n):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans
(n, m, a, b) = mi()
if b / m > a:
	print(n * a)
else:
	print(n // m * b + min(n % m * a, b))


(n, m, a, b) = map(int, input().split())
if n // m * b + b <= n // m * b + n % m * a:
	sb = n // m * b + b
else:
	sb = n // m * b + n % m * a
sa = n * a
if sa > sb:
	print(sb)
else:
	print(sa)


(n, m, a, b) = map(int, input().split(' '))
if n < m and b < n * a:
	print(b)
	exit()
if n < m and b > n * a:
	print(n * a)
	exit()
rem = n // m
cost = rem * b
rem2 = n - rem * m
if rem2 * a > rem2 * b:
	cost += b
else:
	cost += rem2 * a
cost1 = n * a
print(min(cost, cost1))


(n, m, a, b) = [int(f) for f in input().split()]
print(min(n * a, b * (n // m) + b, n // m * b + a * (n - m * (n // m))))


(n, m, a, b) = map(int, input().split())
if a > b / m:
	rem = n % m
	if rem == 0:
		print(n * b // m)
	else:
		lower = n - rem
		upper = lower + m
		tot1 = lower * b // m + rem * a
		tot2 = upper * b // m
		if tot1 < tot2:
			print(tot1)
		else:
			print(tot2)
else:
	print(n * a)


(n, m, a, b) = [int(i) for i in input().split()]
total = 0
if b / m <= a:
	limit = m
	cost = b
else:
	limit = 1
	cost = a
while n >= limit:
	n -= limit
	total += cost
if n * a <= b:
	total += n * a
else:
	total += b
print(str(total))


inp = list(map(int, input().split()))
(n, m, a, b) = (inp[0], inp[1], inp[2], inp[3])
print(n // m * min(b, m * a) + min(n % m * a, b))


(n, m, a, b) = map(int, input().split())
if n < m:
	if n * a < b:
		print(n * a)
	else:
		print(b)
elif b / m < a:
	x = n % m
	y = n // m
	if n % m * b < a:
		if x == 0:
			print(y * b)
		else:
			print(y * b + 1 * b)
	else:
		print(x * a + y * b)
else:
	print(n * a)


import math
(n, m, a, b) = [int(i) for i in input().split()]

def getMinCost():
	if n == 0:
		return 0
	elif b / m > a:
		return n * a
	elif a > b:
		return math.ceil(n / m) * b
	elif m > n and b < n * a:
		return b
	else:
		return math.floor(n / m) * b + n % m * a
minCost = getMinCost()
print(minCost)


import sys

def check_first(n, m, a):
	ans = 0
	while n > 0:
		n -= 1
		ans += a
	return ans

def check_second(n, m, a, b):
	ans = 0
	if b < a:
		while n > 0:
			n -= m
			ans += b
		return ans
	else:
		while n > 0:
			if n - m >= 0:
				n -= m
				ans += b
			else:
				n -= 1
				ans += a
	return ans

def main():
	(n, m, a, b) = map(int, sys.stdin.readline().split())
	if m > n and n != 1:
		sys.stdout.write(f'{b}')
	else:
		sys.stdout.write(f'{min(check_first(n, m, a), check_second(n, m, a, b))}')
main()


(n, m, a, b) = map(int, input().split())
rm = 0
mn = 0
rm = n % m
if rm == 0:
	if n / m * b <= n * a:
		mn = n / m * b
	else:
		mn = n * a
else:
	n = n - rm
	if n / m * b <= n * a:
		mn = n / m * b
	else:
		mn = n * a
	if b < a:
		mn += b
	else:
		mn += a * rm
if m > n:
	if b < mn:
		print(int(b))
	else:
		print(int(mn))
else:
	print(int(mn))


(n, m, a, b) = map(int, input().rstrip().split())
f = n // m * b + n % m * a
t = (n // m + 1) * b
r = n * a
print(min(f, r, t))


import math
string = input().split(' ')
n = int(string[0])
m = int(string[1])
a = int(string[2])
b = int(string[3])
combination = n // m * b + a * (n % m)
print(min(a * n, int(math.ceil(n / m) * b), combination))


(n, m, a, b) = map(int, input().split())
price = b / m
raskhod1 = a * n
raskhod2 = b * (n // m)
if m > n and b < a * n:
	print(b)
elif m > n and b >= a * n:
	print(a * n)
elif a < price:
	print(raskhod1)
elif n % m == 0:
	print(raskhod2)
elif raskhod2 + a * (n % m) < raskhod2 + b:
	print(raskhod2 + a * (n % m))
else:
	print(raskhod2 + b)


(n, m, a, b) = map(int, input().split())
if m * a <= b:
	print(n * a)
else:
	x = int(n / m // 1)
	money = x * b
	if (n - m * x) * a <= b:
		money = money + (n - m * x) * a
	else:
		money = money + b
	print(money)


import math
(n, subscription_n, n_cost, subscription_cost) = [int(x) for x in input().split()]
if subscription_n / subscription_cost <= 1 / n_cost:
	print(n_cost * n)
	exit()
if subscription_cost <= n_cost:
	print(subscription_cost * math.ceil(n / subscription_n))
	exit()
result_cost = 0
after_sub_n = 0
while n > 0:
	after_sub_n += 1
	if after_sub_n * n_cost >= subscription_cost:
		result_cost += subscription_cost
		n -= subscription_n - after_sub_n
		after_sub_n = 0
	n -= 1
result_cost += after_sub_n * n_cost
print(result_cost)


import math
a = list(map(int, input().split()))
k = math.ceil(a[0] / a[1]) * a[3]
k2 = (a[0] - math.floor(a[0] / a[1]) * a[1]) * a[2] + math.floor(a[0] / a[1]) * a[3]
k3 = a[0] * a[2]
l = [k, k2, k3]
print(min(l))


(n, m, a, b) = list(map(int, input().split(' ')))
if a * m < b:
	print(n * a)
else:
	res = n % m * a + (n - n % m) // m * b
	aux = (n + m - n % m) // m * b
	print(min(res, aux))


(n, m, a, b) = list(map(int, input().split()))
c = n % m
ans = min(n * a, n // m * b + c * a)
if c != 0:
	ans = min(ans, (n // m + 1) * b)
print(ans)


nmab = input().split()
n = int(nmab[0])
m = int(nmab[1])
a = int(nmab[2])
b = int(nmab[3])
x = (n // m + 1) * b
y = n * a
z = n // m * b + n % m * a
print(min(x, y, z))


(n, m, a, b) = map(int, input().split(' '))
if b / m >= a:
	print(a * n)
else:
	r = n % m
	q = n // m
	mini = q * b + r * a
	maxi = (q + 1) * b
	print(min(mini, maxi))


(n, m, a, b) = map(int, input().split())
abon = n // m * b + n % m * a
proezd = n * a
abon2 = (n // m + 1) * b
if proezd <= abon and proezd <= abon2:
	print(proezd)
elif abon <= proezd and abon <= abon2:
	print(abon)
elif abon2 <= proezd and abon2 <= abon:
	print(abon2)


(n, m, a, b) = list(map(int, input().split()))
onem = m / b
onen = 1 / a
if onem <= onen:
	print(n * a)
else:
	sum = n // m * b
	if (n - n // m * m) * a >= (n // m + 1) * b - sum:
		print((n // m + 1) * b)
	else:
		print(sum + (n - n // m * m) * a)


(n, m, a, b) = map(int, input().split())
l = []
for i in range(0, n + 1):
	for j in range(0, n + 1):
		if i + j * m >= n:
			l.append(a * i + b * j)
print(min(l))


(a, b, c, d) = map(int, input().split())
if a % b == 0:
	r = a // b
else:
	r = a // b + 1
p = r * d
q = a * c
x = a // b * d + a % b * c
y = min(p, q)
print(min(x, y))


(n, m, a, b) = map(int, input().split())
t = n // m * b + n % m * a
r = n // m * b + b
print(min(n * a, t, r))


import math
(n, m, a, b) = map(int, input().split())
small = a if a < b else b
if n <= m and a * n > b:
	print(b)
elif m * a > b:
	p = n // m * b + min(b, n % m * a)
	print(int(p))
else:
	p = n * a
	print(int(p))


(n, m, a, b) = map(int, input().strip().split(' '))
s1 = n * a
if n // m == 0:
	s2 = b
	print(min(s1, s2))
else:
	s2 = n // m * b + n % m * a
	s3 = (n // m + 1) * b
	print(min(s1, s2, s3))


from sys import stdin, stdout
data = stdin.readline().rstrip().split(' ')
n = int(data[0])
m = int(data[1])
a = int(data[2])
b = int(data[3])
m_rate = b / m
if m_rate < a:
	m_rides = n // m
	b_total = int(m_rides * b)
	a_total = int(n % m * a)
	if a_total > b:
		stdout.write(str(b_total + b))
	else:
		stdout.write(str(b_total + a_total))
else:
	stdout.write(str(int(a * n)))


(n, m, a, b) = map(int, input().split())
allRideAtCostA = n * a
specialRideCost = n // m * b
remainingRideCost = min(n % m * a, b)
totalcost = specialRideCost + remainingRideCost
print(min(allRideAtCostA, totalcost))


(n, m, a, b) = map(int, input().split(' '))
res1 = n // m * b + n % m * a
res2 = n * a
res3 = (n + m - 1) // m * b
print(min(res1, res2, res3))


s = list(map(int, input().split()))
n = s[0]
m = s[1]
a = s[2]
b = s[3]
s = n % m * a + n // m * b
c = (n // m + 1) * b
z = n * a
x = min(c, s, z)
print(x)


(n, m, a, b) = map(int, input().split())
cost = 0
while n != 0:
	if n > m and a * m >= b:
		x = int(n / m)
		n = n % m
		cost += x * b
	if n > m and b > m * a:
		cost += a * n
		n = 0
	if n <= m:
		x = a * n
		if x < b:
			cost = cost + x
			n = 0
		else:
			cost = cost + b
			n = 0
print(cost)


(n, m, a, b) = map(int, input().split(' '))
sum = 0
c = m * a
d = min(c, b)
if d == b:
	if n % m == 0:
		sum += n // m * b
	else:
		sum += n // m * b + min(n % m * a, b)
else:
	sum += a * n
print(sum)


(n, m, a, b) = tuple(map(int, input().split()))
if b / m < a:
	f = n // m
	rem = n - f * m
	if rem * a < b:
		print(f * b + rem * a)
	else:
		print((f + 1) * b)
else:
	print(n * a)


import math
list = input().split()
n = int(list[0])
m = int(list[1])
a = int(list[2])
b = int(list[3])
c1 = a * n
c2 = n // m * b + n % m * a
c3 = (n // m + 1) * b
if c1 <= c2 and c1 <= c3:
	print(c1)
elif c2 <= c1 and c2 <= c3:
	print(c2)
else:
	print(c3)


(a, b, c, d) = list(map(int, input().split()))
dd = d / b
if dd > c:
	print(c * a)
else:
	cnt = a // b
	cnt2 = a % b
	print(min(cnt * d + cnt2 * c, (cnt + 1) * d))


from sys import stdin
import math
inp = lambda : stdin.readline().strip()
(n, m, a, b) = [int(x) for x in inp().split()]
if a * m <= b:
	print(a * n)
else:
	ans = n // m * b
	r = n % m
	ans += min(a * r, b)
	print(ans)


while True:
	try:
		data = input()
		(n, m, a, b) = [int(i) for i in data.split()]
		if b == m * a:
			print(n * a)
		else:
			normal = n * a
			special_part1 = n // m * b
			if n % m * a <= b:
				special_part2 = n % m * a
				special = special_part1 + special_part2
			else:
				special_part2 = b
				special = special_part1 + special_part2
			if normal < special:
				print(normal)
			else:
				print(special)
	except:
		break


(n, m, a, b) = map(int, input().split())
if n < m:
	print(min(b, a * n))
	exit()
print(min(n // m * b + n % m * a, a * n, (n + m - 1) // m * b))


def solve():
	if b / m >= a:
		return a * n
	else:
		cost = 0
		remainder = n - n // m * m
		cost += n // m * b
		if remainder * a > b:
			cost += b
			return cost
		else:
			cost += remainder * a
			return cost
(n, m, a, b) = map(int, input().split())
print(solve())


a = [int(x) for x in input().split()]
if a[1] * a[2] <= a[3]:
	print(a[0] * a[2])
else:
	print(a[0] // a[1] * a[3] + min(a[3], a[0] % a[1] * a[2]))


import math
(n, m, a, b) = map(int, input().split())
unit1 = a
unit2 = b / m
option1 = n * unit1
option2 = n // m * b + b
option3 = n // m * b + n % m * a
print(min(option1, min(option2, option3)))


(n, m, a, b) = map(int, input().split())
c = n * a
d = n // m * b + n % m * a
e = n // m * b + b
if n < m and (b < a or b < n * a):
	print(b)
elif n % m > 0 and n % m < m and (e < d):
	print(e)
else:
	print(min(c, d))


import math
rs = 0
(n, m, a, b) = (int(x) for x in input().split())
if b / m < a:
	rs += math.floor(n / m)
	spc_tic = rs * b
	rs = n % m
	if b < a * rs:
		no_tic = b
	else:
		no_tic = rs * a
	fin = no_tic + spc_tic
else:
	fin = n * a
print(fin)


(n, m, a, b) = map(int, input().split())
satu = n * a
special = 0
special1 = 0
i = 0
while i < n:
	if n - i - m >= 0:
		special += b
		i += m
	else:
		special += a
		i += 1
j = 0
while j < n:
	special1 += b
	j += m
harga = [satu, special, special1]
print(min(harga))


import math
(n, m, a, b) = [int(k) for k in input().split()]
maxspecial = math.ceil(n / m)
price = []
for i in range(0, maxspecial + 1):
	remain = max(0, n - m * i)
	tempt = remain * a + i * b
	price.append(tempt)
print(min(price))


(n, m, a, b) = [int(x) for x in input().split()]
if b / m >= a:
	print(a * n)
else:
	p = b * (n // m) + a * (n - n // m * m)
	q = b * (n // m + 1)
	print(min(p, q))


def input_int():
	return int(input())

def input_str():
	return str(input())

def get_result(arr, s):
	pass
(n, m, a, b) = map(int, input().split())
c = b / m
if c <= a:
	k = int(n / m)
	print(k * b + min((n - k * m) * a, b))
else:
	print(n * a)


(n, m, a, b) = map(int, input().split())
direct = cost = n * a
together = (n - n % m) / m * b + n % m * a
if n % m == 0:
	route = n / m * b
else:
	a = n % m
	n = n - a
	route = (n / m + 1) * b
price = list()
price.append(direct)
price.append(int(route))
price.append(int(together))
print(min(price))


def minsum(n, m, a, b):
	if m * a <= b:
		return n * a
	else:
		return n // m * b + min(n % m * a, b)

def main():
	(n, m, a, b) = map(int, input().split())
	print(minsum(n, m, a, b))
main()


(z, zz) = (input, lambda : list(map(int, z().split())))
(szz, dgraphs, mod) = (lambda : sorted(zz()), {}, 10 ** 9 + 7)
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
(n, m, a, b) = zz()
sp = n // m
total = n * a
if m * a < b:
	print(n * a)
else:
	t = min(sp * b + n % m * a, ceil(n / m) * b)
	print(t)


nmab = input().split(' ')
n = int(nmab[0])
m = int(nmab[1])
a = int(nmab[2])
b = int(nmab[3])
t = b / m
if a < t:
	print(str(n * a))
else:
	k = n // m
	f = k * b
	r = n % m
	if r * a < b:
		f += r * a
	else:
		f += b
	print(str(f))


from math import ceil
(n, m, a, b) = [int(i) for i in input().split()]
price = 0
if b / m < a:
	if b < a:
		price = ceil(n / m) * b
	elif n <= m and b <= a * n:
		price = b
	else:
		while n >= m:
			price += b
			n -= m
		if n > 0:
			price += n * a
else:
	price = n * a
print(price)


from math import ceil
(n, m, a, b) = map(int, input().strip().split())
t1 = n * a
t2 = ceil(n / m) * b
t3 = b / m * (n - n % m) + a * (n % m)
print(ceil(min(t1, t2, t3)))


(n, m, a, b) = map(int, input().split())

def findMinSpending(n, m, a, b):
	minSpending = min(n * a, n // m * b + n % m * a, n // m * b + b)
	return minSpending
print(findMinSpending(n, m, a, b))


import sys
(n, m, a, b) = map(int, input().split())
oneByB = b / m
ans = 0
if oneByB < a:
	abbonements = n // m
	tickets = abbonements * m
	ans = ans + abbonements * b
	n = n - tickets
	if a * n < b:
		ans += a * n
	else:
		ans += b
else:
	ans = n * a
print(ans)


(n, m, a, b) = list(map(int, input().split()))
print(min(n * a, n // m * b + n % m * a, (n // m + 1) * b))


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
(N, M, A, B) = map(int, input().split())
ans = N * A
if N % M == 0:
	ans = min(ans, N // M * B)
else:
	ans = min(ans, N // M * B + B, N // M * B + N % M * A)
print(ans)


import sys
parametrs = list(map(int, input().split()))
n = parametrs[0]
m = parametrs[1]
a = parametrs[2]
b = parametrs[3]
variants = []
if n % m == 0:
	n_abonements = n // m
else:
	n_abonements = n // m + 1
min_price = 10000000
for trip in range(0, n + 1, 1):
	for abonement in range(0, n_abonements + 1, 1):
		trips = trip + abonement * m
		price = trip * a + abonement * b
		if trips >= n:
			if price < min_price:
				min_price = price
print(min_price)


l = list(map(int, input().split(' ')))
n_ride = l[0]
sp_ride = l[1]
one_ticket = l[2]
sp_ticket = l[3]
total = 0
if sp_ticket / sp_ride >= one_ticket:
	print(n_ride * one_ticket)
elif sp_ride <= n_ride:
	k = int(n_ride / sp_ride)
	m = n_ride % sp_ride
	total = total + k * sp_ticket
	if sp_ticket >= one_ticket:
		total = total + m * one_ticket
		print(total)
	else:
		if m != 0:
			total = total + sp_ticket
			print(total)
		if m == 0:
			print(total)
elif sp_ride > n_ride:
	if one_ticket * n_ride >= sp_ticket:
		print(sp_ticket)
	else:
		print(one_ticket * n_ride)


import math

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def dva():
	(n, m) = map(int, input().split())
	b = [int(x) for x in input().split()]
	return (n, m, b)

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)
(n, m, a, b) = map(int, input().split())
s1 = n * a
s3 = -1
if n % m == 0:
	s2 = n // m * b
else:
	s2 = (n // m + 1) * b
	s3 = n // m * b + (n - n // m * m) * a
if s3 == -1:
	s3 = s2
print(min(s1, s2, s3))


a = input().split()
firstArr = [int(x) for x in a]
(n, m, a, b) = firstArr
mTicket = n // m * b
mTicket += n % m * a
allTickets = n * a
anotherMTicket = (n // m + 1) * b
print(min(mTicket, min(allTickets, anotherMTicket)))


import math
(n, m, a, b) = input().split()
n = int(n)
m = int(m)
a = int(a)
b = int(b)
if b < m * a:
	m_ticket = n // m
	p1 = m_ticket * b + (n - m_ticket * m) * a
	p2 = math.ceil(n / m) * b
	if p1 > p2:
		print(p2)
	else:
		print(p1)
else:
	print(n * a)


import sys
import math

def main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def sinp():
	return sys.stdin.readline().strip()

def iinp():
	return int(input())

def ninp():
	return map(int, sys.stdin.readline().strip().split())

def linp():
	return list(map(int, sys.stdin.readline().strip().split()))

def p(a):
	print(a)
(n, m, a, b) = ninp()
if a < b / m:
	print(n * a)
else:
	ride = n // m
	s = ride * b
	n = n - ride * m
	if n * a >= b:
		print(s + b)
	else:
		print(s + n * a)


from math import ceil
(n, m, a, b) = list(map(int, input().split()))
f = n * a
s = ceil(n / m) * b
t = n // m * b + (n - n // m * m) * a
print(min(f, s, t))


(n, m, a, b) = map(int, input().split())
if b / m < a:
	tickets = int((n - n % m) / m)
	if (n - tickets * m) * a < b:
		print(b * tickets + (n - tickets * m) * a)
	else:
		print(b * (1 + tickets))
else:
	print(a * n)


x = [int(q) for q in input().split()]
n = x[0]
m = x[1]
a = x[2]
b = x[3]
ans = min(n // m * b + n % m * a, (n // m + 1) * b, n * a)
print(ans)


(n, m, a, b) = map(int, input().split())
if m * a <= b:
	print(n * a)
else:
	x = n / m
	from math import ceil
	x1 = ceil(x)
	xy = n // m
	x1 = x1 * b
	x2 = min(n % m * a, b)
	x3 = xy * b + x2
	print(min(x1, x3))


import math
(n, m, a, b) = map(int, input().split())
sum1 = 0
while n > 0:
	if n >= m:
		x = m * a
		y = b
		sum1 = sum1 + min(x, y)
	else:
		x = a * n
		y = math.ceil(b / m)
		y = b
		sum1 = sum1 + min(x, y)
	n = n - m
print(sum1)


(n, m, a, b) = [int(x) for x in input().split()]
if a < b / m:
	print(n * a)
else:
	countM = n // m
	total = (n - countM * m) * a + countM * b
	countM += 1
	countM *= b
	print(min(total, countM))


(n, m, a, b) = list(map(int, input().split(' ')))
x = n // m
s1 = x * b
if b >= m * a:
	print(n * a)
else:
	print(s1 + min(n % m * a, b))


(n, m, a, b) = map(int, input().split())
p = n * a
if b // m >= a:
	print(p)
elif n < m and p <= b:
	print(p)
elif n < m and p > b:
	print(b)
else:
	print(min(n // m * b + n % m * a, (n // m + 1) * b))


import sys
(n, m, a, b) = [int(i) for i in input().split()]
min_sum = 0
ortp = int(n * a)
if n >= m:
	r = n % m
	nm = int(n / m)
	if r == 0:
		mrtp = nm * b
	else:
		mrtp = nm * b + (n - m * nm) * a
		mrtp2 = nm * b + b
		if mrtp2 < mrtp:
			mrtp = mrtp2
	min_sum = mrtp
	if mrtp > ortp:
		min_sum = ortp
else:
	min_sum = b
	if b > ortp:
		min_sum = ortp
print(min_sum)


(n, m, a, b) = (int(z) for z in input().split())
c_p = b / m
if m >= n and b <= a * n:
	print(b)
	exit()
if c_p >= a:
	print(int(n * a))
else:
	if n % m == 0:
		print(int(b * (n / m)))
	if n % m != 0 and b <= a:
		print(int(b * (int(n / m) + 1)))
	if n % m != 0 and b > a:
		ans = int(n / m) * b + n % m * a
		print(int(ans))


(n, m, a, b) = map(int, input().split())
if m * a <= b:
	print(n * a)
else:
	p = n // m * b
	if n % m * a > b:
		p += b
	else:
		p += n % m * a
	print(p)


(n, m, a, b) = map(int, input().split())
if n >= m:
	k = n // m
	total3 = (k + 1) * b
	pr1 = k * b
	z = n - k * m
	if z > 0:
		pr2 = z * a
		total = pr1 + pr2
	else:
		total = pr1
	total2 = a * n
	print(min(total, total2, total3))
else:
	total = b
	total2 = a * n
	print(min(total, total2))


(n, m, a, b) = [int(_) for _ in input().split()]
aisCheaper = True
if b / m < a:
	aisCheaper = False
if aisCheaper:
	print(a * n)
else:
	price = n // m * b
	c = n % m
	price += min(c * a, b)
	print(price)


x = input()
x = x.split()
t = []
for i in x:
	t.append(int(i))
times = t[0]
Mride = t[1]
TypicallCost = t[2]
MrideCost = t[3]
print(min(times * TypicallCost, (times // Mride + (times % Mride != 0)) * MrideCost, times // Mride * MrideCost + times % Mride * TypicallCost))


(n, abon_count, one_price, ab_price) = (int(i) for i in input().split())
if ab_price < one_price * abon_count:
	print(n // abon_count * ab_price + min(n % abon_count * one_price, ab_price))
else:
	print(n * one_price)


(n, m, a, b) = map(int, input().split())
r = []
r1 = n // m * b + n % m * a
r.append(r1)
r2 = a * n
r.append(r2)
r3 = (n // m + 1) * b
r.append(r3)
print(min(r))


import math
st = ''

def func(n, m, a, b):
	per_ride = b / m
	if per_ride >= a:
		return a * n
	p = n % m
	k = n // m
	return min(k * b + p * a, (k + 1) * b)
for _ in range(1):
	(n, m, a, b) = map(int, input().split())
	st += str(func(n, m, a, b)) + '\n'
print(st)


(n, m, a, b) = map(int, input().split())
x = divmod(n, m)
y = x[0] * b + x[1] * a
h = x[0] * b + b
print(min(y, h, n * a))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	(n, m, a, b) = LI()
	r = n * a
	t = n // m * b + n % m * a
	if r > t:
		r = t
	t = (n + m) // m * b
	if r > t:
		r = t
	return r
print(main())


x = [int(item) for item in input().split()]
n = x[0]
m = x[1]
a = x[2]
b = x[3]
if b / m < a:
	if b > a * (n % m):
		result = int(n / m) * b + a * (n % m)
	else:
		result = (int(n / m) + 1) * b
else:
	result = n * a
print(result)


inp = input().split()
n = int(inp[0])
m = int(inp[1])
a = int(inp[2])
b = int(inp[3])
sumary = min(b, a * m)
print(min(sumary * (n // m + 1), sumary * (n // m) + (n - n // m * m) * a))


import sys
import math as mt
input = sys.stdin.buffer.readline
t = 1
for __ in range(t):
	(n, m, a, b) = map(int, input().split())
	ans = 0
	if a < b / m:
		print(n * a)
	else:
		j = 0
		while n > j + m:
			ans += b
			j += m
		ans += min(b, (n - j) * a)
		print(ans)


(n, m, a, b) = [int(i) for i in input().split()]
k1 = n * a
k2 = n // m * b + n % m * a
k3 = (n // m + (1 if n % m > 0 else 0)) * b
print(min(k1, k2, k3))


def cheap_travels():
	inp = [int(num) for num in input().split(' ')]
	(total_trip, m_ride, single_ride_cost, m_ride_cost) = (inp[0], inp[1], inp[2], inp[3])
	if m_ride * single_ride_cost > m_ride_cost:
		total_m_ride_trip = total_trip // m_ride
		single_rides = total_trip % m_ride
		return total_m_ride_trip * m_ride_cost + min(single_rides * single_ride_cost, m_ride_cost)
	else:
		return total_trip * single_ride_cost
print(cheap_travels())


(n, m, a, b) = map(int, input().split())
smin = min(m * a, b)
op = 0
while n > 0:
	if n > m:
		op += smin
		n -= m
	elif a * n <= b:
		op += a * n
		n -= n
	else:
		op += b
		n -= m
print(op)


(kolvo, kolvoabon, price1, priceabon) = map(int, input().split())
s = 0
x = kolvo // kolvoabon
z = kolvo % kolvoabon
f = True
if kolvoabon >= kolvo and priceabon <= price1 * kolvo:
	s = priceabon
else:
	if x * priceabon <= price1 * x * kolvoabon:
		s += x * priceabon
	else:
		s += price1 * kolvo
		f = False
	if f:
		if priceabon <= price1 * z:
			s += priceabon
		else:
			s += price1 * z
print(s)


(n, m, a, b) = list(map(int, input().split()))
if b >= m * a:
	print(n * a)
else:
	k = n // m
	l = n % m
	if l <= m and l * a > b:
		print(k * b + b)
	else:
		print(k * b + l * a)


_1 = '466a'
(n, m, a, b) = map(int, input().split())
e = n % m * a + n // m * b
f = (n // m + 1) * b
g = n * a
if e > f:
	print(int(f))
elif g < e and g < f:
	print(int(g))
else:
	print(int(e))


(n, a, b, c) = map(int, input().split())
x = k = 0
if b <= c / a:
	print(n * b)
if b > c / a:
	x = n // a * c
	n = n % a
	if n * b <= c:
		x = x + n * b
	else:
		x = x + c
	print(x)


s = input().split()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])
if b * c < d:
	print(a * c)
elif a % b == 0:
	print(a // b * d)
elif a % b * c < d:
	print(a // b * d + a % b * c)
else:
	print(a // b * d + d)


def solve(n, m, a, b):
	if a <= b / m:
		return a * n
	else:
		special_tickets = n // m
		single_tickets = n % m
		return min(a * single_tickets + b * special_tickets, b * (special_tickets + 1))

def main():
	[n, m, a, b] = [int(i) for i in input().strip().split()]
	result = solve(n, m, a, b)
	print(result)
main()


(n, m, a, b) = map(int, input().split())
x = a * n
y = n // m * b
z = n - m * (n // m)
q = z * a
q1 = y + q
w = n // m + 1
w1 = w * b
print(min(x, q1, w1))


info = list(map(int, input().split()))
n = info[0]
m = info[1]
a = info[2]
b = info[3]
No_Special = n * a
Special_Times = n // m
if Special_Times == n:
	Special_Cost = Special_Times * b
elif Special_Times * b + (n - Special_Times * m) * a < Special_Times * b + b:
	Special_Cost = Special_Times * b + (n - Special_Times * m) * a
else:
	Special_Cost = Special_Times * b + b
if Special_Cost > No_Special:
	print(No_Special)
else:
	print(Special_Cost)


(n, m, a, b) = map(int, input().split())
import math
p = math.ceil(n / m)
ans = min(a * n, p * b)
k = int(n / m)
for i in range(1, k + 1):
	ans = min(ans, a * (n - i * m) + b * i)
print(ans)


import math
nmab = input().split(' ')
n = int(nmab[0])
m = int(nmab[1])
a = int(nmab[2])
b = int(nmab[3])
SINGLE = a * n
PASS = math.ceil(n / m) * b
BEST = min(SINGLE, PASS)
for i in range(math.floor(n / m), 0, -1):
	rem = (n - i * m) * a
	curr = i * b + rem
	BEST = min(BEST, curr)
print(BEST)


import sys
(n, m, a, b) = map(int, sys.stdin.readline().split())
if n * a < b * int(n / m) + min(a * (n % m), b):
	print(n * a)
else:
	print(b * int(n / m) + min(a * (n % m), b))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def isqrt(n):
	x = n
	y = (x + 1) // 2
	while y < x:
		x = y
		y = (x + n // x) // 2
	return x

def abs(x):
	return x if x >= 0 else -x
for t in range(1):
	(n, m, a, b) = list(map(int, input().split()))
	if a * m <= b:
		print(a * n)
	else:
		mini = min(n % m * a, b)
		print(n // m * b + mini)


z = [int(X) for X in input().split()]
n = z[0]
m = z[1]
a = z[2]
b = z[3]
if b / m >= a:
	print(a * n)
else:
	cost = 0
	e = n // m
	cost += e * b
	rem = n % m * a
	if rem <= b:
		cost += rem
		print(cost)
	else:
		cost += b
		print(cost)


import math
(n, m, a, b) = [int(x) for x in input().split()]
h = int(n / m)
if n >= m:
	if a <= b:
		s = h * b + (n - h * m) * a
		print(min(s, n * a))
	else:
		q = math.ceil(n / m)
		print(min(q * b, n * a))
elif n * a >= b:
	print(b)
else:
	print(n * a)


(n, m, a, b) = list(map(int, input().strip().split(' ')))
vals = [n * a, n // m * b + n % m * a, n // m * b + b]
print(min(vals))


(n, m, a, b) = map(int, input().split())
otvet = 0
k = n
otvet += n // m * b
n = n % m
if otvet > k * a:
	print(k * a)
elif otvet + b > otvet + n * a:
	print(otvet + n * a)
else:
	print(otvet + b)


TN = 1

def solution():
	(n, m, a, b) = map(int, input().split())
	if b / m > a:
		print(n * a)
	else:
		cur = 0
		if n % m != 0:
			cur = 1
		print(min(n // m * b + n % m * a, n // m * b + cur * b))
while TN != 0:
	solution()
	TN -= 1


(n, m, a, b) = [int(x) for x in input().strip().split(' ')]
if b / m >= a:
	print(n * a)
elif n < m:
	print(min(n * a, b))
else:
	print(min(int(n / m) * b + (n - int(n / m) * m) * a, (int(n / m) + 1) * b))


(n, m, a, b) = [int(_) for _ in input().split()]
if a * m > b:
	g = n // m * m
	print(n // m * b + min(n % m * a, b))
else:
	print(n * a)


(n, m, a, b) = input().split()
n = int(n)
m = int(m)
a = int(a)
b = int(b)
cost = 0
t = n
for i in range(0, t):
	if b / m >= a and n > m:
		cost = cost + n * a
		break
	elif b / m < a and n > m:
		cost = cost + b
		n = n - m
	elif n <= m:
		if n * a < b:
			cost = cost + n * a
			break
		else:
			cost = cost + b
			n = n - m
	if n <= 0:
		break
print(cost)


(n, m, a, b) = map(int, input().split())
if a * m <= b:
	print(a * n)
else:
	x = n // m
	ans = x * b
	rem = n % m
	ans += min(rem * a, b)
	print(ans)


(n, m, a, b) = map(int, input().split())
if b / m >= a:
	print(a * n)
else:
	c = n % m
	d = n // m
	if b > a * c:
		print(d * b + a * c)
	else:
		print(d * b + b)


(n, m, a, b) = map(int, input().split())
if m * a == b or m * a < b:
	print(n * a)
elif n % m * a > b:
	print(n // m * b + b)
else:
	print(n // m * b + n % m * a)


(n, m, a, b) = map(int, input().split())
c1 = n * a
c2 = n // m * b + n % m * a
c3 = (n + m - 1) // m * b
print(min(c1, c2, c3))


(n, m, a, b) = map(int, input().split())
if a * m > b:
	res = b * (n // m)
	rem = n % m
	if a * rem > b:
		res += b
	else:
		res += a * rem
else:
	res = a * n
print(res)


(n, m, a, b) = map(int, input().split())
multiTickets = n // m
singleTicket = n % m
optionA = n * a
optionB = multiTickets * b + singleTicket * a
optionC = multiTickets * b + (singleTicket != 0) * b
decision = int(min(optionA, optionB, optionC))
print(decision)


def in_tune(n, m, a, b):
	if n >= m:
		if n % m == 0:
			if n * a > n // m * b:
				return n // m * b
			else:
				return n * a
		if n % m != 0:
			result = n // m * b
			if a > b:
				result += b
			else:
				result += n % m * a
			return result
	if m > n:
		if n * a > b:
			return b
		else:
			return n * a
(N, M, A, B) = [int(i) for i in input().split()]
print(in_tune(N, M, A, B))


def howMuch():
	nmab = [int(j) for j in input().split(' ')]
	rides = nmab[0]
	ticketRides = nmab[1]
	rideCost = nmab[2]
	ticketRideCost = nmab[3]
	if rideCost * ticketRides <= ticketRideCost:
		return rides * rideCost
	recorrido = 0
	suma = 0
	while recorrido < rides:
		if recorrido + ticketRides <= rides:
			recorrido += ticketRides
			suma += ticketRideCost
		elif (rides - recorrido) * rideCost <= ticketRideCost:
			recorrido += 1
			suma += rideCost
		else:
			recorrido += ticketRides
			suma += ticketRideCost
	return suma
print(howMuch())


(n, m, a, b) = map(int, input().split())
ans1 = a * n
ans2 = 0
while True:
	n -= m
	ans2 += b
	if n <= 0:
		break
	elif n < m:
		if a < b:
			while True:
				n -= 1
				ans2 += a
				if n == 0:
					break
			if n == 0:
				break
print(min(ans1, ans2))


(n, m, a, b) = map(int, input().split())
q = n // m
r = n % m
f = q * b + r * a
s = (q + 1) * b
t = n * a
print(min(f, s, t))


from sys import stdin
import math
(n, m, a, b) = map(int, stdin.readline().split())
p = int(math.ceil(n / m)) * b
q = n * a
r = n // m * b + n % m * a
print(min(p, q, r))


(n, st, p, stp) = map(int, input().split())
s = 0
m = 0
r1 = stp
r2 = st * p
if r1 < r2:
	m = r1
else:
	m = r2
while n != 0:
	if n < st and stp >= p * n:
		s = s + n * p
		n = n - n
	elif n < st and stp < p * n:
		s = s + stp
		n = n - n
	else:
		n = n - st
		s = s + m
print(s)


data = input().split()
(N, M, A, B) = (int(data[0]), int(data[1]), int(data[2]), int(data[3]))
if M * A <= B:
	print(N * A)
else:
	print(N // M * B + min(N % M * A, B))


a = input()
a = a.split(' ')
m = min(int(a[0]) // int(a[1]) * int(a[3]) + int(a[0]) % int(a[1]) * int(a[2]), int(a[2]) * int(a[0]), (int(a[0]) // int(a[1]) + 1) * int(a[3]))
print(m)


vi = input()
vi = list(map(int, vi.split()))
(rides, freerides, cost, freecost) = vi[:]
if cost / 1 > freecost / freerides:
	final_cost = 0
	a = rides // freerides
	rides -= a * freerides
	final_cost += a * freecost
	if freecost < rides * cost:
		final_cost += freecost
	else:
		final_cost += rides * cost
else:
	final_cost = rides * cost
print(final_cost)


(rides, numOfM, costOfOne, costOfM) = map(int, input().split())
total = 0
if costOfM / numOfM <= costOfOne:
	Ms = rides // numOfM
	total += Ms * costOfM
	rides -= Ms * numOfM
	if costOfM > rides * costOfOne:
		total += rides * costOfOne
	else:
		total += costOfM
else:
	total = rides * costOfOne
print(total)


from sys import stdin, stdout
(n, m, a, b) = map(int, stdin.readline().split(' '))
if m * a <= b:
	stdout.write(str(n * a))
else:
	stdout.write(str(n // m * b + min(n % m * a, b)))


def main():
	(n, m, a, b) = list(map(int, input().split()))
	if b / m >= a:
		print(n * a)
	else:
		print(min(n // m * b + n % m * a, (n // m + 1) * b))

def __starting_point():
	main()
__starting_point()


from math import ceil
(n, m, a, b) = [int(x) for x in input().split()]
result = 0
if m * a <= b:
	result = n * a
else:
	first = int(n / m)
	result = first * b + min(n % m * a, b)
print(result)


inp = input().split(' ')
n = int(inp[0])
m = int(inp[1])
a = int(inp[2])
b = int(inp[3])
s = 0
if b / m < a:
	total_mult = int(n / m)
	leftover = n % m
	s = total_mult * b
	if leftover * a < b:
		s += leftover * a
	else:
		s += b
else:
	s = n * a
print(s)


(n, m, a, b) = map(int, input().split())
if n % m == 0:
	print(int(min(n * a, n / m * b)))
else:
	q = int(n - n % m)
	print(min(n * a, int(q / m * b + (n - q) * a), round(n / m + 0.5) * b))


import sys

def calCost(rides, bundle, single, deal):
	singleCost = rides * single
	numberOfBundle = rides // bundle
	ticRem = rides % bundle
	bundleCost = numberOfBundle * deal + ticRem * single
	allBundle = (numberOfBundle + 1) * deal
	return min(singleCost, min(bundleCost, allBundle))

def main():
	arr = [int(x) for x in sys.stdin.readline().strip().split()]
	(rides, bundle, single, deal) = arr
	print(calCost(rides, bundle, single, deal))
main()


(n, m, a, b) = list(map(int, input().split()))
j = n * a
d = int(n / m)
c = n % m
k = (d + c) * b
p = d * b + c * a
if c < m:
	cc = d * b + b
if cc < p:
	p = cc
if k < p:
	i = k
else:
	i = p
if n < m:
	i = b
if j < i:
	print(j)
else:
	print(i)


(n, m, a, b) = [int(x) for x in input().split()]
result = 0
num = n
while m < n:
	result += b
	n -= m
if a * n < b:
	result += a * n
else:
	result += b
if num * a < result:
	print(num * a)
else:
	print(result)


def fun(n, m, a, b):
	if n > m:
		if m * a <= b:
			return n * a
		else:
			temp = n % m
			return min(n // m * b + temp * a, n // m * b + b)
	else:
		return min(b, n * a)
(n, m, a, b) = list(map(lambda x: int(x), input().split()))
print(fun(n, m, a, b))


(n, m, a, b) = map(int, input().split())
cost1 = n * a
if n > m:
	if b < a:
		if n % m != 0:
			cost2 = (n // m + 1) * b
		else:
			cost2 = n // m * b
	else:
		cost2 = n // m * b + n % m * a
else:
	cost2 = b
if cost1 > cost2:
	cost = cost2
else:
	cost = cost1
print(cost)


(n, m, a, b) = list(map(int, input().split()))
bundle = n // m
single = n % m
_sum = 0
if bundle * b < bundle * m * a:
	_sum += bundle * b
else:
	_sum += bundle * m * a
if single * a > b and single != 0:
	_sum += b
else:
	_sum += single * a
print(_sum)


import math
(n, m, a, b) = map(int, input().split())
c1 = n * a
c2 = math.ceil(n / m) * b
c3 = n // m * b + n % m * a
print(min(c1, c2, c3))


import math
(n, m, a, b) = map(int, input().split())
if n % m == 0:
	n1 = n // m
	z = n1 * b
	z2 = n * a
	if z2 > z:
		print(z)
	else:
		print(z2)
else:
	n1 = n // m
	z = n1 * b
	n2 = n - n1 * m
	z1 = n2 * a
	ans1 = z1 + z
	n3 = math.ceil(n / m)
	ans2 = n3 * b
	if ans2 > ans1:
		print(ans1)
	else:
		print(ans2)


(n, m, a, b) = [int(x) for x in input().split()]
import math
if a <= b / m:
	print(n * a)
else:
	p = math.ceil(n / m)
	print(min(p * b, (p - 1) * b + (n - (p - 1) * m) * a))


import math
(n, m, a, b) = [int(i) for i in input().split()]
res1 = n // m * b + n % m * a
res2 = (n + m - 1) // m * b
res3 = n * a
print(min(res1, min(res2, res3)))


(n, m, a, b) = map(int, input().split())
cost = 0
if b < a:
	t = 0
	if n % m == 0:
		t = n // m
	else:
		t = n // m + 1
	cost = t * b
elif n < m:
	cost = min(n * a, b)
elif n % m == 0:
	cost = min(n * a, n / m * b)
else:
	cost = min(n * a, n // m * b + n % m * a)
print(int(cost))


def solve(n, m, a, b):
	big = float('inf')
	small = float('-inf')
	one_ride = a * n
	tro = n // m * b + n % m * a
	tro2 = big
	if n % m != 0:
		tro2 = (n // m + 1) * b
	return min(one_ride, tro, tro2)

def main():
	d = input()
	d = [int(i) for i in d.split()]
	a = d[0]
	b = d[1]
	c = d[2]
	e = d[3]
	ans = solve(a, b, c, e)
	print(ans)
main()


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve(case):
	(n, m, a, b) = sep()
	if a * m <= b:
		print(n * a)
	else:
		print(min(n // m * b + n % m * a, ceil(n / m) * b))
testcase(1)


(n, m, a, b) = input().split()
n = int(n)
m = int(m)
a = int(a)
b = int(b)
tk = 0
s = 0
if a <= b / m:
	print(int(n * a))
else:
	for i in range(n):
		n = n - m
		tk = tk + b
		if n < 0:
			break
	n = n + m
	s = tk - b
	s = s + n * a
	if s < tk:
		print(s)
	else:
		print(tk)


(n, m, a, b) = list(map(int, input().split()))
if m > n and b < n * a:
	print(b)
	exit()
if n % m == 0:
	s1 = b * (n / m)
else:
	s1 = b * (n / m + 1)
if b > a:
	s2 = b * (n // m) + n % m * a
else:
	s2 = b * (n // m) + n % m * b
s3 = n * a
print(int(min(s1, s2, s3)))


(n, m, a, b) = map(int, input().split())
c = 0
if b / m >= a:
	print(a * n)
else:
	price = b * int(n / m)
	n = n - m * int(n / m)
	price = price + min(a * n, b)
	print(price)


(n, m, a, b) = map(int, input().split())
mb = b / m
if mb < a:
	if n % m * a > b:
		s = n // m * b + b
	else:
		s = n // m * b + n % m * a
else:
	s = a * n
print(s)


(n, m, a, b) = map(int, input().split())
s = 0
r = n % m
q = n // m
c = a * m
if c > b:
	s += q * b
else:
	s += q * c
c = r * a
if c > b:
	s += b
else:
	s += c
print(s)


(n, m, a, b) = map(int, input().split())
mul = b / m
if mul < a:
	r = n // m
	c = r * b
	ri = n % m
	ci = ri * a
	if ci < b:
		c += ci
	else:
		c += b
	print(c)
else:
	print(n * a)


x = list(map(int, input().split()))
sum1 = 0
if x[0] // x[1] * x[-1] < x[0] * x[-2]:
	first = x[0] // x[1] * x[-1]
else:
	first = x[0] * x[-2]
if x[0] % x[1] * x[-2] < x[-1]:
	print(x[0] % x[1] * x[-2] + first)
else:
	print(x[-1] + first)


from sys import stdin

def main():
	(n, m, a, b) = map(int, stdin.readline().strip().split())
	if a * m > b:
		return n // m * b + min(n % m * a, b)
	return n * a
print(main())


(m, n, pm, pn) = list(map(int, input().split()))
l = []
l.append(m // n * pn + m % n * pm)
l.append(m // n * pn + pn)
l.append(m * pm)
print(min(l))


line = input().split()
n = int(line[0])
m = int(line[1])
a = int(line[2])
b = int(line[3])
first = n * a
second = n // m * b + n % m * a
third = n // m * b + b
if m >= n:
	fourth = b
	value = min(first, second, third, fourth)
	print(value)
else:
	value = min(first, second, third)
	print(value)


(n, m, a, b) = [int(i) for i in input().split()]
money = []
for i in range(n // m + 2):
	fee = b * i + a * max(n - m * i, 0)
	money.append(fee)
cheapest = min(money)
print(cheapest)


(n, m, a, b) = map(int, input().split())
if b / m > a:
	money = n * a
elif n < m and n * a < b:
	money = n * a
elif n < m and n * a > b:
	money = b
elif a < b:
	money = int(n / m) * b + int(n % m) * a
elif n % m == 0:
	money = int(n / m) * b
else:
	money = int(n / m) * b + b
print(money)


import math
(n, m, a, b) = map(int, input().split())
resonal = n // m * b + n % m * a
unresonal1 = n * a
unresonal2 = math.ceil(n / m) * b
print(min(resonal, unresonal1, unresonal2))


import math
(n, m, a, b) = map(int, input().split())
divide = math.floor(n / m)
remain = n % m
if remain * a <= b and a * m >= b:
	print(int(divide * b + remain * a))
elif a * m < b:
	print(int(a * n))
else:
	print(int(divide * b + b))


ls = [int(i) for i in input().split()]
val = ls[0] // ls[1]
if val == 0:
	print(min(ls[2] * ls[0], ls[3]))
elif ls[1] * ls[2] >= ls[3]:
	res = val * ls[3]
	ls[0] = ls[0] % ls[1]
	while ls[0] > 0:
		res += min(ls[2], ls[3])
		if min(ls[2], ls[3]) == ls[3]:
			ls[0] -= ls[1]
		else:
			ls[0] -= 1
	print(res)
else:
	print(ls[0] * ls[2])


import math
(n, m, a, b) = map(int, input().split())
c = 0
while n > 0:
	if n * a < b * math.ceil(n / m):
		c = c + n * a
		n = 0
	else:
		c += b
		n = n - m
print(c)


inputdata1 = input()
splitdata1 = inputdata1.split(' ')
data1 = []
for i in range(len(splitdata1)):
	data1.append(int(splitdata1[i]))
if data1[3] / data1[1] < data1[2]:
	a = data1[0] // data1[1]
	b = data1[0] % data1[1]
	if a == 0:
		print(min(data1[0] * data1[2], data1[3]))
	else:
		print(a * data1[3] + min(b * data1[2], data1[3]))
else:
	print(data1[0] * data1[2])


(n, m, a, b) = map(int, input().split())
if m * a <= b:
	print(n * a)
else:
	c = n // m
	z = n - c * m
	if z != 0:
		if b <= z * a:
			print(b * (c + 1))
		else:
			print(c * b + z * a)
	else:
		print(c * b)


(n, m, a, b) = map(int, input().split())
import math
cost1 = n * a
cost2 = 0
if n >= m:
	cost2 = n // m * b + n % m * a
	cost2 = min(cost2, math.ceil(n / m) * b)
elif n < m:
	cost2 = min(b, n * a)
print(min(cost1, cost2))


vals = list(map(int, input().split()))
rides_left = vals[0]
total_price = 0
while rides_left > 0:
	if rides_left >= vals[1]:
		total_price += vals[3]
		rides_left -= vals[1]
	else:
		total_price += vals[2]
		rides_left -= 1
last_price = total_price
total_price = 0
rides_left = vals[0]
while rides_left > 0:
	total_price += vals[2]
	rides_left -= 1
if total_price < last_price:
	last_price = total_price
total_price = 0
rides_left = vals[0]
while rides_left > 0:
	total_price += vals[3]
	rides_left -= vals[1]
if last_price < total_price:
	print(last_price)
else:
	print(total_price)


def mm(v):
	(n, bc, np, bp) = v
	if np < bp / bc:
		return n * np
	m = n * np
	for x in range(n // bc + 1):
		t = x * bp + np * (n - bc * x)
		if t < m:
			m = t
	return min(t, bp * (n // bc + 1))
v = [int(x) for x in input().split()]
print(mm(v))


(a, b, c, d) = input().split()
a = int(a)
b = int(b)
c = int(c)
d = int(d)
if d / b > c:
	print(a * c)
else:
	(e, f) = divmod(a, b)
	ans = e * d + min(f * c, d)
	print(ans)


(num_rides, m_rides, one_price, m_price) = map(int, input().strip().split())
total = num_rides * one_price
if m_price / m_rides > one_price:
	print(one_price * num_rides)
else:
	mult_tickets = num_rides // m_rides
	price = mult_tickets * m_price
	one_ticket = one_price * (num_rides % m_rides)
	if one_ticket + price > price + m_price:
		print(price + m_price)
	else:
		print(one_ticket + price)


import math
datos = input()
num = ''
L = []
for numero in datos:
	if numero != ' ':
		num = num + numero
	else:
		L.append(int(num))
		num = ''
L.append(int(num))
(total, viajes, a, b) = (L[0], L[1], L[2], L[3])
viajesB = math.trunc(total / viajes)
viajesA = total - viajesB * viajes
if viajes * a > b and viajes < total:
	if a >= b:
		if total - viajesB * viajes <= viajes and viajesA != 0:
			print((viajesB + 1) * b)
		else:
			print(viajesB * b + viajesA * a)
	else:
		print(viajesB * b + viajesA * a)
elif total < viajes and total * a > b:
	print(b)
else:
	print(total * a)


(n, m, a, b) = map(int, input().split())
npass = n // m
tcost = npass * b + (n - m * npass) * a
qcost = (npass + 1) * b
rcost = n * a
print(min(tcost, qcost, rcost))


a = list(map(int, input().split(' ')))
import math
c1 = int(math.ceil(float(a[0]) / a[1])) * a[3]
c2 = a[0] * a[2]
c3 = a[0] // a[1] * a[3] + a[0] % a[1] * a[2]
print(min(c1, c2, c3))


(n, m, a, b) = map(int, input().split())
k1 = b * (n // m) + (n - m * (n // m)) * a
k2 = n * a
k3 = b * (n // m) + b
print(min(k1, k2, k3))


(n, m, a, b) = map(int, input().split())
soma = 0
while n:
	viagens = min(n, m)
	soma += min(a * viagens, b)
	n -= viagens
print(soma)


lst = [int(x) for x in input().split(' ')]
(n, m, a, b) = (lst[0], lst[1], lst[2], lst[3])
price = 0
while n > 0:
	if m <= n and b / m < a or (m > n and b < a * n):
		n -= m
		price += b
	else:
		n -= 1
		price += a
print(price)


metro = input()
dannye = metro.split()
poezdok = int(dannye[0])
abonement = int(dannye[1])
zenaproezda = int(dannye[2])
zenaabonementa = int(dannye[3])
k = int(poezdok / abonement)
if k * abonement < poezdok:
	k += 1
k1 = k * zenaabonementa
k2 = poezdok * zenaproezda
k -= 1
k3 = k * zenaabonementa + (poezdok - k * abonement) * zenaproezda
print(min(k1, k2, k3))


def sol():
	(n, m, a, b) = map(int, input().split())
	p = b / m
	if a <= p:
		print(n * a)
	else:
		s = 0
		s += n // m * b
		s += min(n % m * a, b)
		print(s)
sol()


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
(rides, many, single, bulk) = read_ints()
answer = rides // many * min(bulk, single * many)
answer += min(rides % many * single, bulk)
print(answer)


(n, m, a, b) = list(map(int, input().split()))
part1 = min(n // m * b, n // m * m * a)
part2 = min(n % m * a, b)
print(part1 + part2)


(n, m, a, b) = map(int, input().split())
from math import ceil
ss1 = n * a
ss2 = n // m * b + (n - n // m * m) * a
ss3 = ceil(n / m) * b
print(min(ss1, ss2, ss3))


import math
(n, m, a, b) = map(int, input().split())
avg_a = b / m
pref = min(a, avg_a)
copy = n
res = 0
while copy % m != 0:
	copy = copy - 1
if m > n:
	print(min(n * a, b))
else:
	res += min(copy * pref, copy * a)
	rem = n - copy
	if rem * pref < b:
		res += min(rem * a, b)
	else:
		res += min(rem * a, rem * pref)
	print(int(res))


from sys import stdin, stdout
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
(n, m, a, b) = iia()
temp1 = b * (n // m) + n % m * a
temp2 = b * (n // m + 1)
temp3 = a * n
print(min(temp1, temp2, temp3))


(n, m, a, b) = list(map(int, input().split()))
cost = 0
while n > 0:
	if b < a * n and m >= n:
		cost += b
		n = 0
		break
	if b < a * m and n >= m:
		cost += b
		n -= m
	else:
		cost += a
		n -= 1
print(cost)


(n, m, a, b) = input().split()
(n, m, a, b) = (int(n), int(m), int(a), int(b))
ans = 0
if n <= m:
	ans = min(a * n, b)
else:
	k = n // m
	ans = min(b * k, a * m * k) + min(b, a * (n - m * k))
print(ans)


(n, m, a, b) = [int(i) for i in input().split()]
ave = b / m
k = 0
mon = 0
rem = 0
if ave < a:
	k = int(n / m)
	rem = n % m
	mon += k * b
	if b < rem * a:
		mon += b
	else:
		mon += a * rem
else:
	mon = a * n
print(mon)


import math
l = [int(i) for i in input().split()]
k = l[0]
m = l[1]
a = l[2]
b = l[3]
x = 0
y = k // m
x = x + y * b
x = x + (k - y * m) * a
o = k * a
p = math.ceil(k / m) * b
print(min(x, o, p))


import math
(n, m, a, b) = map(int, input().split())
first = math.ceil(n * a)
secd = math.ceil(n / m) * b
thid = n // m * b + (n - n // m * m) * a
print(min(first, secd, thid))


(trips_planned, trips_subs, cost_single, cost_subs) = map(int, input().split())
if trips_planned % trips_subs >= 1:
	res = 1
else:
	res = 0
by_single = cost_single * trips_planned
by_subs = cost_subs * (trips_planned // trips_subs) + res * cost_subs
by_both = cost_subs * (trips_planned // trips_subs) + cost_single * (trips_planned % trips_subs)
list = [by_single, by_subs, by_both]
print(min(list))


(n, m, a, b) = [int(t) for t in input().split()]
if b / m >= a:
	p = n * a
else:
	t = n // m
	v = n % m
	p1 = t * b + v * a
	p2 = (t + 1) * b
	p = min(p1, p2)
print(p)


def main():
	(n, m, a, b) = tuple(map(int, input().rstrip().split()))
	singles = a * n
	combined = b * (n // m) + a * (n % m)
	specials = b * ((n + m - 1) // m)
	print(min(singles, combined, specials))
main()


(n, m, a, b) = map(int, input().split())
mn = float('inf')
for i in range((n + m - 1) // m + 1):
	mn = min(mn, i * b + max(0, n - i * m) * a)
print(mn)


arr = input().split(' ')
n = int(arr[0])
m = int(arr[1])
a = int(arr[2])
b = int(arr[3])
res = 0
ost = 0
if a * m <= b:
	res = a * n
else:
	res = int(n / m) * b
	ost = n - int(n / m) * m
	if ost * a <= b:
		res += ost * a
	else:
		res += b
print(res)


nmab = list(map(int, input().split()))
n = nmab[0]
m = nmab[1]
a = nmab[2]
b = nmab[3]
p = b / m
if p < a:
	t = 0
	s = 0
	while t < n:
		if t + m > n:
			if b < a * (n - t):
				s += b
				break
			else:
				s += a * (n - t)
				break
		else:
			t += m
			s += b
else:
	s = n * a
print(s)


(n, m, a, b) = map(int, input().split())
special = n // m
left = n % m
ans1 = special * b + left * a
ans2 = n * a
ans3 = (special + 1) * b
print(min(ans1, ans2, ans3))


(m, n, a, b) = map(int, input().split())
amount_of_aboniments = m // n
residue_of_rides = m % n
if b / n < a:
	if residue_of_rides * a < b:
		all_money = residue_of_rides * a + amount_of_aboniments * b
	else:
		all_money = amount_of_aboniments * b + b
else:
	all_money = m * a
print(all_money)


(n, m, a, b) = map(int, input().split())
optA = n * a
multiTicketsNeeded = n // m
singleTicketStillNeeded = n % m
optB = multiTicketsNeeded * b + singleTicketStillNeeded * a
optC = multiTicketsNeeded * b + (singleTicketStillNeeded != 0) * b
print(int(min(optA, optB, optC)))


s = list(map(int, input().split()))
n = s[0]
m = s[1]
a = s[2]
b = s[3]
if n % m == 0:
	print(min(n * a, int(n / m) * b))
elif m > n:
	print(min(n * a, b))
else:
	total_rides_by_m = n // m
	non_m_rides = n - total_rides_by_m * m
	print(min(n * a, total_rides_by_m * b + non_m_rides * a, total_rides_by_m * b + non_m_rides * b, total_rides_by_m * b + b))


(a, b, c, d) = map(int, input().split())
sum = [a * c]
e = a // b
sum.append((e + 1) * d)
if d < c * b:
	f = e * d + (a - b * e) * c
	sum.append(f)
print(min(sum))


(a, b, x, y) = map(int, input().split())
i = y / b
ce = a // b
os = a % b
q = a * y
w = ce * y + y
e = ce * y + os * y
r = ce * y + os * x
t = a * x
print(min(q, w, e, r, t))


(n, m, a, d) = map(int, input().split())
k = n * a
ab = n // m * d
if n % m != 0:
	ab = ab + min(n % m * a, d)
print(min(k, ab))


(n, m, a, b) = map(int, input().split())
cost1 = n * a
cost2 = n // m * b + n % m * a
cost3 = n // m * b + n % m * b
cost4 = (n // m + 1) * b
if n < m:
	print(min(n * a, b))
else:
	print(min(cost1, cost2, cost3, cost4))


(n, m, a, b) = map(int, input().split())
First = n // m * b
if n % m > 0:
	First += b
second = n * a
third = n // m * b + n % m * a
print(min(First, second, third))


(n, m, a, b) = list(map(int, input().split()))
res = 10 ** 100
for i in range(10000):
	res = min(res, i * b + max(n - i * m, 0) * a)
print(res)


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline()
(n, m, a, b) = mi()
p = n * a
q = n // m * b + n % m * a
r = ceil(n / m) * b
print(min(p, q, r))


import math
(n, m, a, b) = map(int, input().split())
b1 = n // m * b + n % m * a
b2 = math.ceil(n / m) * b
b3 = n * a
print(min(b1, b2, b3))


i = input()
j = i.split(' ')
n = int(j[0])
m = int(j[1])
a = int(j[2])
b = int(j[3])
cost = []
c = 0
k = 0
while k * m <= n:
	c = 0
	c = (n - k * m) * a + k * b
	cost.append(c)
	k += 1
	if k * m > n and k * b < min(cost):
		cost.append(k * b)
print(min(cost))


(n, m, a, b) = map(int, input().split())
total = []
for i in range(int((n + m - 1) / m) + 1):
	z = n - i * m
	if z < 0:
		z = 0
	x = i * b + z * a
	total.append(x)
print(min(total))


import math
line = input().split()
n = int(line[0])
m = int(line[1])
a = int(line[2])
b = int(line[3])
c1 = n * a
c2 = b * math.ceil(n / m)
c3 = b * (n // m) + a * (n % m)
cost = min(c1, c2, c3)
print(cost)


l = list(map(int, input().split()))
s1 = l[0] * l[2]
sum = l[0] // l[1] * l[3] + min(l[2] * (l[0] % l[1]), l[3])
print(min(s1, sum))


x = input('').split(' ')
n = int(x[0])
m = int(x[1])
a = int(x[2])
b = int(x[3])
if a * m > b:
	p = int(n / m) * b
	if int(n % m) * a > b:
		p = p + b
	else:
		p = p + int(n % m) * a
else:
	p = n * a
print(p)


(total, jalan, harga, hargas) = map(int, input().split())
if hargas / jalan > harga:
	print(total * harga)
else:
	if jalan > total and hargas < total * harga:
		bayar = hargas
	else:
		sisa = total % jalan
		bayar = total // jalan * hargas
		if sisa != 0:
			if harga > hargas:
				bayar = bayar + hargas
			else:
				bayar = bayar + sisa * harga
	print(bayar)


(n, m, a, b) = map(int, input().split())
p = int(0)
s = int(0)
if b / m < a:
	while n * a > b:
		n = n - m
		p = p + b
	if n > 0:
		p = p + n * a
else:
	p = n * a
print(p)


(n, m, a, b) = list(map(int, input().split()))
if b / m >= a:
	print(n * a)
else:
	k = n // m
	print(min(k * b + (n - k * m) * a, (k + 1) * b))


n = input().split()
import math
a = []
for i in range(len(n)):
	a.append(int(n[i]))
n = a[0]
m = a[1]
c = a[2]
b = a[3]
if b / m < c:
	s1 = math.floor(n / m)
	s2 = n - s1 * m
	summ1 = s1 * b + s2 * c
	summ2 = math.ceil(n / m) * b
	summ = min(summ1, summ2)
else:
	summ = n * c
print(summ)


(n, m, a, b) = [int(x) for x in input().strip().split()]
ans = a * n
for i in range(n + 1):
	t = i * m
	k = i * b + a * max(0, n - t)
	ans = min(ans, k)
print(ans)


import math
(n, m, a, b) = map(int, input().split())
n1 = n * a
n2 = math.ceil(n / m) * b
n3 = n // m * b + (n - n // m * m) * a
l = min(n1, n2, n3)
print(l)


def main():
	(n, m, a, b) = list(map(int, input().split()))
	if b / m > a:
		print(a * n)
	else:
		ans = n // m * b
		if n % m * a > b:
			ans += b
		else:
			ans += n % m * a
		print(ans)
t = 1
while t != 0:
	main()
	t -= 1


l = tuple(map(int, input().split()))
(n, m, a, b) = l
if a >= b / m:
	c1 = n // m * b + (n - n // m * m) * a
	c2 = (n // m + 1) * b
	if c1 >= c2:
		cost = c2
	else:
		cost = c1
else:
	cost = n * a
print(cost)


(n, m, a, b) = map(int, input().split())
check = 0
check1 = 0
check = n // m
check1 = n % m
num = []
num.append(check * b + check1 * a)
num.append(n * a)
num.append(n // m * b + b)
num.sort()
print(num[0])


(n, m, a, b) = map(int, input().split())
s = [x * a + (n - x + m - 1) // m * b for x in range(0, n + 1)]
print(min(s))


import math
(n, m, a, b) = list(map(int, input().split()))
AB = n // m * b + n % m * a
A = n * a
B = math.ceil(n / m) * b
print(min(A, AB, B))


import math
(n, m, a, b) = list(map(int, input().split(' ')))
if b >= m * a:
	print(n * a)
else:
	print(min(n % m * a, b) + math.floor(n / m) * b)
print()


nums = input().split(' ')
num = [int(x) for x in nums]
n = num[0]
m = num[1]
a = num[2]
b = num[3]
multitrip = b / m
if multitrip <= a:
	buy = n // m
	left = n - buy * m
	if left * a <= b:
		print(buy * b + left * a)
	else:
		print(buy * b + b)
else:
	print(a * n)


def function1(n, m, a, b):
	price = n // m * b
	if price <= a * n:
		if n % m * a > b:
			price += b
			return price
		else:
			price += n % m * a
			return price
	else:
		return a * n
	pass

def main():
	(n, m, a, b) = list(map(int, input().split()))
	print(function1(n, m, a, b))
main()


from math import ceil
s = str(input())
temp = s.split()
n = int(temp[0])
m = int(temp[1])
a = int(temp[2])
b = int(temp[3])
price_per_ride_in_m = b / m
max_rides_in_m = ceil(n / m)
if a * n < b * max_rides_in_m:
	print(a * n)
elif n % m == 0:
	print(int(n * price_per_ride_in_m))
else:
	max_num_of_m_rides = n // m
	min_num_of_a_rides = n - m * (n // m)
	if b * ceil(min_num_of_a_rides / m) > a * min_num_of_a_rides:
		print(int(b * max_num_of_m_rides + a * min_num_of_a_rides))
	else:
		print(max_rides_in_m * b)


(n, m, a, b) = map(int, input().split())
d = n // m
ans = min(a * n, b * d + min(b, a * (n % m)))
print(ans)


import math
s = list(map(int, input().split()))
print(min(s[0] * s[2], s[3] * int(s[0] / s[1]) + s[0] % s[1] * s[2], int(math.ceil(s[0] / s[1])) * s[3]))


l = tuple(map(int, input().split()))
(n, m, a, b) = l
print(min(int(n / m) * b + min(n % m * a, b), n * a))


(n, m, a, b) = map(int, input().split())
tk = 0
t = 0
s = []
if m > n:
	print(min(n * a, b))
else:
	for i in range(1, n // m + 1):
		t = i * m
		s.append(i * b + (n - t) * a)
	s.append(n * a)
	s.append(n // m * b + min(n % m * a, b))
	print(min(s))


(n, m, a, b) = list(map(int, input().split()))
res = 0
x = n // m * b
y = n % m
if b // m >= a:
	res = n * a
elif y == 0:
	res = x
elif y * a < b:
	res = x + y * a
else:
	res = x + b
print(res)


[n, m, a, b] = [int(x) for x in input().split()]
l = [b * (n // m) + a * (n - m * (n // m)), a * n, b * (n // m + 1)]
print(min(l))


import math
(n, m, a, b) = map(int, input().split(' '))
case1 = 0
case2 = 0
number_of_special_ticket = math.floor(n / m)
case1 = number_of_special_ticket * b
remaining_rides = n - m * number_of_special_ticket
if n % m != 0:
	if remaining_rides * a < b:
		case1 = case1 + remaining_rides * a
	else:
		case1 = case1 + b
case2 = n * a
final_result = min(case1, case2)
print(final_result)


def main():
	(n, m, a, b) = map(int, input().split())
	mon1 = n * a
	mon2 = n % m * a + n // m * b
	mon3 = (n // m + 1) * b
	print(min(mon1, mon2, mon3))
main()


(a, b, c, d) = input().split(' ')
a = int(a)
b = int(b)
c = int(c)
d = int(d)
if d / min(a, b) < c:
	if a <= b:
		print(d)
	elif c < d:
		print(a // b * d + a % b * c)
	else:
		print(a // b * d + (a % b and 1) * d)
else:
	print(a * c)


(n, m, a, b) = [int(t) for t in input().split()]
result = 0
if b / m > a:
	result = a * n
else:
	result = n // m * b + min(n % m * a, b)
print(result)


ar = input().split()
n = int(ar[0])
m = int(ar[1])
a = int(ar[2])
b = int(ar[3])
if a * m < b:
	flag = True
else:
	flag = False
if flag:
	print(a * n)
else:
	r = n % m
	print(min(b * (n // m) + r * a, b * (n // m + 1)))


(n, m, a, b) = map(int, input().split())
t = n // m
sum = t * b
sum += min((n - t * m) * a, b)
sum1 = n * a
print(min(sum1, sum))


import math
import queue
(n, m, a, b) = [int(x) for x in input().split()]
sums = []
sum = 0
rides = n
q = queue.Queue()
case = True
q.put((rides, sum))
while not q.empty():
	node = q.get()
	if node[0] <= 0:
		sums.append(node[1])
	elif case:
		mTimes = math.floor(n / m)
		q.put((node[0] - n, node[1] + a * n))
		q.put((node[0] - m * mTimes, node[1] + b * mTimes))
		case = False
	else:
		q.put((node[0] - 1, node[1] + a))
		q.put((node[0] - m, node[1] + b))
print(min(sums))


(n, m, a, b) = [int(j) for j in input().split()]
ans3 = a * n
if n % m == 0:
	ans1 = int(n / m * b)
	ans2 = a * n
else:
	ans1 = int(n / m) * b + a * (n % m)
	ans2 = (int(n / m) + 1) * b
print(min(ans1, ans2, ans3))


(n, m, a, b) = map(int, input().split())
arr = [0 for i in range(n + m + 1)]
for i in range(1, n + m + 1):
	arr[i] = arr[i - 1] + a
	if i >= m:
		arr[i] = min(arr[i], arr[i - m] + b)
print(min(arr[n:n + m + 1]))


(n, m, a, b) = map(int, input().split())
(u, v) = (n // m, n % m)
print(min(a * n, b * u + a * v, b * u + b))


from math import ceil
(n, m, a, b) = map(int, input().split())
na = n * a
mb = ceil(n / m) * b
namb = n // m * b + n % m * a
j = min(na, mb)
print(min(j, namb))


(n, m, a, b) = [int(x) for x in input().split()]
print([n // m * b + [b, n % m * a][b >= n % m * a], n * a][b / m > a])


(rides, express, p_single, p_express) = [int(x) for x in input().split()]
if 1 / p_single >= express / p_express:
	print(p_single * rides)
elif rides // express * p_express + rides % express * p_single < (rides // express + 1) * p_express:
	print(rides // express * p_express + rides % express * p_single)
else:
	print((rides // express + 1) * p_express)


import math
(n, m, a, b) = [int(i) for i in input().split(' ')]
sum1 = n * a
sum2 = math.ceil(n / m) * b
sum3 = n // m * b + n % m * a
print(min(sum1, sum2, sum3))


inp = input()
inp = inp.split(' ')
n = int(inp[0])
m = int(inp[1])
a = int(inp[2])
b = int(inp[3])
if b / m >= a:
	print(a * n)
else:
	out = b * int(n / m)
	n -= m * int(n / m)
	out += min(a * n, b)
	print(out)


(n, m, a, b) = map(int, input().split())
t1 = n * a
t2 = min(n // m * b + n % m * a, (n // m + 1) * b)
print([t1, t2][t1 >= t2])


(n, m, a, b) = map(int, input().split())
ans = min(b * (n // m) + a * (n % m), a * n, b * (n // m + 1))
print(ans)


a = input()
b = a.split()
n = int(b[0])
m = int(b[1])
k = int(b[2])
l = int(b[3])
if l / m <= k:
	if n % m * k <= l:
		price = n // m * l + n % m * k
	else:
		price = n // m * l + l
	print(price)
else:
	print(n * k)


(n, m, a, b) = [int(x) for x in input().split()]
ans = 99999999
for i in range(1001):
	for j in range(1001):
		if i + j * m >= n:
			c = i * a + j * b
			ans = min(c, ans)
print(ans)


from math import ceil
(nRides, mRides, aRubles, bRubles) = [int(i) for i in input().split()]
total = min(aRubles * nRides, ceil(nRides / mRides) * bRubles, bRubles * (nRides // mRides) + aRubles * (nRides - nRides // mRides * mRides))
print(total)


(n, m, a, b) = map(int, input().split())
d = m * a
e = min(n % m * a, b)
f = int(n / m)
g = f * b
if d <= b:
	print(n * a)
else:
	print(e + g)


(n, m, a, b) = map(int, input().split())
spc = n // m * b
if n % m != 0:
	spc += min(n % m * a, b)
print(min(n * a, spc))


vas = input().split(' ')
n = int(vas[0])
m = int(vas[1])
a = int(vas[2])
b = int(vas[3])
if b <= a * m:
	r = n % m
	ti = n // m
	r = r * a if r * a <= b else b
	print(ti * b + r)
else:
	print(n * a)


L = list(map(int, input().split()))
(n, m, a, b) = L
if b / m >= a:
	res = n * a
else:
	res = n // m * b
	if b < a * (n % m):
		res = res + b
	else:
		res = res + n % m * a
print(res)


(num_rides, num_rides_ticket, price_one_ticket, price_mult_ticket) = map(int, input().split())
num_mult_tickets = num_rides // num_rides_ticket
print(min(num_rides * price_one_ticket, num_mult_tickets * price_mult_ticket + (num_rides - num_mult_tickets * num_rides_ticket) * price_one_ticket, (num_mult_tickets + 1) * price_mult_ticket))


import math
(n, m, a, b) = map(int, input().split())
if n > m:
	c = n // m
	if n % m == 0:
		print(min(n * a, b * c))
	else:
		z = c * m
		x = min(n * a, c * b + a, c * b + b)
		if x == c * b + a:
			z = z + 1
		else:
			z = z + m
		while z < n:
			if x + a < x + b:
				x = x + a
				z = z + 1
			else:
				x = x + b
				z = z + m
		print(x)
else:
	print(min(n * a, b))


(n, m, a, b) = list(map(int, input().split()))
k = n * a
c = n // m * b + b
p = n // m * b + n % m * a
i = min(k, c, p)
print(i)


(n, m, a, b) = list(map(int, input().split()))
ans = 100000000
for x in range(1001):
	for y in range(1001):
		if x + m * y >= n:
			ans = min(ans, a * x + b * y)
print(ans)


l = list(map(int, input().split()))
cnt = 0
if l[2] * l[1] <= l[3]:
	print(l[0] * l[2])
elif l[2] * l[1] >= l[3]:
	n = l[0]
	if n < l[1] and l[2] * n < l[3]:
		print(l[2] * n)
	elif n < l[1] and l[2] * n > l[3]:
		print(l[3])
	else:
		while n > 0:
			cnt += 1
			n -= l[1]
		if l[2] >= l[3]:
			print(cnt * l[3])
		else:
			print((cnt - 1) * l[3] + (l[0] - (cnt - 1) * l[1]) * l[2])


(n, m, a, b) = map(int, input().split(' '))
if m * a <= b:
	print(n * a)
else:
	rupay = int(n / m) * b
	if (n - int(n / m) * m) * a < b:
		rupay += (n - int(n / m) * m) * a
	else:
		rupay += b
	print(rupay)


(n, m, a, b) = (int(x) for x in input().split())
if m > n and b < n * a:
	cena = b
elif b / m < a:
	stevec1 = n // m
	if n % m != 0:
		if a < b:
			stevec2 = n - m * stevec1
			cena = stevec1 * b + stevec2 * a
		else:
			cena = (stevec1 + 1) * b
	else:
		cena = stevec1 * b
else:
	cena = n * a
print(cena)


(n, m, a, b) = [int(x) for x in input().split()]
(x, y) = divmod(n, m)
print(min(x * b + y * a, (x + 1) * b, n * a))


from sys import stdin, stdout
import math, queue, heapq
fastinput = stdin.readline
fastout = stdout.write
t = 1
while t:
	t -= 1
	(n, m, a, b) = map(int, fastinput().split())
	b = min(b, a * m)
	print(n // m * b + min(n % m * a, b))


(n, m, a, b) = map(int, input().split())
a_list = []
a_list.append(b * (n // m) + a * (n % m))
if n % m != 0:
	a_list.append(b * (n // m + 1))
a_list.append(a * n)
a_list.sort()
print(str(a_list[0]))


nmabStr = input()
n = int(nmabStr.split()[0])
m = int(nmabStr.split()[1])
a = int(nmabStr.split()[2])
b = int(nmabStr.split()[3])
cost1 = a * n
speNum = n // m
if n % m > 0:
	speNum = speNum + 1
cost2 = speNum * b
cost3 = n // m * b + n % m * a
print(min(cost1, cost2, cost3))


import math
(n, m, a, b) = map(int, input().split())
k = min(a * n, b * (n // m) + a * (n % m), b * (1 + n // m))
if m > n:
	k = min(k, b)
print(k)


from math import ceil
t = list(map(int, input().split()))
print(min(t[0] * t[2], t[0] // t[1] * t[3] + t[0] % t[1] * t[2], ceil(t[0] / t[1]) * t[3]))


from math import floor
from math import ceil
q = input()
q = q.split(' ')
n = int(q[0])
m = int(q[1])
a = int(q[2])
b = int(q[3])
s = floor(n / m)
l = ceil(n % m)
w = ceil(n / m)
if w * b < s * b + l * a:
	print(w * b)
elif n * a > s * b + l * a:
	print(s * b + l * a)
else:
	print(n * a)


from math import ceil
(n, m, a, b) = map(int, input().split())
(c, d, e) = (ceil(n / m) * b, a * n, n // m * b + (n - n // m * m) * a)
print(min(c, d, e))


(n, m, a, b) = map(int, input().split())
passes = int(n / m) * b + n % m * a
passes1 = int(n / m) * b + b
passes = passes if passes < passes1 else passes1
normal = n * a
if passes > normal:
	print(normal)
else:
	print(passes)


(a, b, c, d) = map(int, input().split())
t = []
for i in range(1001):
	for j in range(1001):
		if i + j * b >= a:
			t.append(c * i + d * j)
print(min(t))


(n, m, a, b) = map(int, input().split())
if m >= n:
	print(min(n * a, b))
else:
	if n % m == 0:
		p = round(n / m)
	elif n % m != 0:
		p = round(n / m) + 1
	k = n // m * b + n % m * a
	kk = p * b
	print(min(n * a, k, kk))


(n, m, a, b) = map(int, input().split())
if n > m:
	chk = b * (n // m)
	if chk <= a * (m * (n // m)):
		if a * (n - m * (n // m)) <= b:
			ans = chk + a * (n - m * (n // m))
		else:
			ans = chk + b
	else:
		ans = a * n
elif a * n <= b:
	ans = a * n
else:
	ans = b
print(ans)


(n, m, a, b) = map(int, input().split())
d = n // m * b
print([min(n * a, d + n % m * a, d + b), min(n * a, b)][not d])


(n, m, a, b) = list(map(int, input().split()))
price1 = n // m * b + n % m * a
price2 = (n // m + 1) * b
price3 = n * a
price = min(price1, price2, price3)
print(price)


import math

def find_minimum_cost(rides: int, rides_in_set_ticket: int, one_ride_price: int, set_ticket_price: int) -> int:
	set_tickets_needed: int = rides // rides_in_set_ticket
	one_ride_tickets_needed: int = rides - set_tickets_needed * rides_in_set_ticket
	if set_ticket_price / rides_in_set_ticket > one_ride_price or set_ticket_price > one_ride_price * rides:
		return rides * one_ride_price
	else:
		if set_tickets_needed == 0:
			return set_ticket_price
		if set_ticket_price < one_ride_price:
			return int(math.ceil(rides / rides_in_set_ticket)) * set_ticket_price
		return set_tickets_needed * set_ticket_price + one_ride_tickets_needed * one_ride_price
entry = input('').split(' ')
entry_int = [int(x) for x in entry]
print(find_minimum_cost(entry_int[0], entry_int[1], entry_int[2], entry_int[3]))


from sys import stdin
(n, m, a, b) = map(int, stdin.readline().rstrip().split(' '))
cost_per_ride_m = b / m
if cost_per_ride_m < a:
	m_tickets = n // m
	tot = m_tickets * b
	rem_tickets = n - m_tickets * m
	if rem_tickets > 0:
		tot += min(b, a * rem_tickets)
	print(tot)
else:
	print(n * a)


(n, m, a, b) = [int(i) for i in input().split()]
if b / m >= a:
	print(int(n * a))
elif n % m == 0:
	print(int(n / m * b))
else:
	x = n // m
	y = n - x * m
	print(min(int(x * b + y * a), (x + 1) * b))


(n, m, nc, mc) = map(int, input().split())
norc = n * nc
a = n // m
ans = a * mc
b = n % m
ans += b * nc
a1 = n // m + 1
ans1 = a1 * mc
print(min(norc, ans, ans1))


(n, m, a, b) = input().split()
n = int(n)
m = int(m)
a = int(a)
b = int(b)
if b / m >= a:
	res = n * a
else:
	res = n // m * b
	if n % m * a < b:
		res += n % m * a
	else:
		res += b
print(res)


t = 1
for _ in range(t):
	(n, m, a, b) = map(int, input().split())
	cost = 0
	cost = min(n // m * b + b, n * a, n // m * b + n % m * a)
	print(cost)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
arr = inlt()
(N, M, A, B) = arr
ans = 0
if B / M >= A:
	ans = N * A
else:
	ans += N // M * B
	N -= M * (N // M)
	ans += min(N * A, B)
print(ans)


(n, m, a, b) = list(map(int, input().split()))
m_price = m * a if m * a < b else b
price = 0
for i in range(n // m):
	price += m_price
price += n % m * a if n % m * a < b else b
print(price)


(n, m, a, b) = [int(i) for i in input().split()]
if b / m > a:
	sum = n * a
else:
	sum1 = n // m * b + n % m * a
	sum2 = (int(n / m) + 1) * b
	sum = min(sum1, sum2)
print(sum)


A = [int(i) for i in input().split()]
if A[3] / A[1] < A[2]:
	print(min(A[0] // A[1] * A[3] + A[0] % A[1] * A[2], (A[0] // A[1] + 1) * A[3]))
else:
	print(A[0] * A[2])


import math
import itertools
gh = lambda : map(int, input().split())
mod = 998244353
mod = int(mod)

def main():
	(n, m, a, b) = gh()
	t = n // m * b + n % m * a
	g = (n // m + (n % m > 0)) * b
	f = n * a
	ans = min(g, t)
	print(min(f, ans))
main()


lst = list(map(int, input().strip().split(' ')))
n = lst[0]
m = lst[1]
a = lst[2]
b = lst[3]
op1 = int(n / m) * b + n % m * a
op2 = int(n / m) * b + b
op3 = n * a
lst1 = [op1, op2, op3]
lst1.sort()
print(lst1[0])


(n, mRides, singleRideCost, multiRidesCost) = [int(p) for p in input().split()]
if multiRidesCost / mRides >= singleRideCost:
	print(singleRideCost * n)
elif mRides >= n:
	if multiRidesCost <= n * singleRideCost:
		print(multiRidesCost)
	else:
		print(singleRideCost * n)
else:
	total = 0
	onlyMultiple = multiRidesCost * (n // mRides)
	if n % mRides != 0:
		onlyMultiple += multiRidesCost
	total += multiRidesCost * (n // mRides)
	total += n % mRides * singleRideCost
	if total < onlyMultiple:
		print(total)
	else:
		print(onlyMultiple)


import math
(n, m, a, b) = [int(x) for x in input().split()]
print(min(n * a, b * math.ceil(n / m), b * (n // m) + a * (n % m), b + a * abs(n - m)))


def main():
	(n, m, a, b) = map(int, input().split())
	if a * m <= b:
		print(n * a)
	else:
		ans = 0
		rides = n // m
		ans += rides * b
		price_a = (n - rides * m) * a
		if price_a > b:
			ans += b
		else:
			ans += price_a
		print(ans)
main()


(n, m, a, b) = map(int, input().split())
avg_price = b / m
if avg_price >= a:
	print(n * a)
else:
	sale = int(n // m)
	money = sale * b + (n - sale * m) * a
	money2 = (sale + 1) * b
	print(min(money, money2))


s = input().split()
n = int(s[0])
m = int(s[1])
a = int(s[2])
b = int(s[3])
ab = b / m
if ab > a:
	print(n * a)
else:
	l = n // m * b + n % m * a
	ll = n // m * b + b
	if l < ll:
		print(l)
	else:
		print(ll)


(n, m, a, b) = map(int, input().split())
ans1 = n // m * b + n % m * a
ans2 = a * n
ans3 = n // m * b + b
print(min(ans1, ans2, ans3))


(n, m, a, b) = map(int, input().split())
if m * a <= b:
	print(n * a)
else:
	specials = n // m
	remainder = n - m * specials
	if remainder * a <= b:
		print(specials * b + remainder * a)
	else:
		print((specials + 1) * b)


(kol, abon, rub, abonr) = map(int, input().split())
if kol // abon == 0 and kol > abon:
	x = min(kol * rub, kol // abon * abonr)
else:
	x = min(kol * rub, (kol // abon + 1) * abonr, kol // abon * abonr + kol % abon * rub)
print(x)


x = input()
(n, m, a, b) = x.split(' ')
c = int(n) % int(m)
z = int(n) - c
p = z / int(m)
r = p * int(b) + c * int(a)
k = min(int(n) * int(a), r, int(b) * (p + 1))
print(int(k))


(n, m, a, b) = input().split()
n = int(n)
m = int(m)
a = int(a)
b = int(b)
sum = 0
if b / m < a:
	sum1 = int(n / m) * b + n % m * a
	sum2 = int((n + m - 1) / m) * b
	if sum1 < sum2:
		print(sum1)
	else:
		print(sum2)
else:
	sum = n * a
	print(sum)


(n, m, a, b) = map(int, input().split())

def ceil(a, b):
	return (a + b - 1) // b
if m * a <= b:
	print(n * a)
else:
	print(min(ceil(n, m) * b, n // m * b + n % m * a))


(n, m, a, b) = input().split()
i = 0
s = 0
n = int(n)
m = int(m)
a = int(a)
b = int(b)
if n * a < int(n / m) * b:
	print(n * a)
	exit(0)
if n % m == 0:
	print(int(n / m * b))
elif n % m * a > b:
	print(int(n / m) * b + b)
else:
	print(int(n / m) * b + int(n % m) * a)


a = list(map(int, input().split()))
print(min(a[0] * a[2], a[3] * (a[0] // a[1]) + a[2] * (a[0] % a[1]), a[3] * ((a[0] - 1) // a[1] + 1)))


import math
(n, m, a, b) = map(int, input().split())
withPass = n // m * b
withoutPass = n * a
if withoutPass <= withPass:
	print(withoutPass)
elif math.ceil(n / m) * b < withoutPass and math.ceil(n / m) * b < withPass + n % m * a:
	print(math.ceil(n / m) * b)
elif withPass + n % m * a < withoutPass:
	print(withPass + n % m * a)
else:
	print(n * a)


import math
(n, m, a, b) = map(int, input().split())
if m * a >= b:
	r = n % m
	if r == 0:
		print(n // m * b)
	else:
		p = math.ceil(n / m) * b
		q = n // m * b + r * a
		if p >= q:
			print(q)
		else:
			print(p)
else:
	print(n * a)


import sys
from math import *
input = sys.stdin.readline
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : input().strip().split()
from collections import defaultdict as df
import heapq
infinite = float('inf')
(n, m, a, b) = RI()
ans = 0
while n != 0:
	if n >= m:
		if b / m < a:
			n -= m
			ans += b
		else:
			n -= m
			ans += m * a
	else:
		if n * a < b:
			ans += n * a
		else:
			ans += b
		n = 0
print(ans)


def main():
	(n, m, a, b) = get_ints()
	result1 = n // m * b + n % m * a
	result2 = a * n
	result3 = n // m * b + b
	print(min(result1, result2, result3))

def get_ints():
	return list((int(x) for x in input().split(' ')))
main()


_ = list(map(int, input().split()))
print(min(min(_[0] // _[1] * _[3], _[0] // _[1] * _[1] * _[2]) + (_[0] - _[0] // _[1] * _[1]) * _[2], (_[0] // _[1] + 1) * _[3]))


import math
(n, m, a, b) = map(int, input().split())
if b / m >= a:
	print(int(n * a))
elif n % m == 0:
	print(int(n / m * b))
else:
	mt = int(n / m) * b
	ot = n % m * a
	tmt = math.ceil(n / m) * b
	mn = min(ot + mt, tmt)
	print(int(mn))


(xucheng, fukecheng, danjia, fujia) = [int(i) for i in input().split()]
if danjia <= fujia / fukecheng:
	print(xucheng * danjia)
else:
	maijizhangfu = xucheng // fukecheng
	print(min(maijizhangfu * fujia + (xucheng - maijizhangfu * fukecheng) * danjia, (maijizhangfu + 1) * fujia))


(n, m, a, b) = map(int, input().split())
t = n * a
p = n % m * a + n // m * b
if n % m == 0:
	q = n // m * b
else:
	q = (n // m + 1) * b
print(min(t, p, q))


import math
(n, m, a, b) = map(int, input().split())
c = 0
if m * a <= b:
	print(n * a)
else:
	x = math.floor(n / m)
	c += x * b
	n = n - m * x
	if n * a <= b:
		c += n * a
	else:
		c += b
	print(c)


(rides, spcl, price, spclprice) = map(int, input().split())
countspcl = 1
if spclprice / spcl >= price:
	print(rides * price)
else:
	while True:
		if countspcl * spcl <= rides:
			countspcl += 1
		else:
			countspcl -= 1
			break
	if countspcl * spcl == rides:
		print(countspcl * spclprice)
	else:
		remain = rides - countspcl * spcl
		total = remain * price + countspcl * spclprice
		total2 = (countspcl + 1) * spclprice
		print(min(total, total2))


num = list(map(int, input().strip().split()))
if num[2] <= num[3] / num[1]:
	print(num[0] * num[2])
else:
	x = num[0] // num[1]
	if (num[0] - x * num[1]) * num[2] > num[3]:
		print((x + 1) * num[3])
	else:
		print(x * num[3] + (num[0] - x * num[1]) * num[2])


import math
(n, m, a, b) = input().split()
n = int(n)
m = int(m)
a = int(a)
b = int(b)
no_m = n // m
no_m2 = math.ceil(n / m)
combine = b * no_m + a * (n - no_m * m)
only_a = a * n
only_b = b * no_m2
print(min(combine, only_b, only_a))


(n, m, a, b) = map(int, input().split())
mcost = b / m
if a <= mcost:
	print(n * a)
else:
	an = b * (n // m)
	x = a * (n % m)
	an += min(x, b)
	print(an)


from sys import stdin
(n, m, a, b) = [int(x) for x in stdin.read().rstrip().split()]
result1 = n // m * b + n % m * a
result2 = n * a
result3 = (n + m - 1) // m * b
result = min(result1, result2, result3)
print(result)


from math import ceil

def main():
	[n, m, a, b] = map(int, input().split(' '))
	first_ratio = b / m
	second_ratio = a / 1
	costs = 0
	if first_ratio < second_ratio:
		costs = b * (n // m)
		rest = n % m
		if a * rest < b:
			costs += a * rest
		else:
			costs += b
	else:
		costs = a * n
	print(costs)
main()


(n, m, a, b) = map(int, input().split())
n1 = n
sum1 = 0
sum2 = 0
for i in range(n):
	sum1 = n * a
while n - m >= 0:
	sum2 = sum2 + b
	n = n - m
if n != 0:
	if b < a:
		sum2 = sum2 + b * (n // m + 1)
	else:
		sum2 = sum2 + n * a
if m > n1:
	sum2 = b
print(min(sum1, sum2))


import math
k = input().split()
(n, m, a, b) = (int(k[0]), int(k[1]), int(k[2]), int(k[3]))
i = n // m
o = i * b
p = n - i * m
o = o + p * a
g = math.ceil(n / m)
o2 = g * b
o3 = n * a
li = [o, o2, o3]
li.sort()
print(li[0])


(n, m, a, b) = map(int, input().split())
if m * a <= b:
	res = n * a
else:
	x = n // m
	y = n - x * m
	res = x * b + min(y * a, b)
print(res)


nmab = input().split()
(n, m, a, b) = (int(nmab[0]), int(nmab[1]), int(nmab[2]), int(nmab[3]))
cc = n // m * b + n % m * a
scc = (n // m + 1) * b
sc = n * a
for i in range(3):
	if cc <= sc and cc < scc:
		print(cc)
		break
	if scc <= cc and scc <= sc:
		print(scc)
		break
	else:
		print(sc)
		break


(n, m, a, b) = map(int, input().split())
from math import floor
from math import ceil
if n < m:
	print(min(n * a, b))
elif b / m < a and b > a:
	print(int(floor(n / m) * b + (n - m * floor(n / m)) * a))
elif b <= a:
	print(int(ceil(n / m) * b))
else:
	print(int(n * a))


(n, m, a, b) = map(int, input().split())
f = a * n
z = m + m
x = n // m
y1 = (n - x * m) * a
y2 = x * b
y3 = y1 + y2
z1 = m + x * m
b1 = b / m
z2 = z1 * b1
z3 = (x + 1) * b
if y3 <= f and y3 <= z2:
	print(y3)
elif f <= z2:
	print(f)
else:
	print(z3)


(a, b, c, d) = map(int, input().split())
if d / b < c:
	e = a // b * d
	f = a % b
	e += min(f * c, d)
	print(e)
else:
	print(a * c)


s = input()
x = list()
x = s.split()
(n, m, a, b) = (int(x[0]), int(x[1]), int(x[2]), int(x[3]))
p = b / m
if p < a:
	print(int(n / m) * b + min(n % m * a, b))
else:
	print(n * a)


import sys
import math
nums = sys.stdin.readline().split(' ')
nums = map(int, nums)
(n, m, a, b) = nums
c = math.floor(b / m)
if c < a:
	num_m_passes = math.floor(n / m)
	spent = num_m_passes * b
	if b < (n - num_m_passes * m) * a:
		spent += b
	else:
		spent += (n - num_m_passes * m) * a
else:
	spent = a * n
print(spent)


nmab = list(map(int, input().split()))
if nmab[2] > nmab[3] / nmab[1] and nmab[0] % nmab[1] * nmab[2] < nmab[3]:
	print(nmab[0] // nmab[1] * nmab[3] + nmab[0] % nmab[1] * nmab[2])
elif nmab[2] > nmab[3] / nmab[1] and nmab[0] % nmab[1] * nmab[2] >= nmab[3]:
	print((nmab[0] // nmab[1] + 1) * nmab[3])
else:
	print(nmab[0] * nmab[2])


(n, m, a, b) = map(int, input().split())
sum1 = n * a
if n % m == 0:
	sum2 = n // m * b
else:
	sum2 = n // m * b
	z = min(n % m * a, b)
	sum2 += z
print(min(sum1, sum2))


(a, b, c, d) = tuple(input().split(' '))
a = int(a)
b = int(b)
c = int(c)
d = int(d)
if float(c) <= d / b:
	print(c * a)
	exit(0)
sum = a // b * d
a -= a // b * b
if a * c < d:
	print(sum + a * c)
else:
	print(sum + d)


(n, m, a, b) = map(int, input().split())
c = 0
while n >= m:
	c += min(m * a, b)
	n -= m
c += min(n * a, b)
print(c)


from math import ceil
(n, m, a, b) = map(int, input().split())
rem = n // m
if rem * b > n * a:
	print(n * a)
else:
	res = rem * b
	if (n - rem * m) * a < b:
		print(res + (n - rem * m) * a)
	else:
		print(res + b)


import math
(n, m, a, b) = [int(i) for i in input().split()]
if n * a < b:
	sum = n * a
elif m * a > b and a < b:
	if n > m:
		sum = n // m * b + n % m * a
	else:
		sum = b
elif m * a > b and a >= b:
	sum = math.ceil(n / m) * b
else:
	sum = n * a
print(sum)


(rid, m, single, mprice) = map(int, input().split())
res = 0
while rid != 0:
	if rid < m:
		if rid * single >= mprice:
			res = res + mprice
			rid = 0
			break
		else:
			res = res + rid * single
			rid = 0
			break
	if single * m >= mprice:
		rid = rid - m
		res = res + mprice
	else:
		res = res + rid * single
		break
print(res)


(n, m, a, b) = map(int, input().split())
res = a * n
for i in range(max(n // m, 1) + 2):
	res = min(res, i * b + a * max(n - i * m, 0))
print(res)


import sys
import math
from collections import Counter
from collections import OrderedDict
from collections import defaultdict
from functools import reduce
sys.setrecursionlimit(10 ** 6)

def inputt():
	return sys.stdin.readline().strip()

def printt(n):
	sys.stdout.write(str(n) + '\n')

def listt():
	return [int(i) for i in inputt().split()]

def gcd(a, b):
	return math.gcd(a, b)

def lcm(a, b):
	return a * b // gcd(a, b)

def factors(n):
	step = 2 if n % 2 else 1
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(math.sqrt(n)) + 1, step) if n % i == 0)))

def comb(n, k):
	factn = math.factorial(n)
	factk = math.factorial(k)
	fact = math.factorial(n - k)
	ans = factn // (factk * fact)
	return ans

def is_prime(n):
	if n <= 1:
		return False
	if n == 2:
		return True
	if n > 2 and n % 2 == 0:
		return False
	max_div = math.floor(math.sqrt(n))
	for i in range(3, 1 + max_div, 2):
		if n % i == 0:
			return False
	return True

def maxpower(n, x):
	B_max = int(math.log(n, x)) + 1
	return B_max
t = 1
for _ in range(t):
	(n, m, a, b) = map(int, inputt().split())
	cost = 0
	cost = min(n // m * b + b, n * a, n // m * b + n % m * a)
	printt(cost)


(n_val, m_val, a_val, b_val) = list(map(int, input().split()))
m_per_ride = b_val / m_val
a_per_ride = a_val
if m_per_ride < a_per_ride:
	money_1 = n_val // m_val * b_val + n_val % m_val * a_val
	money_2 = n_val // m_val * b_val + 1 * b_val
	money = min(money_1, money_2)
else:
	money = n_val * a_per_ride
print(money)


import math
nmab = [int(x) for x in input().split()]
price = 0
while nmab[0] > 0:
	if nmab[0] < nmab[1]:
		if nmab[0] * nmab[2] > nmab[3]:
			price += nmab[3]
			nmab[0] = 0
		else:
			price += nmab[2]
			nmab[0] -= 1
	elif math.ceil(nmab[0] / nmab[1]) * nmab[3] < nmab[0] * nmab[2]:
		price += nmab[3]
		nmab[0] -= nmab[1]
	else:
		price += nmab[2]
		nmab[0] -= 1
print(price)


arr = list(map(int, input().split()))
n = arr[0]
m = arr[1]
a = arr[2]
b = arr[3]
ans = 0
i = n
while i > 0:
	if b < m * a and i > m:
		r = n // m
		ans += r * b
		i -= r * m
	elif b < m * a and i < m:
		if b < a * i:
			ans += b
			i = 0
		else:
			ans += a * i
			i = 0
	else:
		ans += i * a
		i = 0
print(ans)


import math
(n, m, a, b) = map(int, input().split())
lst = [n * a, b * math.floor(n / m) + (n - math.floor(n / m) * m) * b, b * math.floor(n / m) + (n - math.floor(n / m) * m) * a, b * math.floor(n / m) + b]
if m > n and b < a * n:
	print(b)
else:
	print(min(lst))


(n, m, a, b) = [int(i) for i in input().split()]
count = 0
while n > 0:
	if n > m:
		if b < m * a:
			n = n - m
			count = count + b
		else:
			n = n - 1
			count = count + a
	elif n * a < b:
		n = n - 1
		count = count + a
	else:
		n = n - m
		count = count + b
print(count)


(n, m, a, b) = map(int, input().split(' '))
k = int(n / m)
if k * b > k * m * a:
	sol = k * m * a
else:
	sol = k * b
if (n - k * m) * a < b:
	sol = sol + (n - k * m) * a
else:
	sol = sol + b
print(sol)


(n, m, a, b) = map(int, input().split())
i = 1
while True:
	if m * i > n:
		break
	i += 1
raf = i * b
j = i - 1
tut = j * b + (n - j * m) * a
talika = [raf, tut, n * a]
print(min(talika))


(a, b, c, d) = [int(i) for i in input().split()]
print(min(a * c, a // b * d + (a - a // b * b) * c, a // b * d + d))


def chaepTravels(n, m, a, b):
	from math import ceil
	mrides = n // m
	nrides = n % m
	return min(mrides * b + nrides * a, n * a, ceil(n / m) * b)
(n, m, a, b) = input().split()
print(chaepTravels(int(n), int(m), int(a), int(b)))


(n, m, a, b) = map(int, input().split())
ans1 = n * a
t = n // m
if n % m != 0:
	t += 1
ans2 = t * b
k = n % m
ans3 = k * a + n // m * b
print(min(ans1, ans2, ans3))


from math import ceil
(Ra, Rm, Pr, Pm) = map(int, input().split())
m = Ra * Pr
_Pm = Ra // Rm * Pm
_Pm += Ra % Rm * Pr
m = min(m, _Pm)
m = min(m, int(ceil(Ra / Rm)) * Pm)
print(m)


def ch(i, ii):
	if i / ii > int(i / ii):
		return i // ii + 1
	else:
		return i // ii
(i1, i2, i3, i4) = list(map(int, input().split()))
i = ch(i1, i2)
print(min([i * i4, i1 * i3, i1 // i2 * i4 + i1 % i2 * i3]))


import math
(n, m, a, b) = map(int, input().split())
x = n * a
y = math.ceil(n / m) * b
z = n // m * b + n % m * a
print(min(x, y, z))


input_s = input().split(' ')
n = int(input_s[0])
m = int(input_s[1])
a = int(input_s[2])
b = int(input_s[3])
if b / m < a:
	print(n // m * b + min(n % m * a, b))
else:
	print(n * a)


num = list(map(int, input().split()))
(n, m, a, b) = (num[0], num[1], num[2], num[3])
if b / m >= a:
	print(n * a)
elif b > a * (n % m):
	print(n // m * b + n % m * a)
else:
	print((n // m + 1) * b)


(n, m, a, b) = map(int, input().split())
cost = 0
l = 0
if n >= m:
	s = (n - n % m) / m
	g = n % m
	if a / 1 > b / m:
		print(min(int(a * g + b * s), int(b * (s + 1))))
	else:
		print(int(n * a))
else:
	print(min(map(int, [n * a, b])))


(n, m, a, b) = input().split()
(n, m, a, b) = (int(n), int(m), int(a), int(b))
if b / m < a:
	res1 = n % m * a + n // m * b
	if n % m < m:
		res2 = (n // m + 1) * b
	else:
		res2 = (n % m + n // m) * b
	if n < m and b < min(res1, res2):
		print(b)
	else:
		print(min(res1, res2))
else:
	print(n * a)


def codeforces():
	(n, m, a, b) = map(int, input().split())
	res_1 = n * a
	res_2 = n // m * b + min(n % m * a, b)
	return min(res_1, res_2)
print(codeforces())


import math
import os
import sys
import re
import string
import itertools
import functools
import operator
(n, m, a, b) = map(int, input().split())
if a * m <= b:
	print(a * n)
else:
	print(n // m * b + min(n % m * a, b))


(n, m, a, b) = map(int, input().split(' '))
if n == m:
	print(b)
elif n % m == 0:
	va = n * a
	vb = n // m * b
	print(va if va < vb else vb)
elif n > m:
	if a < b:
		vb = (n - n % m) // m * b
		va = n % m * a
		print(va + vb)
	else:
		v = (n - n % m) // m * b + b
		print(v)
elif n < m:
	va = n * a
	if va < b:
		print(va)
	else:
		print(b)


lis = input().split(' ')
arr = [float(i) for i in lis]
check = float(arr[3] / arr[1])
ans = 0
if check >= arr[2]:
	ans = arr[0] * arr[2]
else:
	div = int(arr[0] / arr[1])
	mod = int(arr[0]) % int(arr[1])
	ans = div * arr[3] + min(mod * arr[2], arr[3])
print(int(ans))


import math
(n, m, a, b) = [int(i) for i in input().split()]
if m * a >= b:
	c = math.ceil(n / m) - 1
	d = n - m * c
	if a * d >= b:
		p = (c + 1) * b
	else:
		p = c * b + a * d
else:
	p = n * a
print(p)


import math
(n, m, a, b) = map(int, input().split())
c1 = n * a
c2 = math.ceil(n / m) * b
c3 = n // m * b + n % m * a
if c1 < c2 and c1 < c3:
	print(c1)
elif c2 < c1 and c2 < c3:
	print(c2)
else:
	print(c3)


(a, b, c, d) = map(int, input().split())
print(min(a * c, d * (a // b) + min(a % b * c, d)))


(rides, count, single_ticket, group_ticket) = map(int, input().split())
prices = [group_ticket * i + single_ticket * max(0, rides - count * i) for i in range(1 + (rides + count - 1) // count)]
print(min(prices))


from sys import stdin
(num_rides, num_rides_spec_ticket, cost_one_ride, cost_spec_ticket) = list(map(int, stdin.readline().split()))
total_cost = 0
num_spec_tickets = num_rides // num_rides_spec_ticket
spec_total_cost = num_spec_tickets * cost_spec_ticket
rides_covered_by_spec_tickets = num_spec_tickets * num_rides_spec_ticket
reg_total_cost = rides_covered_by_spec_tickets * cost_one_ride
if spec_total_cost < reg_total_cost:
	total_cost += spec_total_cost
else:
	total_cost += reg_total_cost
num_remaining_rides = num_rides - rides_covered_by_spec_tickets
if num_remaining_rides > 0:
	cost_remaining_rides_nonspec = num_remaining_rides * cost_one_ride
	cost_remaining_rides_spec = cost_spec_ticket
	if cost_remaining_rides_nonspec < cost_remaining_rides_spec:
		total_cost += cost_remaining_rides_nonspec
	else:
		total_cost += cost_remaining_rides_spec
print(total_cost)


(n, m, a, b) = list(map(int, input().split()))
t1 = m * a
if n <= m:
	print(min(b, a * n))
elif t1 <= b:
	print(n * a)
else:
	t2 = n // m
	t3 = n % m
	t4 = t2 * b
	print(min(t4 + b, t4 + t3 * a))


(n, m, a, b) = map(int, input().split(' '))
sum = 0
c = []
d = []
sum1 = 0
sum4 = 0
sum3 = n * a
sum2 = 0
sum5 = 0
while True:
	sum = sum + m
	c.append(b)
	if sum == n:
		break
	elif sum > n:
		sum = sum - m
		c.remove(b)
		subtract = n - sum
		for i in range(subtract):
			c.append(a)
		break
	else:
		continue
for i in range(0, len(c)):
	sum1 = sum1 + c[i]
while True:
	sum2 = sum2 + m
	d.append(b)
	if sum2 == n:
		break
	elif sum2 > n:
		sum2 = sum2 - m
		d.remove(b)
		subtract = n - sum2
		if subtract < m:
			d.append(b)
		break
	else:
		continue
for i in range(0, len(d)):
	sum5 = sum5 + d[i]
if n % m == 0:
	divide = n // m
	for i in range(divide):
		sum4 = sum4 + b
if sum4 != 0:
	print(min(sum1, sum4, sum3, sum5))
else:
	print(min(sum1, sum3, sum5))


def cheaptravel(n, m, a, b):
	if m * a > b:
		q = n // m
		r = n % m
		if r * a > b:
			return q * b + b
		else:
			return q * b + r * a
	else:
		return n * a
(n, m, a, b) = map(int, input().split())
print(cheaptravel(n, m, a, b))


from sys import stdin, stdout
import math
input = stdin.readline

def print(x='', y='', end='\n'):
	if y == '':
		stdout.write(str(x) + end)
	else:
		stdout.write(str(x) + ' ' + str(y) + end)

def solve():
	(n, m, a, b) = map(int, input().split())
	if b // m < a:
		print(n // m * b + min(math.ceil((n - m * (n // m)) / m) * b, (n - m * (n // m)) * a))
	else:
		print(n * a)
tt = 1
for __ in range(tt):
	solve()


from math import ceil
(t, m, c, mc) = map(int, input().split())
tot1 = ceil(t / m) * mc
tot2 = t * c
tot3 = t // m * mc + t % m * c
print(min([tot1, tot2, tot3]))


z = list(map(int, input().split()))
c = 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
f = 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
b = z[0] // z[1] * z[3]
if z[0] % z[1] != 0:
	c = 0
	c = b + z[0] % z[1] * z[3]
	b += z[0] % z[1] * z[2]
	f = z[0] // z[1] * z[1] + z[1]
	if f >= z[0]:
		f = (z[0] // z[1] + 1) * z[3]
	else:
		f = 99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
a = z[0] * z[2]
if z[0] <= z[1]:
	c = z[3]
print(min(a, b, c, f))


import sys
import math
input = sys.stdin.readline

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

def solve(n, m, a, b):
	if b <= a:
		return int(math.ceil(n / m)) * b
	if m >= n:
		if b < n * a:
			return b
		return n * a
	cp = b / m
	if cp < a:
		pr = int(n / m)
		return pr * b + (n - pr * m) * a
	else:
		return n * a
nmab = inlt()
print(int(solve(nmab[0], nmab[1], nmab[2], nmab[3])))


(n, m, a, b) = map(int, input().split())
owayp = n * a
if n % m == 0:
	mwayp = n // m * b
else:
	mwayp1 = (n // m + 1) * b
	mwayp2 = n // m * b + n % m * a
	mwayp = min(mwayp1, mwayp2)
print(min(owayp, mwayp))


(n, m, a, b) = list(map(int, input().split(' ')))
e = 0
c = 0
c = c + n // m * b
e = n // m
d = n - e * m
if d * a < b:
	c = c + d * a
else:
	c = c + b
if n * a < c:
	print(n * a)
else:
	print(c)


(n, m, a, b) = input().split()
n = int(n)
m = int(m)
a = int(a)
b = int(b)
if b < m * a:
	r1 = n // m * b + n % m * a
	r2 = (n // m + 1) * b
	r = min(r1, r2)
else:
	r = n * a
print(r)


import math
num_input = input()
num_input = num_input.split(' ')
n = int(num_input[0])
m = int(num_input[1])
a = int(num_input[2])
b = int(num_input[3])
if b < a:
	combo = math.ceil(n / m)
	rubles = combo * b
elif b / m < a:
	combo = int(n / m)
	rubles = min(combo * b + n % m * a, (combo + 1) * b)
else:
	rubles = n * a
print(rubles)


(p, q, i, j) = map(int, input().split())
t = p // q * j
if p % q * i < j:
	t += p % q * i
else:
	t += j
t1 = p * i
if t < t1:
	print(t)
else:
	print(t1)


(n, m, a, b) = map(int, input().split())
if a <= b / m:
	print(n * a)
else:
	ride_ticket = n // m
	ride_cost = b * ride_ticket
	one_ticket = n - ride_ticket * m
	one_cost = a * one_ticket
	res1 = one_cost + ride_cost
	res2 = (ride_ticket + 1) * b
	print(min(res1, res2))


(n, m, a, b) = map(int, input().split())
n2 = n
total = 0
pay = 0
while n2 >= m:
	total += b
	n2 -= m
if n2 > 0:
	if n2 * a > b:
		total += b
	else:
		total += n2 * a
pay = n * a
if pay < total:
	print(pay)
else:
	print(total)


from math import ceil

def cheaptravel(n, m, a, b):
	cost1 = n // m * b + n % m * a
	cost2 = n * a
	cost3 = ceil(n / m) * b
	print(min(cost1, cost2, cost3))
(n, m, a, b) = input().split()
cheaptravel(int(n), int(m), int(a), int(b))


(l, nm, x, nk) = list(map(int, input().split()))
j = nk / nm
if j >= x:
	print(l * x)
elif nk < l * x and nm >= l:
	print(nk)
else:
	ost = l % nm
	if ost * x >= nk:
		print(l // nm * nk + nk)
	else:
		print(l // nm * nk + ost * x)


args = [int(a) for a in input().strip().split()]
(num_rides, num_special_rides, one_ticket_price, special_ticket_price) = args
if one_ticket_price <= special_ticket_price / num_special_rides:
	print(one_ticket_price * num_rides)
else:
	(special_bought, remainder) = divmod(num_rides, num_special_rides)
	total_spent = special_bought * special_ticket_price
	if remainder != 0:
		if remainder * one_ticket_price < special_ticket_price:
			total_spent += remainder * one_ticket_price
		else:
			total_spent += special_ticket_price
	print(total_spent)


(n, m, a, b) = map(int, input().split())
orgp = a
offp = b / m
amount = 0
if offp < orgp:
	while n > m:
		n -= m
		amount += b
	amount += min(b, n * a)
else:
	amount += n * a
print(amount)


(n, m, a, b) = map(int, input().split())
if b / m < a:
	count1 = int(n / m) * b + n % m * a
	count2 = int(n / m) * b + b
	if count1 < count2:
		print(count1)
	else:
		print(count2)
else:
	print(n * a)


(n, m, a, b) = map(int, input().split())
sum1 = 0
sum2 = 0
rides = 0
if b / m >= a:
	print(n * a)
else:
	while rides <= n:
		rides += m
		sum1 += b
	sum2 = sum1 - b
	rides = rides - m
	while rides < n:
		rides += 1
		sum2 += a
	print(min(sum1, sum2))


def _466A(n, m, a, b):
	if b / m < a:
		if b > n % m * a:
			return n // m * b + n % m * a
		else:
			return (n // m + 1) * b
	else:
		return n * a
(n, m, a, b) = list(map(lambda x: int(x), input().split()))
print(_466A(n, m, a, b))


from math import *

def main():
	(n, m, a, b) = map(int, input().split())
	package_ride = floor(n / m)
	single_ride = n - m * package_ride
	if m * a >= b:
		if n % m == 0:
			ans = package_ride * b
			print(ans)
		elif single_ride * a < b:
			ans = single_ride * a + package_ride * b
			print(ans)
		else:
			ans = package_ride * b + b
			print(ans)
	else:
		ans = n * a
		print(ans)
main()


(n, m, a, b) = map(int, input().split())
all_tickets = n // m * b
if n % m != 0:
	all_tickets += b
most_tickets = n // m * b + n % m * a
no_tickets = n * a
ans = min(all_tickets, most_tickets, no_tickets)
print(ans)


def solution(n, m, a, b):
	if n % m == 0:
		res = min(a * n, b * n // m)
	else:
		res = min(a * n, b * (n // m + 1), b * (n // m) + a * (n % m))
	return res
f = lambda : map(int, input().split())
(n, m, a, b) = f()
print(solution(n, m, a, b))


import math
(n, m, a, b) = list(map(int, input().split()))
if b / m > a:
	print(n * a)
elif b / m < a and b < a * n and (math.ceil(n / m) * b >= n % m * a + n // m * b):
	print(n % m * a + n // m * b)
elif math.ceil(n / m) * b < n % m * a + n // m * b:
	print(math.ceil(n / m) * b)
elif b / m < a and b > a * n:
	print(n * a)
else:
	print(n * a)


(n, m, a, b) = map(int, input().strip().split(' '))
if m <= b / a:
	ans = n * a
else:
	ans = n // m * b
	tmp = min(n % m * a, b)
	ans += tmp
print(ans)


(n, m, a, b) = map(int, input().split())
pay = 0
while n > 0:
	if m < n:
		inc = b if b < m * a else m * a
		n -= m
	else:
		inc = b if b < n * a else n * a
		n = 0
	pay += inc
print(pay)


from sys import stdin, stdout, stderr
import sys
inints = lambda : [int(x) for x in stdin.readline().split()]
fastwrite = lambda s: stdout.write(str(s) + '\n')
fasterr = lambda s: stderr.write(str(s) + '\n')
irange = lambda x, y: range(x, y + 1)
(n, m, a, b) = inints()
res = min(min(a * n, b * (n // m) + a * (n % m)), b * (n // m + 1))
fastwrite(res)


(n, m, a, b) = input().split()
n = int(n)
m = int(m)
a = int(a)
b = int(b)
price_one = n * a
how_many_special = n // m
if n % m != 0:
	how_many_special += 1
price_two = how_many_special * b
how_many_special_tickets = n // m
num_of_single_tickets = n % m
price_three = how_many_special_tickets * b + num_of_single_tickets * a
if price_one < price_two and price_one < price_three:
	print(price_one)
elif price_two < price_one and price_two < price_three:
	print(price_two)
elif price_three < price_one and price_three < price_two:
	print(price_three)
elif price_one == price_two or price_one == price_three:
	print(price_one)
elif price_two == price_one or price_two == price_three:
	print(price_two)


(num_rides, sticket_val, nticket_cost, sticket_cost) = list(map(int, input().split()))
if sticket_cost / sticket_val > nticket_cost:
	print(num_rides * nticket_cost)
else:
	amt_sticket = num_rides // sticket_val
	rest_rides = num_rides - amt_sticket * sticket_val
	if rest_rides * nticket_cost > sticket_cost:
		print((amt_sticket + 1) * sticket_cost)
	else:
		print(amt_sticket * sticket_cost + rest_rides * nticket_cost)


(a, b, c, d) = map(int, input().split())
ans = 0
if d // b < c:
	ans = a // b * d
	a = a % b
else:
	ans = a * c
	a = 0
if a != 0:
	ans += min(a * c, d)
print(ans)


import os
import sys
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
from math import ceil

def main():
	(n, m, a, b) = invr()
	(div, rem) = divmod(n, m)
	print(min(a * n, div * b + min(a * rem, b)))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys

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

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
(n, m, a, b) = rinput()
print(min(n * a, -n // m * -b, n // m * b + n % m * a))


(n, m, a, b) = map(int, input().split())

def cheap(n, m, a, b):
	if n < m:
		total_oneride = a * n
		total_mride = b
		return min(total_oneride, total_mride)
	else:
		total_oneride = 0
		total_mride = 0
		total_oneride = a * n
		temp = n // m
		temp2 = n - temp * m
		total_mride = temp * b
		if temp2 != 0:
			if a <= b:
				total_mride += temp2 * a
			else:
				total_mride += b
		return min(total_mride, total_oneride)
print(cheap(n, m, a, b))


(n, m, a, b) = [int(x) for x in input().split()]
minCost = 10000000
for x in range(0, n + 1):
	for y in range(0, int(n / m) + 2):
		if x + y * m >= n:
			if x * a + y * b < minCost:
				minCost = x * a + y * b
print(minCost)


import math
(n, Srides, nPrice, sPrice) = input().split()
n = int(n)
Srides = int(Srides)
nPrice = int(nPrice)
sPrice = int(sPrice)
if n == Srides:
	print(sPrice if sPrice < n * nPrice else n * nPrice)
else:
	sum = 0
	div = int(n / Srides)
	sum += div * sPrice
	left = n - Srides * div
	sum += left * nPrice
	sum1 = math.ceil(n / Srides) * sPrice
	sum2 = n * nPrice
	minimum = min(sum, min(sum1, sum2))
	print(minimum)


(n, m, a, b) = list(map(int, input().split()))
(tickets_count, abon_count) = (0, 0)
count_money = lambda ticket, abon: ticket * a + b * abon
if b >= a * m:
	print(n * a)
	exit(0)
abon_count = n // m
tickets_count = n % m
if tickets_count * a > b:
	tickets_count = 0
	abon_count += 1
print(tickets_count * a + abon_count * b)


inp = list(map(int, input().split()))
ratio1 = inp[1] / inp[3]
ratio2 = 1 / inp[2]
if ratio2 >= ratio1:
	print(inp[0] * inp[2])
else:
	choice1 = inp[0] // inp[1] * inp[3] + inp[0] % inp[1] * inp[2]
	choice2 = inp[0] // inp[1] * inp[3] + inp[3]
	if choice1 < choice2:
		print(choice1)
	else:
		print(choice2)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import collections as col
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	(N, M, A, B) = getInts()
	return min(A * N, N // M * B + min(N % M * A, B))
print(solve())


import math
(n, m, a, b) = [int(x) for x in input().split()]
result = n * a
diff = b / m
if diff < a:
	result = math.floor(n / m) * b
	n = n % m
	result += a * n if a * n < b else b
print(result)


inputs = input()
inputs = inputs.split(' ')
inputs = [int(i) for i in inputs]
x = int(inputs[0] / inputs[1])
y = inputs[0] % inputs[1]
minim = inputs[3] * x + y * inputs[2]
if minim > inputs[0] * inputs[2]:
	minim = inputs[0] * inputs[2]
if minim > (x + 1) * inputs[3]:
	minim = (x + 1) * inputs[3]
print(minim)


str = input().split()
(n, m, a, b) = (int(str[0]), int(str[1]), int(str[2]), int(str[3]))
min_cost = 10 ** 10
for i in range(n // m + 1):
	min_cost = min(min_cost, i * b + (n - i * m) * a)
min_cost = min(min_cost, round(n / m + 0.499999999999) * b)
print(min_cost)


(n, m, a, b) = list(map(int, input().split()))
if b / m < a:
	(c, d) = divmod(n, m)
	res = c * b
	if d * a < b:
		res += d * a
	else:
		res += b
	print(res)
else:
	print(n * a)


s = input()
for i in range(len(s)):
	if s[i] == ' ':
		n = int(s[:i])
		break
for j in range(i + 1, len(s)):
	if s[j] == ' ':
		m = int(s[i + 1:j])
		break
for k in range(j + 1, len(s)):
	if s[k] == ' ':
		a = int(s[j + 1:k])
		break
b = int(s[k + 1:])
l = []
for f in range(0, n, m):
	c = int((n - f) * a + f / m * b)
	l.append(c)
for i in range(0, n + m, m):
	d = int(i / m * b)
l.append(d)
print(min(l))


(n, m, a, b) = map(int, input().split())
if a * m > b:
	remain = n % m * a
	if remain > b:
		print(n // m * b + b)
	else:
		print(n // m * b + remain)
else:
	print(n * a)


s = input('')
(n, m, a, b) = s.split(' ')
n = int(n)
m = int(m)
a = int(a)
b = int(b)
if m * a < b:
	count = n * a
else:
	c = (n - m * (n // m)) * a
	count = b * (n // m) + min(c, b)
print(count)


import sys
input = sys.stdin.readline

def takeInput():
	return map(int, input().split())

def findM(n, m, a, b):
	n_rides = n * a
	m_rides = n // m * b + n % m * a
	nm_rides = n // m * b + (n % m != 0) * b
	return int(min(m_rides, n_rides, nm_rides))
(n, m, a, b) = takeInput()
print(findM(n, m, a, b))


(n, m, a, b) = map(int, input().split())
s = a * n
i = 0
while m * i <= n:
	s = min(s, i * b + (n - i * m) * a)
	i += 1
if n % m != 0:
	s = min(s, b * (n // m + 1))
print(s)


(a, b, c, d) = [int(i) for i in input().split()]
if b * c > d:
	k = a // b
	n = a % b
	if n != 0:
		mini = min(k * d + n * c, (k + 1) * d)
		print(mini)
	else:
		print(k * d + n * c)
else:
	print(c * a)


def use_special_ticket(n, m, a, b):
	price = 0
	while n > m:
		price += b
		n -= m
	price += min(n * a, b)
	return price
(n, m, a, b) = map(int, input().split())
print(min(a * n, use_special_ticket(n, m, a, b)))


a = list(map(int, input().split()))
if a[2] <= a[3] / a[1]:
	print(a[0] * a[2])
else:
	c = a[0] // a[1] * a[3]
	a[0] %= a[1]
	c += min(a[0] * a[2], a[3])
	print(c)


(n, m, a, b) = map(int, input().split())
if m * a <= b:
	print(a * n)
	exit()
y0 = n // m
r = n % m
print(b * y0 + min(b, a * r))


import sys
input = sys.stdin.readline
from math import log2, log, ceil

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return res

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
(n, m, a, b) = int_array()
x = n // m * b + n % m * a
y = ceil(n / m) * b
print(min(x, y, n * a))


(total_rides, rides, sprice, rupees) = map(int, input().split())
if rupees / rides > sprice and total_rides > rides:
	print(sprice * total_rides)
elif total_rides < rides:
	if sprice * total_rides > rupees:
		print(rupees)
	else:
		print(sprice * total_rides)
else:
	base_fare = total_rides // rides * rupees
	if rupees < sprice * (total_rides % rides):
		cement_fare = rupees
	else:
		cement_fare = sprice * (total_rides % rides)
	print(base_fare + cement_fare)


l = list(map(int, input().strip().split()))
n = l[0]
arr = []
rides = l[1]
one = l[2]
multi = l[3]
a = n // rides
b = n % rides
price = a * multi + b * one
if b != 0:
	rate = multi * (a + 1)
	arr.append(rate)
count = n * one
arr.append(count)
arr.append(price)
print(min(arr))


(n, m, a, b) = map(int, input().split())
one_ride = n * a
if m >= n:
	special = b
else:
	ride = n // m
	if ride == 0:
		ride = 1
	special = ride * b + a * (n % m)
	if special > ride * b + b:
		special = ride * b + b
if one_ride > special:
	one_ride = special
print(one_ride)


(n, m, a, b) = [int(x) for x in input().split()]
if b / m >= a:
	money = n * a
else:
	surplus = n % m
	if surplus * a > b:
		money = b * (int(n / m) + 1)
	else:
		money = b * int(n / m) + surplus * a
print(money)


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())
(n, m, a, b) = get_ints()
if a < b / m:
	prix = n * a
else:
	prix = min(b, n % m * a) + int(n / m) * b
print(prix)


(n, m, a, b) = map(int, input().split())
k = b / m
r = 0
if k < a:
	d = n // m
	f = d * b
	g = n % m
	if g * a < b:
		r = f + g * a
	else:
		r = f + b
else:
	r = a * n
print(r)


(n, m, a, b) = map(int, input().split())
cost = 0
if m > n:
	if n * a < b:
		cost += n * a
	else:
		cost += b
elif n * a < n // m * b:
	cost += n * a
else:
	while n >= m:
		cost += b
		n -= m
	if n != 0:
		cost += min(n * a, b)
print(cost)


(n, m, a, b) = map(int, input().split())
if n <= m:
	if n * a >= b:
		print(b)
	else:
		print(n * a)
if n > m:
	if b <= m * a:
		sum1 = n // m * b + n % m * a
		sum2 = n // m * b + b
		if sum1 > sum2:
			print(sum2)
		else:
			print(sum1)
	else:
		print(n * a)


(n, m, a, b) = map(int, input().split())
x = n // m * b + n % m * a
y = n * a
z = n // m * b + (n % m >= 1) * b
if x <= y and x < z:
	print(x)
if y < x and y < z:
	print(y)
if z <= y and z <= x:
	print(z)


q = input().split()
n = int(q[0])
m = int(q[1])
a = int(q[2])
b = int(q[3])
nm = n // m
mm = nm * b
left = n - nm * m
mn = left * a
if n % m == 0:
	x = n / m
else:
	x = n // m + 1
if n * a < mm + mn:
	print(n * a)
elif x * b < mm + mn:
	print(x * b)
else:
	print(mm + mn)


items = [int(tmp) for tmp in input().strip('\n\r\t\\ ').split(' ')]
n = items[0]
m = items[1]
a = items[2]
b = items[3]
l = []
l.append(a * n)
l.append(b * (n // m) + a * (n % m))
l.append(b * (n // m + 1))
print(min(l))


(n, m, a, b) = (int(i) for i in input().split())
f_price = a
a_price = b / m
if f_price < a_price:
	total = n * f_price
else:
	total = n // m * b
	last = f_price * (n % m)
	total += last if last < b else b
print(total)


(n, m, a, b) = map(int, input().split())
total_cost_tkt = a * n
min_fare = total_cost_tkt
amount_pass = n // m * b
if float(a) < b / m:
	print(a * n)
elif amount_pass + b > amount_pass + a * (n - n // m * m):
	print(amount_pass + a * (n - n // m * m))
else:
	print(amount_pass + b)


(n, m, a, b) = [int(x) for x in input().split()]
l = False
if b < a * m:
	l = True
c = 0
if l:
	c += n // m * b
	need = n % m
	c += min(b, a * need)
else:
	c += a * n
print(c)


(n, m, a, b) = list(map(int, input().split()))
if b > m * a:
	print(n * a)
else:
	x = n % m
	y = n // m
	cost = y * b
	if x * a > b:
		cost = cost + b
	else:
		cost = cost + x * a
	print(cost)


import math

def test_case(n, m, a, b):
	if b / m >= a:
		return a * n
	op1 = math.floor(n / m) * b + n % m * a
	op2 = math.ceil(n / m) * b
	return min(op1, op2)

def main():
	(n, m, a, b) = (int(x) for x in input().split(' '))
	print(test_case(n, m, a, b))
main()


import os
import sys
import math
(n, m, a, b) = input().strip().split(' ')
(n, m, a, b) = [int(n), int(m), int(a), int(b)]
cost = -1
if a * m <= b:
	cost = n * a
else:
	cost = n // m * b + min(n % m * a, b)
print(cost)


def main():
	item = list(map(int, input().split(' ')))
	rides = item[0]
	ridesAb = item[1]
	priceRide = item[2]
	priceAb = item[3]
	optimum = 0
	end = 1
	if max(rides / ridesAb, 1) * priceAb < priceRide * rides:
		if ridesAb >= rides:
			optimum = priceAb
		else:
			optimum = priceAb * (rides // ridesAb)
			end = rides - rides // ridesAb * ridesAb
			if end != 0 and priceAb < priceRide * end:
				optimum += priceAb
			elif end != 0:
				optimum += priceRide * end
	else:
		optimum = priceRide * rides
	print(optimum)
main()


def get_value():
	(rides, mrides, ride_cost, mride_cost) = [int(num) for num in input().split()]
	first_option = rides * ride_cost
	second_option = rides // mrides * mride_cost + rides % mrides * ride_cost
	third_option = (rides // mrides + 1) * mride_cost
	return min([first_option, second_option, third_option])
print(get_value())


info = list(map(int, input().split()))
n = info[0]
m = info[1]
a = info[2]
b = info[3]
ans = 0
if b / m < a:
	k = int(n / m)
	ans += k * b
	x = n % m
	if x * a < b:
		ans += x * a
	else:
		ans += b
	print(ans)
else:
	print(n * a)


(rides, sptic, normone, spprice) = map(int, input().split())
only_normal = rides * normone
only_special = rides / sptic * spprice if rides % sptic == 0 else (rides // sptic + 1) * spprice
combo = rides // sptic * spprice + rides % sptic * normone
print(int(min(only_normal, only_special, combo)))


import fileinput

def solve(n, m, a, b):
	cost = 0
	if b < m * a and m > 0:
		cost = n // m * b
		cost += min(b, n % m * a)
	else:
		cost = n * a
	return cost

def __starting_point():
	for line in fileinput.input():
		(n, m, a, b) = list(map(int, line.split(' ')))
		sol = solve(n, m, a, b)
		print(sol)
__starting_point()


a = input()
b = a.split()
if int(b[2]) > int(b[3]):
	if int(b[0]) / int(b[1]) != int(b[0]) // int(b[1]):
		ks = int(b[0]) // int(b[1]) + 1
		print(ks * int(b[3]))
	else:
		print(int(b[0]) // int(b[1]) * int(b[3]))
elif int(b[3]) / int(b[1]) < int(b[2]):
	if int(b[0]) / int(b[1]) != int(b[0]) // int(b[1]):
		cishu = int(b[0]) // int(b[1])
		if (cishu + 1) * int(b[3]) <= int(b[2]) * int(b[0]) and cishu == 0:
			print((int(b[0]) // int(b[1]) + 1) * int(b[3]))
		elif (cishu + 1) * int(b[3]) <= int(b[2]) * int(b[0]):
			print(int(b[0]) // int(b[1]) * int(b[3]) + int(b[0]) % int(b[1]) * int(b[2]))
		else:
			print(int(b[0]) * int(b[2]))
	elif int(b[0]) // int(b[1]) * int(b[3]) < int(b[2]) * int(b[0]):
		print(int(b[0]) // int(b[1]) * int(b[3]) + int(b[0]) % int(b[1]) * int(b[2]))
	else:
		print(int(b[0]) * int(b[2]))
else:
	print(int(b[0]) * int(b[2]))


(n, m, a, b) = [int(i) for i in input().split()]
x = int(n / m)
y = n % m
f = (x + 1) * b
k = x * b + y * a
l = n * a
print(min(f, k, l))


(n, m, a, b) = map(int, input().rstrip().split(' '))
z = n // m
y = n % m
t = min(z * a * m, b * z)
t += min(y * a, b)
print(t)


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
[n, m, a, b] = list(invr())
m_rate = b / m
if m_rate < a:
	cost = n // m * b
	if n % m * a > b:
		print(cost + b)
	else:
		print(cost + n % m * a)
else:
	print(n * a)


from sys import stdin, stdout
import math
get = stdin.readline
put = stdout.write
(n, m, a, b) = map(int, get().split())
k = b / m
if k <= a:
	m = min(n, m)
	x = n // m * b
	y = n % m
	print(min(x + b if b <= y * a else x + y * a, n * a))
else:
	print(n * a)


nmab = [int(i) for i in input().split()]
n = nmab[0]
m = nmab[1]
a = nmab[2]
b = nmab[3]
cost1 = n * a
cost2 = n // m * b + (n - n // m * m) * a
cost3 = (n // m + 1) * b
print(min(cost1, cost2, cost3))


(n, m, a, b) = map(int, input().split())
mTrips = n // m
print(min(a * n, mTrips * b + n % m * a, (mTrips + 1) * b))


(n, m, a, b) = [int(x) for x in input().split()]
q = int(n / m)
r = n - q * m
s1 = q * b + r * a
s2 = (q + 1) * b
s3 = n * a
print(min(s1, s2, s3))


(n, m, a, b) = map(int, input().split())
x = []
x.append(n * a)
l = n % m
n = n - l
n = n // m
x.append(n * b + l * a)
x.append(n * b + b)
print(min(x))


data = input()
data = data.split()
rides_num = int(data[0])
ticket_rides = int(data[1])
ticket_price = int(data[3])
one_ride = int(data[2])
ticket_one_price = ticket_price / ticket_rides
sum = 0
if ticket_one_price < one_ride:
	num_of_tickets = int(rides_num / ticket_rides)
	sum += num_of_tickets * ticket_price
	rest = rides_num - num_of_tickets * ticket_rides
	if rest * one_ride < ticket_price:
		sum += rest * one_ride
	else:
		sum += ticket_price
	print(sum)
else:
	print(rides_num * one_ride)


(n, m, a, b) = [int(x) for x in input().split()]
money = int()
least = int(n / m)
if int(b / m) >= a:
	money = n * a
else:
	money = min(least * b + (n - least * m) * a, (least + 1) * b)
print(money)


x = input().split()
n = int(x[0])
m = int(x[1])
a = int(x[2])
b = int(x[3])
if a <= float(b) / m:
	cost = a * n
else:
	cost = 0
	cost += n // m * b
	if n % m * a <= b:
		cost += n % m * a
	else:
		cost += b
print(cost)


(n, m, a, b) = map(int, input().split())
ans = pow(10, 10)
for i in range(n + 1):
	for j in range(n + 1):
		if m * i + j >= n:
			ans = min(ans, i * b + j * a)
print(ans)


liste = [int(x) for x in input().split()]
n = liste[0]
m = liste[1]
a = liste[2]
b = liste[3]
c = b / m
d = int(n / m)
e = n - d * m
preis = 0
if c >= a:
	preis = n * a
elif c < a and b >= a:
	if d == n / m:
		preis = d * b
	else:
		preis = min(d * b + e * a, (d + 1) * b)
elif c < a and b < a:
	if d == n / m:
		preis = d * b
	else:
		preis = (d + 1) * b
print(preis)


(n, m, a, b) = map(int, input().split())

def answer(n, m, a, b, cost):
	if b / m < a:
		if m > n:
			cost += min(a * n, b)
		else:
			cost = min(b * (n // m + 1), b * (n // m) + a * (n - m * (n // m)))
	else:
		cost += n * a
	return cost
print(answer(n, m, a, b, 0))


def cheap_travel(n, m, a, b):
	if b / m < a:
		if n // m * b + n % m * a <= (n // m + 1) * b:
			return n // m * b + n % m * a
		else:
			return (n // m + 1) * b
	else:
		return n * a
array = list(map(int, input().split(' ')))
print(cheap_travel(*array))


(n, m, a, b) = map(int, input().split())
total_cost = n * a
dif_cost = b / m
if a <= dif_cost:
	print(total_cost)
elif n % m == 0:
	print(b * (n // m))
else:
	abonements = n // m
	total_rides_abon = abonements * m
	differ = n - total_rides_abon
	if differ * a < b:
		print(abonements * b + differ * a)
	else:
		print((abonements + 1) * b)


(n, m, a, b) = input().split()
n = int(n)
m = int(m)
a = int(a)
b = int(b)
if b / m < a:
	t1 = n % m
	t2 = int(n / m)
	if (t2 + 1) * b < t2 * b + t1 * a:
		print((t2 + 1) * b)
	else:
		print(t2 * b + t1 * a)
else:
	print(n * a)


(n, m, a, b) = map(int, input().split())
k = n // m
s = n % m
print(min([a * s + b * k, a * n, (n + (m - 1)) // m * b]))


import math

def solve():
	(n, m, a, b) = map(int, input().split())
	if a * m <= b:
		print(a * n)
		return
	print(min(n // m * b + n % m * a, math.ceil(n / m) * b))
	return
solve()


(n, m, a, b) = map(int, input().split())
arr = []
c = n - n // m * m
s = c * a + n // m * b
arr.append(s)
arr.append(a * n)
if m < n:
	arr.append((1 + n // m) * b)
else:
	arr.append(b)
print(min(arr))


(n, m, a, b) = map(int, input().split())
specialRides = n // m
remainingRides = n % m
if m * a > b:
	if remainingRides * a > b:
		print(specialRides * b + b)
	else:
		print(specialRides * b + remainingRides * a)
else:
	print(n * a)


(n, m, a, b) = input().split()
n = int(n)
m = int(m)
a = int(a)
b = int(b)
k = n // m
x = (k + 1) * b
while k >= 0:
	y = k * b + (n - k * m) * a
	if y <= x:
		x = y
	k = k - 1
print(x)


from math import *

def ride():
	(n, m, a, b) = map(int, input().split())
	if m >= n:
		if b <= a * n:
			return b
		elif a * n < b:
			return a * n
	elif m < n:
		k = n / m
		if b * k < a * n:
			rem = n % m
			if rem * a <= b:
				cost = b * floor(k) + rem * a
				return cost
			elif rem * a > b:
				cost = ceil(k) * b
				return cost
		elif b * k >= a * n:
			return a * n
print(ride())


(n, m, a, b) = map(int, input().split())
pos = []
pos.append(n * a)
if n % m == 0:
	ans2 = n // m
	ans2 *= b
	pos.append(ans2)
else:
	ans2 = n // m
	ans2 += 1
	ans2 *= b
	pos.append(ans2)
	ans3 = n // m
	ans3 *= b
	ans3 += n % m * a
	pos.append(ans3)
print(min(pos))


(n, m, a, b) = map(int, input().split())
if b >= m * a:
	print(n * a)
else:
	sum = n // m * b
	n %= m
	if n * a < b:
		sum += n * a
	else:
		sum += b
	print(sum)


(n, m, a, b) = list(map(int, input().split()))
res = []
c = 0
mride = 0
while c + m <= n:
	c += m
	mride += b
x = n - c
if c != n:
	if mride + b < mride + x * a:
		mride += b
	else:
		mride += x * a
st = n * a
res.append(mride)
res.append(st)
res.sort()
print(res[0])


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().rstrip().split())
inl = lambda : list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))
(n, m, a, b) = inm()
print(min(n * a, (n + m - 1) // m * b, n // m * b + n % m * a))


x = list(map(int, input().split()))
if x[3] / x[1] < x[2]:
	print(x[0] // x[1] * x[3] + min(x[0] % x[1] * x[2], x[3]))
else:
	print(x[0] * x[2])


(n, m, a, b) = map(int, input().split())
r = n % m
d1 = (n // m + 1) * b
d2 = n * a
d3 = (n - r) // m * b + r * a
print(min(d1, min(d2, d3)))


(n, m, a, b) = map(int, input().split())
a1 = min(n // m * b, (n - n % m) * a)
a2 = min(b, n % m * a)
print(a1 + a2)


(n, m, a, b) = list(map(int, input().split()))
m1 = min(n * a, n // m * b)
m2 = min(b, n % m * a)
m = m1 + m2
print(m)


l = input()
res = [int(i) for i in l.split() if i.isdigit()]
n = res[0]
m = res[1]
a = res[2]
b = res[3]
if n < m:
	print(min(b, n * a))
elif float(b / m) > a:
	print(a * n)
else:
	rides = 0
	sum = 0
	while rides <= n:
		sum += b
		rides += m
	sum -= b
	rides -= m
	print(min(sum + (n - rides) * a, sum + b))


(n, m, a, b) = (int(x) for x in input().split())
s = 0
if m * a <= b:
	print(n * a)
else:
	x = n // m
	s += x * b
	x1 = n - m * x
	if x1 * a <= b:
		s += x1 * a
		print(s)
	else:
		s += b
		print(s)


q = input().split()
z = list(q)
n = int(z[0])
m = int(z[1])
a = int(z[2])
b = int(z[3])
p = 0
x = float(b) / m
if x < float(a):
	c = n // m
	v = n % m
	if v * a < b:
		p = c * b + v * a
	else:
		p = c * b + b
else:
	p = n * a
print(p)


def main():
	(n, m, a, b) = map(int, input().split())
	m_b = b / m
	if m_b < a:
		ans = b * (n // m)
		if a * (n % m) < b:
			ans += a * (n % m)
		else:
			ans += b
		print(ans)
	else:
		print(a * n)
main()


(n, m, one, m_1) = map(int, input().split())
if m_1 / m < one:
	if n % m == 0:
		print(n // m * m_1)
	else:
		A = n % m
		if m_1 < one * A:
			print(n // m * m_1 + m_1)
		else:
			print(n // m * m_1 + one * A)
else:
	print(n * one)


import math

def min_cost(n, m, a, b):
	if b / m >= a:
		return a * n
	return int(min([b * math.ceil(n / m), b * math.floor(n / m) + a * (n % m)]))
t = [int(x) for x in input().split()]
n = t[0]
m = t[1]
a = t[2]
b = t[3]
print(min_cost(n, m, a, b))


a = list(map(int, input().split()))
ride_cost = 0
if a[3] > a[1] * a[2]:
	ride_cost = a[0] * a[2]
else:
	ride_cost = a[3] * (a[0] // a[1])
	if a[2] * (a[0] % a[1]) < a[3]:
		ride_cost += a[2] * (a[0] % a[1])
	else:
		ride_cost += a[3]
print(ride_cost)


(n, m, a, b) = list(map(int, input().split()))
price = 0
i = n * a
j = n // m * b
if i == 1:
	price = i
elif i > j:
	price = j
	if j * m > n:
		if a >= b and abs(n - n // m * m) > 0:
			price += b
		else:
			price += abs(n - n // m * m) * a
	elif n % m != 0:
		price += b
else:
	price = i
print(price)


import math
(n, m, a, b) = map(int, input().split())
if m * a <= b:
	print(n * a)
else:
	res = 0
	x = n // m
	res = res + x * b
	x = x * m
	n = n - x
	res = res + min(a * n, b * 1)
	print(res)


import math
(n, m, a, b) = map(int, input().split())
if b / m < a:
	m1 = math.trunc(n / m)
	m2 = math.ceil(n / m)
	c1 = m1 * b + (n - m1 * m) * a
	c2 = m2 * b
	c = min(c1, c2)
else:
	c = n * a
print(c)


(n, m, a, b) = map(int, input().split())
c1 = n * a
c2 = n // m * b + n % m * a
if n % m == 0:
	c3 = n // m * b
else:
	c3 = (n // m + 1) * b
print(min(c1, c2, c3))


from math import *
(n, m, a, b) = map(int, input().split())
times = floor(n / m)
remain = n % m
if b / m >= a:
	print(n * a)
elif m >= n and b < a:
	print(b)
else:
	price1 = remain * a + times * b
	price2 = (times + 1) * b
	print(min(price2, price1))


(n, m, a, b) = map(int, input().split())
x1 = a * n
x2 = n // m * b + n % m * a
x3 = n // m * b + b
print(min(x1, x2, x3))


p = input()
(n1, m1, a1, b1) = p.split()
n = int(n1)
m = int(m1)
a = int(a1)
b = int(b1)
if n <= m:
	print(int(min(b, a * n)))
else:
	l = (n - n % m) / m
	p = a * (n % m) + b * l
	f = b * (l + 1)
	k = a * n
	print(int(min(f, k, p)))


(n, m, a, b) = map(int, input().split())
if b / m < a:
	init = n
	total = 0
	while init > 0:
		if m <= init:
			total += b
			init -= m
		elif b < a * init:
			init -= m
			total += b
		else:
			total += a * init
			init -= 1 * init
	print(total)
else:
	print(a * n)


def Check(NumofRides, Mrides):
	C = 0
	while NumofRides != 0:
		if NumofRides - Mrides >= 0:
			NumofRides -= Mrides
			C += MridePr
		else:
			NumofRides -= 1
			C += OneRidePr
	return C
(NumofRides, Mrides, OneRidePr, MridePr) = map(int, input().split())
if NumofRides % Mrides == 0:
	print(min(MridePr * NumofRides // Mrides, NumofRides * OneRidePr))
else:
	C = 0
	X = 0
	while X <= NumofRides:
		X += Mrides
		C += MridePr
	print(min(Check(NumofRides, Mrides), C))


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def vars():
	return map(int, input().split())

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

def main():
	(n, m, a, b) = vars()
	one = b / m
	if one < a:
		ans1 = math.ceil(n / m) * b
		ans = n // m * b
		n -= n // m * m
		ans += n * a
		ans = min(ans, ans1)
	else:
		ans = n * a
	print(ans)
t = 1
for _ in range(t):
	main()


(m, n, a, b) = map(int, input().split())
k = b / n
if k > a:
	print(a * m)
else:
	j = m % n
	l = m // n
	min_cost = min(a * j + b * l, b * (l + 1))
	print(min_cost)


(n, m, a, b) = list(map(int, input().split()))
if b / m >= a:
	print(n * a)
	exit(0)
print(n // m * b + min(a * (n % m), b))


import math
inp = input()
arr = inp.split()
n = int(arr[0])
m = int(arr[1])
a = int(arr[2])
b = int(arr[3])
if a * m > b:
	einzelt = n % m
	specialt = n // m
	if einzelt * a < b:
		print(einzelt * a + specialt * b)
	else:
		print(b + specialt * b)
else:
	print(n * a)


from sys import stdin, stdout, stderr, setrecursionlimit
setrecursionlimit(100000)

def debug(*e):
	if not __debug__:
		print(*e, file=stderr)

def dd(*vals):
	import inspect, re
	frame = inspect.getframeinfo(inspect.stack()[1][0])
	vs = re.search('dd\\((.+)\\)', frame.code_context[0]).group(1).split(',')
	if vs:
		debug(','.join(('{0} = {1}'.format(vs[i], v) for (i, v) in enumerate(vals))))

def trace(f):

	def traced(*args, **kw):
		debug('calling {} with args {}, {}'.format(f.__name__, args, kw))
		return f(*args, **kw)
	return traced

def read():
	return stdin.readline().rstrip()

def readarr(sep=None, maxsplit=-1):
	return read().split(sep, maxsplit)

def readint():
	return int(read())

def readintarr(sep=None, maxsplit=-1):
	return [int(a) for a in readarr(sep, maxsplit)]

def write(*args, **kwargs):
	sep = kwargs.get('sep', ' ')
	end = kwargs.get('end', '\n')
	stdout.write(sep.join((str(a) for a in args)) + end)

def writearr(arr, sep=' ', end='\n'):
	stdout.write(sep.join((str(a) for a in arr)) + end)
import math
(n, m, one, mprice) = readintarr()
a = math.ceil(n / m) * mprice
b = n * one
c = n // m * mprice + n % m * one
mn = min(a, b, c)
write(mn)


(n, m, a, b) = [int(x) for x in input().split()]
if b / m < a:
	t1 = n // m
	price1 = t1 * b
	t2 = n - t1 * m
	print(min(t2 * a, b) + price1)
else:
	print(n * a)


(n, m, a, b) = map(int, input().split())
if m > n:
	m = n
if m % n == 0:
	rez = 0
else:
	rez = 1
var1 = a * n
impr = int(n / m)
var2 = (impr + rez) * b
pcs = n - impr * m
var3 = impr * b + pcs * a
print(min(var1, var2, var3))


(n, m, a, b) = map(lambda x: int(x), input().split())
if b / m < a:
	t = n // m * b + n % m * a
	f = (n // m + 1) * b
	print(min(t, f))
else:
	print(n * a)


import math
(n, m, a, b) = map(int, input().split())
d = n * a
e = n // m * b + n % m * a
f = math.ceil(n / m) * b
print(min(d, e, f))


(n, k, a, b) = map(int, input().split())
if a * k <= b:
	print(a * n)
elif n % k == 0:
	print(n // k * b)
elif (n // k + 1) * b > n // k * b + n % k * a:
	print(n // k * b + n % k * a)
else:
	print((n // k + 1) * b)


(n, m, a, b) = map(int, input().split())
money = 0
if n % m == 0:
	money += n // m * b
else:
	money += n // m * b
	rd = n % m
	if a * rd > b * rd:
		money += b
	else:
		money += a * rd
if money > n * a:
	money = n * a
if m > n:
	if n * a > b:
		money = b
	else:
		money = n * a
print(money)


import math
(n, m, a, b) = map(int, input().split())
f = n // m
left = n % m
money = a * left + f * b
money = min(money, math.ceil(n / m) * b, n * a)
print(money)


import math
(a, b, c, d) = map(int, input().split(' '))
if d / b <= c:
	print(min(d * int(a / b) + a % b * c, d * math.ceil(a / b)))
else:
	print(a * c)


import sys, math
(nbVoyage, nbCouvert, unite, m) = map(int, sys.stdin.readline().split())
prix1 = nbVoyage * unite
prix2 = nbVoyage // nbCouvert * m + nbVoyage % nbCouvert * unite
prix3 = math.ceil(nbVoyage / nbCouvert) * m
print(min(prix1, prix2, prix3))


(n, m, a, b) = input().split(' ')
n = int(n)
m = int(m)
a = int(a)
b = int(b)
d = 0
c = 0
if n > m:
	if a <= b // m:
		c = n * a
	elif a <= b:
		c = n // m * b + n % m * a
	elif n % m == 0:
		c = n // m * b
	else:
		c = n // m * b + b
	print(c)
elif n * a > b:
	print(b)
else:
	print(n * a)


import math

def inp():
	return int(input())

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

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
(n, m, a, b) = invr()
res = 0
if a * m <= b:
	res = a * n
else:
	res = n // m * b + min(a * (n % m), b)
print(res)


(n, m, a, b) = str(input()).split()
n = int(n)
m = int(m)
a = int(a)
b = int(b)
if n % m == 0:
	print(min(int(n * a), int(n / m) * b))
else:
	print(min(int(n * a), int(n / m + 1) * b, int(n / m) * b + (n - int(n / m) * m) * a))


a = input().split()
b = int(a[0])
c = int(a[1])
d = int(a[2])
e = int(a[3])
if c * d <= e:
	s = b * d
else:
	s = e * (b // c) + min(d * (b % c), e)
print(s)


import math
content = input().split()
n = int(content[0])
m = int(content[1])
a = int(content[2])
b = int(content[3])
result = 0
if m * a <= b:
	result = n * a
else:
	result = int(n / m) * b + min(n % m * a, b)
print(int(result))


(x, y, m, n) = map(int, input().strip().split())
a = x * m
if x % y == 0:
	b = x // y * n
	c = x * m
else:
	b = (x // y + 1) * n
	c = x // y * n + x % y * m
menor = a
if b < menor:
	menor = b
if c < menor:
	menor = c
print(menor)


import math
(n, m, a, b) = [int(i) for i in input().split()]
single_fare = a * n
multiple_only = math.ceil(n / m) * b
mixed = b * (n // m) + n % m * a
print(min(single_fare, multiple_only, mixed))


(n, m, a, b) = map(int, input().split())
d = n * a
g = -n // m * -b
h = n // m * b + n % m * a
print(min(d, g, h))


import sys
import io
import os
total = 0
failed = 0

def debug(*args):
	if 'LOCALTEST' in os.environ:
		print(*args, file=sys.stderr)

def run(test, res):
	x = io.StringIO()
	with io.StringIO(test) as sys.stdin:
		with x as sys.stdout:
			work()
			z = x.getvalue().strip()
	sys.stdout = sys.__stdout__
	print('Passed?', z == res)
	print('Expected: ', res)
	print('Actual  : ', z)
	global total, failed
	total += 1
	failed += 1 if z != res else 0

def work():
	(n, m, a, b) = map(int, input().split())
	if m * a < b:
		print(n * a)
		return
	print(n // m * b + min(b, n % m * a))

def test():
	run('10 3 5 1', '4')
	run('6 2 1 2', '6')
	run('5 2 2 3', '8')
if 'LOCALTEST' in os.environ:
	test()
	print('\n Result: %s (%d total, %d failed)' % ('FAILED' if failed > 0 else 'PASSED', total, failed))
else:
	work()


s = input().split()
n = int(s[0])
m = int(s[1])
a = int(s[2])
b = int(s[3])
c = n * a
for i in range(1, int(n / m) + 1):
	if c > b * i + a * (n - m * i):
		c = b * i + a * (n - m * i)
if b * (int(n / m) + 1) < c:
	c = b * (int(n / m) + 1)
print(c)


from math import ceil
a = input()
b = a.split()
cost = 0
if int(b[1]) / int(b[3]) > 1 / int(b[2]):
	if int(b[3]) < int(b[0]) % int(b[1]) * int(b[2]):
		cost += ceil(int(b[0]) / int(b[1])) * int(b[3])
	else:
		cost += int(b[0]) // int(b[1]) * int(b[3]) + int(b[0]) % int(b[1]) * int(b[2])
else:
	cost += int(b[0]) * int(b[2])
print(cost)


import math
c = [int(i) for i in input().split(' ')]
n = c[0]
m = c[1]
a = c[2]
b = c[3]
if m * a <= b:
	print(n * a)
else:
	x = n // m
	if (n - m * x) * a < b:
		print(x * b + (n - m * x) * a)
	else:
		print(x * b + b)


try:
	(n, m, a, b) = input().split()
	(n, m, a, b) = [int(x) for x in [n, m, a, b]]
	t = int(n / m)
	rem = n % m
	c1 = n * a
	c2 = t * b + rem * a
	c3 = (t + 1) * b
	print(min(c1, c2, c3))
except EOFError:
	pass


(nt, mval, aval, bval) = map(int, input().split())
print(nt * aval) if bval >= mval * aval else print(nt // mval * bval + min(bval, nt % mval * aval))


(n, m, a, b) = [int(i) for i in input().split()]
print(min(n * a, n // m * b + n % m * a, int(n / m + 0.99999) * b))


(n, m, a, b) = input().split()
n = int(n)
m = int(m)
a = int(a)
b = int(b)
c = b / m
d = 0
e = 0
f = 0
g = 0
if c < a:
	d = int(n / m)
	e = n - d * m
	f = int(e / m + 1)
	if f * b < e * a or f == 0:
		g = (d + f) * b
	else:
		g = d * b + e * a
else:
	g = n * a
print(g)


import math
(n, m, a, b) = map(int, input().split())
RubPosA = n * a
RubPosB = math.ceil(n / m) * b
RubPosC = 0
Ride = 0
while n - Ride - m >= 0:
	RubPosC += b
	Ride += m
while Ride < n:
	RubPosC += a
	Ride += 1
print(min(RubPosA, RubPosB, RubPosC))


(n, m, a, b) = [int(x) for x in input().split()]
c = b / m
if c < a:
	d = n // m
	print(min((d + 1) * b, d * b + (n - m * d) * a))
else:
	print(n * a)


(n, m, a, b) = list(map(int, input().split()))
oneRide = n * a
mRide = n // m * b + min((n - n // m * m) * a, b)
print(min(oneRide, mRide))


(n, m, a, b) = list(map(int, input().split()))
c = 0
if b / m < a:
	q = n // m
	c += q * b
	if n % m != 0:
		mi = min(n % m * a, b)
		c += mi
	print(c)
else:
	print(n * a)


word = input().split(' ')
n = int(word[0])
m = int(word[1])
a = int(word[2])
b = int(word[3])
k = 0
while m * k <= n:
	k = k + 1
l = k - 1
rub = min(b * l + a * (n - m * l), a * n, b * k)
print(rub)


(n, m, a, b) = map(int, input().split())
mCost = b / min(m, n)
nCost = a
sum = 0
while n != 0:
	if mCost < nCost:
		sum += n // min(n, m) * b
		n -= n // min(n, m) * min(m, n)
		if m == 0 or n == 0:
			break
		mCost = b / min(m, n)
	else:
		sum += n * a
		n = 0
print(sum)


(n, m, a, b) = map(int, input().split(' '))
price = 0
if b / m > a:
	print(n * a)
else:
	count = 0
	while n - m > 0:
		n = n - m
		count = count + 1
	if (count + 1) * b < n * a + count * b:
		print((count + 1) * b)
	else:
		print(n * a + count * b)


(a, b, c, d) = map(int, input().split())
k = c * a
j = min(a // b * d + a % b * c, a // b * d + (a % b // b + 1) * d)
if b > a and d < a * c:
	print(d)
else:
	print(min(k, j))


(n, m, a, b) = map(int, input().split())
if a == b:
	if n < m:
		if m == 1:
			print(n * a)
		else:
			print(b)
	elif n // m == n / m:
		print(n // m * b)
	else:
		print(n // m * b + b)
elif n < m:
	if m == 1:
		print(n * a)
	else:
		print(min(n * a, b))
elif n // m == n / m:
	print(min(n * a, n // m * b))
else:
	k = 0
	while k < n % m:
		k += 1
	print(min(n * a, n // m * b + b, n // m * b + k * a))


n_m_a_b_string = input('')
n_m_a_b_list = list(n_m_a_b_string.split())
nmab = []
for i in range(4):
	nmab.append(int(n_m_a_b_list[i]))
(n, m, a, b) = nmab
c = n // m
d = n % m
if m * a > b:
	remain = d * a
	if remain > b:
		print(c * b + b)
	else:
		print(c * b + remain)
else:
	print(n * a)


(n, m, p, w) = map(int, input().split(' '))
a = n * p
b = n // m * w + w
c = n // m * w + n % m * p

def mayor(a, b):
	return b if a > b else a
print(mayor(a, mayor(b, c)))


s = input().split()
ride = int(s[0])
mride = int(s[1])
p = int(s[2])
pm = int(s[3])
c = 0
lr = 0
tr = 0
k = pm / mride
if k < p:
	c = int(ride / mride)
	lr = ride - c * mride
	if lr * p < pm:
		tr = c * pm + int(lr) * p
	elif ride % mride == 0:
		tr = int(ride / mride) * pm
	else:
		tr = (c + 1) * pm
else:
	tr = ride * p
print(tr)


(n, m, a, b) = [int(z) for z in input().split()]
if n % m == 0:
	print(min(n * a, n // m * b))
elif m > n and b < a * n:
	print(b)
elif b // m < a:
	print(n // m * b + min(b, n % m * a))
else:
	print(n * a)


import math
(n, subscription_n, n_cost, subscription_cost) = [int(x) for x in input().split()]
if subscription_n / subscription_cost <= 1 / n_cost:
	print(n_cost * n)
	exit()
if subscription_cost <= n_cost:
	print(subscription_cost * math.ceil(n / subscription_n))
	exit()
res = math.floor(n / subscription_n)
last = n - res * subscription_n
res *= subscription_cost
if n_cost * last > subscription_cost:
	res += subscription_cost
else:
	res += n_cost * last
print(res)


(a, b, n, m) = map(int, input().split())
t = a // b
rem = a % b
lst = []
for i in range(rem + t + 1):
	l = a - i * b
	if l < 0:
		l = 0
	lst.append(i * m + n * l)
print(min(lst))


from math import ceil
(n, m, a, b) = [int(i) for i in input().strip().split(' ')]
ans = min(a * n, a * (n % m) + b * (n // m), ceil(n / m) * b)
print(ans)


try:
	A = list(map(int, input().split()))
	n = A[0]
	m = A[1]
	a = A[2]
	b = A[3]
	if b / m >= a:
		print(a * n)
	else:
		split_num = str(n / m).split('.')
		int_part = int(split_num[0])
		cost = b * int_part
		remain = n % m * a
		if remain > b:
			print(cost + b)
		else:
			print(cost + remain)
except:
	pass


(n, m, a, b) = map(int, input().split())
if b / m > a:
	print(n * a)
else:
	cb = n // m
	r = n % m
	if r * a > b:
		cb += 1
		ca = 0
	else:
		ca = r
	print(ca * a + cb * b)


(n, m, a, b) = map(int, input().split())
costA = 0
costB = 0
costA = n * a
if n < m and b < costA:
	print(b)
else:
	div = n // m
	costB = div * b
	r = n % m
	if b <= a:
		while r > 0:
			costB += b
			r = r - m
	elif b > a:
		costB = div * b + r * a
	print(min(costA, costB))


(n, m, a, b) = tuple((int(x) for x in input().split(' ')))
abon_amount = n // m
non_overlapping_rides = n - m * abon_amount
money_with_abon = abon_amount * b + non_overlapping_rides * a
money = n * a
only_abon = abon_amount * b if non_overlapping_rides == 0 else (abon_amount + 1) * b
m = min([money_with_abon, money, only_abon])
print(m)


s = [int(i) for i in input().split()]
n = s[0]
m = s[1]
a = s[2]
b = s[3]
if a * m <= b:
	print(a * n)
elif n % m * a <= b:
	print(round((n - n % m) / m) * b + n % m * a)
else:
	print(round((n - n % m) / m) * b + b)


s = input().split()
n = int(s[0])
m = int(s[1])
a = int(s[2])
b = int(s[3])
ans = -1
if n < m:
	ans = min(n * a, b)
else:
	ans = 1000 * 1000
	div = n // m
	for i in range(div + 2):
		left = n - i * m
		if n - i * m < 0:
			left = 0
		ans = min(ans, i * b + left * a)
print(ans)


import math
(n, m, a, b) = list(map(int, input().split()))
c = 0
while n > 0:
	if n >= m:
		c += min(m * a, b)
		n -= m
	else:
		c += min(a * n, b)
		n = 0
print(c)


def ticket(n, m, a, b):
	minSum = 0
	if b <= a * m:
		while n >= m:
			n -= m
			minSum += b
		if n <= 0:
			return minSum
		else:
			r = min(minSum + a * n, minSum + b)
			return r
	else:
		return n * a
(n, m, a, b) = list(map(int, input().split()))
print(ticket(n, m, a, b))


(n, b, c, d) = map(int, input().split())
if b * c <= d:
	print(n * c)
else:
	k = n // b
	t = k * d
	n = n % b
	if n * c >= d:
		t = t + d
		print(t)
	else:
		t = t + n * c
		print(t)


import sys

def data():
	return sys.stdin.readline().strip()

def sp():
	return map(int, data().split())

def l():
	return list(sp())
temp = l()
n = temp[0]
m = temp[1]
a = temp[2]
b = temp[3]
if m * a <= b:
	print(n * a)
else:
	res = n // m * b + min(n % m * a, b)
	print(res)


from math import sqrt, ceil, floor

def main():
	(n, m, a, b) = [int(i) for i in input().split()]
	print(min(a * n, floor(n / m) * b + min(n % m * a, b)))
main()


x = []
y = input()
x = y.split(' ')
n = int(x[0])
m = int(x[1])
a = int(x[2])
b = int(x[3])
t = int(n / m)
ca = a * t * m
cb = b * t
diff = n % m
cax = diff * a
if ca < cb:
	print(ca + cax)
elif diff * a < b:
	print(cb + cax)
else:
	print(cb + b)


(a, b, c, d) = map(int, input().split())
x1 = 0
x2 = 0
y = a // b
x1 = y * d
if a % b != 0:
	if (a - b * y) * c < d:
		x1 += (a - b * y) * c
	else:
		x1 += d
x2 = a * c
print(min(x1, x2))


(n, m, a, b) = [int(value) for value in input().split(' ')]
fare = 0
if m * a <= b:
	fare += n * a
else:
	x = int(n / m)
	leftover = n - m * x
	fare += x * b
	if leftover * a > b:
		fare += b
	else:
		fare += leftover * a
print(fare)


(n, m, a, b) = input().split()
n = int(n)
m = int(m)
a = int(a)
b = int(b)
r = n % m
s = a * n
if r * a < b:
	mu = n // m * b + r * a
else:
	mu = (n // m + 1) * b
print(min(s, mu))


(n, m, a, b) = [int(x) for x in input().split()]
if n % m == 0:
	ans = min(a * n, b * n // m)
else:
	temp1 = b * (n // m) + n % m * a
	temp2 = (n // m + 1) * b
	ans = min(temp1, temp2)
print(ans)


issues = input().split(' ')
rides = int(issues[0])
ridesForPass = int(issues[1])
singleRide = int(issues[2])
passVal = int(issues[3])
ridesSingleCost = rides * singleRide
ridesWithPass = rides // ridesForPass
if ridesWithPass == 0:
	ridesWithPassCost = passVal
else:
	ridesWithPassCost = ridesWithPass * passVal
	rides = rides - ridesWithPass * ridesForPass
	decider = min(rides * singleRide, passVal)
	ridesWithPassCost += decider
print(min(ridesSingleCost, ridesWithPassCost))


(n, m, a, b) = map(int, input().split())
q = n / m
nor1 = n * a
if q > int(n / m):
	nor2 = int(n / m) * b + n % m * a
	nor3 = (int(n / m) + 1) * b
	if nor3 < nor2:
		nor2 = nor3
else:
	nor2 = n / m * b
if m > n:
	nor2 = b
list = [nor1, nor2]
list.sort()
print(int(list[0]))


import math
(desire, lenth, single, dul) = map(int, input().split())
dulcost = dul / lenth
cost = 0
cost2 = 999999999999
cost3 = math.ceil(desire / lenth) * dul
if dulcost <= single:
	while lenth <= desire:
		cost += dul
		desire -= lenth
	cost2 = cost + dul
	cost += single * desire
else:
	cost = single * desire
print(min(cost, cost2, cost3))


def solve():
	(n, m, single, multi) = [int(x) for x in input().split()]
	if multi / m > single:
		print(single * n)
		return
	price = 0
	while n > 0:
		if n < m:
			if multi < n * single:
				n -= m
				price += multi
			else:
				n -= 1
				price += single
		else:
			n -= m
			price += multi
	print(price)
	return
solve()


import math

def CheapTravel(n, m, a, b):
	return min(int(n % m * a + n // m * b), int(math.ceil(n / m) * b), n * a)
(n, m, a, b) = [int(x) for x in input().split()]
print(CheapTravel(n, m, a, b))


b = [int(b) for b in input().split()]
n = b[0]
m = b[1]
a = b[2]
b = b[3]
sum = 0

def min(a, b):
	if a <= b:
		return a
	else:
		return b
if b <= a * m and m <= n:
	if n % m != 0:
		sum1 = n // m * b + n % m * a
		sum2 = n // m * b + b
		fsum = min(sum1, sum2)
	else:
		fsum = n // m * b
if b > a * m and m <= n:
	fsum = n * a
if m > n:
	if b <= n * a:
		fsum = b
	else:
		fsum = a * n
print(fsum)


(n, m_rides, price1, price_m) = map(int, input().split())
if price_m / m_rides > price1:
	print(n * price1)
else:
	a = n // m_rides * price_m
	if n % m_rides * price1 <= price_m:
		print(a + n % m_rides * price1)
	else:
		print(a + price_m)


(n, m, a, b) = map(int, input().split())
if a <= b // m:
	print(a * n)
else:
	w = n // m * b
	n -= n // m * m
	if b < n * a:
		w += b
	else:
		w += n * a
	print(w)


(n, m, a, b) = map(int, input().split())
x = 0
if a <= b / m:
	print(n * a)
else:
	while x * m <= n:
		x += 1
	ans = (x - 1) * b + a * (n - m * (x - 1))
	if x * m == n:
		print(x * b)
	elif ans >= x * b:
		print(x * b)
	else:
		print(ans)


def cheap_travel(n, m, a, b):
	d = []
	d.append(n // m * b + n % m * a)
	d.append((n // m + 1) * b)
	d.append(n * a)
	return min(d)
f = lambda : list(map(int, input().split()))
(n, m, a, b) = f()
print(cheap_travel(n, m, a, b))


(n, m, a, b) = input().split(' ')
n = int(n)
m = int(m)
a = int(a)
b = int(b)
numSpecial = int((n - n % m) / m)
if n > m and a <= b / m:
	print(n * a)
elif n > m and a > b / m and (a >= b):
	if n - numSpecial * m != 0:
		print(numSpecial * b + b)
	else:
		print(numSpecial * b)
elif n > m and a > b / m and (a < b):
	print(numSpecial * b + (n - numSpecial * m) * a)
elif m > n and n * a < b:
	print(n * a)
else:
	print(b)


(n, m, a, b) = [int(s) for s in input().split()]
if a >= b / m and n % m * a <= b:
	print(n // m * b + n % m * a)
elif a >= b / m and n % m * a > b:
	print(n // m * b + b)
else:
	print(n * a)


(n, m, a, b) = map(int, input().split())
k = n // m
V = k * b
if n % m != 0:
	V = V + min(n % m * a, b)
if k == 0:
	V = b
V = min(V, a * n)
print(V)


(n, m, a, b) = map(int, input().split())
cost = 0
flag = False
if b <= a * m:
	cost += n // m * b
	n = n % m
	flag = True
if b <= a * n and flag:
	cost += b
else:
	cost += a * n
print(cost)


(n, m, a, b) = input().split()
(n, m, a, b) = (int(n), int(m), int(a), int(b))
if b / m >= a:
	print(n * a)
else:
	ans = n // m * b
	n = n - n // m * m
	if n * a < b:
		print(ans + n * a)
	else:
		print(ans + b)


(rides, rides_per_card, ticket, card) = map(int, input().split())
if rides_per_card < rides:
	if card / rides_per_card > ticket:
		print(rides * ticket)
	elif rides % rides_per_card == 0:
		print(rides // rides_per_card * card + ticket * (rides - rides_per_card * (rides // rides_per_card)))
	else:
		print(min(rides // rides_per_card * card + ticket * (rides - rides_per_card * (rides // rides_per_card)), (rides // rides_per_card + 1) * card))
else:
	print(min(card, rides * ticket))


(n, m, a, b) = map(int, input().split())
q = n * a
w = n // m
if n % m != 0:
	w += 1
w *= b
e = n // m
e *= b
e += n % m * a
print(min(q, w, e))


data = [int(m) for m in input().split()]
cost_single_rides = data[0] * data[2]
cost_multiple_rides = data[3] if data[1] >= data[0] else min(data[0] // data[1] * data[3] + data[0] % data[1] * data[2], (data[0] // data[1] + 1) * data[3])
print(min(cost_single_rides, cost_multiple_rides))


strInp = str(input()).split()
n = int(strInp[0])
m = int(strInp[1])
a = int(strInp[2])
b = int(strInp[3])
eachTripPaidPrice = a * n
abonTripPaidPrice = b
if n > m:
	abonTripPaidPrice = b * int(n / m)
	if n % m > 0:
		if a * (n % m) > b:
			abonTripPaidPrice += b
		else:
			abonTripPaidPrice += a * (n % m)
print(min([eachTripPaidPrice, abonTripPaidPrice]))


(n, m, a, b) = map(int, input().split())
s = 0
fixprice = b / m
while n > 0:
	if fixprice > a:
		n -= 1
		s += a
	elif n > m:
		n -= m
		s += b
	elif n * a < b:
		n -= 1
		s += a
	else:
		n -= m
		s += b
print(s)


(n, m, a, b) = map(int, input().split())
if b / m < a:
	t = int(n / m)
	c = int(n - t * m)
	print(min((t + 1) * b, t * b + c * a))
else:
	print(a * n)


(n, m, a, b) = map(int, input().split())
if b / m < a:
	t = n // m * b
	if n % m * a < b:
		t += n % m * a
	else:
		t += b
	print(t)
else:
	print(n * a)


from math import ceil
(n, m, a, b) = [int(i) for i in input().split()]
k = ceil(n / m)
Min = a * n
for i in range(1, k):
	j = i * b + a * (n - i * m)
	if Min > j:
		Min = j
j = k * b
if Min > j:
	Min = j
print(Min)


(n, m, a, b) = [int(x) for x in input().split()]
if m >= n:
	if b <= n * a:
		print(b)
	else:
		print(n * a)
elif m * a <= b:
	print(n * a)
else:
	nr_left = n % m
	cost = int(n / m) * b
	if nr_left * a < b:
		cost = cost + nr_left * a
	else:
		cost = cost + b
	print(cost)


(n, m, a, b) = [int(i) for i in input().split()]
p = n // m * b
q = n % m
x = q * a
y = b
r = p + min(x, y)
t = n * a
print(min(r, t))


(n, m, a, b) = map(int, input().rstrip().split())
rd = n // m
r = n % m
ans1 = rd * b + r * a
ans2 = n * a
ans3 = (n // m + 1) * b
print(min(ans1, ans2, ans3))


from sys import stdin, stdout
(travels, abonement_travels, price, abonement_price) = [int(x) for x in stdin.readline().rstrip().split()]
min_price = travels * price
for i in range(travels):
	price1 = price * i
	if (travels - i) % abonement_travels == 0:
		price2 = (travels - i) / abonement_travels * abonement_price
		standart_price = price1 + price2
	else:
		price2 = (travels - i - (travels - i) % abonement_travels) / abonement_travels * abonement_price
		price3 = price1 + (travels - i) % abonement_travels * price
		price4 = (int((travels - i) / abonement_travels) + 1) * abonement_price
		if price1 + price4 > price2 + price3:
			standart_price = price2 + price3
		else:
			standart_price = price1 + price4
	if standart_price < min_price:
		min_price = standart_price
stdout.write(str(int(min_price)))


(n, m, a, b) = [int(x) for x in input().split()]
if b > m * a:
	print(n * a)
elif n % m == 0:
	print(b * (n // m))
else:
	k = n % m
	money = b * (n // m) + a * k
	money2 = b * (n // m + 1)
	if money2 > money:
		print(money)
	else:
		print(money2)


def main():
	(n, m, a, b) = map(int, input().split())
	if n <= m:
		print(min(n * a, b))
	else:
		nOt = n // m
		if n % m != 0:
			nOt = nOt + 1
		collection = []
		for i in range(nOt, -1, -1):
			first = b * i
			second = a * (n - i * m)
			if second < 0:
				second = 0
			collection.append(first + second)
		print(min(collection))
main()


(n, m, a, b) = map(int, input().split())
dic = {}

def calculate(n):
	x = [0]
	for i in range(1, n + 1):
		x1 = a + x[i - 1]
		if i >= m:
			x2 = b + x[i - m]
		else:
			x2 = b
		x.append(min(x1, x2))
	return x[n]
print(calculate(n))


(n, m, a, b) = map(int, input().split(' '))
counter = 0
if a * m <= b:
	counter += a * n
	n = 0
while n > 0:
	if b < a * n:
		counter += b
		n -= m
	else:
		counter += a
		n -= 1
print(counter)


(n, m, a, b) = input().split()
n = int(n)
m = int(m)
a = int(a)
b = int(b)
list1 = []
list1.append(n * a)
l = n % m
c = n // m
list1.append(l * a + c * b)
if l != 0:
	list1.append(c * b + b)
print(min(list1))


import math
(n, m, a, b) = map(int, input().split())
(total1, total2) = (math.inf, math.inf)
if a * m > b:
	total1 = 0
	while n >= m:
		total1 += b
		n = n - m
	total1 += n * a if n * a < b else b
else:
	total2 = n * a
print(min(total1, total2))


def main():
	(n, m, a, b) = map(int, input().split())
	if a <= b / m:
		costf = a * n
	elif a > b / m:
		cost1 = n // m * b + n % m * a
		cost2 = n // m * b + b
		costf = min(cost1, cost2)
	print(costf)
main()


import math
(n, m, a, b) = map(int, input().split())
if m * a <= b:
	print(n * a)
else:
	x = math.floor(n / m)
	y = math.ceil(n / m)
	c = (n - x * m) * a + x * b
	d = y * b
	if c < d:
		print(c)
	else:
		print(d)


(n, m, a, b) = list(map(int, input().split()))
ans = min(a * n, b * (n // m) + a * (n % m), b * (n // m) + b)
print(ans)


(n, m, a, costm) = map(int, input().split())
x = n * a
y = -n // m * -costm
z = n // m * costm + n % m * a
print(min([x, y, z]))


num = list(map(int, input().split()))
l = num[0]
one_price = num[2]
m = num[1]
m_price = num[3]
m_permail = m_price / m
if m_permail >= one_price:
	print(l * one_price)
else:
	num_mmail = l // m
	p1 = num_mmail * m_price
	left_l = l - m * num_mmail
	p2 = left_l * one_price
	p3 = m_price
	print(p1 + min(p2, p3))


import math
(n, m, a, b) = [int(i) for i in input().split()]
num = math.ceil(n / m)
su = []
for i in range(num):
	su.append(b * i + a * (n - i * m))
su.append(b * num)
print(min(su))


import math
(n, m, a, b) = input().split()
(n, m, a, b) = (int(n), int(m), int(a), int(b))
(price, price1, price2) = (0, 0, 0)
price = math.ceil(n / m) * b
price1 = n * a
price2 = n // m * b + n % m * a
print(min(price, price1, price2))


(rr, mm, aa, bb) = [int(x) for x in input().split()]
print(min(rr // mm * bb + rr % mm * aa, rr * aa, -(-rr // mm) * bb))


(n, m, a, b) = map(int, input().split())
p = a * n
d = b * (n // m) + a * (n % m)
t = b * (n // m + 1)
print(min(p, d, t))


(a, b, c, d) = map(int, input().split())
z = a * c
x = a // b * d
v = (a // b + 1) * d
q = a // b * d + (a - a // b * b) * c
if a < b and z > d:
	print(d)
elif a % b == 0 and x < z:
	print(x)
elif a % b == 0 and x > z:
	print(z)
elif v < min(z, q):
	print(v)
else:
	print(q)


data = list(map(int, input().split()))
variants = []
if data[0] % data[1]:
	for i in range(data[0] // data[1] + 2):
		if data[0] - i * data[1] > 0:
			variants.append(i * data[3] + (data[0] - i * data[1]) * data[2])
		else:
			variants.append(i * data[3])
else:
	for i in range(data[0] // data[1] + 1):
		variants.append(i * data[3] + (data[0] - i * data[1]) * data[2])
print(min(variants))


(a, b, c, d) = input().split(' ')
(a, b, c, d) = (int(a), int(b), int(c), int(d))
print(min(a * c, d * (a // b) + c * (a % b), d * (a // b + 1)))


(n, m, a, b) = map(int, input().split())
ans = a * n
for y in range(1, 1001):
	x = max(n - m * y, 0)
	ans = min(ans, a * x + b * y)
print(ans)


from math import ceil
(n, m, a, b) = input().split()
n = int(n)
m = int(m)
a = int(a)
b = int(b)
l = []
a1 = ceil(n / m) * b
l.append(a1)
a2 = n * a
l.append(a2)
a3 = int(n / m) * b + n % m * a
l.append(a3)
l.sort()
print(l[0])


(n, m, a, b) = map(int, input().split())
v = b / m
s = 0
if v >= a:
	print(n * a)
else:
	u = n // m
	s = s + u * b
	r = n - u * m
	w = r * a
	if w <= b:
		s = s + w
	if w > b:
		s = s + b
	print(s)


(n, m, a, b) = map(int, input().split())
if b / m >= a:
	print(n * a)
else:
	s = n // m * b
	n = n % m
	ss = 0
	if n != 0:
		ss = min(b, n * a)
	s += ss
	print(s)


import math
arr = input().split()
n = int(arr[0])
m = int(arr[1])
a = int(arr[2])
b = int(arr[3])
if a <= b / m:
	print(str(n * a))
else:
	sum = 0
	x = n / m
	bee = math.floor(x)
	sum += bee * b
	chill = (n - bee * m) * a
	if b < chill:
		sum += b
	else:
		sum += chill
	print(str(sum))


from math import ceil

def main():
	params = [int(x) for x in input().split(' ')]
	spent = []
	spent.append(params[0] * params[2])
	spent.append(ceil(params[0] / params[1]) * params[3])
	b_rides = params[0] // params[1]
	a_rides = params[0] % params[1]
	spent.append(b_rides * params[3] + a_rides * params[2])
	print(min(spent))
main()


(n, m, a, b) = [int(i) for i in input().split()]
p1 = int(b * (n // m) + a * (n % m))
p = int(b * ((n + m - 1) // m))
if p < p1:
	p1 = p
p2 = int(a * n)
if p1 < p2:
	print(p1)
else:
	print(p2)


l = list(map(int, input().split()))
n = l[0]
m = l[1]
a = l[2]
b = l[3]
ans = 10000000
j = 0
res = 0
if m * a <= b:
	print(n * a)
else:
	print(int(n / m) * b + min(n % m * a, b))


(n, m, a, b) = map(int, input().split())
s1 = n * a
s2 = int(n / m) * b + int(n % m) * a
s3 = int(n / m) * b + b
if m > n:
	print(min(s1, s2, s3, b))
else:
	print(min(s1, s2, s3))


(a, b, c, d) = map(int, input().strip().split())
if a < b:
	if c * a > d:
		ans = d
	else:
		ans = a * c
elif d / b == c:
	ans = a * c
elif d / b > c:
	ans = a * c
else:
	e = a // b
	if a % b * c < d:
		ans = e * d + a % b * c
	else:
		ans = (e + 1) * d
print(ans)


(n, m, a, b) = map(int, input().split())
s = n * a
s1 = n // m * b + n % m * a
s2 = n // m * b + b
if s <= s1 and s <= s2:
	print(s)
elif s1 <= s and s1 <= s2:
	print(s1)
else:
	print(s2)


(n, m, a, b) = map(int, input().split())
n_cost = n * a
m_cost = int(n / m) * b + min((n - m * int(n / m)) * a, b)
print(min(n_cost, m_cost))


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
(n, m, a, b) = get_int_list()
if b / m >= a:
	print(a * n)
else:
	c = n // m * b
	if n % m * a > b:
		c += b
	else:
		c += n % m * a
	print(c)


(total_rides, rides_m, a, b) = [int(x) for x in input().split()]
costa = 0
costb = 0
if a > b / rides_m:
	costa = total_rides // rides_m * b
	total_rides = total_rides % rides_m
	if total_rides * a < b:
		costa += total_rides * a
	else:
		costa += b
	print(costa)
else:
	print(total_rides * a)


(n, m, a, b) = list(map(int, input().split()))
minSum = 0
if b <= a * m:
	while n >= m:
		n -= m
		minSum += b
	if n <= 0:
		print(minSum)
	else:
		print(min(minSum + a * n, minSum + b))
else:
	print(n * a)


(n, m, a, b) = map(int, input().split())
cost = min(n // m * b, n // m * m * a)
rides_left = n % m
cost += min(b, rides_left * a)
print(cost)


import sys
inf = float('inf')
(mod, MOD) = (1000000007, 998244353)
from math import ceil, floor, log, sqrt, factorial

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(n, m, a, b) = get_ints()
print(min(n * a, min(ceil(n / m) * b, n // m * b + n % m * a)))


(n, m, a, b) = map(int, input().split())
x = int(n / m)
ans = b * x
x = n - x * m
ans = ans + min(x * a, b)
print(min(ans, n * a))


ip = input()
ip = ip.split(' ')
n = int(ip[0])
m = int(ip[1])
a = int(ip[2])
b = int(ip[3])
if n % m == 0:
	y = int(n / m)
else:
	y = int(n / m) + 1
min_cost = b * y
for x in range(1, n + 1):
	if (n - x) % m == 0:
		y = int((n - x) / m)
	else:
		y = int((n - x) / m) + 1
	cost = a * x + b * y
	if cost < min_cost:
		min_cost = cost
print(min_cost)


(n, m, a, b) = map(int, input().split())
div = b / m
flag = 0
if div <= a:
	req = n // m
	p = m * req
	cost = p * div + (n - p) * a
	flag = 1
else:
	cost = n * a
	print(int(cost))
if flag == 1:
	ncost = m * (req + 1) * div
	if ncost < cost:
		print(int(ncost))
	else:
		print(int(cost))


import math
(n_trips, n_card, cost_trip, cost_card) = [int(s) for s in input().split()]
if cost_card / n_card >= cost_trip:
	print(n_trips * cost_trip)
else:
	min_cost = min(math.ceil(n_trips / n_card) * cost_card, n_trips // n_card * cost_card + (n_trips - n_trips // n_card * n_card) * cost_trip)
	print(min_cost)


(n, n_abon, c, c_abon) = [int(x) for x in input().split()]
print(min([n * c, n // n_abon * c_abon + n % n_abon * c, (n // n_abon + 1) * c_abon]))


(n, m, a, b) = map(int, input().split())
ans = 0
if b < a * m:
	k = b
	rides = m
	remain = n % m * a
	if remain > b:
		ans = n // m * b + b
	else:
		ans = n // m * b + remain
else:
	ans = n * a
print(ans)


(n, m, a, b) = map(int, input().split())
if n > m and b / m < a:
	k = n // m * b
	n = n % m
else:
	k = 0
k += min(n * a, -(-n // m) * b)
print(k)


(n, m, a, b) = map(int, input().split())
res = 100000000
for x in range(0, 1001):
	for y in range(0, 1001):
		if m * x + y >= n:
			res = min(res, b * x + y * a)
print(res)


for i in range(1):
	(n, m, a, b) = map(int, input().split())
	if m * a <= b:
		print(n * a)
	else:
		s = int(n / m) * b + min(n % m * a, b)
		print(s)


(n, m, a, b) = map(int, input().split())
c = 0
m1 = b / m
x = 0
if m1 < a:
	if n > m:
		x = int(n / m)
		c = c + x * b
	else:
		pass
	n = n - m * x
	if c + b < c + a * n:
		c += b
	else:
		c = c + a * n
else:
	c = c + a * n
print(c)


def solve(n, m, a, b):
	perday = min(b / m, a)
	if perday == a:
		return n * a
	else:
		return b * (n // m) + min(a * (n % m), b)
(n, m, a, b) = map(int, input().split())
print(solve(n, m, a, b))


def main():
	(n, m, a, b) = read()
	if b / m < a:
		if n % m and a * (n % m) > b:
			print((n // m + 1) * b)
		else:
			print(n % m * a + n // m * b)
	else:
		print(n * a)

def read(mode=2):
	inputs = input().strip()
	if mode == 0:
		return inputs
	if mode == 1:
		return inputs.split()
	if mode == 2:
		return list(map(int, inputs.split()))

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s, end='')
write(main())


(n, m, a, b) = list(map(int, input().split()[:4]))
sisa = n % m
hargan = n * a
if b / m < a:
	hargam = b * int(n / m)
	if sisa != 0:
		hargaa = a * sisa
		total = hargam + hargaa
		totalb = hargam + b
		if total < totalb:
			pri = total
		else:
			pri = totalb
		print(pri)
	else:
		print(hargam)
else:
	print(hargan)


(n, m, a, b) = map(int, input().split())
if m * a <= b:
	print(n * a)
else:
	ans = n // m
	ans *= b
	val = n % m
	val *= a
	if val <= b:
		ans += val
	else:
		ans += b
	print(ans)


from typing import List

def parse_input() -> List[int]:
	return [int(x) for x in input().split()]

def solve(n: int, m: int, a: int, b: int) -> int:
	cost = 0
	b_unit_cost = b / m
	if a <= b_unit_cost:
		return n * a
	if n >= b and b_unit_cost < a:
		cost += int(n / m) * b
		n %= m
	return cost + min(n * a, b)
(n, m, a, b) = parse_input()
print(solve(n, m, a, b))


(n, m, a, b) = [int(i) for i in input().split()]
if m * a < b:
	print(n * a)
else:
	rest = n % m
	div = n // m
	if rest * a > b:
		print(div * b + b)
	else:
		print(div * b + rest * a)


(n, m, a, b) = input().split()
(n, m, a, b) = (int(n), int(m), int(a), int(b))
cost = 0
mPerb = b / m
if a < mPerb:
	cost = n * a
else:
	times = n // m
	val = times * b + (n - times * m) * a
	cost = min(val, times * b + b)
print(cost)


import math
(n, m, a, b) = map(int, input().split())
if b >= a * m:
	print(n * a)
	exit()
d = n // m
e = n % m
print(min(a * e + b * d, b * math.ceil(n / m)))


(n, m, a, b) = map(int, input().split())
abon = n // m * b + n % m * a
proezd = n * a
abon2 = (n // m + 1) * b
print(min(abon, abon2, proezd))


import os, sys
from io import BytesIO, IOBase
import math

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
(n, m, a, b) = mi()
if b / m > a:
	ans = n * a
else:
	ans = min(math.ceil(n / m) * b, n // m * b + n % m * a)
print(ans)


import sys
(n, m, a, b) = map(int, input().split())
(i, ans, c) = (1, sys.maxsize, 0)
if m >= n:
	print(min(b, a * n))
else:
	while True:
		if i * m <= n:
			ans = min(ans, a * (n - i * m) + b * i)
		else:
			ans = min(ans, b * i)
		i += 1
		if i * m > n:
			if c == 0:
				c += 1
			else:
				break
	print(min(ans, a * n))