Cellular Automaton#6293

Cellular Automaton

5 seconds
64 megabytes
Medium

A cellular automaton is a collection of cells on a grid of specified shape that evolves through a number of discrete time steps according to a set of rules that describe the new state of a cell based on the states of neighboring cells. The order of the cellular automaton is the number of cells it contains. Cells of the automaton of order are numbered from to .

The order of the cell is the number of different values it may contain. Usually, values of a cell of order are considered to be integer numbers from to m-1.

One of the most fundamental properties of a cellular automaton is the type of grid on which it is computed. In this problem we examine the special kind of cellular automaton — circular cellular automaton of order with cells of order . We will denote such kind of cellular automaton as -automaton.

A distance between cells and in -automaton is defined as \min(|i-j|, n-|i-j|). A -environment of a cell is the set of cells at a distance not greater than .

On each -step values of all cells are simultaneously replaced by new values. The new value of cell after -step is computed as a sum of values of cells belonging to the -environment of the cell modulo .

The following picture shows -step of the -automaton.

The problem is to calculate the state of the -automaton after -steps.

Input

The first line of the input contains four integer numbers , , , and (1 \le n \le 500, 1 \le m \le 1000000, 0 \le d < n/2, 1 \le k \le 10000000). The second line contains integer numbers from to m-1 — initial values of the automaton's cells.

Output

Output the values of the -automaton's cells after -steps.

Examples

Example 1

Loading
Loading