Our world has been invaded by shape shifting aliens that kidnap people and steal their identities.You are an inspector from a task force dedicated to detect and capture them. As such, you were given special tools to detect aliens and differentiate them 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 whose are aliens and whose aren’t, 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 are monitoring 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 the Headquarters.With the aim of minimizing 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’re 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 ≤ 10^4),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’s guaranteed that there exists at least one solution such that the absolute value of each coefficient is less than 2^63.

样例输入1复制

HHH

样例输出1复制

0
1

样例输入2复制

AHHA

样例输出2复制

2
-1 10 -21

样例输入3复制

AHHHAH

样例输出3复制

3
1 -23 159 -297

题意:

给一个由“H”和“A”组成的字符串,H代表人类,A代表外星人,构造一个一元 n 多次方程,使得每个字母 H 对应的下标的2倍对应的因变量 > 0,A对应的因变量 < 0

思路:

给出了若干方程的解,将其转化为一般式。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e4 + 3;

ll a[N], b[N];///b[i]: (i - 1)次方的系数

int main()
{
    string s;
    while(cin >> s)
    {
        int len = s.size();
        s = "#" + s;
        int tot = 0;
        for(int i = 1;  i < len; ++i)///根
        {
            if(s[i] != s[i + 1])
            {
                a[++tot] = 2 * i + 1;
            }
        }
        b[1] = 1;
        for(int i = 1; i <= tot; ++i)
        {
            for(int j = i + 1; j >= 1; --j)
            {
                b[j] = b[j - 1];
            }
            for(int j = 1; j <= i + 1; ++j)
            {
                b[j - 1] -= a[i] * b[j];
            }
        }
        int flag = 1;
        if(s[1] == 'H' && tot % 2)
            flag = -1;
        if(s[1] == 'A' && tot % 2 == 0)
            flag = -1;
        cout<<tot<<'\n';
        for(int i = tot + 1; i >= 1; --i)
        {
            cout<<b[i] * flag;
            if(i > 1)
                cout<<' ';
        }
        cout<<'\n';
    }
    return 0;
}
/*
HHH
AHHA
AHHHAH
*/