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. PBOC第八部分和第十一部分关于TYPEA总结(二)——传输协议(ISO14443-4)

    二.传输协议(ISO14443-4)(8,P50 11,P30) 1.选择应答请求(RATS) 使用RATS命令和PICC协商通讯的最大帧长度(FSD和FSC).帧等待时间(FWT)和启动帧保护时间( ...

  2. Vue用递归实现一个消除输入框表情符的自定义directive

    最近项目中有一个需求,所有的文本输入框需要过滤掉表情符号,但是觉得每次表单验证的时候去判断,有点麻烦.于是我想到了自定义一个指令,后续遇到需要删除表情符号的输入框,直接通过指令将表情符号删除就好了,方 ...

  3. 关于CPU的一些操作(CPU设置超频)

    常见的几种CPU模式: .ondemand:系统默认的超频模式,按需调节,内核提供的功能,不是很强大,但有效实现了动态频率调节,平时以低速方式运行,当系统负载提高时候自动提高频率.以这种模式运行不会因 ...

  4. hdu 1215 求约数和 唯一分解定理的基本运用

    http://acm.hdu.edu.cn/showproblem.php?pid=1215 题意:求解小于n的所有因子和 利用数论的唯一分解定理. 若n = p1^e1 * p2^e2 * ……*p ...

  5. webmagic学习之路-3:采集安居客经纪人详情页

    这里希望安居客的同行的轻喷!!单纯的做测试,玩玩. 就这么糟践你们的服务器了!!!sorry! 这次学会了webmagic 设置处理的访问HTML返回代码,因为之前一直404的页面process根本都 ...

  6. 动画方案 Lottie 学习(一)之基础

    参考 lottie系列文章(一):lottie介绍 lottie系列文章(二):lottie最佳实践 lottie系列文章(三):动画设计规范 lottie系列文章(四):源码分析——svg渲染

  7. luogu P1552 [APIO2012]派遣 题解--可并堆/贪心

    题目链接: https://www.luogu.org/problemnew/show/P1552 分析: 一开始愣是没看懂题,后面发现就是你要找一个树上点集使得各点权值之和小于\(M\),并且找一个 ...

  8. Facebook团队合影

    今晚公司年会,晚上有些人不去,我晚上要带孩子,也不去,大家就说那我们中午照个合照吧.没啥子准备,大家都一副油腻的样子.除了要去party的化了妆.

  9. aipai服务架构

    概述 业务服务器30+ 1.根据业务不同,有四个主入口,负责负载均衡. 2.主要是业务分离,防止宕机影响所有业务. 3.nginx反向代理,保证每个业务至少有两个服务. redis集群12台 主要使用 ...

  10. (九)How to use the audio gadget driver

    Contents [hide]  1 Introduction 2 Audio Gadget Driver 1.0 2.1 Enabling the audio gadget driver 2.2 U ...