$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: interview

Starter code:

Solutions:
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);


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=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)


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
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 )


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;


def __starting_point():
        k=input()
        lis=k.split(' ')
        #print("{}\n".format(k))
        #print("{}\n".format(lis))
        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))
__starting_point()

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_)


#!/usr/bin/env python3

[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)


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)

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 = 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)
    # print(i, ans_here)
    ans = max(ans, ans_here * i)
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))


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

[n,k,M,D]=input().split()
n=int(n)
k=int(k)
M=int(M)
D=int(D)
"""
ll best=0;
	for (ll i=0; i<=(D-1); i++){
		ll x=min(up,n/(i*k+1));
		ll score=(i+1)*x;
		best=max(best,score);
	}
	
	cout<<best<<endl;
"""
best=0
for i in range(D):
	#print(n, i*k+1)
	x=min(M,(n//(i*k+1)))
	#print(i, x)
	score=(i+1)*x
	best=max(best,score)
print(best)

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)


## This is a solution for problem candies-splitting
#  This is nk_ok.py
#
#  @author: Nikolay Kalinin
#  @date: Mon, 23 Apr 2018 21:58:46 +0300

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

ans = 0
for d in range(1, D + 1):
    # (d - 1) * k * x + x <= n
    maxx = M
    maxx = min(n // ((d - 1) * k + 1), maxx)
    
    if maxx == 0:
        continue
    reald = (n // maxx + k - 1) // k
    if reald != d:
        continue
    
    def f(x):
        return x * (d - 1) + x
    
    ans = max(ans, f(maxx))
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)


Q = [int(x) for x in input().split(' ')]
n = Q[0]
k = Q[1]
M = Q[2]
D = Q[3]

mm = 0

for i in range(D):
    m = n // (i * k + 1)
    if m > M:
        m = M
    mm = max(m * (i + 1), mm)

print(mm)


n, k, m, d = [int(x) for x in 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)


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 = -1e18
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)

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)

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)

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)
            
    
def __starting_point():
    main()
__starting_point()

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)

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()