# 2. 题解

$001001001000000000000000000000000000000000000000000000000000000000000000000000$

QvQ

#include <bits/stdc++.h>

#define NS (10005)
#define MS (105)
#define MOD (14233333ll)

using namespace std;

int n, cnt[26], len[NS], h[NS], htab[MOD], dis[NS], pre[NS], ans, mx;

bool book[NS];

char str[NS][MS];

queue<int> que;

stack<int> st;

int main(int argc, char const* argv[])
{
while (~scanf("%s", str[++n])); n--;
for (int i = 1; i <= n; i += 1)
{
len[i] = strlen(str[i]), memset(cnt, 0, sizeof(cnt));
for (int j = 0; j < len[i]; j += 1)cnt[str[i][j] - 'a']++;
for (int j = 0; j < 26; j += 1)
h[i] = ((100ll * h[i] % MOD) + cnt[j]) % MOD;
htab[h[i]] = i, que.push(i), dis[i] = book[i] = 1;
}
while (!que.empty())
{
int F = que.front(); que.pop(), book[F] = 0;
for (int i = 0, tot = 1, nxt; i < 26; i += 1, tot = 100ll * tot % MOD)
if (htab[(h[F] + tot) % MOD])
if (nxt = htab[(h[F] + tot) % MOD], dis[nxt] < dis[F] + 1)
{
dis[nxt] = dis[F] + 1, pre[nxt] = F;
if (!book[nxt]) que.push(nxt), book[nxt] = 1;
}
}
for (int i = 1; i <= n; i += 1) if (ans < dis[i]) mx = i, ans = dis[i];
while (mx) st.push(mx), mx = pre[mx];
printf("%d\n", ans);
while (!st.empty()) puts(str[st.top()]), st.pop();
return 0;
}