Codeforces Round #349 (Div. 2) C. Reberland Linguistics Dp+set

Source: Internet
Author: User

C. Reberland Linguistics

First-rate specialists graduate from Berland State Institute of peace and friendship. You is one of the most talented students in this university. The education is isn't easy because your need to has fundamental knowledge in different areas, which sometimes was not relat Ed to all other.

For example, should know linguistics very well. You learn a structure of Reberland language as foreign language. In this language words is constructed according to the following rules. First you need to choose the "root" of the Word-some string which have more Than 4 lette Rs. Then several strings with the Length 2 or 3  Symbols is appended to this word. The only Restriction- it are not allowed to append the same of string twice in a row. All these strings is considered to being suffixes of the word (this time we use word "suffix" to describe a morpheme and not The few last characters of the string as you are used to).

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

Strings is considered distinct if they has different length or there is a position in which corresponding characters does not match.

Let's look at the example:the word abacabaca is given. This word can being obtained in the following ways:, where the root of the word was overlined, and suffixes is marked by "Co Rners ". 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 中文版 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
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.

Test instructions

  

Give you a string of strings that will be followed by 5 (as long as after 5) the second half is divided into a continuous suffix of only three or two letters

Suffix: The same can be spaced to meet the same discontinuity;

All suffixes that satisfy the criteria are put into the collection, output in dictionary order

Exercises

  

#include <bits/stdc++.h>using namespacestd;Const intN = 1e4+ -, M = 1e6+Ten, mod = 1e9+7, INF = 1e9+ +; typedefLong Longll;CharA[n];Set<string>s;intf[n][5];//I start to L is feasibleintMain () {scanf ("%s", a); intn =strlen (a); A[n]='0'; A[n+1] ='0'; A[n+2] ='0'; if(n<=6) {cout<<0<<Endl; return  0; }    if(n2>=5) {        stringtmp; TMP= tmp + a[n-2]+ a[n-1];        S.insert (TMP); F[n-2][2] =1; }     if(n3>=5) {        stringtmp; TMP= tmp + a[n-3]+ a[n-2]+ a[n-1];        S.insert (TMP); F[n-3][3] =1; }     for(inti=n-4; i>=5; i--) {        stringS1 ="", S2 =""; S1= S1 + a[i] + a[i+1]; S2= s2 + a[i+2] + a[i+3]; if((s1!=s2&&f[i+2][2])|| f[i+2][3]) {f[i][2] =1; S.insert (S1);//cout<<s1<<endl;        }        if(i+2<N) {s1="", S2 =""; S1= S1 + a[i] + a[i+1] + a[i+2]; S2= s2 + a[i+3] + a[i+4] + a[i+5]; if((s1!=s2&&f[i+3][3])|| f[i+3][2]) {f[i][3] =1;                S.insert (S1); //cout<<s1<<endl;} }} cout<<s.size () <<Endl;  for(Set<string>:: Iterator It=s.begin (); It!=s.end (); it++) cout<< (*it) <<Endl; return 0;}

Codeforces Round #349 (Div. 2) C. Reberland Linguistics Dp+set

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.