#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
using namespace std;
#define MN 750
#define MX 10000000
#define MV 1500
#define ME 300000
#define S MV+1
#define T MV+2
#define INF 0x7FFFFFFF
namespace flow
{
struct edge{int nx,t,w;}e[ME*2+5];
int h[MV+5],en=1,d[MV+5],c[MV+5],q[MV+5],qn;
inline void ins(int x,int y,int w)
{
	e[++en]=(edge){h[x],y,w};h[x]=en;
	e[++en]=(edge){h[y],x,0};h[y]=en;
}
bool bfs()
{
	int i,j;memset(d,0,sizeof(d));
	for(d[q[i=qn=0]=S]=1;i<=qn;++i)for(j=c[q[i]]=h[q[i]];j;j=e[j].nx)
		if(e[j].w&&!d[e[j].t])d[q[++qn]=e[j].t]=d[q[i]]+1;
	return d[T];
}
int dfs(int x,int r)
{
	if(x==T)return r;
	int k,u=0;
	for(int&i=c[x];i;i=e[i].nx)if(e[i].w&&d[e[i].t]==d[x]+1)
	{
		k=dfs(e[i].t,min(e[i].w,r-u));
		e[i].w-=k;e[i^1].w+=k;u+=k;
		if(u==r)return u;
	}
	return d[x]=0,u;
}
}
char s[MX+5];
int tn,c[MX+5][2],f[MX+5],q[MX+5],qn,t[MX+5];
bitset<MN+5> b[MN+5],bb;
struct edge{int nx,t;}E[MX*2+5];
int v[MX+5],fc[MX+5],en,z[MX+5],zn;
inline void ins(int*h,int x,int y){E[++en]=(edge){h[x],y};h[x]=en;}
int main()
{
	int n,i,j,x,y,ans;
	scanf("%d",&n);ans=n;
	for(i=1;i<=n;++i)
	{
		scanf("%s",s);
		for(j=x=0;s[j];ins(v,x=c[x][s[j++]-'a'],i))
			if(!c[x][s[j]-'a'])c[x][s[j]-'a']=++tn;
		t[x]=i;
	}
	for(i=0;i<2;++i)if(c[0][i])ins(fc,0,q[++qn]=c[0][i]);
	for(i=1;i<=qn;++i)for(j=0;j<2;++j)if(c[q[i]][j])
	{
		for(x=f[q[i]];x&&!c[x][j];x=f[x]);
		f[c[q[i]][j]]=c[x][j];
		ins(fc,c[x][j],c[q[i]][j]);
		q[++qn]=c[q[i]][j];
	}
	f[qn=0]=-1;
	while(zn>=0)
		if(x=z[zn],f[zn]<0)
		{
			if(t[x])q[++qn]=t[x];
			if(qn)for(int i=v[x];i;i=E[i].nx)b[E[i].t][q[qn]]=b[E[i].t][q[qn-1]]=1;
			f[zn]=fc[x];
		}
		else if(f[zn])
		{
			z[zn+1]=E[f[zn]].t;f[zn+1]=-1;
			f[zn]=E[f[zn]].nx;++zn;
		}
		else{if(t[x])--qn;--zn;}
	for(x=1;x<=n;++x)for(i=1;i<=n;++i)if(b[i][x])b[i]|=b[x];
	using namespace flow;
	for(i=1;i<=n;++i)
	{
		ins(S,i,1);ins(i+n,T,1);
		for(j=1;j<=n;++j)if(i!=j&&b[i][j])ins(i,j+n,1);
	}
	while(bfs())ans-=dfs(S,INF);
	printf("%d\n",ans);
	for(i=1;i<=n;++i)for(t[i]=0,j=h[i];j;j=e[j].nx)if(!e[j].w&&e[j].t!=S)t[i]=e[j].t-n;
	for(i=h[T];i;i=e[i].nx)if(!e[i].w)for(j=e[i].t-n;j;j=t[j])if(!bb[j])
	{
		for(x=e[i].nx;x;x=e[x].nx)if(!e[x].w)
		{
			for(y=e[x].t-n;y;y=t[y])if(!bb[y]&&!b[j][y]&&!b[y][j])break;
			if(!y)break;
		}
		if(x)continue;
		printf("%d ",j);
		for(x=1;x<=n;++x)bb[x]=bb[x]|b[j][x]|b[x][j];
		break;
	}
}


