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;
}

【16.67%】【codeforces 667C】Reberland Linguistics的更多相关文章

  1. codeforces 667C C. Reberland Linguistics(dp)

    题目链接: C. Reberland Linguistics time limit per test 1 second memory limit per test 256 megabytes inpu ...

  2. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  3. 【24.67%】【codeforces 551C】 GukiZ hates Boxes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【16.23%】【codeforces 586C】Gennady the Dentist

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【26.67%】【codeforces 596C】Wilbur and Points

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【codeforces 807D】Dynamic Problem Scoring

    [题目链接]:http://codeforces.com/contest/807/problem/D [题意] 给出n个人的比赛信息; 5道题 每道题,或是没被解决->用-1表示; 或者给出解题 ...

  7. 【codeforces 67A】Partial Teacher

    [题目链接]:http://codeforces.com/problemset/problem/67/A [题意] 给一个长度为n-1的字符串; 每个字符串是'L','R','='这3种字符中的一个; ...

  8. 【codeforces 821E】Okabe and El Psy Kongroo

    [题目链接]:http://codeforces.com/problemset/problem/821/E [题意] 一开始位于(0,0)的位置; 然后你每次可以往右上,右,右下3走一步; (x+1, ...

  9. 【81.82%】【codeforces 740B】Alyona and flowers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. C# exe文件 添加到windows 服务

    我们运行.net的发布工具installutil.exe来添加到windows服务里面(该工具默认在C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727目录下) ...

  2. 国密算法SM2证书制作

    国密算法sm2非对称算法椭圆曲线 原文:http://www.jonllen.cn/jonllen/work/162.aspx 前段时间将系统的RSA算法全部升级为SM2国密算法,密码机和UKey硬件 ...

  3. 【CS Round #48 (Div. 2 only)】Dominant Free Sets

    [链接]h在这里写链接 [题意] 让你在n个点组成的集合里面选取不为空的集合s. 使得这里面的点没有出现某个点a和b,ax>=bx且ay>=by; 问你s的个数. [题解] 我们把这些点按 ...

  4. dataTable() 与 DataTable() 的差别与处理方式

    jQuery dataTable的初始化有两种方式: var dataTable = $('#example').dataTable(); 与 var DataTable = $('#example' ...

  5. (转)ipv4的网段表示方法

    简单一点举例说明:ip段:10.0.0.1-10.0.0.255            的表示方法:10.0.0.0/24ip段:10.0.0.1-10.0.255.255        的表示方法: ...

  6. 9.6 Binder系统_驱动情景分析_server的多线程实现

    当多个client对server发出请求的时候,如果server忙不过来的时候会创建多线程来处理请求 那么忙不过来由谁来判断? server进程有个binder_proc结构体,其里面有todo链表( ...

  7. Eclipse高效开发插件汇总

    以下是我整理的自己开发过程中的常用Eclipse插件,按字母排序: (1)    AmaterasUML         介绍:Eclipse的UML插件,支持UML活动图,class图,sequen ...

  8. Android(Lollipop/5.0) Material Design(四) 创建列表和卡片

    Material Design系列 Android(Lollipop/5.0)Material Design(一) 简单介绍 Android(Lollipop/5.0)Material Design( ...

  9. 手动脱KBys Packer(0.28)壳实战

    作者:Fly2015 吾爱破解培训第一课选修作业第5个练习程序.在公司的时候用郁金香OD调试该加壳程序的时候出了点问题,可是回家用吾爱破解版的OD一调试,浑身精神爽,啥问题也没有. 首先使用查壳工具对 ...

  10. Spring+Netty+WebSocket实例

    比较贴近生产,详见注释 一.pom.xml 具体太长,详见源码 </dependency> <dependency> <groupId>io.netty</g ...