#include <iostream>
# include <vector>
# include <algorithm>
# include <utility>
# include <set>
# include <string>
using namespace std;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int i;
    string s1;
    for (i = 5; i < n; i++)
    {
        s1 += s[i];
    }
    //cout << s1;
    n = s1.size();
    //cout << n;
    int dp2[100000], dp3[10000];
    if (n >= 2)
    dp2[n - 2] = 1;
    if (n >= 3)
    dp3[n - 3] = 1;
    set <string> set1;
    string str;
    if (n >= 2)
    {
        str += s1[n - 2];
        str += s1[n - 1];
        set1.insert(str);
    }
    str = "";
    if (n >= 3)
    {
        str += s1[n - 3];
        str += s1[n - 2];
        str += s1[n - 1];
        set1.insert(str);
    }
    string str1;
    for (i = n - 4; i >= 0; i--)
    {
        str = "";
        str1 = "";
        if (dp3[i + 2] == 1)
        {
            dp2[i] = 1;
            str += s1[i];
            str += s1[i + 1];
            set1.insert(str);
        }
        else
        {
            str = "";
            str += s1[i];
            str += s1[i + 1];
            str1 += s1[i + 2];
            str1 += s1[i + 3];
            if (dp2[i + 2] == 1 && str != str1)
            {
                dp3[i] = 1;
                set1.insert(str);
            }
        }
        str = "";
        str1 = "";
        if (dp2[i + 3] == 1)
        {
            dp3[i] = 1;
            str += s1[i];
            str += s1[i + 1];
            str += s1[i + 2];
            set1.insert(str);
        }
        else
        {
            str = "";
            if (i <= n - 6 && dp3[i + 3] == 1)
            {
                str += s1[i];
                str += s1[i + 1];
                str += s1[i + 2];
                str1 += s1[i + 3];
                str1 += s1[i + 4];
                str1 += s1[i + 5];
                if (str != str1)
                {
                    dp3[i] = 1;
                    set1.insert(str);
                }
            }
        }
    }
    cout << set1.size() << endl;
    n = set1.size();
    string mas[100000];
    int len = -1;
    //set <int> ::iterator it;
    for (set <string>::const_iterator it = set1.begin(); it != set1.end(); it++)
    {
        len++;
        mas[len] = *it;
        cout << *it << endl;
    }
//    sort(mas, mas + len + 1, comp);
    return 0;
}


#include <iostream>
# include <vector>
# include <algorithm>
# include <utility>
# include <set>
# include <string>
using namespace std;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int i;
    string s1;
    for (i = 5; i < n; i++)
    {
        s1 += s[i];
    }
    n = s1.size();
    int dp2[100000], dp3[10000];
    dp2[n - 2] = 1;
    dp3[n - 3] = 1;
    set <string> set1;
    string str;
    str += s1[n - 2] + s1[n -1];
    set1.insert(str);
    str = "";
    str += s1[n - 3] + s1[n - 2] + s1[n - 1];
    set1.insert(str);
    string str1;
    for (i = n - 4; i >= 0; i--)
    {
        str = "";
        str1 = "";
        if (dp3[i + 2] == 1)
        {
            dp2[i] = 1;
            str += s[i] + s[i + 1];
            set1.insert(str);
        }
        else
        {
            str = "";
            str += s[i] + s[i + 1];
            str1 += s[i + 2] + s[i + 3];
            if (dp2[i + 2] == 1 && str != str1)
            {
                dp3[i] = 1;
                set1.insert(str);
            }
        }
        str = "";
        str1 = "";
        if (dp2[i + 3] == 1)
        {
            dp3[i] = 1;
            str += s[i] + s[i + 1] + s[i + 2];
            set1.insert(str);
        }
        else
        {
            str = "";
            if (i <= n - 6 && dp3[i + 3] == 1)
            {
                str += s[i] + s[i + 1] + s[i + 2];
                str1 += s[i + 3] + s[i + 4] + s[i + 5];
                if (str != str1)
                {
                    dp3[i] = 1;
                    set1.insert(str);
                }
            }
        }
    }
    cout << set1.size() << endl;
    n = set1.size();
    //set <int> ::iterator it;
    for (set <int>::const_iterator it = set1.begin(); it != set1.end(); ++it)
    {
        cout << *it << endl;
    }
    return 0;
}


#include <iostream>
# include <vector>
# include <algorithm>
# include <utility>
# include <set>
using namespace std;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int i;
    string s1;
    for (i = 5; i < n; i++)
    {
        s1 += s[i];
    }
    n = s1.size();
    int dp2[100000], dp3[10000];
    dp2[n - 2] = 1;
    dp3[n - 3] = 1;
    set <string> set1;
    string str;
    str += s1[n - 2] + s1[n -1];
    set1.insert(str);
    str = "";
    str += s1[n - 3] + s1[n - 2] + s1[n - 1];
    set1.insert(str);
    string str1;
    for (i = n - 4; i >= 0; i--)
    {
        str = "";
        str1 = "";
        if (dp3[i + 2] == 1)
        {
            dp2[i] = 1;
            str += s[i] + s[i + 1];
            set1.insert(str);
        }
        else
        {
            str = "";
            str += s[i] + s[i + 1];
            str1 += s[i + 2] + s[i + 3];
            if (dp2[i + 2] == 1 && str != str1)
            {
                dp3[i] = 1;
                set1.insert(str);
            }
        }
        str = "";
        str1 = "";
        if (dp2[i + 3] == 1)
        {
            dp3[i] = 1;
            str += s[i] + s[i + 1] + s[i + 2];
            set1.insert(str);
        }
        else
        {
            str = "";
            if (i <= n - 6 && dp3[i + 3] == 1)
            {
                str += s[i] + s[i + 1] + s[i + 2];
                str1 += s[i + 3] + s[i + 4] + s[i + 5];
                if (str != str1)
                {
                    dp3[i] = 1;
                    set1.insert(str);
                }
            }
        }
    }
    cout << set1.size() << endl;
    n = set1.size();
    //set <int> ::iterator it;
    for (set <int>::const_iterator it = set1.begin(); it != set1.end(); ++it)
    {
        cout << *it << endl;
    }
    return 0;
}


#include <iostream>
# include <vector>
# include <algorithm>
# include <utility>
# include <set>
# include <string>
using namespace std;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int i;
    string s1;
    for (i = 5; i < n; i++)
    {
        s1 += s[i];
    }
    //cout << s1;
    n = s1.size();
    //cout << n;
    int dp2[100000], dp3[10000];
    if (n >= 2)
    dp2[n - 2] = 1;
    if (n >= 3)
    dp3[n - 3] = 1;
    set <string> set1;
    string str;
    if (n >= 2)
    {
        str += s1[n - 2];
        str += s1[n - 1];
        set1.insert(str);
    }
    str = "";
    if (n >= 3)
    {
        str += s1[n - 3];
        str += s1[n - 2];
        str += s1[n - 1];
        set1.insert(str);
    }
    string str1;
    for (i = n - 4; i >= 0; i--)
    {
        str = "";
        str1 = "";
        if (dp3[i + 2] == 1)
        {
            dp2[i] = 1;
            str += s[i];
            str += s[i + 1];
            set1.insert(str);
        }
        else
        {
            str = "";
            str += s[i];
            str += s[i + 1];
            str1 += s[i + 2];
            str1 += s[i + 3];
            if (dp2[i + 2] == 1 && str != str1)
            {
                dp3[i] = 1;
                set1.insert(str);
            }
        }
        str = "";
        str1 = "";
        if (dp2[i + 3] == 1)
        {
            dp3[i] = 1;
            str += s[i];
            str += s[i + 1];
            str += s[i + 2];
            set1.insert(str);
        }
        else
        {
            str = "";
            if (i <= n - 6 && dp3[i + 3] == 1)
            {
                str += s[i];
                str += s[i + 1];
                str += s[i + 2];
                str1 += s[i + 3];
                str1 += s[i + 4];
                str1 += s[i + 5];
                if (str != str1)
                {
                    dp3[i] = 1;
                    set1.insert(str);
                }
            }
        }
    }
    cout << set1.size() << endl;
    n = set1.size();
    //set <int> ::iterator it;
    for (set <string>::const_iterator it = set1.begin(); it != set1.end(); it++)
    {
        cout << *it << endl;
    }
    return 0;
}


										/* in the name of Allah */
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <list>
#include <map>
#include <set>

using namespace std;

#define uint unsigned int
#define int64 long long
#define P pair<int, int>
#define Pss pair<string, string>
#define PLL pair<int64, int64>
#define Inf 1000000
#define Mod 1000000007LL

string str;
set <string> s;
bool dp[10010][5];

void mem(int idx, int bef){
	if(dp[idx][bef]) return;
	dp[idx][bef] = true;

	for(int i = 2; i < 4; i++){
		if(idx > 4 + i && str.substr(idx - i, i) != str.substr(idx, bef)){
			s.insert(str.substr(idx - i, i));
			mem(idx - i, i);
		}
	}
}

int main(){
	cin >> str;
	int n = str.size();

	if(n > 6){
		s.insert(str.substr(n - 2));
		mem(n - 2, 2);
	}

	if(n > 7){
		s.insert(str.substr(n - 3));
		mem(n - 3, 3);
	}

	cout << s.size() << endl;
	for(set <string>::iterator it = s.begin(); it != s.end(); it++)
		cout << (*it) << endl;
	return 0;
}


										/* in the name of Allah */
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <list>
#include <map>
#include <set>

using namespace std;

#define uint unsigned int
#define int64 long long
#define P pair<int, int>
#define Pss pair<string, string>
#define PLL pair<int64, int64>
#define Inf 1000000
#define Mod 1000000007LL

set <string> st;

