time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output

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.

【题解】



这题的限制是说连续的两个串不能是一样的。

如果中间隔了一个是允许的0 0

设can[i][2]和can[i][3]分别表示从I点能否截取长度为2、长度为3的连续串;

初始化can[len-1][2] = true,can[len-2][3] = true;

转移方式如下

            if (can[i+2][3] || (can[i+2][2] && s.substr(i,2)!=s.substr(i+2,2)))
{
can[i][2]=true;
·····
}
if (can[i+3][2] || (can[i+3][3] && s.substr(i,3)!=s.substr(i+3,3)))
{
can[i][3]=true;
.....
}
//每次截取到一串就加入到vector中。最后把vector用sort排下序;
//顺序输出就好;
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
#define LL long long using namespace std; const int MAXN = 1e4+10; string s;
vector <string> a;
map <string,int> dic;
bool can[MAXN][5] = {0}; void input_LL(LL &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)) t = getchar();
LL sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} void input_int(int &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)) t = getchar();
int sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
cin>>s;
int len = s.size();
string temp;
for (int i = len-2;i>=5;i--)
{
if (i+1==len-1)
{
can[i][2] = true;
temp = s.substr(i,2);
if (!dic[temp])
{
dic[temp] = 1;
a.push_back(temp);
}
continue;
}
if (i+2==len-1)
{
can[i][3] = true;
temp = s.substr(i,3);
if (!dic[temp])
{
dic[temp] = 1;
a.push_back(temp);
}
continue;
}
if (can[i+2][3] || (can[i+2][2] && s.substr(i,2)!=s.substr(i+2,2)))
{
temp = s.substr(i,2);
can[i][2]=true;
if (!dic[temp])
{
dic[temp] = 1;
a.push_back(temp);
}
}
if (can[i+3][2] || (can[i+3][3] && s.substr(i,3)!=s.substr(i+3,3)))
{
temp = s.substr(i,3);
can[i][3]=true;
if (!dic[temp])
{
dic[temp] = 1;
a.push_back(temp);
}
}
}
sort(a.begin(),a.end());
len = a.size();
printf("%d\n",len);
for (int i = 0;i <= len-1;i++)
puts(a[i].c_str());
return 0;
}

最新文章

  1. JavaSE高级之GUI编程
  2. IIS跳转html页面自动识别是PC端还是手机端
  3. 日志监控系统中,大批量查询mysql方案
  4. switch 与 python字典
  5. C#数组
  6. 火狐浏览器修改userAgent
  7. percona-toolkit介绍及安装
  8. git初识
  9. Browser GetImage
  10. php curl简单使用
  11. darknet集成遇到的问题以及解决方法
  12. eclipse软件仿真操作
  13. JAVA中的值传递和引用传递问题
  14. RN返回navigation方法
  15. 批处理taskkill运行结束不掉程序以及停留问题
  16. ImportError: cannot import name &#39;path&#39;
  17. 查找可用的谷歌IP地址
  18. Linux命令详解-cp
  19. bzoj 4034: [HAOI2015]树上操作——树链剖分
  20. loj #6136. 「2017 山东三轮集训 Day4」Left

热门文章

  1. 通达OA二次开发 对通达2015版微信查询用户信息模块升级开发(图文)
  2. hdu5389
  3. session的生命周期是怎样的
  4. 读文件头数据判断 PE 文件格式和类型
  5. 希捷硬盘扩容软件-----DiscWizard
  6. jQuery常用的API
  7. 【hdu5527】【2015ACM/ICPC亚洲区长春站 】Too Rich
  8. hprof教程 分类: B1_JAVA 2015-03-02 12:18 444人阅读 评论(0) 收藏
  9. error: { &quot;$err&quot; : &quot;not master and slaveOk=false&quot;, &quot;code&quot; : 13435 }
  10. 【53.57%】【codeforces 722D】Generating Sets