Problem:
Encryption System
A programmer developed a new encryption system.
However, his system has an issue that
two or more distinct strings are `encrypted' to the same string.
We have a string encrypted by his system. 
To decode the original string, we want to enumerate all the candidates of the string before the encryption.
Your mission is to write a program for this task.
The encryption is performed taking the following steps. Given a string that consists only of lowercase letters ('a' to 'z').
Change the first 'b' to 'a'. If there is no 'b', do nothing.
Change the first 'c' to 'b'. If there is no 'c', do nothing.
...
Change the first 'z' to 'y'. If there is no 'z', do nothing.
Input
The input consists of at most 100 datasets.
Each dataset is a line containing an encrypted string.
The encrypted string consists only of lowercase letters, and contains at least 1 and at most 20 characters.
The input ends with a line with a single '#' symbol.
Output
For each dataset,
the number of candidates
n
of the string before encryption should be printed in a line first,
followed by lines each containing a candidate of the string before encryption.
If
n
does not exceed 10, print all candidates in dictionary order;
otherwise, print the first five and the last five candidates in dictionary order.
Here, dictionary order is recursively defined as follows.
The empty string comes the first in dictionary order.
For two nonempty strings
x
=
x
1
...
x
k
and
y
=
y
1
...
y
l
, 
the string
x
precedes the string
y
in dictionary order if
x
1
precedes
y
1
in alphabetical order ('a' to 'z'), or
x
1
and
y
1
are the same character and
x
2
...
x
k
precedes
y
2
...
y
l
in dictionary order.
Sample Input
enw
abc
abcdefghijklmnopqrst
z
#
Output for the Sample Input
1
fox
5
acc
acd
bbd
bcc
bcd
17711
acceeggiikkmmooqqssu
acceeggiikkmmooqqstt
acceeggiikkmmooqqstu
acceeggiikkmmooqrrtt
acceeggiikkmmooqrrtu
bcdefghijklmnopqrrtt
bcdefghijklmnopqrrtu
bcdefghijklmnopqrssu
bcdefghijklmnopqrstt
bcdefghijklmnopqrstu
0

Submitted solutions:

code_snippet: #include <stdio.h>
#include <memory.h>
#include <string.h>
#define MAX 30

char ch[MAX], p[MAX];
int len, b[MAX], ac[30], cnt;
char ch2[1050000][22];

void dfs(int now, int sw){
	int i;
	b[now]=sw;
	if (now==len){
		for (i=1;i<=len;i++){
			p[i]=ch[i];
			if (b[i]) p[i]++;
		}
		memset(ac, 0, sizeof(ac));
		int flag=0;
		for (i=1;i<=len;i++){
			if (ac[p[i]-'a']){
				if (p[i]!=ch[i]){
					flag=1;
					break;
				}
			}else{
				ac[p[i]-'a']=1;
				if (p[i]-1!=ch[i] && p[i]!='a'){
					flag=1;
					break;
				}
			}
		}
		if (flag==0){
			cnt++;
			for (i=1;i<=len;i++) ch2[cnt][i]=p[i];
		}
	}else{
		dfs(now+1, 0);
		if (ch[now+1]!='z') dfs(now+1, 1);
	}
}

int main(void){
	int i,j;
	for (;;){
		scanf("%s", &ch[1]);
		if (ch[1]=='#') break;
		len=strlen(&ch[1]);
		dfs(1, 0);
		if (ch[1]!='z') dfs(1, 1);
		printf("%d\n", cnt);
		if (cnt>=10){
			for (i=1;i<=5;i++) printf("%s\n", &ch2[i][1]);
			for (i=cnt-4;i<=cnt;i++) printf("%s\n", &ch2[i][1]);
		}else{
			for (i=1;i<=cnt;i++) printf("%s\n", &ch2[i][1]);
		}
		for (i=1;i<=cnt;i++){
			for (j=1;j<=len;j++) ch2[i][j]=0;
		}
		cnt=0;

	}
	return false;
}
accuracy: 1
time_ms: 1630
memory_kb: 3196
final_rank: 2

code_snippet: #include <bits/stdc++.h>
#define Mid (l + r >> 1)
#define lson (rt << 1)
#define rson (rt << 1 | 1)
using namespace std;
int read() {
	char c; int num, f = 1;
	while(c = getchar(),!isdigit(c)) if(c == '-') f = -1; num = c - '0';
	while(c = getchar(), isdigit(c)) num = num * 10 + c - '0';
	return f * num;
}
string s;
vector<string> v;
void dfs(char c) {
	if(c == 'a' - 1) {
		v.push_back(s);
		return ;
	}
	int f = 0;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == c + 1) {
			f = 1;
			break;
		} else if(s[i] == c) {
			s[i] = c + 1;
			dfs(c - 1);
			s[i] = c;
		}
	}
	if(!f) dfs(c - 1);
}
void work() {
	if(s.size() == 1 && s[0] == '#') exit(0);
	v.clear();
	dfs('y');
	sort(v.begin(), v.end());
	cout << v.size() << endl;
	if(v.size() <= 10) {
		for(auto x : v)
			cout << x << endl;
	} else {
		for(int i = 0; i < 5; i++)
			cout << v[i] << endl;
		for(int i = v.size() - 5; i < v.size(); i++)
			cout << v[i] << endl;
	}
}
signed main()
{
	while(cin >> s) work();
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4568
final_rank: 9

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

const long long MOD1 = 1000000007;
const long long MOD2 = 998244353;
#define all(v) v.begin(), v.end()
#define rall(a) a.rbegin(), a.rend()
#define fi first
#define se second
#define endl "\n"

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

template <typename T>
using vc = vector<T>; // prioriy_queueに必要なのでここにこれ書いてます
template <typename T>
using vv = vc<vc<T>>;
#define int long long
using ll = long long;
ll INF = 2e18;

#ifdef ONLINE_JUDGE
// ジャッジ環境ではデバッグマクロを無効化
#define debug_x(x) \
    do             \
    {              \
    } while (0)
#define debug_vc(v) \
    do              \
    {               \
    } while (0)
#define debug_vv(v) \
    do              \
    {               \
    } while (0)
#else
// ローカルではデバッグ出力
#define debug_x(x) cout << #x << " = " << (x) << endl
#define debug_vc(v)                    \
    {                                  \
        cout << #v << endl;            \
        ll n = size(v);                \
        rep(i, n) cout << v[i] << ' '; \
        cout << endl;                  \
    } // 一次元配列を出力する
#define debug_vv(v)                                        \
    {                                                      \
        cout << #v << endl;                                \
        ll n = size(v);                                    \
        rep(i, n)                                          \
        {                                                  \
            rep(j, size(v[i])) { cout << v[i][j] << ' '; } \
            cout << endl;                                  \
        }                                                  \
    } // 二次元配列を出力する
#endif

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define drep(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define nfor(i, s, n) for (ll i = s; i < n; i++)        // i=s,s+1...n-1 ノーマルfor
#define dfor(i, s, n) for (ll i = (s) - 1; i >= n; i--) // s-1スタートでnまで落ちる

using ld = long double;
using bl = bool;

template <class T>
using pq = priority_queue<T, vc<T>>; // 大きい順
template <class T>
using pq_g = priority_queue<T, vc<T>, greater<T>>; // 小さい順

using vl = vc<ll>;
using vvl = vv<ll>;
using vvvl = vv<vl>;
using vvvvl = vv<vvl>;
using vs = vc<string>;
using vvs = vv<string>;
using vb = vc<bl>;
using vvb = vv<bl>;
using vvvb = vv<vb>;
using vld = vc<ld>;
using vvld = vv<ld>;
using vvvld = vv<vld>;
using P = pair<ll, ll>;
using vP = vc<P>;
using vvP = vc<vP>;
using vvvP = vv<vP>;

#define pb push_back

#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define YN                     \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    } // if(a==b)YN;
#define dame cout << -1 << endl

string dir = "DRUL";   // 第4象限の場合
vl di = {1, 0, -1, 0}; // vl di={1,1,0,-1,-1,-1,0,1};
vl dj = {0, 1, 0, -1}; // vl dj={0,1,1,1,0,-1,-1,-1};

bool out_grid(ll i, ll j, ll h, ll w)
{ // trueならcontinue
    return (!(0 <= i && i < h && 0 <= j && j < w));
}

bl solve()
{
    string s;
    cin >> s;
    if (s == "#")
        return 0;
    ll n = s.size();
    vvs t(n + 1);
    t[0].pb({""});
    rep(i, n)
    {
        char x = s[i];
        rep(j, t[i].size())
        {
            string st = t[i][j];
            bl include = false;
            rep(k, st.size())
            {
                if (st[k] == x)
                {
                    include = true;
                    break;
                }
            }
            if (include||x=='a')
            {
                string nex = st;
                nex += x;
                t[i + 1].pb(nex);
                if (x != 'z')
                {
                    bl ok = true;
                    rep(k, st.size())
                    {
                        if (st[k] == x + 1)
                        {
                            ok = false;
                            break;
                        }
                    }
                    if (!ok)
                        continue;
                    string nex2 = st;
                    nex2 += (x + 1);
                    t[i + 1].pb(nex2);
                }
            }
            else
            {
                if (x == 'z')
                    continue;
                bl ok = true;
                rep(k, st.size())
                {
                    if (st[k] == x + 1)
                    {
                        ok = false;
                        break;
                    }
                }
                if (!ok)
                    continue;
                string nex = st;
                nex += (x + 1);
                t[i + 1].pb(nex);
            }
        }
    }
    // debug_vv(t);
    // rep(i, 25)
    // {
    //     char tar = 'a' + i;
    //     char prev = tar + 1;
    //     vs cand;
    //     for (auto t : st)
    //     {
    //         rep(j, t.size())
    //         {
    //             if (t[j] == tar)
    //             {
    //                 t[j] = prev;
    //                 cand.pb(t);
    //                 t[j] = tar;
    //                 break;
    //             }
    //         }
    //     }
    //     rep(j, cand.size())
    //     {
    //         string tmp = cand[j];
    //         rep(k, 25)
    //         {
    //             char tar = 'a' + k + 1;
    //             char nex = tar - 1;
    //             rep(l, tmp.size())
    //             {
    //                 if (tmp[l] == tar)
    //                 {
    //                     tmp[l] = nex;
    //                     break;
    //                 }
    //             }
    //             // if (i < 3)
    //             // {
    //             //     cout << i << endl;
    //             //     cout << t << endl;
    //             // }
    //         }
    //         if (tmp == s)
    //         {
    //             // cout << "ERIRIRIRIRIIRIIIIIII" << t << endl;
    //             st.insert(cand[j]);
    //         }
    //     }
    // }
    // vs elimi;
    // for (auto t : st)
    // {
    //     // cout << "start is" << t << endl;
    //     string start = t;
    //     rep(i, 25)
    //     {
    //         char tar = 'a' + i + 1;
    //         char nex = tar - 1;
    //         rep(j, t.size())
    //         {
    //             if (t[j] == tar)
    //             {
    //                 t[j] = nex;
    //                 break;
    //             }
    //         }
    //         // if (i < 3)
    //         // {
    //         //     cout << i << endl;
    //         //     cout << t << endl;
    //         // }
    //     }
    //     if (t != s)
    //     {
    //         // cout << "ERIRIRIRIRIIRIIIIIII" << t << endl;
    //         elimi.pb(start);
    //     }
    // }
    // rep(i, elimi.size())
    // {
    //     // cout << elimi[i] << endl;
    //     st.erase(elimi[i]);
    // }
    cout << t[n].size() << endl;
    if (t[n].size() <= 10)
    {
        rep(i,t[n].size()){
            cout << t[n][i] << endl;
        }
    }
    else
    {
        for(ll i=0;i<5;i++){
            cout << t[n][i] << endl;
        }
        for(ll i=t[n].size()-5;i<t[n].size();i++){
            cout << t[n][i] << endl;
        }
    }
    return 1;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    while (true)
    {
        if (!solve())
            break;
    }
    return 0;
}

/*
shift+alt+Fで成形
f2で変数名変更

スニペット
basic
 m:atcoder以外用
 ma:ABC/ARC用
 mahc:AHC用
math
 floor:床関数
 ceil:天井関数
 comv:二項係数
 modpow: a^b mod m
 GCD:最大公約数
 extGCD:拡張ユークリッド互除法
 PFD:素因数分解
 isprime:エラトステネスの篩
 matrixpow:行列累乗
data_structure
 seg:セグメント木
technic
 Compress:座標圧縮
 runlength:ランレングス圧縮
graph
 warshall:ワーシャルフロイド法
 dfs:深さ優先探索
 bfs:幅優先探索
 LCA:最近共通祖先
*/
accuracy: 1
time_ms: 20
memory_kb: 6204
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rrep(i,start,end) for (ll i = start;i >= (ll)(end);i--)
#define repn(i,end) for(ll i = 0; i <= (ll)(end); i++)
#define reps(i,start,end) for(ll i = start; i < (ll)(end); i++)
#define repsn(i,start,end) for(ll i = start; i <= (ll)(end); i++)
#define each(p,a) for(auto &p:a)
typedef vector<ll> vll;
typedef vector<pair<ll ,ll>> vpll;
typedef vector<vector<ll>> vvll;
typedef set<ll> sll;
typedef map<ll , ll> mpll;
typedef pair<ll ,ll> pll;
typedef tuple<ll , ll , ll> tpl3;
#define LL(...) ll __VA_ARGS__; input(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__; input(__VA_ARGS__)
#define Str(...) string __VA_ARGS__; input(__VA_ARGS__)
#define Ch(...) char __VA_ARGS__; input(__VA_ARGS__)
#define all(a)  (a).begin(),(a).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define sz(x) (ll)x.size()
// << std::fixed << std::setprecision(10)
const ll INF = 1LL << 30;
const ld EPS = 1e-9;
 
ll lceil(ll a,ll b){if(a%b==0){return a/b;}if(a>=0){return (a/b)+1;}else{return -((-a)/b);}}
ll lfloor(ll a,ll b){if(a%b==0){return a/b;}if(a>=0){return (a/b);}else{return -((-a)/b)-1;}}
inline ll positive_mod(ll a,ll m){return (a % m + m)%m;}
inline ll popcnt(ull a){ return __builtin_popcountll(a);}
//0indexed
inline ll topbit(ll a){assert(a != 0);return 63 - __builtin_clzll(a);}
inline ll smlbit(ll a){assert(a != 0);return __builtin_ctzll(a);}
template<class T> bool chmin(T& a, T b){if(a > b){a = b;return true;}return false;}
template<class T> bool chmax(T& a, T b){if(a < b){a = b;return true;}return false;}
template<typename T> std::istream &operator>>(std::istream&is,std::vector<T>&v){for(T &in:v){is>>in;}return is;}
template<typename T> std::ostream &operator<<(std::ostream&os,const std::vector<T>&v){for(auto it=std::begin(v);it!=std::end(v);){os<<*it<<((++it)!=std::end(v)?" ":"");}return os;}
template<typename T1, typename T2>std::ostream &operator<< (std::ostream &os, std::pair<T1,T2> p){os << "{" << p.first << "," << p.second << "}";return os;}
template<class... T>void input(T&... a){(cin >> ... >> a);}
void print(){cout << endl;}
template<class T, class... Ts>void print(const T& a, const Ts&... b){cout << a;((cout << ' ' << b), ...);cout << endl;}
template<class T> void pspace(const T& a){ cout << a << ' ';}
void perr(){cerr << endl;}
template<class T, class... Ts>void perr(const T& a, const Ts&... b){cerr << a;((cerr << ' ' << b), ...);cerr << endl;}
void yes(bool i = true){ return print(i?"yes":"no"); }
void Yes(bool i = true){ return print(i?"Yes":"No"); }
void YES(bool i = true){ return print(i?"YES":"NO"); }
template <class T> vector<T> &operator++(vector<T> &v) {for(auto &e : v) e++;return v;}
template <class T> vector<T> operator++(vector<T> &v, signed) {auto res = v;for(auto &e : v) e++;return res;}
template <class T> vector<T> &operator--(vector<T> &v) {for(auto &e : v) e--;return v;}
template <class T> vector<T> operator--(vector<T> &v, signed) {auto res = v;for(auto &e : v) e--;return res;}
//grid探索用
vector<ll> _ta = {0,0,1,-1,1,1,-1,-1};
vector<ll> _yo = {1,-1,0,0,1,-1,1,-1};
bool isin(ll now_i,ll now_j,ll h,ll w){return (0<=now_i && now_i < h && 0 <= now_j && now_j < w);}
  
ll lpow(ll x,ll n){ll ans = 1;while(n >0){if(n & 1)ans *= x;x *= x;n >>= 1;}return ans;}
ll Modlpow(ll x,ll n,ll m){ll ans = 1;ll a = x%m;while(n >0){if(n & 1){ans *= a;ans%= m;}a *= a;a %= m;n >>= 1;}return ans;} 
const ll MOD9 = 998244353LL;
const ll MOD10 = 1000000007LL;

pair<ll,set<string>> myans(string s){
  //答えの型注意
  ll n = sz(s);
  set<string> mae;
  set<string> usi;
  auto check = [&](string &t){
    vll fin(26,-1);
    // string u = t;
    rep(i,sz(t)){
      ll v= t[i]-'a';
      if(fin[v] == -1 && v != 0){
        fin[v] = i ;
        t[i] = char('a'+v-1);
      }
    }
    bool same = t == s;
    rep(i,26)if(fin[i]!= -1){
      ll v= t[fin[i]]-'a';
      t[fin[i]] = char('a' + v+1);
    }
    return same;
  };
  ll ans = 0;
  rep(i,1 << n){
    string t = "";
    bool able = true;
    rep(j,n){
      //次にする
      if(i >> j & 1){
        if(s[j] == 'z'){
          able = false;
        }else{
          t += char('a'+(s[j]-'a')+1);
        }
      }else{
        t += s[j];
      }
    }
    if(!able)continue;
    
    if(check(t)){
      ans++;
      mae.insert(t);
      while(sz(mae) > 5){
        mae.erase(*mae.rbegin());
      }
      usi.insert(t);
      while(sz(usi) > 5){
        usi.erase(*usi.begin());
      }
    }
  }
  set<string> ret = mae;
  each(p,usi){
    ret.insert(p);
  }
  // cout << ans << endl;
  // each(p,ret){
  //   cout << p << endl;
  // }
  return {ans,ret};
}


int main(){
  ios::sync_with_stdio(false);cin.tie(nullptr);
  while(true) {
    string s;
    cin >> s;
    if (s == "#") break;
    auto [ans,ret] = myans(s);
    cout << ans << endl;
    each(p,ret){
      cout << p << endl;
    }
  }
  // string t = "acd";
  // cout << encode(t) << endl;
}
accuracy: 1
time_ms: 7050
memory_kb: 3456
final_rank: 15

code_snippet: #include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr int SIZ = 26;

vector<string> ans;
void dfs(string cur, string& S, vector<bool> shifted) {
    if (cur.size() == S.size()) {
        ans.push_back(cur);
        return;
    }

    const int pos = static_cast<int>(cur.size());
    if (shifted[S[pos] - 'a'] || S[pos] == 'a') {
        cur.push_back(S[pos]);
        dfs(cur, S, shifted);
        cur.pop_back();
    }

    if (S[pos] != 'z') {
        if (shifted[S[pos] + 1 - 'a']) {
            return;
        }
        shifted[S[pos] + 1 - 'a'] = true;
        cur.push_back(static_cast<char>(S[pos] + 1));
        dfs(cur, S, shifted);
        cur.pop_back();
        shifted[S[pos] + 1 - 'a'] = false;
    }
}

int main() {
    while (true) {
        string S;
        cin >> S;
        if (S == "#") {
            break;
        }

        ans.clear();
        vector shifted(SIZ, false);
        dfs("", S, shifted);

        ranges::sort(ans);
        ans.erase(ranges::unique(ans).begin(), ans.end());

        const int n = static_cast<int>(ans.size());
        cout << n << endl;
        if (n <= 10) {
            for (int i = 0; i < n; i++) {
                cout << ans[i] << endl;
            }
        } else {
            for (int i = 0; i < 5; i++) {
                cout << ans[i] << endl;
            }
            for (int i = n - 5; i < n; i++) {
                cout << ans[i] << endl;
            }
        }
    }
}
accuracy: 1
time_ms: 20
memory_kb: 4952
final_rank: 10

code_snippet: #include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr int SIZ = 26;

vector<string> ans;
void solve(string cur, string& S, vector<bool> used) {
    if (cur.size() == S.size()) {
        ans.push_back(cur);
        return;
    }

    const int id = static_cast<int>(cur.size());
    if (used[S[id] - 'a'] || S[id] == 'a') {
        cur.push_back(S[id]);
        solve(cur, S, used);
        cur.pop_back();
    }

    if (S[id] != 'z') {
        if (used[S[id] + 1 - 'a']) {
            return;
        }
        used[S[id] + 1 - 'a'] = true;
        cur.push_back(char(S[id] + 1));
        solve(cur, S, used);
        cur.pop_back();
        used[S[id] + 1 - 'a'] = false;
    }
}

int main() {
    while (true) {
        string S;
        cin >> S;
        if (S == "#") {
            break;
        }

        ans.clear();
        vector used(SIZ, false);
        solve("", S, used);

        ranges::sort(ans);
        ans.erase(ranges::unique(ans).begin(), ans.end());

        const int n = static_cast<int>(ans.size());
        cout << n << endl;
        if (n <= 10) {
            for (int i = 0; i < n; i++) {
                cout << ans[i] << endl;
            }
        } else {
            for (int i = 0; i < 5; i++) {
                cout << ans[i] << endl;
            }
            for (int i = n - 5; i < n; i++) {
                cout << ans[i] << endl;
            }
        }
    }
}
accuracy: 1
time_ms: 20
memory_kb: 4952
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(a) a.begin(),a.end()
#define reps(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, a, n) for (int i = (a); i > (int)(n); i--)
const long long mod = 1000000007;
const long long INF = 1e18;
ll myceil(ll a, ll b) {return (a+b-1)/b;}


string s;
int n;
vector<string> ans(0);


void f(int st, string t) {
    if (st == -1) {
        ans.push_back(t);
        return;
    }

    int fl = 0;
    rep(i,n) {
        if (t[i] == 'a'+st) {
            fl++;
            t[i]++;
            f(st-1,t);
            t[i]--;
        }
        else if (t[i] == 'a'+st+1) {
            return;
        }
    }

    f(st-1,t);
    
}


void solve() {
    ans.resize(0);
    n = s.length();

    f(24,s);

    sort(all(ans));

    cout << ans.size() << endl;
    if (ans.size() >= 11) {
        rep(i,5) {
            cout << ans[i] << endl;
        }
        rep(i,5) {
            cout << ans[ans.size()+i-5] << endl;
        }
    }
    else {
        rep(i,ans.size()) {
            cout << ans[i] << endl;
        }
    }
    return;


}


int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    while (cin >> s && s != "#") {
        solve();
    }
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4500
final_rank: 6

code_snippet: // (⁠◕⁠ᴗ⁠◕⁠✿⁠)

// #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define srep(i, s, n) for (ll i = s; i < (n); i++)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
template<typename T> using vvv = vv<vc<T>>;
using vi = vc<int>;using vvi = vv<int>; using vvvi = vv<vi>;
using ll = long long;using vl = vc<ll>;using vvl = vv<ll>; using vvvl = vv<vl>;
using ld = long double; using vld = vc<ld>; using vvld = vc<vld>; using vvvld = vc<vvld>;
using uint = unsigned int;
using ull = unsigned long long;
const ld pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
// const ll mod = 1000000007;
const ll mod = 998244353;
inline bool inside(ll y, ll x, ll H, ll W) {return 0 <= (y) and (y) < (H) and 0 <= (x) and (x) < (W); }

#define debug(var)  do{std::cout << #var << " : \n";view(var);}while(0)
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vc<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vv<T>& vv){ for(const auto& v : vv){ view(v); } }
vc<string> tot;
string S;
void f(int c){
    if (c == 0){
        tot.push_back(S);
        return;
    }
    
    rep(i, len(S)){
        if (S[i] == 'a' + c) return;
        if (S[i] == 'a' + c - 1){
            S[i]++;
            f(c - 1);
            S[i]--;
        }
    }
    f(c - 1);
}
void solve(){
    tot.clear();
    f(25);
    sort(all(tot));
    cout << len(tot) << endl;
    if (len(tot) < 10){
        for (auto x : tot) cout << x << endl;
    }else{
        rep(i, 5) cout << tot[i] << endl;
        srep(i, len(tot) - 5, len(tot)) cout << tot[i] << endl;
    }
}

int main(){
    while (true){
        cin >> S;
        if (S == "#") break;
        solve();
    }
}
accuracy: 1
time_ms: 10
memory_kb: 4540
final_rank: 8

code_snippet: #include <bits/stdc++.h>
    using namespace std;
    
    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
    #define rep(i,n) for (int i = 0; i < (n); ++i)

    typedef long long ll;
    typedef unsigned long long ull;
    using P=pair<ll,ll>;
    using tp=tuple<ll,ll,ll>;
    const int INF=1001001001;
    const ll INFL=1e18;
    const int mod=998244353;

	bool check(string s,string target){
		int n=s.size();
		for(char c='b';c<='z';c++){
			rep(i,n){
				if(s[i]==c){
					s[i]=c-1;
					break;
				}
			}
		}
		return s==target;
	}

	void dfs(int i,string& s,string& target,vector<string>& t){
		int n=s.size();
		if(i==s.size()){
			if(check(s,target))t.push_back(s);
			return;
		}
		dfs(i+1,s,target,t);
		s[i]+=1;
		dfs(i+1,s,target,t);
		s[i]-=1;
	}
    bool solve(){
		string s;
		cin>>s;
		if(s=="#")return false;

		vector<string>t;
		string target=s;
		dfs(0,s,target,t);
		sort(t.begin(),t.end());

		int T=t.size();
		cout<<T<<endl;
		if(T>10){
			rep(i,5){
				cout<<t[i]<<endl;
			}
			rep(i,5){
				cout<<t[T-5+i]<<endl;
			}
		}else{
			rep(i,T){
				cout<<t[i]<<endl;
			}
		}
		
		return true;
    }

    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);

		while(1){
			if(!solve())break;
		}
		
        return 0;
    }
accuracy: 1
time_ms: 6620
memory_kb: 4968
final_rank: 18

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

template <unsigned mod = 1000000007> struct fp {
    unsigned v;
    static constexpr int get_mod() {
        return mod;
    }
    constexpr unsigned inv() const {
        assert(v != 0);
        int x = v, y = mod, p = 1, q = 0, t = 0, tmp = 0;
        while (y > 0) {
            t = x / y;
            x -= t * y, p -= t * q;
            tmp = x, x = y, y = tmp;
            tmp = p, p = q, q = tmp;
        }
        if (p < 0)
            p += mod;
        return p;
    }
    constexpr fp(ll x = 0) : v(x >= 0 ? x % mod : (mod - (-x) % mod) % mod) {}
    fp operator-() const {
        return fp() - *this;
    }
    fp pow(ull t) {
        fp res = 1, b = *this;
        while (t) {
            if (t & 1)
                res *= b;
            b *= b;
            t >>= 1;
        }
        return res;
    }
    fp &operator+=(const fp &x) {
        if ((v += x.v) >= mod)
            v -= mod;
        return *this;
    }
    fp &operator-=(const fp &x) {
        if ((v += mod - x.v) >= mod)
            v -= mod;
        return *this;
    }
    fp &operator*=(const fp &x) {
        v = ull(v) * x.v % mod;
        return *this;
    }
    fp &operator/=(const fp &x) {
        v = ull(v) * x.inv() % mod;
        return *this;
    }
    fp operator+(const fp &x) const {
        return fp(*this) += x;
    }
    fp operator-(const fp &x) const {
        return fp(*this) -= x;
    }
    fp operator*(const fp &x) const {
        return fp(*this) *= x;
    }
    fp operator/(const fp &x) const {
        return fp(*this) /= x;
    }
    bool operator==(const fp &x) const {
        return v == x.v;
    }
    bool operator!=(const fp &x) const {
        return v != x.v;
    }
    friend istream &operator>>(istream &is, fp &x) {
        return is >> x.v;
    }
    friend ostream &operator<<(ostream &os, const fp &x) {
        return os << x.v;
    }
};

template <unsigned mod> void rd(fp<mod> &x) {
    fastio::rd(x.v);
}
template <unsigned mod> void wt(fp<mod> x) {
    fastio::wt(x.v);
}

template <typename T> T Inv(ll n) {
    static const int md = T::get_mod();
    static vector<T> buf({0, 1});
    assert(n > 0);
    n %= md;
    while (SZ(buf) <= n) {
        int k = SZ(buf), q = (md + k - 1) / k;
        buf.push_back(buf[k * q - md] * q);
    }
    return buf[n];
}

template <typename T> T Fact(ll n, bool inv = 0) {
    static const int md = T::get_mod();
    static vector<T> buf({1, 1}), ibuf({1, 1});
    assert(n >= 0 and n < md);
    while (SZ(buf) <= n) {
        buf.push_back(buf.back() * SZ(buf));
        ibuf.push_back(ibuf.back() * Inv<T>(SZ(ibuf)));
    }
    return inv ? ibuf[n] : buf[n];
}

template <typename T> T nPr(int n, int r, bool inv = 0) {
    if (n < 0 || n < r || r < 0)
        return 0;
    return Fact<T>(n, inv) * Fact<T>(n - r, inv ^ 1);
}
template <typename T> T nCr(int n, int r, bool inv = 0) {
    if (n < 0 || n < r || r < 0)
        return 0;
    return Fact<T>(n, inv) * Fact<T>(r, inv ^ 1) * Fact<T>(n - r, inv ^ 1);
}
template <typename T> T nHr(int n, int r, bool inv = 0) {
    return nCr<T>(n + r - 1, r, inv);
}

/**
 * @brief Modint
 */

pair<ll,vector<string>> DFS(string S, int K) {
    if (K == 0) return {1,{S}};
    vector<int> V;
    rep(i,0,S.size()) {
        if (S[i] == (char)(K+'a')) V.push_back(i);
    }
    ll Ret = 0;
    vector<string> ANS;
    pair<ll,vector<string>> P;
    if (V.empty()) {
        P = DFS(S,K-1);
        Ret += P.first;
        rep(i,0,P.second.size()) ANS.push_back(P.second[i]);
        rep(i,0,S.size()) {
            if (S[i] == (char)(K-1+'a')) {
                S[i] = (char)(K+'a');
                auto P = DFS(S,K-1);
                Ret += P.first;
                rep(i,0,P.second.size()) ANS.push_back(P.second[i]);
                S[i] = (char)(K-1+'a');
            }
        }
    }
    else {
        rep(i,0,V[0]) {
            if (S[i] == (char)(K-1+'a')) {
                S[i] = (char)(K+'a');
                P = DFS(S,K-1);
                Ret += P.first;
                rep(i,0,P.second.size()) ANS.push_back(P.second[i]);
                S[i] = (char)(K-1+'a');
            }
        }
    }
    sort(ANS.begin(), ANS.end());
    vector<string> ANS2;
    if (ANS.size() <= 10) ANS2 = ANS;
    else {
        rep(i,0,5) ANS2.push_back(ANS[i]);
        rep(i,0,5) ANS2.push_back(ANS[ANS.size()-5+i]);
    }
    return {Ret, ANS2};
}

int main() {
while(1) {
    string S;
    cin >> S;
    if (S == "#") return 0;
    pair<ll,vector<string>> P = DFS(S,25);
    cout << P.first << endl;
    rep(i,0,P.second.size()) cout << P.second[i] << endl;
}
}
accuracy: 1
time_ms: 110
memory_kb: 3420
final_rank: 1

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;

using ll = long long;
using i64 = long long;
using pll = pair<ll,ll>;
using plll = pair<pll,ll>;
using pii =pair<int,int>;

constexpr ll mod = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int dX[4]={1,0,-1,0};
int dY[4]={0,-1,0,1};



//library

//end


using Graph =vector<vector<ll>>;

int main(){
    while (true){
        string S;
        cin>>S;
        if (S=="#")break;

        int n=S.size();
        vector<string> ans;

        for (int i=0; i<(1<<n); i++){
            unordered_set<int> cset;
            string T=S;
            for (int j=0; j<n; j++){
                int num=S[j]-'a';
                if ((1<<j)&i){
                    if (cset.count(num+1)!=0 || S[j]=='z')goto end;
                    cset.emplace(num+1);
                    T[j]='a'+num+1;
                }
                else{
                    if (cset.count(num)==0 && S[j]!='a')goto end;
                    cset.emplace(num);
                }
            }
            ans.push_back(T);
            end:;
        }
        sort(ans.begin(),ans.end());
        cout<<ans.size()<<endl;
        if (ans.size()<10){
            for (auto v: ans)cout<<v<<endl;
        }
        else{
            for (int i=0; i<5; i++){
                cout<<ans[i]<<endl;
            }
            for (int i=4; i>=0; i--){
                cout<<ans[ans.size()-1-i]<<endl;
            }
        }

    }

    return 0;

}
accuracy: 1
time_ms: 4630
memory_kb: 4812
final_rank: 17

code_snippet: #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

vector<short> exist(26);

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    while (true) {
        string s;
        cin >> s;
        if (s == "#") break;

        int n = s.size();
        vector<string> ans;
        for (int i = 0; i < (1<<n); ++i) {
            string t = s;
            for (int j = 0; j < n; ++j) {
                if ((i >> j & 1) && s[j] != 'z') {
                    ++t[j];
                }
            }

            string cand = t;
            fill(exist.begin(), exist.end(), 0);
            for (char &c : t) {
                exist[c-'a'] = 1;
            }
            for (int i = 1; i < 26; ++i) {
                if (!exist[i]) continue;
                for (int j = 0; j < t.size(); ++j) {
                    if (t[j] == 'a' + i) {
                        t[j] -= 1;
                        break;
                    }
                }
            }
            if (s == t) ans.emplace_back(cand);
        }

        sort(ans.begin(), ans.end());
        ans.erase(unique(ans.begin(), ans.end()), ans.end());
        cout << ans.size() << '\n';
        if (ans.size() <= 10) {
            for (string &c : ans) {
                cout << c << '\n';
            }
        } else {
            int m = ans.size();
            for (int i = 0; i < 5; ++i) cout << ans[i] << '\n';
            for (int i = m-5; i < m; ++i) cout << ans[i] << '\n';
        }
    }
}
accuracy: 1
time_ms: 7480
memory_kb: 4936
final_rank: 19

code_snippet: #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

vector<short> exist(26);

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    while (true) {
        string s;
        cin >> s;
        if (s == "#") break;

        int n = s.size();
        vector<string> ans;
        for (int i = 0; i < (1<<n); ++i) {
            string t = s;
            for (int j = 0; j < n; ++j) {
                if ((i >> j & 1) && s[j] != 'z') {
                    ++t[j];
                }
            }

            string cand = t;
            fill(exist.begin(), exist.end(), 0);
            for (char &c : t) {
                exist[c-'a'] = 1;
            }
            for (int i = 1; i < 26; ++i) {
                if (!exist[i]) continue;
                for (int j = 0; j < t.size(); ++j) {
                    if (t[j] == 'a' + i) {
                        t[j] -= 1;
                        break;
                    }
                }
            }
            if (s == t) ans.emplace_back(cand);
        }

        unordered_set<string> st;
        for (string & t: ans) {
            st.emplace(t);
        }
        ans.clear();
        for (const string &t : st) {
            ans.emplace_back(t);
        }
        sort(ans.begin(), ans.end());
        cout << ans.size() << '\n';
        if (ans.size() <= 10) {
            for (string &c : ans) {
                cout << c << '\n';
            }
        } else {
            int m = ans.size();
            for (int i = 0; i < 5; ++i) cout << ans[i] << '\n';
            for (int i = m-5; i < m; ++i) cout << ans[i] << '\n';
        }
    }
}
accuracy: 1
time_ms: 8000
memory_kb: 6008
final_rank: 20

code_snippet: #include <bits/stdc++.h>

int to(char c) {
    return c - 'a';
}

bool solve() {
    std::string S;
    std::cin >> S;
    if (S == "#") return false;
    std::vector<std::string> ans;
    auto rec{[&](auto rec, int i, int used, std::string& cur) -> void {
        if (i == (int)S.size()) {
            assert(cur.size() == S.size());
            ans.push_back(cur);
            return;
        }
        if (S[i] == 'a') {
            if (!(used & (1 << to('b')))) {
                cur += 'b';
                rec(rec, i + 1, used | (1 << to('b')), cur);
                cur.pop_back();
            }
            cur += 'a';
            rec(rec, i + 1, used, cur);
            cur.pop_back();
        }
        else if (S[i] == 'z') {
            if (!(used & (1 << to('z')))) {
                return;
            }
            cur += 'z';
            rec(rec, i + 1, used, cur);
            cur.pop_back();
        }
        else {
            if (!(used & (1 << to(S[i] + 1)))) {
                cur += S[i] + 1;
                rec(rec, i + 1, used | (1 << to(S[i] + 1)), cur);
                cur.pop_back();
            }
            if ((used & (1 << to(S[i])))) {
                cur += S[i];
                rec(rec, i + 1, used, cur);
                cur.pop_back();
            }
        }
    }};
    std::string T;
    rec(rec, 0, 0, T);
    std::sort(ans.begin(), ans.end());
    std::cout << ans.size() << '\n';
    if (ans.size() <= 10u) {
        for (const auto& x : ans) std::cout << x << '\n';
    }
    else {
        for (int i{} ; i < 5 ; i++) std::cout << ans[i] << '\n';
        for (int i{4} ; i >= 0 ; i--) std::cout << ans[ans.size() - i - 1] << '\n';
    }
    return true;
}

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);
    while (solve()) ;
}
accuracy: 1
time_ms: 10
memory_kb: 4400
final_rank: 4

code_snippet: #line 2 "cp-library/src/cp-template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull  = unsigned long long;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
template < class T > bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }
template < class T > bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
template < class T, class U > T ceil (T x, U y) { return (x > 0 ? (x + y - 1) / y :           x / y); }
template < class T, class U > T floor(T x, U y) { return (x > 0 ?           x / y : (x - y + 1) / y); }
int popcnt(i32 x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(i64 x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }

#line 2 "cp-library/src/utility/rep_itr.hpp"
template < class T > struct itr_rep {
    T i, d;
    constexpr itr_rep(const T i) noexcept : i(i), d(1) {}
    constexpr itr_rep(const T i, const T d) noexcept : i(i), d(d) {}
    void operator++() noexcept { i += d; }
    constexpr int operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr_rep x) const noexcept { return d > 0 ? i < x.i : i > x.i; }
};

template < class T > struct rep {
    const itr_rep< T > s, t;
    constexpr rep(const T t) noexcept : s(0), t(t) {}
    constexpr rep(const T s, const T t) noexcept : s(s), t(t) {}
    constexpr rep(const T s, const T t, const T d) noexcept : s(s, d), t(t, d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};

template < class T > struct revrep {
    const itr_rep < T > s, t;
    constexpr revrep(const T t) noexcept : s(t - 1, -1), t(-1, -1) {}
    constexpr revrep(const T s, const T t) noexcept : s(t - 1, -1), t(s - 1, -1) {}
    constexpr revrep(const T s, const T t, const T d) noexcept : s(t - 1, -d), t(s - 1, -d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};
#line 3 "cp-library/src/utility/io.hpp"

/* 128bit integer */
istream& operator>>(istream& is, i128& x) {
    std::string s; is >> s;
    int pm = (s[0] == '-');
    x = 0;
    for(int i : rep(pm, int(s.size()))) x = x * 10 + (s[i] - '0');
    if(pm) x *= -1;
    return is;
}
ostream& operator<<(ostream& os, const i128& x) {
    if(x == 0) return os << '0';
    i128 y = x;
    if(y < 0) { os << '-'; y *= -1; }
    std::vector<int> ny;
    while(y > 0) { ny.push_back(y % 10); y /= 10; }
    for(int i : revrep(ny.size())) os << ny[i];
    return os;
}

template < class S, class T > istream& operator>>(istream& is,       std::pair< S, T >& x) { is >> x.first        >> x.second; return is; }
template < class S, class T > ostream& operator<<(ostream& os, const std::pair< S, T >& x) { os << x.first << " " << x.second; return os; }

namespace scanner {
    struct sca {
        template < class T > operator T() {
            T s; std::cin >> s; return s;
        }
    };
    struct vec {
        int n;
        vec(int n) : n(n) {}
        template < class T > operator std::vector< T >() {
            std::vector< T > v(n);
            for(T& x : v) std::cin >> x;
            return v;
        }
    };
    struct mat {
        int h, w;
        mat(int h, int w) : h(h), w(w) {}
        template < class T > operator std::vector< std::vector< T > >() {
            std::vector m(h, std::vector< T >(w));
            for(std::vector< T >& v : m) for(T& x : v) std::cin >> x;
            return m;
        }
    };
    struct speedup {
        speedup() {
            std::cin.tie(0);
            std::ios::sync_with_stdio(0);
        }
    } speedup_instance;
}
scanner::sca in() { return scanner::sca(); }
scanner::vec in(int n) { return scanner::vec(n); }
scanner::mat in(int h, int w) { return scanner::mat(h, w); }

namespace printer {
    void precision(int d) { std::cout << std::fixed << std::setprecision(d); }
    void flush() { std::cout.flush(); }
}

template < class T >
ostream& operator<<(ostream& os, const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) { os << a[i]; if(i != n - 1) os << ' '; }
    return os;
}

int print() { std::cout << '\n'; return 0; }
template < class head, class... tail > int print(head&& h, tail&&... t) {
    std::cout << h; if(sizeof...(tail)) std::cout << ' ';
    return print(std::forward<tail>(t)...);
}
template < class T > int print_n(const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) std::cout << a[i] << "\n";
    return 0;
}


#line 2 "cp-library/src/utility/key_val.hpp"

template < class K, class V >
struct key_val {
    K key; V val;
    key_val() {}
    key_val(K key, V val) : key(key), val(val) {}
    template < std::size_t Index >
    std::tuple_element_t< Index, key_val >& get() {
        if constexpr (Index == 0) return key;
        if constexpr (Index == 1) return val;
    }
};

namespace std {

template < class K, class V > struct tuple_size < key_val< K, V > > : integral_constant< size_t, 2 > {};
template < class K, class V > struct tuple_element < 0, key_val< K, V > > { using type = K; };
template < class K, class V > struct tuple_element < 1, key_val< K, V > > { using type = V; };

}
#line 2 "cp-library/src/utility/vec_op.hpp"
template < class T > key_val< int, T > max_of(const vector< T >& a) {
    int i = std::max_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class T > key_val< int, T > min_of(const vector< T >& a) {
    int i = std::min_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class S, class T > S sum_of(const vector< T >& a) {
    S sum = 0;
    for(const T x : a) sum += x;
    return sum;
}
template < class S, class T > vector< S > freq_of(const vector< T >& a, T L, T R) {
    vector< S > res(R - L, S(0));
    for(const T x : a) res[x - L] += 1;
    return res;
}
template < class S, class T > struct prefix_sum {
    vector< S > s;
    prefix_sum(const vector< T >& a) : s(a) {
        s.insert(s.begin(), S(0));
        for(int i : rep(a.size())) s[i + 1] += s[i];
    }
    // [L, R)
    S sum(int L, int R) { return s[R] - s[L]; }
};
#line 3 "cp-library/src/utility/heap.hpp"

template < class T > using heap_min = std::priority_queue< T, std::vector< T >, std::greater< T > >;
template < class T > using heap_max = std::priority_queue< T, std::vector< T >, std::less< T > >;

#line 27 "cp-library/src/cp-template.hpp"

#line 1 "cp-library/src/algorithm/bin_search.hpp"
template < class T, class F >
T bin_search(T ok, T ng, F f) {
    while(abs(ng - ok) > 1) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

template < class T, class F >
T bin_search_real(T ok, T ng, F f, int step = 80) {
    while(step--) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}
#line 2 "cp-library/src/algorithm/argsort.hpp"

template < class T > std::vector< int > argsort(const std::vector< T > &a) {
    std::vector< int > ids((int)a.size());
    std::iota(ids.begin(), ids.end(), 0);
    std::sort(ids.begin(), ids.end(), [&](int i, int j) {
        return a[i] < a[j] || (a[i] == a[j] && i < j);
    });
    return ids;
}
#line 1 "macro.hpp"
namespace macro {

using size_type = int;
template < class container > void  sort(container& a) { std::sort(std:: begin(a), std:: end(a)); }
template < class container > void rsort(container& a) { std::sort(std::rbegin(a), std::rend(a)); }
template < class container > void reverse(container& a) { std::reverse(std::begin(a), std::end(a)); }
template < class container > void unique(container& a) {
    std::sort(std::begin(a), std::end(a));
    a.erase(std::unique(std::begin(a), std::end(a)), std::end(a));
}
template < class container > container  sorted(const container& a) { container b = a;  sort(b); return std::move(b); }
template < class container > container rsorted(const container& a) { container b = a; rsort(b); return std::move(b); }
template < class container, class compare > void sort(container& a, const compare& cmp) { std::sort(std::begin(a), std::end(a), cmp); }
template < class container, class compare > container sorted(const container& a, const compare& cmp) { container b = a; sort(b, cmp); return std::move(b); }
template < class container, class value > size_type lower_bound(const container& a, const value& x) { return std::lower_bound(std::begin(a), std::end(a), x) - std::begin(a); }
template < class container, class value > size_type upper_bound(const container& a, const value& x) { return std::upper_bound(std::begin(a), std::end(a), x) - std::begin(a); }

const std::vector<std::pair<size_type, size_type>> dir4 = { {+1,  0}, {-1,  0}, { 0, +1}, { 0, -1} };
const std::vector<std::pair<size_type, size_type>> dir8 = { {-1, -1}, {-1,  0}, {-1, +1}, { 0, -1}, { 0, +1}, {+1, -1}, {+1,  0}, {+1, +1} };

#ifdef _DEBUG
#define debug(x) std::cout << "[" << __LINE__ << "] " << #x << ": " << x << std::endl
#else
#define debug(x)
#endif

template < class container > void concat(container& a, const container& b) {
    a.insert(std::end(a), std::begin(b), std::end(b));
}
std::vector<size_type> iota(const size_type n) {
    std::vector<size_type> I(n);
    std::iota(std::begin(I), std::end(I), 0);
    return I;
}
template < class container > std::vector<size_type> sort_idx(const container& a) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return a[i] < a[j] or (a[i] == a[j] and i < j); });
    return I;
}
template < class container, class compare > std::vector<size_type> sort_idx(const container& a, const compare& cmp) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return cmp(a[i], a[j]) or (a[i] == a[j] and i < j); });
    return std::move(I);
}

struct grid {
    using size_type = int;
    size_type H, W;
    grid(const size_type H, const size_type W) : H(H), W(W) {}
    bool contains(const size_type i, const size_type j) {
        return 0 <= i and i < H and 0 <= j and j < W;
    }
};

} // namespace macro

using namespace macro;
#line 3 "A.cpp"

vector<string> solve(string target) {
    vector<string> ans;
    auto dfs = [&](auto self, string s, int id) -> void {
        if(id == 25) {
            ans.push_back(s);
            return;
        } else {
            char y = char('z' - id - 1), z = char('z' - id);
            int lz = s.size();
            for(int i : revrep(s.size())) if(s[i] == z) lz = i;
            for(int i : rep(s.size())) if(s[i] == y and i < lz) {
                string t = s;
                t[i] = z;
                self(self, t, id + 1);
            }
            if(lz == s.size()) self(self, s, id + 1);
        }
    };

    dfs(dfs, target, 0);
    sort(ans);
    return ans;
}

int main() {
    while(true) {
        string s = in();
        if(s == "#") return 0;
        auto ans = solve(s);
        print(ans.size());
        if(ans.size() <= 10) {
            print_n(ans);
        } else {
            for(int i : rep(5)) print(ans[i]);
            for(int i : revrep(5)) print(ans[ans.size() - 1 - i]);
        }
    }
}
accuracy: 1
time_ms: 20
memory_kb: 4972
final_rank: 12

code_snippet: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

void solve(string S) {
	vector<string> Cand;

	// Brute Force
	for (int i = 0; i < (1 << S.size()); i++) {
		vector<bool> used(26, false);
		bool flag = true;
		for (int j = 0; j < S.size(); j++) {
			int chr = (S[j] - 'a');
			int prv = chr + ((i >> j) & 1);
			if (chr != prv && (S[j] == 'z' || used[prv] == true)) { flag = false; break; }
			if (chr == prv && (S[j] != 'a' && used[prv] == false)) { flag = false; break; }
			used[prv] = true;
		}
		if (flag == false) continue;
		string str = "";
		for (int j = 0; j < S.size(); j++) {
			if (((i >> j) & 1) == 1) str += (S[j] + 1);
			if (((i >> j) & 1) == 0) str += (S[j] + 0);
		}
		Cand.push_back(str);
	}

	// Sorting
	sort(Cand.begin(), Cand.end());
	cout << Cand.size() << endl;
	if (Cand.size() <= 10) {
		for (int i = 0; i < Cand.size(); i++) cout << Cand[i] << endl;
	}
	else {
		for (int i = 0; i < 5; i++) cout << Cand[i] << endl;
		for (int i = Cand.size() - 5; i < Cand.size(); i++) cout << Cand[i] << endl;
	}
}

int main() {
	while (true) {
		string str; cin >> str;
		if (str == "#") break;
		solve(str);
	}
	return 0;
}
accuracy: 1
time_ms: 690
memory_kb: 4776
final_rank: 13

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, a, n) for (int i = a; i < n; i++)
using namespace std;

string s;
vector<string> vs;

void dfs(string &t, int now) {
  if (now == s.size()) {
    vs.push_back(t);
    return;
  }
  int d[26] = {};
  rep(i, 0, now) d[t[i] - 'a']++;
  if (t[now] != 'z' && d[t[now] + 1 - 'a'] == 0) {
    t[now] = t[now] + 1;
    dfs(t, now + 1);
    t[now] = t[now] - 1;
  }
  if (t[now] == 'a' || d[t[now] - 'a'] != 0)
    dfs(t, now + 1);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  while (1) {
    cin >> s;
    if (s == "#")
      break;
    vs.clear();
    dfs(s, 0);
    int ans = vs.size();
    sort(vs.begin(), vs.end());
    cout << ans << endl;
    if (ans <= 10) {
      rep(i, 0, ans) { cout << vs[i] << endl; }
    } else {
      rep(i, 0, 5) { cout << vs[i] << endl; }
      rep(i, ans - 5, ans) { cout << vs[i] << endl; }
    }
  }
}
accuracy: 1
time_ms: 10
memory_kb: 4452
final_rank: 5

code_snippet: #include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
using namespace std;
string s;
set<string> vs;
bool f[26];
void dfs(string t, int now) {
  if (now == s.size()) {
    vs.insert(t);
    return;
  }
  int d[26] = {};
  rep(i, 0, now) d[t[i] - 'a']++;
  if (t[now] != 'z' && d[t[now] + 1 - 'a'] == 0) {
    string tmp = t;
    tmp[now] = tmp[now] + 1;
    dfs(tmp, now + 1);
  }
  if (t[now] == 'a' || d[t[now] - 'a'] != 0)
    dfs(t, now + 1);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  while (1) {
    cin >> s;
    if (s == "#")
      break;
    vs.clear();
    dfs(s, 0);
    int ans = vs.size();
    cout << ans << endl;
    auto it = vs.begin();
    if (ans <= 10) {
      rep(i, 0, ans) { 
         cout << *it++ << endl; 
      }
    } else {
      rep(i, 0, 5) { 
         cout << *it++ << endl; 
      }
      it = prev(vs.end(), 5);
      rep(i, ans - 5, ans) { 
         cout << *it++ << endl; 
      }
    }
  }
}
accuracy: 1
time_ms: 20
memory_kb: 5236
final_rank: 14

code_snippet: #include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
using namespace std;
string s;
vector<string> vs;
void dfs(string t, int now) {
  if (now == s.size()) {
    vs.push_back(t);
    return;
  }
  int d[26] = {};
  rep(i, 0, now) d[t[i] - 'a']++;
  if (t[now] != 'z' && d[t[now] + 1 - 'a'] == 0) {
    string tmp = t;
    tmp[now] = tmp[now] + 1;
    dfs(tmp, now + 1);
  }
  if (t[now] == 'a' || d[t[now] - 'a'] != 0)
    dfs(t, now + 1);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  while (1) {
    cin >> s;
    if (s == "#")
      break;
    vs.clear();
    dfs(s, 0);
    int ans = vs.size();
    sort(vs.begin(), vs.end());
    cout << ans << endl;
    if (ans <= 10) {
      rep(i, 0, ans) { cout << vs[i] << endl; }
    } else {
      rep(i, 0, 5) { cout << vs[i] << endl; }
      rep(i, ans - 5, ans) { cout << vs[i] << endl; }
    }
  }
}
accuracy: 1
time_ms: 10
memory_kb: 4336
final_rank: 3

code_snippet: #include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
using namespace std;
string s;
vector<string> vs;
bool f[26];
void dfs(string t, int now) {
  if (now == s.size()) {
    vs.push_back(t);
    return;
  }
  int d[26] = {};
  rep(i, 0, now) d[t[i] - 'a']++;
  if (t[now] != 'z' && d[t[now] + 1 - 'a'] == 0) {
    string tmp = t;
    tmp[now] = tmp[now] + 1;
    dfs(tmp, now + 1);
  }
  if (t[now] == 'a' || d[t[now] - 'a'] != 0)
    dfs(t, now + 1);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  while (1) {
    cin >> s;
    if (s == "#")
      break;
    vs.clear();
    dfs(s, 0);
    int ans = vs.size();
    sort(vs.begin(), vs.end());
    cout << ans << endl;
    if (ans <= 10) {
      rep(i, 0, ans) { cout << vs[i] << endl; }
    } else {
      rep(i, 0, 5) { cout << vs[i] << endl; }
      rep(i, ans - 5, ans) { cout << vs[i] << endl; }
    }
  }
}
accuracy: 1
time_ms: 10
memory_kb: 4520
final_rank: 7