PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000011. Tối đa hóa MEX (MEX maximizing)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tối đa hóa MEX (MEX maximizing)

MEX maximizing

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Start with an empty array. Each of qq queries appends a nonnegative number yy. After each append, you may increase or decrease any element by xx any number of times without making it negative. The MEX is the smallest absent nonnegative integer. Output the maximum obtainable MEX after each query. Operations are reset before the next query.

Input

First line: q,xq,x. Then qq lines, each with an appended value yy.

Output

Print qq lines, the maximum MEX after each query.

Subtasks

  • Subtask 1 (20 points): 1≤q,x≤201 \le q,x \le 20; 0≤y≤1000 \le y \le 100
  • Subtask 2 (30 points): 1≤q,x≤20001 \le q,x \le 2000; 0≤y≤1060 \le y \le 10^{6}
  • Subtask 3 (50 points): 1≤q,x≤4∗1051 \le q,x \le 4*10^{5}; 0≤y≤1090 \le y \le 10^{9}

Examples

Input

4 3
1
2
1
2

Output

0
0
0
0

Explanation

No appended element has remainder 00 modulo 33. Such moves preserve remainders, hence 00 is always missing.