Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the _same number_ of the commentary boxes. If any box is left unoccupied then the delegations will be upset. _So each box should be occupied by exactly one delegation._
If $n$ is not divisible by $m$, it is impossible to distribute the boxes to the delegations at the moment.
Organizers can build a new commentary box paying $a$ burles and demolish a commentary box paying $b$ burles. They can both build and demolish boxes arbitrary number of times (each time paying a corresponding fee). It is allowed to demolish all the existing boxes.
What is the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$)?
## Input
The only line contains four integer numbers $n$, $m$, $a$ and $b$ ($1 \le n, m \le 10^{12}$, $1 \le a, b \le 100$), where $n$ is the initial number of the commentary boxes, $m$ is the number of delegations to come, $a$ is the fee to build a box and $b$ is the fee to demolish a box.
## Output
Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$). It is allowed that the final number of the boxes is equal to $0$.
[samples]
## Note
In the first example organizers can build $5$ boxes to make the total of $14$ paying $3$ burles for the each of them.
In the second example organizers can demolish $2$ boxes to make the total of $0$ paying $7$ burles for the each of them.
In the third example organizers are already able to distribute all the boxes equally among the delegations, each one get $5$ boxes.
Berland Football Cup 即将开幕!来自世界各地的评论员都将前来参加这一赛事。
主办方已经建好了 $n$ 个评论席位。$m$ 个地区代表团将前来参加杯赛。每个代表团应获得相同数量的评论席位。如果存在任何未被占用的席位,代表团将会不满。因此,每个席位必须恰好被一个代表团占用。
如果 $n$ 不能被 $m$ 整除,则当前无法将席位分配给代表团。
主办方可以通过支付 $a$ 卢布新建一个评论席位,或通过支付 $b$ 卢布拆除一个评论席位。他们可以任意次数地新建或拆除席位(每次操作支付相应费用)。允许拆除所有现有席位。
求主办方为满足所有代表团(即使得席位总数能被 $m$ 整除)所需支付的最少卢布数。
仅一行包含四个整数 $n$, $m$, $a$ 和 $b$($1 lt.eq n, m lt.eq 10^(12)$,$1 lt.eq a, b lt.eq 100$),其中 $n$ 是初始的评论席位数,$m$ 是将要到来的代表团数量,$a$ 是新建一个席位的费用,$b$ 是拆除一个席位的费用。
请输出满足所有代表团需求所需的最少卢布数(即使得席位总数能被 $m$ 整除)。允许最终席位数为 $0$。
在第一个示例中,主办方可以新建 $5$ 个席位,使总数变为 $14$,每个新建席位花费 $3$ 卢布。
在第二个示例中,主办方可以拆除 $2$ 个席位,使总数变为 $0$,每个拆除席位花费 $7$ 卢布。
在第三个示例中,主办方已经能够将所有席位平均分配给各代表团,每个代表团获得 $5$ 个席位。
## Input
仅一行包含四个整数 $n$, $m$, $a$ 和 $b$($1 lt.eq n, m lt.eq 10^(12)$,$1 lt.eq a, b lt.eq 100$),其中 $n$ 是初始的评论席位数,$m$ 是将要到来的代表团数量,$a$ 是新建一个席位的费用,$b$ 是拆除一个席位的费用。
## Output
请输出满足所有代表团需求所需的最少卢布数(即使得席位总数能被 $m$ 整除)。允许最终席位数为 $0$。
[samples]
## Note
在第一个示例中,主办方可以新建 $5$ 个席位,使总数变为 $14$,每个新建席位花费 $3$ 卢布。在第二个示例中,主办方可以拆除 $2$ 个席位,使总数变为 $0$,每个拆除席位花费 $7$ 卢布。在第三个示例中,主办方已经能够将所有席位平均分配给各代表团,每个代表团获得 $5$ 个席位。
Let $ n $, $ m $, $ a $, $ b $ be given integers with $ 1 \leq n, m \leq 10^{12} $, $ 1 \leq a, b \leq 100 $.
Let $ r = n \bmod m $.
Then $ 0 \leq r < m $.
We wish to find the minimal cost to make $ n' \equiv 0 \pmod{m} $, where $ n' $ is the final number of boxes, obtained by either:
- **Adding** $ k $ boxes: $ n' = n + k $, where $ k \geq 0 $, and $ n + k \equiv 0 \pmod{m} $ → $ k \equiv -r \pmod{m} $, so minimal $ k = (m - r) \bmod m $.
Since $ r \ne 0 $, $ k = m - r $; if $ r = 0 $, $ k = 0 $.
- **Removing** $ k $ boxes: $ n' = n - k $, where $ k \geq 0 $, and $ n - k \equiv 0 \pmod{m} $ → $ k \equiv r \pmod{m} $, so minimal $ k = r $ (since $ r < m $).
Thus, two candidate operations:
1. **Build** $ k_1 = (m - r) \bmod m $ boxes: cost = $ a \cdot k_1 $
Since $ r \in [0, m-1] $, $ k_1 = \begin{cases} 0 & \text{if } r = 0 \\ m - r & \text{if } r > 0 \end{cases} $
2. **Demolish** $ k_2 = r $ boxes: cost = $ b \cdot r $
Also, we may consider **both** building and demolishing to reach a multiple of $ m $ farther away, but since we can reach the *nearest* multiples above and below $ n $, and costs are linear, the minimum cost must occur at one of the two nearest multiples of $ m $: the largest multiple $ \leq n $, and the smallest multiple $ \geq n $.
So define:
- $ n_{\text{down}} = n - r $ (largest multiple of $ m $ ≤ $ n $) → cost to demolish: $ b \cdot r $
- $ n_{\text{up}} = n + (m - r) $ if $ r > 0 $, else $ n $ → cost to build: $ a \cdot (m - r) $ if $ r > 0 $, else 0
If $ r = 0 $, cost = 0.
Otherwise, minimal cost = $ \min(a \cdot (m - r), b \cdot r) $
Thus, the minimal cost is:
$$
\boxed{
\begin{cases}
0 & \text{if } r = 0 \\
\min(a \cdot (m - r),\ b \cdot r) & \text{if } r > 0
\end{cases}
}
\quad \text{where } r = n \bmod m
$$