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. Neo4j图数据库配置文件详解

    For more details and a complete list of settings, please see https://neo4j.com/docs/operations-manua ...

  2. “007~ASP 0104~不允许操作”错误的解决方法(图解)

    今天测试一个Z-Blog程序的上传文件时发现总提示“ 007~ASP 0104~不允许操作 ”的错误,经过度度上各位朋友的帮忙,终于找到解决方法. 这是windows2003 server对上传文件的 ...

  3. 单元操作和仓储模式 repository+unitOfWork

    仓储和工作单元模式是用来在数据访问层和业务逻辑层之间创建一个抽象层.应用这些模式,可以帮助用来隔离你的程序在数据存储变化. 在数据源层和业务层之间增加一个repository层进行协调,有如下作用:1 ...

  4. 学习笔记--Tarjan算法之割点与桥

    前言 图论中联通性相关问题往往会牵扯到无向图的割点与桥或是下一篇博客会讲的强连通分量,强有力的\(Tarjan\)算法能在\(O(n)\)的时间找到割点与桥 定义 若您是第一次了解\(Tarjan\) ...

  5. 防止表单提交时刷新页面-阻止form表单的默认提交行为

    最近在写 ajax 提交的时候遇到一个问题,在执行 ajax 提交之后,浏览器页面自动刷新了,主要是没有 由于form 表单的默认提交行为.一下是几种阻止 form 表单默认提交行为的方式. 1.使用 ...

  6. Redis之淘汰策略

    Redis 内存数据集大小上升到一定大小的时候,就会进行数据淘汰策略. Redis 提供了 6 种数据淘汰策略: 1. volatile-lru:从已设置过期时间的数据集中挑选最近最少使用的数据淘汰. ...

  7. 宝塔控制面板+wordpress搭建个人网站

    上个月买了服务器和域名之后就搁置了,今天有空闲就来配合教程尝试一下搭建个人网站,下面是网站搭建的详细过程以及中间的一些细节问题,写这篇文章的目的就是希望能够帮到一些小伙伴,或者为以后搭建网站做一些参考 ...

  8. day10 mysql常用操作

    一. 目录 1.mysql的简介 2.增删改查操作 3.单表查询 4.多表查询常见的三种方式 5.pymysql模块操作数据库 二. 内容 一.mysql的简介  概述:mysql是一个关系型数据库, ...

  9. Go语言并发机制

    Go语言中的并发 使用goroutine编程 使用 go 关键字用来创建 goroutine .将go声明放到一个需调用的函数之前,在相同地址空间调用运行这个函数,这样该函数执行时便会作为一个独立的并 ...

  10. Flutter-动画-概念篇

    一.Flutter中的动画的基本概念图 二.Flutter各动画的概念 视图动画 补间动画 就是一个View,定义了起点和终点.时间以及运动曲线,并按照所定规则由起点运动到终点的过程. 帧动画 帧动画 ...