D. Palindromic characteristics
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th number is the total number of non-empty substrings of s which are k-palindromes.

A string is 1-palindrome if and only if it reads the same backward as forward.

A string is k-palindrome (k > 1) if and only if:

  1. Its left half equals to its right half.
  2. Its left and right halfs are non-empty (k - 1)-palindromes.

The left half of string t is its prefix of length ⌊|t| / 2⌋, and right half — the suffix of the same length. ⌊|t| / 2⌋ denotes the length of string tdivided by 2, rounded down.

Note that each substring is counted as many times as it appears in the string. For example, in the string "aaa" the substring "a" appears 3 times.

Input

The first line contains the string s (1 ≤ |s| ≤ 5000) consisting of lowercase English letters.

Output

Print |s| integers — palindromic characteristics of string s.

Examples
input
abba
output
6 1 0 0 
input
abacaba
output
12 4 1 0 0 0 0 
Note

In the first example 1-palindromes are substring «a», «b», «b», «a», «bb», «abba», the substring «bb» is 2-palindrome. There are no 3- and 4-palindromes here.

题意:给你一个字串,让你分别统计k类回文字符串的个数。其中第一类是普通的回文字符串,即只要是回文字符串,他就一定是第一类,第二类回文字符串必须满足其左右两端是第一类回文字符串,后边的以此类推。。。。

题解:定义两个数组即可,a[i][j]:表示i到j能否组成回文字符串       b[i][j]:统计该区间能组成第几类回文字符串。然后就是无脑往两边搜索即可。

#include<map>      
#include<stack>      
#include<queue>    
#include<vector>      
#include<math.h>      
#include<stdio.h>    
#include<iostream>  
#include<string.h>      
#include<stdlib.h>      
#include<algorithm>      
using namespace std;      
typedef __int64 ll;      
#define inf 1000000000      
#define mod 1000000007     
#define maxn  5005  
#define lowbit(x) (x&-x)      
#define eps 1e-10    
char s[maxn];
int a[maxn][maxn],b[maxn][maxn],ans[maxn],len;
int sech(int l,int r)
{
	if(a[l][r]==0)
		return 0;
	if(b[l][r]==-1)
	{
		int len=(r-l+1)/2;
		b[l][r]=min(sech(l,l+len-1),sech(r-len+1,r))+1;
	}
	return b[l][r];
}
int  main(void)
{
	int i,j,k;
	scanf("%s",s);
	memset(b,-1,sizeof(b));
	len=strlen(s);
	for(i=0;i<len;i++)
	{
		for(j=i,k=i;j>=0 && k<len;j--,k++)
		{
			a[j][k]=(s[j]==s[k]);
			if(s[j]!=s[k])
				break;
		}
		if(i<len-1)
		{
			for(j=i,k=i+1;j>=0 && k<len;j--,k++)
			{
				a[j][k]=(s[j]==s[k]);
				if(s[j]!=s[k])
					break;
			}
		}
	}
	for(i=0;i<len;i++)
		for(j=i;j<len;j++)
			ans[sech(i,j)]++;
	for(i=len-1;i>0;i--)
		ans[i]+=ans[i+1];
	printf("%d",ans[1]);
	for(i=2;i<=len;i++)
		printf(" %d",ans[i]);
	printf("\n");
	return 0;
}