Under construction

Still being built. Things may change

Take-out

Time limit1sMemory limit128 MB

Summary
A white block is 'b' and a black block is 'c'. Scan a row of blocks with a stack; whenever the top k+1 blocks hold k white and one black, pop and record them, then print the recorded groups in reverse order.
Level

Medium5 of 10

Topics
Stack, Simulation, Greedy
Solved
No attempts yet

Problem

Little Edna received the take-out game as a present. Take-out is a single-player game. The player is given a row of nn blocks placed side by side and numbered 11 to nn from left to right. Each block is either white or black, and the number of white blocks is exactly kk times the number of black blocks.

The goal is to remove every block using permissible moves.

A single move removes exactly kk white blocks together with one black block, without moving any of the other blocks. Call a gap the empty space left by a block that was removed in an earlier move. A move is permissible when, listing the k+1k+1 blocks it removes from left to right, no gap sits between two consecutive removed blocks. Blocks that are still present may sit between the removed blocks; only gaps created by earlier moves are forbidden.

Every input can be cleared completely, so such a sequence of moves always exists.

Input

The first line contains two integers nn and kk (2≤n≤1,000,0002 \le n \le 1{,}000{,}000, 1≤k≤n−11 \le k \le n-1) separated by a single space: the number of blocks, and the number of white blocks removed together with one black block in each move. In every test case k+1k+1 divides nn.

The second line is a string of nn characters. Each character is b for a white block or c for a black block, giving the colors of the blocks from left to right.

Output

Print nk+1\frac{n}{k+1} lines, one per move. Each line lists the k+1k+1 block indices removed in that move, in increasing order, separated by single spaces.

Many valid sequences can exist, so print the specific one built by the following canonical procedure, which always produces a valid answer:

  1. Scan the blocks from left to right, pushing each one onto a stack.
  2. After every push, while the top k+1k+1 blocks on the stack contain exactly one black block (hence kk white blocks), pop those k+1k+1 blocks as one group and place the group at the front of the answer list. Re-check the new top before pushing the next block.
  3. Once the last block has been pushed the stack is empty and exactly nk+1\frac{n}{k+1} groups have been formed.

Print the groups in that order, so the group formed last is printed first. Within a line the indices are in increasing order.

Note

A gap is the empty space left where a block was taken out. For the first sample input, performing its moves in order transforms the row of blocks step by step, as illustrated below.

Examples2

  1. Example 1

    Input
    12 2
    ccbcbbbbbbcb
    
    Expected output
    10 11 12 
    1 8 9 
    2 6 7 
    3 4 5 
    
  2. Example 2

    Input
    2 1
    cb
    
    Expected output
    1 2