Under construction

Still being built. Things may change

Key Knocking

Time limit1sMemory limit512 MB

Summary
Given a binary string of length 3n, greedily pick operations in each 3-bit block to reach a weight of at least 2n within n moves.
Level

Medium5 of 10

Topics
Greedy, Implementation, Array
Solved
No attempts yet

Problem

Goran is recovering from knee surgery and spends the time experimenting with a smart card that stores cryptographic keys. In this problem a key is a bitstring of length 3n3n, where nn is a positive integer. The bits of the key are numbered from 11 to 3n3n, left to right. The weight of a key is the number of pairs of neighbouring bits that hold different values, plus 11. For example, the weight of the key "000" is 11, and the weight of the key "011010100" is 77.

Goran found out that he can tamper with the key by sending small jolts of electricity through the circuits of the smart card. To be precise, he can reliably perform the following operation as often as he wants. Pick any two neighbouring bits of the key and flip both of them. For example, one operation can change the key "000" into "110".

You are given a key of length 3n3n. Find a way to turn it into a key of weight at least 2n2n using at most nn operations. A solution always exists.

Input

The first line contains a string of the characters "0" and "1". This string is the initial key. The length of the key is 3n3n, where nn is an integer with 1≤n≤1000001 \le n \le 100000.

Output

On the first line print the number of operations mm. If m>0m > 0, print on the second line the mm indices in the order the operations are performed, separated by single spaces. The kk-th number aka_k is the number of the left bit of the pair flipped in step kk. If m=0m = 0, print only the first line.

Many operation sequences meet the weight requirement, so this problem accepts exactly the one sequence produced by the following rule.

Cut the key into nn blocks of three bits from the left. Block kk covers the positions a=3k−2a = 3k-2, b=3k−1b = 3k-1 and c=3kc = 3k. Process the blocks in order from k=1k = 1 to k=nk = n, and in each block read the current key, which earlier operations may already have changed.

In a block with k<nk < n, look at the three pairs (a,b)(a, b), (b,c)(b, c) and (c,c+1)(c, c+1). Try the following three actions in the written order and take the first one that leaves at least two of the three pairs holding different bits: do nothing, operate at index bb, operate at index cc.

In the last block, k=nk = n, look only at the pairs (a,b)(a, b) and (b,c)(b, c). If at least one of them already holds different bits, do nothing, otherwise operate at index bb.

This rule never uses more than nn operations, and it always reaches weight at least 2n2n.

Examples3

  1. Example 1

    Input
    000000000
    
    Expected output
    3
    2 5 8
  2. Example 2

    Input
    111001000111
    
    Expected output
    2
    3 9
  3. Example 3

    Input
    010101
    
    Expected output
    0