#P9851. Torch Puzzle in Tianqiu Valley

    ID: 22996 Type: Default 1000ms 256MiB

Torch Puzzle in Tianqiu Valley

Torch Puzzle in Tianqiu Valley

In the north tower of Tianqiu Valley's ruins, Lumine faces the final and most challenging flame torch puzzle. There are \(n\) torches arranged in a circle, and some are ignited initially. Two torches are adjacent if they are consecutive in the circle (with torch \(n\) adjacent to torch \(1\)).

In each move, Lumine can ignite an extinguished torch. When she ignites a torch at position \(i\) (which must be off), the two adjacent torches at positions \(i-1\) and \(i+1\) (using modular arithmetic so that positions wrap around) will have their statuses toggled; that is, a lit torch becomes extinguished and an extinguished one becomes lit. The goal is to have all torches lit. Lumine wants to solve the puzzle in at most \(2n\) moves, or determine that the puzzle is unsolvable.

Note: The torches are numbered from 1 to \(n\) in clockwise order, and a move can only be made on a torch that is currently extinguished.

inputFormat

The first line contains an integer \(n\) representing the number of torches.

The second line contains a binary string of length \(n\) where '1' indicates an ignited torch and '0' indicates an extinguished torch.

outputFormat

If it is possible to light all the torches in at most \(2n\) moves, output the number of moves \(k\) on the first line, followed by a line with \(k\) space-separated integers representing the indices (1-indexed) of the torches to ignite in order. Otherwise, output -1.

sample

3
000
1

1

</p>