Language: C++

#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string>
#include<set>
#include<vector>
#include<string.h>
using namespace std;
char str[50];
char word[35][30];
vector<string>ans;
struct wolf{
	int flag;
	int par;
	int chi[27];
	int dep;
	int val;
	int fail;
	wolf(){
		flag=dep=0;
		val=-1;
		par=-1;
		fail=0;
		for(int i=0;i<27;i++)chi[i]=-1;
	}
};
int LIM=5;
wolf pool[1100];
typedef unsigned long long nt;
nt key=1000000007;
set<nt>hash;
int len;
int sz;
int ret;
inline int chk(string t){
	int at=0;
	int last=0;
	for(int i=0;i<t.size();i++){
		while(1){
			if(pool[at].chi[t[i]-'@']!=-1){
				at=pool[at].chi[t[i]-'@'];
				break;
			}
			if(at==0){
				break;
			}
			at=pool[at].fail;
		}
		if(pool[at].flag)last=i+1;
		if(pool[at].dep<=i-last)return 0;
	}
	
	if(last==t.size()){
	//	printf("%s\n",t.c_str());
		return 1;
	}
	return 0;
}
void dfs(int a,string b){
	//printf("%d %s\n",a,b.c_str());
	
	nt t=0;
	for(int i=0;i<b.size();i++){
		t*=key;
		t+=b[i]-'@'+1;
	}
	if(!hash.count(t)){
		hash.insert(t);
		if(chk(b)){
			ret++;
			if(ans.size()<LIM){
				ans.push_back(b);
			}
		}
	}
	if(a==0)return;
	
	for(int i=0;i<27;i++){
		for(int j=0;j<=b.size();j++){
			string c=b;
			c.insert(c.begin()+j,'@'+i);
			dfs(a-1,c);
		}
		for(int j=0;j<b.size();j++){
			char p=b[j];
			b[j]='@'+i;
			dfs(a-1,b);
			b[j]=p;
		}
	}
	for(int i=0;i<b.size();i++){
		string c=b;
		c.erase(c.begin()+i);
		dfs(a-1,c);
	}
}
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),b){
		scanf("%s",str);
		for(int i=0;str[i];i++)if(str[i]=='.')str[i]='@';
		for(int i=0;i<b;i++){
			scanf("%s",word+i);
			for(int j=0;word[i][j];j++)if(word[i][j]=='.')word[i][j]='@';
		}
		ans.clear();
		len=strlen(str);
		ret=0;
		sz=1;
		pool[0]=wolf();
		hash.clear();
		for(int i=0;i<b;i++){
			int at=0;
			for(int j=0;word[i][j];j++){
				if(pool[at].chi[word[i][j]-'@']==-1){
					pool[sz]=wolf();
					pool[sz].val=word[i][j]-'@';
					pool[sz].par=at;
					pool[at].chi[word[i][j]-'@']=sz;
					pool[sz].dep=j+1;
					at=sz;
					sz++;
				}else{
					at=pool[at].chi[word[i][j]-'@'];
				}
			}
			pool[at].flag=1;
		}
		
		queue<int>Q;
		Q.push(0);
		while(Q.size()){
			int now=Q.front();Q.pop();
			for(int i=0;i<27;i++){
				if(~pool[now].chi[i])Q.push(pool[now].chi[i]);
			}
			if(now==0||pool[now].par==0){
				pool[now].fail=0;continue;
			}
			int at=pool[now].par;
			while(1){
				if(at==0){
					pool[now].fail=0;break;
				}
				at=pool[at].fail;
				if(pool[at].chi[pool[now].val]!=-1){
					pool[now].fail=pool[at].chi[pool[now].val];
					if(pool[pool[now].fail].flag)pool[now].flag=1;
					break;
				}
			}
		}
		string T=str;
		dfs(a,T);
		printf("%d\n",ret);
		if(ret<=LIM){
			std::sort(ans.begin(),ans.end());
			for(int i=0;i<ret;i++){
				for(int j=0;j<ans[i].size();j++){
					if(ans[i][j]=='@')printf(".");
					else printf("%c",ans[i][j]);
				}
				printf("\n");
			}
		}
	}
}

Compiler output:
a.cc: In function 'void dfs(int, std::string)':
a.cc:67:13: error: reference to 'hash' is ambiguous
   67 |         if(!hash.count(t)){
      |             ^~~~
In file included from /usr/include/c++/14/bits/stl_bvector.h:65,
                 from /usr/include/c++/14/vector:67,
                 from /usr/include/c++/14/queue:63,
                 from a.cc:3:
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:31:8: note:                 'std::set<long long unsigned int> hash'
   31 | set<nt>hash;
      |        ^~~~
a.cc:68:17: error: reference to 'hash' is ambiguous
   68 |                 hash.insert(t);
      |                 ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:31:8: note:                 'std::set<long long unsigned int> hash'
   31 | set<nt>hash;
      |        ^~~~
a.cc: In function 'int main()':
a.cc:111:17: error: reference to 'hash' is ambiguous
  111 |                 hash.clear();
      |                 ^~~~
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:31:8: note:                 'std::set<long long unsigned int> hash'
   31 | set<nt>hash;
      |        ^~~~