int main(){
	string inp;
	cin >> inp;
	for(int i = 5; i < inp.size(); i++)
		for(int j = 2; j < 4 && i + j <= inp.size(); j++)
			if(i + j + 1 != inp.size())
				st.insert(inp.substr(i, j));
	cout << st.size() << endl;
	for(set <string>::iterator it = st.begin(); it != st.end(); it++)
		cout << (*it) << endl;
	return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <sstream>
#include <assert.h>
#include <fstream>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstdio>
#include <complex>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <set>
#include <map>
#include <map>

using namespace std;

const int N = 10001;

bool dp[N][2];
string s;
set < string > st;

int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	memset(dp, false, sizeof(dp));
	cin >> s;
	int n = (int)s.size() - 1;
	dp[n - 1][0] = true;
	dp[n - 2][1] = true;
	for (int i = n - 3; i >= 5; --i)
	{
		if (dp[i + 2][1] == true || (dp[i + 2][0] == true && s.substr(i, 2) != s.substr(i + 2, 2)))
			dp[i][0] = true;
		if (dp[i + 3][0] == true || (dp[i + 3][1] == true && s.substr(i, 3) != s.substr(i + 3, 3)))
			dp[i][1] = true;
	}
	for (int i = 5; i <= n; ++i)
	{
		if (dp[i][0] == true)
			st.insert(s.substr(i, 2));
		if (dp[i][1] == true)
			st.insert(s.substr(i, 3));
	}
	printf("%d\n", (int)st.size());
	for (auto it = st.begin(); it != st.end(); ++it)
		cout << *(it) << endl;
    return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <sstream>
#include <assert.h>
#include <fstream>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstdio>
#include <complex>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <set>
#include <map>
#include <map>

using namespace std;

const int N = 10001;

bool dp[N][2];
string s;
set < string > st;

int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	memset(dp, false, sizeof(dp));
	cin >> s;
	int n = (int)s.size() - 1;
	dp[n - 1][0] = true; st.insert(s.substr(n - 1, 2));
	dp[n - 2][1] = true; st.insert(s.substr(n - 2, 3));
	for (int i = n - 3; i >= 5; --i)
	{
		if (dp[i + 2][1] == true || (dp[i + 2][0] == true && s.substr(i, 2) != s.substr(i + 2, 2)))
		{
			dp[i][0] = true;
			st.insert(s.substr(i, 2));
		}
		if (dp[i + 3][0] == true || (dp[i + 3][1] == true && s.substr(i, 3) != s.substr(i + 3, 3)))
		{
			dp[i][1] = true;
			st.insert(s.substr(i, 3));
		}
	}
	printf("%d\n", (int)st.size());
	for (auto it = st.begin(); it != st.end(); ++it)
		cout << *(it) << endl;
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <ctime>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <deque>
#include <algorithm>
#include <utility>
#include <iterator>

using namespace std;

#define forn(i, n) for (auto i(0); i < n; ++i)
#define forab(i, a, b) for (auto i(a); i <= b; ++i)
#define forv(it, v) for(auto it = begin(v); it != end(v); ++it)
#define forvr(it, v) for(auto it = rbegin(v); it != rend(v); ++it)
#define m_p(a, b) make_pair(a, b)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((x).size())

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<vector<int> > vvint;
typedef vector<vector<ll> > vvll;
typedef pair<int, int> mpair;
typedef pair<ll, ll> Mpair;

const int INF = 1e9;

set<string> ans;
set<pair<int, string>> used;
string str;

void count(int size, string last) {
    if (used.count(make_pair(size, last))) {
        return;
    }
    used.insert(make_pair(size, last));
    if (size <= 5) {
        return;
    }
    string suf2 = str.substr(size - 2, 2);
    string suf3 = str.substr(size - 3, 3);
    if (size - 2 >= 5 && last != suf2) {
        count(size - 2, suf2);
        ans.insert(suf2);
    }
    if (size - 3 >= 5 && last != suf3) {
        count(size - 3, suf3);
        ans.insert(suf3);
    }
}

int main(){
    getline(cin, str);
    count(str.size(), "");
    cout << ans.size() << "\n";
    forv (it, ans) {
        cout << *it << "\n";
    }
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <ctime>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <deque>
#include <algorithm>
#include <utility>
#include <iterator>

using namespace std;

#define forn(i, n) for (auto i(0); i < n; ++i)
#define forab(i, a, b) for (auto i(a); i <= b; ++i)
#define forv(it, v) for(auto it = begin(v); it != end(v); ++it)
#define forvr(it, v) for(auto it = rbegin(v); it != rend(v); ++it)
#define m_p(a, b) make_pair(a, b)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((x).size())

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<vector<int> > vvint;
typedef vector<vector<ll> > vvll;
typedef pair<int, int> mpair;
typedef pair<ll, ll> Mpair;

const int INF = 1e9;

set<string> ans;
set<pair<int, string>> used;
string str;

void count(int size, string last) {
    if (used.count(make_pair(size, last))) {
        return;
    }
    used.insert(make_pair(size, last));
    if (size <= 5) {
        return;
    }
    string suf2 = str.substr(size - 2, 2);
    string suf3 = str.substr(size - 3, 3);
    count(size - 2, suf2);
    count(size - 3, suf3);
    if (size - 2 >= 5 && last != suf2) {
        ans.insert(suf2);
    }
    if (size - 3 >= 5 && last != suf3) {
        ans.insert(suf3);
    }
}

int main(){
    getline(cin, str);
    count(str.size(), "");
    cout << ans.size() << "\n";
    forv (it, ans) {
        cout << *it << "\n";
    }
}


#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll,ll> ii;

const int N=1e4+10;

set<string>st;
set<string>::iterator it;
string t,t2;
bool vld[N][3];
char s[N];
ll n;

void solve()
{
	cin>>s;
	n=strlen(s);
	vld[n][0]=1;
	vld[n][1]=1;
	vld[n-1][0]=0;
	vld[n-1][1]=0;
	for(int i=n-2;i>=5;i--)
	{
		vld[i][0]=0;
		if(i+1<n)
		{
			t="";
			t+=s[i];
			t+=s[i+1];
			if(vld[i+2][1])
			{
				vld[i][0]=1;
				st.insert(t);
			}
			else if(vld[i+2][0])
			{
				if(i+2==n)
				{
					vld[i][0]=1;
					st.insert(t);
				}
				else
				{
					t2="";
					t2+=s[i+2];
					t2+=s[i+3];
					if(t!=t2)
					{
						vld[i][0]=1;
						st.insert(t);
					}
				}
			}
		}
		vld[i][1]=0;
		if(i+2<n)
		{
			t="";
			t+=s[i];
			t+=s[i+1];
			t+=s[i+2];
			if(vld[i+3][0])
			{
				vld[i][1]=1;
				st.insert(t);
			}
			else if(vld[i+3][1])
			{
				if(i+3==n)
				{
					vld[i][1]=1;
					st.insert(t);
				}
				else
				{
					t2="";
					t2+=s[i+3];
					t2+=s[i+4];
					t2+=s[i+5];
					if(t!=t2)
					{
						vld[i][1]=1;
						st.insert(t);
					}
				}
			}
		}
	}
	cout<<st.size()<<"\n";
	for(it=st.begin();it!=st.end();it++)
	{
		cout<<(*it)<<"\n";
	}
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	solve();
	return 0;
}


#include <queue>
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <functional>
#include <algorithm>  //min, max, sort
#include <cstdlib>
#include <cstring>    //memset
#include <map>
#include <iomanip>
#include <limits>
#include <unordered_map>
#include <set>
#include <cmath>
#include <numeric> //accumulate
#include <stack>

//#include <unordered_set>//unordered_set

#define rep(i,a) for (int i = 0; i < (a); ++i)
#define rep2(i,a,b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define PI 3.14159265359;

using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef const vector<int> cvi;
typedef vector<bool> vb;
const int INF = 987654321;

map<string, int> my;
string str;
int n;
int cache[10002][4];
int rec(int here, int prevSize) {
	if (here == n) return 1;
	if (here > n) return 0;
	int& ret = cache[here][prevSize];
	if (ret != -1) return ret;

	ret = 0;
	if (prevSize != 3 || str.substr(here - 3, 3) != str.substr(here, 3)) {
		int ok = rec(here + 3, 3);
		if (ok == 1) {
			my[str.substr(here, 3)]++;
			ret++;
		}
	}
	if (prevSize != 2 || str.substr(here - 2, 2) != str.substr(here, 2)) {
		int ok = rec(here + 2, 2);
		if (ok == 1) {
			my[str.substr(here, 2)]++;
			ret++;
		}
	}
	if (ret > 0) ret = 1;
	return ret;
}
int main() {
	memset(cache, -1, sizeof(cache));
	my.clear();
	cin >> str;
	n = str.size();
	rep2(i, 5, n) rec(i, 0);
	cout << my.size() << endl;
	map<string, int>::iterator it;
	for (it = my.begin(); it != my.end(); ++it)
		cout << it->first << endl;
	return 0;
}


#include <queue>
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <functional>
#include <algorithm>  //min, max, sort
#include <cstdlib>
#include <cstring>    //memset
#include <map>
#include <iomanip>
#include <limits>
#include <unordered_map>
#include <set>
#include <cmath>
#include <numeric> //accumulate
#include <stack>

//#include <unordered_set>//unordered_set

#define rep(i,a) for (int i = 0; i < (a); ++i)
#define rep2(i,a,b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define PI 3.14159265359;

using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef const vector<int> cvi;
typedef vector<bool> vb;
const int INF = 987654321;

map<string, int> my;
string str;
int n;
int cache[10002][4];
int rec(int here, int prevSize) {	//prevSize: 0, 2: 2size, 3: 3size
	if (here == n) return 1;
	if (here > n) return 0;
	int& ret = cache[here][prevSize];
	if (ret != -1) return ret;

	int prev3 = here - 3;
	int prev2 = here - 2;
	string pstr3 = str.substr(prev3, 3);
	string pstr2 = str.substr(prev2, 2);

	string nstr3 = "", nstr2 = "";
	ret = 0;

	if (here + 3 - 1 < n)
		nstr3 = str.substr(here, 3);
	if (here + 2 - 1 < n)
		nstr2 = str.substr(here, 2);
	if (pstr3 != nstr3 || prevSize != 3) {	//???????? 2????
		int ok = rec(here + 3, 3);
		if (ok == 1 && nstr3.size() == 3) {
			my[nstr3]++;
			ret++;
		}
	}
	if (pstr2 != nstr2 || prevSize != 2) {	//???????? 3????
		int ok = rec(here + 2, 2);
		if (ok == 1 && nstr2.size() == 2) {
			my[nstr2]++;
			ret++;
		}
	}
	//int ok = rec(here + 1);
	//if (ok == 1) ret++;
	if (ret > 0) ret = 1;
	return ret;
}
int main() {
	memset(cache, -1, sizeof(cache));
	my.clear();
	cin >> str;
	n = str.size();
	for (int i = 5; i < n; ++i) {
		rec(i, 0);
	}
	cout << my.size() << endl;
	map<string, int>::iterator it;
	for (it = my.begin(); it != my.end(); ++it) {
		cout << it->first << endl;
	}
	return 0;
}


#include <queue>
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <functional>
#include <algorithm>  //min, max, sort
#include <cstdlib>
#include <cstring>    //memset
#include <map>
#include <iomanip>
#include <limits>
#include <unordered_map>
#include <set>
#include <cmath>
#include <numeric> //accumulate
#include <stack>

//#include <unordered_set>//unordered_set

#define rep(i,a) for (int i = 0; i < (a); ++i)
#define rep2(i,a,b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define PI 3.14159265359;

using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef const vector<int> cvi;
typedef vector<bool> vb;
const int INF = 987654321;

map<string, int> my;
string str;
int n;
int cache[10002];
int rec(int here) {
	if (here == n) return 1;
	if (here > n) return 0;
	int& ret = cache[here];
	if (ret != -1) return ret;

	int prev3 = here - 3;
	int prev2 = here - 2;
	string pstr3 = str.substr(prev3, 3);
	string pstr2 = str.substr(prev2, 2);

	string nstr3 = "", nstr2 = "";
	ret = 0;

	if (here + 3 - 1 < n)
		nstr3 = str.substr(here, 3);
	if (here + 2 - 1 < n)
		nstr2 = str.substr(here, 2);
	if (pstr3 != nstr3) {
		int ok = rec(here + 3);
		if (ok == 1 && nstr3.size() == 3) {
			my[nstr3]++;
			ret++;
		}
	}
	if (pstr2 != nstr2) {
		int ok = rec(here + 2);
		if (ok == 1 && nstr2.size() == 2) {
			my[nstr2]++;
			ret++;
		}
	}
	//int ok = rec(here + 1);
	//if (ok == 1) ret++;
	if (ret > 0) ret = 1;
	return ret;
}
int main() {
	memset(cache, -1, sizeof(cache));
	my.clear();
	cin >> str;
	n = str.size();
	for (int i = 5; i < n; ++i) {
		rec(i);
	}
	cout << my.size() << endl;
	map<string, int>::iterator it;
	for (it = my.begin(); it != my.end(); ++it) {
		cout << it->first << endl;
	}
	return 0;
}


#include <queue>
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <functional>
#include <algorithm>  //min, max, sort
#include <cstdlib>
#include <cstring>    //memset
#include <map>
#include <iomanip>
#include <limits>
#include <unordered_map>
#include <set>
#include <cmath>
#include <numeric> //accumulate
#include <stack>

//#include <unordered_set>//unordered_set

#define rep(i,a) for (int i = 0; i < (a); ++i)
#define rep2(i,a,b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define PI 3.14159265359;

using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef const vector<int> cvi;
typedef vector<bool> vb;
const int INF = 987654321;

map<string, int> my;
string str;
int n;
int cache[10002][4];
int rec(int here, int prevSize) {	//prevSize: 0, 2: 2size, 3: 3size
	if (here == n) return 1;
	if (here > n) return 0;
	int& ret = cache[here][prevSize];
	if (ret != -1) return ret;

	int prev3 = here - 3;
	int prev2 = here - 2;
	string pstr3 = str.substr(prev3, 3);
	string pstr2 = str.substr(prev2, 2);

	string nstr3 = "", nstr2 = "";
	ret = 0;

	if (here + 3 - 1 < n)
		nstr3 = str.substr(here, 3);
	if (here + 2 - 1 < n)
		nstr2 = str.substr(here, 2);
	if (pstr3 != nstr3 || prevSize == 2) {	//�������� 2����
		int ok = rec(here + 3, 3);
		if (ok == 1 && nstr3.size() == 3) {
			my[nstr3]++;
			ret++;
		}
	}
	if (pstr2 != nstr2 || prevSize == 3) {	//�������� 3����
		int ok = rec(here + 2, 2);
		if (ok == 1 && nstr2.size() == 2) {
			my[nstr2]++;
			ret++;
		}
	}
	//int ok = rec(here + 1);
	//if (ok == 1) ret++;
	if (ret > 0) ret = 1;
	return ret;
}
int main() {
	memset(cache, -1, sizeof(cache));
	my.clear();
	cin >> str;
	n = str.size();
	for (int i = 5; i < n; ++i) {
		rec(i, 0);
	}
	cout << my.size() << endl;
	map<string, int>::iterator it;
	for (it = my.begin(); it != my.end(); ++it) {
		cout << it->first << endl;
	}
	return 0;
}


#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#include<math.h>
#include<memory>
#include<vector>
#include<bitset>
#include<fstream>
#include<stdio.h>
#include<utility>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
char a[10005];
bool dp[10005][2];
int val[10005][2];
bool ok[20005];
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    scanf("%s",a);
    int i;
    int n=strlen(a);
    for (i=5;i<n-1;i++)
    {
        val[i][0]=(a[i]-'a')*26+a[i+1]-'a';
        if (i!=n-2)
        {
            val[i][1]=val[i][0]*26+a[i+2]-'a';
            val[i][1]+=26*26;
        }
    }
    val[n][0]=20000;
    val[n][1]=20000;
    dp[n][0]=true;
    dp[n][1]=true;
    for (i=n-2;i>=5;i--)
    {
        if (val[i][0]!=val[i+2][0])
        {
            dp[i][0]|=dp[i+2][0];
        }
        dp[i][0]|=dp[i+2][1];
        if (val[i][1]!=val[i+3][1])
        {
            dp[i][1]|=dp[i+3][1];
        }
        dp[i][1]|=dp[i+3][0];
        if (dp[i][0])
        {
            ok[val[i][0]]=true;
        }
        if (dp[i][1])
        {
            ok[val[i][1]]=true;
        }
    }
    int sum=0;
    for (i=0;i<20000;i++)
    {
        sum+=ok[i];
    }
    printf("%d\n",sum);
    int cnt=0;
    int cnt2=26*26;
    for (i=0;i<26;i++)
    {
        int j;
        for (j=0;j<26;j++)
        {
            if (ok[cnt])
            {
                printf("%c%c\n",i+'a',j+'a');
            }
            cnt++;
            int k;
            for (k=0;k<26;k++)
            {
                if (ok[cnt2])
                {
                    printf("%c%c%c\n",i+'a',j+'a',k+'a');
                }
                cnt2++;
            }
        }
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#if 1
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <utility>
#include <string>
#include <algorithm>
#include <bitset>
using namespace std;
typedef char ch;
typedef string st;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef set<ll> sl;
const ll INF = 1000000000000;
#define wh while
#define bs bitset
#define mp make_pair
#define in1(a) cin >> a;
#define in2(a, b) cin >> a >> b;
#define in3(a, b, c) cin >> a >> b >> c;
#define in4(a, b, c, d) cin >> a >> b >> c >> d;
#define ou1(a) cout << a;
#define ou2(a, b) cout << a << b;
#define ou3(a, b, c) cout << a << b << c;
#define ou4(a, b, c, d) cout << a << b << c << d;
#define fi(i, n) for (ll i=0; i<n; i++)
#define fd(i, n) for (ll i=n; i>=0; i--)
#define all(a) a.begin(), a.end()
#define yes cout << "YES";
#define no cout << "NO";
#define imp cout << "IMPOSSIBLE";
#define stop cout << endl, system("pause");
#define maxf(a,b) (a>b) ? (a) : (b)
#define minf(a,b) (a<b) ? (a) : (b)
#define ex exit(0);
#define ts to_string
#define re freopen("a.in", "r", stdin)
#define wr freopen("a.out", "w", stdout)
#endif
set<st> ss;
vl v;
ll d;
st s;
bool suff(ll n, st pr) {
	if (n < d) if (v[n] != -1) return v[n];
	if (d - n == 0) return 1;
	else if (d - n == 1) {
		v[n] = 0; return 0;
	}
	st s2 = "", s3 = "";
	s2 += s[n]; s2 += s[n + 1];
	if (d - n > 2) {
		s3 += s[n];
		s3 += s[n + 1];
		s3 += s[n + 2];
	}
	else s3 = pr;
	ll k = 0;
	if (s2 != pr) {
		if (suff(n + 2, s2)) {
			ss.insert(s2); k++;
		}
	}
	if (s3 != pr) {
		if (suff(n + 3, s3)) {
			ss.insert(s3); k++;
		}
	}
	if (k) {
		v[n] = 1; return 1;
	}
	else {
		v[n] = 0; return 0;
	}
}
int main() {
	cin >> s;
	d = s.size();
	v.resize(d, -1);
	/*if (d > 6) suff(5, "");
	if (d > 7) suff(6, "");*/
	for (ll i = 5; i < d - 1; i++) {
		st s2 = "", s3 = "";
		if (i != d - 3) {
			s2 += s[i];
			s2 += s[i + 1];
			ss.insert(s2);
		}
		if (i != d - 4 && i != d - 2) {
			s3 += s[i];
			s3 += s[i + 1];
			s3 += s[i + 2];
			ss.insert(s3);
		}
	}
	cout << ss.size() << endl;
	ll i = 0;
	for (auto iter = ss.begin(); iter != ss.end(); iter++, i++) {
		cout << *iter << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#if 1
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <utility>
#include <string>
#include <algorithm>
#include <bitset>
using namespace std;
typedef char ch;
typedef string st;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef set<ll> sl;
const ll INF = 1000000000000;
#define wh while
#define bs bitset
#define mp make_pair
#define in1(a) cin >> a;
#define in2(a, b) cin >> a >> b;
#define in3(a, b, c) cin >> a >> b >> c;
#define in4(a, b, c, d) cin >> a >> b >> c >> d;
#define ou1(a) cout << a;
#define ou2(a, b) cout << a << b;
#define ou3(a, b, c) cout << a << b << c;
#define ou4(a, b, c, d) cout << a << b << c << d;
#define fi(i, n) for (ll i=0; i<n; i++)
#define fd(i, n) for (ll i=n; i>=0; i--)
#define all(a) a.begin(), a.end()
#define yes cout << "YES";
#define no cout << "NO";
#define imp cout << "IMPOSSIBLE";
#define stop cout << endl, system("pause");
#define maxf(a,b) (a>b) ? (a) : (b)
#define minf(a,b) (a<b) ? (a) : (b)
#define ex exit(0);
#define ts to_string
#define re freopen("a.in", "r", stdin)
#define wr freopen("a.out", "w", stdout)
#endif
set<st> ss;
vl v;
ll d;
st s;
bool suff(ll n, st pr) {
	if (v[n] != -1) return v[n];
	if (d - n == 0) {
		v[n] = 1; return 1;
	}
	else if (d - n == 1 || n > d) {
		v[n] = 0; return 0;
	}
	st s2 = "", s3 = "";
	s2 += s[n]; s2 += s[n + 1];
	if (d - n > 2) {
		s3 += s[n];
		s3 += s[n + 1];
		s3 += s[n + 2];
	}
	else s3 = pr;
	ll k = 0;
	if (s2 != pr) {
		if (suff(n + 2, s2)) {
			ss.insert(s2); k++;
		}
	}
	if (s3 != pr) {
		if (suff(n + 3, s3)) {
			ss.insert(s3); k++;
		}
	}
	if (k) {
		v[n] = 1; return 1;
	}
	else {
		v[n] = 0; return 0;
	}
}
int main() {
	cin >> s;
	d = s.size();
	v.resize(d, -1);
	suff(5, ""); suff(6, "");
	cout << ss.size() << endl;
	ll i = 0;
	for (auto iter = ss.begin(); iter != ss.end(); iter++, i++) {
		cout << *iter << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#if 1
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <utility>
#include <string>
#include <algorithm>
#include <bitset>
using namespace std;
typedef char ch;
typedef string st;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef set<ll> sl;
const ll INF = 1000000000000;
#define wh while
#define bs bitset
#define mp make_pair
#define in1(a) cin >> a;
#define in2(a, b) cin >> a >> b;
#define in3(a, b, c) cin >> a >> b >> c;
#define in4(a, b, c, d) cin >> a >> b >> c >> d;
#define ou1(a) cout << a;
#define ou2(a, b) cout << a << b;
#define ou3(a, b, c) cout << a << b << c;
#define ou4(a, b, c, d) cout << a << b << c << d;
#define fi(i, n) for (ll i=0; i<n; i++)
#define fd(i, n) for (ll i=n; i>=0; i--)
#define all(a) a.begin(), a.end()
#define yes cout << "YES";
#define no cout << "NO";
#define imp cout << "IMPOSSIBLE";
#define stop cout << endl, system("pause");
#define maxf(a,b) (a>b) ? (a) : (b)
#define minf(a,b) (a<b) ? (a) : (b)
#define ex exit(0);
#define ts to_string
#define re freopen("a.in", "r", stdin)
#define wr freopen("a.out", "w", stdout)
#endif
set<st> ss;
vl v;
ll d;
st s;
bool suff(ll n, st pr) {
	if (n < d) v[n] = 1;
	if (d - n == 0) return 1;
	else if (d - n == 1 || n > d) return 0;
	st s2 = "", s3 = "";
	s2 += s[n]; s2 += s[n + 1];
	if (d - n > 2) {
		s3 += s[n];
		s3 += s[n + 1];
		s3 += s[n + 2];
	}
	else s3 = pr;
	if (s2 != pr) {
		if (suff(n + 2, s2)) ss.insert(s2);
	}
	if (s3 != pr) {
		if (suff(n + 3, s3)) ss.insert(s3);
	}
}
int main() {
	cin >> s;
	d = s.size();
	v.resize(d, 0);
	for (ll i = 5; i <= d - 2; i++) {
		if (!v[i]) suff(i, "");
	}
	cout << ss.size() << endl;
	for (auto iter = ss.begin(); iter != ss.end(); iter++) {
		cout << *iter << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#if 1
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <utility>
#include <string>
#include <algorithm>
#include <bitset>
using namespace std;
typedef char ch;
typedef string st;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef set<ll> sl;
const ll INF = 1000000000000;
#define wh while
#define bs bitset
#define mp make_pair
#define in1(a) cin >> a;
#define in2(a, b) cin >> a >> b;
#define in3(a, b, c) cin >> a >> b >> c;
#define in4(a, b, c, d) cin >> a >> b >> c >> d;
#define ou1(a) cout << a;
#define ou2(a, b) cout << a << b;
#define ou3(a, b, c) cout << a << b << c;
#define ou4(a, b, c, d) cout << a << b << c << d;
#define fi(i, n) for (ll i=0; i<n; i++)
#define fd(i, n) for (ll i=n; i>=0; i--)
#define all(a) a.begin(), a.end()
#define yes cout << "YES";
#define no cout << "NO";
#define imp cout << "IMPOSSIBLE";
#define stop cout << endl, system("pause");
#define maxf(a,b) (a>b) ? (a) : (b)
#define minf(a,b) (a<b) ? (a) : (b)
#define ex exit(0);
#define ts to_string
#define re freopen("a.in", "r", stdin)
#define wr freopen("a.out", "w", stdout)
#endif
set<st> ss;
vl v;
ll d;
st s;
bool suff(ll n, st pr) {
	if (v[n] != -1) return v[n];
	if (d - n == 0) {
		v[n] = 1; return 1;
	}
	else if (d - n == 1 || n > d) {
		v[n] = 0; return 0;
	}
	st s2 = "", s3 = "";
	s2 += s[n]; s2 += s[n + 1];
	if (d - n > 2) {
		s3 += s[n];
		s3 += s[n + 1];
		s3 += s[n + 2];
	}
	else s3 = pr;
	ll k = 0;
	if (s2 != pr) {
		if (suff(n + 2, s2)) {
			ss.insert(s2); k++;
		}
	}
	if (s3 != pr) {
		if (suff(n + 3, s3)) {
			ss.insert(s3); k++;
		}
	}
	if (k) {
		v[n] = 1; return 1;
	}
	else {
		v[n] = 0; return 0;
	}
}
int main() {
	cin >> s;
	d = s.size();
	v.resize(d, -1);
	for (ll i = 5; i <= d - 2; i++) {
		if (v[i] == -1) suff(i, "");
	}
	cout << ss.size() << endl;
	ll i = 0;
	for (auto iter = ss.begin(); iter != ss.end(); iter++, i++) {
		cout << *iter << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#if 1
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <utility>
#include <string>
#include <algorithm>
#include <bitset>
using namespace std;
typedef char ch;
typedef string st;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef set<ll> sl;
const ll INF = 1000000000000;
#define wh while
#define bs bitset
#define mp make_pair
#define in1(a) cin >> a;
#define in2(a, b) cin >> a >> b;
#define in3(a, b, c) cin >> a >> b >> c;
#define in4(a, b, c, d) cin >> a >> b >> c >> d;
#define ou1(a) cout << a;
#define ou2(a, b) cout << a << b;
#define ou3(a, b, c) cout << a << b << c;
#define ou4(a, b, c, d) cout << a << b << c << d;
#define fi(i, n) for (ll i=0; i<n; i++)
#define fd(i, n) for (ll i=n; i>=0; i--)
#define all(a) a.begin(), a.end()
#define yes cout << "YES";
#define no cout << "NO";
#define imp cout << "IMPOSSIBLE";
#define stop cout << endl, system("pause");
#define maxf(a,b) (a>b) ? (a) : (b)
#define minf(a,b) (a<b) ? (a) : (b)
#define ex exit(0);
#define ts to_string
#define re freopen("a.in", "r", stdin)
#define wr freopen("a.out", "w", stdout)
#endif
set<st> ss;
vl v;
ll d;
st s;
bool suff(ll n, st pr) {
	if (n < d) v[n] = 1;
	if (d - n == 0) return 1;
	else if (d - n == 1 || n > d) return 0;
	st s2 = "", s3 = "";
	s2 += s[n]; s2 += s[n + 1];
	if (d - n > 2) {
		s3 += s[n];
		s3 += s[n + 1];
		s3 += s[n + 2];
	}
	else s3 = pr;
	if (s2 != pr) {
		if (suff(n + 2, s2)) ss.insert(s2);
	}
	if (s3 != pr) {
		if (suff(n + 3, s3)) ss.insert(s3);
	}
}
int main() {
	cin >> s;
	d = s.size();
	v.resize(d, 0);
	for (ll i = 5; i <= d - 2; i++) {
		if (!v[i]) suff(i, "");
	}
	cout << ss.size() << endl;
	ll i = 0;
	for (auto iter = ss.begin(); iter != ss.end(); iter++, i++) {
		cout << *iter;
		if (i != ss.size() - 1) cout << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#if 1
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <utility>
#include <string>
#include <algorithm>
#include <bitset>
using namespace std;
typedef char ch;
typedef string st;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef set<ll> sl;
const ll INF = 1000000000000;
#define wh while
#define bs bitset
#define mp make_pair
#define in1(a) cin >> a;
#define in2(a, b) cin >> a >> b;
#define in3(a, b, c) cin >> a >> b >> c;
#define in4(a, b, c, d) cin >> a >> b >> c >> d;
#define ou1(a) cout << a;
#define ou2(a, b) cout << a << b;
#define ou3(a, b, c) cout << a << b << c;
#define ou4(a, b, c, d) cout << a << b << c << d;
#define fi(i, n) for (ll i=0; i<n; i++)
#define fd(i, n) for (ll i=n; i>=0; i--)
#define all(a) a.begin(), a.end()
#define yes cout << "YES";
#define no cout << "NO";
#define imp cout << "IMPOSSIBLE";
#define stop cout << endl, system("pause");
#define maxf(a,b) (a>b) ? (a) : (b)
#define minf(a,b) (a<b) ? (a) : (b)
#define ex exit(0);
#define ts to_string
#define re freopen("a.in", "r", stdin)
#define wr freopen("a.out", "w", stdout)
#endif
set<st> ss;
vl v;
ll d;
st s;
bool suff(ll n, st pr) {
	if (v[n] != -1) return v[n];
	if (d - n == 0) {
		v[n] = 1; return 1;
	}
	else if (d - n == 1 || n > d) {
		v[n] = 0; return 0;
	}
	st s2 = "", s3 = "";
	s2 += s[n]; s2 += s[n + 1];
	if (d - n > 2) {
		s3 += s[n];
		s3 += s[n + 1];
		s3 += s[n + 2];
	}
	else s3 = pr;
	ll k = 0;
	if (s2 != pr) {
		if (suff(n + 2, s2)) {
			ss.insert(s2); k++;
		}
	}
	if (s3 != pr) {
		if (suff(n + 3, s3)) {
			ss.insert(s3); k++;
		}
	}
	if (k) {
		v[n] = 1; return 1;
	}
	else {
		v[n] = 0; return 0;
	}
}
int main() {
	cin >> s;
	d = s.size();
	v.resize(d, -1);
	if (d > 6) suff(5, "");
	if (d > 7) suff(6, "");
	cout << ss.size() << endl;
	ll i = 0;
	for (auto iter = ss.begin(); iter != ss.end(); iter++, i++) {
		cout << *iter << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#if 1
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <utility>
#include <string>
#include <algorithm>
#include <bitset>
using namespace std;
typedef char ch;
typedef string st;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef set<ll> sl;
const ll INF = 1000000000000;
#define wh while
#define bs bitset
#define mp make_pair
#define in1(a) cin >> a;
#define in2(a, b) cin >> a >> b;
#define in3(a, b, c) cin >> a >> b >> c;
#define in4(a, b, c, d) cin >> a >> b >> c >> d;
#define ou1(a) cout << a;
#define ou2(a, b) cout << a << b;
#define ou3(a, b, c) cout << a << b << c;
#define ou4(a, b, c, d) cout << a << b << c << d;
#define fi(i, n) for (ll i=0; i<n; i++)
#define fd(i, n) for (ll i=n; i>=0; i--)
#define all(a) a.begin(), a.end()
#define yes cout << "YES";
#define no cout << "NO";
#define imp cout << "IMPOSSIBLE";
#define stop cout << endl, system("pause");
#define maxf(a,b) (a>b) ? (a) : (b)
#define minf(a,b) (a<b) ? (a) : (b)
#define ex exit(0);
#define ts to_string
#define re freopen("a.in", "r", stdin)
#define wr freopen("a.out", "w", stdout)
#endif
set<st> ss;
vl v;
ll d;
st s;
bool suff(ll n, st pr) {
	if (n<d) if (v[n] != -1) return v[n];
	if (d - n == 0) return 1;
	else if (d - n == 1) {
		v[n] = 0; return 0;
	}
	st s2 = "", s3 = "";
	s2 += s[n]; s2 += s[n + 1];
	if (d - n > 2) {
		s3 += s[n];
		s3 += s[n + 1];
		s3 += s[n + 2];
	}
	else s3 = pr;
	ll k = 0;
	if (s2 != pr) {
		if (suff(n + 2, s2)) {
			ss.insert(s2); k++;
		}
	}
	if (s3 != pr) {
		if (suff(n + 3, s3)) {
			ss.insert(s3); k++;
		}
	}
	if (k) {
		v[n] = 1; return 1;
	}
	else {
		v[n] = 0; return 0;
	}
}
int main() {
	cin >> s;
	d = s.size();
	v.resize(d, -1);
	if (d > 6) suff(5, "");
	if (d > 7) suff(6, "");
	cout << ss.size() << endl;
	ll i = 0;
	for (auto iter = ss.begin(); iter != ss.end(); iter++, i++) {
		cout << *iter << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#if 1
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <utility>
#include <string>
#include <algorithm>
#include <bitset>
using namespace std;
typedef char ch;
typedef string st;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef set<ll> sl;
const ll INF = 1000000000000;
#define wh while
#define bs bitset
#define mp make_pair
#define in1(a) cin >> a;
#define in2(a, b) cin >> a >> b;
#define in3(a, b, c) cin >> a >> b >> c;
#define in4(a, b, c, d) cin >> a >> b >> c >> d;
#define ou1(a) cout << a;
#define ou2(a, b) cout << a << b;
#define ou3(a, b, c) cout << a << b << c;
#define ou4(a, b, c, d) cout << a << b << c << d;
#define fi(i, n) for (ll i=0; i<n; i++)
#define fd(i, n) for (ll i=n; i>=0; i--)
#define all(a) a.begin(), a.end()
#define yes cout << "YES";
#define no cout << "NO";
#define imp cout << "IMPOSSIBLE";
#define stop cout << endl, system("pause");
#define maxf(a,b) (a>b) ? (a) : (b)
#define minf(a,b) (a<b) ? (a) : (b)
#define ex exit(0);
#define ts to_string
#define re freopen("a.in", "r", stdin)
#define wr freopen("a.out", "w", stdout)
#endif
set<st> ss;
int main() {
	string s;
	cin >> s;
	ll d = s.size();
	vector<bool> dp2(d, 0), dp3(d, 0);
	reverse(all(s));
	dp2[0] = 1; dp3[0] = 1;
	dp2[1] = 0; dp3[1] = 0;
	for (ll i = 2; i < d; i++) {
		dp2[i] = (i >= 3 && dp3[i - 3]) || (dp2[i - 2] &&
			s.substr(i - 2, 2) != s.substr(i, 2));
		dp3[i] = dp2[i - 2] || (i >= 3 && dp3[i - 3] &&
			s.substr(i - 3, 3) != s.substr(i, 3));
	}
	st s2, s3;
	reverse(all(s)); //reverse(all(dp2)); reverse(all(dp3));
	for (ll i = 0; i < d; i++) {
		if (dp2[i]) {
			if (i + 6 < d) {
				s2 = s.substr(d - i - 2, 2); ss.insert(s2);
			}
		}
		if (dp3[i]) {
			if (i + 7 < d) {
				s3 = s.substr(d - i - 3, 3); ss.insert(s3);
			}
		}
	}
	cout << ss.size() << endl;
	for (auto iter = ss.begin(); iter != ss.end(); iter++) {
		cout << *iter << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#if 1
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <utility>
#include <string>
#include <algorithm>
#include <bitset>
using namespace std;
typedef char ch;
typedef string st;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef set<ll> sl;
const ll INF = 1000000000000;
#define wh while
#define bs bitset
#define mp make_pair
#define in1(a) cin >> a;
#define in2(a, b) cin >> a >> b;
#define in3(a, b, c) cin >> a >> b >> c;
#define in4(a, b, c, d) cin >> a >> b >> c >> d;
#define ou1(a) cout << a;
#define ou2(a, b) cout << a << b;
#define ou3(a, b, c) cout << a << b << c;
#define ou4(a, b, c, d) cout << a << b << c << d;
#define fi(i, n) for (ll i=0; i<n; i++)
#define fd(i, n) for (ll i=n; i>=0; i--)
#define all(a) a.begin(), a.end()
#define yes cout << "YES";
#define no cout << "NO";
#define imp cout << "IMPOSSIBLE";
#define stop cout << endl, system("pause");
#define maxf(a,b) (a>b) ? (a) : (b)
#define minf(a,b) (a<b) ? (a) : (b)
#define ex exit(0);
#define ts to_string
#define re freopen("a.in", "r", stdin)
#define wr freopen("a.out", "w", stdout)
#endif
set<st> ss;
vl v;
ll d;
st s;
bool suff(ll n, st pr) {
	if (n < d) v[n] = 1;
	if (d - n == 0) return 1;
	else if (d - n == 1 || n > d) return 0;
	st s2 = "", s3 = "";
	s2 += s[n]; s2 += s[n + 1];
	if (d - n > 2) {
		s3 += s[n];
		s3 += s[n + 1];
		s3 += s[n + 2];
	}
	else s3 = pr;
	ll k = 0;
	if (s2 != pr) {
		if (suff(n + 2, s2)) {
			ss.insert(s2); k++;
		}
	}
	if (s3 != pr) {
		if (suff(n + 3, s3)) {
			ss.insert(s3); k++;
		}
	}
	if (k) return 1; else return 0;
}
int main() {
	cin >> s;
	d = s.size();
	v.resize(d, 0);
	for (ll i = 5; i <= d - 2; i++) {
		if (!v[i]) suff(i, "");
	}
	cout << ss.size() << endl;
	ll i = 0;
	for (auto iter = ss.begin(); iter != ss.end(); iter++, i++) {
		cout << *iter << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#if 1
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <utility>
#include <string>
#include <algorithm>
#include <bitset>
using namespace std;
typedef char ch;
typedef string st;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef set<ll> sl;
const ll INF = 1000000000000;
#define wh while
#define bs bitset
#define mp make_pair
#define in1(a) cin >> a;
#define in2(a, b) cin >> a >> b;
#define in3(a, b, c) cin >> a >> b >> c;
#define in4(a, b, c, d) cin >> a >> b >> c >> d;
#define ou1(a) cout << a;
#define ou2(a, b) cout << a << b;
#define ou3(a, b, c) cout << a << b << c;
#define ou4(a, b, c, d) cout << a << b << c << d;
#define fi(i, n) for (ll i=0; i<n; i++)
#define fd(i, n) for (ll i=n; i>=0; i--)
#define all(a) a.begin(), a.end()
#define yes cout << "YES";
#define no cout << "NO";
#define imp cout << "IMPOSSIBLE";
#define stop cout << endl, system("pause");
#define maxf(a,b) (a>b) ? (a) : (b)
#define minf(a,b) (a<b) ? (a) : (b)
#define ex exit(0);
#define ts to_string
#define re freopen("a.in", "r", stdin)
#define wr freopen("a.out", "w", stdout)
#endif
set<st> ss;
vl v;
ll d;
st s;
bool suff(ll n, st pr) {
	if (n < d) v[n] = 1;
	if (d - n == 0) return 1;
	else if (d - n == 1 || n > d) return 0;
	st s2 = "", s3 = "";
	s2 += s[n]; s2 += s[n + 1];
	if (d - n > 2) {
		s3 += s[n];
		s3 += s[n + 1];
		s3 += s[n + 2];
	}
	else s3 = pr;
	if (s2 != pr) {
		if (suff(n + 2, s2)) {
			ss.insert(s2); return 1;
		}
	}
	if (s3 != pr) {
		if (suff(n + 3, s3)) {
			ss.insert(s3); return 1;
		}
	}
	return 0;
}
int main() {
	cin >> s;
	d = s.size();
	v.resize(d, 0);
	for (ll i = 5; i <= d - 2; i++) {
		if (!v[i]) suff(i, "");
	}
	cout << ss.size() << endl;
	ll i = 0;
	for (auto iter = ss.begin(); iter != ss.end(); iter++, i++) {
		cout << *iter << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#if 1
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <utility>
#include <string>
#include <algorithm>
#include <bitset>
using namespace std;
typedef char ch;
typedef string st;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef set<ll> sl;
const ll INF = 1000000000000;
#define wh while
#define bs bitset
#define mp make_pair
#define in1(a) cin >> a;
#define in2(a, b) cin >> a >> b;
#define in3(a, b, c) cin >> a >> b >> c;
#define in4(a, b, c, d) cin >> a >> b >> c >> d;
#define ou1(a) cout << a;
#define ou2(a, b) cout << a << b;
#define ou3(a, b, c) cout << a << b << c;
#define ou4(a, b, c, d) cout << a << b << c << d;
#define fi(i, n) for (ll i=0; i<n; i++)
#define fd(i, n) for (ll i=n; i>=0; i--)
#define all(a) a.begin(), a.end()
#define yes cout << "YES";
#define no cout << "NO";
#define imp cout << "IMPOSSIBLE";
#define stop cout << endl, system("pause");
#define maxf(a,b) (a>b) ? (a) : (b)
#define minf(a,b) (a<b) ? (a) : (b)
#define ex exit(0);
#define ts to_string
#define re freopen("a.in", "r", stdin)
#define wr freopen("a.out", "w", stdout)
#endif
set<st> ss;
vl v;
ll d;
st s;
bool suff(ll n, st pr) {
	if (n<d) if (v[n] != -1) return v[n];
	if (d - n == 0) {
		v[n] = 1; return 1;
	}
	else if (d - n == 1 || n > d) {
		v[n] = 0; return 0;
	}
	st s2 = "", s3 = "";
	s2 += s[n]; s2 += s[n + 1];
	if (d - n > 2) {
		s3 += s[n];
		s3 += s[n + 1];
		s3 += s[n + 2];
	}
	else s3 = pr;
	ll k = 0;
	if (s2 != pr) {
		if (suff(n + 2, s2)) {
			ss.insert(s2); k++;
		}
	}
	if (s3 != pr) {
		if (suff(n + 3, s3)) {
			ss.insert(s3); k++;
		}
	}
	if (k) {
		v[n] = 1; return 1;
	}
	else {
		v[n] = 0; return 0;
	}
}
int main() {
	cin >> s;
	d = s.size();
	v.resize(d, -1);
	if (d > 6) suff(5, "");
	if (d > 7) suff(6, "");
	cout << ss.size() << endl;
	ll i = 0;
	for (auto iter = ss.begin(); iter != ss.end(); iter++, i++) {
		cout << *iter << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>

#define PI 3.14159265358979323846
#define PO << " " <<
#define P " "
#define ABS(x) (((x) > 0) ? (x) : (-(x)))
#define RND(x) ((int)( (x) + 0.5 ))
#define MAX(x, y) (( (x) > (y) ) ? (x) : (y))
#define MIN(x, y) (( (x) < (y) ) ? (x) : (y))
#define LOOP(i, ending) for (int i = 0; i < ending; i++)
#define IT(v) v.begin(), v.end()

typedef long long int lint;
typedef unsigned long long int ulint;
typedef std::pair <int, int> pint;

using namespace std;

int main()
{
	string s; cin >> s;
	s = s.substr(5);
	int n = s.length();
	set <string> ans;

	vector <char> a(n), b(n); //2, 3

	for (int i = n - 1; i >= 0; i--) {
		if (i + 2 == n)
			a[i] = true;
		if (i + 3 == n)
			b[i] = true;
		if (i + 3 < n) {
			if (a[i + 2] && s.substr(i, 2) != s.substr(i + 2, 2) || b[i + 2])
				a[i] = true;
			if (b[i + 3] && s.substr(i, 3) != s.substr(i + 3, 3) || a[i + 3])
				b[i] = true;
		}
		if (a[i] == true)
			ans.insert(s.substr(i, 2));
		if (b[i] == true)
			ans.insert(s.substr(i, 3));
	}

	cout << ans.size() << endl;
	for (set<string> ::iterator i = ans.begin(); i != ans.end(); ++i)
		cout << *i << endl;
	return 0;
}


//#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:2899887000")
#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <bitset>
#include <map>
#include <iostream>
#include <iomanip>
#include <stack>
#include <string>
#include <random>
#include <list>
#include <functional>
#include <utility>
#include <numeric>
#include <cstring>
#include <memory>

using namespace std;

#define LOCAL 0
#define ll long long
#define uint unsigned int
#define get_time (int)(clock() * 1000.0 / CLOCKS_PER_SEC)

const int MAXN = (int)1e4 + 5;

int main()
{
#if LOCAL == 1
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif

    string s;
    cin >> s;

    int n = s.size();

    char uniq[2][MAXN];
    memset(uniq, 0, sizeof(uniq));

    uniq[0][n - 2] = uniq[1][n - 3] = 1;

    for (int i = n - 3; i >= 0; --i)
    {
        if (i + 2 > n)
            uniq[0][i] = 0;
        else if (i + 2 == n)
            uniq[0][i] = 1;
        else if (i + 4 > n)
            uniq[0][i] = 0;
        else if (uniq[1][i + 2] == 1)
            uniq[0][i] = 1;
        else if (s.substr(i, 2) != s.substr(i + 2, 2))
            uniq[0][i] = 1;

        if (i + 3 > n)
            uniq[1][i] = 0;
        else if (i + 3 == n)
            uniq[1][i] = 1;
        else if (i + 4 == n)
            uniq[1][i] = 0;
        else if (uniq[0][i + 3] == 1)
            uniq[1][i] = 1;
        else if (i + 6 <= n && s.substr(i, 3) != s.substr(i + 3, 3))
            uniq[1][i] = 1;
    }

    for (int i = 0; i < 5; ++i)
        uniq[0][i] = uniq[1][i] = 0;

    vector <string> a;

    for (int i = 0; i < n; ++i)
    {
        if (uniq[0][i] == 1)
            a.push_back(s.substr(i, 2));
        if (uniq[1][i] == 1)
            a.push_back(s.substr(i, 3));
    }

    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());

    cout << a.size() << '\n';
    for (int i = 0; i < (int)a.size(); ++i)
        cout << a[i] << '\n';

    return 0;
}


//#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:2899887000")
#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <bitset>
#include <map>
#include <iostream>
#include <iomanip>
#include <stack>
#include <string>
#include <random>
#include <list>
#include <functional>
#include <utility>
#include <numeric>
#include <cstring>
#include <memory>

using namespace std;

#define LOCAL 0
#define ll long long
#define uint unsigned int
#define get_time (int)(clock() * 1000.0 / CLOCKS_PER_SEC)

const int MAXN = (int)1e4 + 5;

int main()
{
#if LOCAL == 1
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif

    string s;
    cin >> s;

    int n = s.size();

    char uniq[2][MAXN];
    memset(uniq, 0, sizeof(uniq));

    for (int i = n - 1; i >= 0; --i)
    {
        if (i + 2 > n)
            uniq[0][i] = 0;
        else if (i + 2 == n)
            uniq[0][i] = 1;
        else if (i + 4 > n)
            uniq[0][i] = 0;
        else if (s.substr(i, 2) != s.substr(i + 2, 2))
            uniq[0][i] = 1;
        else if (uniq[1][i + 2] == 1)
            uniq[0][i] = 1;

        if (i + 3 > n)
            uniq[1][i] = 0;
        else if (i + 3 == n)
            uniq[1][i] = 1;
        else if (i + 6 > n)
            uniq[1][i] = 0;
        else if (s.substr(i, 3) != s.substr(i + 3, 3))
            uniq[1][i] = 1;
        else if (uniq[0][i + 3] == 1)
            uniq[1][i] = 1;
    }

    for (int i = 0; i < 5; ++i)
        uniq[0][i] = uniq[1][i] = 0;

    vector <string> a;

    for (int i = 0; i < n; ++i)
    {
        if (uniq[0][i] == 1)
            a.push_back(s.substr(i, 2));
        if (uniq[1][i] == 1)
            a.push_back(s.substr(i, 3));
    }

    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());

    cout << a.size() << '\n';
    for (int i = 0; i < (int)a.size(); ++i)
        cout << a[i] << '\n';

    return 0;
}


//#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:2899887000")
#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <bitset>
#include <map>
#include <iostream>
#include <iomanip>
#include <stack>
#include <string>
#include <random>
#include <list>
#include <functional>
#include <utility>
#include <numeric>
#include <cstring>
#include <memory>

using namespace std;

#define LOCAL 0
#define ll long long
#define uint unsigned int
#define get_time (int)(clock() * 1000.0 / CLOCKS_PER_SEC)

#define LOCAL 1

const int MAXN = (int)1e4 + 5;

int main()
{
#if LOCAL == 1
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif

    string s;
    cin >> s;

    int n = s.size();

    char uniq[2][MAXN];
    memset(uniq, 0, sizeof(uniq));

    for (int i = n - 1; i >= 0; --i)
    {
        if (i + 2 > n)
            uniq[0][i] = 0;
        else if (i + 2 == n)
            uniq[0][i] = 1;
        else if (i + 4 > n)
            uniq[0][i] = 0;
        else if (s.substr(i, 2) != s.substr(i + 2, 2))
            uniq[0][i] = 1;
        else if (uniq[1][i + 2] == 1)
            uniq[0][i] = 1;

        if (i + 3 > n)
            uniq[1][i] = 0;
        else if (i + 3 == n)
            uniq[1][i] = 1;
        else if (i + 6 > n)
            uniq[1][i] = 0;
        else if (s.substr(i, 3) != s.substr(i + 3, 3))
            uniq[1][i] = 1;
        else if (uniq[0][i + 3] == 1)
            uniq[1][i] = 1;
    }

    for (int i = 0; i < 5; ++i)
        uniq[0][i] = uniq[1][i] = 0;

    vector <string> a;

    for (int i = 0; i < n; ++i)
    {
        if (uniq[0][i] == 1)
            a.push_back(s.substr(i, 2));
        if (uniq[1][i] == 1)
            a.push_back(s.substr(i, 3));
    }

    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());

    cout << a.size() << '\n';
    for (int i = 0; i < (int)a.size(); ++i)
        cout << a[i] << '\n';

    return 0;
}


//#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:2899887000")
#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <bitset>
#include <map>
#include <iostream>
#include <iomanip>
#include <stack>
#include <string>
#include <random>
#include <list>
#include <functional>
#include <utility>
#include <numeric>
#include <cstring>
#include <memory>

using namespace std;

#define LOCAL 0
#define ll long long
#define uint unsigned int
#define get_time (int)(clock() * 1000.0 / CLOCKS_PER_SEC)

const int MAXN = (int)1e4 + 5;

int main()
{
#if LOCAL == 1
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif

    string s;
    cin >> s;

    int n = s.size();

    char uniq[2][MAXN];
    memset(uniq, 0, sizeof(uniq));

    uniq[0][n - 2] = uniq[1][n - 3] = 1;

    for (int i = n - 3; i >= 0; --i)
    {
        if (i + 2 > n)
            uniq[0][i] = 0;
        else if (i + 2 == n)
            uniq[0][i] = 1;
        else if (i + 4 > n)
            uniq[0][i] = 0;
        else if (uniq[1][i + 2] == 1)
            uniq[0][i] = 1;
        else if (uniq[0][i + 2] == 1 && s.substr(i, 2) != s.substr(i + 2, 2))
            uniq[0][i] = 1;

        if (i + 3 > n)
            uniq[1][i] = 0;
        else if (i + 3 == n)
            uniq[1][i] = 1;
        else if (i + 4 == n)
            uniq[1][i] = 0;
        else if (uniq[0][i + 3] == 1)
            uniq[1][i] = 1;
        else if (i + 6 <= n && uniq[1][i + 3] == 1 && s.substr(i, 3) != s.substr(i + 3, 3))
            uniq[1][i] = 1;
    }

    for (int i = 0; i < 5; ++i)
        uniq[0][i] = uniq[1][i] = 0;

    vector <string> a;

    for (int i = 0; i < n; ++i)
    {
        if (uniq[0][i] == 1)
            a.push_back(s.substr(i, 2));
        if (uniq[1][i] == 1)
            a.push_back(s.substr(i, 3));
    }

    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());

    cout << a.size() << '\n';
    for (int i = 0; i < (int)a.size(); ++i)
        cout << a[i] << '\n';

    return 0;
}


#include "stdio.h"
#include "string.h"
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "math.h"
#include "map"
#include "vector"
using namespace std;
using namespace std;

vector<string>ans;
string str;
int vis[10010][5];

void dfs(int x, int len)
{
	if (x<0||vis[x][len])
		return;
	vis[x][len]++;
	ans.push_back(str.substr(x, len));
	if (len == 2)
	{
		if (x >= 2 && str.substr(x,x+1)!=str.substr(x-2,x-1))
			dfs(x - 2, 2);
		if (x >= 3)
			dfs(x - 3, 3);
	}
	else
	{
		if (x >= 3 && str.substr(x,x+2)!=str.substr(x-3,x-1))
			dfs(x - 3, 3);
		if (x >= 2)
			dfs(x - 2, 2);
	}
}

int main()
{
	while (cin >> str)
	{
		ans.clear();
		memset(vis, 0, sizeof(vis));
		str = str.substr(5);
		int len = str.length();
		dfs(len - 2, 2);
		dfs(len - 3, 3);
		cout << ans.size() << endl;
		for (int i = 0;i < ans.size();i++)
			cout << ans[i] << endl;
	}
}


#include "stdio.h"
#include "string.h"
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "math.h"
#include "set"
#include "vector"
using namespace std;

set<string>ans;
string str;
int vis[10010][5];

void dfs(int x, int len)
{
	if (x<0||vis[x][len])
		return;
	vis[x][len]++;
	ans.insert(str.substr(x, len));
	if (len == 2)
	{
		if (x >= 2 && str.substr(x,2)!=str.substr(x-2,2))
			dfs(x - 2, 2);
		if (x >= 3)
			dfs(x - 3, 3);
	}
	else
	{
		if (x >= 3 && str.substr(x,3)!=str.substr(x-3,3))
			dfs(x - 3, 3);
		if (x >= 2)
			dfs(x - 2, 2);
	}
}

int main()
{
	while (cin >> str)
	{
		ans.clear();
		memset(vis, 0, sizeof(vis));
		str = str.substr(5);
		int len = str.length();
		dfs(len - 2, 2);
		dfs(len - 3, 3);
		cout << ans.size() << endl;
		for (set<string>::const_iterator p = ans.cbegin();p != ans.cend();p++)
			cout << *p << endl;
	}
}


#include "stdio.h"
#include "string.h"
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "math.h"
#include "set"
#include "vector"
using namespace std;

set<string>ans;
string str;
int vis[10010][5];

void dfs(int x, int len)
{
	if (x<0||vis[x][len])
		return;
	vis[x][len]++;
	ans.insert(str.substr(x, len));
	if (len == 2)
	{
		if (x >= 2 && str.substr(x,2)!=str.substr(x-2,2))
			dfs(x - 2, 2);
		if (x >= 3)
			dfs(x - 3, 3);
	}
	else
	{
		if (x >= 3 && str.substr(x,3)!=str.substr(x-3,3))
			dfs(x - 3, 3);
		if (x >= 2)
			dfs(x - 2, 2);
	}
}

int main()
{
	while (cin >> str)
	{
		ans.clear();
		memset(vis, 0, sizeof(vis));
		str = str.substr(5);
		int len = str.length();
		dfs(len - 2, 2);
		dfs(len - 3, 3);
		cout << ans.size() << endl;
		sort(ans.begin(), ans.end());
		for (set<string>::const_iterator p = ans.cbegin();p != ans.cend();p++)
			cout << *p << endl;
	}
}


#include "string.h"
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "math.h"
#include "map"
#include "vector"
using namespace std;
using namespace std;

vector<string>ans;
string str;
int vis[10010][5];

void dfs(int x, int len)
{
	if (x<0||vis[x][len])
		return;
	vis[x][len]++;
	ans.push_back(str.substr(x, len));
	if (len == 2)
	{
		if (x >= 2 && str.substr(x,2)!=str.substr(x-2,2))
			dfs(x - 2, 2);
		if (x >= 3)
			dfs(x - 3, 3);
	}
	else
	{
		if (x >= 3 && str.substr(x,3)!=str.substr(x-3,3))
			dfs(x - 3, 3);
		if (x >= 2)
			dfs(x - 2, 2);
	}
}

int main()
{
	while (cin >> str)
	{
		ans.clear();
		memset(vis, 0, sizeof(vis));
		str = str.substr(5);
		int len = str.length();
		dfs(len - 3, 3);
		dfs(len - 2, 2);
		cout << ans.size() << endl;
		sort(ans.begin(), ans.end());
		for (int i = 0;i < ans.size();i++)
			cout << ans[i] << endl;
	}
}


#include "stdio.h"
#include "string.h"
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "math.h"
#include "map"
#include "vector"
using namespace std;
using namespace std;

vector<string>ans;
string str;
int vis[10010][5];

void dfs(int x, int len)
{
	if (x<0||vis[x][len])
		return;
	vis[x][len]++;
	ans.push_back(str.substr(x, len));
	if (len == 2)
	{
		if (x >= 2 && str.substr(x,x+1)!=str.substr(x-2,x-1))
			dfs(x - 2, 2);
		if (x >= 3)
			dfs(x - 3, 3);
	}
	else
	{
		if (x >= 3 && str.substr(x,x+2)!=str.substr(x-3,x-1))
			dfs(x - 3, 3);
		if (x >= 2)
			dfs(x - 2, 2);
	}
}

int main()
{
	while (cin >> str)
	{
		ans.clear();
		memset(vis, 0, sizeof(vis));
		str = str.substr(5);
		int len = str.length();
		dfs(len - 3, 3);
		dfs(len - 2, 2);
		cout << ans.size() << endl;
		sort(ans.begin(), ans.end());
		for (int i = 0;i < ans.size();i++)
			cout << ans[i] << endl;
	}
}


#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

#define MR 10010

char s[MR];

map < int, bool > dp[MR];

int main()
{
	scanf("%s", s);
	map<string, int> M;
	M[""] = 0;
	int cnt = 1;
	FORQ(i, 'a', 'z')FORQ(j, 'a', 'z')
	{
		string s = ""; s += i; s += j;
		M[s] = cnt++;
	}
	FORQ(i, 'a', 'z')FORQ(j, 'a', 'z')FORQ(k,'a','z')
	{
		string s = ""; s += i; s += j; s += k;
		M[s] = cnt++;
	}
	set<string> S;
	int n = strlen(s);
	dp[n][0] = 1;
	FORD(i, n-1, 5)
	{
		string s1 = string(s + i, s + i + 2);
		int ind = M[s1];
		for (auto it = dp[i + 2].begin(); it != dp[i + 2].end(); it++)
		{
			if (it->first != ind)
				dp[i][ind] = 1;
		}
		if (dp[i][ind]) S.insert(s1);

		if (i + 3 > n) continue;

		s1 = string(s + i, s + i + 3);
		ind = M[s1];
		for (auto it = dp[i + 3].begin(); it != dp[i + 3].end(); it++)
		{
			if (it->first != ind)
				dp[i][ind] = 1;
		}
		if (dp[i][ind]) S.insert(s1);
	}

	printf("%d\n", S.size());
	for (auto it = S.begin(); it != S.end(); it++) printf("%s\n", it->c_str());
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

#define MR 10010

char s[MR];

map < int, bool > dp[MR];

int main()
{
	scanf("%s", s);
	map<string, int> M;
	M[""] = 0;
	int cnt = 1;
	FORQ(i, 'a', 'z')FORQ(j, 'a', 'z')
	{
		string s = ""; s += i; s += j;
		M[s] = cnt++;
	}
	FORQ(i, 'a', 'z')FORQ(j, 'a', 'z')FORQ(k,'a','z')
	{
		string s = ""; s += i; s += j; s += k;
		M[s] = cnt++;
	}
	set<string> S;
	int n = strlen(s);
	dp[n][0] = 1;
	FORD(i, n-1, 5)
	{
		string s1 = string(s + i, s + i + 2);
		int ind = M[s1];
		dp[i][ind] = 0;
		for (auto it = dp[i + 2].begin(); it != dp[i + 2].end(); it++)
		{
			if (it->first != ind)
				dp[i][ind] = 1;
		}
		if (dp[i][ind]) S.insert(s1);

		if (i + 3 > n) continue;

		s1 = string(s + i, s + i + 3);
		ind = M[s1];
		dp[i][ind] = 0;
		for (auto it = dp[i + 3].begin(); it != dp[i + 3].end(); it++)
		{
			if (it->first != ind)
				dp[i][ind] = 1;
		}
		if (dp[i][ind]) S.insert(s1);
	}

	printf("%d\n", S.size());
	for (auto it = S.begin(); it != S.end(); it++) printf("%s\n", it->c_str());
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

#define MR 10010

char s[MR];

map < int, bool > dp[MR];

int main()
{
	scanf("%s", s);
	map<string, int> M;
	M[""] = 0;
	int cnt = 1;
	FORQ(i, 'a', 'z')FORQ(j, 'a', 'z')
	{
		string s = ""; s += i; s += j;
		M[s] = cnt++;
	}
	FORQ(i, 'a', 'z')FORQ(j, 'a', 'z')FORQ(k,'a','z')
	{
		string s = ""; s += i; s += j; s += k;
		M[s] = cnt++;
	}
	set<string> S;
	int n = strlen(s);
	dp[n][0] = 1;
	FORD(i, n-1, 5)
	{
		string s1 = string(s + i, s + i + 2);
		int ind = M[s1];
		dp[i][ind] = 0;
		for (auto it = dp[i + 2].begin(); it != dp[i + 2].end(); it++)
		{
			if (it->first != ind && it->second)
				dp[i][ind] = 1;
		}
		if (dp[i][ind]) S.insert(s1);

		if (i + 3 > n) continue;

		s1 = string(s + i, s + i + 3);
		ind = M[s1];
		dp[i][ind] = 0;
		for (auto it = dp[i + 3].begin(); it != dp[i + 3].end(); it++)
		{
			if (it->first != ind && it->second)
				dp[i][ind] = 1;
		}
		if (dp[i][ind]) S.insert(s1);
	}

	printf("%d\n", S.size());
	for (auto it = S.begin(); it != S.end(); it++) printf("%s\n", it->c_str());
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <set>
using namespace std;
bool can[200005];
string s;
set<string> all;
int main(){
	cin>>s;
	can[(int)s.size()] = true;
	for(int i=(int)s.size()-2;i>=5;i--){
		if(can[i+2] == true){all.insert(s.substr(i,2));can[i]=true;}
		if(can[i+3] == true){all.insert(s.substr(i,3));can[i]=true;}
	}
	cout<<(int)all.size()<<endl;
	for(set<string>::iterator it = all.begin();it != all.end();it++){
		cout<<(*it)<<endl;
	}
}


#include <iostream>
#include <vector>
#include <string>
#include <set>
using namespace std;
bool can[20005][2];
string s;
set<string> all;
int main(){
	cin>>s;
	can[(int)s.size()][1] = can[(int)s.size()][0] = true;
	for(int i=(int)s.size()-2;i>=5;i--){
		if(can[i+2][1] == true || (can[i+2][0] == true && s.substr(i,2) != s.substr(i+2,2))){
			all.insert(s.substr(i,2));
			can[i][0]=true;
		}
		if(can[i+3][0] == true || (can[i+3][1] == true && s.substr(i,3) != s.substr(i+3,3))){
			all.insert(s.substr(i,3));
			can[i][1]=true;
		}
	}
	cout<<(int)all.size()<<endl;
	for(set<string>::iterator it = all.begin();it != all.end();it++){
		cout<<(*it)<<endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <list>
#include <set>
#include <cstdlib>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <stack>
#include <ctime>
#include <queue>
#include <map>
#include <cstring>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef bool bl;
typedef pair<bl, bl> pbl;
typedef pair<ld, ld> pld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define mp make_pair
#define ft first
#define sd second
#define forn(i, y, x) for(int i = y; i < x; i++)
#define ford(i, y, x) for(int i = y; i >= x; i--)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define error exit(1)
#define DEBUG
const int mod = (int)1e9;
const ll inf = (ll)2e18;
const int base = 1000 * 1000 * 1000;
const int maxn = 1000005;
const ld pi = acosl(-1.0);
const ld eps = 1e-9;

bool cmp(string &s, int i, int a, int j, int b)
{
	if (a != b) return true;
	else{
		forn(k, 0, a) if (s[i + k] != s[j + k]){
			return true;
		}
	}
	return false;
}

char buff[12345];

void solve()
{
	scanf("%s", buff);
	string s(buff);
	int n = sz(s);
	set<string> ans;
	vector<pair<bool, bool>> u(n, mp(false, false));
	if (n > 6){
		if (n >= 7){
			u[n - 2].ft = true;
			string t = "";
			t = t + s[n - 2] + s[n - 1];
			ans.insert(t);
		}
		if (n >= 8){
			u[n - 3].sd = true;
			string t = "";
			t = t + s[n - 3] + s[n - 2] + s[n - 1];
			ans.insert(t);
		}
		ford(i, n - 4, 5){
			int p = i + 2;
			if (u[p].ft && cmp(s, i, 2, p, 2) ||
				u[p].sd && cmp(s, i, 2, p, 3)){
				string t = "";
				t = t + s[i] + s[i + 1];
				ans.insert(t);
				u[i].ft = true;
			}
			p++;
			if (u[p].ft && cmp(s, i, 3, p, 2) ||
				u[p].sd && cmp(s, i, 3, p, 3)){
				string t = "";
				t = s[i] + s[i + 1] + s[i + 2];
				ans.insert(t);
				u[i].sd = true;
			}
		}
	}
	printf("%d\n", sz(ans));
	while (sz(ans)){
		printf("%s\n", (*ans.begin()).c_str());
		ans.erase(ans.begin());
	}
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <list>
#include <set>
#include <cstdlib>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <stack>
#include <ctime>
#include <queue>
#include <map>
#include <cstring>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef bool bl;
typedef pair<bl, bl> pbl;
typedef pair<ld, ld> pld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define mp make_pair
#define ft first
#define sd second
#define forn(i, y, x) for(int i = y; i < x; i++)
#define ford(i, y, x) for(int i = y; i >= x; i--)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define error exit(1)
#define DEBUG
const int mod = (int)1e9;
const ll inf = (ll)2e18;
const int base = 1000 * 1000 * 1000;
const int maxn = 1000005;
const ld pi = acosl(-1.0);
const ld eps = 1e-9;

bool cmp(string &s, int i, int a, int j, int b)
{
	if (a != b) return true;
	else{
		forn(k, 0, a) if (s[i + k] != s[j + k]){
			return true;
		}
	}
	return false;
}

char buff[12345];

void solve()
{
	scanf("%s", buff);
	string s(buff);
	int n = sz(s);
	set<string> ans;
	vector<pair<bool, bool>> u(n, mp(false, false));
	if (n > 6){
		if (n >= 7){
			u[n - 2].ft = true;
			string t = "";
			t = t + s[n - 2] + s[n - 1];
			ans.insert(t);
		}
		if (n >= 8){
			u[n - 3].sd = true;
			string t = "";
			t = t + s[n - 3] + s[n - 2] + s[n - 1];
			ans.insert(t);
		}
		ford(i, n - 4, 5){
			int p = i + 2;
			if (u[p].ft && cmp(s, i, 2, p, 2) ||
				u[p].sd && cmp(s, i, 2, p, 3)){
				string t = "";
				t = t + s[i] + s[i + 1];
				ans.insert(t);
				u[i].ft = true;
			}
			p++;
			if (u[p].ft && cmp(s, i, 3, p, 2) ||
				u[p].sd && cmp(s, i, 3, p, 3)){
				string t = "";
				t = t + s[i] + s[i + 1] + s[i + 2];
				ans.insert(t);
				u[i].sd = true;
			}
		}
	}
	printf("%d\n", sz(ans));
	while (sz(ans)){
		printf("%s\n", (*ans.begin()).c_str());
		ans.erase(ans.begin());
	}
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();
	return 0;
}


#pragma comment(linker, "/STACK:134217728")
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <numeric>
#include <complex>
#include <functional>
#include <cmath>
#include <time.h>

using namespace std;

typedef long long LL;

string s;

bool used[111111][5];
set<string> answ;
void go(int pos, int len)
{
	if (pos < 5)
		return;
	if (used[pos][len])
		return;
	used[pos][len] = true;
	string s1 = "";
	string s2 = "";
	string s3 = "";
	for (int i = 0; i < len; i++)
		s1 += s[pos - i];
	if (pos - len - 2 >= 4) {
		for (int i = 0; i < 2; i++)
			s2 += s[pos - len - i];
	}
	if (pos - len - 3 >= 4) {
		for (int i = 0; i < 3; i++)
			s3 += s[pos - len - i];
	}
	reverse(s1.begin(), s1.end());
	reverse(s2.begin(), s2.end());
	reverse(s3.begin(), s3.end());
	answ.insert(s1);
	if (s1 != s2 && s2 != "") {
		answ.insert(s2);
		go(pos - len, 2);
	}
	if (s1 != s3 && s3 != "") {
		answ.insert(s3);
		go(pos - len, 3);
	}
}
int main()
{
	int n;
	cin >> s;
	if (s.size() > 6)
	go(s.length() - 1, 2);
	if (s.size() > 7)
	go(s.length() - 1, 3);
	cout << answ.size() << endl;
	for (set<string>::iterator it = answ.begin(); it != answ.end(); it++) {
		string  t = *it;
		cout << t << endl;
	}
	return 0;
}


#pragma comment(linker, "/STACK:134217728")
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <numeric>
#include <complex>
#include <functional>
#include <cmath>
#include <time.h>

using namespace std;

typedef long long LL;

string s;

bool used[111111][5];
set<string> answ;
void go(int pos, int len)
{
	if (pos < 5)
		return;
	if (used[pos][len])
		return;
	used[pos][len] = true;
	string s1 = "";
	string s2 = "";
	string s3 = "";
	for (int i = 0; i < len; i++)
		s1 += s[pos - i];
	if (pos - len - 2 >= 4) {
		for (int i = 0; i < 2; i++)
			s2 += s[pos - len - i];
	}
	if (pos - len - 3 >= 4) {
		for (int i = 0; i < 3; i++)
			s3 += s[pos - len - i];
	}
	reverse(s1.begin(), s1.end());
	reverse(s2.begin(), s2.end());
	reverse(s3.begin(), s3.end());
	answ.insert(s1);
	if (s1 != s2 && s2 != "") {
		answ.insert(s2);
		go(pos - len, 2);
	}
	if (s1 != s3 && s3 != "") {
		answ.insert(s3);
		go(pos - len, 3);
	}
}
int main()
{
	int n;
	cin >> s;
	go(s.length() - 1, 2);
	go(s.length() - 1, 3);
	cout << answ.size() << endl;
	for (set<string>::iterator it = answ.begin(); it != answ.end(); it++) {
		string  t = *it;
		cout << t << endl;
	}
	return 0;
}


#include <iostream>
#include <string>
#include <set>
#include <vector>

using namespace std;

set<string> ans;

string s;
vector<string> st;

void dfs(int pos) {
	if (pos == s.length()) {
		for (int i = 0; i < st.size(); ++i) {
			ans.insert(st[i]);
		}
	}

	else {
		if (pos <= s.length() - 2) {
			string s2 = s.substr(pos, 2);
			if (st.empty() || s2 != st[st.size() - 1]) {
			    st.push_back(s2);
			    dfs(pos + 2);
			    st.pop_back();
			}
		}
		if (pos <= s.length() - 3) {
			string s2 = s.substr(pos, 3);
			if (st.empty() || s2 != st[st.size() - 1]) {
			    st.push_back(s2);
			    dfs(pos + 3);
			    st.pop_back();
			}
		}
	}
}

int main() {
	cin >> s;
	dfs(5);
	dfs(6);
	dfs(7);
	dfs(8);
	dfs(9);

	cout << ans.size() << endl;
	for (set<string>::iterator it = ans.begin(); it != ans.end(); ++it) {
		cout << *it << endl;
	}

	return 0;
}


#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <unordered_map>

using namespace std;

bool two[10002], three[10002];

set<string> ans;

string s;

int main() {
	cin >> s;
	if (s.length() > 7) {
		three[s.length() - 1] = true;
		ans.insert(s.substr(s.length() - 3, 3));
	}
	if (s.length() > 6) {
		two[s.length() - 1] = true;
		ans.insert(s.substr(s.length() - 2, 2));
	}

	for (int i = s.length() - 3; i >= 6; --i) {
		if (i <= s.length() - 3 && two[i + 2]) {
			if (!(s[i - 1] == s[i + 1] && s[i] == s[i + 2])) {
				two[i] = true;
				ans.insert(s.substr(i - 1, 2));
			}
		}
		if (i <= s.length() - 4 && i >= 7 && three[i + 3]) {
			if (!(s[i - 2] == s[i + 1] && s[i - 1] == s[i + 2] && s[i] == s[i + 3])) {
				three[i] = true;
				ans.insert(s.substr(i - 2, 3));
			}
		}
	}

	cout << ans.size() << endl;
	for (set<string>::iterator it = ans.begin(); it != ans.end(); ++it) {
		cout << *it << endl;
	}

	return 0;
}


#include <iostream>
#include <string>
#include <set>
#include <vector>

using namespace std;

set<string> ans;

string s;
vector<string> st;

void dfs(int pos) {
	if (pos == s.length()) {
		for (int i = 0; i < st.size(); ++i) {
			ans.insert(st[i]);
		}
	}

	else {
		if (pos <= s.length() - 2) {
			string s2 = s.substr(pos, 2);
			if (st.empty() || s2 != st[st.size() - 1]) {
			    st.push_back(s2);
			    dfs(pos + 2);
			    st.pop_back();
			}
		}
		if (pos <= s.length() - 3) {
			string s2 = s.substr(pos, 3);
			if (st.empty() || s2 != st[st.size() - 1]) {
			    st.push_back(s2);
			    dfs(pos + 3);
			    st.pop_back();
			}
		}
	}
}

int main() {
	cin >> s;
	for (int i = 5; i <= s.length() - 2; ++i) {
		dfs(i);
	}

	cout << ans.size() << endl;
	for (set<string>::iterator it = ans.begin(); it != ans.end(); ++it) {
		cout << *it << endl;
	}
	return 0;
}


#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <unordered_map>

using namespace std;

bool two[10002], three[10002];

set<string> ans;

string s;

int main() {
	cin >> s;
	s.erase(0, 5);
	if (s.length() > 2) {
		three[s.length() - 1] = true;
		ans.insert(s.substr(s.length() - 3, 3));
	}
	if (s.length() > 1) {
		two[s.length() - 1] = true;
		ans.insert(s.substr(s.length() - 2, 2));
	}

	for (int i = s.length() - 3; i >= 1; --i) {
		if (i <= s.length() - 3 && two[i + 2]) {
			if (!(s[i - 1] == s[i + 1] && s[i] == s[i + 2])) {
				two[i] = true;
				ans.insert(s.substr(i - 1, 2));
			}
			if (i >= 2) {
				three[i] = true;
				ans.insert(s.substr(i - 2, 3));
			}
		}
		if (i <= s.length() - 4 && i >= 2 && three[i + 3]) {
			if (!(s[i - 2] == s[i + 1] && s[i - 1] == s[i + 2] && s[i] == s[i + 3])) {
				three[i] = true;
				ans.insert(s.substr(i - 2, 3));
			}
			two[i] = true;
			ans.insert(s.substr(i - 1, 2));
		}
	}

	cout << ans.size() << endl;
	for (set<string>::iterator it = ans.begin(); it != ans.end(); ++it) {
		cout << *it << endl;
	}

	return 0;
}


#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <unordered_map>

using namespace std;

bool two[10002], three[10002];

set<string> ans;

string s;

int main() {
	cin >> s;
	s.erase(0, 5);
	if (s.length() > 2) {
		three[s.length() - 1] = true;
		ans.insert(s.substr(s.length() - 3, 3));
	}
	if (s.length() > 1) {
		two[s.length() - 1] = true;
		ans.insert(s.substr(s.length() - 2, 2));
	}

	for (int i = s.length() - 3; i >= 1; --i) {
		if (i <= s.length() - 3 && two[i + 2]) {
			if (!(s[i - 1] == s[i + 1] && s[i] == s[i + 2])) {
				two[i] = true;
				ans.insert(s.substr(i - 1, 2));
			}
			if (i >= 2) {
				three[i] = true;
				ans.insert(s.substr(i - 2, 3));
			}
		}
		if (i <= s.length() - 4 && i >= 2 && three[i + 3]) {
			if (!(s[i - 2] == s[i + 1] && s[i - 1] == s[i + 2] && s[i] == s[i + 3])) {
				three[i] = true;
				ans.insert(s.substr(i - 2, 3));
			}
			two[i] = true;
			ans.insert(s.substr(i - 1, 2));
		}
	}

	cout << ans.size() << endl;
	for (set<string>::iterator it = ans.begin(); it != ans.end(); ++it) {
		cout << *it << endl;
	}

	for (int i = 0; i < s.length(); ++i) {
		cout << int(two[i]);
	}
	cout << endl;
	for (int i = 0; i < s.length(); ++i) {
		cout << int(three[i]);
	}
	return 0;
}


#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <unordered_map>

using namespace std;

set<string> ans;

string s;
vector<string> st;
unordered_map<int, set<string>> used;

void dfs(int pos) {
	if (!st.empty() && used[pos].find(st[st.size() - 1]) != used[pos].end()) {
		return;
	}
	if (!st.empty()) used[pos].insert(st[st.size() - 1]);

	if (pos == s.length()) {
		for (int i = 0; i < st.size(); ++i) {
			ans.insert(st[i]);
		}
	}

	else {
		if (pos <= s.length() - 2) {
			string s2 = s.substr(pos, 2);
			if (st.empty() || s2 != st[st.size() - 1]) {
			    st.push_back(s2);
			    dfs(pos + 2);
			    st.pop_back();
			}
		}
		if (pos <= s.length() - 3) {
			string s2 = s.substr(pos, 3);
			if (st.empty() || s2 != st[st.size() - 1]) {
			    st.push_back(s2);
			    dfs(pos + 3);
			    st.pop_back();
			}
		}
	}
}

int main() {
	cin >> s;
	dfs(5);
	dfs(6);
	dfs(7);
	dfs(8);
	dfs(9);

	cout << ans.size() << endl;
	for (set<string>::iterator it = ans.begin(); it != ans.end(); ++it) {
		cout << *it << endl;
	}

	return 0;
}


#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <unordered_map>

using namespace std;

set<string> ans;

string s;
vector<string> st;
unordered_map<string, set<int>> used;

void dfs(int pos) {
	if (!st.empty() && used[st[st.size() - 1]].find(pos) != used[st[st.size() - 1]].end()) {
		return;
	}
	if (!st.empty()) used[st[st.size() - 1]].insert(pos);

	if (pos == s.length()) {
		for (int i = 0; i < st.size(); ++i) {
			ans.insert(st[i]);
		}
	}

	else {
		if (pos <= s.length() - 2) {
			string s2 = s.substr(pos, 2);
			if (st.empty() || s2 != st[st.size() - 1]) {
			    st.push_back(s2);
			    dfs(pos + 2);
			    st.pop_back();
			}
		}
		if (pos <= s.length() - 3) {
			string s2 = s.substr(pos, 3);
			if (st.empty() || s2 != st[st.size() - 1]) {
			    st.push_back(s2);
			    dfs(pos + 3);
			    st.pop_back();
			}
		}
	}
}

int main() {
	cin >> s;
	dfs(5);
	dfs(6);
	dfs(7);
	dfs(8);
	dfs(9);

	cout << ans.size() << endl;
	for (set<string>::iterator it = ans.begin(); it != ans.end(); ++it) {
		cout << *it << endl;
	}

	return 0;
}


#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <unordered_map>

using namespace std;

bool two[10002], three[10002];

set<string> ans;

string s;

int main() {
	cin >> s;
	s.erase(0, 5);
	if (s.length() > 2) {
		three[s.length() - 1] = true;
		ans.insert(s.substr(s.length() - 3, 3));
	}
	if (s.length() > 1) {
		two[s.length() - 1] = true;
		ans.insert(s.substr(s.length() - 2, 2));
	}

	for (int i = s.length() - 3; i >= 1; --i) {
		if (i <= s.length() - 3 && two[i + 2]) {
			if (!(s[i - 1] == s[i + 1] && s[i] == s[i + 2])) {
				two[i] = true;
				ans.insert(s.substr(i - 1, 2));
			}
			if (i >= 2) {
				three[i] = true;
				ans.insert(s.substr(i - 2, 3));
			}
		}
		if (i <= s.length() - 4 && i >= 2 && three[i + 3]) {
			if (!(s[i - 2] == s[i + 1] && s[i - 1] == s[i + 2] && s[i] == s[i + 3])) {
				three[i] = true;
				ans.insert(s.substr(i - 2, 3));
			}
		}
		if (i <= s.length() - 4 && three[i + 3]) {
			two[i] = true;
			ans.insert(s.substr(i - 1, 2));
		}
	}

	cout << ans.size() << endl;
	for (set<string>::iterator it = ans.begin(); it != ans.end(); ++it) {
		cout << *it << endl;
	}

	return 0;
}


#include <iostream>
#include <string>
#include <set>
#include <vector>

using namespace std;

set<string> ans;

string s;
vector<string> st;

void dfs(int pos) {
	if (pos == s.length()) {
		for (int i = 0; i < st.size(); ++i) {
			ans.insert(st[i]);
		}
	}

	else {
		if (pos <= s.length() - 2) {
			string s2 = s.substr(pos, 2);
			if (st.empty() || s2 != st[st.size() - 1]) {
			    st.push_back(s2);
			    dfs(pos + 2);
			    st.pop_back();
			}
		}
		if (pos <= s.length() - 3) {
			string s2 = s.substr(pos, 3);
			if (st.empty() || s2 != st[st.size() - 1]) {
			    st.push_back(s2);
			    dfs(pos + 3);
			    st.pop_back();
			}
		}
	}
}

int main() {
	cin >> s;
	for (int i = 5; i < s.length() - 2; ++i) {
		dfs(i);
	}

	cout << ans.size() << endl;
	for (set<string>::iterator it = ans.begin(); it != ans.end(); ++it) {
		cout << *it << endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <stack>
#include <time.h>
#include <vector>
#include <set>
#include <string>
#include <fstream>

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define endl "\n"
#define mp make_pair
#define pll pair<ll,ll>

bool dp[12345][2];
int main()
{
	ios_base::sync_with_stdio(0);

	string s;
	cin >> s;
	int size = s.size();
	s += "12345";
	set<string> ans;
	dp[size+1][0] = 1;
	dp[size+2][1] = 1;
	for(int i = size - 1; i >= 5; --i)
	{
		// dp[i][0] for 2
		// dp[i][1] for 3

		for(int j = 0; j < 2; ++j)
		{
			string cur = s.substr(i-j-1,j+2);
			if(i-j-1>=5)
			{
				string nx = s.substr(i+1,j+2);
				if(nx != cur)
					dp[i][j] |= dp[i+j+2][j];
				if(j == 0)
					dp[i][j] |= dp[i+3][1];
				else
					dp[i][j] |= dp[i+2][0];
			}
			if(dp[i][j])
				ans.insert(cur);
		}

	}

	cout << ans.size() << "\n";
	for(set<string>::iterator it = ans.begin(); it != ans.end(); ++it)
		cout << *it << "\n";
	return 0;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <stack>
#include <time.h>
#include <vector>
#include <set>
#include <string>
#include <fstream>

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define endl "\n"
#define mp make_pair
#define pll pair<ll,ll>

ifstream in("task.in");
ofstream out("task.out");
/*
#define cin in
#define cout out
/**/

int main()
{
	ios_base::sync_with_stdio(0);

	string s;
	cin >> s;
	int size = s.size();
	set<string> ans;

	for(int i = size-1; i >= 5; --i)
	{
		string cur = s.substr(i-1, 2);
		string cur2 = s.substr(i-2, 3);
		{
			bool ok = 1;
			if(i == size-2 || i-1 <= 4)
				ok = 0;

			if(ok)
				ans.insert(cur);
		}
		{
			bool ok = 1;
			if(i == size-2 || i-2 <= 4)
				ok = 0;

			if(ok)
				ans.insert(cur2);
		}
	}

	cout << ans.size() << "\n";
	for(set<string>::iterator it = ans.begin(); it != ans.end(); ++it)
	{
		cout << *it << "\n";
	}
	return 0;
}


#include<iostream>

using namespace std;

int main(void)
{
	long long cases = 0, a, all = 0, b = 0, yu, maxx = 0;

	cin>>cases;
	for(int j = 0;j < cases; j++)
	{
		cin>>a;

		for(int n = 0;n < a; n++)
			{
				cin>>b;
				all += b;
				maxx = max(maxx, b);
			}

		if(a == 2)
			{
				cout<< 0 <<endl;
				all = 0;
				maxx = 0;
				continue;
			}

		yu = (a - 1) * maxx - all;

		if(yu < 0)
			yu = (a - 1) + yu % (a - 1);

		cout<<yu<<endl;

		all = 0;
		maxx = 0;
	}

	return 0;
}


#include<iostream>

using namespace std;

int main(void)
{
	long long cases = 0, a, all = 0, b = 0, yu, maxx = 0;

	cin>>cases;
	for(int j = 0;j < cases; j++)
	{
		cin>>a;

		for(int n = 0;n < a; n++)
			{
				cin>>b;
				all += b;
				maxx = max(maxx, b);
			}

		if(a == 2)
			{
				cout<< 0 <<endl;
				continue;
			}

		yu = (a - 1) - all%(a - 1) + (maxx - all/(a - 1) - 1) * (a - 1);

		while( yu < 0 )
			yu += a-1;

		cout<<yu<<endl;

		all = 0;
		maxx = 0;
	}

	return 0;
}


#include<iostream>
#include<list>
#include<algorithm>

using namespace std;

int main(void)
{
	long long cases = 0, a, b = 0, jian,p[100000];

	cin>>cases;
	for(int j = 0;j < cases; j++)
	{
		cin>>a;

		for(int n = 0;n < a; n++)
			{
				cin>>p[n];
			}

		if(a == 2)
			{
				cout<< 0 <<endl;
				continue;
			}

		sort(p,p + a);

		for(int kk = 0;kk < a - 2; kk++)
		{
			b +=p[a-1] - p[kk];
		}

		b -= p[a-2];

		while(b < 0)
			b += a - 1;

		cout<<b<<endl;

		b = 0;
	}

	return 0;
}


#include<iostream>

using namespace std;

int main(void)
{
	long long cases = 0, a, all = 0, b = 0, yu, maxx = 0;

	cin>>cases;
	for(int j = 0;j < cases; j++)
	{
		cin>>a;

		for(int n = 0;n < a; n++)
			{
				cin>>b;
				all += b;
				maxx = max(maxx, b);
			}

		if(a == 2)
			{
				cout<< 0 <<endl;
				all = 0;
				maxx = 0;
				continue;
			}

		yu = (a - 1) * maxx - all;

		while( yu < 0 )
			yu += a-1;

		cout<<yu<<endl;

		all = 0;
		maxx = 0;
	}

	return 0;
}


#include<iostream>

using namespace std;

int main(void)
{
	long long cases = 0, a, all = 0, b = 0, yu, maxx = 0;

	cin>>cases;
	for(int j = 0;j < cases; j++)
	{
		cin>>a;

		for(int n = 0;n < a; n++)
			{
				cin>>b;
				all += b;
				maxx = max(maxx, b);
			}

		if(a == 2)
			{
				cout<< 0 <<endl;
				continue;
			}

		yu = (a - 1) - all%(a - 1) + (maxx - all/(a - 1) - 1) * (a - 1);

		while( yu< 0 )
			yu += a-1;

		cout<<yu<<endl;

		all = 0;
		maxx = 0;
	}

	return 0;
}


#include<iostream>
#include<list>
#include<algorithm>

using namespace std;

int main(void)
{
	long long cases = 0, a, b = 0, jian,p[100000];

	cin>>cases;
	for(int j = 0;j < cases; j++)
	{
		cin>>a;

		for(int n = 0;n < a; n++)
			{
				cin>>p[n];
			}

		if(a == 2)
			{
				cout<< 0 <<endl;
				continue;
			}

		sort(p,p + a);

		for(int kk = 0;kk < a - 2; kk++)
		{
			b +=p[a-1] - p[kk];
		}

		b -= p[a-2];

		if(b < 0)
			b = b % (a - 1);
		if(b < 0)
			b += (a - 1);

		cout<<b<<endl;

		b = 0;
	}

	return 0;
}


#include<iostream>
#include<list>
#include<algorithm>

using namespace std;

int main(void)
{
	long long cases = 0, a, b = 0, jian,*p;

	cin>>cases;
	for(int j = 0;j < cases; j++)
	{
		cin>>a;

		p = new long long [a];

		for(int n = 0;n < a; n++)
			{
				cin>>p[n];
			}

		if(a == 2)
			{
				cout<< 0 <<endl;
				delete p;
				continue;
			}

		sort(p,p + a);

		for(int kk = 0;kk < a - 2; kk++)
		{
			b +=p[a-1] - p[kk];
		}

		b -= p[a-2];

		if(b < 0)
			b += a - 1;

		cout<<b<<endl;
		b = 0;
		delete p;
	}

	return 0;
}


#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(...) begin(__VA_ARGS__) , end(__VA_ARGS__)

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector <int> vi;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
constexpr ll nax = 2e5+6969, INF = 2e16+6969;

int qq;

int main()
{
	scanf("%d", &qq);
	while(qq--)
	{
		ll n,m1,m2,sum,t[nax],ans = 0;
		cin >> n;
		sum = 0;
		m1 = m2 = 0;
		for(int i=0;i<n;++i)
		{
			ll x;
			cin >> x;
			t[i] = x;
			sum += x;
			if(x > m1)
			{
				m2 = m1;
				m1 = x;
			}
			else if(x>=m2)
			{
				m2 = x;
			}
		}
		for(int i=0;i<n;++i)
		{
			ll M;
			if(t[i] == m1) M = m2;
			else M = m1;
			if(M*(n-1) >= sum)
			{
				ans = max(ans, M*(n-1) - sum);
			}
			else
			{
				ll x = t[i] - sum + M*(n-1);
				x%=(n-1);
				if(x == 0) continue;
				ans = max(ans,n-1-x);
			}
		}
		cout << ans << "\n";
	}
	return 0;
}


#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(...) begin(__VA_ARGS__) , end(__VA_ARGS__)

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector <int> vi;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
constexpr ll nax = 2e5+6969, INF = 2e16+6969;

int qq;

int main()
{
	scanf("%d", &qq);
	while(qq--)
	{
		ll n,m1,m2,sum,t[nax],ans = 0;
		cin >> n;
		sum = 0;
		m1 = m2 = 0;
		for(int i=0;i<n;++i)
		{
			ll x;
			cin >> x;
			t[i] = x;
			sum += x;
			if(x > m1)
			{
				m2 = m1;
				m1 = x;
			}
			else if(x>=m2)
			{
				m2 = x;
			}
		}

		for(int i=0;i<n;++i)
		{
			if(t[i] < m2) ans += m2 - t[i];
		}
		ll tmp = max(ans, m1*(n-1) - sum);
		ans += (n-1-m1%(n-1))%(n-1);
		sum = m2*(n-1) + m1;
		ans = max(ans, m1 - m2*(n-2));
		cout << ans << "\n";
	}
	return 0;
}


#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(...) begin(__VA_ARGS__) , end(__VA_ARGS__)

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector <int> vi;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
constexpr ll nax = 2e5+6969, INF = 2e16+6969;

int qq;

int main()
{
	scanf("%d", &qq);
	while(qq--)
	{
		ll n,m1,m2,sum,t[nax],ans = INF;
		cin >> n;
		m1 = m2 = 0;
		for(int i=0;i<n;++i)
		{
			ll x;
			cin >> x;
			t[i] = x;
			sum += x;
			if(x > m1)
			{
				m2 = m1;
				m1 = x;
			}
			else if(x>=m2)
			{
				m2 = x;
			}
		}
		for(int i=0;i<n;++i)
		{
			ll M;
			if(t[i] == m1) M = m2;
			else M = m1;
			if(M*(n-1) > sum)
			{
				ans = min(ans, M*(n-1) - sum);
			}
			else
			{
				ll x = t[i]*2 - sum + M*(n-1);
				x%=(n-1);
				ans = min(ans,n-1-x);
				if(x == 0) ans = 0;
			}
		}
		cout << ans << "\n";
	}
	return 0;
}


#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(...) begin(__VA_ARGS__) , end(__VA_ARGS__)

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector <int> vi;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
constexpr ll nax = 2e5+6969, INF = 2e16+6969;

int qq;

int main()
{
	scanf("%d", &qq);
	while(qq--)
	{
		ll n,t[nax];
		ll m,ans,sum;
		m = ans = sum = 0;
		cin >> n;
		for(int i=0;i<n;++i)
		{
			cin >> t[i];
			sum += t[i];
			m = max(m,t[i]);
		}
		m = max(m, (sum+n-2)/(n-1));
		//  for(int i=0;i<n;++i) ans += m - t[i];
		ans = (n-1)*m - sum;
		cout << ans << "\n";
	}
	return 0;
}


#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(...) begin(__VA_ARGS__) , end(__VA_ARGS__)

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector <int> vi;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
constexpr ll nax = 2e5+6969, INF = 2e16+6969;

int qq;

int main()
{
	scanf("%d", &qq);
	while(qq--)
	{
		ll n,m1,m2,sum,t[nax],ans = 0;
		cin >> n;
		sum = 0;
		m1 = m2 = 0;
		for(int i=0;i<n;++i)
		{
			ll x;
			cin >> x;
			t[i] = x;
			sum += x;
			if(x > m1)
			{
				m2 = m1;
				m1 = x;
			}
			else if(x>=m2)
			{
				m2 = x;
			}
		}
		for(int i=0;i<n;++i)
		{
			ll M;
			if(t[i] == m1) M = m2;
			else M = m1;
			//  if(i == 0) printf("%d\n", sum);
			if(M*(n-1) >= sum)
			{
				ans = max(ans, M*(n-1) - sum);
			}
			else
			{
				ll x = t[i]*2 - sum + M*(n-1);
				x%=(n-1);
				if(x == 0) continue;
				//  ans = max(ans,n-1-x);
				if(ans < n-1-x)
				{
					ans = n-1-x;
					//  puts("jest");
				}
			}
		}
		cout << ans << "\n";
	}
	return 0;
}


#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(...) begin(__VA_ARGS__) , end(__VA_ARGS__)

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector <int> vi;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
constexpr ll nax = 2e5+6969, INF = 2e16+6969;

int qq;

int main()
{
	scanf("%d", &qq);
	while(qq--)
	{
		ll n,m1,m2,sum,t[nax],ans = 0;
		cin >> n;
		sum = 0;
		m1 = m2 = 0;
		for(int i=0;i<n;++i)
		{
			ll x;
			cin >> x;
			t[i] = x;
			sum += x;
			if(x > m1)
			{
				m2 = m1;
				m1 = x;
			}
			else if(x>=m2)
			{
				m2 = x;
			}
		}

		for(int i=0;i<n;++i)
		{
			if(t[i] < m2) ans += m2 - t[i];
		}
		ll tmp = max(ans, m1*(n-1) - sum);
		ans += (n-1-m1%(n-1))%(n-1);
		sum = m2*(n-1) + m1;
		ans = max(ans, m1 - m2*(n-1));
		cout << ans << "\n";
	}
	return 0;
}


#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(...) begin(__VA_ARGS__) , end(__VA_ARGS__)

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector <int> vi;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
constexpr ll nax = 2e5+6969, INF = 2e16+6969;

int qq;

int main()
{
	scanf("%d", &qq);
	while(qq--)
	{
		ll n,m1,m2,sum,t[nax],ans = 0;
		cin >> n;
		sum = 0;
		m1 = m2 = 0;
		for(int i=0;i<n;++i)
		{
			ll x;
			cin >> x;
			t[i] = x;
			sum += x;
			if(x > m1)
			{
				m2 = m1;
				m1 = x;
			}
			else if(x>=m2)
			{
				m2 = x;
			}
		}
		for(int i=0;i<n;++i)
		{
			ll M;
			if(t[i] == m1) M = m2;
			else M = m1;
			if(M*(n-1) >= sum)
			{
				ans = max(ans, M*(n-1) - sum);
			}
			else
			{
				ll x = t[i]*2 - sum + M*(n-1);
				x%=(n-1);
				if(x == 0) continue;
				ans = max(ans,n-1-x);
			}
		}
		cout << ans << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(){
int t;
cin>>t;
while(t--)
{int n;
cin>>n;
vector <long long int> a;
long long int sum=0,max=0;
for(int i=0;i<n;i++)
{
	long long int x;
	cin>>x;
	sum+=x;
	if(x>max)
	max=x;
	a.push_back(x);
 }
 long long int k=0;
 if(sum%(n-1)==0)
 k=sum;
 else
 k=(sum/(n-1)+1)*(n-1);
 if(max<=k)
 cout<<k-sum<<endl;
 else
 cout<<max*(n-1)-sum<<endl;

}

}