#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <string>
#include <stack>
using namespace std;
const int N = 1e5 + 10;
map<string, int> mp;
stack<string> st;
int n;
string str;
int son[N][52], idx;
void init_map() {
mp["AC"] = 0;
mp["2C"] = 1;
mp["3C"] = 2;
mp["4C"] = 3;
mp["5C"] = 4;
mp["6C"] = 5;
mp["7C"] = 6;
mp["8C"] = 7;
mp["9C"] = 8;
mp["10C"] = 9;
mp["JC"] = 10;
mp["QC"] = 11;
mp["KC"] = 12;
mp["AD"] = 13;
mp["2D"] = 14;
mp["3D"] = 15;
mp["4D"] = 16;
mp["5D"] = 17;
mp["6D"] = 18;
mp["7D"] = 19;
mp["8D"] = 20;
mp["9D"] = 21;
mp["10D"] = 22;
mp["JD"] = 23;
mp["QD"] = 24;
mp["KD"] = 25;
mp["AH"] = 26;
mp["2H"] = 27;
mp["3H"] = 28;
mp["4H"] = 29;
mp["5H"] = 30;
mp["6H"] = 31;
mp["7H"] = 32;
mp["8H"] = 33;
mp["9H"] = 34;
mp["10H"] = 35;
mp["JH"] = 36;
mp["QH"] = 37;
mp["KH"] = 38;
mp["AS"] = 39;
mp["2S"] = 40;
mp["3S"] = 41;
mp["4S"] = 42;
mp["5S"] = 43;
mp["6S"] = 44;
mp["7S"] = 45;
mp["8S"] = 46;
mp["9S"] = 47;
mp["10S"] = 48;
mp["JS"] = 49;
mp["QS"] = 50;
mp["KS"] = 51;
}
void insert() {
int p = 0;
while (st.size()) {
string t = st.top();
st.pop();
int u = mp[t];
if (!son[p][u])
son[p][u] = ++ idx;
p = son[p][u];
}
}
int main() {
init_map();
while (~scanf("%d", &n)) {
if (n == 0)
break;
memset(son, 0, sizeof son);
idx = 0;
while (n -- ) {
while (st.size())
st.pop();
int m;
scanf("%d", &m);
while (m -- ) {
cin >> str;
st.push(str);
}
insert();
}
printf("%d\n", idx);
}
return 0;
}
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 100;
char str[10];
bool flag;
int casei;
int son[N][2], idx, cnt[N];
bool insert(char str[]) {
int p = 0;
for (int i = 0; str[i]; i ++ ) {
int u = str[i] - '0';
if (!son[p][u])
son[p][u] = ++ idx;
p = son[p][u];
if (cnt[p])
return true;
}
for (int i = 0; i < 2; i ++ )
if (son[p][i])
return true;
cnt[p] ++ ;
return false;
}
int main() {
while (gets(str)) {
if (str[0] == '9') {
if (flag)
printf("Set %d is not immediately decodable\n", ++ casei);
else
printf("Set %d is immediately decodable\n", ++ casei);
memset(son, 0, sizeof son);
memset(cnt, 0, sizeof cnt);
idx = 0;
flag = false;
} else if (insert(str))
flag = true;
}
return 0;
}
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 4e5 + 10;
int son[N][4], cnt[N], idx;
int n, m;
char str[20010][30];
int ans[20010];
int solve(char ch) {
if (ch == 'A')
return 0;
else if (ch == 'C')
return 1;
else if (ch == 'G')
return 2;
return 3;
}
void insert(char str[]) {
int p = 0;
for (int i = 0; str[i]; i ++ ) {
int u = solve(str[i]);
if (!son[p][u])
son[p][u] = ++ idx;
p = son[p][u];
}
cnt[p] ++ ;
}
int main() {
while (~scanf("%d%d", &n, &m)) {
if (n == 0 && m == 0)
break;
memset(son, 0, sizeof son);
idx = 0;
memset(cnt, 0, sizeof cnt);
memset(ans, 0, sizeof ans);
for (int i = 1; i <= n; i ++ ) {
scanf("%s", str[i]);
insert(str[i]);
}
for (int i = 1; i <= idx; i ++ )
if (cnt[i])
ans[cnt[i]] ++ ;
for (int i = 1; i <= n; i ++ )
printf("%d\n", ans[i]);
}
return 0;
}