#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
int n,cnt = 0;
long long int ans = 0;
const int maxn = 4000007;
char ch[1007];
struct Node
{
int nx[64];
int cnt;
}tree[maxn];
void Init() {
cnt = 1;
ans = 0;
memset(&tree[1], 0, sizeof(Node));
}
int GetId(char input) {
if (input == '\0') return 0;
else if (input >= '0' && input <= '9') return 1 + input - '0';
else if (input >= 'A' && input <= 'Z') return 11 + input - 'A';
else return input - 'a' + 37;
}
void Insert(char* input) {
int cur = 1,id = 0,isNew = 0;
int len = strlen(input);
int last = tree[cur].cnt;
for (int i = 0; i <= len; i++) {
id = GetId(input[i]);
if (tree[cur].nx[id] == 0) {
memset(&tree[cnt + 1], 0, sizeof(Node));
tree[cur].nx[id] = ++cnt;
if (!isNew) ans += last;
isNew = 1;
}
else {
int nx = tree[cur].nx[id];
ans += last - tree[nx].cnt;
ans += tree[nx].cnt * 2;
}
cur = tree[cur].nx[id];
last = tree[cur].cnt;
tree[cur].cnt++;
}
tree[1].cnt++;
}
static auto speedup = [](){ios::sync_with_stdio(false);cin.tie(nullptr);return nullptr;}();
int main()
{
int kCase = 0;
while (cin >> n && n) {
Init();
for (int i = 0; i < n; i++) {
cin >> ch;
Insert(ch);
}
cout <<"Case " << ++kCase << ": " << ans << endl;
}
return 0;
}
uva11732
于 2022-02-08 21:31:31 首次发布