Reberland Linguistics

CodeForces - 666A

First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other.

For example, you should know linguistics very well. You learn a structure of Reberland language as foreign language. In this language words are constructed according to the following rules. First you need to choose the "root" of the word — some string which has more than 4 letters. Then several strings with the length 2 or 3 symbols are appended to this word. The only restriction — it is not allowed to append the same string twice in a row. All these strings are considered to be suffixes of the word (this time we use word "suffix" to describe a morpheme but not the few last characters of the string as you may used to).

Here is one exercise that you have found in your task list. You are given the word s. Find all distinct strings with the length 2 or 3, which can be suffixes of this word according to the word constructing rules in Reberland language.

Two strings are considered distinct if they have different length or there is a position in which corresponding characters do not match.

Let's look at the example: the word abacabaca is given. This word can be obtained in the following ways: , where the root of the word is overlined, and suffixes are marked by "corners". Thus, the set of possible suffixes for this word is {aca, ba, ca}.

Input

The only line contains a string s (5 ≤ |s| ≤ 104) consisting of lowercase English letters.

Output

On the first line print integer k — a number of distinct possible suffixes. On the next k lines print suffixes.

Print suffixes in lexicographical (alphabetical) order.

Examples

Input
abacabaca
Output
3
aca
ba
ca
Input
abaca
Output
0

Note

The first test was analysed in the problem statement.

In the second example the length of the string equals 5. The length of the root equals 5, so no string can be used as a suffix.

sol:像个dp一样,略微有点阿八。需要熟练掌握字符串的STL

从后往前推,每次判断一段区间是否会有重复,然后向前转移

/*
题目大意:一个单词由长度不少于5的词根和长度为2或3的若干个后缀组成,
并且两个相邻的后缀不能一样,给定一个单词,问这个单词总共可以有多少个后缀
*/
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n;
string S;
bool dp[N];
set<string>Ans;
set<string>::iterator it;
int main()
{
int i;
string t;
cin>>S; n=S.size();
if(n<=) return puts(""),;
dp[n]=;
for(i=n-;i>=;i--)
{
if(dp[i+])
{
t=S.substr(i,);
if(Ans.find(t)==Ans.end()||dp[i+]) {Ans.insert(t); dp[i]=;}
}
if((i!=n-)&&dp[i+])
{
t=S.substr(i,);
if(Ans.find(t)==Ans.end()||dp[i+]) {Ans.insert(t); dp[i]=;}
}
}
Wl((int)(Ans.size()));
for(it=Ans.begin();it!=Ans.end();++it)
{
cout<<*it<<endl;
}
return ;
}
/*
Input
abacabaca
Output
3
aca
ba
ca Input
abaca
Output
0
*/

codeforces666A的更多相关文章

随机推荐

  1. X86逆向13:向程序中插入Dll

    本章我们将学习Dll的注入技巧,我们将把一个动态链接库永久的插入到目标程序中,让程序在运行后直接执行这个Dll文件,这一章的内容也可以看作是第八课的加强篇,第八课中我们向程序中插入了一个弹窗,有木有发 ...

  2. Java反射的理解(六)-- 通过反射了解集合泛型的本质

    Java反射的理解(六)-- 通过反射了解集合泛型的本质 上述写了那么多,我们可能会有个疑问,为什么要用反射,步骤比我们常规的加载类操作复杂多了,别急,这个问题我最后才解答,我们先来了解集合泛型的本质 ...

  3. qt 静态编译配置项

    configure -confirm-license -opensource -platform win32-msvc2013 -debug-and-release -static -prefix & ...

  4. aspose导出数据

    注意 aspose合并单元格后设置单元格样式要一格一格的设置 public class InvoiceAsposeExcel { /// <summary> /// 导出数据 /// &l ...

  5. JS基础_break和continue

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. ZROIDay4-比赛解题报告

    ZROIDay4-比赛解题报告 扯闲话 感觉这个出题人的题做起来全都没感觉啊,今天又凉了,T1完全不知道什么意思,T2只会暴力,T3现在还不懂什么意思,真的太菜了 A 题意半天没搞懂爆零GG了,讲了一 ...

  7. mysq练习

    表名和字段 –1.学生表Student(s_id,s_name,s_birth,s_sex) --学生编号,学生姓名, 出生年月,学生性别–2.课程表Course(c_id,c_name,t_id) ...

  8. 02 Go程序执行流程

    一.把源码编译成二进制后执行 .go代码源文件 => go build => 可执行文件(.exe文件或者linux二进制文件) => 运行结果 二.对源码直接运行 .go源代码文件 ...

  9. c语言测试芯片好坏

    问题描述有n个(2<n<20)芯片,好的或坏的,并且有比坏的芯片更多的已知的好的芯片.每个芯片都可以用来测试其他芯片.当用一个好的芯片测试其他芯片时,它可以正确地给出被测芯片是好是坏.当用 ...

  10. SocketClient

    import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.i ...