P17435 "LWLV Round 1" W

Background

Little L really likes the letter W.

Description

Little L wants you to construct a **positive integer** sequence $a$ that satisfies: 1. This sequence has $n$ numbers, with indices in $[1,n]$. 2. $\sum\limits_{i=1}^n a_i = m$. Please find the maximum value of: $$\sum\limits_{i=1}^n (a_i \bmod k)$$

Input Format

One line with $3$ positive integers $n,m,k$.

Output Format

One line containing this maximum value.

Explanation/Hint

#### Sample Explanation For sample 1, you can construct the sequence $[2,1,2]$, and the answer is $5$. #### Constraints | Subtask ID | $n,k$ | $m$ | Score | |:-:|:-:|:-:|:-:| | $0$ | $\le 10$ | $\le 10^{18}$ | $20$ | | $1$ | $\le 500$ | ^ | $20$ | | $2$ | $\le 10^{9}$ | ^ | $60$ | For $100\%$ of the testdata, it is guaranteed that $2 \le n \le k \le 10^9$ and $m \le 10^{18}$. Translated by ChatGPT 5