Yet Another Contest 5 P1 - Number Pyramid

View as PDF

Submit solution


Points: 7 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem types

Josh is playing with number pyramids! A number pyramid consists of N rows, labelled from 1 to N from top to bottom. The i-th row contains i cells, each containing a single integer between 0 and K1 (inclusive).

A number pyramid has a special property; each cell (apart from those on the N-th row) contains an integer equal to the sum of the two integers in the cells directly below it, modulo K. Formally, if vi,j is the integer written in the j-th cell (from the left) of the i-th row, then vi,j=(vi+1,j+vi+1,j+1) mod K. A number pyramid with N=6 and K=5 is shown below for clarity.

Josh would like to construct a number pyramid such that the integer written in the topmost cell is X (i.e. v1,1=X). He wonders the following question: what is the lexicographically largest sequence of integers written in the bottom row of any such number pyramid? Formally, what is the lexicographically largest possible sequence vN,1,vN,2,,vN,N? Note that Josh cannot choose the values of N and K, and that all integers in the pyramid must be between 0 and K1 (inclusive).

Sequence a1,a2,a3,,aN is lexicographically larger than sequence b1,b2,b3,,bN if, for the smallest i such that aibi, ai>bi.

Constraints

2N106

1K109

0X<K

Subtask 1 [10%]

N=2

Subtask 2 [20%]

2N200

1K200

Subtask 3 [30%]

2N2000

Subtask 4 [40%]

No additional constraints.

Input Specification

The only line contains three space-separated integers, N, K, and X respectively.

Output Specification

On a single line, output N space-separated integers, representing the lexicographically largest possible sequence of integers written on row N.

Sample Input

Copy
3 2 1

Sample Output

Copy
1 1 0

Explanation

The optimal number pyramid is shown below.


Comments

There are no comments at the moment.