Under construction

Still being built. Things may change

Circle of Life

Time limit2sMemory limit512 MB

Summary
A circular binary strip updates so each cell is alive next generation only if exactly one neighbor is alive; find the state after T generations, with T up to 10^15.
Level

Medium7 of 10

Topics
Bit manipulation, Math, Simulation, Implementation
Solved
No attempts yet

Problem

Conway's Game of Life applies a handful of rules to cells on a grid and still produces very complicated configurations. This problem uses a version of that game simplified down to a one dimensional circular strip.

There is a circular strip of NN cells. The cells are numbered from 1 to NN in order: cell 1 and cell 2 are adjacent, cell 2 and cell 3 are adjacent, and so on up to cell N−1N-1, which is adjacent to cell NN. Since the strip is circular, cell 1 is also adjacent to cell NN.

Each cell is either alive or dead. An alive cell is written as the character '1' and a dead cell as the character '0'. When a generation passes, every cell changes state at the same time. If exactly one of a cell's two neighbours is alive in the current generation, then the cell is alive in the next generation. Otherwise the cell is dead in the next generation.

Given the initial state of the strip, find the state after TT generations.

Input

The first line contains two integers NN and TT separated by a space (3≤N≤1000003 \le N \le 100000, 1≤T≤10151 \le T \le 10^{15}).

The second line contains a string of exactly NN characters describing the initial state. Each character is either '0' or '1', and the ii-th character is the initial state of cell ii. The character '1' means an alive cell and '0' means a dead cell.

Output

Print the state of the NN cells after TT generations on one line, in the same format and order as the input. That is, print a string of NN characters whose ii-th character is '1' if cell ii is alive and '0' if it is dead.

Examples2

  1. Example 1

    Input
    7 1
    0000001
    
    Expected output
    1000010
    
  2. Example 2

    Input
    5 3
    01011
    
    Expected output
    10100