$k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away.

The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and then give the first $x$ candies to himself, the next $x$ candies to the second person, the next $x$ candies to the third person and so on in a cycle. The leftover (the remainder that is not divisible by $x$) will be thrown away.

Arkady can't choose $x$ greater than $M$ as it is considered greedy. Also, he can't choose such a small $x$ that some person will receive candies more than $D$ times, as it is considered a slow splitting.

Please find what is the maximum number of candies Arkady can receive by choosing some valid $x$.


-----Input-----

The only line contains four integers $n$, $k$, $M$ and $D$ ($2 \le n \le 10^{18}$, $2 \le k \le n$, $1 \le M \le n$, $1 \le D \le \min{(n, 1000)}$, $M \cdot D \cdot k \ge n$) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can receive candies.


-----Output-----

Print a single integer — the maximum possible number of candies Arkady can give to himself.

Note that it is always possible to choose some valid $x$.


-----Examples-----
Input
20 4 5 2

Output
8

Input
30 9 4 1

Output
4



-----Note-----

In the first example Arkady should choose $x = 4$. He will give $4$ candies to himself, $4$ candies to the second person, $4$ candies to the third person, then $4$ candies to the fourth person and then again $4$ candies to himself. No person is given candies more than $2$ times, and Arkady receives $8$ candies in total.

Note that if Arkady chooses $x = 5$, he will receive only $5$ candies, and if he chooses $x = 3$, he will receive only $3 + 3 = 6$ candies as well as the second person, the third and the fourth persons will receive $3$ candies, and $2$ candies will be thrown away. He can't choose $x = 1$ nor $x = 2$ because in these cases he will receive candies more than $2$ times.

In the second example Arkady has to choose $x = 4$, because any smaller value leads to him receiving candies more than $1$ time.

Difficulty: HARD

Solutions:
(n, k, M, D) = map(int, input().split())
ans = 0
for d in range(1, D + 1):
	l = 1
	r = k
	while l != r:
		mid = (l + r) // 2
		mxx = n // ((d - 1) * k + mid)
		mnx = n // ((d - 1) * k + mid + 1) + 1
		if mnx > M:
			l = mid + 1
		else:
			r = mid
	mxx = n // ((d - 1) * k + l)
	mnx = n // ((d - 1) * k + l + 1) + 1
	if mnx > M:
		continue
	mxx = min(mxx, M)
	ans = max(ans, mxx * d)
print(ans)