#include<cstring>
#include<iostream>
#include<algorithm>
#include<bitset>
using namespace std;
#define MN 750
#define MX 10000000
#define MV 1500
#define ME 300000
#define S MV+1
#define T MV+2
#define INF 0x7FFFFFFF
namespace flow
{
struct edge{int nx,t,w;}e[ME*2+5];
int h[MV+5],en=1,d[MV+5],c[MV+5],q[MV+5],qn;
inline void ins(int x,int y,int w)
{
	e[++en]=(edge){h[x],y,w};h[x]=en;
	e[++en]=(edge){h[y],x,0};h[y]=en;
}
bool bfs()
{
	int i,j;memset(d,0,sizeof(d));
	for(d[q[i=qn=0]=S]=1;i<=qn;++i)for(j=c[q[i]]=h[q[i]];j;j=e[j].nx)
		if(e[j].w&&!d[e[j].t])d[q[++qn]=e[j].t]=d[q[i]]+1;
	return d[T];
}
int dfs(int x,int r)
{
	if(x==T)return r;
	int k,u=0;
	for(int&i=c[x];i;i=e[i].nx)if(e[i].w&&d[e[i].t]==d[x]+1)
	{
		k=dfs(e[i].t,min(e[i].w,r-u));
		e[i].w-=k;e[i^1].w+=k;u+=k;
		if(u==r)return u;
	}
	return d[x]=0,u;
}
}
string s[MN+5];
int tn,c[MX+5][2],f[MX+5],q[MX+5],qn,t[MX+5];
bitset<MN+5> b[MN+5],bs;
struct edge{int nx,t;}E[MX*2+5];
int v[MX+5],fc[MX+5],en,z[MX+5],zn,g[MX+5];
inline void ins(int*h,int x,int y){E[++en]=(edge){h[x],y};h[x]=en;}
int main()
{
	int n,i,j,x,ans;
	cin>>n;ans=n;
	for(i=1;i<=n;++i)
	{
		cin>>s[i];
		for(j=x=0;j<s[i].size();ins(v,x=c[x][s[i][j++]-'a'],i))
			if(!c[x][s[i][j]-'a'])c[x][s[i][j]-'a']=++tn;
		t[x]=i;
	}
	for(i=0;i<2;++i)if(c[0][i])ins(fc,0,q[++qn]=c[0][i]);
	for(i=1;i<=qn;++i)for(j=0;j<2;++j)if(c[q[i]][j])
	{
		for(x=f[q[i]];x&&!c[x][j];x=f[x]);
		f[c[q[i]][j]]=c[x][j];
		ins(fc,c[x][j],c[q[i]][j]);
		q[++qn]=c[q[i]][j];
	}
	g[0]=-1;
	while(zn>=0)
		if(x=z[zn],g[zn]<0)
		{
			if(t[x])bs[t[x]]=1;
			for(int i=v[x];i;i=E[i].nx)b[E[i].t]|=bs;
			g[zn]=fc[x];
		}
		else if(g[zn])
		{
			z[zn+1]=E[g[zn]].t;g[zn+1]=-1;
			g[zn]=E[g[zn]].nx;++zn;
		}
		else
		{
			if(t[x])bs[t[x]]=0;
			--zn;
		}
	using namespace flow;
	for(i=1;i<=n;++i)
	{
		ins(S,i,1);ins(i+n,T,1);
		for(j=1;j<=n;++j)if(i!=j&&b[i][j])ins(i,j+n,1);
	}
	while(bfs())ans-=dfs(S,INF);
	printf("%d\n",ans);
	for(i=1;i<=n;++i)for(j=h[i];j;j=e[j].nx)if(e[j].t==S&&!e[j].w)printf("%d ",i);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
using namespace std;
#define MN 750
#define MX 10000000
#define MV 1500
#define ME 300000
#define S MV+1
#define T MV+2
#define INF 0x7FFFFFFF
namespace flow
{
struct edge{int nx,t,w;}e[ME*2+5];
int h[MV+5],en=1,d[MV+5],c[MV+5],q[MV+5],qn;
inline void ins(int x,int y,int w)
{
	e[++en]=(edge){h[x],y,w};h[x]=en;
	e[++en]=(edge){h[y],x,0};h[y]=en;
}
bool bfs()
{
	int i,j;memset(d,0,sizeof(d));
	for(d[q[i=qn=0]=S]=1;i<=qn;++i)for(j=c[q[i]]=h[q[i]];j;j=e[j].nx)
		if(e[j].w&&!d[e[j].t])d[q[++qn]=e[j].t]=d[q[i]]+1;
	return d[T];
}
int dfs(int x,int r)
{
	if(x==T)return r;
	int k,u=0;
	for(int&i=c[x];i;i=e[i].nx)if(e[i].w&&d[e[i].t]==d[x]+1)
	{
		k=dfs(e[i].t,min(e[i].w,r-u));
		e[i].w-=k;e[i^1].w+=k;u+=k;
		if(u==r)return u;
	}
	return d[x]=0,u;
}
}
char s[MX+5];
int tn,c[MX+5][2],f[MX+5],q[MX+5],qn,t[MX+5];
bitset<MN+5> b[MN+5],bb;
struct edge{int nx,t;}E[MX*2+5];
int v[MX+5],fc[MX+5],en,z[MX+5],zn;
inline void ins(int*h,int x,int y){E[++en]=(edge){h[x],y};h[x]=en;}
int main()
{
	int n,i,j,x,y,ans;
	scanf("%d",&n);ans=n;
	for(i=1;i<=n;++i)
	{
		scanf("%s",s);
		for(j=x=0;s[j];ins(v,x=c[x][s[j++]-'a'],i))
			if(!c[x][s[j]-'a'])c[x][s[j]-'a']=++tn;
		t[x]=i;
	}
	for(i=0;i<2;++i)if(c[0][i])ins(fc,0,q[++qn]=c[0][i]);
	for(i=1;i<=qn;++i)for(j=0;j<2;++j)if(c[q[i]][j])
	{
		for(x=f[q[i]];x&&!c[x][j];x=f[x]);
		f[c[q[i]][j]]=c[x][j];
		ins(fc,c[x][j],c[q[i]][j]);
		q[++qn]=c[q[i]][j];
	}
	f[qn=0]=-1;
	while(zn>=0)
		if(x=z[zn],f[zn]<0)
		{
			if(t[x])q[++qn]=t[x];
			if(qn)for(int i=v[x];i;i=E[i].nx)b[E[i].t][q[qn]]=b[E[i].t][q[qn-1]]=1;
			f[zn]=fc[x];
		}
		else if(f[zn])
		{
			z[zn+1]=E[f[zn]].t;f[zn+1]=-1;
			f[zn]=E[f[zn]].nx;++zn;
		}
		else{if(t[x])--qn;--zn;}
	for(x=1;x<=n;++x)for(i=1;i<=n;++i)if(b[i][x])b[i]|=b[x];
	using namespace flow;
	for(i=1;i<=n;++i)
	{
		ins(S,i,1);ins(i+n,T,1);
		for(j=1;j<=n;++j)if(i!=j&&b[i][j])ins(i,j+n,1);
	}
	while(bfs())ans-=dfs(S,INF);
	printf("%d\n",ans);
	for(i=1;i<=n;++i)for(t[i]=0,j=h[i];j;j=e[j].nx)if(!e[j].w&&e[j].t!=S)t[i]=e[j].t-n;
	for(i=h[T];i;i=e[i].nx)if(!e[i].w)for(j=e[i].t-n;;j=t[j])
	{
		for(x=e[i].nx;x;x=e[x].nx)if(!e[x].w)
		{
			for(y=e[x].t-n;y;y=t[y])if(!bb[y]&&!b[j][y]&&!b[y][j])break;
			if(!y)break;
		}
		if(x)continue;
		printf("%d ",j);
		if(ans==8&&j==9)printf("(debug %d)",int(b[5][9]));
		for(x=1;x<=n;++x)bb[x]=bb[x]|b[j][x]|b[x][j];
		break;
	}
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
using namespace std;
#define MN 750
#define MX 10000000
#define MV 1500
#define ME 300000
#define S MV+1
#define T MV+2
#define INF 0x7FFFFFFF
namespace flow
{
struct edge{int nx,t,w;}e[ME*2+5];
int h[MV+5],en=1,d[MV+5],c[MV+5],q[MV+5],qn;
inline void ins(int x,int y,int w)
{
	e[++en]=(edge){h[x],y,w};h[x]=en;
	e[++en]=(edge){h[y],x,0};h[y]=en;
}
bool bfs()
{
	int i,j;memset(d,0,sizeof(d));
	for(d[q[i=qn=0]=S]=1;i<=qn;++i)for(j=c[q[i]]=h[q[i]];j;j=e[j].nx)
		if(e[j].w&&!d[e[j].t])d[q[++qn]=e[j].t]=d[q[i]]+1;
	return d[T];
}
int dfs(int x,int r)
{
	if(x==T)return r;
	int k,u=0;
	for(int&i=c[x];i;i=e[i].nx)if(e[i].w&&d[e[i].t]==d[x]+1)
	{
		k=dfs(e[i].t,min(e[i].w,r-u));
		e[i].w-=k;e[i^1].w+=k;u+=k;
		if(u==r)return u;
	}
	return d[x]=0,u;
}
}
char s[MX+5];
int tn,c[MX+5][2],f[MX+5],q[MX+5],qn,t[MX+5],z[MX+5],zn,v[MX+5];
bitset<MN+5> b[MN+5],bb;
int main()
{
	int n,i,j,x,y,ans;
	scanf("%d",&n);ans=n;
	for(i=1;i<=n;++i)
	{
		scanf("%s",s);
		for(j=x=0;s[j];z[++zn]=x=c[x][s[j++]-'a'],v[zn]=i)
			if(!c[x][s[j]-'a'])c[x][s[j]-'a']=++tn;
		t[x]=i;
	}
	for(i=0;i<2;++i)if(c[0][i])q[++qn]=c[0][i];
	for(i=1;i<=qn;++i)for(j=0;j<2;++j)if(c[q[i]][j])
	{
		for(x=f[q[i]];x&&!c[x][j];x=f[x]);
		f[c[q[i]][j]]=c[x][j];
		if(!t[c[q[i]][j]])t[c[q[i]][j]]=t[c[x][j]];
		q[++qn]=c[q[i]][j];
	}
	for(i=1;i<=zn;++i)b[v[i]][t[z[i]]]=b[v[i]][t[f[z[i]]]]=1;
	for(x=1;x<=n;++x)for(i=1;i<=n;++i)if(b[i][x])b[i]|=b[x];
	using namespace flow;
	for(i=1;i<=n;++i)
	{
		ins(S,i,1);ins(i+n,T,1);
		for(j=1;j<=n;++j)if(i!=j&&b[i][j])ins(i,j+n,1);
	}
	while(bfs())ans-=dfs(S,INF);
	printf("%d\n",ans);
	for(bfs(),i=1;i<=n;++i)if(d[i]&&!d[i+n])printf("%d ",i);
}


#include<cstring>
#include<iostream>
#include<algorithm>
#include<bitset>
using namespace std;
#define MN 750
#define MX 1000000
#define MV 1500
#define ME 300000
#define S MV+1
#define T MV+2
#define INF 0x7FFFFFFF
struct edge{int nx,t,w;}e[ME*2+5];
int h[MV+5],en=1,d[MV+5],cc[MV+5],qq[MV+5],qn;
inline void ins(int x,int y,int w)
{
	e[++en]=(edge){h[x],y,w};h[x]=en;
	e[++en]=(edge){h[y],x,0};h[y]=en;
}
bool bfs()
{
	int i,j;memset(d,0,sizeof(d));
	for(d[qq[i=qn=0]=S]=1;i<=qn;++i)for(j=cc[qq[i]]=h[qq[i]];j;j=e[j].nx)
		if(e[j].w&&!d[e[j].t])d[qq[++qn]=e[j].t]=d[qq[i]]+1;
	return d[T];
}
int dfs(int x,int r)
{
	if(x==T)return r;
	int k,u=0;
	for(int&i=cc[x];i;i=e[i].nx)if(e[i].w&&d[e[i].t]==d[x]+1)
	{
		k=dfs(e[i].t,min(e[i].w,r-u));
		e[i].w-=k;e[i^1].w+=k;u+=k;
		if(u==r)return u;
	}
	return d[x]=0,u;
}
string s[MN+5];
int tn,c[MX+5][2],f[MX+5],q[MX+5];
bitset<MN+5> b[MX+5],bs;
int main()
{
	int n,i,j,x,ans;
	cin>>n;ans=n;
	for(i=1;i<=n;++i)
	{
		cin>>s[i];
		for(j=x=0;j<s[i].size();x=c[x][s[i][j++]-'a'])
			if(!c[x][s[i][j]-'a'])c[x][s[i][j]-'a']=++tn;
		b[x][i]=1;
	}
	for(i=0;i<2;++i)if(c[0][i])q[++qn]=c[0][i];
	for(i=1;i<=qn;++i)for(j=0;j<2;++j)if(c[q[i]][j])
	{
		for(x=f[q[i]];x&&!c[x][j];x=f[x]);
		f[c[q[i]][j]]=c[x][j];
		b[c[q[i]][j]]|=b[c[x][j]];
		q[++qn]=c[q[i]][j];
	}
	for(i=1;i<=n;++i)
	{
		ins(S,i,1);ins(i+n,T,1);
		bs.reset();
		for(j=x=0;j<s[i].size();++j)bs|=b[x=c[x][s[i][j]-'a']];
		for(j=1;j<=n;++j)if(i!=j&&bs[j])ins(i,j+n,1);
	}
	while(bfs())ans-=dfs(S,INF);
	printf("%d\n",ans);
	for(i=1;i<=n;++i)for(j=h[i];j;j=e[j].nx)if(e[j].t==S&&!e[j].w)printf("%d ",i);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MN 750
#define MX 10000000
#define MV 1500
#define ME 300000
#define S MV+1
#define T MV+2
#define INF 0x7FFFFFFF
namespace flow
{
struct edge{int nx,t,w;}e[ME*2+5];
int h[MV+5],en=1,d[MV+5],c[MV+5],q[MV+5],qn;
inline void ins(int x,int y,int w)
{
	e[++en]=(edge){h[x],y,w};h[x]=en;
	e[++en]=(edge){h[y],x,0};h[y]=en;
}
bool bfs()
{
	int i,j;memset(d,0,sizeof(d));
	for(d[q[i=qn=0]=S]=1;i<=qn;++i)for(j=c[q[i]]=h[q[i]];j;j=e[j].nx)
		if(e[j].w&&!d[e[j].t])d[q[++qn]=e[j].t]=d[q[i]]+1;
	return d[T];
}
int dfs(int x,int r)
{
	if(x==T)return r;
	int k,u=0;
	for(int&i=c[x];i;i=e[i].nx)if(e[i].w&&d[e[i].t]==d[x]+1)
	{
		k=dfs(e[i].t,min(e[i].w,r-u));
		e[i].w-=k;e[i^1].w+=k;u+=k;
		if(u==r)return u;
	}
	return d[x]=0,u;
}
}
char s[MX+5];
int tn,c[MX+5][2],f[MX+5],q[MX+5],qn,t[MX+5];
struct BS
{
	unsigned long long s[12];
	inline void rev(int x){s[x>>6]^=1ULL<<(x&63);}
	inline void operator|=(const BS&x){for(register int i=0;i<12;++i)s[i]|=x.s[i];}
	inline bool x(int x){return s[x>>6]&(1ULL<<(x&63));}
}b[MN+5],bs;
struct edge{int nx,t;}E[MX*2+5];
int v[MX+5],fc[MX+5],en,z[MX+5],zn;
inline void ins(int*h,int x,int y){E[++en]=(edge){h[x],y};h[x]=en;}
int main()
{
	int n,i,j,x,ans;
	scanf("%d",&n);ans=n;
	for(i=1;i<=n;++i)
	{
		scanf("%s",s);
		for(j=x=0;s[j];ins(v,x=c[x][s[j++]-'a'],i))
			if(!c[x][s[j]-'a'])c[x][s[j]-'a']=++tn;
		t[x]=i;
	}
	for(i=0;i<2;++i)if(c[0][i])ins(fc,0,q[++qn]=c[0][i]);
	for(i=1;i<=qn;++i)for(j=0;j<2;++j)if(c[q[i]][j])
	{
		for(x=f[q[i]];x&&!c[x][j];x=f[x]);
		f[c[q[i]][j]]=c[x][j];
		ins(fc,c[x][j],c[q[i]][j]);
		q[++qn]=c[q[i]][j];
	}
	f[0]=-1;
	while(zn>=0)
		if(x=z[zn],f[zn]<0)
		{
			if(t[x])bs.rev(t[x]);
			for(int i=v[x];i;i=E[i].nx)b[E[i].t]|=bs;
			f[zn]=fc[x];
		}
		else if(f[zn])
		{
			z[zn+1]=E[f[zn]].t;f[zn+1]=-1;
			f[zn]=E[f[zn]].nx;++zn;
		}
		else
		{
			if(t[x])bs.rev(t[x]);
			--zn;
		}
	using namespace flow;
	for(i=1;i<=n;++i)
	{
		ins(S,i,1);ins(i+n,T,1);
		for(j=1;j<=n;++j)if(i!=j&&b[i].x(j))ins(i,j+n,1);
	}
	while(bfs())ans-=dfs(S,INF);
	printf("%d\n",ans);
	for(i=1;i<=n;++i)for(j=h[i];j;j=e[j].nx)if(e[j].t==S&&!e[j].w)printf("%d ",i);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
using namespace std;
#define MN 750
#define MX 10000000
#define MV 1500
#define ME 300000
#define S MV+1
#define T MV+2
#define INF 0x7FFFFFFF
namespace flow
{
struct edge{int nx,t,w;}e[ME*2+5];
int h[MV+5],en=1,d[MV+5],c[MV+5],q[MV+5],qn;
inline void ins(int x,int y,int w)
{
	e[++en]=(edge){h[x],y,w};h[x]=en;
	e[++en]=(edge){h[y],x,0};h[y]=en;
}
bool bfs()
{
	int i,j;memset(d,0,sizeof(d));
	for(d[q[i=qn=0]=S]=1;i<=qn;++i)for(j=c[q[i]]=h[q[i]];j;j=e[j].nx)
		if(e[j].w&&!d[e[j].t])d[q[++qn]=e[j].t]=d[q[i]]+1;
	return d[T];
}
int dfs(int x,int r)
{
	if(x==T)return r;
	int k,u=0;
	for(int&i=c[x];i;i=e[i].nx)if(e[i].w&&d[e[i].t]==d[x]+1)
	{
		k=dfs(e[i].t,min(e[i].w,r-u));
		e[i].w-=k;e[i^1].w+=k;u+=k;
		if(u==r)return u;
	}
	return d[x]=0,u;
}
}
char s[MX+5];
int tn,c[MX+5][2],f[MX+5],q[MX+5],qn,t[MX+5];
bitset<MN+5> b[MN+5];
struct edge{int nx,t;}E[MX*2+5];
int v[MX+5],fc[MX+5],en,z[MX+5],zn;
inline void ins(int*h,int x,int y){E[++en]=(edge){h[x],y};h[x]=en;}
int main()
{
	int n,i,j,x,ans;
	scanf("%d",&n);ans=n;
	for(i=1;i<=n;++i)
	{
		scanf("%s",s);
		for(j=x=0;s[j];ins(v,x=c[x][s[j++]-'a'],i))
			if(!c[x][s[j]-'a'])c[x][s[j]-'a']=++tn;
		t[x]=i;
	}
	for(i=0;i<2;++i)if(c[0][i])ins(fc,0,q[++qn]=c[0][i]);
	for(i=1;i<=qn;++i)for(j=0;j<2;++j)if(c[q[i]][j])
	{
		for(x=f[q[i]];x&&!c[x][j];x=f[x]);
		f[c[q[i]][j]]=c[x][j];
		ins(fc,c[x][j],c[q[i]][j]);
		q[++qn]=c[q[i]][j];
	}
	f[qn=0]=-1;
	while(zn>=0)
		if(x=z[zn],f[zn]<0)
		{
			if(t[x])q[++qn]=t[x];
			if(qn)for(int i=v[x];i;i=E[i].nx)b[E[i].t][q[qn]]=b[E[i].t][q[qn-1]]=1;
			f[zn]=fc[x];
		}
		else if(f[zn])
		{
			z[zn+1]=E[f[zn]].t;f[zn+1]=-1;
			f[zn]=E[f[zn]].nx;++zn;
		}
		else{if(t[x])--qn;--zn;}
	for(x=1;x<=n;++x)for(i=1;i<=n;++i)if(b[i][x])b[i]|=b[x];
	using namespace flow;
	for(i=1;i<=n;++i)
	{
		ins(S,i,1);ins(i+n,T,1);
		for(j=1;j<=n;++j)if(i!=j&&b[i][j])ins(i,j+n,1);
	}
	while(bfs())ans-=dfs(S,INF);
	printf("%d\n",ans);
	for(i=h[S];i;i=e[i].nx)if(e[i].w)printf("%d ",e[i].t);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<ctime>
int tms=clock();
using namespace std;
#define MN 750
#define MX 10000000
#define MV 1500
#define ME 300000
#define S MV+1
#define T MV+2
#define INF 0x7FFFFFFF
namespace flow
{
struct edge{int nx,t,w;}e[ME*2+5];
int h[MV+5],en=1,d[MV+5],c[MV+5],q[MV+5],qn;
inline void ins(int x,int y,int w)
{
	e[++en]=(edge){h[x],y,w};h[x]=en;
	e[++en]=(edge){h[y],x,0};h[y]=en;
}
bool bfs()
{
	int i,j;memset(d,0,sizeof(d));
	for(d[q[i=qn=0]=S]=1;i<=qn;++i)for(j=c[q[i]]=h[q[i]];j;j=e[j].nx)
		if(e[j].w&&!d[e[j].t])d[q[++qn]=e[j].t]=d[q[i]]+1;
	return d[T];
}
int dfs(int x,int r)
{
	if(x==T)return r;
	int k,u=0;
	for(int&i=c[x];i;i=e[i].nx)if(e[i].w&&d[e[i].t]==d[x]+1)
	{
		k=dfs(e[i].t,min(e[i].w,r-u));
		e[i].w-=k;e[i^1].w+=k;u+=k;
		if(u==r)return u;
	}
	return d[x]=0,u;
}
}
char s[MX+5];
int tn,c[MX+5][2],f[MX+5],q[MX+5],qn,t[MX+5];
struct BS
{
	unsigned long long s[12];
	inline void rev(int x){s[x>>6]^=1ULL<<(x&63);}
	inline void operator|=(const BS&x){for(register int i=0;i<12;++i)s[i]|=x.s[i];}
	inline bool x(int x){return s[x>>6]&(1ULL<<(x&63));}
}b[MN+5],bs;
struct edge{int nx,t;}E[MX*2+5];
int v[MX+5],fc[MX+5],en,z[MX+5],zn;
inline void ins(int*h,int x,int y){E[++en]=(edge){h[x],y};h[x]=en;}
int main()
{
	int n,i,j,x,ans;
	scanf("%d",&n);ans=n;
	for(i=1;i<=n;++i)
	{
		scanf("%s",s);
		for(j=x=0;s[j];ins(v,x=c[x][s[j++]-'a'],i))
			if(!c[x][s[j]-'a'])c[x][s[j]-'a']=++tn;
		t[x]=i;
	}
	for(i=0;i<2;++i)if(c[0][i])ins(fc,0,q[++qn]=c[0][i]);
	for(i=1;i<=qn;++i)for(j=0;j<2;++j)if(c[q[i]][j])
	{
		for(x=f[q[i]];x&&!c[x][j];x=f[x]);
		f[c[q[i]][j]]=c[x][j];
		ins(fc,c[x][j],c[q[i]][j]);
		q[++qn]=c[q[i]][j];
	}
	f[0]=-1;
	if(tn>MX/2)return 0*printf("%d\n",clock()-tms);
	while(zn>=0)
		if(x=z[zn],f[zn]<0)
		{
			if(t[x])bs.rev(t[x]);
			for(int i=v[x];i;i=E[i].nx)b[E[i].t]|=bs;
			f[zn]=fc[x];
		}
		else if(f[zn])
		{
			z[zn+1]=E[f[zn]].t;f[zn+1]=-1;
			f[zn]=E[f[zn]].nx;++zn;
		}
		else
		{
			if(t[x])bs.rev(t[x]);
			--zn;
		}
	using namespace flow;
	for(i=1;i<=n;++i)
	{
		ins(S,i,1);ins(i+n,T,1);
		for(j=1;j<=n;++j)if(i!=j&&b[i].x(j))ins(i,j+n,1);
	}
	while(bfs())ans-=dfs(S,INF);
	printf("%d\n",ans);
	for(i=1;i<=n;++i)for(j=h[i];j;j=e[j].nx)if(e[j].t==S&&!e[j].w)printf("%d ",i);
}


#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<bitset>
using namespace std;
#define MN 750
#define MX 10000000
#define MV 1500
#define ME 300000
#define S MV+1
#define T MV+2
#define INF 0x7FFFFFFF
namespace flow
{
struct edge{int nx,t,w;}e[ME*2+5];
int h[MV+5],en=1,d[MV+5],c[MV+5],q[MV+5],qn;
inline void ins(int x,int y,int w)
{
	e[++en]=(edge){h[x],y,w};h[x]=en;
	e[++en]=(edge){h[y],x,0};h[y]=en;
}
bool bfs()
{
	int i,j;memset(d,0,sizeof(d));
	for(d[q[i=qn=0]=S]=1;i<=qn;++i)for(j=c[q[i]]=h[q[i]];j;j=e[j].nx)
		if(e[j].w&&!d[e[j].t])d[q[++qn]=e[j].t]=d[q[i]]+1;
	return d[T];
}
int dfs(int x,int r)
{
	if(x==T)return r;
	int k,u=0;
	for(int&i=c[x];i;i=e[i].nx)if(e[i].w&&d[e[i].t]==d[x]+1)
	{
		k=dfs(e[i].t,min(e[i].w,r-u));
		e[i].w-=k;e[i^1].w+=k;u+=k;
		if(u==r)return u;
	}
	return d[x]=0,u;
}
}
string s[MN+5];
int tn,c[MX+5][2],f[MX+5],q[MX+5],qn,t[MX+5];
bitset<MN+5> b[MN+5],bs;
vector<int> v[MX+5],fc[MX+5];
void dfs(int x)
{
	if(t[x])bs[t[x]]=1;
	for(int i=0;i<v[x].size();++i)b[v[x][i]]|=bs;
	for(int i=0;i<fc[x].size();++i)dfs(fc[x][i]);
	if(t[x])bs[t[x]]=0;
}
int main()
{
	int n,i,j,x,ans;
	cin>>n;ans=n;
	for(i=1;i<=n;++i)
	{
		cin>>s[i];
		for(j=x=0;j<s[i].size();v[x=c[x][s[i][j++]-'a']].push_back(i))
			if(!c[x][s[i][j]-'a'])c[x][s[i][j]-'a']=++tn;
		t[x]=i;
	}
	for(i=0;i<2;++i)if(c[0][i])fc[0].push_back(q[++qn]=c[0][i]);
	for(i=1;i<=qn;++i)for(j=0;j<2;++j)if(c[q[i]][j])
	{
		for(x=f[q[i]];x&&!c[x][j];x=f[x]);
		f[c[q[i]][j]]=c[x][j];
		fc[c[x][j]].push_back(c[q[i]][j]);
		q[++qn]=c[q[i]][j];
	}
	dfs(0);
	using namespace flow;
	for(i=1;i<=n;++i)
	{
		ins(S,i,1);ins(i+n,T,1);
		for(j=1;j<=n;++j)if(i!=j&&b[i][j])ins(i,j+n,1);
	}
	while(bfs())ans-=dfs(S,INF);
	printf("%d\n",ans);
	for(i=1;i<=n;++i)for(j=h[i];j;j=e[j].nx)if(e[j].t==S&&!e[j].w)printf("%d ",i);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MN 750
#define MX 10000000
#define MV 1500
#define ME 300000
#define S MV+1
#define T MV+2
#define INF 0x7FFFFFFF
namespace flow
{
struct edge{int nx,t,w;}e[ME*2+5];
int h[MV+5],en=1,d[MV+5],c[MV+5],q[MV+5],qn;
inline void ins(int x,int y,int w)
{
	e[++en]=(edge){h[x],y,w};h[x]=en;
	e[++en]=(edge){h[y],x,0};h[y]=en;
}
bool bfs()
{
	int i,j;memset(d,0,sizeof(d));
	for(d[q[i=qn=0]=S]=1;i<=qn;++i)for(j=c[q[i]]=h[q[i]];j;j=e[j].nx)
		if(e[j].w&&!d[e[j].t])d[q[++qn]=e[j].t]=d[q[i]]+1;
	return d[T];
}
int dfs(int x,int r)
{
	if(x==T)return r;
	int k,u=0;
	for(int&i=c[x];i;i=e[i].nx)if(e[i].w&&d[e[i].t]==d[x]+1)
	{
		k=dfs(e[i].t,min(e[i].w,r-u));
		e[i].w-=k;e[i^1].w+=k;u+=k;
		if(u==r)return u;
	}
	return d[x]=0,u;
}
}
char s[MX+5];
int tn,c[MX+5][2],f[MX+5],q[MX+5],qn,t[MX+5];
struct BS
{
	unsigned long long s[12];
	inline void rev(int x){s[x>>6]^=1ULL<<(x&63);}
	inline void operator|=(const BS&x){for(register int i=0;i<12;++i)s[i]|=x.s[i];}
	inline bool x(int x){return s[x>>6]&(1ULL<<(x&63));}
}b[MN+5],bs;
struct edge{int nx,t;}E[MX*2+5];
int v[MX+5],fc[MX+5],en,z[MX+5],zn;
inline void ins(int*h,int x,int y){E[++en]=(edge){h[x],y};h[x]=en;}
int main()
{
	int n,i,j,x,ans;
	scanf("%d",&n);ans=n;
	for(i=1;i<=n;++i)
	{
		scanf("%s",s);
		for(j=x=0;s[j];ins(v,x=c[x][s[j++]-'a'],i))
			if(!c[x][s[j]-'a'])c[x][s[j]-'a']=++tn;
		t[x]=i;
	}
	for(i=0;i<2;++i)if(c[0][i])ins(fc,0,q[++qn]=c[0][i]);
	for(i=1;i<=qn;++i)for(j=0;j<2;++j)if(c[q[i]][j])
	{
		for(x=f[q[i]];x&&!c[x][j];x=f[x]);
		f[c[q[i]][j]]=c[x][j];
		ins(fc,c[x][j],c[q[i]][j]);
		q[++qn]=c[q[i]][j];
	}
	f[0]=-1;
	while(zn>=0)
		if(x=z[zn],f[zn]<0)
		{
			if(t[x])bs.rev(t[x]);
			if(tn<MX/2)for(int i=v[x];i;i=E[i].nx)b[E[i].t]|=bs;
			f[zn]=fc[x];
		}
		else if(f[zn])
		{
			z[zn+1]=E[f[zn]].t;f[zn+1]=-1;
			f[zn]=E[f[zn]].nx;++zn;
		}
		else
		{
			if(t[x])bs.rev(t[x]);
			--zn;
		}
	if(tn>MX/2)return 0;
	using namespace flow;
	for(i=1;i<=n;++i)
	{
		ins(S,i,1);ins(i+n,T,1);
		for(j=1;j<=n;++j)if(i!=j&&b[i].x(j))ins(i,j+n,1);
	}
	while(bfs())ans-=dfs(S,INF);
	printf("%d\n",ans);
	for(i=1;i<=n;++i)for(j=h[i];j;j=e[j].nx)if(e[j].t==S&&!e[j].w)printf("%d ",i);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MN 750
#define MX 10000000
#define MV 1500
#define ME 300000
#define S MV+1
#define T MV+2
#define INF 0x7FFFFFFF
namespace flow
{
struct edge{int nx,t,w;}e[ME*2+5];
int h[MV+5],en=1,d[MV+5],c[MV+5],q[MV+5],qn;
inline void ins(int x,int y,int w)
{
	e[++en]=(edge){h[x],y,w};h[x]=en;
	e[++en]=(edge){h[y],x,0};h[y]=en;
}
bool bfs()
{
	int i,j;memset(d,0,sizeof(d));
	for(d[q[i=qn=0]=S]=1;i<=qn;++i)for(j=c[q[i]]=h[q[i]];j;j=e[j].nx)
		if(e[j].w&&!d[e[j].t])d[q[++qn]=e[j].t]=d[q[i]]+1;
	return d[T];
}
int dfs(int x,int r)
{
	if(x==T)return r;
	int k,u=0;
	for(int&i=c[x];i;i=e[i].nx)if(e[i].w&&d[e[i].t]==d[x]+1)
	{
		k=dfs(e[i].t,min(e[i].w,r-u));
		e[i].w-=k;e[i^1].w+=k;u+=k;
		if(u==r)return u;
	}
	return d[x]=0,u;
}
}
char s[MX+5];
int tn,c[MX+5][2],f[MX+5],q[MX+5],qn,t[MX+5];
struct BS
{
	unsigned long long s[12];
	inline void rev(int x){s[x>>6]^=1ULL<<(x&63);}
	inline void operator|=(const BS&x){for(register int i=0;i<12;++i)s[i]|=x.s[i];}
	inline bool x(int x){return s[x>>6]&(1ULL<<(x&63));}
}b[MN+5],bs;
struct edge{int nx,t;}E[MX*2+5];
int v[MX+5],fc[MX+5],en,z[MX+5],zn;
inline void ins(int*h,int x,int y){E[++en]=(edge){h[x],y};h[x]=en;}
int main()
{
	int n,i,j,x,ans;
	scanf("%d",&n);ans=n;
	for(i=1;i<=n;++i)
	{
		scanf("%s",s);
		for(j=x=0;s[j];ins(v,x=c[x][s[j++]-'a'],i))
			if(!c[x][s[j]-'a'])c[x][s[j]-'a']=++tn;
		t[x]=i;
	}
	for(i=0;i<2;++i)if(c[0][i])ins(fc,0,q[++qn]=c[0][i]);
	for(i=1;i<=qn;++i)for(j=0;j<2;++j)if(c[q[i]][j])
	{
		for(x=f[q[i]];x&&!c[x][j];x=f[x]);
		f[c[q[i]][j]]=c[x][j];
		ins(fc,c[x][j],c[q[i]][j]);
		q[++qn]=c[q[i]][j];
	}
	f[0]=-1;
	while(zn>=0)
		if(x=z[zn],f[zn]<0)
		{
			if(t[x])bs.rev(t[x]);
			if(tn>MX/2)for(int i=v[x];i;i=E[i].nx)b[E[i].t]|=bs;
			f[zn]=fc[x];
		}
		else if(f[zn])
		{
			z[zn+1]=E[f[zn]].t;f[zn+1]=-1;
			f[zn]=E[f[zn]].nx;++zn;
		}
		else
		{
			if(t[x])bs.rev(t[x]);
			--zn;
		}
	using namespace flow;
	for(i=1;i<=n;++i)
	{
		ins(S,i,1);ins(i+n,T,1);
		for(j=1;j<=n;++j)if(i!=j&&b[i].x(j))ins(i,j+n,1);
	}
	while(bfs())ans-=dfs(S,INF);
	printf("%d\n",ans);
	for(i=1;i<=n;++i)for(j=h[i];j;j=e[j].nx)if(e[j].t==S&&!e[j].w)printf("%d ",i);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
using namespace std;
#define MN 750
#define MX 10000000
#define MV 1500
#define ME 300000
#define S MV+1
#define T MV+2
#define INF 0x7FFFFFFF
namespace flow
{
struct edge{int nx,t,w;}e[ME*2+5];
int h[MV+5],en=1,d[MV+5],c[MV+5],q[MV+5],qn;
inline void ins(int x,int y,int w)
{
	e[++en]=(edge){h[x],y,w};h[x]=en;
	e[++en]=(edge){h[y],x,0};h[y]=en;
}
bool bfs()
{
	int i,j;memset(d,0,sizeof(d));
	for(d[q[i=qn=0]=S]=1;i<=qn;++i)for(j=c[q[i]]=h[q[i]];j;j=e[j].nx)
		if(e[j].w&&!d[e[j].t])d[q[++qn]=e[j].t]=d[q[i]]+1;
	return d[T];
}
int dfs(int x,int r)
{
	if(x==T)return r;
	int k,u=0;
	for(int&i=c[x];i;i=e[i].nx)if(e[i].w&&d[e[i].t]==d[x]+1)
	{
		k=dfs(e[i].t,min(e[i].w,r-u));
		e[i].w-=k;e[i^1].w+=k;u+=k;
		if(u==r)return u;
	}
	return d[x]=0,u;
}
}
char s[MX+5];
int tn,c[MX+5][2],f[MX+5],q[MX+5],qn,t[MX+5];
bitset<MN+5> b[MN+5];
struct edge{int nx,t;}E[MX*2+5];
int v[MX+5],fc[MX+5],en,z[MX+5],zn;
inline void ins(int*h,int x,int y){E[++en]=(edge){h[x],y};h[x]=en;}
int main()
{
	int n,i,j,x,ans;
	scanf("%d",&n);ans=n;
	for(i=1;i<=n;++i)
	{
		scanf("%s",s);
		for(j=x=0;s[j];ins(v,x=c[x][s[j++]-'a'],i))
			if(!c[x][s[j]-'a'])c[x][s[j]-'a']=++tn;
		t[x]=i;
	}
	for(i=0;i<2;++i)if(c[0][i])ins(fc,0,q[++qn]=c[0][i]);
	for(i=1;i<=qn;++i)for(j=0;j<2;++j)if(c[q[i]][j])
	{
		for(x=f[q[i]];x&&!c[x][j];x=f[x]);
		f[c[q[i]][j]]=c[x][j];
		ins(fc,c[x][j],c[q[i]][j]);
		q[++qn]=c[q[i]][j];
	}
	f[qn=0]=-1;
	while(zn>=0)
		if(x=z[zn],f[zn]<0)
		{
			if(t[x])q[++qn]=t[x];
			if(qn)for(int i=v[x];i;i=E[i].nx)b[E[i].t][q[qn]]=b[E[i].t][q[qn-1]]=1;
			f[zn]=fc[x];
		}
		else if(f[zn])
		{
			z[zn+1]=E[f[zn]].t;f[zn+1]=-1;
			f[zn]=E[f[zn]].nx;++zn;
		}
		else{if(t[x])--qn;--zn;}
	for(x=1;x<=n;++x)for(i=1;i<=n;++i)if(b[i][x])b[i]|=b[x];
	using namespace flow;
	for(i=1;i<=n;++i)
	{
		ins(S,i,1);ins(i+n,T,1);
		for(j=1;j<=n;++j)if(i!=j&&b[i][j])ins(i,j+n,1);
	}
	while(bfs())ans-=dfs(S,INF);
	printf("%d\n",ans);
	for(i=1;i<=n;++i)for(j=h[i];j;j=e[j].nx)if(e[j].t==S&&!e[j].w)printf("%d ",i);
}


#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<bitset>
using namespace std;
#define MN 750
#define MX 10000000
#define MV 1500
#define ME 300000
#define S MV+1
#define T MV+2
#define INF 0x7FFFFFFF
struct edge{int nx,t,w;}e[ME*2+5];
int h[MV+5],en=1,d[MV+5],cc[MV+5],qq[MV+5],qn;
inline void ins(int x,int y,int w)
{
	e[++en]=(edge){h[x],y,w};h[x]=en;
	e[++en]=(edge){h[y],x,0};h[y]=en;
}
bool bfs()
{
	int i,j;memset(d,0,sizeof(d));
	for(d[qq[i=qn=0]=S]=1;i<=qn;++i)for(j=cc[qq[i]]=h[qq[i]];j;j=e[j].nx)
		if(e[j].w&&!d[e[j].t])d[qq[++qn]=e[j].t]=d[qq[i]]+1;
	return d[T];
}
int dfs(int x,int r)
{
	if(x==T)return r;
	int k,u=0;
	for(int&i=cc[x];i;i=e[i].nx)if(e[i].w&&d[e[i].t]==d[x]+1)
	{
		k=dfs(e[i].t,min(e[i].w,r-u));
		e[i].w-=k;e[i^1].w+=k;u+=k;
		if(u==r)return u;
	}
	return d[x]=0,u;
}
string s[MN+5];
int tn,c[MX+5][2],f[MX+5],q[MX+5];
bitset<MN+5> b[MN+5],bs;
vector<int> v[MX+5],vv[MX+5],fc[MX+5];
void dfs(int x)
{
	for(int i=0;i<vv[x].size();++i)bs[vv[x][i]]=1;
	for(int i=0;i<v[x].size();++i)b[v[x][i]]|=bs;
	for(int i=0;i<fc[x].size();++i)dfs(fc[x][i]);
	for(int i=0;i<vv[x].size();++i)bs[vv[x][i]]=0;
}
int main()
{
	int n,i,j,x,ans;
	cin>>n;ans=n;
	for(i=1;i<=n;++i)
	{
		cin>>s[i];
		for(j=x=0;j<s[i].size();v[x=c[x][s[i][j++]-'a']].push_back(i))
			if(!c[x][s[i][j]-'a'])c[x][s[i][j]-'a']=++tn;
		vv[x].push_back(i);
	}
	for(i=0;i<2;++i)if(c[0][i])fc[0].push_back(q[++qn]=c[0][i]);
	for(i=1;i<=qn;++i)for(j=0;j<2;++j)if(c[q[i]][j])
	{
		for(x=f[q[i]];x&&!c[x][j];x=f[x]);
		f[c[q[i]][j]]=c[x][j];
		fc[c[x][j]].push_back(c[q[i]][j]);
		q[++qn]=c[q[i]][j];
	}
	dfs(0);
	for(i=1;i<=n;++i)
	{
		ins(S,i,1);ins(i+n,T,1);
		for(j=1;j<=n;++j)if(i!=j&&b[i][j])ins(i,j+n,1);
	}
	while(bfs())ans-=dfs(S,INF);
	printf("%d\n",ans);
	for(i=1;i<=n;++i)for(j=h[i];j;j=e[j].nx)if(e[j].t==S&&!e[j].w)printf("%d ",i);
}


#include<cstring>
#include<iostream>
#include<algorithm>
#include<bitset>
using namespace std;
#define MN 750
#define MX 10000000
#define MV 1500
#define ME 300000
#define S MV+1
#define T MV+2
#define INF 0x7FFFFFFF
namespace flow
{
struct edge{int nx,t,w;}e[ME*2+5];
int h[MV+5],en=1,d[MV+5],c[MV+5],q[MV+5],qn;
inline void ins(int x,int y,int w)
{
	e[++en]=(edge){h[x],y,w};h[x]=en;
	e[++en]=(edge){h[y],x,0};h[y]=en;
}
bool bfs()
{
	int i,j;memset(d,0,sizeof(d));
	for(d[q[i=qn=0]=S]=1;i<=qn;++i)for(j=c[q[i]]=h[q[i]];j;j=e[j].nx)
		if(e[j].w&&!d[e[j].t])d[q[++qn]=e[j].t]=d[q[i]]+1;
	return d[T];
}
int dfs(int x,int r)
{
	if(x==T)return r;
	int k,u=0;
	for(int&i=c[x];i;i=e[i].nx)if(e[i].w&&d[e[i].t]==d[x]+1)
	{
		k=dfs(e[i].t,min(e[i].w,r-u));
		e[i].w-=k;e[i^1].w+=k;u+=k;
		if(u==r)return u;
	}
	return d[x]=0,u;
}
}
string s[MN+5];
int tn,c[MX+5][2],f[MX+5],q[MX+5],qn,t[MX+5];
bitset<MN+5> b[MN+5],bs;
struct edge{int nx,t;}E[MX*2+5];
int v[MX+5],fc[MX+5],en,z[MN+5],zn,g[MN+5];
inline void ins(int*h,int x,int y){E[++en]=(edge){h[x],y};h[x]=en;}
int main()
{
	int n,i,j,x,ans;
	cin>>n;ans=n;
	for(i=1;i<=n;++i)
	{
		cin>>s[i];
		for(j=x=0;j<s[i].size();ins(v,x=c[x][s[i][j++]-'a'],i))
			if(!c[x][s[i][j]-'a'])c[x][s[i][j]-'a']=++tn;
		t[x]=i;
	}
	for(i=0;i<2;++i)if(c[0][i])ins(fc,0,q[++qn]=c[0][i]);
	for(i=1;i<=qn;++i)for(j=0;j<2;++j)if(c[q[i]][j])
	{
		for(x=f[q[i]];x&&!c[x][j];x=f[x]);
		f[c[q[i]][j]]=c[x][j];
		ins(fc,c[x][j],c[q[i]][j]);
		q[++qn]=c[q[i]][j];
	}
	g[0]=-1;
	while(zn>=0)
		if(x=z[zn],g[zn]<0)
		{
			if(t[x])bs[t[x]]=1;
			for(int i=v[x];i;i=E[i].nx)b[E[i].t]|=bs;
			g[zn]=fc[x];
		}
		else if(g[zn])
		{
			z[zn+1]=E[g[zn]].t;g[zn+1]=-1;
			g[zn]=E[g[zn]].nx;++zn;
		}
		else
		{
			if(t[x])bs[t[x]]=0;
			--zn;
		}
	using namespace flow;
	for(i=1;i<=n;++i)
	{
		ins(S,i,1);ins(i+n,T,1);
		for(j=1;j<=n;++j)if(i!=j&&b[i][j])ins(i,j+n,1);
	}
	while(bfs())ans-=dfs(S,INF);
	printf("%d\n",ans);
	for(i=1;i<=n;++i)for(j=h[i];j;j=e[j].nx)if(e[j].t==S&&!e[j].w)printf("%d ",i);
}


#include<cstring>
#include<iostream>
#include<algorithm>
#include<bitset>
using namespace std;
#define MN 750
#define MX 10000000
#define MV 1500
#define ME 300000
#define S MV+1
#define T MV+2
#define INF 0x7FFFFFFF
namespace flow
{
struct edge{int nx,t,w;}e[ME*2+5];
int h[MV+5],en=1,d[MV+5],c[MV+5],q[MV+5],qn;
inline void ins(int x,int y,int w)
{
	e[++en]=(edge){h[x],y,w};h[x]=en;
	e[++en]=(edge){h[y],x,0};h[y]=en;
}
bool bfs()
{
	int i,j;memset(d,0,sizeof(d));
	for(d[q[i=qn=0]=S]=1;i<=qn;++i)for(j=c[q[i]]=h[q[i]];j;j=e[j].nx)
		if(e[j].w&&!d[e[j].t])d[q[++qn]=e[j].t]=d[q[i]]+1;
	return d[T];
}
int dfs(int x,int r)
{
	if(x==T)return r;
	int k,u=0;
	for(int&i=c[x];i;i=e[i].nx)if(e[i].w&&d[e[i].t]==d[x]+1)
	{
		k=dfs(e[i].t,min(e[i].w,r-u));
		e[i].w-=k;e[i^1].w+=k;u+=k;
		if(u==r)return u;
	}
	return d[x]=0,u;
}
}
string s[MN+5];
int tn,c[MX+5][2],f[MX+5],q[MX+5],qn,t[MX+5];
bitset<MN+5> b[MN+5],bs;
struct edge{int nx,t;}E[MX*2+5];
int v[MX+5],fc[MX+5],en;
inline void ins(int*h,int x,int y){E[++en]=(edge){h[x],y};h[x]=en;}
void dfs(int x)
{
	if(t[x])bs[t[x]]=1;
	for(int i=v[x];i;i=E[i].nx)b[E[i].t]|=bs;
	for(int i=fc[x];i;i=E[i].nx)dfs(E[i].t);
	if(t[x])bs[t[x]]=0;
}
int main()
{
	int n,i,j,x,ans;
	cin>>n;ans=n;
	for(i=1;i<=n;++i)
	{
		cin>>s[i];
		for(j=x=0;j<s[i].size();ins(v,x=c[x][s[i][j++]-'a'],i))
			if(!c[x][s[i][j]-'a'])c[x][s[i][j]-'a']=++tn;
		t[x]=i;
	}
	for(i=0;i<2;++i)if(c[0][i])ins(fc,0,q[++qn]=c[0][i]);
	for(i=1;i<=qn;++i)for(j=0;j<2;++j)if(c[q[i]][j])
	{
		for(x=f[q[i]];x&&!c[x][j];x=f[x]);
		f[c[q[i]][j]]=c[x][j];
		ins(fc,c[x][j],c[q[i]][j]);
		q[++qn]=c[q[i]][j];
	}
	dfs(0);
	using namespace flow;
	for(i=1;i<=n;++i)
	{
		ins(S,i,1);ins(i+n,T,1);
		for(j=1;j<=n;++j)if(i!=j&&b[i][j])ins(i,j+n,1);
	}
	while(bfs())ans-=dfs(S,INF);
	printf("%d\n",ans);
	for(i=1;i<=n;++i)for(j=h[i];j;j=e[j].nx)if(e[j].t==S&&!e[j].w)printf("%d ",i);
}


#include<cstring>
#include<iostream>
#include<algorithm>
#include<bitset>
using namespace std;
#define MN 750
#define MX 10000000
#define MV 1500
#define ME 300000
#define S MV+1
#define T MV+2
#define INF 0x7FFFFFFF
struct edge{int nx,t,w;}e[ME*2+5];
int h[MV+5],en=1,d[MV+5],cc[MV+5],qq[MV+5],qn;
inline void ins(int x,int y,int w)
{
	e[++en]=(edge){h[x],y,w};h[x]=en;
	e[++en]=(edge){h[y],x,0};h[y]=en;
}
bool bfs()
{
	int i,j;memset(d,0,sizeof(d));
	for(d[qq[i=qn=0]=S]=1;i<=qn;++i)for(j=cc[qq[i]]=h[qq[i]];j;j=e[j].nx)
		if(e[j].w&&!d[e[j].t])d[qq[++qn]=e[j].t]=d[qq[i]]+1;
	return d[T];
}
int dfs(int x,int r)
{
	if(x==T)return r;
	int k,u=0;
	for(int&i=cc[x];i;i=e[i].nx)if(e[i].w&&d[e[i].t]==d[x]+1)
	{
		k=dfs(e[i].t,min(e[i].w,r-u));
		e[i].w-=k;e[i^1].w+=k;u+=k;
		if(u==r)return u;
	}
	return d[x]=0,u;
}
string s[MN+5];
int tn,c[MX+5][2],f[MX+5],q[MX+5];
bitset<MN+5> b[MX+5],bs;
int main()
{
	int n,i,j,x,ans;
	cin>>n;ans=n;
	for(i=1;i<=n;++i)
	{
		cin>>s[i];
		for(j=x=0;j<s[i].size();x=c[x][s[i][j++]-'a'])
			if(!c[x][s[i][j]-'a'])c[x][s[i][j]-'a']=++tn;
		b[x][i]=1;
	}
	for(i=0;i<2;++i)if(c[0][i])q[++qn]=c[0][i];
	for(i=1;i<=qn;++i)for(j=0;j<2;++j)if(c[q[i]][j])
	{
		for(x=f[q[i]];x&&!c[x][j];x=f[x]);
		f[c[q[i]][j]]=c[x][j];
		b[c[q[i]][j]]|=b[c[x][j]];
		q[++qn]=c[q[i]][j];
	}
	for(i=1;i<=n;++i)
	{
		ins(S,i,1);ins(i+n,T,1);
		bs.reset();
		for(j=x=0;j<s[i].size();++j)bs|=b[x=c[x][s[i][j]-'a']];
		for(j=1;j<=n;++j)if(i!=j&&bs[j])ins(i,j+n,1);
	}
	while(bfs())ans-=dfs(S,INF);
	printf("%d\n",ans);
	for(i=1;i<=n;++i)for(j=h[i];j;j=e[j].nx)if(e[j].t==S&&!e[j].w)printf("%d ",i);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MN 750
#define MX 10000000
#define MV 1500
#define ME 300000
#define S MV+1
#define T MV+2
#define INF 0x7FFFFFFF
namespace flow
{
struct edge{int nx,t,w;}e[ME*2+5];
int h[MV+5],en=1,d[MV+5],c[MV+5],q[MV+5],qn;
inline void ins(int x,int y,int w)
{
	e[++en]=(edge){h[x],y,w};h[x]=en;
	e[++en]=(edge){h[y],x,0};h[y]=en;
}
bool bfs()
{
	int i,j;memset(d,0,sizeof(d));
	for(d[q[i=qn=0]=S]=1;i<=qn;++i)for(j=c[q[i]]=h[q[i]];j;j=e[j].nx)
		if(e[j].w&&!d[e[j].t])d[q[++qn]=e[j].t]=d[q[i]]+1;
	return d[T];
}
int dfs(int x,int r)
{
	if(x==T)return r;
	int k,u=0;
	for(int&i=c[x];i;i=e[i].nx)if(e[i].w&&d[e[i].t]==d[x]+1)
	{
		k=dfs(e[i].t,min(e[i].w,r-u));
		e[i].w-=k;e[i^1].w+=k;u+=k;
		if(u==r)return u;
	}
	return d[x]=0,u;
}
}
char s[MX+5];
int tn,c[MX+5][2],f[MX+5],q[MX+5],qn,t[MX+5];
struct BS
{
	unsigned long long s[12];
	inline void rev(int x){s[x>>6]^=1ULL<<(x&63);}
	inline void operator|=(const BS&x){for(register int i=0;i<12;++i)s[i]|=x.s[i];}
	inline int x(int x){return s[x>>6]&(1ULL<<(x&63));}
}b[MN+5],bs;
struct edge{int nx,t;}E[MX*2+5];
int v[MX+5],fc[MX+5],en,z[MX+5],zn;
inline void ins(int*h,int x,int y){E[++en]=(edge){h[x],y};h[x]=en;}
int main()
{
	int n,i,j,x,ans;
	scanf("%d",&n);ans=n;
	for(i=1;i<=n;++i)
	{
		scanf("%s",s);
		for(j=x=0;s[j];ins(v,x=c[x][s[j++]-'a'],i))
			if(!c[x][s[j]-'a'])c[x][s[j]-'a']=++tn;
		t[x]=i;
	}
	for(i=0;i<2;++i)if(c[0][i])ins(fc,0,q[++qn]=c[0][i]);
	for(i=1;i<=qn;++i)for(j=0;j<2;++j)if(c[q[i]][j])
	{
		for(x=f[q[i]];x&&!c[x][j];x=f[x]);
		f[c[q[i]][j]]=c[x][j];
		ins(fc,c[x][j],c[q[i]][j]);
		q[++qn]=c[q[i]][j];
	}
	f[0]=-1;
	while(zn>=0)
		if(x=z[zn],f[zn]<0)
		{
			if(t[x])bs.rev(t[x]);
			for(int i=v[x];i;i=E[i].nx)b[E[i].t]|=bs;
			f[zn]=fc[x];
		}
		else if(f[zn])
		{
			z[zn+1]=E[f[zn]].t;f[zn+1]=-1;
			f[zn]=E[f[zn]].nx;++zn;
		}
		else
		{
			if(t[x])bs.rev(t[x]);
			--zn;
		}
	using namespace flow;
	for(i=1;i<=n;++i)
	{
		ins(S,i,1);ins(i+n,T,1);
		for(j=1;j<=n;++j)if(i!=j&&b[i].x(j))ins(i,j+n,1);
	}
	while(bfs())ans-=dfs(S,INF);
	printf("%d\n",ans);
	for(i=1;i<=n;++i)for(j=h[i];j;j=e[j].nx)if(e[j].t==S&&!e[j].w)printf("%d ",i);
}


#include<cstring>
#include<iostream>
#include<algorithm>
#include<bitset>
using namespace std;
#define MN 750
#define MX 10000000
#define MV 1500
#define ME 300000
#define S MV+1
#define T MV+2
#define INF 0x7FFFFFFF
namespace flow
{
struct edge{int nx,t,w;}e[ME*2+5];
int h[MV+5],en=1,d[MV+5],c[MV+5],q[MV+5],qn;
inline void ins(int x,int y,int w)
{
	e[++en]=(edge){h[x],y,w};h[x]=en;
	e[++en]=(edge){h[y],x,0};h[y]=en;
}
bool bfs()
{
	int i,j;memset(d,0,sizeof(d));
	for(d[q[i=qn=0]=S]=1;i<=qn;++i)for(j=c[q[i]]=h[q[i]];j;j=e[j].nx)
		if(e[j].w&&!d[e[j].t])d[q[++qn]=e[j].t]=d[q[i]]+1;
	return d[T];
}
int dfs(int x,int r)
{
	if(x==T)return r;
	int k,u=0;
	for(int&i=c[x];i;i=e[i].nx)if(e[i].w&&d[e[i].t]==d[x]+1)
	{
		k=dfs(e[i].t,min(e[i].w,r-u));
		e[i].w-=k;e[i^1].w+=k;u+=k;
		if(u==r)return u;
	}
	return d[x]=0,u;
}
}
string s[MN+5];
int tn,c[MX+5][2],f[MX+5],q[MX+5],qn,t[MX+5];
bitset<MN+5> b[MN+5],bs;
struct edge{int nx,t;}E[MX*2+5];
int v[MX+5],fc[MX+5],en,z[MX+5],zn;
inline void ins(int*h,int x,int y){E[++en]=(edge){h[x],y};h[x]=en;}
int main()
{
	int n,i,j,x,ans;
	cin>>n;ans=n;
	for(i=1;i<=n;++i)
	{
		cin>>s[i];
		for(j=x=0;j<s[i].size();ins(v,x=c[x][s[i][j++]-'a'],i))
			if(!c[x][s[i][j]-'a'])c[x][s[i][j]-'a']=++tn;
		t[x]=i;
	}
	for(i=0;i<2;++i)if(c[0][i])ins(fc,0,q[++qn]=c[0][i]);
	for(i=1;i<=qn;++i)for(j=0;j<2;++j)if(c[q[i]][j])
	{
		for(x=f[q[i]];x&&!c[x][j];x=f[x]);
		f[c[q[i]][j]]=c[x][j];
		ins(fc,c[x][j],c[q[i]][j]);
		q[++qn]=c[q[i]][j];
	}
	f[0]=-1;
	while(zn>=0)
		if(x=z[zn],f[zn]<0)
		{
			if(t[x])bs[t[x]]=1;
			for(int i=v[x];i;i=E[i].nx)b[E[i].t]|=bs;
			f[zn]=fc[x];
		}
		else if(f[zn])
		{
			z[zn+1]=E[f[zn]].t;f[zn+1]=-1;
			f[zn]=E[f[zn]].nx;++zn;
		}
		else
		{
			if(t[x])bs[t[x]]=0;
			--zn;
		}
	using namespace flow;
	for(i=1;i<=n;++i)
	{
		ins(S,i,1);ins(i+n,T,1);
		for(j=1;j<=n;++j)if(i!=j&&b[i][j])ins(i,j+n,1);
	}
	while(bfs())ans-=dfs(S,INF);
	printf("%d\n",ans);
	for(i=1;i<=n;++i)for(j=h[i];j;j=e[j].nx)if(e[j].t==S&&!e[j].w)printf("%d ",i);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MN 750
#define MX 10000000
#define MV 1500
#define ME 300000
#define S MV+1
#define T MV+2
#define INF 0x7FFFFFFF
namespace flow
{
struct edge{int nx,t,w;}e[ME*2+5];
int h[MV+5],en=1,d[MV+5],c[MV+5],q[MV+5],qn;
inline void ins(int x,int y,int w)
{
	e[++en]=(edge){h[x],y,w};h[x]=en;
	e[++en]=(edge){h[y],x,0};h[y]=en;
}
bool bfs()
{
	int i,j;memset(d,0,sizeof(d));
	for(d[q[i=qn=0]=S]=1;i<=qn;++i)for(j=c[q[i]]=h[q[i]];j;j=e[j].nx)
		if(e[j].w&&!d[e[j].t])d[q[++qn]=e[j].t]=d[q[i]]+1;
	return d[T];
}
int dfs(int x,int r)
{
	if(x==T)return r;
	int k,u=0;
	for(int&i=c[x];i;i=e[i].nx)if(e[i].w&&d[e[i].t]==d[x]+1)
	{
		k=dfs(e[i].t,min(e[i].w,r-u));
		e[i].w-=k;e[i^1].w+=k;u+=k;
		if(u==r)return u;
	}
	return d[x]=0,u;
}
}
char s[MX+5];
int tn,c[MX+5][2],f[MX+5],q[MX+5],qn,t[MX+5];
struct BS
{
	unsigned long long s[12];
	inline void rev(int x){s[x>>6]^=1ULL<<(x&63);}
	inline void operator|=(const BS&x){for(register int i=0;i<12;++i)s[i]|=x.s[i];}
	inline bool x(int x){return s[x>>6]&(1ULL<<(x&63));}
}b[MN+5],bs;
struct edge{int nx,t;}E[MX*2+5];
int v[MX+5],fc[MX+5],en,z[MX+5],zn;
inline void ins(int*h,int x,int y){E[++en]=(edge){h[x],y};h[x]=en;}
int main()
{
	int n,i,j,x,ans;
	scanf("%d",&n);ans=n;
	for(i=1;i<=n;++i)
	{
		scanf("%s",s);
		for(j=x=0;s[j];ins(v,x=c[x][s[j++]-'a'],i))
			if(!c[x][s[j]-'a'])c[x][s[j]-'a']=++tn;
		t[x]=i;
	}
	for(i=0;i<2;++i)if(c[0][i])ins(fc,0,q[++qn]=c[0][i]);
	for(i=1;i<=qn;++i)for(j=0;j<2;++j)if(c[q[i]][j])
	{
		for(x=f[q[i]];x&&!c[x][j];x=f[x]);
		f[c[q[i]][j]]=c[x][j];
		ins(fc,c[x][j],c[q[i]][j]);
		q[++qn]=c[q[i]][j];
	}
	f[0]=-1;
	while(zn>=0)
		if(x=z[zn],f[zn]<0)
		{
			if(t[x])bs.rev(t[x]);
			if(tn<MX/2)for(int i=v[x];i;i=E[i].nx)b[E[i].t]|=bs;
			f[zn]=fc[x];
		}
		else if(f[zn])
		{
			z[zn+1]=E[f[zn]].t;f[zn+1]=-1;
			f[zn]=E[f[zn]].nx;++zn;
		}
		else
		{
			if(t[x])bs.rev(t[x]);
			--zn;
		}
	using namespace flow;
	for(i=1;i<=n;++i)
	{
		ins(S,i,1);ins(i+n,T,1);
		for(j=1;j<=n;++j)if(i!=j&&b[i].x(j))ins(i,j+n,1);
	}
	while(bfs())ans-=dfs(S,INF);
	printf("%d\n",ans);
	for(i=1;i<=n;++i)for(j=h[i];j;j=e[j].nx)if(e[j].t==S&&!e[j].w)printf("%d ",i);
}


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

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(i=a;i<b;i++)
#define repv(i,a,b) for(i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=755;
string s[N];
bool a[N][N];
vi sufflink;
int sz;
vector<map<char,int> > trie;
map<int,vi> endat;
void insert(int ind)
{
  int curr=0,i,j;
  rep(i,0,sz(s[ind]))
    {
      if(!trie[curr].count(s[ind][i]))
	{
	  trie[curr][s[ind][i]]=++sz;
	  trie.pb(map<char,int>());
	}
      curr=trie[curr][s[ind][i]];
    }
  endat[curr].pb(ind);
}
void build_automation()
{
  sufflink.resize(sz+3);
  queue<int> q;
  int i,j;
  for(auto x:trie[0])
    {
      sufflink[x.se]=0;
      q.push(x.se);
    }
  while(!q.empty())
    {
      int curr=q.front();
      q.pop();
      for(auto x:trie[curr])
	{
	  q.push(x.se);
	  int tmp=sufflink[curr];
	  while(!trie[tmp].count(x.fi) && tmp)
	    tmp=sufflink[tmp];
	  if(trie[tmp].count(x.fi))
	    sufflink[x.se]=trie[tmp][x.fi];
	  else
	    sufflink[x.se]=0;
	}
    }
}
void makegraph(int ind)
{
  int i,curr=0;
  rep(i,0,sz(s[ind]))
    {
      if(endat.count(curr))
	{
	  for(int ind2:endat[curr])
	    a[ind2][ind]=true;
	}
      int nxt=sufflink[curr];
      if(endat.count(nxt))
	{
	  for(int ind2:endat[nxt])
	    a[ind2][ind]=true;
	}
      curr=trie[curr][s[ind][i]];
    }
  if(endat.count(curr))
    {
      for(int ind2:endat[curr])
	a[ind2][ind]=true;
    }
  int nxt=sufflink[curr];
  if(endat.count(nxt))
    {
      for(int ind2:endat[nxt])
	a[ind2][ind]=true;
    }
}
bool seen[N];
int l[N],r[N],n;
bool findmatch(int i)
{
  int j;
  rep(j,1,n+1)
    {
      if(a[i][j] && !seen[j])
	{
	  seen[j]=true;
	  if(r[j]<0 || findmatch(r[j]))
	    {
	      l[i]=j; r[j]=i;
	      return true;
	    }
	}
    }
  return false;
}
int bipartitematch()
{
  int cnt=0,i,j;
  rep(i,1,n+1) l[i]=-1;
  rep(i,1,n+1) r[i]=-1;
  rep(i,1,n+1)
    {
      rep(j,1,n+1) seen[j]=false;
      if(findmatch(i)) cnt++;
    }
  return cnt;
}
bool vis[2*N];
void dfs(int u)
{
  vis[u]=true;
  int i;
  rep(i,1,n+1)
    {
      if(vis[n+i] || !a[u][i] || r[i]==-1) continue;
      vis[n+i]=true;
      dfs(r[i]);
    }
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int i,j,k;
  trie.resize(1);
  cin>>n;
  rep(i,1,n+1)
    {
      cin>>s[i];
      insert(i);
    }
  build_automation();
  rep(i,1,n+1)
    makegraph(i);
  rep(k,1,n+1)
    rep(i,1,n+1)
    rep(j,1,n+1)
    a[i][j]|=(a[i][k]&a[k][j]);
  rep(i,1,n+1) a[i][i]=false;
  //http://codeforces.com/blog/entry/17534?#comment-223759( how to find min vertex cover from max matching)
  int ans=n-bipartitematch();
  //rep(i,1,n+1)
  //trace(i,l[i],r[i]);
  rep(i,1,n+1) // all unmatched nodes from left side
    if(l[i]==-1 && !vis[i]) dfs(i);
  cout<<ans<<endl;
  rep(i,1,n+1)
    {
      bool vc1=(vis[i]==false),vc2=(vis[i+n]==true);
      if(!vc1 && !vc2)
	cout<<i<<" ";
    }
  cout<<endl;
  return 0;
}


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

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(i=a;i<b;i++)
#define repv(i,a,b) for(i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=755,MX=1e7+5;
string s[N];
bool a[N][N];
vi sufflink;
int sz;
int trie[MX][2],nearest[MX];
bool en[MX];
vi endat[MX];
void insert(int ind)
{
  int curr=0,i,j;
  rep(i,0,sz(s[ind]))
    {
      int tmp=s[ind][i]-'a';
      if(!trie[curr][tmp])
	trie[curr][tmp]=++sz;
      curr=trie[curr][tmp];
    }
  en[curr]=true;
  endat[curr].pb(ind);
}
void build_automation()
{
  sufflink.resize(sz+3);
  queue<int> q;
  int i,j;
  rep(i,0,2)
    if(trie[0][i])
      q.push(trie[0][i]);
  while(!q.empty())
    {
      int curr=q.front();
      q.pop();
      rep(i,0,2)
	{
	  if(!trie[curr][i]) continue;
	  ii x=mp(i,trie[curr][i]);
	  q.push(x.se);
	  int tmp=sufflink[curr];
	  while(!trie[tmp][x.fi] && tmp)
	    tmp=sufflink[tmp];
	  sufflink[x.se]=trie[tmp][x.fi];
	  int nxt=sufflink[x.se];
	  if(en[nxt])
	    nearest[x.se]=nxt;
	  else
	    nearest[x.se]=nearest[nxt];
	}
    }
}
void makegraph(int ind)
{
  int i,curr=0;
  rep(i,0,sz(s[ind]))
    {
      //if(ind==4)
	//trace(sufflink[curr],curr);
      for(int ind2:endat[curr])
	a[ind2][ind]=true;
      int nxt=sufflink[curr];
      for(int ind2:endat[nxt])
	a[ind2][ind]=true;
      curr=trie[curr][s[ind][i]-'a'];
    }
  for(int ind2:endat[curr])
    a[ind2][ind]=true;
  int nxt=sufflink[curr];
  for(int ind2:endat[nxt])
    a[ind2][ind]=true;
}
bool seen[N];
int l[N],r[N],n;
vi v[N];
bool findmatch(int i)
{
  int j;
  rep(j,1,n+1)
    {
      if(a[i][j] && !seen[j])
	{
	  seen[j]=true;
	  if(r[j]<0 || findmatch(r[j]))
	    {
	      l[i]=j; r[j]=i;
	      return true;
	    }
	}
    }
  return false;
}
int bipartitematch()
{
  int cnt=0,i,j;
  rep(i,1,n+1) l[i]=-1;
  rep(i,1,n+1) r[i]=-1;
  rep(i,1,n+1)
    {
      rep(j,1,n+1) seen[j]=false;
      if(findmatch(i)) cnt++;
    }
  return cnt;
}
bool vis[2*N];
void dfs(int u)
{
  vis[u]=true;
  for(int i:v[u])
    {
      if(vis[n+i] || r[i]==-1) continue;
      vis[n+i]=true;
      dfs(r[i]);
    }
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ;
  int i,j,k;
  cin>>n;
  rep(i,1,n+1)
    {
      cin>>s[i];
      insert(i);
    }
  build_automation();
  rep(i,1,n+1)
    makegraph(i);
  rep(k,1,n+1)
    rep(i,1,n+1)
    rep(j,1,n+1)
    a[i][j]|=(a[i][k]&a[k][j]);
  rep(i,1,n+1) a[i][i]=false;
  rep(i,1,n+1)
    rep(j,1,n+1)
    if(a[i][j]) v[i].pb(j);
  //http://codeforces.com/blog/entry/17534?#comment-223759( how to find min vertex cover from max matching)
  int ans=n-bipartitematch();
  //rep(i,1,n+1)
  //trace(i,l[i],r[i]);
  rep(i,1,n+1) // all unmatched nodes from left side
    if(l[i]==-1 && !vis[i]) dfs(i);
  cout<<ans<<endl;
  rep(i,1,n+1)
    {
      bool vc1=(vis[i]==false),vc2=(vis[i+n]==true);
      if(!vc1 && !vc2)
	cout<<i<<" ";
    }
  cout<<endl;
  return 0;
}


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

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(i=a;i<b;i++)
#define repv(i,a,b) for(i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=755,MX=1e7+5;
string s[N];
bool a[N][N];
vi sufflink;
int sz;
int trie[MX][2];
vi endat[MX];
void insert(int ind)
{
  int curr=0,i,j;
  rep(i,0,sz(s[ind]))
    {
      int tmp=s[ind][i]-'a';
      if(!trie[curr][tmp])
	trie[curr][tmp]=++sz;
      curr=trie[curr][tmp];
    }
  endat[curr].pb(ind);
}
void build_automation()
{
  sufflink.resize(sz+3);
  queue<int> q;
  int i,j;
  rep(i,0,2)
    if(trie[0][i])
      q.push(trie[0][i]);
  while(!q.empty())
    {
      int curr=q.front();
      q.pop();
      rep(i,0,2)
	{
	  if(!trie[curr][i]) continue;
	  ii x=mp(i,trie[curr][i]);
	  q.push(x.se);
	  int tmp=sufflink[curr];
	  while(!trie[tmp][x.fi] && tmp)
	    tmp=sufflink[tmp];
	  if(trie[tmp][x.fi])
	    {
	      sufflink[x.se]=trie[tmp][x.fi];
	      vi tmp;
	      if(sz(endat[sufflink[x.se]]))
		{
		  for(int ind:endat[sufflink[x.se]])
		    tmp.pb(ind);
		  for(int ind:tmp)
		    endat[x.se].pb(ind);
		  sort(all(endat[x.se]));
		  endat[x.se].erase(unique(all(endat[x.se])),endat[x.se].end());
		}
	    }
	  else
	    sufflink[x.se]=0;
	}
    }
}
void makegraph(int ind)
{
  int i,curr=0;
  rep(i,0,sz(s[ind]))
    {
      //if(ind==4)
	//trace(sufflink[curr],curr);
      for(int ind2:endat[curr])
	a[ind2][ind]=true;
      int nxt=sufflink[curr];
      for(int ind2:endat[nxt])
	a[ind2][ind]=true;
      curr=trie[curr][s[ind][i]-'a'];
    }
  for(int ind2:endat[curr])
    a[ind2][ind]=true;
  int nxt=sufflink[curr];
  for(int ind2:endat[nxt])
    a[ind2][ind]=true;
}
bool seen[N];
int l[N],r[N],n;
vi v[N];
bool findmatch(int i)
{
  int j;
  rep(j,1,n+1)
    {
      if(a[i][j] && !seen[j])
	{
	  seen[j]=true;
	  if(r[j]<0 || findmatch(r[j]))
	    {
	      l[i]=j; r[j]=i;
	      return true;
	    }
	}
    }
  return false;
}
int bipartitematch()
{
  int cnt=0,i,j;
  rep(i,1,n+1) l[i]=-1;
  rep(i,1,n+1) r[i]=-1;
  rep(i,1,n+1)
    {
      rep(j,1,n+1) seen[j]=false;
      if(findmatch(i)) cnt++;
    }
  return cnt;
}
bool vis[2*N];
void dfs(int u)
{
  vis[u]=true;
  for(int i:v[u])
    {
      if(vis[n+i] || r[i]==-1) continue;
      vis[n+i]=true;
      dfs(r[i]);
    }
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ;
  int i,j,k;
  cin>>n;
  rep(i,1,n+1)
    {
      cin>>s[i];
      insert(i);
    }
  build_automation();
  rep(i,1,n+1)
    makegraph(i);
  rep(k,1,n+1)
    rep(i,1,n+1)
    rep(j,1,n+1)
    a[i][j]|=(a[i][k]&a[k][j]);
  rep(i,1,n+1) a[i][i]=false;
  rep(i,1,n+1)
    rep(j,1,n+1)
    if(a[i][j]) v[i].pb(j);
  //http://codeforces.com/blog/entry/17534?#comment-223759( how to find min vertex cover from max matching)
  int ans=n-bipartitematch();
  //rep(i,1,n+1)
  //trace(i,l[i],r[i]);
  rep(i,1,n+1) // all unmatched nodes from left side
    if(l[i]==-1 && !vis[i]) dfs(i);
  cout<<ans<<endl;
  rep(i,1,n+1)
    {
      bool vc1=(vis[i]==false),vc2=(vis[i+n]==true);
      if(!vc1 && !vc2)
	cout<<i<<" ";
    }
  cout<<endl;
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(i=a;i<b;i++)
#define repv(i,a,b) for(i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
struct ahocorasick
{
  vi sufflink,out;
  int sz;
  vector<map<char,int> > trie;
  vector<vi> endat;
  ahocorasick()
  {
    int i;
    sz=0;
    out.resize(1); trie.resize(1); endat.resize(1);
  }
  inline void insert(string &s,int ind)
  {
    int curr=0,i,j;
    rep(i,0,s.size())
      {
	if(!trie[curr].count(s[i]))
	  {
	    trie[curr][s[i]]=++sz;
	    trie.pb(map<char,int>());
	    endat.pb(vi());
	    out.pb(0);
	  }
	curr=trie[curr][s[i]];
      }
    out[curr]++;
    endat[curr].pb(ind);
  }
  inline void build_automation()
  {
    sufflink.resize(sz+3);
    queue<int> q;
    int i,j;
    for(auto x:trie[0])
      {
	sufflink[x.se]=0;
	q.push(x.se);
      }
    while(!q.empty())
      {
	int curr=q.front();
	q.pop();
	for(auto x:trie[curr])
	  {
	    q.push(x.se);
	    int tmp=sufflink[curr];
	    while(!trie[tmp].count(x.fi) && tmp)
	      tmp=sufflink[tmp];
	    if(trie[tmp].count(x.fi))
	      sufflink[x.se]=trie[tmp][x.fi];
	    else
	      sufflink[x.se]=0;
	    out[x.se]+=out[sufflink[x.se]];
	  }
      }
  }
  int findnextstate(int curr,char ch)
  {
    while(curr && !trie[curr].count(ch))
      curr=sufflink[curr];
    return curr;
  }
  ll query(string &s)
  {
    ll ans=0;
    int curr=0,i;
    rep(i,0,s.size())
      {
	curr=findnextstate(curr,s[i]);
	curr=trie[curr][s[i]];
	ans+=out[curr];
      }
    return ans;
  }
  void clear()
  {
    trie.clear(); sufflink.clear(); out.clear();
    out.resize(1); trie.resize(1); sz=0;
  }
};
ahocorasick ac;
const int N=800;
string s[N];
bool v[N][N];
void makegraph(int ind)
{
  int i,curr=0;
  rep(i,0,sz(s[ind]))
    {
      for(int ind2:ac.endat[curr])
	v[ind2][ind]=true;
      int nxt=ac.sufflink[curr];
      for(int ind2:ac.endat[nxt])
        v[ind2][ind]=true;
      curr=ac.trie[curr][s[ind][i]];
    }
  for(int ind2:ac.endat[curr])
    v[ind2][ind]=true;
  int nxt=ac.sufflink[curr];
  for(int ind2:ac.endat[nxt])
    v[ind2][ind]=true;
}
bool seen[N];
int l[N],r[N],n;
bool a[N][N];
bool findmatch(int i)
{
  int j;
  rep(j,1,n+1)
    {
      if(a[i][j] && !seen[j])
	{
	  seen[j]=true;
	  if(r[j]<0 || findmatch(r[j]))
	    {
	      l[i]=j; r[j]=i;
	      return true;
	    }
	}
    }
  return false;
}
int bipartitematch()
{
  int cnt=0,i,j;
  rep(i,1,n+1) l[i]=-1;
  rep(i,1,n+1) r[i]=-1;
  rep(i,1,n+1)
    {
      rep(j,1,n+1) seen[j]=false;
      if(findmatch(i)) cnt++;
    }
  return cnt;
}
bool mark[2*N],vis[2*N],vc[2*N];
void dfs(int u)
{
  vis[u]=true;
  int i;
  rep(i,1,n+1)
    {
      if(vis[n+i] || !a[u][i] || r[i]==-1) continue;
      vis[n+i]=true;
      dfs(r[n+i]);
    }
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int i,j,k;
  cin>>n;
  rep(i,1,n+1)
    {
      cin>>s[i];
      ac.insert(s[i],i);
    }
  ac.build_automation();
  rep(i,1,n+1)
    makegraph(i);
  rep(k,1,n+1)
    rep(i,1,n+1)
    rep(j,1,n+1)
    v[i][j]|=(v[i][k]&v[k][j]);
  rep(i,1,n+1) v[i][i]=false;
  //http://codeforces.com/blog/entry/17534?#comment-223759( how to find min vertex cover from max matching
  rep(i,1,n+1) rep(j,1,n+1) a[i][j]=v[i][j];
  int ans=bipartitematch();
  //rep(i,1,n+1)
  //trace(i,l[i],r[i]);
  rep(i,1,n+1)
    if(l[i]!=-1)
      mark[l[i]+n]=mark[i]=true;
  rep(i,1,n+1)
    if(!mark[i] && !vis[i]) dfs(i);
  rep(i,1,2*n+1)
    {
      if(!mark[i]) continue;
      vc[i]=((i<=n && !vis[i]) || (i>n && vis[i]));
    }
  cout<<n-ans<<endl;
  rep(i,1,n+1)
    if(!vc[i] && !vc[i+n])
      cout<<i<<" ";
  cout<<endl;
  return 0;
}


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

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(i=a;i<b;i++)
#define repv(i,a,b) for(i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=755,MX=1e7+5;
string s[N];
bool a[N][N];
vi sufflink;
int sz;
int trie[MX][2];
vi endat[MX];
void insert(int ind)
{
  int curr=0,i,j;
  rep(i,0,sz(s[ind]))
    {
      int tmp=s[ind][i]-'a';
      if(!trie[curr][tmp])
	trie[curr][tmp]=++sz;
      curr=trie[curr][tmp];
    }
  endat[curr].pb(ind);
}
void build_automation()
{
  sufflink.resize(sz+3);
  queue<int> q;
  int i,j;
  rep(i,0,2)
    if(trie[0][i])
      q.push(trie[0][i]);
  while(!q.empty())
    {
      int curr=q.front();
      q.pop();
      rep(i,0,2)
	{
	  if(!trie[curr][i]) continue;
	  ii x=mp(i,trie[curr][i]);
	  q.push(x.se);
	  int tmp=sufflink[curr];
	  while(!trie[tmp][x.fi] && tmp)
	    tmp=sufflink[tmp];
	  if(trie[tmp][x.fi])
	    {
	      sufflink[x.se]=trie[tmp][x.fi];
	      vi tmp;
	      if(sz(endat[sufflink[x.se]]))
		{
		  for(int ind:endat[sufflink[x.se]])
		    tmp.pb(ind);
		  for(int ind:tmp)
		    endat[x.se].pb(ind);
		  sort(all(endat[x.se]));
		  endat[x.se].erase(unique(all(endat[x.se])),endat[x.se].end());
		}
	    }
	  else
	    sufflink[x.se]=0;
	}
    }
}
void makegraph(int ind)
{
  int i,curr=0;
  rep(i,0,sz(s[ind]))
    {
      //if(ind==4)
	//trace(sufflink[curr],curr);
      for(int ind2:endat[curr])
	a[ind2][ind]=true;
      int nxt=sufflink[curr];
      for(int ind2:endat[nxt])
	a[ind2][ind]=true;
      curr=trie[curr][s[ind][i]-'a'];
    }
  for(int ind2:endat[curr])
    a[ind2][ind]=true;
  int nxt=sufflink[curr];
  for(int ind2:endat[nxt])
    a[ind2][ind]=true;
}
bool seen[N];
int l[N],r[N],n;
bool findmatch(int i)
{
  int j;
  rep(j,1,n+1)
    {
      if(a[i][j] && !seen[j])
	{
	  seen[j]=true;
	  if(r[j]<0 || findmatch(r[j]))
	    {
	      l[i]=j; r[j]=i;
	      return true;
	    }
	}
    }
  return false;
}
int bipartitematch()
{
  int cnt=0,i,j;
  rep(i,1,n+1) l[i]=-1;
  rep(i,1,n+1) r[i]=-1;
  rep(i,1,n+1)
    {
      rep(j,1,n+1) seen[j]=false;
      if(findmatch(i)) cnt++;
    }
  return cnt;
}
bool vis[2*N];
void dfs(int u)
{
  vis[u]=true;
  int i;
  rep(i,1,n+1)
    {
      if(vis[n+i] || !a[u][i] || r[i]==-1) continue;
      vis[n+i]=true;
      dfs(r[i]);
    }
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int i,j,k;
  cin>>n;
  rep(i,1,n+1)
    {
      cin>>s[i];
      insert(i);
    }
  build_automation();
  rep(i,1,n+1)
    makegraph(i);
  rep(k,1,n+1)
    rep(i,1,n+1)
    rep(j,1,n+1)
    a[i][j]|=(a[i][k]&a[k][j]);
  rep(i,1,n+1) a[i][i]=false;
  //http://codeforces.com/blog/entry/17534?#comment-223759( how to find min vertex cover from max matching)
  int ans=n-bipartitematch();
  //rep(i,1,n+1)
  //trace(i,l[i],r[i]);
  rep(i,1,n+1) // all unmatched nodes from left side
    if(l[i]==-1 && !vis[i]) dfs(i);
  cout<<ans<<endl;
  rep(i,1,n+1)
    {
      bool vc1=(vis[i]==false),vc2=(vis[i+n]==true);
      if(!vc1 && !vc2)
	cout<<i<<" ";
    }
  cout<<endl;
  return 0;
}


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

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(i=a;i<b;i++)
#define repv(i,a,b) for(i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=755,MX=1e7+5;
string s[N];
bool a[N][N];
vi sufflink;
int sz;
int trie[MX][2];
map<int,vi> endat;
void insert(int ind)
{
  int curr=0,i,j;
  rep(i,0,sz(s[ind]))
    {
      int tmp=s[ind][i]-'a';
      if(!trie[curr][tmp])
	trie[curr][tmp]=++sz;
      curr=trie[curr][tmp];
    }
  endat[curr].pb(ind);
}
void build_automation()
{
  sufflink.resize(sz+3);
  queue<int> q;
  int i,j;
  rep(i,0,2)
    if(trie[0][i])
      q.push(trie[0][i]);
  while(!q.empty())
    {
      int curr=q.front();
      q.pop();
      rep(i,0,2)
	{
	  if(!trie[curr][i]) continue;
	  ii x=mp(i,trie[curr][i]);
	  q.push(x.se);
	  int tmp=sufflink[curr];
	  while(!trie[tmp][x.fi] && tmp)
	    tmp=sufflink[tmp];
	  if(trie[tmp][x.fi])
	    sufflink[x.se]=trie[tmp][x.fi];
	  else
	    sufflink[x.se]=0;
	}
    }
}
void makegraph(int ind)
{
  int i,curr=0;
  rep(i,0,sz(s[ind]))
    {
      if(endat.count(curr))
	{
	  for(int ind2:endat[curr])
	    a[ind2][ind]=true;
	}
      int nxt=sufflink[curr];
      if(endat.count(nxt))
	{
	  for(int ind2:endat[nxt])
	    a[ind2][ind]=true;
	}
      curr=trie[curr][s[ind][i]];
    }
  if(endat.count(curr))
    {
      for(int ind2:endat[curr])
	a[ind2][ind]=true;
    }
  int nxt=sufflink[curr];
  if(endat.count(nxt))
    {
      for(int ind2:endat[nxt])
	a[ind2][ind]=true;
    }
}
bool seen[N];
int l[N],r[N],n;
bool findmatch(int i)
{
  int j;
  rep(j,1,n+1)
    {
      if(a[i][j] && !seen[j])
	{
	  seen[j]=true;
	  if(r[j]<0 || findmatch(r[j]))
	    {
	      l[i]=j; r[j]=i;
	      return true;
	    }
	}
    }
  return false;
}
int bipartitematch()
{
  int cnt=0,i,j;
  rep(i,1,n+1) l[i]=-1;
  rep(i,1,n+1) r[i]=-1;
  rep(i,1,n+1)
    {
      rep(j,1,n+1) seen[j]=false;
      if(findmatch(i)) cnt++;
    }
  return cnt;
}
bool vis[2*N];
void dfs(int u)
{
  vis[u]=true;
  int i;
  rep(i,1,n+1)
    {
      if(vis[n+i] || !a[u][i] || r[i]==-1) continue;
      vis[n+i]=true;
      dfs(r[i]);
    }
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int i,j,k;
  cin>>n;
  rep(i,1,n+1)
    {
      cin>>s[i];
      insert(i);
    }
  build_automation();
  rep(i,1,n+1)
    makegraph(i);
  rep(k,1,n+1)
    rep(i,1,n+1)
    rep(j,1,n+1)
    a[i][j]|=(a[i][k]&a[k][j]);
  rep(i,1,n+1) a[i][i]=false;
  //http://codeforces.com/blog/entry/17534?#comment-223759( how to find min vertex cover from max matching)
  int ans=n-bipartitematch();
  //rep(i,1,n+1)
  //trace(i,l[i],r[i]);
  rep(i,1,n+1) // all unmatched nodes from left side
    if(l[i]==-1 && !vis[i]) dfs(i);
  cout<<ans<<endl;
  rep(i,1,n+1)
    {
      bool vc1=(vis[i]==false),vc2=(vis[i+n]==true);
      if(!vc1 && !vc2)
	cout<<i<<" ";
    }
  cout<<endl;
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(i=a;i<b;i++)
#define repv(i,a,b) for(i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
struct ahocorasick
{
  vi sufflink,out;
  int sz;
  vector<map<char,int> > trie;
  vector<vi> endat;
  ahocorasick()
  {
    int i;
    sz=0;
    out.resize(1); trie.resize(1); endat.resize(1);
  }
  inline void insert(string &s,int ind)
  {
    int curr=0,i,j;
    rep(i,0,s.size())
      {
	if(!trie[curr].count(s[i]))
	  {
	    trie[curr][s[i]]=++sz;
	    trie.pb(map<char,int>());
	    endat.pb(vi());
	    out.pb(0);
	  }
	curr=trie[curr][s[i]];
      }
    out[curr]++;
    endat[curr].pb(ind);
  }
  inline void build_automation()
  {
    sufflink.resize(sz+3);
    queue<int> q;
    int i,j;
    for(auto x:trie[0])
      {
	sufflink[x.se]=0;
	q.push(x.se);
      }
    while(!q.empty())
      {
	int curr=q.front();
	q.pop();
	for(auto x:trie[curr])
	  {
	    q.push(x.se);
	    int tmp=sufflink[curr];
	    while(!trie[tmp].count(x.fi) && tmp)
	      tmp=sufflink[tmp];
	    if(trie[tmp].count(x.fi))
	      sufflink[x.se]=trie[tmp][x.fi];
	    else
	      sufflink[x.se]=0;
	    out[x.se]+=out[sufflink[x.se]];
	  }
      }
  }
  int findnextstate(int curr,char ch)
  {
    while(curr && !trie[curr].count(ch))
      curr=sufflink[curr];
    return curr;
  }
  ll query(string &s)
  {
    ll ans=0;
    int curr=0,i;
    rep(i,0,s.size())
      {
	curr=findnextstate(curr,s[i]);
	curr=trie[curr][s[i]];
	ans+=out[curr];
      }
    return ans;
  }
  void clear()
  {
    trie.clear(); sufflink.clear(); out.clear();
    out.resize(1); trie.resize(1); sz=0;
  }
};
ahocorasick ac;
const int N=800;
string s[N];
bool v[N][N];
void makegraph(int ind)
{
  int i,curr=0;
  rep(i,0,sz(s[ind]))
    {
      for(int ind2:ac.endat[curr])
	v[ind2][ind]=true;
      int nxt=ac.sufflink[curr];
      for(int ind2:ac.endat[nxt])
        v[ind2][ind]=true;
      curr=ac.trie[curr][s[ind][i]];
    }
  for(int ind2:ac.endat[curr])
    v[ind2][ind]=true;
  int nxt=ac.sufflink[curr];
  for(int ind2:ac.endat[nxt])
    v[ind2][ind]=true;
}
bool seen[N];
int l[N],r[N],n;
bool a[N][N];
bool findmatch(int i)
{
  int j;
  rep(j,1,n+1)
    {
      if(a[i][j] && !seen[j])
	{
	  seen[j]=true;
	  if(r[j]<0 || findmatch(r[j]))
	    {
	      l[i]=j; r[j]=i;
	      return true;
	    }
	}
    }
  return false;
}
int bipartitematch()
{
  int cnt=0,i,j;
  rep(i,1,n+1) l[i]=-1;
  rep(i,1,n+1) r[i]=-1;
  rep(i,1,n+1)
    {
      rep(j,1,n+1) seen[j]=false;
      if(findmatch(i)) cnt++;
    }
  return cnt;
}
bool mark[2*N],vis[2*N],vc[2*N];
void dfs(int u)
{
  vis[u]=true;
  int i;
  rep(i,1,n+1)
    {
      if(vis[n+i] || !a[u][i] || r[i]==-1) continue;
      vis[n+i]=true;
      dfs(r[i]);
    }
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int i,j,k;
  cin>>n;
  rep(i,1,n+1)
    {
      cin>>s[i];
      ac.insert(s[i],i);
    }
  ac.build_automation();
  rep(i,1,n+1)
    makegraph(i);
  rep(k,1,n+1)
    rep(i,1,n+1)
    rep(j,1,n+1)
    v[i][j]|=(v[i][k]&v[k][j]);
  rep(i,1,n+1) v[i][i]=false;
  //http://codeforces.com/blog/entry/17534?#comment-223759( how to find min vertex cover from max matching)
  rep(i,1,n+1) rep(j,1,n+1) a[i][j]=v[i][j];
  int ans=n-bipartitematch();
  //rep(i,1,n+1)
  //trace(i,l[i],r[i]);
  rep(i,1,n+1)
    if(l[i]!=-1)
      mark[l[i]+n]=mark[i]=true;
  rep(i,1,n+1)
    if(!mark[i] && !vis[i]) dfs(i);
  rep(i,1,2*n+1)
    {
      if(!mark[i]) continue;
      vc[i]=((i<=n && !vis[i]) || (i>n && vis[i]));
    }
  cout<<ans<<endl;
  rep(i,1,n+1)
    if(!vc[i] && !vc[i+n])
      cout<<i<<" ";
  cout<<endl;
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(i=a;i<b;i++)
#define repv(i,a,b) for(i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
struct ahocorasick
{
  vi sufflink;
  int sz;
  vector<map<char,int> > trie;
  map<int,vi> endat;
  ahocorasick()
  {
    int i;
    sz=0;
    trie.resize(1);
  }
  inline void insert(string &s,int ind)
  {
    int curr=0,i,j;
    rep(i,0,s.size())
      {
	if(!trie[curr].count(s[i]))
	  {
	    trie[curr][s[i]]=++sz;
	    trie.pb(map<char,int>());
	  }
	curr=trie[curr][s[i]];
      }
    endat[curr].pb(ind);
  }
  inline void build_automation()
  {
    sufflink.resize(sz+3);
    queue<int> q;
    int i,j;
    for(auto x:trie[0])
      {
	sufflink[x.se]=0;
	q.push(x.se);
      }
    while(!q.empty())
      {
	int curr=q.front();
	q.pop();
	for(auto x:trie[curr])
	  {
	    q.push(x.se);
	    int tmp=sufflink[curr];
	    while(!trie[tmp].count(x.fi) && tmp)
	      tmp=sufflink[tmp];
	    if(trie[tmp].count(x.fi))
	      sufflink[x.se]=trie[tmp][x.fi];
	    else
	      sufflink[x.se]=0;
	  }
      }
  }
  int findnextstate(int curr,char ch)
  {
    while(curr && !trie[curr].count(ch))
      curr=sufflink[curr];
    return curr;
  }
  ll query(string &s)
  {
    ll ans=0;
    int curr=0,i;
    rep(i,0,s.size())
      {
	curr=findnextstate(curr,s[i]);
	curr=trie[curr][s[i]];
	//ans+=out[curr];
      }
    return ans;
  }
  void clear()
  {
    trie.clear(); sufflink.clear();
    trie.resize(1); sz=0;
  }
};
ahocorasick ac;
const int N=755;
string s[N];
bool a[N][N];
void makegraph(int ind)
{
  int i,curr=0;
  rep(i,0,sz(s[ind]))
    {
      if(ac.endat.count(curr))
	{
	  for(int ind2:ac.endat[curr])
	    a[ind2][ind]=true;
	}
      int nxt=ac.sufflink[curr];
      if(ac.endat.count(nxt))
	{
	  for(int ind2:ac.endat[nxt])
	    a[ind2][ind]=true;
	}
      curr=ac.trie[curr][s[ind][i]];
    }
  if(ac.endat.count(curr))
    {
      for(int ind2:ac.endat[curr])
	a[ind2][ind]=true;
    }
  int nxt=ac.sufflink[curr];
  if(ac.endat.count(nxt))
    {
      for(int ind2:ac.endat[nxt])
	a[ind2][ind]=true;
    }
}
bool seen[N];
int l[N],r[N],n;
bool findmatch(int i)
{
  int j;
  rep(j,1,n+1)
    {
      if(a[i][j] && !seen[j])
	{
	  seen[j]=true;
	  if(r[j]<0 || findmatch(r[j]))
	    {
	      l[i]=j; r[j]=i;
	      return true;
	    }
	}
    }
  return false;
}
int bipartitematch()
{
  int cnt=0,i,j;
  rep(i,1,n+1) l[i]=-1;
  rep(i,1,n+1) r[i]=-1;
  rep(i,1,n+1)
    {
      rep(j,1,n+1) seen[j]=false;
      if(findmatch(i)) cnt++;
    }
  return cnt;
}
bool vis[2*N];
void dfs(int u)
{
  vis[u]=true;
  int i;
  rep(i,1,n+1)
    {
      if(vis[n+i] || !a[u][i] || r[i]==-1) continue;
      vis[n+i]=true;
      dfs(r[i]);
    }
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int i,j,k;
  cin>>n;
  rep(i,1,n+1)
    {
      cin>>s[i];
      ac.insert(s[i],i);
    }
  ac.build_automation();
  rep(i,1,n+1)
    makegraph(i);
  rep(k,1,n+1)
    rep(i,1,n+1)
    rep(j,1,n+1)
    a[i][j]|=(a[i][k]&a[k][j]);
  rep(i,1,n+1) a[i][i]=false;
  //http://codeforces.com/blog/entry/17534?#comment-223759( how to find min vertex cover from max matching)
  int ans=n-bipartitematch();
  //rep(i,1,n+1)
  //trace(i,l[i],r[i]);
  rep(i,1,n+1) // all unmatched nodes from left side
    if(l[i]==-1 && !vis[i]) dfs(i);
  cout<<ans<<endl;
  rep(i,1,n+1)
    {
      bool vc1=(vis[i]==false),vc2=(vis[i+n]==true);
      if(!vc1 && !vc2)
	cout<<i<<" ";
    }
  cout<<endl;
  return 0;
}


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

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(i=a;i<b;i++)
#define repv(i,a,b) for(i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=755,MX=1e7+5;
string s[N];
bool a[N][N];
vi sufflink;
int sz;
int trie[MX][2];
vi endat[MX];
void insert(int ind)
{
  int curr=0,i,j;
  rep(i,0,sz(s[ind]))
    {
      int tmp=s[ind][i]-'a';
      if(!trie[curr][tmp])
	trie[curr][tmp]=++sz;
      curr=trie[curr][tmp];
    }
  endat[curr].pb(ind);
}
void build_automation()
{
  sufflink.resize(sz+3);
  queue<int> q;
  int i,j;
  rep(i,0,2)
    if(trie[0][i])
      q.push(trie[0][i]);
  while(!q.empty())
    {
      int curr=q.front();
      q.pop();
      rep(i,0,2)
	{
	  if(!trie[curr][i]) continue;
	  ii x=mp(i,trie[curr][i]);
	  q.push(x.se);
	  int tmp=sufflink[curr];
	  while(!trie[tmp][x.fi] && tmp)
	    tmp=sufflink[tmp];
	  if(trie[tmp][x.fi])
	    {
	      sufflink[x.se]=trie[tmp][x.fi];
	      vi tmp;
	      if(sz(endat[sufflink[x.se]]))
		{
		  for(int ind:endat[sufflink[x.se]])
		    tmp.pb(ind);
		  for(int ind:tmp)
		    endat[x.se].pb(ind);
		  //sort(all(endat[x.se]));
		  //endat[x.se].erase(unique(all(endat[x.se])),endat[x.se].end());
		}
	    }
	  else
	    sufflink[x.se]=0;
	}
    }
}
void makegraph(int ind)
{
  int i,curr=0;
  rep(i,0,sz(s[ind]))
    {
      //if(ind==4)
	//trace(sufflink[curr],curr);
      for(int ind2:endat[curr])
	a[ind2][ind]=true;
      int nxt=sufflink[curr];
      for(int ind2:endat[nxt])
	a[ind2][ind]=true;
      curr=trie[curr][s[ind][i]-'a'];
    }
  for(int ind2:endat[curr])
    a[ind2][ind]=true;
  int nxt=sufflink[curr];
  for(int ind2:endat[nxt])
    a[ind2][ind]=true;
}
bool seen[N];
int l[N],r[N],n;
vi v[N];
bool findmatch(int i)
{
  int j;
  rep(j,1,n+1)
    {
      if(a[i][j] && !seen[j])
	{
	  seen[j]=true;
	  if(r[j]<0 || findmatch(r[j]))
	    {
	      l[i]=j; r[j]=i;
	      return true;
	    }
	}
    }
  return false;
}
int bipartitematch()
{
  int cnt=0,i,j;
  rep(i,1,n+1) l[i]=-1;
  rep(i,1,n+1) r[i]=-1;
  rep(i,1,n+1)
    {
      rep(j,1,n+1) seen[j]=false;
      if(findmatch(i)) cnt++;
    }
  return cnt;
}
bool vis[2*N];
void dfs(int u)
{
  vis[u]=true;
  for(int i:v[u])
    {
      if(vis[n+i] || r[i]==-1) continue;
      vis[n+i]=true;
      dfs(r[i]);
    }
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ;
  int i,j,k;
  cin>>n;
  rep(i,1,n+1)
    {
      cin>>s[i];
      insert(i);
    }
  build_automation();
  rep(i,1,n+1)
    makegraph(i);
  rep(k,1,n+1)
    rep(i,1,n+1)
    rep(j,1,n+1)
    a[i][j]|=(a[i][k]&a[k][j]);
  rep(i,1,n+1) a[i][i]=false;
  rep(i,1,n+1)
    rep(j,1,n+1)
    if(a[i][j]) v[i].pb(j);
  //http://codeforces.com/blog/entry/17534?#comment-223759( how to find min vertex cover from max matching)
  int ans=n-bipartitematch();
  //rep(i,1,n+1)
  //trace(i,l[i],r[i]);
  rep(i,1,n+1) // all unmatched nodes from left side
    if(l[i]==-1 && !vis[i]) dfs(i);
  cout<<ans<<endl;
  rep(i,1,n+1)
    {
      bool vc1=(vis[i]==false),vc2=(vis[i+n]==true);
      if(!vc1 && !vc2)
	cout<<i<<" ";
    }
  cout<<endl;
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(i=a;i<b;i++)
#define repv(i,a,b) for(i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=755,MX=1e7+5;
bool a[N][N];
int sufflink[MX];
int sz;
int to[MX][2];
map<int,vi> endat;
string s[N];
void insert(int ind)
{
  int curr=0,i,j;
  rep(i,0,sz(s[ind]))
    {
      int tmp=s[ind][i]-'a';
      if(!to[curr][tmp])
	to[curr][tmp]=++sz;
      curr=to[curr][tmp];
    }
  endat[curr].pb(ind);
}
void build_automation()
{
  queue<int> q;
  int i,j;
  rep(i,0,2)
    if(to[0][i])
      q.push(to[0][i]);
  while(!q.empty())
    {
      int curr=q.front();
      q.pop();
      rep(i,0,2)
	{
	  if(!to[curr][i]) continue;
	  q.push(to[curr][i]);
	  int tmp=sufflink[curr];
	  while(!to[tmp][i] && tmp)
	    tmp=sufflink[tmp];
	  if(to[tmp][i])
	    sufflink[to[curr][i]]=to[tmp][i];
	  else
	    sufflink[to[curr][i]]=0;
	}
    }
}
void makegraph(int ind)
{
  int i,curr=0;
  rep(i,0,sz(s[ind]))
    {
      if(endat.count(curr))
	{
	  for(int ind2:endat[curr])
	    a[ind2][ind]=true;
	}
      int nxt=sufflink[curr];
      if(endat.count(nxt))
	{
	  for(int ind2:endat[nxt])
	    a[ind2][ind]=true;
	}
      curr=to[curr][s[ind][i]-'a'];
    }
  if(endat.count(curr))
    {
      for(int ind2:endat[curr])
	a[ind2][ind]=true;
    }
  int nxt=sufflink[curr];
  if(endat.count(nxt))
    {
      for(int ind2:endat[nxt])
	a[ind2][ind]=true;
    }
}
bool seen[N];
int l[N],r[N],n;
bool findmatch(int i)
{
  int j;
  rep(j,1,n+1)
    {
      if(a[i][j] && !seen[j])
	{
	  seen[j]=true;
	  if(r[j]<0 || findmatch(r[j]))
	    {
	      l[i]=j; r[j]=i;
	      return true;
	    }
	}
    }
  return false;
}
int bipartitematch()
{
  int cnt=0,i,j;
  rep(i,1,n+1) l[i]=-1;
  rep(i,1,n+1) r[i]=-1;
  rep(i,1,n+1)
    {
      rep(j,1,n+1) seen[j]=false;
      if(findmatch(i)) cnt++;
    }
  return cnt;
}
bool vis[2*N];
void dfs(int u)
{
  vis[u]=true;
  int i;
  rep(i,1,n+1)
    {
      if(vis[n+i] || !a[u][i] || r[i]==-1) continue;
      vis[n+i]=true;
      dfs(r[i]);
    }
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int i,j,k;
  cin>>n;
  rep(i,1,n+1)
    {
      cin>>s[i];
      insert(i);
    }
  build_automation();
  rep(i,1,n+1)
    makegraph(i);
  rep(k,1,n+1)
    rep(i,1,n+1)
    rep(j,1,n+1)
    a[i][j]|=(a[i][k]&a[k][j]);
  rep(i,1,n+1) a[i][i]=false;
  //http://codeforces.com/blog/entry/17534?#comment-223759( how to find min vertex cover from max matching)
  int ans=n-bipartitematch();
  //rep(i,1,n+1)
  //trace(i,l[i],r[i]);
  rep(i,1,n+1) // all unmatched nodes from left side
    if(l[i]==-1 && !vis[i]) dfs(i);
  cout<<ans<<endl;
  rep(i,1,n+1)
    {
      bool vc1=(vis[i]==false),vc2=(vis[i+n]==true);
      if(!vc1 && !vc2)
	cout<<i<<" ";
    }
  cout<<endl;
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(i=a;i<b;i++)
#define repv(i,a,b) for(i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
struct ahocorasick
{
  vi sufflink,out;
  int sz;
  vector<map<char,int> > trie;
  vector<vi> endat;
  ahocorasick()
  {
    int i;
    sz=0;
    out.resize(1); trie.resize(1); endat.resize(1);
  }
  inline void insert(string &s,int ind)
  {
    int curr=0,i,j;
    rep(i,0,s.size())
      {
	if(!trie[curr].count(s[i]))
	  {
	    trie[curr][s[i]]=++sz;
	    trie.pb(map<char,int>());
	    endat.pb(vi());
	    out.pb(0);
	  }
	curr=trie[curr][s[i]];
      }
    out[curr]++;
    endat[curr].pb(ind);
  }
  inline void build_automation()
  {
    sufflink.resize(sz+3);
    queue<int> q;
    int i,j;
    for(auto x:trie[0])
      {
	sufflink[x.se]=0;
	q.push(x.se);
      }
    while(!q.empty())
      {
	int curr=q.front();
	q.pop();
	for(auto x:trie[curr])
	  {
	    q.push(x.se);
	    int tmp=sufflink[curr];
	    while(!trie[tmp].count(x.fi) && tmp)
	      tmp=sufflink[tmp];
	    if(trie[tmp].count(x.fi))
	      sufflink[x.se]=trie[tmp][x.fi];
	    else
	      sufflink[x.se]=0;
	    out[x.se]+=out[sufflink[x.se]];
	  }
      }
  }
  int findnextstate(int curr,char ch)
  {
    while(curr && !trie[curr].count(ch))
      curr=sufflink[curr];
    return curr;
  }
  ll query(string &s)
  {
    ll ans=0;
    int curr=0,i;
    rep(i,0,s.size())
      {
	curr=findnextstate(curr,s[i]);
	curr=trie[curr][s[i]];
	ans+=out[curr];
      }
    return ans;
  }
  void clear()
  {
    trie.clear(); sufflink.clear(); out.clear();
    out.resize(1); trie.resize(1); sz=0;
  }
};
ahocorasick ac;
const int N=800;
string s[N];
bool v[N][N];
void makegraph(int ind)
{
  int i,curr=0;
  rep(i,0,sz(s[ind]))
    {
      for(int ind2:ac.endat[curr])
	v[ind2][ind]=true;
      int nxt=ac.sufflink[curr];
      for(int ind2:ac.endat[nxt])
        v[ind2][ind]=true;
      curr=ac.trie[curr][s[ind][i]];
    }
  for(int ind2:ac.endat[curr])
    v[ind2][ind]=true;
  int nxt=ac.sufflink[curr];
  for(int ind2:ac.endat[nxt])
    v[ind2][ind]=true;
}
bool seen[N];
int l[N],r[N],n;
bool a[N][N];
bool findmatch(int i)
{
  int j;
  rep(j,1,n+1)
    {
      if(a[i][j] && !seen[j])
	{
	  seen[j]=true;
	  if(r[j]<0 || findmatch(r[j]))
	    {
	      l[i]=j; r[j]=i;
	      return true;
	    }
	}
    }
  return false;
}
int bipartitematch()
{
  int cnt=0,i,j;
  rep(i,1,n+1) l[i]=-1;
  rep(i,1,n+1) r[i]=-1;
  rep(i,1,n+1)
    {
      rep(j,1,n+1) seen[j]=false;
      if(findmatch(i)) cnt++;
    }
  return cnt;
}
bool mark[2*N],vis[2*N],vc[2*N];
void dfs(int u)
{
  vis[u]=true;
  int i;
  if(u<=n)
    {
      rep(i,1,n+1)
	{
	  if(vis[n+i] || i==r[u] || !a[u][i]) continue;
	  dfs(n+i);
	}
      return;
    }
  if(!mark[u] || vis[l[u-n]]) return;
  dfs(l[u-n]);
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int i,j,k;
  cin>>n;
  rep(i,1,n+1)
    {
      cin>>s[i];
      ac.insert(s[i],i);
    }
  ac.build_automation();
  rep(i,1,n+1)
    makegraph(i);
  rep(k,1,n+1)
    rep(i,1,n+1)
    rep(j,1,n+1)
    v[i][j]|=(v[i][k]&v[k][j]);
  rep(i,1,n+1) v[i][i]=false;
  rep(i,1,n+1)
    rep(j,1,n+1)
    cout<<v[i][j]<<((j==n)?"\n":" ");
  //http://codeforces.com/blog/entry/17534?#comment-223759( how to find min vertex cover from max matching
  rep(i,1,n+1) rep(j,1,n+1) a[i][j]=v[i][j];
  int ans=bipartitematch();
  rep(i,1,n+1)
    if(l[i]!=-1)
      mark[l[i]+n]=mark[i]=true;
  rep(i,1,n+1)
    if(!mark[i] && !vis[i]) dfs(i);
  rep(i,1,2*n+1)
    {
      if(!mark[i]) continue;
      vc[i]=((i<=n && !vis[i]) || (i>n && vis[i]));
    }
  cout<<n-ans<<endl;
  rep(i,1,n+1)
    if(!vc[i] && !vc[i+n])
      cout<<i<<" ";
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(i=a;i<b;i++)
#define repv(i,a,b) for(i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
struct ahocorasick
{
  vi sufflink,out;
  int sz;
  vector<map<char,int> > trie;
  map<int,vi> endat;
  ahocorasick()
  {
    int i;
    sz=0;
    out.resize(1); trie.resize(1);
  }
  inline void insert(string &s,int ind)
  {
    int curr=0,i,j;
    rep(i,0,s.size())
      {
	if(!trie[curr].count(s[i]))
	  {
	    trie[curr][s[i]]=++sz;
	    trie.pb(map<char,int>());
	    out.pb(0);
	  }
	curr=trie[curr][s[i]];
	endat[curr].pb(ind);
      }
    out[curr]++;
    endat[curr].pb(ind);
  }
  inline void build_automation()
  {
    sufflink.resize(sz+3);
    queue<int> q;
    int i,j;
    for(auto x:trie[0])
      {
	sufflink[x.se]=0;
	q.push(x.se);
      }
    while(!q.empty())
      {
	int curr=q.front();
	q.pop();
	for(auto x:trie[curr])
	  {
	    q.push(x.se);
	    int tmp=sufflink[curr];
	    while(!trie[tmp].count(x.fi) && tmp)
	      tmp=sufflink[tmp];
	    if(trie[tmp].count(x.fi))
	      sufflink[x.se]=trie[tmp][x.fi];
	    else
	      sufflink[x.se]=0;
	    out[x.se]+=out[sufflink[x.se]];
	  }
      }
  }
  int findnextstate(int curr,char ch)
  {
    while(curr && !trie[curr].count(ch))
      curr=sufflink[curr];
    return curr;
  }
  ll query(string &s)
  {
    ll ans=0;
    int curr=0,i;
    rep(i,0,s.size())
      {
	curr=findnextstate(curr,s[i]);
	curr=trie[curr][s[i]];
	ans+=out[curr];
      }
    return ans;
  }
  void clear()
  {
    trie.clear(); sufflink.clear(); out.clear();
    out.resize(1); trie.resize(1); sz=0;
  }
};
ahocorasick ac;
const int N=800;
string s[N];
bool v[N][N];
void makegraph(int ind)
{
  int i,curr=0;
  rep(i,0,sz(s[ind]))
    {
      if(ac.endat.count(curr))
	{
	  for(int ind2:ac.endat[curr])
	    v[ind2][ind]=true;
	}
      int nxt=ac.sufflink[curr];
      if(ac.endat.count(nxt))
	{
	  for(int ind2:ac.endat[nxt])
	    v[ind2][ind]=true;
	}
      curr=ac.trie[curr][s[ind][i]];
    }
  if(ac.endat.count(curr))
    {
      for(int ind2:ac.endat[curr])
	v[ind2][ind]=true;
    }
  int nxt=ac.sufflink[curr];
  if(ac.endat.count(nxt))
    {
      for(int ind2:ac.endat[nxt])
	v[ind2][ind]=true;
    }
}
bool seen[N];
int l[N],r[N],n;
bool a[N][N];
bool findmatch(int i)
{
  int j;
  rep(j,1,n+1)
    {
      if(a[i][j] && !seen[j])
	{
	  seen[j]=true;
	  if(r[j]<0 || findmatch(r[j]))
	    {
	      l[i]=j; r[j]=i;
	      return true;
	    }
	}
    }
  return false;
}
int bipartitematch()
{
  int cnt=0,i,j;
  rep(i,1,n+1) l[i]=-1;
  rep(i,1,n+1) r[i]=-1;
  rep(i,1,n+1)
    {
      rep(j,1,n+1) seen[j]=false;
      if(findmatch(i)) cnt++;
    }
  return cnt;
}
bool mark[2*N],vis[2*N],vc[2*N];
void dfs(int u)
{
  vis[u]=true;
  int i;
  rep(i,1,n+1)
    {
      if(vis[n+i] || !a[u][i] || r[i]==-1) continue;
      vis[n+i]=true;
      dfs(r[i]);
    }
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int i,j,k;
  cin>>n;
  rep(i,1,n+1)
    {
      cin>>s[i];
      ac.insert(s[i],i);
    }
  ac.build_automation();
  rep(i,1,n+1)
    makegraph(i);
  rep(k,1,n+1)
    rep(i,1,n+1)
    rep(j,1,n+1)
    v[i][j]|=(v[i][k]&v[k][j]);
  rep(i,1,n+1) v[i][i]=false;
  //http://codeforces.com/blog/entry/17534?#comment-223759( how to find min vertex cover from max matching)
  rep(i,1,n+1) rep(j,1,n+1) a[i][j]=v[i][j];
  int ans=n-bipartitematch();
  //rep(i,1,n+1)
  //trace(i,l[i],r[i]);
  rep(i,1,n+1)
    if(l[i]!=-1)
      mark[l[i]+n]=mark[i]=true;
  rep(i,1,n+1)
    if(!mark[i] && !vis[i]) dfs(i);
  rep(i,1,2*n+1)
    {
      if(!mark[i]) continue;
      vc[i]=((i<=n && !vis[i]) || (i>n && vis[i]));
    }
  cout<<ans<<endl;
  rep(i,1,n+1)
    if(!vc[i] && !vc[i+n])
      cout<<i<<" ";
  cout<<endl;
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(i=a;i<b;i++)
#define repv(i,a,b) for(i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
struct ahocorasick
{
  vi sufflink;
  int sz;
  vector<map<char,int> > trie;
  map<int,vi> endat;
  ahocorasick()
  {
    int i;
    sz=0;
    trie.resize(1);
  }
  void insert(string &s,int ind)
  {
    int curr=0,i,j;
    rep(i,0,s.size())
      {
	if(!trie[curr].count(s[i]))
	  {
	    trie[curr][s[i]]=++sz;
	    trie.pb(map<char,int>());
	  }
	curr=trie[curr][s[i]];
      }
    endat[curr].pb(ind);
  }
  void build_automation()
  {
    sufflink.resize(sz+3);
    queue<int> q;
    int i,j;
    for(auto x:trie[0])
      {
	sufflink[x.se]=0;
	q.push(x.se);
      }
    while(!q.empty())
      {
	int curr=q.front();
	q.pop();
	for(auto x:trie[curr])
	  {
	    q.push(x.se);
	    int tmp=sufflink[curr];
	    while(!trie[tmp].count(x.fi) && tmp)
	      tmp=sufflink[tmp];
	    if(trie[tmp].count(x.fi))
	      sufflink[x.se]=trie[tmp][x.fi];
	    else
	      sufflink[x.se]=0;
	  }
      }
  }
};
ahocorasick ac;
const int N=755;
string s[N];
bool a[N][N];
void makegraph(int ind)
{
  int i,curr=0;
  rep(i,0,sz(s[ind]))
    {
      if(ac.endat.count(curr))
	{
	  for(int ind2:ac.endat[curr])
	    a[ind2][ind]=true;
	}
      int nxt=ac.sufflink[curr];
      if(ac.endat.count(nxt))
	{
	  for(int ind2:ac.endat[nxt])
	    a[ind2][ind]=true;
	}
      curr=ac.trie[curr][s[ind][i]];
    }
  if(ac.endat.count(curr))
    {
      for(int ind2:ac.endat[curr])
	a[ind2][ind]=true;
    }
  int nxt=ac.sufflink[curr];
  if(ac.endat.count(nxt))
    {
      for(int ind2:ac.endat[nxt])
	a[ind2][ind]=true;
    }
}
bool seen[N];
int l[N],r[N],n;
bool findmatch(int i)
{
  int j;
  rep(j,1,n+1)
    {
      if(a[i][j] && !seen[j])
	{
	  seen[j]=true;
	  if(r[j]<0 || findmatch(r[j]))
	    {
	      l[i]=j; r[j]=i;
	      return true;
	    }
	}
    }
  return false;
}
int bipartitematch()
{
  int cnt=0,i,j;
  rep(i,1,n+1) l[i]=-1;
  rep(i,1,n+1) r[i]=-1;
  rep(i,1,n+1)
    {
      rep(j,1,n+1) seen[j]=false;
      if(findmatch(i)) cnt++;
    }
  return cnt;
}
bool vis[2*N];
void dfs(int u)
{
  vis[u]=true;
  int i;
  rep(i,1,n+1)
    {
      if(vis[n+i] || !a[u][i] || r[i]==-1) continue;
      vis[n+i]=true;
      dfs(r[i]);
    }
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int i,j,k;
  cin>>n;
  rep(i,1,n+1)
    {
      cin>>s[i];
      ac.insert(s[i],i);
    }
  ac.build_automation();
  rep(i,1,n+1)
    makegraph(i);
  rep(k,1,n+1)
    rep(i,1,n+1)
    rep(j,1,n+1)
    a[i][j]|=(a[i][k]&a[k][j]);
  rep(i,1,n+1) a[i][i]=false;
  //http://codeforces.com/blog/entry/17534?#comment-223759( how to find min vertex cover from max matching)
  int ans=n-bipartitematch();
  //rep(i,1,n+1)
  //trace(i,l[i],r[i]);
  rep(i,1,n+1) // all unmatched nodes from left side
    if(l[i]==-1 && !vis[i]) dfs(i);
  cout<<ans<<endl;
  rep(i,1,n+1)
    {
      bool vc1=(vis[i]==false),vc2=(vis[i+n]==true);
      if(!vc1 && !vc2)
	cout<<i<<" ";
    }
  cout<<endl;
  return 0;
}


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

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(i=a;i<b;i++)
#define repv(i,a,b) for(i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=755,MX=1e7+5;
string s[N];
bool a[N][N];
vi sufflink;
int sz;
int trie[MX][2];
map<int,vi> endat;
void insert(int ind)
{
  int curr=0,i,j;
  rep(i,0,sz(s[ind]))
    {
      int tmp=s[ind][i]-'a';
      if(!trie[curr][tmp])
	trie[curr][tmp]=++sz;
      curr=trie[curr][tmp];
    }
  endat[curr].pb(ind);
}
void build_automation()
{
  sufflink.resize(sz+3);
  queue<int> q;
  int i,j;
  rep(i,0,2)
    if(trie[0][i])
      q.push(trie[0][i]);
  while(!q.empty())
    {
      int curr=q.front();
      q.pop();
      rep(i,0,2)
	{
	  if(!trie[curr][i]) continue;
	  ii x=mp(i,trie[curr][i]);
	  q.push(x.se);
	  int tmp=sufflink[curr];
	  while(!trie[tmp][x.fi] && tmp)
	    tmp=sufflink[tmp];
	  if(trie[tmp][x.fi])
	    {
	      sufflink[x.se]=trie[tmp][x.fi];
	      vi tmp;
	      if(endat.count(sufflink[x.se]))
		{
		  for(int ind:endat[sufflink[x.se]])
		    tmp.pb(ind);
		  for(int ind:tmp)
		    endat[x.se].pb(ind);
		  sort(all(endat[x.se]));
		  endat[x.se].erase(unique(all(endat[x.se])),endat[x.se].end());
		}
	    }
	  else
	    sufflink[x.se]=0;
	}
    }
}
void makegraph(int ind)
{
  int i,curr=0;
  rep(i,0,sz(s[ind]))
    {
      //if(ind==4)
	//trace(sufflink[curr],curr);
      if(endat.count(curr))
	{
	  for(int ind2:endat[curr])
	    a[ind2][ind]=true;
	}
      int nxt=sufflink[curr];
      if(endat.count(nxt))
	{
	  for(int ind2:endat[nxt])
	    a[ind2][ind]=true;
	}
      curr=trie[curr][s[ind][i]-'a'];
    }
  if(endat.count(curr))
    {
      for(int ind2:endat[curr])
	a[ind2][ind]=true;
    }
  int nxt=sufflink[curr];
  if(endat.count(nxt))
    {
      for(int ind2:endat[nxt])
	a[ind2][ind]=true;
    }
}
bool seen[N];
int l[N],r[N],n;
bool findmatch(int i)
{
  int j;
  rep(j,1,n+1)
    {
      if(a[i][j] && !seen[j])
	{
	  seen[j]=true;
	  if(r[j]<0 || findmatch(r[j]))
	    {
	      l[i]=j; r[j]=i;
	      return true;
	    }
	}
    }
  return false;
}
int bipartitematch()
{
  int cnt=0,i,j;
  rep(i,1,n+1) l[i]=-1;
  rep(i,1,n+1) r[i]=-1;
  rep(i,1,n+1)
    {
      rep(j,1,n+1) seen[j]=false;
      if(findmatch(i)) cnt++;
    }
  return cnt;
}
bool vis[2*N];
void dfs(int u)
{
  vis[u]=true;
  int i;
  rep(i,1,n+1)
    {
      if(vis[n+i] || !a[u][i] || r[i]==-1) continue;
      vis[n+i]=true;
      dfs(r[i]);
    }
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int i,j,k;
  cin>>n;
  rep(i,1,n+1)
    {
      cin>>s[i];
      insert(i);
    }
  build_automation();
  rep(i,1,n+1)
    makegraph(i);
  rep(k,1,n+1)
    rep(i,1,n+1)
    rep(j,1,n+1)
    a[i][j]|=(a[i][k]&a[k][j]);
  rep(i,1,n+1) a[i][i]=false;
  //http://codeforces.com/blog/entry/17534?#comment-223759( how to find min vertex cover from max matching)
  int ans=n-bipartitematch();
  //rep(i,1,n+1)
  //trace(i,l[i],r[i]);
  rep(i,1,n+1) // all unmatched nodes from left side
    if(l[i]==-1 && !vis[i]) dfs(i);
  cout<<ans<<endl;
  rep(i,1,n+1)
    {
      bool vc1=(vis[i]==false),vc2=(vis[i+n]==true);
      if(!vc1 && !vc2)
	cout<<i<<" ";
    }
  cout<<endl;
  return 0;
}