Know your Aliens

Interview

Time limit2sMemory limit512 MB

Summary
Given a human/alien label for each even number 2 to 2N, build the lowest-degree monic or anti-monic integer polynomial whose sign at 2i matches the label.
Level

Medium7 of 10

Topics
Math, Divide and conquer, Recursion, Sorting
Solved
No attempts yet

Problem

Our world has been invaded by shapeshifting aliens that kidnap people and steal their identities. You are an inspector from a task force dedicated to detecting and capturing them. To this end, you were given special tools to detect aliens and tell them apart from real humans. Your current mission is to visit a city that is suspected of have been invaded, secretly inspect every person there so as to know who is an alien and who is not, and report it all to Headquarters. Then they can send forces to the city by surprise and capture all the aliens at once.

The aliens are aware of the work of inspectors like you, and they monitor all radio channels to detect the transmission of such reports, in order to anticipate any retaliation. Therefore, there have been several efforts to encrypt the reports, and the most recent method uses polynomials.

The city you must visit has N citizens, each identified by a distinct even integer from 2 to 2N. You want to find a polynomial P such that, for every citizen i, P(i) > 0 if citizen i is a human, and P(i) < 0 otherwise. This polynomial will be transmitted to Headquarters. To minimize bandwidth, the polynomial has some additional requirements: each root and coefficient must be an integer, the coefficient of its highest degree term must be either 1 or −1, and its degree must be the lowest possible.

For each citizen, you know whether they are a human or not. Given this information, you must find a polynomial that satisfies the described constraints.

Input

The input consists of a single line that contains a string S of length N (1 ≤ N ≤ 104), where N is the population of the city. For i = 1, 2, . . . , N, the i-th character of S is either the uppercase letter “H” or the uppercase letter “A”, indicating respectively that citizen 2i is a human or an alien.

Output

The first line must contain an integer D indicating the degree of a polynomial that satisfies the described constraints. The second line must contain D + 1 integers representing the coefficients of the polynomial, in decreasing order of the corresponding terms. It is guaranteed that there exists at least one solution such that the absolute value of each coefficient is less than 263.

Examples3

  1. Example 1

    Input
    HHH
    
    Expected output
    0
    1
    
  2. Example 2

    Input
    AHHA
    
    Expected output
    2
    -1 10 -21
    
  3. Example 3

    Input
    AHHHAH
    
    Expected output
    3
    1 -23 159 -297