```go
package main
import (
"fmt"
)
func main() {
var n, k, M, D int64
_, err := fmt.Scan(&n, &k, &M, &D)
if err != nil {
return
}
var maxCandies int64 = 0
// Iterate over the target number of times Arkady receives candies (c).
// We want to find the largest x such that Arkady receives candies exactly c times (or more if constrained by M, but kept <= D).
// Essentially, for each potential "number of rounds" c, we find the optimal x.
// Since x * count is what we want to maximize, and for a fixed count, larger x is better,
// we look at the boundaries where the number of rounds changes.
for c := int64(1); c <= D; c++ {
var limitX int64
if c == 1 {
// To receive at least 1 time, we just need total batches T >= 1.
// n/x >= 1 => x <= n.
limitX = n
} else {
// To receive at least c times, Arkady needs to be part of the batch sequence:
// 1, k+1, 2k+1, ..., (c-1)k+1.
// So total batches T must be >= (c-1)*k + 1.
// floor(n/x) >= (c-1)*k + 1
// This implies x <= n / ((c-1)*k + 1).
// Check for potential overflow or exceeding n
// We check if (c-1)*k > n.
if k > n/(c-1) {
limitX = 0
} else {
minBatches := (c-1)*k + 1
if minBatches > n {
limitX = 0
} else {
limitX = n / minBatches
}
}
}
if limitX == 0 {
// If limitX is 0, it means we need more batches than possible even with x=1.
// Since required batches increase with c, we can break.
break
}
// Apply the constraint x <= M
x := limitX
if x > M {
x = M
}
if x == 0 {
continue
}
// Calculate actual number of times Arkady receives candies with this x
T := n / x
// Arkady receives in batches 1, k+1, ...
// Count is ceil(T / k)
receives := (T + k - 1) / k
// Valid if receives <= D
if receives <= D {
candies := receives * x
if candies > maxCandies {
maxCandies = candies
}
}
}
fmt.Println(maxCandies)
}
```