import sys
import math
[n, k, M, D] = list(map(int, sys.stdin.readline().split(' ')))
best = min(n, M)
for d in range(D):
	ppl = d * k + 1
	x = min(n // ppl, M)
	best = max(best, x * (d + 1))
print(best)


(candies, people, m, d) = [int(i) for i in input().split(' ')]
max_score = 0
for t in range(d):
	x = candies // (people * t + 1)
	x = min(x, m)
	score = (t + 1) * x
	if score > max_score:
		max_score = score
print(max_score)


(n, k, m, D) = map(int, input().split())
ans = 0
for d in range(1, D + 1):
	xmax = min(n // ((d - 1) * k + 1), m)
	if xmax == 0:
		continue
	if n % (xmax * k) >= xmax:
		if n // (xmax * k) == d - 1:
			ans = max(xmax * d, ans)
	elif n // (xmax * k) == d:
		ans = max(xmax * d, ans)
print(ans)


(n, k, m, d) = map(int, input().split())

def binary_search(curr):
	(l, r) = (1, m)
	while l <= r:
		mid = (l + r) // 2
		if n // mid >= curr:
			l = mid + 1
		else:
			r = mid - 1
	return l - 1
res = 0
for i in range(1, d + 1):
	x = binary_search((i - 1) * k + 1)
	if x <= 0 or n // x > i * k:
		continue
	res = max(res, x * i)
print(res)


[n, k, m, d] = [int(x) for x in input().split()]
res = 0
for i in range(1, d + 1):
	xmax = n // (k * (i - 1) + 1)
	if xmax > m:
		xmax = m
	if xmax * i > res:
		res = xmax * i
print(res)


(n, k, M, D) = map(int, input().split())
print(max([d * min(M, n // (k * (d - 1) + 1)) for d in range(1, D + 1)]))


(n, k, m, d) = map(int, input().split())
ans = -1e+19
sr = n // m
sr = (sr + (k - 1)) // k
sr = sr * m
for i in range(1, d, 1):
	x = n // (i * k + 1)
	if x <= m:
		cur_res = (i + 1) * x
		ans = max(ans, cur_res)
	else:
		continue
print(max(ans, sr))


from sys import stdin, stdout
from itertools import accumulate
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
for _ in range(1):
	(c, p, M, D) = lst()
	ans = 0
	for i in range(1, D + 1):
		r = min(M, c // (p * i - p + 1))
		l = c // (p * i)
		ans = max(ans, i * min(M, max(l, r)))
	print(ans)


(n, k, M, D) = map(int, input().split())

def f(x):
	ans = n // (x * k)
	if n % (x * k) >= x:
		ans += 1
	return ans

def calc(d):
	l = 1
	r = M + 1
	while r - l > 1:
		md = (l + r) // 2
		if f(md) < d:
			r = md
		else:
			l = md
	return l
best = -1

def sol(d):
	r = calc(d)
	if f(r) > d:
		return 0
	return f(r) * r
for dd in range(1, D + 1):
	best = max(best, sol(dd))
print(best)


[n, k, M, D] = list(map(int, input().strip().split()))

def ceil(a, b):
	return -(-a // b)

def arkkonf(x):
	return x * ceil(n // x, k)
res = 0
for d in range(D):
	x = n // (k * d + 1)
	x = min(x, M)
	if x == 0:
		continue
	while x < M and n // x > k * D:
		x += 1
	if n // x > k * D:
		continue
	res = max(res, arkkonf(x))
print(res)


from sys import stdin, stdout
(N, K, M, D) = [int(x) for x in input().split()]
best = 0
for ture in range(1, D + 1):
	bomb = N // (1 + (ture - 1) * K)
	bomb = min(bomb, M)
	best = max(best, ture * bomb)
print(best)


import sys
import math
from collections import defaultdict
import heapq
mod = 10 ** 9 + 7
(n, k, m, d) = map(int, sys.stdin.readline().split())
ans = 0
for i in range(d):
	low = 1
	high = k
	x = -1
	while low <= high:
		mid = (low + high) // 2
		y = n // (i * k + mid)
		if y <= m:
			x = mid
			high = mid - 1
		else:
			ans = max(ans, m * (i + 1))
			low = mid + 1
	if x != -1:
		y = n // (i * k + x)
		ans = max(ans, y * (i + 1))
print(ans)


def f(x):
	return x * (d - 1) + x
(n, k, M, D) = map(int, input().split())
ans = 0
for d in range(1, D + 1):
	maxx = M
	maxx = min(n // ((d - 1) * k + 1), maxx)
	if maxx == 0:
		continue
	reald = (n // maxx + k - 1) // k
	if reald != d:
		continue
	ans = max(ans, f(maxx))
print(ans)


(n, k, M, D) = map(int, input().strip().split())
cnt = n // M
res = (cnt + k - 1) // k * M
for d in range(1, D + 1):
	min_cnt = (d - 1) * k + 1
	max_cnt = (d - 1) * k + k
	x_max = min(M, n // min_cnt)
	x_min = min(M, n // max_cnt)
	res = max(res, d * x_min)
	res = max(res, d * x_max)
print(res)


import sys
import math
(n, k, M, D) = list(map(int, sys.stdin.readline().strip().split(' ')))
maxsf = 0
for d in range(D):
	x = int(math.floor(n // (k * d + 1)))
	maxsf = max(maxsf, min(M, x) * (d + 1))
print(maxsf)


(n, k, m, d) = map(int, input().split())
ans = 0
for x in range(1, d + 1):
	y = min(n // ((x - 1) * k + 1), m)
	ans = max(ans, x * y)
print(ans)


(n, k, M, D) = map(int, input().split())
flo = lambda a, b: (a + b - 1) // b
print(max([d * (n // (k * d - k + 1)) for d in range(1, D + 1) if M >= n // (k * d - k + 1)] + [M * flo(n // M, k)]))


(n, k, M, D) = map(int, input().split())

def calc(n, k, x):
	if x == 0:
		return 0
	return x * ((n // x + k - 1) // k)
ans = 0
for i in range(1, D + 1):
	l = 1
	r = min(n, M) + 1
	while r - l > 1:
		mid = (r + l) // 2
		if (n // mid + k - 1) // k >= i:
			l = mid
		else:
			r = mid
	if (n // l + k - 1) // k == i:
		ans = max(ans, calc(n, k, l))
print(ans)


(n, k, m, d) = map(int, input().split())
ans = 0
for i in range(1, d + 1):
	x = 0
	if n / ((i - 1) * k + 1) <= m:
		x = n // ((i - 1) * k + 1)
	else:
		x = m
	if x * i >= ans:
		ans = x * i
print(ans)


(n, k, m, d) = map(int, input().split())
ans = 0
for i in range(1, d + 1):
	hi = min(m, n // (k * (i - 1) + 1))
	lo = n // (k * i + 1)
	if hi > lo:
		ans = max(ans, i * hi)
print(ans)


(n, k, m, d) = [int(x) for x in input().split()]
res = -1
for i in range(1, d + 1):
	iter = (i - 1) * k + 1
	max_x = n // iter
	min_x = n // (i * k)
	if min_x > m:
		continue
	if max_x > m:
		res = max(res, i * m)
	else:
		res = max(res, i * max_x)
print(int(res))


(n, k, m, d) = [int(x) for x in input().split()]
x = 0
for i in range(d):
	z = n // (i * k + 1)
	x = max(x, (i + 1) * min(z, m))
print(max(m, x))


(n, k, m, d) = map(int, input().split())
ans = 0
for t in range(1, d + 1):
	r = n // (t + (t - 1) * (k - 1))
	r = min(r, m)
	if r == 0:
		continue
	T = n // (r * k)
	if n % (r * k) >= r:
		T = T + 1
	if T <= d:
		ans = max(ans, r * T)
print(ans)


(n, k, M, D) = map(int, input().split())
res = 0
for d in range(1, D + 1):
	max_paquetes_repartidos = (d - 1) * k + 1
	caramelos_por_paquete = n // max_paquetes_repartidos
	maxv = min(M, caramelos_por_paquete)
	res = max(res, maxv * d)
print(res)


(n, k, m, d) = map(int, input().split())
ans = 0
for i in range(1, d + 1):
	lo = 0
	hi = m
	x = -1
	while lo <= hi:
		mid = (lo + hi) // 2
		if k * mid * (i - 1) + mid <= n:
			x = mid
			lo = mid + 1
		else:
			hi = mid - 1
	if x <= 0:
		continue
	c = (n - x) // (x * k) + 1
	if c > d:
		continue
	ans = max(ans, x * c)
print(ans)


import sys
(n, k, M, D) = [int(x) for x in sys.stdin.readline().split()]
ans = 0
for d in range(1, D + 1):
	x = min(M, n // (k * (d - 1) + 1))
	if n < (k * d + 1) * x:
		ans = max(ans, d * x)
print(ans)


def binn(p):
	nonlocal n, k, m, d
	l = 0
	r = m
	while l + 1 < r:
		m1 = (l + r) // 2
		if m1 * p * k + m1 - 1 >= n:
			r = m1
		else:
			l = m1
	return r

def binn1(x, p):
	nonlocal n, k, m, d
	l = x
	r = m + 1
	while l + 1 < r:
		m1 = (l + r) // 2
		if m1 * p + (k - 1) * (p - 1) * m1 <= n:
			l = m1
		else:
			r = m1
	return l
(n, k, m, d) = map(int, input().split())
ans = -1e+18
for i in range(1, d + 1):
	x = binn(i)
	x1 = binn1(x, i)
	if x1 * i + (k - 1) * (i - 1) * x1 <= n and x1 * i * k + x1 - 1 >= n:
		ans = max(ans, x1 * i)
print(ans)


ins = input().split(' ')
n = eval(ins[0])
k = eval(ins[1])
m = eval(ins[2])
d = eval(ins[3])
maxn = min(n, m)
thisrun = 0
round = 0
if d == 1:
	print(m)
	exit(0)
for i in range(1, d):
	if m * (i * k + 1) > n:
		break
	maxn = max(maxn, m * (i + 1))
for i in range(1, d):
	thisrun = n // (k * i + 1)
	if thisrun <= m:
		maxn = max(maxn, thisrun * (i + 1))
print(maxn)


import math
(n, k, M, D) = map(int, input().split())
ans = 0
for d in range(1, D + 1):
	x = n // (1 + (d - 1) * k)
	x = min(x, M)
	if (d - 1) * x * k + x > n:
		continue
	if d * x * k + x <= n:
		continue
	ans = max(ans, d * x)
print(int(ans))


(n, k, m, d) = map(int, input().split())
ans = 0
for i in range(1, d + 1):
	x = min(n // ((i - 1) * k + 1), m)
	if x and (n // x + k - 1) // k == i:
		ans = max(ans, x * i)
print(ans)


(n, k, m, d) = input().split(' ')
n = int(n)
k = int(k)
m = int(m)
d = int(d)

def can(x):
	global k, n
	laps = n // (k * x)
	ost = n % (k * x)
	if ost < x:
		return laps
	return laps + 1

def take(x):
	global k, n
	laps = n // (k * x)
	ost = n % (k * x)
	if ost < x:
		return laps * x
	return laps * x + x
ans = 0
for D in range(1, d + 1):
	l = 1
	r = int(1e+18)
	while r - l > 1:
		mid = (l + r) // 2
		if can(mid) < D:
			r = mid
		else:
			l = mid
	tMax = l
	l = 0
	r = int(1e+18)
	while r - l > 1:
		mid = (l + r) // 2
		if can(mid) <= D:
			r = mid
		else:
			l = mid
	tMin = r
	if tMin > m:
		continue
	tMax = min(m, tMax)
	tMax = max(tMax, tMin)
	ans = max(ans, take(tMin))
	ans = max(ans, take(tMax))
print(ans)


(n, k, m, d) = list(map(int, input().split()))
ans = 0
for t in range(1, d + 1):
	x = n // (k * t - k + 1)
	if x <= m:
		ans = max(ans, t * x)
x = m
t = (n // x + k - 1) // k
if t <= d:
	ans = max(ans, t * x)
print(ans)


(n, k, m, d) = map(int, input().split())
ans = -1
for i in range(1, d + 1):
	cur = n // (k * i - k + 1)
	ans = max(ans, min(cur, m) * i)
print(ans)


(nSweets, nPeople, xMax, maxCount) = (int(x) for x in input().split())
answ = 0
for curr in range(1, maxCount + 1):
	x = min(xMax, nSweets // ((curr - 1) * nPeople + 1))
	if x == 0:
		continue
	answ = max(answ, x * curr)
print(answ)


(n, k, M, D) = map(int, input().split())
ans = 0
for i in range(1, D + 1):
	x = min(M, n // (k * (i - 1) + 1))
	ans = max(ans, i * x)
print(ans)


(n, k, M, D) = map(int, input().split())
ans = 0
for i in range(1, D + 1):
	l = n // (i * k)
	r = n // ((i - 1) * k + 1)
	if l <= M:
		ans = max(ans, min(M, r) * i)
print(ans)


v = input().split()
n = int(v[0])
k = int(v[1])
M = int(v[2])
D = int(v[3])
ans = -100000000000000000000000000000000000
for times in range(1, D + 1):
	den = (times - 1) * k + 1
	x = min(n // den, M)
	ans = max(ans, times * x)
print(ans)


(n, k, m, d) = map(int, input().split())
r = 0
l = 1
while l <= d:
	r = max(r, min(m * l, n // ((l - 1) * k + 1) * l))
	l += 1
print(max(r, m))


(n, k, M, D) = [int(i) for i in input().split()]
max_ = 0
for t in range(1, D + 1):
	c = min(M, n // (t + (k - 1) * (t - 1)))
	max_ = max(max_, c * t)
print(max_)


(n, k, m, d) = map(int, input().split(' '))
ans = 0
for i in range(1, d + 1):
	ant = min(m, n // (k * i))
	ant = max(ant, min(m, n // ((k - 1) * (i - 1) + i)))
	if ant == 0:
		continue
	c = int(n // ant // k)
	if n // ant % k != 0:
		c = c + 1
	if c > d:
		continue
	ans = max(ans, ant * c)
print(ans)


(n, k, m, d) = list(map(int, input().split()))
res = 0
for i in range(1, d + 1):
	x = n // ((i - 1) * k + 1)
	x = min(x, m)
	if x == 0:
		continue
	if (n // x - 1) // k + 1 != i:
		continue
	res = max(res, i * x)
print(int(res))


(n, k, m, d0) = list(map(int, input().split()))
ans = 0
for d in range(1, d0 + 1):
	x = min(m, n // ((d - 1) * k + 1))
	if x == 0:
		continue
	new_d = (n // x + k - 1) // k
	if d != new_d:
		continue
	ans = max(ans, x * d)
print(ans)


(n, k, m, d) = map(int, input().split())
ans = 0
for i in range(1, d + 1):
	s = 1
	e = m
	while s < e:
		mid = (s + e + 1) // 2
		if mid * (k * (i - 1) + 1) <= n:
			s = mid
		else:
			e = mid - 1
	if s * (k * (i - 1) + 1) <= n:
		ans = max(ans, i * s)
print(ans)


from sys import stdin
from math import ceil
(n, k, m, d) = map(int, stdin.readline().strip().split())
ans = 0
for i in range(1, d + 1):
	low = 1
	high = m
	while high - low > 1:
		mid = (high + low) // 2
		y = mid * (i - 1) * k
		y += mid
		if y <= n:
			low = mid
		else:
			high = mid
	y = high * (i - 1) * k
	y += high
	if y <= n:
		ans = max(ans, high * i)
	else:
		y = low * (i - 1) * k
		y += low
		if y <= n:
			ans = max(ans, low * i)
print(ans)


(n, k, m, d) = [int(i) for i in input().split()]
ans = 0
for i in range(1, d + 1):
	x = n // (k * i - k + 1)
	if x > m:
		x = m
	if x <= 0:
		continue
	if not (k * i - k + 1 <= n // x and n // x <= k * i):
		continue
	while k * i - k + 1 <= n // (x + 1) and x + 1 <= m:
		x += 1
	if x * i > ans:
		ans = x * i
print(ans)


(n, k, m, d) = map(int, input().split())
ans = 0
for i in range(1, d + 1):
	times = (i - 1) * k + 1
	per = n // times
	if per == 0:
		break
	per = min(per, m)
	ans = max(ans, i * per)
print(ans)


(n, k, m, d) = [int(x) for x in input().split(' ')]
ans = -1
for i in range(1, d + 1):
	maxserve = i + (i - 1) * (k - 1)
	minserve = i * k
	xmax = -1
	xmin = -1
	xmax = n // maxserve
	xmin = n // minserve
	if xmin <= m:
		bc = min(xmax, m)
		ans = max(ans, bc * i)
print(ans)


(n, k, m, d) = list(map(int, list(input().split())))
ans = 0
j = 1
while j <= d:
	ub = min(m, n // ((j - 1) * k + 1))
	lb = lb = n // j // k
	if lb <= ub:
		ans = max(ans, ub * j)
	j += 1
print(int(ans))


(n, k, m, q) = map(int, input().split())
ans = m
for i in range(q):
	x = min(m, n // (k * i + 1))
	ans = max(ans, (i + 1) * x)
print(ans)


import sys
(n, k, M, D) = map(int, sys.stdin.readline().strip().split())
best = 0
for d in range(1, D + 1):
	R = (d - 1) * k + 1
	x = n // R
	if x > M:
		x = M
	if d * x > best:
		best = d * x
print(best)


def get(sp, n, k, m, d):
	hx = n // (sp * k - k + 1)
	lx = n // (sp * k)
	if lx > m:
		return 0
	else:
		return min(m, hx) * sp
k = input()
lis = k.split(' ')
n = int(lis[0])
k = int(lis[1])
m = int(lis[2])
d = int(lis[3])
ans = -1
for i in range(1, d + 1):
	ans = max(ans, get(i, n, k, m, d))
print('{}\n'.format(ans))


import math
[n, k, M, D] = input().split()
n = int(n)
k = int(k)
M = int(M)
D = int(D)
best = 0
for i in range(D):
	x = min(M, n // (i * k + 1))
	score = (i + 1) * x
	best = max(best, score)
print(best)


(n, k, m, d) = map(int, input().split())
ans = m
for i in range(2, d + 1):
	lo = 1
	hi = m
	mid = 0
	tot = (i - 1) * k + 1
	while lo <= hi:
		mid = int((lo + hi) / 2)
		tmp = int(n / mid)
		if tmp >= tot:
			ans = max(ans, i * mid)
			lo = mid + 1
		else:
			hi = mid - 1
print(ans)


(n, k, m, d) = list(map(int, input().split()))
(final, max) = (0, 0)
for i in range(1, d + 1):
	final = min(m, n // ((i - 1) * k + 1)) * i
	if final > max:
		max = final
print(max)


(n, k, M, D) = map(int, input().split())
res = 0
for day in range(1, D + 1):
	ma = n // ((day - 1) * k + 1)
	if ma <= M:
		res = max(res, ma * day)
if (n // M - 1) // k + 1 <= D:
	res = max(res, M * ((n // M - 1) // k + 1))
print(res)


Q = [int(x) for x in input().split(' ')]
n = Q[0]
k = Q[1]
M = Q[2]
D = Q[3]
m1 = 0
for i in range(D):
	m = n // (i * k + 1)
	if m > M:
		m = M
	m1 = max(m * (i + 1), m1)
print(m1)


(numCandies, numPeople, maxiCandies, maxiTurn) = map(int, input().split())
ans = 0
for turn in range(1, maxiTurn + 1):
	maxi = maxiCandies
	maxi = min(maxi, numCandies // ((turn - 1) * numPeople + 1))
	if maxi == 0:
		continue
	if turn != (numCandies // maxi + numPeople - 1) // numPeople:
		continue
	x = maxi * (turn - 1) + maxi
	ans = max(ans, x)
print(ans)


import sys, math
sys.setrecursionlimit(100000000)
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, k, m, d) = invr()
ans = 1
for i in range(1, d + 1):
	hi = m
	lo = 1
	while hi >= lo:
		mid = (hi + lo) // 2
		temp = n // (mid * k)
		if n % (mid * k) >= mid:
			temp += 1
		if temp >= i:
			ans = max(ans, mid * i)
			lo = mid + 1
		else:
			hi = mid - 1
print(ans)


(n, k, M, D) = input().split()
n = int(n)
k = int(k)
M = int(M)
D = int(D)
val = 0
for d in range(1, D + 1):
	y = (d - 1) * k + 1
	x = n // y
	if x > M:
		x = M
	if x * d > val:
		val = x * d
print(val)


(n, k, M, D) = (int(x) for x in input().split())
ans = 0
for d in range(1, D + 1):
	l = n // (k * d + 1)
	r = min(n // (k * (d - 1) + 1), M)
	if l < r:
		ans = max(ans, r * d)
print(ans)


name = input()
(n, k, M, D) = [int(i) for i in name.split(' ')]
ret = 0
if k > n / M:
	ret = M
for i in range(D):
	d = i + 1
	l1 = (n + d * k + 1) // (1 + d * k)
	l2 = (n + d * k + k) // (k + d * k)
	r1 = n // (d * k)
	r2 = n // (1 + d * k)
	if max(l1, l2) <= min(M, r1):
		ret = max(ret, min(M, r1) * d)
	if l2 <= min(M, min(r1, r2)) and d + 1 <= D:
		ret = max(ret, min(M, min(r2, r1)) * (d + 1))
print(ret)


(n, k, m, d) = map(int, input().split())

def clc(x):
	return min(m, n // (x * k + 1)) * (x + 1)
ans = 0
for i in range(0, d):
	ans = max(ans, clc(i))
print(ans)


import sys
(n, k, m, d) = map(int, sys.stdin.readline().split())
ans = 0
for i in range(d):
	low = 1
	high = k
	x = -1
	while low <= high:
		mid = (low + high) // 2
		y = n // (i * k + mid)
		if y <= m:
			x = mid
			high = mid - 1
		else:
			ans = max(ans, m * (i + 1))
			low = mid + 1
	if x != -1:
		y = n // (i * k + x)
		ans = max(ans, y * (i + 1))
print(ans)


def main():
	(n, k, m, d) = map(int, input().split())
	ans = -1
	for p in range(d):
		j = n // (p * k + 1)
		if j <= m:
			ans = max(ans, j * (p + 1))
		else:
			ans = max(ans, m * (p + 1))
	print(ans)
	return
main()


(n, k, m, d) = map(int, input().split())
if n % (k * d) == 0:
	p = n // (k * d)
else:
	p = n // (k * d) + 1
ans = 0
for j in range(1, d + 1):
	if k * (j - 1) > 10 ** 18 or k * (j - 1) < 0:
		break
	x = n // (k * (j - 1) + 1)
	x = min(x, m)
	x *= j
	ans = max(ans, max(x, 0))
print(ans)


(n, k, m, d) = map(int, input().split())
ans = 0
for i in range(1, d + 1):
	mix = min(n // ((i - 1) * k + 1), m)
	if mix == 0:
		continue
	r = (n // mix + k - 1) // k
	if r != i:
		continue

	def ror(x):
		return x * (i - 1) + x
	ans = max(ans, ror(mix))
print(ans)


a = input()
a = a.split(' ')
for i in range(len(a)):
	a[i] = int(a[i])

def kandidati():
	d = []
	for i in range(1, a[3]):
		if a[0] // (i * a[1] + 1) < a[2]:
			d += [a[0] // (i * a[1] + 1) * (i + 1)]
	if a[0] % int(a[1] * a[2]) == 0:
		s = a[0] / (a[1] * a[2])
		d += [int(a[2] * s)]
	else:
		f = int(a[0] // (a[1] * a[2]))
		if a[0] - f * a[2] * a[1] >= a[2]:
			s = a[0] // (a[1] * a[2]) + 1
		else:
			s = a[0] // (a[1] * a[2])
		d += [int(a[2] * s)]
	print(max(d))
kandidati()


(n, k, m1, d) = map(int, input().split())
ans = 0
for i in range(d + 1):
	l = 0
	r = m1 + 1
	while r - l > 1:
		m = (l + r) // 2
		if n // (k * m) >= i:
			l = m
		else:
			r = m
	if l == 0:
		continue
	ans = max(ans, l * i)
	l1 = 0
	r = min(l + 1, m1 + 1)
	while r - l1 > 1:
		m = (l1 + r) // 2
		if n - i * k * m >= m:
			l1 = m
		else:
			r = m
	if l1 == 0 or i == d:
		continue
	ans = max(ans, l1 * i + l1)
print(ans)


(n, k, M, D) = list(map(int, input().split()))
ans = 0
for d in range(1, D + 1):
	bot = 0
	top = M + 1
	while top > bot + 1:
		mid = (bot + top) // 2
		cur = (d - 1) * mid * k
		cur += mid
		if cur > n:
			top = mid
		else:
			bot = mid
	ans = max(ans, bot * d)
print(ans)


str = input()
ls = str.split(' ')
n = int(ls[0])
k = int(ls[1])
M = int(ls[2])
D = int(ls[3])
ans = 0
for i in range(D + 1):
	maxX = n // (i * k - k + 1)
	minX = n // (i * k + 1)
	if n % (i * k + 1) == 0:
		minX += 1
	maxX = min(maxX, M)
	if minX <= maxX:
		ans = max(ans, i * maxX)
print(ans)


(n, k, m, d) = map(int, input().split())
result = 0
for f in range(1, d + 1):
	x_max = n // (k * (f - 1) + 1)
	x_min = n // (k * f)
	if x_min > m:
		continue
	result = max(result, f * min(m, x_max))
print(result)


(n, k, m, d) = map(int, input().split())
ans = min(n, m)
for i in range(1, d + 1):
	maxc = min(n // ((i - 1) * k + 1), m)
	if maxc == 0 or (n // maxc + k - 1) // k != i:
		continue
	ans = max(ans, i * maxc)
print(ans)


(n, k, M, D) = list(map(int, input().split()))
max_ = 0
for i in range(1, D + 1):
	max_ = max(max_, i * min(M, n // (i * k - k + 1)))
print(max_)


num = list(map(int, input().split()))
n = num[0]
k = num[1]
m = num[2]
p = num[3]
ans = 0
for d in range(1, p + 1):
	var1 = d + (k - 1) * (d - 1)
	var2 = n // var1
	if var2 > m:
		var2 = m
	ans = max(ans, d * var2)
print(ans)


(n, k, M, D) = map(int, input().split())
ans = 0
for d in range(D + 1):
	x1 = n // (k * (d - 1) + 1)
	x2 = 0
	if M * (k * (d - 1) + 1) <= n:
		x2 = M
	if x1 > M:
		x1 = 0
	ans = max(ans, max(x1 * d, x2 * d))
print(ans)


def bs(cnt):
	global n, m, k
	l = 1
	r = min(n, m) + 1
	while l + 1 != r:
		md = l + (r - l) // 2
		res = n // (md * k)
		if n % (md * k) >= md:
			res += 1
		if res >= cnt:
			l = md
		else:
			r = md
	return l
(n, k, m, d) = map(int, input().split())
ans = 0
for i in range(1, d + 1):
	h = bs(i)
	h1 = n // (h * k)
	if n % (h * k) >= h:
		h1 += 1
	if h1 != i:
		continue
	ans = max(ans, h * i)
print(ans)


(n, k, M, D) = input().split()
n = int(n)
k = int(k)
M = int(M)
D = int(D)
low = (n + k * D - 1) // (k * D)
high = M
i = 1
an = 0
while i <= D:
	lo = low - 1
	hi = high
	while lo != hi:
		mi = (lo + hi + 1) // 2
		if (i - 1) * k * mi + mi <= n:
			lo = mi
		else:
			hi = mi - 1
	if lo != low - 1 and an < lo * i:
		an = lo * i
	i = i + 1
print(an)


(n, k, m, d) = map(int, input().split())
best = -1
for i in range(1, d + 1):
	curr = min(m, n // (k * (i - 1) + 1))
	if curr == 0:
		continue
	times = n // curr
	check = times // k
	if times % k != 0:
		check += 1
	if check != i:
		continue
	best = max(best, curr * i)
print(best)


import math
import sys
input = sys.stdin.readline

def main():
	(n, k, m, d) = [int(x) for x in input().split(' ')]
	best = 0
	for i in range(1, d + 1):
		pos = 1
		for j in range(100, -1, -1):
			jump = 2 ** j
			if pos + jump > m or pos + jump > n:
				continue
			goes_into = n // ((pos + jump) * k)
			rem = 0
			if n % ((pos + jump) * k) >= pos + jump:
				rem = 1
			if goes_into + rem >= i:
				pos += jump
		goes_into = n // (pos * k)
		rem = 0
		if n % (pos * k) >= pos:
			rem = 1
		if pos <= m and goes_into + rem == i:
			best = max(best, pos * i)
	print(best)
main()


(n, k, m, d) = map(int, input().split())
ans = int(0)
for i in range(1, d + 1):
	(l, r, mid) = (1, m + 1, 0)
	while l + 1 < r:
		mid = (l + r) // 2
		if (n - mid) // (k * mid) < i - 1:
			r = mid
		else:
			l = mid
	if (n - l) // (k * l) < i - 1:
		break
	ans = max(ans, l * i)
print(ans)


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


(n, k, m, D) = [int(x) for x in input().split()]
print(max((d * min(m, n // (k * (d - 1) + 1)) for d in range(1, D + 1))))


(N, K, M, D) = map(int, input().split())
ans = 0
for d in range(1, D + 1):
	x = min(M, N // ((d - 1) * K + 1))
	ans = max(ans, d * x)
print(ans)


(n, k, m, d) = map(int, input().split())
mi = n // (k * d)
z = n
if n % (k * d) != 0:
	mi += 1
t = n // (k * mi)
z -= k * mi * t
if z >= mi:
	t += 1
d = min(d, t)
ans = 0
for i in range(1, d + 1):
	x = n // ((i - 1) * k + 1)
	for j in range(x, x + 1):
		if j * (i - 1) * k >= n:
			continue
		if j * i * k < n and n - j * i * k >= x:
			continue
		if j >= mi and j <= m:
			ans = max(ans, i * j)
		if mi * (i - 1) * k >= n:
			continue
		if mi * i * k < n and n - j * i * k >= mi:
			continue
		ans = max(ans, i * mi)
		if m * (i - 1) * k >= n:
			continue
		if m * i * k < n and n - j * i * k >= m:
			continue
		ans = max(ans, i * m)
print(ans)


(n, k, M, D) = [int(x) for x in input().split()]
tim = min(D, n // (M * k))
ans = M * tim
if tim != D and n - M * tim * k >= M:
	ans += M
for tim in range(1, D + 1):
	x = n // (k * tim)
	if x <= M:
		val = x * tim
		if n - x * tim * k >= x and tim != D:
			val += x
		ans = max(ans, val)
	if tim != D:
		x = n // (k * tim + 1)
		if x <= M:
			ans = max(ans, x * (tim + 1))
print(ans)


def calc(n, k, M, D):
	ans = 0
	for d in range(1, D + 1):
		g = k * d - k + 1
		x = min(n // g, M)
		ans = max(ans, x * d)
	return ans
(n, k, M, D) = map(int, input().split())
ans = calc(n, k, M, D)
print(ans)


(n, k, m, d) = map(int, input().split())
ans = 0
for i in range(1, d + 1):
	maxx = min(n // ((i - 1) * k + 1), m)
	if maxx:
		curd = (n // maxx + k - 1) // k
		if curd == i:
			ans = max(ans, i * maxx)
print(ans)


ins = input().split(' ')
n = int(ins[0])
k = int(ins[1])
m = int(ins[2])
d = int(ins[3])
ans = m * ((n // m + k - 1) // k)
for p in range(1, d + 1):
	if n // (k * (p - 1) + 1) <= m:
		ans = max(ans, n // (k * (p - 1) + 1) * p)
print(ans)


(n, k, M, D) = map(int, input().split())
best = 0
for t in range(D + 1):
	fmin = max(1, (t - 1) * k + 1)
	xmax = min(M, n // fmin)
	if xmax != 0 and (n // xmax + k - 1) // k == t:
		best = max(best, t * xmax)
print(best)


def atoi(s):
	s = s[::-1]
	num = 0
	for (i, v) in enumerate(s):
		for j in range(0, 10):
			if v == str(j):
				num += j * 10 ** i
	return num
(n, k, M, D) = input().split()
n = atoi(n)
k = atoi(k)
M = atoi(M)
D = atoi(D)
ans = 0
for i in range(1, D + 1):
	x = n // (k * (D - i) + 1)
	if x > M:
		x = M
	else:
		ans = max(ans, x * (D - i + 1))
ndivM = n // M
cnt = ndivM // k
if ndivM % k != 0:
	cnt += 1
if cnt > D:
	cnt = D
ans = max(ans, cnt * M)
print(ans)


def ifthen(x, y, z):
	return y if x else z
(n, k, M, D) = map(int, input().split())
t = M
t2 = n // M // k + ifthen(n // M % k, 1, 0)
ans = t * t2
for i in range(2, D + 1):
	l = n // (k * i)
	r = n // (k * (i - 1))
	tmp = k * (i - 1) + 1
	while r - l > 1:
		mid = (l + r) // 2
		if tmp * mid <= n:
			if mid <= M:
				ans = max(ans, mid * i)
			l = mid
		else:
			r = mid
	if tmp * l <= n and l <= M:
		ans = max(ans, l * i)
	if tmp * r <= n and r <= M:
		ans = max(ans, r * i)
print(ans)


import sys
(n, k, M, D) = map(int, sys.stdin.readline().strip().split())
best = 0
for d in range(1, D + 1):
	x = min(M, n // (1 + (d - 1) * k))
	best = max(best, d * x)
print(best)


(n, k, M, D) = map(int, input().split())
t = (n // M + k - 1) // k
ans = t * M
for i in range(t + 1, D + 1):
	s = n // (i * k - k + 1)
	if s * i > ans:
		ans = s * i
print(ans)


(N, K, M, D) = input().split(' ')
N = int(N)
K = int(K)
M = int(M)
D = int(D)
ans = M
for d in range(1, D + 1):
	x_1 = N // (K * (d - 1) + 1)
	fin_x = min(x_1, M)
	ans = max(ans, fin_x * d)
print(ans)


(n, k, M, D) = list(map(int, input().split()))
mx = 0
for d in range(1, D + 1):
	x = n // (k * d - k + 1)
	x = min(x, M)
	ans = x * d
	mx = max(mx, ans)
print(mx)


(n, k, m, d) = [int(i) for i in input().split()]
ma = 0
for i in range(d):
	cnt = k * i + 1
	ans = min(n // cnt, m) * (i + 1)
	ma = max(ma, ans)
print(ma)


(n, k, M, D) = map(int, input().split())
cand = 0
for i in range(D):
	m = n // (k * i + 1)
	m = min(m, M)
	cand = max(m * (i + 1), cand)
print(cand)


from sys import stdin
(n, k, M, D) = map(int, stdin.readline().strip().split())
print(max(map(lambda d: d * min(M, n // (1 + (d - 1) * k)), range(1, D + 1))))


(n, k, m, d) = map(int, input().split())
ans = 0
for i in range(d + 1):
	w = 0
	if i > 0:
		w = n // (k * i)
	if w > m:
		w = m
	res = w * i
	if n - k * i * w >= w and i + 1 <= d:
		res += w
	ans = max(ans, res)
	w = n // (k * i + 1)
	if w > m:
		w = m
	res = w * i
	if n - k * i * w >= w and i + 1 <= d:
		res += w
	ans = max(ans, res)
print(ans)


(n, k, m, d) = list(map(int, input().split()))
ans = 0
for i in range(1, d + 1):
	if m < n // (k * i):
		continue
	if n < k * (i - 1) + 1:
		break
	ans_here = min(n // (k * (i - 1) + 1), m)
	ans = max(ans, ans_here * i)
print(ans)


(n, k, m, d) = input().split()
(n, k, m, d) = (int(n), int(k), int(m), int(d))
res = 0
for t in range(0, d):
	x = min(m, n // (t * k + 1))
	if x == 0:
		continue
	curr = (n // x + k - 1) // k
	if curr == t + 1:
		res = max(res, x * (t + 1))
print(res)


(n, k, m, d) = map(int, input().split())
ans = 0
for dd in range(1, d + 1):
	(A, B) = ((dd - 1) * k + 1, dd * k + 1)
	(mx, mn) = (min(m, n // A), n // B + 1)
	if mn <= mx:
		ans = max(ans, mx * dd)
print(ans)


t = 1
while t > 0:
	t -= 1
	(n, k, m, d) = list(map(int, input().split()))
	ans = 0
	for i in range(1, d + 1):
		x = m
		x = min(m, n // ((i - 1) * k + 1))
		if x == 0:
			continue
		rd = (n - x) // (k * x)
		rd = rd + 1
		if i != rd:
			continue
		ans = max(ans, x * (i - 1) + x)
	print(ans)


(N, K, M, D) = input().split(' ')
N = int(N)
K = int(K)
M = int(M)
D = int(D)
ans = -1
for d in range(1, D + 1):
	numDivisors = K * (d - 1) + 1
	candiesPer = N // numDivisors
	if candiesPer == 0:
		continue
	if candiesPer > M:
		candiesPer = M
		if N // (candiesPer * K) > D:
			candiesPer = N // (D * K)
	ans = max(ans, candiesPer * d)
print(ans)


from math import floor
(n, k, M, D) = map(int, input().split())
_max = M
for g in range(2, D + 1):
	x = min(M, n // ((g - 1) * k + 1))
	max_g = g * x
	_max = max(_max, max_g)
print(_max)


import math
from decimal import Decimal
(n, k, m, d) = map(int, input().split())
ans = 0
for i in range(1, d + 1):
	times = (i - 1) * k + 1
	per = n // times
	per = min(per, m)
	ans = max(ans, i * per)
print(ans)


(n, k, m, d) = map(int, input().split())
for i in range(1, d + 1):
	t = 0
	if i == 1:
		if n // m % k == 0:
			re = n // m // k * m
		else:
			re = (1 + n // m // k) * m
	else:
		x = n // ((i - 1) * k + 1)
		r = n % ((i - 1) * k + 1)
		if x <= m and x > (n - r) // (k * d):
			t = i * x
		if t > re:
			re = t
print(re)


import sys
import math

def main():
	(n, k, M, D) = map(int, input().split())
	ans = 1
	for i in range(1, D + 1):
		d = k * (i - 1) + 1
		left = n // (i * k)
		right = n // d
		cnt = 1
		if M <= right:
			cnt = M
		else:
			cnt = right
		added = cnt * i
		ans = max(ans, added)
	print(ans)
main()


(n, k, M, D) = map(int, input().split())
ans = 0
for d in range(1, D + 1):
	a = 1 + k * (d - 1)
	b = M
	b = min(n // a, b)
	if b == 0:
		continue
	dd = (n // b + (k - 1)) // k
	if dd != d:
		continue
	ans = max(ans, b * (d - 1) + b)
print(ans)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
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')
(n, k, m, d) = map(int, input().split())
mx = 0
for i in range(1, d + 1):
	j = i + (i - 1) * (k - 1)
	x = min(m, n // j)
	mx = max(mx, x * i)
print(mx)


(n, k, M, D) = map(int, input().split())
res = 0
for cnt in range(D):
	res = max(res, (cnt + 1) * min(M, n // (k * cnt + 1)))
print(res)


(n, k, m, d) = map(int, input().split())
ma = -1
for i in range(1, d + 1):
	xma = min(n // ((i - 1) * k + 1), m)
	ma = max(ma, xma * i)
print(ma)


(n, k, m, d) = map(int, input().split())
maxr = 0
for i in range(1, d + 1):
	peeps = k * (i - 1) + 1
	t = n // peeps
	if t <= m:
		maxr = max(maxr, t * i)
		continue
	sec = k * i
	t2 = n // sec
	if t2 > m:
		continue
	r = n // m
	if r % k == 0:
		cyc = r // k
	else:
		cyc = r // k + 1
	maxr = max(maxr, cyc * m)
print(maxr)


(n, k, m, D) = map(int, input().split())
res = 0
for d in range(1, D + 1):
	x = m
	x = min(x, n // ((d - 1) * k + 1))
	if x * k * (d - 1) + x > n:
		break
	if res == 0 or res < x * d:
		res = x * d
print(res)


(n, k, m, D) = [int(s) for s in input().split()]
maxc = 0
for d in range(1, D + 1):
	x = n // (k * (d - 1) + 1)
	if x > m:
		x = m
	c = x * d
	if c > maxc:
		maxc = c
print(maxc)


(n, k, M, d) = map(int, input().split())
ans = 0
for i in range(1, d + 1):
	l = 1
	r = M + 1
	while r - l > 1:
		m = (l + r) // 2
		if n // (k * m) + (n % (k * m) >= m) >= i:
			l = m
		else:
			r = m
	ii = n // (k * l) + (n % (k * l) >= l)
	if ii > i:
		continue
	ans = max(ans, l * ii)
print(ans)


(n, k, M, D) = map(int, input().split())
best = -1
ans = -1
for i in range(1, D + 1):
	num_of_rounds = k * (i - 1) + 1
	x = n // num_of_rounds
	if x == 0:
		continue
	if n // x >= k * (i + 1) + 1:
		x = (n + num_of_rounds - 1) // num_of_rounds
	if x == 0:
		continue
	ours = n // (x * k) * x + x * (1 if n % (k * x) >= x else 0)
	if x <= M:
		if ours > best:
			best = ours
			ans = x
	else:
		x = M
		ours = n // (x * k) * x + x * (1 if n % (k * x) >= x else 0)
		if ours > best:
			best = ours
			ans = x
print(best)


(n, k, m, d) = map(int, input().split())
ans = 0
for id in range(1, d + 1):
	le = n // ((id - 1) * k + 1)
	if n // (id * k) <= n % (id * k):
		ri = n // (id * k) + 1
	else:
		ri = n // (id * k)
	if m >= ri and ri <= le:
		tans = min(le, m)
		ans = max(ans, tans * id)
print(ans)


from math import *
(n, k, m, d) = map(int, input().split())
ot = 0
x = 0
y = 1
while y <= d:
	x = n // ((y - 1) * k + 1)
	x = min(x, m)
	ot = max(ot, y * x)
	y += 1
print(ot)


(n, k, M, D) = map(int, input().split())
ans = 0
for d in range(0, D + 1):
	x = n // ((d - 1) * k + 1)
	if x > M:
		x = M
	if x * d > ans:
		ans = x * d
print(ans)


(n, k, M, D) = map(int, input().split())
ans = 0
for d in range(1, D + 1):
	max_x = min(M, n // (k * (d - 1) + 1))
	ans = max(ans, max_x * d)
print(ans)


import math
(n, k, M, D) = input().split()
n = int(n)
k = int(k)
M = int(M)
D = int(D)
ans = -1
for a in range(1, D + 1):
	r = a * k
	l = (a - 1) * k + 1
	l1 = math.ceil(n / (r + 1))
	if l > 0:
		r1 = n // l
	else:
		r1 = 999999999999999999
	if r1 >= l1 and M >= l1:
		x = min(r1, M)
		ans = max(ans, x * a)
print(ans)


(n, k, m, d) = map(int, input().split(' '))
t = n // m
res = 0
i = 1
while True:
	kk = k * i
	if kk >= t:
		res = i * min(m, n)
		break
	i += 1
for j in range(i, d):
	kk = k * j
	res = max(res, n // (kk + 1) * (j + 1))
print(res)


(n, k, m, d) = map(int, input().split(' '))
ans = 0
hand = 0
for i in range(d):
	koita = hand + 1
	val = min(n // koita, m)
	ans = max(ans, val * (i + 1))
	hand += k
print(ans)


(n, k, m, d) = map(int, input().split())
ans = int(0)
for i in range(1, d + 1):
	num = n // (k * (i - 1) + 1)
	if num > m:
		num = m
	ans = max(ans, num * i)
print(ans)


a = input().split(' ')
n = int(a[0])
k = int(a[1])
m = int(a[2])
d = int(a[3])
ans = 0
for i in range(1, d + 1):
	(l, r, x) = (1, m, -1)
	cur = (i - 1) * k + 1
	while l <= r:
		mid = (l + r) // 2
		if n // mid >= cur:
			l = mid + 1
			x = mid
		else:
			r = mid - 1
	if x == -1 or n // x > i * k:
		continue
	if x * i > ans:
		ans = x * i
print(int(ans))


s = input().split()
s = [int(c) for c in s]
(n, k, M, Du) = s
Db = (n // M - 1 + k) // k
ans = Db * M
for i in range(Db + 1, Du + 1):
	ans = max(ans, n // ((i - 1) * k + 1) * i)
print(ans)


s = list(map(int, input().split()))
n = s[0]
k = s[1]
M = s[2]
D = s[3]
ans = 0
for d in range(0, D + 1):
	x = n // ((d - 1) * k + 1)
	if x > M:
		x = M
	if x * d > ans:
		ans = x * d
print(ans)


(n, k, M, D) = list(map(int, input().split(' ')))
gain = 0
for i in range(1, D + 1):
	x = n // ((i - 1) * k + 1)
	x = min(M, x)
	if x > 0:
		true_d = (n // x + k - 1) // k
		if true_d != i:
			continue
		gain = max(gain, x * i)
print(gain)


from math import floor
(n, k, m, d) = [int(i) for i in input().split()]
ans = 0
for i in range(1, d + 1):
	cur = int(n // (k * (i - 1) + 1))
	if m < cur:
		cur = m
	if cur * i > ans:
		ans = cur * i
print(ans)


(n, k, M, D) = map(int, input().split())
ans = 0
for time in range(1, D + 1):
	x = n // ((time - 1) * k + 1)
	if x > M:
		x = M
		if n // x > time * k:
			continue
	ans = max(ans, time * x)
print(ans)


(n, k, m, d) = [int(x) for x in input().split()]
ans = 0
for t in range(1, d + 1):
	R = n // ((t - 1) * k + 1)
	L = n // (t * k)
	if L <= R:
		if L <= m <= R:
			ans = max(ans, m * t)
		elif R <= m:
			ans = max(ans, R * t)
print(ans)


(N, K, M, D) = map(int, input().split())
maxi = 0
for i in range(0, D):
	x = max(N // ((i + 1) * K), min(M, N // (i * K + 1)))
	if x > M:
		continue
	maxi = max(maxi, (i + 1) * x)
print(maxi)


(n, k, M, D) = map(int, input().split())
w = 0

def binarySearchCount(i, n):
	left = 0
	right = M
	mid = 0
	count = 0
	while left <= right:
		mid = (right + left) // 2
		w = (k - 1) * (i - 1) * mid + i * mid
		if w <= n:
			count = mid
			left = mid + 1
		else:
			right = mid - 1
	return count
for i in range(1, D + 1):
	c = binarySearchCount(i, n)
	w = max(w, c * i)
print(w)


(n, k, m, d) = input().split()
n = int(n)
k = int(k)
m = int(m)
d = int(d)
ans = 0
for i in range(min(d, 1000), 0, -1):
	xr = n // ((i - 1) * k + 1)
	xl = n // (i * k + 1) + 1
	if xl > m:
		break
	x = min(m, xr)
	ans = max(ans, x * i)
print(int(ans))


def ceil_div(a, b):
	res = a // b
	if a % b != 0:
		res += 1
	return res

def solve_range(n, k, m, r):
	(low, up) = (1, m)
	up = min(up, n // (1 + (r - 1) * k))
	low = max(low, n // (1 + r * k) + (1 if n % (1 + r * k) == 0 else 0))
	return (low, up)

def main():
	(n, k, m, d) = tuple([int(part) for part in input().split(' ')])
	ans = 0
	for r in range(1, d + 1):
		(xmin, xmax) = solve_range(n, k, m, r)
		if xmin <= xmax:
			ans = max(ans, r * xmax)
	print(ans)
main()