- 148

## Statement

## Goal

Your goal is to write a program that can show the evolution of an Elementary Cellular Automaton! This is a one-dimensional binary system in which each cell (For example, consider the

`pattern`:

0010110

In order to determine the next value for the 4th cell, we look at the neighborhood:

Since neighborhoods can have any one of 8 different values (

For example, a rule could state that neighborhoods that resemble

`pattern`

000100

001000

010000

In this puzzle, the rule will be provided in the

**Input**in the form of a Wolfram code (a single 8-bit number) where each digit in the binary representation of the code represents the evolution for the corresponding neighborhood.

For example, if the provided rule is the code

Neighborhood:111 110 101 100 011 010 001 000

Next value:0 0 1 1 0 1 0 1

And so a neighborhood resembling

For further explanation, see:

wikipedia.org/wiki/Elementary_cellular_automaton#The_numbering_system

**Note:**The system is periodic, or wrapped around, meaning that for the

`pattern`[ . . @ . @ ], the neighborhood for the 1st cell is [ @ . . ], the 2nd is [ . . @ ], the 3rd is [ . @ . ], the 4th is [ @ . @ ], and the neighborhood for the last cell is [ . @ . ].

Input

**Line 1:**A rule

`R`provided as a Wolfram code.

**Line 2:**The number

`N`of lines to output.

**Line 3:**The starting

`pattern`to evolve.

Output

**The evolution of the starting**

`N`lines:`pattern`. The first line must be the starting pattern, itself, and the next

`N`-1 lines represent the subsequent evolutions from the starting pattern.

Constraints

0 ≤

10 ≤

`R`≤ 25510 ≤

`pattern`.length ≤ 50Example

Input

254 5 .....@.....

Output

.....@..... ....@@@.... ...@@@@@... ..@@@@@@@.. .@@@@@@@@@.

A higher resolution is required to access the IDE

Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!

JOIN US ON DISCORD Online Participants