Under construction

Still being built. Things may change

Fox Chef

Time limit1sMemory limit1024 MB

Summary
Given a row of O and X cookies, find the fewest flips of at least K consecutive cookies that make all cookies show the same side, and list those flips.
Level

Medium6 of 10

Topics
Dynamic programming, Prefix sum, Greedy
Solved
No attempts yet

Problem

Foxes in the fox village also care about owning a home. A baby fox recently succeeded in living on its own, so its friends gathered at the baby fox's house to celebrate.

The baby fox decided to be a chef for a day and serve its grateful friends.

As an appetizer, the baby fox plans to arrange NN cookies decorated with foxes in a single row on a long plate. While setting the plate on the table, however, some cookies flipped over. If guests arrive like this, they may think the baby fox prepared the food carelessly.

The baby fox wants to flip the cookies back using tongs. Consecutive cookies can be flipped in one use. Because the cookies are small compared to the tongs, each use must flip at least KK consecutive cookies. The goal is to give the guests a neat impression, so it does not matter whether the cookies all face up or all face down, as long as they all show the same side.

The guests will arrive soon, and the baby fox has many other dishes to prepare. Determine whether all cookies can be made to show the same side using the tongs. If it is possible, find the minimum number of uses and how to use the tongs.

Input

The first line contains two positive integers NN and KK, separated by a space. (1≤K≤N≤500 0001\le K\le N\le 500\,000)

The second line contains a string of length NN consisting only of O and X. The ii-th character is O if the ii-th cookie lies face up, and X if it lies face down.

Output

If it is impossible to make all cookies show the same side no matter how the tongs are used, print -1 on the first line.

If it is possible, print the minimum number of tong uses MM (M≥0M\ge 0) on the first line. Then print the MM uses, one per line, in order. To flip the cookies from the ii-th to the jj-th, print ii and jj separated by a space. (1≤i≤j≤N1\le i\le j\le N; j−i≥K−1j-i\ge K-1)

Hint

You cannot move the cookies with the tongs. You can only change the face of each cookie in place.

Examples3

  1. Example 1

    Input
    10 3
    OXXXOXOXOO
    
    Expected output
    3
    2 6
    5 7
    6 8
    
  2. Example 2

    Input
    9 6
    XXXXXOOOO
    
    Expected output
    -1
    
  3. Example 3

    Input
    7 7
    XXXXXXX
    
    Expected output
    0