A prefix code assigns to every character of an alphabet a distinct binary string called its code word. The code words satisfy two rules:
010010 is the code word of a letter, then none of 0, 01, 010, 0100, 01001, nor any string that begins with 010010, is the code word of another letter.0 or a 1 appended) is again a prefix of some code word or a complete code word. For example, if 0100 is a prefix of some code word, then 01000 and 01001 are each a prefix of some code word or a complete code word.Equivalently, the code words are the leaves of a full binary tree in which every internal node has exactly two children.
Here is an example prefix code over the alphabet {A, B, C, D, E}:
| character | code word |
|---|---|
| A | 00 |
| B | 10 |
| C | 11 |
| D | 010 |
| E | 011 |
A message is encoded by concatenating the code words of its characters in order. For example, BACAEBABAE encodes to 1000110001110001000011.
If some leading bits of an encoded message are lost, the message may be decoded incorrectly, or not decoded at all. For example, dropping the first five bits above leaves 10001110001000011, which decodes as BACBABAE: the last five letters (BABAE) are correct, but the first three (BAC) are not. Notice that every letter after the first E is decoded correctly. In fact, once every bit of the code word of E has been read intact, all following characters are decoded correctly, no matter which leading bits were lost. The code word of D shares this property, but those of A, B, and C do not.
A code word with this property is called synchronizing: if the decoder reads it in full and correctly, then, regardless of any lost leading bits, every character after it is decoded correctly. Your task is to find all synchronizing code words of a given prefix code.
The code words are presented on a device with four buttons:
0 - append the bit 0 to the display.1 - append the bit 1 to the display.B - backspace: delete the last bit shown on the display.X - beep: signals that the display currently shows a complete code word.The display starts empty. Each code word is entered by pressing buttons until it appears on the display, and then pressing X. Code words are numbered 1,2,3,… in the order in which their X presses occur. After the last code word, the display is cleared with as many B presses as needed.
The first line contains an integer n (6≤n≤3000000): the number of button presses. The second line is a string of n characters over 0, 1, B, and X describing the presses in order. Each X completes one code word, and code words are numbered starting from 1. The total length of all code words does not exceed 108.
On the first line print the number k of synchronizing code words. Then print the numbers of the synchronizing code words in increasing order, one per line. If there are no synchronizing code words, print a single line containing 0.
In the example input the buttons enter five code words in order: 11, 10, 00, 011, and 010. Among them, 011 (code word 4) and 010 (code word 5) are synchronizing, so the answer lists 4 and 5.