#P17435. 「LWLV Round 1」W

「LWLV Round 1」W

Background

Little L really likes the letter W.

Problem Description

Little L wants you to construct a positive integer sequence aa that satisfies:

  1. This sequence has nn numbers, with indices in [1,n][1,n].
  2. ∑i=1nai=m\sum\limits_{i=1}^n a_i = m.

Please find the maximum value of:

∑i=1n(ai mod k)\sum\limits_{i=1}^n (a_i \bmod k)

Input Format

One line with 33 positive integers n,m,kn,m,k.

Output Format

One line containing this maximum value.

3 5 3
5
3 11 3
5

Hint

Sample Explanation

For sample 1, you can construct the sequence [2,1,2][2,1,2], and the answer is 55.

Constraints

Subtask ID n,kn,k mm Score
00 ≤10\le 10 ≤1018\le 10^{18} 2020
11 ≤500\le 500 ^
22 ≤109\le 10^{9} 6060

For 100%100\% of the testdata, it is guaranteed that 2≤n≤k≤1092 \le n \le k \le 10^9 and m≤1018m \le 10^{18}.

Translated by ChatGPT 5