Smallest Word

IA has so many colorful magnets on her fridge! Exactly one letter is written on each magnet, 'a' or 'b'. She loves to play with them, placing all magnets in a row. However, the girl is quickly bored and usually thinks how to make her entertainment more interesting.

Today, when IA looked at the fridge, she noticed that the word formed by magnets is really messy. "It would look much better when I'll swap some of them!" — thought the girl — "but how to do it?". After a while, she got an idea. IA will look at all prefixes with lengths from 11 to the length of the word and for each prefix she will either reverse this prefix or leave it as it is. She will consider the prefixes in the fixed order: from the shortest to the largest. She wants to get the lexicographically smallest possible word after she considers all prefixes. Can you help her, telling which prefixes should be chosen for reversing?

A string aa is lexicographically smaller than a string bb if and only if one of the following holds:

  • aa is a prefix of bb, but a≠ba≠b;
  • in the first position where aa and bb differ, the string aa has a letter that appears earlier in the alphabet than the corresponding letter in bb.

Input

The first and the only line contains a string ss (1≤|s|≤10001≤|s|≤1000), describing the initial string formed by magnets. The string ss consists only of characters 'a' and 'b'.

Output

Output exactly |s||s| integers. If IA should reverse the ii-th prefix (that is, the substring from 11 to ii), the ii-th integer should be equal to 11, and it should be equal to 00 otherwise.

If there are multiple possible sequences leading to the optimal answer, print any of them.

Examples

Input

bbab

Output

0 1 1 0

Input

aaaaa

Output

1 0 0 0 1

Note

In the first example, IA can reverse the second and the third prefix and get a string "abbb". She cannot get better result, since it is also lexicographically smallest string obtainable by permuting characters of the initial string.

In the second example, she can reverse any subset of prefixes — all letters are 'a'.

题意:

只有a,b组成的一个字符串,将一个位置(包括当前位置)前面的子字符串翻转,最后结果为最小的字典序排列,翻转的位置输出为1,否则为0。

分析:每次翻转必为出现与前一个字符不同的的位置,遍历一遍,使相同的字母在一起。最后在判断最后一个字母是否为b,若是a在翻转一次。

代码:

#include<iostream>
using namespace std;
int a[10008];
int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.length()-1;i++)
    {
        if(s[i]!=s[i+1]) a[i]=1;
    }
    if(s[s.length()-1]=='a') a[s.length()-1]=1;
    for(int i=0;i<s.length();i++)
    {
        if(a[i]==1) cout<<"1 ";
        else cout<<"0 ";
    }
    cout<<endl;
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不会敲代码的小帅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值