Problem:
Score : 600 points

Problem Statement

Takahashi is playing a board game called Sugoroku.

On the board, there are N + 1 squares numbered 0 to N. Takahashi starts at Square 0, and he has to stop exactly at Square N to win the game.

The game uses a roulette with the M numbers from 1 to M. In each turn, Takahashi spins the roulette. If the number x comes up when he is at Square s, he moves to Square s+x. If this makes him go beyond Square N, he loses the game.

Additionally, some of the squares are Game Over Squares. He also loses the game if he stops at one of those squares. You are given a string S of length N + 1, representing which squares are Game Over Squares. For each i (0 \leq i \leq N), Square i is a Game Over Square if S[i] = 1 and not if S[i] = 0.

Find the sequence of numbers coming up in the roulette in which Takahashi can win the game in the fewest number of turns possible. If there are multiple such sequences, find the lexicographically smallest such sequence. If Takahashi cannot win the game, print -1.

Constraints

1 \leq N \leq 10^5

1 \leq M \leq 10^5

|S| = N + 1

S consists of 0 and 1.

S[0] = 0

S[N] = 0

Input

Input is given from Standard Input in the following format:

N M
S

Output

If Takahashi can win the game, print the lexicographically smallest sequence among the shortest sequences of numbers coming up in the roulette in which Takahashi can win the game, with spaces in between.

If Takahashi cannot win the game, print -1.

Sample Input 1

9 3
0001000100

Sample Output 1

1 3 2 3

If the numbers 1, 3, 2, 3 come up in this order, Takahashi can reach Square 9 via Square 1, 4, and 6. He cannot reach Square 9 in three or fewer turns, and this is the lexicographically smallest sequence in which he reaches Square 9 in four turns.

Sample Input 2

5 4
011110

Sample Output 2

-1

Takahashi cannot reach Square 5.

Sample Input 3

6 6
0101010

Sample Output 3

6

Solution in Fortran (gfortran v4.8.4) (judge verdict: Wrong Answer)

module mod_segment_tree
  implicit none
  type t_segment_tree
    private
    integer :: deflt = 1000000000
    integer :: n, p
    integer, pointer :: arr(:) => null()
  contains
    procedure :: init => init_segtree
    procedure :: release => release_segtree
    procedure :: update => update
    procedure :: query => query
    procedure :: default => set_default
    procedure :: change => change_default
  end type
  interface segment_tree
    module procedure :: newst
  end interface segment_tree
contains
  integer function op(x,y)
    integer, intent(in) :: x, y
    op = min(x,y)
  end
  function newst(n) result(ret)
    integer, intent(in) :: n
    type(t_segment_tree) :: ret
    integer :: p
    p = 1
    do while (p < n)
      p = 2*p
    end do
    ret%n = n
    ret%p = p
    allocate(ret%arr(2*p-1))
    ret%arr = ret%deflt
  end
  subroutine init_segtree(this,n)
    class(t_segment_tree), intent(inout) :: this
    integer, intent(in) :: n
    integer :: p
    p = 1
    do while (p < n)
      p = 2*p
    end do
    this%n = n
    this%p = p
    allocate(this%arr(2*p-1))
    this%arr = this%deflt
  end
  subroutine release_segtree(this)
    class(t_segment_tree), intent(inout) :: this
    if (associated(this%arr)) deallocate(this%arr)
  end
  subroutine set_default(this,i)
    class(t_segment_tree), intent(inout) :: this
    integer, intent(in) :: i
    integer :: x
    x = i+this%p-1
    this%arr(x) = this%deflt
    do while (x > 1)
      x = x/2
      this%arr(x) = op(this%arr(2*x),this%arr(2*x+1))
    end do
  end
  subroutine change_default(this,deflt)
    class(t_segment_tree), intent(inout) :: this
    integer, intent(in) :: deflt
    this%deflt = deflt
  end
  subroutine update(this,i,v)
    class(t_segment_tree), intent(inout) :: this
    integer, intent(in) :: i
    integer, intent(in) :: v
    integer :: x
    x = i+this%p-1
    this%arr(x) = v
    do while (x > 1)
      x = x/2
      this%arr(x) = op(this%arr(2*x),this%arr(2*x+1))
    end do
  end
  integer function query(this,a,b)
    class(t_segment_tree), intent(inout) :: this
    integer, intent(in) :: a, b
    integer :: l, r
    query = this%deflt
    l = a+this%p-1
    r = b+this%p-1
    do while (l <= r)
      if (mod(l,2) == 1) then
        query = op(query,this%arr(l))
        l = l+1
      end if
      if (mod(r,2) == 0) then
        query = op(query,this%arr(r))
        r = r-1
      end if
      l = l/2
      r = r/2
    end do
  end
end module mod_segment_tree
program Sugoroku
  use mod_segment_tree
  implicit none
  integer :: n, m, i, x, y, a(0:100001) = 0
  character(100001) :: s
  type(t_segment_tree) :: st
  read(*,*) n, m
  if (n <= m) then
    write(*,'(i0)') n
    stop
  end if
  read(*,*) s
  st = segment_tree(n+1)
  call st%update(1,0)
  do i = 2, n+1
    if (s(i:i) == "1") cycle
    x = st%query(max(1,i-m),i-1)
    if (x > n) then
      write(*,'(i0)') -1
      stop
    end if
    call st%update(i,x+1)
  end do
  y = st%query(n+1,n+1)
  a(y) = n+1
  do i = n+1, 1, -1
    if (s(i:i) == "1") cycle
    x = st%query(i,i)
    if (x == y) cycle
    a(x) = max(i,a(x+1)-m)
  end do
  write(*,'(i0)',advance='no') a(1)-a(0)
  do i = 1, y-1
    write(*,'(x,i0)',advance='no') a(i+1)-a(i)
  end do
  write(*,*)
end program Sugoroku