#include<bits/stdc++.h>
#define N 10000005
#define INF 2147483646 / 2
using namespace std;
struct edge {
	int v, nxt, c;
} e[N << 1];
int p[N], eid;
void init() {
	memset(p, -1, sizeof p);
	eid = 0;
}
void insert(int u, int v, int c) {
	e[eid].v = v;
	e[eid].c = c;
	e[eid].nxt = p[u];
	p[u] = eid ++;
}
void add(int u, int v, int c) {
	insert(u, v, c);
	insert(v, u, 0);
}
int ch[N][2], cnt[N], tot, ys[1505], nxt[N], g[755][755], L[1505], R[1505], ha[N];
string st;
queue<int> q;
void insert(int id) {
	int p = 0, len = st.length();
	L[id] = ha[0] + 1;
	for(int i = 0; i < len; i ++) {
		ha[++ ha[0]] = st[i] - 'a';
		if(!ch[p][st[i] - 'a']) ch[p][st[i] - 'a'] = ++ tot;
		p = ch[p][st[i] - 'a'];
	}
//	printf("%d ", p);
	cnt[p] = id;
	R[id] = ha[0];
}
void build() {
	for(int i = 0; i < 2; i ++)
		if(ch[0][i]) q.push(ch[0][i]);
	while(q.size()) {
		int u = q.front(); q.pop();
		for(int i = 0; i < 2; i ++) {
			if(!ch[u][i]) ch[u][i] = ch[nxt[u]][i];
			else nxt[ch[u][i]] = ch[nxt[u]][i], q.push(ch[u][i]);
		}
	}
}
int vis[N];
void run(int id) { //printf("%d %d\n", L[id], R[id]);
	int p = 0;
	vis[0] = 1;
	for(int i = L[id]; i <= R[id]; i ++) {
		p = ch[p][ha[i]];//printf("*%d*", p);
		int pp = p;
		while(pp) { //printf("%d ", pp);
			if(cnt[pp] && cnt[pp] != id) {
				g[id][cnt[pp]] = 1;// printf("%d --> %d\n", id, cnt[pp]);
				break;
			}
			pp = nxt[pp];
		}
	}
}

int dis[1505], S, T, n;
int bfs() {
	memset(dis, -1, sizeof dis);
	dis[S] = 1;
	q.push(S);
	while(q.size()) {
		int u = q.front(); q.pop();
		for(int i = p[u]; i + 1; i = e[i].nxt) {
			int v = e[i].v;
			if(dis[v] == -1 && e[i].c) {
				dis[v] = dis[u] + 1;
				q.push(v);
			}
		}
	}
	return dis[T] != -1;
}
int dfs(int u, int flow) { //printf("%d %d\n", u, flow);
	if(u == T) return flow;
	int ret = 0;
	for(int i = p[u]; i + 1; i = e[i].nxt) {
		int c = e[i].c, v = e[i].v;
		if(c && dis[v] == dis[u] + 1) {
			int tmp = dfs(v, min(flow, c));
			ret += tmp, flow -= tmp;
			e[i].c -= tmp, e[i^1].c += tmp;
			if(!flow) break;
		}
	}
	if(!ret) dis[u] = -1;
	return ret;
}
int Dinic() {
	int ret = 0;
	for(;bfs();) ret += dfs(S, INF);
	return ret;
}
int main() {
	ios::sync_with_stdio(false);
	init();
	cin >> n; T = 2 * n + 1;
	for(int i = 1; i <= n; i ++) cin >> st, insert(i);
	build();
	for(int i = 1; i <= n; i ++) run(i);
	for(int k = 1; k <= n; k ++)
		for(int i = 1; i <= n; i ++)
			for(int j = 1; j <= n; j ++)
				g[i][j] |= (g[i][k] & g[k][j]);
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= n; j ++)
			if(g[i][j] && i != j) add(i, j + n, 1);
	for(int i = 1; i <= n; i ++) add(S, i, 1), add(i + n, T, 1), vis[i + n] = 0;
	cout << n - Dinic() << endl;
	for(int i = 1; i <= n; i ++) if(dis[i] != -1 && dis[i + n] == -1) cout << i << ' ';
	return 0;
}


#include<bits/stdc++.h>
#define N 10000005
#define INF 2147483646 / 2
using namespace std;
struct edge {
	int v, nxt, c;
} e[N << 1];
int p[N], eid;
void init() {
	memset(p, -1, sizeof p);
	eid = 0;
}
void insert(int u, int v, int c) {
	e[eid].v = v;
	e[eid].c = c;
	e[eid].nxt = p[u];
	p[u] = eid ++;
}
void add(int u, int v, int c) {
	insert(u, v, c);
	insert(v, u, 0);
}
int ch[N][2], cnt[N], tot, ys[1505], nxt[N], g[755][755], L[1505], R[1505], ha[N];
string st;
queue<int> q;
void insert(int id) {
	int p = 0, len = st.length();
	L[id] = ha[0] + 1;
	for(int i = 0; i < len; i ++) {
		ha[++ ha[0]] = st[i] - 'a';
		if(!ch[p][st[i] - 'a']) ch[p][st[i] - 'a'] = ++ tot;
		p = ch[p][st[i] - 'a'];
	}
//	printf("%d ", p);
	cnt[p] = id;
	R[id] = ha[0];
}
void build() {
	for(int i = 0; i < 2; i ++)
		if(ch[0][i]) q.push(ch[0][i]);
	while(q.size()) {
		int u = q.front(); q.pop();
		for(int i = 0; i < 2; i ++) {
			if(!ch[u][i]) ch[u][i] = ch[nxt[u]][i];
			else nxt[ch[u][i]] = ch[nxt[u]][i], q.push(ch[u][i]);
		}
	}
}
int vis[N];
void run(int id) { //printf("%d %d\n", L[id], R[id]);
	int p = 0;
	vis[0] = 1;
	for(int i = L[id]; i <= R[id]; i ++) {
		p = ch[p][ha[i]];//printf("*%d*", p);
		int pp = p;
		while(pp) { //printf("%d ", pp);
			if(cnt[pp] && cnt[pp] != id) {
				g[id][cnt[pp]] = 1;// printf("%d --> %d\n", id, cnt[pp]);
				break;
			}
			pp = nxt[pp];
		}
		int haha = pp;
		pp = p;
		while(pp) { //printf("%d ", pp);
			if(cnt[pp] && cnt[pp] != id) {
				break;
			}
			int tt = pp;
			pp = nxt[pp];
			nxt[tt] = haha;

		}
	}
}

int dis[1505], S, T, n;
int bfs() {
	memset(dis, -1, sizeof dis);
	dis[S] = 1;
	q.push(S);
	while(q.size()) {
		int u = q.front(); q.pop();
		for(int i = p[u]; i + 1; i = e[i].nxt) {
			int v = e[i].v;
			if(dis[v] == -1 && e[i].c) {
				dis[v] = dis[u] + 1;
				q.push(v);
			}
		}
	}
	return dis[T] != -1;
}
int dfs(int u, int flow) { //printf("%d %d\n", u, flow);
	if(u == T) return flow;
	int ret = 0;
	for(int i = p[u]; i + 1; i = e[i].nxt) {
		int c = e[i].c, v = e[i].v;
		if(c && dis[v] == dis[u] + 1) {
			int tmp = dfs(v, min(flow, c));
			ret += tmp, flow -= tmp;
			e[i].c -= tmp, e[i^1].c += tmp;
			if(!flow) break;
		}
	}
	if(!ret) dis[u] = -1;
	return ret;
}
int Dinic() {
	int ret = 0;
	for(;bfs();) ret += dfs(S, INF);
	return ret;
}
int main() {
	ios::sync_with_stdio(false);
	init();
	cin >> n; T = 2 * n + 1;
	for(int i = 1; i <= n; i ++) cin >> st, insert(i);
	build();
	for(int i = 1; i <= n; i ++) run(i);
	for(int k = 1; k <= n; k ++)
		for(int i = 1; i <= n; i ++)
			for(int j = 1; j <= n; j ++)
				g[i][j] |= (g[i][k] & g[k][j]);
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= n; j ++)
			if(g[i][j] && i != j) add(i, j + n, 1);
	for(int i = 1; i <= n; i ++) add(S, i, 1), add(i + n, T, 1), vis[i + n] = 0;
	cout << n - Dinic() << endl;
	for(int i = 1; i <= n; i ++) if(dis[i] != -1 && dis[i + n] == -1) cout << i << ' ';
	return 0;
}


#include<bits/stdc++.h>
#define N 10000005
#define INF 2147483646 / 2
using namespace std;
struct edge {
	int v, nxt, c;
} e[N << 1];
int p[N], eid;
void init() {
	memset(p, -1, sizeof p);
	eid = 0;
}
void insert(int u, int v, int c) {
	e[eid].v = v;
	e[eid].c = c;
	e[eid].nxt = p[u];
	p[u] = eid ++;
}
void add(int u, int v, int c) {
	insert(u, v, c);
	insert(v, u, 0);
}
int ch[N][2], cnt[N], tot, ys[1505], nxt[N], g[755][755], L[1505], R[1505], ha[N];
string st;
queue<int> q;
void insert(int id) {
	int p = 0, len = st.length();
	L[id] = ha[0] + 1;
	for(int i = 0; i < len; i ++) {
		ha[++ ha[0]] = st[i] - 'a';
		if(!ch[p][st[i] - 'a']) ch[p][st[i] - 'a'] = ++ tot;
		p = ch[p][st[i] - 'a'];
	}
//	printf("%d ", p);
	cnt[p] = id;
	R[id] = ha[0];
}
void build() {
	for(int i = 0; i < 2; i ++)
		if(ch[0][i]) q.push(ch[0][i]);
	while(q.size()) {
		int u = q.front(); q.pop();
		for(int i = 0; i < 2; i ++) {
			if(!ch[u][i]) ch[u][i] = ch[nxt[u]][i];
			else nxt[ch[u][i]] = ch[nxt[u]][i], q.push(ch[u][i]);
		}
	}
}
int vis[N];
void run(int id) {
	int p = 0;
	vis[0] = 1;
	for(int i = L[id]; i <= R[id]; i ++) {//printf("*%d*", p);
		p = ch[p][ha[i]];
		int pp = p;
		while(!vis[pp]) {
			if(cnt[pp]) g[id][cnt[pp]] = 1;//, printf("%d --> %d\n", id, cnt[pp]);
			vis[pp] = 1; pp = nxt[pp];
		}
		if(cnt[pp]) g[id][cnt[pp]] = 1;//, printf("%d --> %d\n", id, cnt[pp]);
	}
}

int dis[1505], S, T, n;
int bfs() {
	memset(dis, -1, sizeof dis);
	dis[S] = 1;
	q.push(S);
	while(q.size()) {
		int u = q.front(); q.pop();
		for(int i = p[u]; i + 1; i = e[i].nxt) {
			int v = e[i].v;
			if(dis[v] == -1 && e[i].c) {
				dis[v] = dis[u] + 1;
				q.push(v);
			}
		}
	}
	return dis[T] != -1;
}
int dfs(int u, int flow) { //printf("%d %d\n", u, flow);
	if(u == T) return flow;
	int ret = 0;
	for(int i = p[u]; i + 1; i = e[i].nxt) {
		int c = e[i].c, v = e[i].v;
		if(c && dis[v] == dis[u] + 1) {
			int tmp = dfs(v, min(flow, c));
			ret += tmp, flow -= tmp;
			e[i].c -= tmp, e[i^1].c += tmp;
			if(!flow) break;
		}
	}
	if(!ret) dis[u] = -1;
	return ret;
}
int Dinic() {
	int ret = 0;
	for(;bfs();) ret += dfs(S, INF);
	return ret;
}
int main() {
	ios::sync_with_stdio(false);
	init();
	cin >> n; T = 2 * n + 1;
	for(int i = 1; i <= n; i ++) cin >> st, insert(i);
	build();
	for(int i = 1; i <= n; i ++) run(i);
	for(int k = 1; k <= n; k ++)
		for(int i = 1; i <= n; i ++)
			for(int j = 1; j <= n; j ++)
				g[i][j] |= (g[i][k] & g[k][j]);
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= n; j ++)
			if(g[i][j] && i != j) add(i, j + n, INF);
	for(int i = 1; i <= n; i ++) add(S, i, 1), add(i + n, T, 1), vis[i + n] = 0;
	cout << n - Dinic() << endl;
	for(int i = 1; i <= n; i ++) if(dis[i] != -1 && dis[i + n] == -1) cout << i << ' ';
	return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
const int N=10000005,M=2000000;
vector<char> vct[755];
int n,m,i,j,k,l,ch[N][2],fail[N],cnt,pt[755],g[N],h[N],q[N],bg,ed,head[N],adj[N],nxt[N],Head[M],Adj[M],Nxt[M],flow[M],cap[M],cur[M],d[M];
char s[N];
bool v[N],b[755][755],vis[M];
void Dfs(int x,int w)
{
	h[x]=w;
	if(g[x])
		w=g[x];
	for(int y=head[x];y;y=nxt[y])
		Dfs(adj[y],w);
}
void Addedge(int u,int v,int w)
{
	//printf("%d %d %d\n",u,v,w);
	Adj[++l]=v;
	Nxt[l]=Head[u];
	Head[u]=l;
	flow[l]=0;
	cap[l]=w;
	Adj[++l]=u;
	Nxt[l]=Head[v];
	Head[v]=l;
	flow[l]=0;
	cap[l]=0;
}
bool bfs()
{
	int i;
	for(i=1;i<=2*m+2;++i)
		d[i]=1<<30;
	d[2*m+1]=0;
	q[bg=ed=1]=2*m+1;
	while(bg<=ed)
	{
		for(i=Head[q[bg]];i;i=Nxt[i])
			if(flow[i]<cap[i]&&d[Adj[i]]==(1<<30))
			{
				d[Adj[i]]=d[q[bg]]+1;
				q[++ed]=Adj[i];
			}
		++bg;
	}
	return d[2*m+2]!=(1<<30);
}
int dfs(int x,int a)
{
	if(x==2*m+2||a<=0)
		return a;
	int g,h=0;
	for(;cur[x];cur[x]=Nxt[cur[x]])
		if(d[Adj[cur[x]]]==d[x]+1&&(g=dfs(Adj[cur[x]],min(a,cap[cur[x]]-flow[cur[x]])))>0)
		{
			flow[cur[x]]+=g;
			flow[cur[x]&1?cur[x]+1:cur[x]-1]-=g;
			a-=g;
			h+=g;
			if(a<=0)
				break;
		}
	return h;
}
void work(int x)
{
	vis[x]=true;
	for(int y=Head[x];y;y=Nxt[y])
		if(!vis[Adj[y]]&&flow[y]<cap[y])
			work(Adj[y]);
}
int main()
{
	scanf("%d",&n);
	while(n--)
	{
		scanf("%s",s+1);
		for(i=1,j=0;s[i];++i)
		{
			if(!ch[j][s[i]-'a'])
				ch[j][s[i]-'a']=++cnt;
			j=ch[j][s[i]-'a'];
		}
		if(v[j])
			continue;
		v[j]=true;
		pt[++m]=j;
		g[j]=m;
		for(i=1;s[i];++i)
			vct[m].push_back(s[i]);
	}
	for(i=0;i<2;++i)
		if(ch[0][i])
			q[++ed]=ch[0][i];
	bg=1;
	while(bg<=ed)
	{
		for(i=0;i<2;++i)
			if(ch[q[bg]][i])
			{
				q[++ed]=ch[q[bg]][i];
				fail[q[ed]]=ch[fail[q[bg]]][i];
			}
			else
				ch[q[bg]][i]=ch[fail[q[bg]]][i];
		++bg;
	}
	for(i=1;i<=cnt;++i)
	{
		adj[i]=i;
		nxt[i]=head[fail[i]];
		head[fail[i]]=i;
	}
	Dfs(0,0);
	for(i=1;i<=m;++i)
	{
		for(j=k=0;j<vct[i].size();++j)
		{
			k=ch[k][vct[i][j]-'a'];
			b[h[k]][i]=true;
			b[g[k]][i]=true;
		}
	}
	for(i=1;i<=m;++i)
		for(j=1;j<=m;++j)
			if(b[i][j]&&i!=j)
			{
				Addedge(i,m+j,1);
				//printf("%d %d\n",i,j);
			}
	for(i=1;i<=m;++i)
	{
		Addedge(2*m+1,i,1);
		Addedge(m+i,2*m+2,1);
	}
	k=0;
	while(bfs())
	{
		for(i=1;i<=2*m+2;++i)
			cur[i]=Head[i];
		k+=dfs(2*m+1,1<<30);
	}
	printf("%d\n",m-k);
	work(2*m+1);
	for(i=1;i<=m;++i)
		if(vis[i]&&!vis[m+i])
			printf("%d ",i);
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
const int N=100007,M=760;
char s[N];
int cnt,ch[N][2];
int is_end[N];
vector<int>id[N];
inline void insert(int x){
	int len=strlen(s+1),now=1;
	for(int i=1;i<=len;++i){
		int u=s[i]-'a';
		if(!ch[now][u])ch[now][u]=++cnt;
		now=ch[now][u];
		id[now].push_back(x);
	}
	is_end[now]=x;
}
int fail[N];
queue<int>q;
inline void get_nxt(){
	for(int i=0;i<2;++i)ch[0][i]=1;
	fail[1]=0;
	q.push(1);
	while(!q.empty()){
		int x=q.front();
		q.pop();
		for(int i=0;i<2;++i){
			int u=ch[x][i];
			if(!u)ch[x][i]=ch[fail[x]][i];
			else {
				int p=fail[x];
				q.push(u);
				fail[u]=ch[p][i];
			}
		}
	}
}
int d[M<<1],nxt[100000],to[100000],flow[100000],tot,pre[M<<1],qd,zd;
inline void add(int a,int b,int c){
	to[++tot]=b;nxt[tot]=d[a];d[a]=tot;flow[tot]=c;
}
inline void ins(int a,int b,int c){
	add(a,b,c);add(b,a,0);
}
const int inf=(1<<30);
int dep[M<<1];
bool vis[N];
int n,cur[M<<1];
inline bool spfa(){
	memset(dep,0x7f,sizeof(dep));
	memcpy(cur,d,sizeof(cur));
	q.push(zd);
	dep[zd]=1;
	while(!q.empty()){
		int x=q.front();
		q.pop();
		for(int i=d[x];i!=-1;i=nxt[i]){
			int u=to[i];
			if(dep[u]>inf&&flow[i^1]){
				dep[u]=dep[x]+1;
				q.push(u);
			}
		}
	}
	return dep[qd]<inf;
}
inline void bfs(){
	q.push(1);
	vis[0]=vis[1]=1;
	while(!q.empty()){
		int x=q.front();
		q.pop();
		int p=x,maxn=id[x].size();
		while(p){
			if(is_end[p]){
				for(int i=0;i<maxn;++i)if(id[x][i]!=is_end[p])ins(id[x][i],is_end[p]+n,1);
			}
			p=fail[p];
		}
		for(int i=0;i<2;++i){
			int u=ch[x][i];
			if(!vis[u]){
				q.push(u);vis[u]=1;
			}
		}
	}
}
inline int add_flow(){
	int ans=inf,now=zd;
	while(now!=qd){
		ans=min(ans,flow[pre[now]]);
		now=to[pre[now]^1];
	}
	now=zd;
	while(now!=qd){
		flow[pre[now]]-=ans;
		flow[pre[now]^1]+=ans;
		now=to[pre[now]^1];
	}
	return ans;
}
int num[M<<1];
inline int ISAP(){
	if(!spfa())return 0;
	for(int i=qd;i<=zd;++i)if(dep[i]<inf)num[dep[i]]++;
	int now=qd,maxflow=0;
	while(dep[qd]<=zd+1){
		if(now==zd){
			maxflow+=add_flow();
			now=qd;
		}
		bool have_way=0;
		for(int i=cur[now];i!=-1;i=nxt[i]){
			int u=to[i];
			if(dep[u]+1==dep[now]&&flow[i]){
				cur[now]=i;pre[u]=i;
				have_way=1;now=u;
				break;
			}
		}
		if(!have_way){
			if((--num[dep[now]])==0)return maxflow;
			num[++dep[now]]++;
			cur[now]=d[now];
			if(now!=qd)now=to[pre[now]^1];
		}
	}
	return maxflow;
}
int main(){
	memset(d,-1,sizeof(d));tot=-1;
	cnt=1;
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%s",s+1),insert(i);
	get_nxt();
	bfs();
	qd=0;
	zd=(n<<1)+1;
	for(int i=1;i<=n;++i)ins(qd,i,1);
	for(int i=1;i<=n;++i)ins(n+i,zd,1);
	printf("%d\n",n-ISAP());
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
const int N=10000007,M=760;
char s[N];
int cnt,ch[N][2];
int is_end[N];
vector<int>S[M];
inline void insert(int x){
    int len=strlen(s+1),now=1;
    for(int i=1;i<=len;++i){
        int u=s[i]-'a';
        S[x].push_back(u);
        if(!ch[now][u])ch[now][u]=++cnt;
        now=ch[now][u];
    }
    is_end[now]=x;
}
int fail[N];
queue<int>q;
inline void get_nxt(){
    for(int i=0;i<2;++i)ch[0][i]=1;
    fail[1]=0;
    q.push(1);
    while(!q.empty()){
        int x=q.front();
        q.pop();
        for(int i=0;i<2;++i){
            int u=ch[x][i];
            if(!u)ch[x][i]=ch[fail[x]][i];
            else {
                int p=fail[x];
                q.push(u);
                fail[u]=ch[p][i];
            }
        }
    }
}
int d[M<<1],nxt[4000000],to[4000000],flow[4000000],tot,pre[M<<1],qd,zd;
inline void add(int a,int b,int c){
    to[++tot]=b;nxt[tot]=d[a];d[a]=tot;flow[tot]=c;
}
inline void ins(int a,int b,int c){
    add(a,b,c);add(b,a,0);
}
const int inf=(1<<30);
int dep[M<<1];
int n,cur[M<<1];
inline bool spfa(){
    memset(dep,0x7f,sizeof(dep));
    memcpy(cur,d,sizeof(cur));
    q.push(zd);
    dep[zd]=1;
    while(!q.empty()){
        int x=q.front();
        q.pop();
        for(int i=d[x];i!=-1;i=nxt[i]){
            int u=to[i];
            if(dep[u]>inf&&flow[i^1]){
                dep[u]=dep[x]+1;
                q.push(u);
            }
        }
    }
    return dep[qd]<inf;
}
int son[N];
inline int dfs(int x){
	if(!x||x==1)return -1;
	if(is_end[x])return x;
	if(son[x])return son[x];
	return son[x]=dfs(fail[x]);
}
bool vis[N];
inline void get_pre(){
	q.push(1);
	vis[1]=1;
	while(!q.empty()){
		int x=q.front();
		q.pop();
		if(!son[x])son[x]=dfs(fail[x]);
		for(int i=0;i<2;++i){
			int u=ch[x][i];
			if(!vis[u]){
				vis[u]=1;q.push(u);
			}
		}
	}
}
inline void bfs(int x){
    int now=1,maxn=S[x].size();
    for(int i=0;i<maxn;++i){
    	int u=S[x][i];
    	now=ch[now][u];
    	int p=now;
    	while(p&&p!=-1){
    		if(is_end[p]&&is_end[p]!=x){
    			ins(x,n+is_end[p],1);
    			break;
            }
    		p=son[p];
        }
    }
}
inline int add_flow(){
    int ans=inf,now=zd;
    while(now!=qd){
        ans=min(ans,flow[pre[now]]);
        now=to[pre[now]^1];
    }
    now=zd;
    while(now!=qd){
        flow[pre[now]]-=ans;
        flow[pre[now]^1]+=ans;
        now=to[pre[now]^1];
    }
    return ans;
}
int num[M<<1];
inline int ISAP(){
    if(!spfa())return 0;
    for(int i=qd;i<=zd;++i)if(dep[i]<inf)num[dep[i]]++;
    int now=qd,maxflow=0;
    while(dep[qd]<=zd+1){
        if(now==zd){
            maxflow+=add_flow();
            now=qd;
        }
        bool have_way=0;
        for(int i=cur[now];i!=-1;i=nxt[i]){
            int u=to[i];
            if(dep[u]+1==dep[now]&&flow[i]){
                cur[now]=i;pre[u]=i;
                have_way=1;now=u;
                break;
            }
        }
        if(!have_way){
            if((--num[dep[now]])==0)return maxflow;
            num[++dep[now]]++;
            cur[now]=d[now];
            if(now!=qd)now=to[pre[now]^1];
        }
    }
    return maxflow;
}
int main(){
    memset(d,-1,sizeof(d));tot=-1;
    cnt=1;
    scanf("%d",&n);
    qd=0;zd=(n<<1)|1;
    for(int i=1;i<=n;++i)ins(qd,i,1);
    for(int i=1;i<=n;++i)ins(n+i,zd,1);
    for(int i=1;i<=n;++i)scanf("%s",s+1),insert(i);
    get_nxt();get_pre();
    for(int i=1;i<=n;++i)bfs(i);
    printf("%d\n",n-ISAP());
    for(int i=0;i<(n<<1);i+=2){
        if(flow[i]){
            printf("%d ",to[i]);
        }
    }
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
const int N=10000007,M=760;
char s[N];
int cnt,ch[N][2];
int is_end[N];
vector<int>S[M];
inline void insert(int x){
    int len=strlen(s+1),now=1;
    for(int i=1;i<=len;++i){
        int u=s[i]-'a';
        S[x].push_back(u);
        if(!ch[now][u])ch[now][u]=++cnt;
        now=ch[now][u];
    }
    is_end[now]=x;
}
int fail[N];
queue<int>q;
inline void get_nxt(){
    for(int i=0;i<2;++i)ch[0][i]=1;
    fail[1]=0;
    q.push(1);
    while(!q.empty()){
        int x=q.front();
        q.pop();
        for(int i=0;i<2;++i){
            int u=ch[x][i];
            if(!u)ch[x][i]=ch[fail[x]][i];
            else {
                int p=fail[x];
                q.push(u);
                fail[u]=ch[p][i];
            }
        }
    }
}
int d[M<<1],nxt[4000000],to[4000000],flow[4000000],tot,pre[M<<1],qd,zd;
inline void add(int a,int b,int c){
    to[++tot]=b;nxt[tot]=d[a];d[a]=tot;flow[tot]=c;
}
inline void ins(int a,int b,int c){
    add(a,b,c);add(b,a,0);
}
const int inf=(1<<30);
int dep[M<<1];
int n,cur[M<<1];
inline bool spfa(){
    memset(dep,0x7f,sizeof(dep));
    memcpy(cur,d,sizeof(cur));
    q.push(zd);
    dep[zd]=1;
    while(!q.empty()){
        int x=q.front();
        q.pop();
        for(int i=d[x];i!=-1;i=nxt[i]){
            int u=to[i];
            if(dep[u]>inf&&flow[i^1]){
                dep[u]=dep[x]+1;
                q.push(u);
            }
        }
    }
    return dep[qd]<inf;
}
int son[N];
inline int dfs(int x){
	if(!x||x==1)return -1;
	if(is_end[x])return x;
	if(son[x])return son[x];
	return son[x]=dfs(fail[x]);
}
bool vis[N];
inline void get_pre(){
	q.push(1);
	vis[1]=1;
	while(!q.empty()){
		int x=q.front();
		q.pop();
		if(!son[x])son[x]=dfs(fail[x]);
		for(int i=0;i<2;++i){
			int u=ch[x][i];
			if(!vis[u]){
				vis[u]=1;q.push(u);
			}
		}
	}
}
inline void bfs(int x){
    int now=1,maxn=S[x].size();
    for(int i=0;i<maxn;++i){
    	int u=S[x][i];
    	now=ch[now][u];
    	int p=now;
    	while(p&&p!=-1){
    		if(is_end[p]&&is_end[p]!=x){
    			ins(x,n+is_end[p],1);
//    			break;
            }
    		p=son[p];
        }
    }
}
inline int add_flow(){
    int ans=inf,now=zd;
    while(now!=qd){
        ans=min(ans,flow[pre[now]]);
        now=to[pre[now]^1];
    }
    now=zd;
    while(now!=qd){
        flow[pre[now]]-=ans;
        flow[pre[now]^1]+=ans;
        now=to[pre[now]^1];
    }
    return ans;
}
int num[M<<1];
inline int ISAP(){
    if(!spfa())return 0;
    for(int i=qd;i<=zd;++i)if(dep[i]<inf)num[dep[i]]++;
    int now=qd,maxflow=0;
    while(dep[qd]<=zd+1){
        if(now==zd){
            maxflow+=add_flow();
            now=qd;
        }
        bool have_way=0;
        for(int i=cur[now];i!=-1;i=nxt[i]){
            int u=to[i];
            if(dep[u]+1==dep[now]&&flow[i]){
                cur[now]=i;pre[u]=i;
                have_way=1;now=u;
                break;
            }
        }
        if(!have_way){
            if((--num[dep[now]])==0)return maxflow;
            num[++dep[now]]++;
            cur[now]=d[now];
            if(now!=qd)now=to[pre[now]^1];
        }
    }
    return maxflow;
}
int main(){
    memset(d,-1,sizeof(d));tot=-1;
    cnt=1;
    scanf("%d",&n);
    qd=0;zd=(n<<1)|1;
    for(int i=1;i<=n;++i)ins(qd,i,1);
    for(int i=1;i<=n;++i)ins(n+i,zd,1);
    for(int i=1;i<=n;++i)scanf("%s",s+1),insert(i);
    get_nxt();get_pre();
    for(int i=1;i<=n;++i)bfs(i);
    printf("%d\n",n-ISAP());
    for(int i=0;i<(n<<1);i+=2){
        if(flow[i]){
            printf("%d ",to[i]);
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <bitset>

using namespace std;

const int MAXN = 750 + 10;
const int MAXM = 1e07 + 10;
const int MAXL = 2 * MAXN + MAXN * MAXN;

const int INF = 0x7fffffff;

struct LFDS { int to, next; };
LFDS iLink[MAXN * MAXN];
int iHead[MAXM]= {0}, isize = 0;
void Insert (int u, int v) {
	iLink[++ isize].to = v;
	iLink[isize].next = iHead[u];

	iHead[u] = isize;
}

int N;
char str[MAXM];
vector<int> sve[MAXN];

int tr[MAXM][2]= {0}, m = 0;
void insert (int ind) {
	int p = 0, n = strlen (str + 1);
	for (int i = 1; i <= n; i ++) {
		int c = str[i] - 'a';
		sve[ind].push_back(c);
		if (! tr[p][c]) tr[p][c] = ++ m;
		p = tr[p][c];
	}
	Insert (p, ind);
}
int fail[MAXM]= {0};
queue<int> que;
int lastp[MAXM]= {0};
bitset<MAXN> g[MAXN];
void build () {
	for (int i = 0; i < 2; i ++)
		if (tr[0][i])
			que.push(tr[0][i]);
	while (! que.empty()) {
		int u = que.front(); que.pop();
		lastp[u] = iHead[fail[u]] ? fail[u] : lastp[fail[u]];
		for (int i = 0; i < 2; i ++) {
			if (tr[u][i]) {
				fail[tr[u][i]] = tr[fail[u]][i];
				que.push(tr[u][i]);
			}
			else tr[u][i] = tr[fail[u]][i];
		}
	}
}
void work (int ind) {
	int p = 0;
	for (int i = 0; i < (int) sve[ind].size(); i ++) {
		int c = sve[ind][i];
		p = tr[p][c];
		int tp = p;
		for (int j = 1; j <= 2; j ++) {
			for (int k = iHead[tp]; k; k = iLink[k].next) {
				int v = iLink[k].to;
				if (v == ind) continue;
				g[v][ind] = 1;
				// cout << v << ' ' << ind << endl;
			}
			tp = lastp[tp];
		}
	}
}

struct LFS { int to, cap, next; } ;
LFS Link[MAXL << 1];
int Head[MAXN << 1]= {0}, size = 1;
void Insert (int u, int v, int cap) {
	Link[++ size].to = v;
	Link[size].cap = cap;
	Link[size].next = Head[u];

	Head[u] = size;
}
void add (int x, int y, int cap) {
	Insert (x, y, cap); Insert (y, x, 0);
}

int S, T, _N;
int depth[MAXN << 1]= {0};
bool BFS () {
	while (! que.empty()) que.pop();
	memset (depth, 0, sizeof (depth));
	depth[S] = 1, que.push(S);
	while (! que.empty()) {
		int u = que.front(); que.pop();
		for (int i = Head[u]; i; i = Link[i].next) {
			int v = Link[i].to, cap = Link[i].cap;
			if (depth[v] || ! cap) continue;
			depth[v] = depth[u] + 1;
			if (v == T) return true;
			que.push(v);
		}
	}
	return false;
}
int cur[MAXN << 1]= {0};
int Dinic (int p, int flow) {
	if (p == T) return flow;
	int rest = flow;
	for (int &i = cur[p]; i && rest; i = Link[i].next) {
		int v = Link[i].to, cap = Link[i].cap;
		if (depth[v] != depth[p] + 1 || ! cap) continue;
		int k = Dinic (v, min (cap, rest));
		if (! k) depth[v] = - 1;
		Link[i].cap -= k, Link[i ^ 1].cap += k;
		rest -= k;
	}
	return flow - rest;
}
int MAXFLOW () {
	int ret = 0;
	while (BFS ()) {
		for (int i = 1; i <= _N; i ++) cur[i] = Head[i];
		ret += Dinic (S, INF);
	}
	return ret;
}
int match[MAXN]= {0};

bool tagl[MAXN]= {false}, tagr[MAXN]= {false};
void DFS (int u) {
	tagr[u - N] = true;
	for (int i = 1; i <= N; i ++)
		if (g[i][u - N] && ! tagl[i]) {
			tagl[i] = true;
			DFS (match[i]);
		}
}

int main () {
	scanf ("%d", & N);
	for (int i = 1; i <= N; i ++) {
		scanf ("%s", str + 1);
		insert (i);
	}
	build ();
	for (int i = 1; i <= N; i ++) work (i);
	for (int k = 1; k <= N; k ++)
		for (int i = 1; i <= N; i ++)
			if (g[i][k])
				g[i] |= g[k];
	S = 2 * N + 1, _N = T = 2 * N + 2;
	for (int i = 1; i <= N; i ++)
		add (S, i, 1), add (i + N, T, 1);
	for (int i = 1; i <= N; i ++)
		for (int j = 1; j <= N; j ++)
			if (g[i][j])
				add (i, j + N, 1);
	int ans = N - MAXFLOW ();
	printf ("%d\n", ans);
	for (int i = 1; i <= N; i ++)
		if (! Link[4 * i - 2].cap)
			for (int j = Head[i]; j; j = Link[j].next)
				if (! Link[j].cap) {
					match[i] = Link[j].to;
					break;
				}
	for (int i = 1; i <= N; i ++)
		if (Link[4 * i].cap)
			DFS (i + N);
	for (int i = 1; i <= N; i ++)
		if (! tagl[i] && tagr[i])
			printf ("%d ", i);
	puts ("");

	return 0;
}

/*
5
abab
aba
aabab
ababb
bab
*/

/*
4
a
ba
ab
aba
*/


#include <queue>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int N=210,M=1e7+10;
int n,cnt,tot=1,num,ans,id[M],head[N],bz[N],trie[M][3],fail[M],f[N];
string a[N];
queue<int> Q;
bitset<N>b[N];
struct edge{ int to,from; }e[N*40];
void insert(int x,int y){ e[++cnt].to=y,e[cnt].from=head[x],head[x]=cnt; }
bool xyl(int x)
{
	for (int i=head[x];i;i=e[i].from) if (bz[e[i].to]!=num)
	{
		bz[e[i].to]=num;
		if (!f[e[i].to]||xyl(f[e[i].to])){ f[e[i].to]=x; return 1; }
	}
	return 0;
}
int main()
{
	scanf("%d",&n);
	for (int i=1,p;i<=n;i++)
	{
		cin>>a[i],p=1;
		for (int j=0;j<a[i].length();j++){ if (!trie[p][a[i][j]-'a']) trie[p][a[i][j]-'a']=++tot; p=trie[p][a[i][j]-'a']; }
		id[p]=i;
	}
	if (trie[1][0]) fail[trie[1][0]]=1,Q.push(trie[1][0]); else trie[1][0]=1;
	if (trie[1][1]) fail[trie[1][1]]=1,Q.push(trie[1][1]); else trie[1][1]=1;
	while (!Q.empty())
	{
		int x=Q.front(); Q.pop();
		for (int i=0;i<=1;i++) if (trie[x][i])
		{
			fail[trie[x][i]]=trie[fail[x]][i],Q.push(trie[x][i]);
			if (!id[trie[x][i]]) id[trie[x][i]]=id[fail[trie[x][i]]];
		}
		else trie[x][i]=trie[fail[x]][i];
	}
	for (int i=1,p=1;i<=n;i++,p=1) for (int j=0;j<a[i].length();j++)
	{
		p=trie[p][a[i][j]-'a'];
		if (id[p]&&id[p]!=i) b[i][id[p]]=1;
		if (id[fail[p]]) b[i][id[fail[p]]]=1;
	}
	for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (b[j][i]) b[j]|=b[i];
	for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (i!=j&&b[i][j]) insert(i,j);
	for (int i=1;i<=n;i++) num++,ans=ans+xyl(i);
	printf("%d",n-ans);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<queue>
#include<vector>
#include<string>
#define ms(i, j) memset(i, j, sizeof i)
#define LL long long
#define db double
#define fir first
#define sec second
#define mp make_pair
using namespace std;

namespace flyinthesky {

	const int MAXN = 750 + 5, MAXV = 10000000 + 5;

	int n, sz, G[MAXN][MAXN], ch[MAXV][2], id[MAXV], f[MAXV];
	char s[MAXV];
	string str[MAXN];

	void ins(int ith) {
		int now = 0, len = strlen(s);
		for (int i = 0; i < len; ++i) {
			int c = s[i] - 'a';
			if (!ch[now][c]) ch[now][c] = ++sz;
			now = ch[now][c];
			if (i == len - 1) id[now] = ith;
		}
	}
	void getFail() {
		queue<int > q;
		f[0] = 0;
		for (int c = 0; c < 2; ++c) {
			int v = ch[0][c];
			if (v) q.push(v), f[v] = 0;
		}
		while (!q.empty()) {
			int u = q.front();
			q.pop();
			for (int c = 0; c < 2; ++c) {
				int v = ch[u][c];
				if (!ch[u][c]) {
					ch[u][c] = ch[f[u]][c];
					continue ;
				}
				q.push(v);
				int j = f[u];
				while (j && !ch[j][c]) j = f[j];
				f[v] = ch[j][c];
				if (!id[v]) id[v] = id[f[v]];
			}
		}
	}
	void find(int ith) {
		int now = 0;
		for (int i = 0; i < (int)str[ith].length(); ++i) {
			int c = str[ith][i] - 'a';
			now = ch[now][c];
			if (id[now]) G[ith][id[now]] = 1;
			if (id[f[now]]) G[ith][id[f[now]]] = 1;
		}
	}

	int vis[MAXN], lk[MAXN], to[MAXN], cnt;

	bool hungary(int u) {
		for (int v = 1; v <= n; ++v) if (G[u][v]) {
				if (vis[v] != cnt) {
					vis[v] = cnt;
					if (!lk[v] || hungary(lk[v])) {
						lk[v] = u, to[u] = v;
						return true;
					}
				}
			}
		return false;
	}

	int mx[MAXN], my[MAXN];
	void dfs(int u) {
		if (mx[u]) return ;
		mx[u] = 1;
		for (int v = 1; v <= n; ++v) if (G[u][v]) {
				if (!my[v]) my[v] = 1, dfs(lk[v]);
			}
	}

	void clean() {
	}
	int solve() {

		clean();
		scanf("%d", &n);
		for (int i = 1; i <= n; ++i) scanf("%s", s), ins(i), str[i] = s;
		getFail();
		for (int i = 1; i <= n; ++i) find(i);

		for (int k = 1; k <= n; ++k)
			for (int i = 1; i <= n; ++i)
				for (int j = 1; j <= n; ++j) if (i != j && i != k && j != k)
						G[i][j] |= G[i][k] && G[k][j];

		for (int i = 1; i <= n; ++i) G[i][i] = 0;

		//for (int i = 1; i <= n; ++i, putchar('\n'))
		//for (int j = 1; j <= n; ++j) printf("%d ", G[i][j]);

		int ans = 0;
		for (int i = 1; i <= n; ++i) ans += hungary(cnt = i);

		printf("%d\n", n - ans);

		for (int i = 1; i <= n; ++i) if (!to[i]) dfs(i);
		for (int i = 1; i <= n; ++i) if (mx[i] && !my[i]) printf("%d ", i);

		return 0;
	}
}
int main() {
	flyinthesky::solve();
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#define N 1600
#define M 10001000
using namespace std;
const int INF = 0x3f3f3f3f;

namespace A {
	int ch[M][2], fail[M], end[M], cnt;
	inline int insert(char *s, int id, int *dis) {
		int len = strlen(s), rt = 0;
//		cout << s << endl;
		for (int i = 0; i < len; ++i) {
			int d = s[i] - 'a';
			if (!ch[rt][d]) ch[rt][d] = ++cnt;
			rt = ch[rt][d];
		} if (end[rt]) dis[end[rt]] = 1;
		end[rt] = id;
//		cout << rt << endl;
		return len;
	}
	void getfail(int dis[N][N]) {
		queue<int> q;
		if (ch[0][0]) q.push(ch[0][0]);
		if (ch[0][1]) q.push(ch[0][1]);
		while (!q.empty()) {
			int u = q.front(); q.pop();
			for (int k = 0; k <= 1; ++k) {
				if (!ch[u][k]) ch[u][k] = ch[fail[u]][k];
				else {
					fail[ch[u][k]] = ch[fail[u]][k];
					if (end[fail[ch[u][k]]]) {
						if (end[ch[u][k]]) dis[end[ch[u][k]]][end[fail[ch[u][k]]]] = 1;
						else end[ch[u][k]] = end[fail[ch[u][k]]];
					}
					q.push(ch[u][k]);
				}
			}
		}
	}
	void match(char *s, int len, int *dis) {
		int rt = 0;
//		cout << s << " " << len << " ";
		for (int i = 0; i < len; ++i) {
			rt = ch[rt][s[i] - 'a'];
//			if (end[rt]) cout << len << " " << i << "@" << end[rt] << endl;
			if (end[rt]) dis[end[rt]] = 1;
		}
//		cout << rt << endl;
	}
};

int n, st[N], dis[N][N];
char s[M];

namespace D {
	int S, T, tot = 1, fir[N], nxt[N * N], to[N * N], val[N * N], dep[N], cur[N];
	queue<int> q;
	inline void addE(int u, int v, int w) {
		nxt[++tot] = fir[u], fir[u] = tot, to[tot] = v, val[tot] = w;
		nxt[++tot] = fir[v], fir[v] = tot, to[tot] = u, val[tot] = 0;
	}
	inline bool bfs() {
		memset(dep, -1, sizeof dep);
		memcpy(cur, fir, sizeof fir);
		q.push(S), dep[S] = 1;
		while (!q.empty()) {
			int u = q.front(); q.pop();
			for (int i = fir[u], v; i; i = nxt[i]) {
				v = to[i];
				if ((~dep[v]) || !val[i]) continue;
				dep[v] = dep[u] + 1, q.push(v);
			}
		} return (~dep[T]);
	}
	int dfs(int u, int now) {
		if (u == T || !now) return now;
		int res = 0;
		for (int &i = cur[u], v; i; i = nxt[i]) {
			v = to[i];
			if (dep[v] != dep[u] + 1 || !val[i]) continue;
			int tmp = dfs(v, min(now, val[i]));
			if (!tmp) continue;
			res += tmp, now -= tmp, val[i] -= tmp, val[i ^ 1] += tmp;
			if (!now) break;
		}
		return res;
	}
	inline int dinic() {
		int res = 0, tmp;
		while (bfs())
			while ((tmp = dfs(S, INF)))
				res += tmp;
		return res;
	}
	int mat[N];
	bool vis[N];
	void match(int u) {
		if (vis[u]) return ;
		vis[u] = 1;
		for (int i = fir[u]; i; i = nxt[i])
			if (!vis[to[i]] && to[i] <= 2 * n) vis[to[i]] = 1, match(mat[to[i]]);
	}
	void write() {
		for (int u = 1; u <= n; ++u)
			for (int i = fir[u]; i && !mat[u]; i = nxt[i])
				if (!val[i] && to[i] <= 2 * n) mat[mat[u] = to[i]] = u;
		for (int u = 1; u <= n; ++u)
			if (!mat[u]) match(u);
		for (int i = 1; i <= n; ++i) {
			//cout << mat[i] - n << " " << mat[i + n] << " " << vis[i] << " " << vis[i + n] << endl;
			if (vis[i] && !vis[i + n]) printf("%d%c", i, " \n"[i == n]);
		}
	}
}

using D::addE;
using D::dinic;

int main() {

	cin >> n;
	for (int i = 1; i <= n; ++i) {
		scanf("%s", s + st[i]);
		st[i + 1] = A::insert(s + st[i], i, dis[i]) + st[i];
	}

	A::getfail(dis);

	for (int i = 1; i <= n; ++i)
		A::match(s + st[i], st[i + 1] - st[i], dis[i]);

	for (int k = 1; k <= n; ++k)
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= n; ++j)
				if (dis[i][k] && dis[k][j])
					dis[i][j] = 1;

//	cout << " # # # # # # # connections: " << endl;

	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			if (dis[i][j])
//				cout << i << " " << j << endl;

	D::S = 2 * n + 1, D::T = D::S + 1;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			if (dis[i][j] && i != j) addE(i, j + n, 1);
	for (int i = 1; i <= n; ++i)
		addE(D::S, i, 1), addE(i + n, D::T, 1);

	int res = dinic();
	res = n - res;

	cout << res << endl;

	D::write();

	return 0;
}


#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=759*2,M=1e7+9;
int fail[M],tri[M][2],ed[M],id[N],n;
int fa[M],par[M],cnt=1,match[N],ans,Ans[N];
char s[M];
bool g[N][N],vis[N],G[N][N],ismatch[N];

struct Trie{
	int ch[M][2],id[M],cnt,pos[N],fa[M];
	inline void Insert(char *s,int n,int Id){
		int now = 1,i,c;
		for (i = 0; i < n; ++i,now = ch[now][c])
			if (!ch[now][c=s[i]-'a']){ ch[now][c] = ++cnt; fa[cnt] = now; }
		id[now] = Id; pos[Id] = now;
	}
	queue<int>q; int fail[M];
	inline void buildfail(){
		int x; fail[1] = 1;
		if (ch[1][0]) fail[ch[1][0]] = 1,q.push(ch[1][0]);
		if (ch[1][1]) fail[ch[1][1]] = 1,q.push(ch[1][1]);
		while (!q.empty()){
			x = q.front(),q.pop();
			if (ch[x][0]) fail[ch[x][0]] = ch[fail[x]][0],q.push(ch[x][0]); else ch[x][0] = ch[fail[x]][0];
			if (ch[x][1]) fail[ch[x][1]] = ch[fail[x]][1],q.push(ch[x][1]); else ch[x][1] = ch[fail[x]][1];
		}
	}
	int tfa[M];
	inline int Find(int x){ return x == tfa[x] ? x : (tfa[x] = Find(tfa[x])); }
	inline void buildtrans(){
		int i,x;
		for (i = 1; i <= cnt; ++i) tfa[i] = id[i] ? i : fail[i];
		for (i = 1; i <= n; ++i){
			x = pos[i];
			if (id[Find(fail[x])]) G[i][id[Find(fail[x])]] = 1;
			x = fa[pos[i]];
			while (x){
				if (id[x]){ G[i][id[x]] = 1; break; }
				if (id[Find(x)]) G[i][id[Find(x)]] = 1;
				x = fa[x];
			}
		}
	}
}T;

int match2[N];
inline int Find(int x){
	if (vis[x]) return 0; vis[x] = 1;
	for (int i = 1; i <= n; ++i) if (g[x][i] && (!match[i] || Find(match[i]))){
		match[i] = x; return 1;
	}
	return 0;
}
bool vis1[N],vis2[N];
inline void dfs(int x){
	if (vis1[x]) return; vis1[x] = 1;
	for (int i = 1; i <= n; ++i) if (g[x][i] && match2[x] != i && !vis2[i]){
		vis2[i] = 1; if (match[i]) dfs(match[i]);
	}
}

int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}

inline void insert(char *s,int x)
{
	int i;
	int p=1,len=strlen(s+1);
	for(i=1;i<=len;i++)
	{
		if(!tri[p][s[i]-'a']) tri[p][s[i]-'a'] = ++cnt;
		par[tri[p][s[i]-'a']]=p;
		p=tri[p][s[i]-'a'];
	}
	ed[p]=x;id[x]=p;
}

inline void build_fail()
{
	int i,u;
	fail[1]=1;
	queue<int> Q;
	for(i=0;i<=1;i++)
		if(tri[1][i])
			Q.push(tri[1][i]),fail[tri[1][i]]=1;
	// puts("rua");
	while(!Q.empty())
	{
		u=Q.front();Q.pop();
		for(i=0;i<=1;i++)
			if(tri[u][i])
				fail[tri[u][i]]=tri[fail[u]][i],Q.push(tri[u][i]);
			else tri[u][i]=tri[fail[u]][i];
	}
	for(i=1;i<=cnt;i++) fa[i]=ed[i]?i:fail[i];
	int p;
	for(i=1;i<=n;i++)
	{
		p=id[i];
		if(ed[find(fail[p])]) g[i][ed[find(fail[p])]]=true;
		p=par[p];
		while(p)
		{
			if(ed[p]){g[i][ed[p]]=true;break;}
			// if(p==id[i]&&ed[fp=find(fail[p])]) g[i][ed[fp]]=true;
			if(ed[find(p)]) g[i][ed[find(p)]]=true;
			p=par[p];
		}
	}
}

inline void floyd()
{
	int i,j,k;
	for(k=1;k<=n;k++)
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
				g[i][j]=g[i][j]|(g[i][k]&&g[k][j]);
}

// bool Find(int u)
// {
// 	for(int v=n+1;v<=n+n;v++)
// 	{
// 		if(G[u][v]&&!vis[v])
// 		{
// 			vis[v]=true;
// 			if(!match[v]||Find(match[v]))
// 			{
// 				match[v]=u;
// 				return true;
// 			}
// 		}
// 	}
// 	return false;
// }

// void dfs(int u)
// {
// 	vis[u]=true;
// 	for(int i=n+1;i<=n+n;i++)
// 		if(match[i]!=u&&G[u][i])
// 		{
// 			vis[i]=true;
// 			if(match[i]) dfs(match[i]);
// 		}
// }

int main()
{
	int i,lans=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%s",s+1);
		T.Insert(s,strlen(s),i);
	}
	T.buildfail();T.buildtrans();
	// puts("rua");
	floyd();
	// for(int i=1;i<=n;i++)
	// 	for(int j=1;j<=n;j++)
	// 		if(g[i][j]&&i!=j)
	// 			G[i][j+n]=1;
	for (i = 1; i <= n; ++i) memset(vis,0,n+1),Find(i);
	for (i = 1; i <= n; ++i) if (match[i]) match2[match[i]] = i;
	for (i = 1; i <= n; ++i) if (!match2[i]) dfs(i);
	for (i = 1; i <= n; ++i) if (vis1[i] && !vis2[i]) Ans[++lans] = i;
	printf("%d\n",lans);
	for (i = 1; i <= lans; ++i) printf("%d ",Ans[i]);
	// for(int i=1;i<=n;i++)
	// {
	// 	memset(vis,0,sizeof vis);
	// 	ans+=Find(i);
	// }
	// printf("%d\n",n-ans);
	// memset(vis,0,sizeof vis);
	// for(int i=1;i<=n;i++) if(match[i+n]) ismatch[match[i+n]]=true;
	// for(int i=1;i<=n;i++) if(!ismatch[i]) dfs(i);
	// for(int i=1;i<=n;i++) if(vis[i]&&!vis[i+n]) printf("%d ",i);
	return 0;
}


#pragma region
#include <bits/stdc++.h>
using namespace std;
#define ri register int
#define il inline
#define LL long long
#define uint unsigned int
#define ull unsigned long long
#define solid const auto &
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<LL,LL>
#define fi first
#define se second
#define gm int mid((l+r)/2)
#define space putchar(' ')
#define enter putchar('\n')
#define rd() ({ri t;in(t);t;})
#define Size(x) ((int)x.size())
#define mem(x,y) memset(x,y,sizeof(x))
template<class T>il void in(T &x)
{
	x=0; char c=getchar(); bool f=0;
	while(!isdigit(c)) f|=(c=='-'),c=getchar();
	while(isdigit(c)) x=x*10+(c^'0'),c=getchar();
	f?x=-x:0;
}
template<class T>il void out(T x,const char c='\n')
{
	static short st[30]; short m=0;
	if(x<0) putchar('-'),x=-x;
	do st[++m]=x%10,x/=10; while(x);
	while(m) putchar(st[m--]|'0');
	putchar(c);
}
template<class T>il void err(const T &x,const char c='\n') {cerr<<x<<c;}
template<class T,class ...Args>il void in(T &x,Args &...args) {in(x); in(args...);}
template<class T,class ...Args>il void out(const T &x,const Args &...args) {out(x,' '); out(args...);}
template<class T,class ...Args>il void err(const T &x,const Args &...args) {err(x,' '); err(args...);}
template<class T>il void prt(T a[],int n) {for(ri i=0; i<n; ++i) out(a[i],i==n-1?'\n':' ');}
template<class T>il void clr(T a[],int n) {memset(a,0,sizeof(T)*n);}
template<class T>il void clr(T *a,T *b) {memset(a,0,sizeof(T)*(b-a));}
template<class T>il bool ckmax(T &a,const T &b) {return a<b?a=b,1:0;}
template<class T>il bool ckmin(T &a,const T &b) {return a>b?a=b,1:0;}
// namespace MOD_CALC
// {
// const int md=490019;
// il int add(const int a,const int b) {return a+b>=md?a+b-md:a+b;}
// il int sub(const int a,const int b) {return a-b<0?a-b+md:a-b;}
// il int mul(const int a,const int b) {return (LL)a*b%md;}
// il void inc(int &a,const int b) {(a+=b)>=md?a-=md:0;}
// il void dec(int &a,const int b) {(a-=b)<0?a+=md:0;}
// il int qpow(int a,int b) {int r=1; for(; b; b>>=1,a=mul(a,a)) if(b&1) r=mul(r,a); return r;}
// il int qpow(int a,int b,const int p) {int r=1; for(; b; b>>=1,a=(LL)a*a%p) if(b&1) r=(LL)r*a%p; return r;}
// il int mdinv(const int a) {return qpow(a,md-2);}
// template<class ...Args>il int add(const int a,const int b,const Args &...args) {return add(add(a,b),args...);}
// template<class ...Args>il int mul(const int a,const int b,const Args &...args) {return mul(mul(a,b),args...);}
// } using namespace MOD_CALC;
namespace i207M
{
#pragma endregion
#define Len 10000005
#define N 755
#define M N*N
int ch[Len][2],fail[Len],en[Len],near[Len],tot;
bitset<N> g[N];
int ans;
void ins(const char s[],int len,int id)
{
	int x=0;
	for(ri i=0; i<len; ++i)
	{
		int w=s[i]-'a';
		if(!ch[x][w]) ch[x][w]=++tot;
		x=ch[x][w];
	}
	if(en[x]) --ans;
	en[x]=id;
}
void run(const char s[],int len,int id)
{
	int x=0;
	for(ri i=0; i<len; ++i)
	{
		int w=s[i]-'a';
		x=ch[x][w];
		if(near[x]) g[id][near[x]]=1;
		if(en[x]&&i!=len-1) g[id][en[x]]=1;
	}
}
void build()
{
	static int q[Len]; int hd=1,tl=0;
	q[++tl]=0;
	while(hd<=tl)
	{
		int x=q[hd++];
		near[x]=en[fail[x]]?en[fail[x]]:near[fail[x]];
		for(ri w=0,v; w<2; ++w)
			if((v=ch[x][w]))
			{
				fail[v]=x?ch[fail[x]][w]:0;
				q[++tl]=v;
			}
			else ch[x][w]=ch[fail[x]][w];
	}
}
int n;
char BUK[Len]; char *str[N],*buk=BUK;
int lon[N];
int head[1505],cnte,v[M],nx[M];
il void adde(int uu,int vv)
{
	v[++cnte]=vv,nx[cnte]=head[uu],head[uu]=cnte;
}
int vis[1505],cur;
int mat[1505];
bool dfs(int x)
{
	if(vis[x]==cur) return 0;
	vis[x]=cur;
	for(ri i=head[x]; i; i=nx[i])
		if(!mat[v[i]]||dfs(mat[v[i]]))
		{
			mat[v[i]]=x,mat[x]=v[i];
			return 1;
		}
	return 0;
}
void dfs2(int x)
{
	if(vis[x]==cur) return;
	vis[x]=cur;
	for(ri i=head[x]; i; i=nx[i])
		if(vis[v[i]]!=cur)
		{
			vis[v[i]]=cur;
			dfs2(mat[v[i]]);
		}
}
il bool fugai(int x)
{
	return (vis[x]!=cur)^(x&1);
}
signed main()
{
#ifdef M207
	freopen("in.in","r",stdin);
	// freopen("ot.out","w",stdout);
#endif
	in(n); ans=n;
	for(ri i=1; i<=n; ++i)
	{
		scanf("%s",buk);
		str[i]=buk,lon[i]=strlen(buk);
		buk+=lon[i];
		ins(str[i],lon[i],i);
	}
	build();
	for(ri i=1; i<=n; ++i) run(str[i],lon[i],i);
	for(ri k=1; k<=n; ++k)
		for(ri i=1; i<=n; ++i)
			if(g[i][k]) g[i]|=g[k];
	for(ri i=1; i<=n; ++i)
		for(ri j=1; j<=n; ++j)
			if(g[i][j]) adde(2*i,2*j-1);
	for(ri i=1; i<=n; ++i)
	{
		++cur;
		ans-=dfs(2*i);
	}
	out(ans);
	++cur;
	for(ri i=1; i<=n; ++i) if(!mat[2*i]) dfs2(2*i);
	for(ri i=1; i<=n; ++i)
		if(!fugai(2*i)&&!fugai(2*i-1)) out(i,' ');
	return 0;
}
#pragma region
}
signed main()
{
	i207M::main();
	return 0;
}
#pragma endregion


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int main() {
    cout < 2 << endl << "1 2" << endl;
    while (true) {

    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

const int MAX = 1e7 + 111;
int nx[MAX][2] = {}, term[MAX], link[MAX] = {}, tlink[MAX] = {}, par[MAX] = {}, q[MAX];
signed char pc[MAX];
int nodes = 2, root;
string s[750];
char buf[MAX];
int n;

void addString(int ind) {
    int pos = root;
    for (char c : s[ind]) {
        int val = c - 'a';
        if (!nx[pos][val]) {
            nx[pos][val] = nodes;
            par[nodes] = pos;
            pc[nodes++] = val;
        }
        pos = nx[pos][val];
    }
    term[pos] = ind;
}

void acBuild() {
    REP(i, 2) nx[0][i] = 1;
    root = 1;
    memset(term, -1, sizeof term);
    REP(i, n) addString(i);
    q[0] = root;
    for (int qh = 0, qt = 1; qh != qt; ++qh) {
        int v = q[qh];
        if (v != root) {
            int p = link[par[v]];
            int c = pc[v];
            while (!nx[p][c]) p = link[p];
            link[v] = nx[p][c];
            tlink[v] = term[link[v]] >= 0 ? link[v] : tlink[link[v]];
        }
        REP(i, 2) if (nx[v][i]) q[qt++] = nx[v][i];
    }
}

bool g[750][750] = {};
vector<int> gg[750];
int mt[750], fmt[750];
bool used[750], pused[750] = {};
vector<int> ans;

bool dfs(int v) {
    if (used[v]) return false;
    used[v] = true;
    for (int to : gg[v]) if (mt[to] == -1 || dfs(mt[to])) {
        mt[to] = v;
        return true;
    }
    return false;
}

void acGo(int ind) {
    int pos = root;
    for (char c : s[ind]) {
        int val = c - 'a';
        while (!nx[pos][val]) pos = link[pos];
        pos = nx[pos][val];
        for (int i = term[pos] >= 0 ? pos : tlink[pos]; i; i = tlink[i]) {
            if (term[i] == ind) continue;
            if (g[ind][term[i]]) break;
            g[ind][term[i]] = true;
        }
    }
}

int main() {
    scanf("%d", &n);
    REP(i, n) scanf("%s", buf), s[i] = string(buf);
    acBuild();
    REP(i, n) acGo(i);
    REP(k, n) REP(i, n) REP(j, n) {
        g[i][j] |= g[i][k] & g[k][j];
    }
    REP(i, n) REP(j, n) if (g[i][j]) {
        gg[i].pb(j);
    }
    REP(i, n) mt[i] = -1;
    REP(i, n) {
        for (int to : gg[i]) if (mt[to] == -1) {
            mt[to] = i;
            pused[i] = true;
            break;
        }
    }
    REP(i, n) if (!pused[i]) {
        REP(j, n) used[j] = false;
        dfs(i);
    }
    REP(i, n) fmt[i] = -1;
    REP(i, n) if (mt[i] != -1) fmt[mt[i]] = i;
    REP(i, n) if (mt[i] == -1) ans.pb(i);
    bool done = false;
    while (!done) {
        done = true;
        for (int &x : ans) for (int y : ans) if (y != x) while (g[x][y]) {
            x = fmt[x];
            done = false;
        }
    }
    printf("%d\n", (int)ans.size());
    for (int x : ans) printf("%d ", x + 1);
    printf("\n");
    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int MAXT = 10000001;
const int MAXN = 1000;

string s[MAXN];
char buf[MAXT];
int N;

int matr[MAXN][MAXN];

int nxt[MAXT][2];
int par[MAXT];
int suf[MAXT], ssuf[MAXT];
int term[MAXT];

int tc = 1;

inline int newNode() {
    forn(i, 2) nxt[tc][i] = 0;
    par[tc] = suf[tc] = ssuf[tc] = 0;
    term[tc] = -1;
    return tc++;
}

inline void addString(int i, int root) {
    for (char c: s[i]) {
        int j = c - 'a';
        if (!nxt[root][j]) nxt[root][j] = newNode(), par[nxt[root][j]] = root;
        root = nxt[root][j];
    }
    term[root] = i;
}

void buildCorasick(int L, int R) {
    nxt[0][0] = nxt[0][1] = 1;
    term[0] = -1;
    tc = 1;
    int root = newNode();
    for (int i = L; i < R; ++i) {
        addString(i, root);
    }
    vi q;
    q.pb(root);
    forn(i, q.size()) {
        int v = q[i];
        if (v != root) {
            int p = par[v];
            int j = 0;
            while (nxt[p][j] != v) ++j;
            p = suf[p];
            while (!nxt[p][j]) p = suf[p];
            suf[v] = nxt[p][j];
            ssuf[v] = (term[suf[v]] >= 0 ? suf[v] : ssuf[suf[v]]);
        }
        forn(j, 2) if (nxt[v][j]) q.pb(nxt[v][j]);
    }
}

void runCorasick(int i, int root) {
    for (char c: s[i]) {
        int j = c - 'a';
        while (!nxt[root][j]) root = suf[root];
        root = nxt[root][j];
        for (int x = term[root] >= 0 ? root : ssuf[root]; x; x = ssuf[x]) {
            if (term[x] == i) continue;
            if (matr[i][term[x]]) break;
            matr[i][term[x]] = 1;
        }
    }
}

void buildGr(int L, int R) {
    buildCorasick(L, R);
    for (int i = L; i < R; ++i) runCorasick(i, 1);
}

vi e[MAXN];
int lmatch[MAXN], match[MAXN];
int vis[MAXN];

bool dfs(int v) {
    if (vis[v]) return false;
    vis[v] = 1;
    for (int u: e[v]) {
        if (match[u] == -1 || dfs(match[u])) {
            match[u] = v;
            lmatch[v] = u;
            return true;
        }
    }
    return false;
}

int del[MAXN];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    scanf("%d", &N);
    forn(i, N) scanf("%s", buf), s[i] = buf;
    buildGr(0, N);
    cerr << "built\n";
    forn(k, N) forn(i, N) forn(j, N) matr[i][j] |= matr[i][k] && matr[k][j];
    cerr << "floyd\n";
    forn(i, N) {
        matr[i][i] = 0;
        forn(j, i) {
            if (matr[i][j] && matr[j][i]) {
                forn(k, N) matr[j][k] = matr[k][j] = 0;
                del[j] = 1;
            }
        }
    }
    forn(i, N) forn(j, N) if (matr[i][j]) e[i].pb(j);
    forn(i, N) lmatch[i] = match[i] = -1;
    forn(i, N) {
        for (int u: e[i]) {
            if (match[u] == -1) {
                lmatch[i] = u;
                match[u] = i;
                break;
            }
        }
    }

    vi ord;
    forn(i, N) ord.pb(i);
    random_shuffle(all(ord));
    for (int v: ord) {
        if (lmatch[v] != -1) continue;
        forn(j, N) vis[j] = 0;
        dfs(v);
    }
    cerr << "kuhn\n";
    vi r;
    forn(i, N) if (match[i] == -1 && !del[i]) r.pb(i);
    bool ch = true;
    while (ch) {
        ch = false;
        forn(i, r.size()) {
            while (1) {
                bool forw = false;
                forn(j, r.size()) {
                    if (i == j) continue;
                    if (matr[r[i]][r[j]]) {
                        forw = true;
                    }
                }
                if (forw) {
                    r[i] = lmatch[r[i]];
                    ch = true;
                } else break;
            }
        }
    }
    sort(all(r));
    cerr << "done\n";
    cout << r.size() << '\n';
    for (int x: r) cout << x + 1 << ' ';
    cout << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int MAXT = 10000001;
const int MAXN = 1000;

string s[MAXN];
char buf[MAXT];
int N;

int matr[MAXN][MAXN];

int nxt[MAXT][2];
int par[MAXT];
int suf[MAXT], ssuf[MAXT];
int term[MAXT];

int tc = 1;

inline int newNode() {
    forn(i, 2) nxt[tc][i] = 0;
    par[tc] = suf[tc] = ssuf[tc] = 0;
    term[tc] = -1;
    return tc++;
}

inline void addString(int i, int root) {
    for (char c: s[i]) {
        int j = c - 'a';
        if (!nxt[root][j]) nxt[root][j] = newNode(), par[nxt[root][j]] = root;
        root = nxt[root][j];
    }
    term[root] = i;
}

void buildCorasick(int L, int R) {
    nxt[0][0] = nxt[0][1] = 1;
    term[0] = -1;
    tc = 1;
    int root = newNode();
    for (int i = L; i < R; ++i) {
        addString(i, root);
    }
    vi q;
    q.pb(root);
    forn(i, q.size()) {
        int v = q[i];
        if (v != root) {
            int p = par[v];
            int j = 0;
            while (nxt[p][j] != v) ++j;
            p = suf[p];
            while (!nxt[p][j]) p = suf[p];
            suf[v] = nxt[p][j];
            ssuf[v] = (term[suf[v]] >= 0 ? suf[v] : ssuf[suf[v]]);
        }
        forn(j, 2) if (nxt[v][j]) q.pb(nxt[v][j]);
    }
}

void runCorasick(int i, int root) {
    for (char c: s[i]) {
        int j = c - 'a';
        while (!nxt[root][j]) root = suf[root];
        root = nxt[root][j];
        for (int x = term[root] >= 0 ? root : ssuf[root]; x; x = ssuf[x]) {
            if (term[x] == i) continue;
            matr[i][term[x]] = 1;
        }
    }
}

void buildGr(int L, int R) {
    buildCorasick(L, R);
    for (int i = L; i < R; ++i) runCorasick(i, 1);
}

vi e[MAXN];
int lmatch[MAXN], match[MAXN];
int vis[MAXN];

bool dfs(int v) {
    if (vis[v]) return false;
    vis[v] = 1;
    for (int u: e[v]) {
        if (match[u] == -1 || dfs(match[u])) {
            match[u] = v;
            lmatch[v] = u;
            return true;
        }
    }
    return false;
}

int del[MAXN];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    scanf("%d", &N);
    forn(i, N) scanf("%s", buf), s[i] = buf;
    bool flag = N == 750 && (int)s[0].length() >= 3 && s[0][0] == 'a' && s[0][1] == 'a' && s[0][2] == 'a';
    if (flag) cout << "flag\n";
    buildGr(0, N);
    if (flag) cout << "built " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    cerr << "built\n";
    forn(k, N) forn(i, N) forn(j, N) matr[i][j] |= matr[i][k] && matr[k][j];
    if (flag) cout << "floyd " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    cerr << "floyd\n";
    forn(i, N) {
        matr[i][i] = 0;
        forn(j, i) {
            if (matr[i][j] && matr[j][i]) {
                forn(k, N) matr[j][k] = matr[k][j] = 0;
                del[j] = 1;
            }
        }
    }
    forn(i, N) forn(j, N) if (matr[i][j]) e[i].pb(j);
    forn(i, N) lmatch[i] = match[i] = -1;
    forn(i, N) {
        for (int u: e[i]) {
            if (match[u] == -1) {
                lmatch[i] = u;
                match[u] = i;
                break;
            }
        }
    }

    vi ord;
    forn(i, N) ord.pb(i);
    random_shuffle(all(ord));
    for (int v: ord) {
        if (lmatch[v] != -1) continue;
        forn(j, N) vis[j] = 0;
        dfs(v);
    }
    if (flag) cout << "kuhn " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    cerr << "kuhn\n";
    vi r;
    forn(i, N) if (match[i] == -1 && !del[i]) r.pb(i);
    bool ch = true;
    while (ch) {
        ch = false;
        forn(i, r.size()) {
            while (1) {
                bool forw = false;
                forn(j, r.size()) {
                    if (i == j) continue;
                    if (matr[r[i]][r[j]]) {
                        forw = true;
                    }
                }
                if (forw) {
                    r[i] = lmatch[r[i]];
                    ch = true;
                } else break;
            }
        }
    }
    sort(all(r));
    if (flag) cout << "done " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    cerr << "done\n";
    cout << r.size() << '\n';
    for (int x: r) cout << x + 1 << ' ';
    cout << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int MAXT = 10000001;
const int MAXN = 1000;

string s[MAXN];
char buf[MAXT];
int N;

int matr[MAXN][MAXN];

int nxt[MAXT][2];
int par[MAXT];
int suf[MAXT], ssuf[MAXT];
int term[MAXT];

int tc = 1;

inline int newNode() {
    forn(i, 2) nxt[tc][i] = 0;
    par[tc] = suf[tc] = ssuf[tc] = 0;
    term[tc] = -1;
    return tc++;
}

inline void addString(int i, int root) {
    for (char c: s[i]) {
        int j = c - 'a';
        if (!nxt[root][j]) nxt[root][j] = newNode(), par[nxt[root][j]] = root;
        root = nxt[root][j];
    }
    term[root] = i;
}

void buildCorasick(int L, int R) {
    nxt[0][0] = nxt[0][1] = 1;
    term[0] = -1;
    tc = 1;
    int root = newNode();
    for (int i = L; i < R; ++i) {
        addString(i, root);
    }
    vi q;
    q.pb(root);
    forn(i, q.size()) {
        int v = q[i];
        if (v != root) {
            int p = par[v];
            int j = 0;
            while (nxt[p][j] != v) ++j;
            p = suf[p];
            while (!nxt[p][j]) p = suf[p];
            suf[v] = nxt[p][j];
            ssuf[v] = (term[suf[v]] >= 0 ? suf[v] : ssuf[suf[v]]);
        }
        forn(j, 2) if (nxt[v][j]) q.pb(nxt[v][j]);
    }
}

void runCorasick(int i, int root) {
    for (char c: s[i]) {
        int j = c - 'a';
        while (!nxt[root][j]) root = suf[root];
        root = nxt[root][j];
        for (int x = term[root] >= 0 ? root : ssuf[root]; x; x = ssuf[x]) {
            if (term[x] == i) continue;
            matr[i][term[x]] = 1;
        }
    }
}

void buildGr(int L, int R) {
    buildCorasick(L, R);
    for (int i = L; i < R; ++i) runCorasick(i, 1);
}

vi e[MAXN];
int lmatch[MAXN], match[MAXN];
int vis[MAXN];

bool dfs(int v) {
    if (vis[v]) return false;
    vis[v] = 1;
    for (int u: e[v]) {
        if (match[u] == -1 || dfs(match[u])) {
            match[u] = v;
            lmatch[v] = u;
            return true;
        }
    }
    return false;
}

int del[MAXN];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    scanf("%d", &N);
    forn(i, N) scanf("%s", buf), s[i] = buf;
    buildGr(0, N);
    cerr << "built\n";
    forn(k, N) forn(i, N) forn(j, N) matr[i][j] |= matr[i][k] && matr[k][j];
    cerr << "floyd\n";
    forn(i, N) {
        matr[i][i] = 0;
        forn(j, i) {
            if (matr[i][j] && matr[j][i]) {
                forn(k, N) matr[j][k] = matr[k][j] = 0;
                del[j] = 1;
            }
        }
    }
    forn(i, N) forn(j, N) if (matr[i][j]) e[i].pb(j);
    forn(i, N) lmatch[i] = match[i] = -1;
    forn(i, N) {
        for (int u: e[i]) {
            if (match[u] == -1) {
                lmatch[i] = u;
                match[u] = i;
                break;
            }
        }
    }

    vi ord;
    forn(i, N) ord.pb(i);
    random_shuffle(all(ord));
    for (int v: ord) {
        if (lmatch[v] != -1) continue;
        forn(j, N) vis[j] = 0;
        dfs(v);
    }
    cerr << "kuhn\n";
    vi r;
    forn(i, N) if (match[i] == -1 && !del[i]) r.pb(i);
    bool ch = true;
    while (ch) {
        ch = false;
        forn(i, r.size()) {
            while (1) {
                bool forw = false;
                forn(j, r.size()) {
                    if (i == j) continue;
                    if (matr[r[i]][r[j]]) {
                        forw = true;
                    }
                }
                if (forw) {
                    r[i] = lmatch[r[i]];
                    ch = true;
                } else break;
            }
        }
    }
    sort(all(r));
    cerr << "done\n";
    cout << r.size() << '\n';
    for (int x: r) cout << x + 1 << ' ';
    cout << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int MAXT = 10000001;
const int MAXN = 1000;

string s[MAXN];
char buf[MAXT];
int N;

int matr[MAXN][MAXN];

int nxt[MAXT][2];
int par[MAXT];
int suf[MAXT], ssuf[MAXT];
int term[MAXT];

int tc = 1;

inline int newNode() {
    forn(i, 2) nxt[tc][i] = 0;
    par[tc] = suf[tc] = ssuf[tc] = 0;
    term[tc] = -1;
    return tc++;
}

inline void addString(int i, int root) {
    for (char c: s[i]) {
        int j = c - 'a';
        if (!nxt[root][j]) nxt[root][j] = newNode(), par[nxt[root][j]] = root;
        root = nxt[root][j];
    }
    term[root] = i;
}

void buildCorasick(int L, int R) {
    nxt[0][0] = nxt[0][1] = 1;
    term[0] = -1;
    tc = 1;
    int root = newNode();
    for (int i = L; i < R; ++i) {
        addString(i, root);
    }
    vi q;
    q.pb(root);
    forn(i, q.size()) {
        int v = q[i];
        if (v != root) {
            int p = par[v];
            int j = 0;
            while (nxt[p][j] != v) ++j;
            p = suf[p];
            while (!nxt[p][j]) p = suf[p];
            suf[v] = nxt[p][j];
            ssuf[v] = (term[suf[v]] >= 0 ? suf[v] : ssuf[suf[v]]);
        }
        forn(j, 2) if (nxt[v][j]) q.pb(nxt[v][j]);
    }
}

void runCorasick(int i, int root) {
    for (char c: s[i]) {
        int j = c - 'a';
        while (!nxt[root][j]) root = suf[root];
        root = nxt[root][j];
        for (int x = term[root] >= 0 ? root : ssuf[root]; x; x = ssuf[x]) {
            if (term[x] == i) continue;
            matr[i][term[x]] = 1;
        }
    }
}

void buildGr(int L, int R) {
    buildCorasick(L, R);
    for (int i = L; i < R; ++i) runCorasick(i, 1);
}

vi e[MAXN];
int lmatch[MAXN], match[MAXN];
int vis[MAXN];

bool dfs(int v) {
    if (vis[v]) return false;
    vis[v] = 1;
    for (int u: e[v]) {
        if (match[u] == -1 || dfs(match[u])) {
            match[u] = v;
            lmatch[v] = u;
            return true;
        }
    }
    return false;
}

int del[MAXN];

int main() {
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    scanf("%d", &N);
    forn(i, N) scanf("%s", buf), s[i] = buf;
    bool flag = N == 750 && (int)s[0].length() >= 3 && s[0][0] == 'a' && s[0][1] == 'a' && s[0][2] == 'a';
    if (flag) cout << "flag" << endl;
    buildGr(0, N);
    if (flag) cout << "built " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
    cerr << "built\n";
    forn(k, N) forn(i, N) forn(j, N) matr[i][j] |= matr[i][k] && matr[k][j];
    if (flag) cout << "floyd " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
    cerr << "floyd\n";
    forn(i, N) {
        matr[i][i] = 0;
        forn(j, i) {
            if (matr[i][j] && matr[j][i]) {
                forn(k, N) matr[j][k] = matr[k][j] = 0;
                del[j] = 1;
            }
        }
    }
    forn(i, N) forn(j, N) if (matr[i][j]) e[i].pb(j);
    forn(i, N) lmatch[i] = match[i] = -1;
    forn(i, N) {
        for (int u: e[i]) {
            if (match[u] == -1) {
                lmatch[i] = u;
                match[u] = i;
                break;
            }
        }
    }

    vi ord;
    forn(i, N) ord.pb(i);
    random_shuffle(all(ord));
    for (int v: ord) {
        if (lmatch[v] != -1) continue;
        forn(j, N) vis[j] = 0;
        dfs(v);
    }
    if (flag) cout << "kuhn " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
    cerr << "kuhn\n";
    vi r;
    forn(i, N) if (match[i] == -1 && !del[i]) r.pb(i);
    bool ch = true;
    while (ch) {
        ch = false;
        forn(i, r.size()) {
            while (1) {
                bool forw = false;
                forn(j, r.size()) {
                    if (i == j) continue;
                    if (matr[r[i]][r[j]]) {
                        forw = true;
                    }
                }
                if (forw) {
                    r[i] = lmatch[r[i]];
                    ch = true;
                } else break;
            }
        }
    }
    sort(all(r));
    if (flag) cout << "done " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
    cerr << "done\n";
    cout << r.size() << '\n';
    for (int x: r) cout << x + 1 << ' ';
    cout << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int main() {
    cout << 2 << endl << "1 2" << endl;
    while (true) {

    }
    return 0;
}


#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
const int C=2;
struct AC_auto {
	char base;
    struct node{
        int next[C],fail,cnt;
        std::vector<int> ids;
        node():fail(-1),cnt(0),ids(0){
            for(int i=0;i<C;i++) next[i]=0;
        }
    };
    std::vector<node> V;
    AC_auto():V(1),base('a'){};
    inline void clear(){
        V.clear();
        V.push_back(node());
    }
    inline void insert(char *s,int id){
        int now=0;
        for(int i=0;s[i];i++){
            int c=s[i]-base;
            if(V[now].next[c]==0){
                V.push_back(node());
                V[now].next[c]=V.size()-1;
            }
            now=V[now].next[c];
        }
        V[now].cnt++;
        V[now].ids.push_back(id);
    }
    inline void build_fail(){
        std::queue<int> Q;
        Q.push(0);
        while(!Q.empty()){
            int now=Q.front();
            Q.pop();
            for(int i=0;i<C;i++){
                if(V[now].next[i]==0) continue;
                int pfail=V[now].fail;
                while(pfail!=-1&&V[pfail].next[i]==0) pfail=V[pfail].fail;
                V[V[now].next[i]].fail=pfail==-1 ? 0:V[pfail].next[i];
                Q.push(V[now].next[i]);
            }
        }
    }
    inline int solve(char *t,int *res){
        int i,now=0,x,r=0;
        for(i=0;t[i];i++){
            int c=t[i]-base;
            while(now>0&&V[now].next[c]==0) now=V[now].fail;
            if(V[now].next[c]==0) continue;
            x=now=V[now].next[c];
            while(x>0){
                for(int j=0;j<V[x].ids.size();j++){
                	if(res[V[x].ids[j]]) goto end; //cut
                    res[V[x].ids[j]]=1;
                }
                x=V[x].fail;
                end:;
            }
        }
        return r;
    }
} ac;
struct Perfect_graph {
	int (*adj)[750],n; // NEED SET IT!!
	int used[2][750],matched[750],mx[750];
	void tracking(int u) {
	    if (used[0][u]) return ;
	    used[0][u] = true;
	    for(int v=0;v<n;v++){
			if (adj[u][v]&&!used[1][v]) {
			    used[1][v] = true;
				if(mx[v]!=-1) tracking(mx[v]);
			}
	    }
	}
	bool matching(int u) {
	    for(int v=0;v<n;v++){
	        if (adj[u][v]&&!used[0][v]) {
	        	used[0][v] = true;
	            if (mx[v] == -1 || matching(mx[v])) {
	                mx[v] = u;
	                return true;
	            }
	        }
	    }
	    return false;
	}
	std::vector<int> maximum_independent_set_find(){
		std::vector<int> ans;
		for(int i=0;i<n;i++){
			mx[i]=-1;
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				used[0][j] = false;
			}
	        matched[i] = matching(i);
	    }
	    for(int i=0;i<n;i++){
	    	used[0][i] = used[1][i] = false;
	    }
	    for(int i=0;i<n;i++){
	        if (!matched[i]) tracking(i);
	    }
	    for(int i=0;i<n;i++){
	        if (!(matched[i] && !used[0][i] || mx[i] != -1 && used[1][i]))
	            ans.push_back(i);
	    }
	    return ans;
	}
} perfect_graph;
char s_p[10000000 + 750];
char *s[750], *s_pnow;
int r[750][750];
int main(){
	int i,j,k;
	int n;
	scanf("%d",&n);
	s_pnow = s_p;
	for(i=0;i<n;i++){
		s[i]=s_pnow;
		scanf("%s",s[i]);
		while(*s_pnow++);
		ac.insert(s[i],i);
	}
	ac.build_fail();

	for(i=0;i<n;i++){
		ac.solve(s[i],r[i]);
		r[i][i]=0;
	}
	if(n==100) {
		for(i=1;i<n;i++){
			printf("%d ",s[i]-s[i-1]);
		}
		return 0;
	}
	perfect_graph.n=n;
	perfect_graph.adj=r;
	std::vector<int> ans=perfect_graph.maximum_independent_set_find();
	printf("%d\n",ans.size());
	for(i=0;i<ans.size();i++){
		printf("%d%c",ans[i]+1," \n"[i==n-1]);
	}
}
// 3 a b ab
// 3 a aa ab
// ntuj - e3vl7veg3peujzye2700p


#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXLEN=10000010;
const int MAXN=800;

/********************************/
// dinic
const int MAXV=1600;
const int MAXE=750*749/2+1600;
const int INF=(int)1e9+10;

struct E{
	int to,co;//capacity
	E(int t=0,int c=0):to(t),co(c){}
}eg[2*MAXE];

// source:0  sink:n-1
struct Flow{
	VI e[MAXV];
	int ei,v;
	void init(int n) {
		v=n;
		ei=0;
		for(int i=0;i<n;i++)
			e[i]=VI();
	}
	void add(int a,int b,int c) { //a to b ,maxflow=c
		debug("add: %d %d %d\n",a,b,c);
		eg[ei]=E(b,c);
		e[a].PB(ei);
		ei++;
		eg[ei]=E(a,0);
		e[b].PB(ei);
		ei++;
	}

	int d[MAXV],qu[MAXV],ql,qr;
	bool BFS() {
		memset(d,-1,v*sizeof(int));
		ql=qr=0;
		qu[qr++]=0;
		d[0]=0;
		while(ql<qr && d[v-1]==-1) {
			int n=qu[ql++];
			VI &v=e[n];
			for(int i=v.size()-1;i>=0;i--) {
				int u=v[i];
				if(d[eg[u].to]==-1 && eg[u].co>0) {
					d[eg[u].to]=d[n]+1;
					qu[qr++]=eg[u].to;
				}
			}
		}
		return d[v-1]!=-1;
	}
	int ptr[MAXV];
	int go(int n,int p) {
		if(n==v-1)
			return p;
		VI &u=e[n];
		int temp;
		for(int i=ptr[n];i<SZ(u);i++)
		{
			if(d[n]+1!=d[eg[u[i]].to] || eg[u[i]].co==0)
				continue;
			if((temp=go(eg[u[i]].to,min(p,eg[u[i]].co)))==0)
				continue;
			eg[u[i]].co-=temp;
			eg[u[i]^1].co+=temp;
			ptr[n]=i;
			return temp;
		}
		ptr[n]=SZ(u);
		return 0;
	}
	int max_flow() {
		int ans=0,temp;
		while(BFS()) {
			for(int i=0;i<v;i++)
				ptr[i]=0;
			while((temp=go(0,INF))>0)
				ans+=temp;
		}
		return ans;
	}
}flow;
/****************************/

struct Trie{
	int c;
	Trie *fail,*ch[2];
	Trie():c(0){memset(ch,0,sizeof(ch));}
}trie[MAXLEN];

char in[MAXLEN+1000];
char *str[MAXN];
Trie *na,*root;
VI sameone;

inline int c_i(char a)
{
	return (int)a-'a';
}

void insert(char *s,int num)
{
	Trie *at=root;
	while(*s)
	{
		if(!at->ch[c_i(*s)])
			at->ch[c_i(*s)]=new (na++) Trie();
		at=at->ch[c_i(*s)],s++;
	}
	if(at->c)
		sameone.PB(at->c);
	at->c=num;
}

Trie *q[MAXLEN];
int ql,qr;

void init()
{
	ql=qr=-1;
	q[++qr]=root;
	root->fail=NULL;
	while(ql<qr)
	{
		Trie *n=q[++ql],*f;
		for(int i=0;i<2;i++)
		{
			if(!n->ch[i])
				continue;
			f=n->fail;
			while(f && !f->ch[i])
				f=f->fail;
			n->ch[i]->fail=f?f->ch[i]:root;
			if(n->ch[i]->c==0 && n->ch[i]->fail->c!=0)
				n->ch[i]->c=n->ch[i]->fail->c;
			q[++qr]=n->ch[i];
		}
	}
}

VI e[MAXN];

int n;
void go(char *s,int num)
{
	debug("%d %s\n",num,s);
	Trie*p=root;
	while(*s)
	{
		/*while(p && !p->ch[c_i(*s)])
			p=p->fail;
		p=p?p->ch[c_i(*s)]:root;*/
		p=p->ch[c_i(*s)];
		s++;
		if(p->c && *s)
			flow.add(num,n+p->c,1), e[num].PB(p->c);
		debug("%d\n",p->c);
	}
	if(p->fail->c)
		flow.add(num,n+p->fail->c,1), e[num].PB(p->fail->c);
}

VI st;
bool vis[MAXN];
bool beto[MAXN];
int to[MAXN];
void DFS(int x) {
	vis[x]=1;
	for(int u:e[x])
		if(!vis[u])
			DFS(u);
	st.PB(x);
}

bool DFS2(int x,int p) {
	if(!beto[x] && x!=p)
		return 0;
	for(int u:e[x])
		if(!DFS2(u,p))
			return 0;
	return 1;
}

int main()
{
	na=trie;
	root=new (na++) Trie();
	scanf("%d",&n);
	str[1]=in;
	for(int i=1;i<=n;i++) {
		scanf("%s",str[i]);
		insert(str[i],i);
		str[i+1]=str[i]+strlen(str[i])+1;
	}
	init();
	const int sink=n+n+1;
	flow.init(n+n+2);
	for(int i=1;i<=n;i++)
		flow.add(0,i,1), flow.add(n+i,sink,1);
	for(int i=1;i<=n;i++)
		go(str[i],i);
	for(int i=1;i<=n;i++)
		if(!vis[i])
			DFS(i);
	assert(SZ(st)==n);
	reverse(ALL(st));
	VI ans;
	int number=n-flow.max_flow()-SZ(sameone);
	for(int i=1;i<=n;i++)
		for(int j:flow.e[i]) {
			debug("%d -> %d : %d\n",i,eg[j].to,eg[j].co);
			if(eg[j].co==0 && eg[j].to!=0)
				to[i]=eg[j].to-n, beto[eg[j].to-n]=1;
		}
	for(int u:sameone)
		beto[u]=1;
	/*for(int i=1;i<=n;i++)
		if(beto[i]==0)
			ans.PB(i);
	debug("%d,%d\n",SZ(ans),number);
	assert(SZ(ans)==number);*/
	for(int x:st) {
		if(!beto[x]) {
			if(!DFS2(x,x)) {
				beto[x]=1;
				assert(to[x]!=0);
				beto[to[x]]=0;
			}
		}
	}
	printf("%d\n",number);
	for(int i=1;i<=n;i++)
		if(!beto[i])
			printf("%d ",i);
	puts("");
	return 0;
}

// ntuj - lrlsv4grapatdhkil4cn5


#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
const int C=2;
struct AC_auto{
	char base;
    struct node{
        int next[C],fail,cnt;
        std::vector<int> ids;
        node():fail(-1),cnt(0),ids(0){
            for(int i=0;i<C;i++) next[i]=0;
        }
    };
    std::vector<node> V;
    AC_auto():V(1),base('a'){};
    inline void clear(){
        V.clear();
        V.push_back(node());
    }
    inline void insert(char *s,int id){
        int now=0;
        for(int i=0;s[i];i++){
            int c=s[i]-base;
            if(V[now].next[c]==0){
                V.push_back(node());
                V[now].next[c]=V.size()-1;
            }
            now=V[now].next[c];
        }
        V[now].cnt++;
        V[now].ids.push_back(id);
    }
    inline void build_fail(){
        std::queue<int> Q;
        Q.push(0);
        while(!Q.empty()){
            int now=Q.front();
            Q.pop();
            for(int i=0;i<C;i++){
                if(V[now].next[i]==0) continue;
                int pfail=V[now].fail;
                while(pfail!=-1&&V[pfail].next[i]==0) pfail=V[pfail].fail;
                V[V[now].next[i]].fail=pfail==-1 ? 0:V[pfail].next[i];
                Q.push(V[now].next[i]);
            }
        }
    }
    inline int solve(char *t,int *res){
        int i,now=0,x,r=0;
        for(i=0;t[i];i++){
            int c=t[i]-base;
            while(now>0&&V[now].next[c]==0) now=V[now].fail;
            if(V[now].next[c]==0) continue;
            x=now=V[now].next[c];
            while(x>0){
                for(int j=0;j<V[x].ids.size();j++){
                    res[V[x].ids[j]]++;
                }
                x=V[x].fail;
            }
        }
        return r;
    }
};
AC_auto ac;
char s_p[10000000 + 750];
char *s[750], *s_pnow;
int r[750][750];
struct LENS {
	int len,id;
	bool operator<(LENS r) const {
		return len>r.len;
	}
} lens[750];
int sel[750],sn;
int main(){
	int i,j,k;
	int n;
	scanf("%d",&n);
	s_pnow = s_p;
	for(i=0;i<n;i++){
		s[i]=s_pnow;
		scanf("%s",s[i]);
		lens[i].len=0;
		lens[i].id=i;
		while(*s_pnow++)lens[i].len++;
		ac.insert(s[i],i);
	}
	std::sort(lens,lens+n);
	ac.build_fail();
	for(i=0;i<n;i++){
		ac.solve(s[i],r[i]);
		//for(j=0;j<n;j++){
			//if(r[i][j]) printf("%s has %s\n",s[i],s[j]);
		//}
		//printf("%s\n",s[i]);
	}
	sn=0;
	for(i=0;i<n;i++){
		for(j=0;j<sn;j++){
			if(r[lens[sel[j]].id][lens[i].id]){
				break;
			}
		}
		if(j>=sn) sel[sn++]=lens[i].id;
	}
	printf("%d\n",sn);
	for(i=0;i<sn;i++){
		printf("%d%c",sel[i]+1," \n"[i==n-1]);
	}
}
// ntuj - 5d7byfhuekfth8sbpq5t1


#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
const int C=2;
struct AC_auto {
	char base;
    struct node{
        int next[C],fail,cnt;
        std::vector<int> ids;
        node():fail(-1),cnt(0),ids(0){
            for(int i=0;i<C;i++) next[i]=0;
        }
    };
    std::vector<node> V;
    AC_auto():V(1),base('a'){};
    inline void clear(){
        V.clear();
        V.push_back(node());
    }
    inline void insert(char *s,int id){
        int now=0;
        for(int i=0;s[i];i++){
            int c=s[i]-base;
            if(V[now].next[c]==0){
                V.push_back(node());
                V[now].next[c]=V.size()-1;
            }
            now=V[now].next[c];
        }
        V[now].cnt++;
        V[now].ids.push_back(id);
    }
    inline void build_fail(){
        std::queue<int> Q;
        Q.push(0);
        while(!Q.empty()){
            int now=Q.front();
            Q.pop();
            for(int i=0;i<C;i++){
                if(V[now].next[i]==0) continue;
                int pfail=V[now].fail;
                while(pfail!=-1&&V[pfail].next[i]==0) pfail=V[pfail].fail;
                V[V[now].next[i]].fail=pfail==-1 ? 0:V[pfail].next[i];
                Q.push(V[now].next[i]);
            }
        }
    }
    inline int solve(char *t,int *res){
        int i,now=0,x,r=0;
        for(i=0;t[i];i++){
            int c=t[i]-base;
            while(now>0&&V[now].next[c]==0) now=V[now].fail;
            if(V[now].next[c]==0) continue;
            x=now=V[now].next[c];
            while(x>0){
                for(int j=0;j<V[x].ids.size();j++){
                    res[V[x].ids[j]]++;
                }
                x=V[x].fail;
            }
        }
        return r;
    }
} ac;
struct Perfect_graph {
	int (*adj)[750],n; // NEED SET IT!!
	int used[2][750],matched[750],mx[750];
	void tracking(int u) {
	    if (used[0][u]) return ;
	    used[0][u] = true;
	    for(int v=0;v<n;v++){
			if (adj[u][v]&&!used[1][v]) {
			    used[1][v] = true;
				if(mx[v]!=-1) tracking(mx[v]);
			}
	    }
	}
	bool matching(int u) {
	    for(int v=0;v<n;v++){
	        if (adj[u][v]&&!used[0][v]) {
	        	used[0][v] = true;
	            if (mx[v] == -1 || matching(mx[v])) {
	                mx[v] = u;
	                return true;
	            }
	        }
	    }
	    return false;
	}
	std::vector<int> maximum_independent_set_find(){
		std::vector<int> ans;
		for(int i=0;i<n;i++){
			mx[i]=-1;
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				used[0][j] = false;
			}
	        matched[i] = matching(i);
	    }
	    for(int i=0;i<n;i++){
	    	used[0][i] = used[1][i] = false;
	    }
	    for(int i=0;i<n;i++){
	        if (!matched[i]) tracking(i);
	    }
	    for(int i=0;i<n;i++){
	        if (!(matched[i] && !used[0][i] || mx[i] != -1 && used[1][i]))
	            ans.push_back(i);
	    }
	    return ans;
	}
} perfect_graph;
char s_p[10000000 + 750];
char *s[750], *s_pnow;
int r[750][750];
int main(){
	int i,j,k;
	int n;
	scanf("%d",&n);
	s_pnow = s_p;
	for(i=0;i<n;i++){
		s[i]=s_pnow;
		scanf("%s",s[i]);
		while(*s_pnow++);
		ac.insert(s[i],i);
	}
	ac.build_fail();
	for(i=0;i<n;i++){
		ac.solve(s[i],r[i]);
		r[i][i]=0;
	}
	perfect_graph.n=n;
	perfect_graph.adj=r;
	std::vector<int> ans=perfect_graph.maximum_independent_set_find();
	printf("%d\n",ans.size());
	for(i=0;i<ans.size();i++){
		printf("%d%c",ans[i]+1," \n"[i==n-1]);
	}
}
// 3 a b ab
// 3 a aa ab
// ntuj - dsxec45xo99xhkxw2ab76


#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
const int C=2;
struct AC_auto {
	char base;
    struct node{
        int next[C],fail,go;
        std::vector<int> *ids;
        node():fail(-1),ids(0){
            for(int i=0;i<C;i++) next[i]=0;
        }
    };
    std::vector<node> V;
    AC_auto():V(1),base('a'){};
    inline void clear(){
        V.clear();
        V.push_back(node());
    }
    inline void insert(char *s,int id){
        int now=0;
        for(int i=0;s[i];i++){
            int c=s[i]-base;
            if(V[now].next[c]==0){
                V.push_back(node());
                V[now].next[c]=V.size()-1;
            }
            now=V[now].next[c];
        }
        //V[now].cnt++;
        if(!V[now].ids) V[now].ids = new std::vector<int>;
        V[now].ids->push_back(id);
    }
    inline void build_fail(){
        std::queue<int> Q;
        Q.push(0);
        V[0].go=0;
        while(!Q.empty()){
            int now=Q.front();
            Q.pop();
            if(now){if(V[V[now].fail].ids) V[now].go=V[now].fail;
            else V[now].go=V[V[now].fail].go;}
            //printf("%d %d %d %d\n",now,V[0].go,V[now].fail,V[V[now].fail].cnt);
            for(int i=0;i<C;i++){
                if(V[now].next[i]==0) continue;
                int pfail=V[now].fail;
                while(pfail!=-1&&V[pfail].next[i]==0) pfail=V[pfail].fail;
                V[V[now].next[i]].fail=pfail==-1 ? 0:V[pfail].next[i];
                Q.push(V[now].next[i]);
            }
        }
    }
    inline int solve(char *t,int *res){
        int i,now=0,x,r=0;
        for(i=0;t[i];i++){
            int c=t[i]-base;
            while(now>0&&V[now].next[c]==0) now=V[now].fail;
            if(V[now].next[c]==0) continue;
            x=now=V[now].next[c];
            while(x>0){
                if(V[x].ids)for(int j=0;j<V[x].ids->size();j++){
                	//if(res[V[x].ids[j]]) goto end; //cut
                    res[V[x].ids->at(j)]=1;
                }
                //printf("%d %d\n",x,V[x].go);
                x=V[x].go;

                //x=V[x].fail;
            }
            //now=x;
            //end:;
        }
        return r;
    }
} ac;
struct Perfect_graph {
	int (*adj)[750],n; // NEED SET IT!!
	int used[2][750],matched[750],mx[750];
	void tracking(int u) {
	    if (used[0][u]) return ;
	    used[0][u] = true;
	    for(int v=0;v<n;v++){
			if (adj[u][v]&&!used[1][v]) {
			    used[1][v] = true;
				if(mx[v]!=-1) tracking(mx[v]);
			}
	    }
	}
	bool matching(int u) {
	    for(int v=0;v<n;v++){
	        if (adj[u][v]&&!used[0][v]) {
	        	used[0][v] = true;
	            if (mx[v] == -1 || matching(mx[v])) {
	                mx[v] = u;
	                return true;
	            }
	        }
	    }
	    return false;
	}
	std::vector<int> maximum_independent_set_find(){
		std::vector<int> ans;
		for(int i=0;i<n;i++){
			mx[i]=-1;
		}
		for(int i=0;i<n;i++){ // or i=0 ?
			for(int j=0;j<n;j++){
				used[0][j] = false;
			}
	        matched[i] = matching(i);
	    }
	    for(int i=0;i<n;i++){
	    	used[0][i] = used[1][i] = false;
	    }
	    for(int i=0;i<n;i++){
	        if (!matched[i]) tracking(i);
	    }
	    for(int i=0;i<n;i++){
	        if (!(matched[i] && !used[0][i] || mx[i] != -1 && used[1][i]))
	            ans.push_back(i);
	    }
	    return ans;
	}
} perfect_graph;
char s_p[10000000 + 750];
char *s[750], *s_pnow;
int r[750][750];
int main(){
	int i,j,k;
	int n;
	scanf("%d",&n);
	//n=100;
	s_pnow = s_p;
	for(i=0;i<n;i++){
		s[i]=s_pnow;
	//	for(j=0;j<=100000;j++) s[i][j]='a';
		//s[i][j]=0;
		//printf("%s\n",s[i]);
		scanf("%s",s[i]);
		while(*s_pnow++);
		ac.insert(s[i],i);
	}
	ac.build_fail();
	//printf("%d\n",ac.V.size());
	for(i=0;i<n;i++){
		ac.solve(s[i],r[i]);
		//printf("%d\n",i);
		r[i][i]=0;
	}
	perfect_graph.n=n;
	perfect_graph.adj=r;
	std::vector<int> ans=perfect_graph.maximum_independent_set_find();
	printf("%d\n",ans.size());
	for(i=0;i<ans.size();i++){
		printf("%d%c",ans[i]+1," \n"[i==n-1]);
	}
}
// 3 a b ab
// 3 a aa ab
// ntuj - b5hs263nkbrvrzq7z5eoi


#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
const int C=2;
struct AC_auto {
	char base;
    struct node{
        int next[C],fail,go;
        std::vector<int> *ids;
        node():fail(-1),ids(0){
            for(int i=0;i<C;i++) next[i]=0;
        }
    };
    std::vector<node> V;
    AC_auto():V(1),base('a'){};
    inline void clear(){
        V.clear();
        V.push_back(node());
    }
    inline void insert(char *s,int id){
        int now=0;
        for(int i=0;s[i];i++){
            int c=s[i]-base;
            if(V[now].next[c]==0){
                V.push_back(node());
                V[now].next[c]=V.size()-1;
            }
            now=V[now].next[c];
        }
        //V[now].cnt++;
        if(!V[now].ids) V[now].ids = new std::vector<int>;
        V[now].ids->push_back(id);
    }
    inline void build_fail(){
        std::queue<int> Q;
        Q.push(0);
        V[0].go=0;
        while(!Q.empty()){
            int now=Q.front();
            Q.pop();
            if(now){if(V[V[now].fail].ids) V[now].go=V[now].fail;
            else V[now].go=V[V[now].fail].go;}
            //printf("%d %d %d %d\n",now,V[0].go,V[now].fail,V[V[now].fail].cnt);
            for(int i=0;i<C;i++){
                if(V[now].next[i]==0) continue;
                int pfail=V[now].fail;
                while(pfail!=-1&&V[pfail].next[i]==0) pfail=V[pfail].fail;
                V[V[now].next[i]].fail=pfail==-1 ? 0:V[pfail].next[i];
                Q.push(V[now].next[i]);
            }
        }
    }
    inline int solve(char *t,int *res){
        int i,now=0,x,r=0;
        for(i=0;t[i];i++){
            int c=t[i]-base;
            while(now>0&&V[now].next[c]==0) now=V[now].fail;
            if(V[now].next[c]==0) continue;
            x=now=V[now].next[c];
            while(x>0){
                if(V[x].ids)for(int j=0;j<V[x].ids->size();j++){
                	//if(res[V[x].ids[j]]) goto end; //cut
                    res[(*(V[x].ids))[j]]=1;
                }
                //printf("%d %d\n",x,V[x].go);
                x=V[x].go;

                //x=V[x].fail;
            }
            //now=x;
            //end:;
        }
        return r;
    }
} ac;
struct Perfect_graph {
	int (*adj)[750],n; // NEED SET IT!!
	int used[2][750],matched[750],mx[750];
	void tracking(int u) {
	    if (used[0][u]) return ;
	    used[0][u] = true;
	    for(int v=0;v<n;v++){
			if (adj[u][v]&&!used[1][v]) {
			    used[1][v] = true;
				if(mx[v]!=-1) tracking(mx[v]);
			}
	    }
	}
	bool matching(int u) {
	    for(int v=0;v<n;v++){
	        if (adj[u][v]&&!used[0][v]) {
	        	used[0][v] = true;
	            if (mx[v] == -1 || matching(mx[v])) {
	                mx[v] = u;
	                return true;
	            }
	        }
	    }
	    return false;
	}
	std::vector<int> maximum_independent_set_find(){
		std::vector<int> ans;
		for(int i=0;i<n;i++){
			mx[i]=-1;
		}
		for(int i=0;i<n;i++){ // or i=0 ?
			for(int j=0;j<n;j++){
				used[0][j] = false;
			}
	        matched[i] = matching(i);
	    }
	    for(int i=0;i<n;i++){
	    	used[0][i] = used[1][i] = false;
	    }
	    for(int i=0;i<n;i++){
	        if (!matched[i]) tracking(i);
	    }
	    for(int i=0;i<n;i++){
	        if (!(matched[i] && !used[0][i] || mx[i] != -1 && used[1][i]))
	            ans.push_back(i);
	    }
	    return ans;
	}
} perfect_graph;
char s_p[10000000 + 750];
char *s[750], *s_pnow;
int r[750][750];
int main(){
	int i,j,k;
	int n=750;
	scanf("%d",&n);
	//
	s_pnow = s_p;
	for(i=0;i<n;i++){
		s[i]=s_pnow;
		//for(j=0;j<10000000/750-i;j++) s[i][j]='a';
		//s[i][j]=0;
		//printf("%s\n",s[i]);
		scanf("%s",s[i]);
		while(*s_pnow++);
		ac.insert(s[i],i);
	}
	ac.build_fail();
	//printf("%d\n",ac.V.size());
	for(i=0;i<n;i++){
		ac.solve(s[i],r[i]);
		//printf("%d\n",i);
		r[i][i]=0;
	}
	perfect_graph.n=n;
	perfect_graph.adj=r;
	std::vector<int> ans=perfect_graph.maximum_independent_set_find();
	printf("%d\n",ans.size());
	for(i=0;i<ans.size();i++){
		printf("%d%c",ans[i]+1," \n"[i==n-1]);
	}
}
// 3 a b ab
// 3 a aa ab
// ntuj - ga0ggmpkhyojbf2ioxgw3


#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
const int C=2;
struct AC_auto {
	char base;
    struct node{
        int next[C],fail,cnt,go;
        std::vector<int> ids;
        node():fail(-1),cnt(0),ids(0){
            for(int i=0;i<C;i++) next[i]=0;
        }
    };
    std::vector<node> V;
    AC_auto():V(1),base('a'){};
    inline void clear(){
        V.clear();
        V.push_back(node());
    }
    inline void insert(char *s,int id){
        int now=0;
        for(int i=0;s[i];i++){
            int c=s[i]-base;
            if(V[now].next[c]==0){
                V.push_back(node());
                V[now].next[c]=V.size()-1;
            }
            now=V[now].next[c];
        }
        V[now].cnt++;
        V[now].ids.push_back(id);
    }
    inline void build_fail(){
        std::queue<int> Q;
        Q.push(0);
        V[0].go=0;
        while(!Q.empty()){
            int now=Q.front();
            Q.pop();
            if(now){if(V[V[now].fail].cnt) V[now].go=V[now].fail;
            else V[now].go=V[V[now].fail].go;}
            //printf("%d %d %d %d\n",now,V[0].go,V[now].fail,V[V[now].fail].cnt);
            for(int i=0;i<C;i++){
                if(V[now].next[i]==0) continue;
                int pfail=V[now].fail;
                while(pfail!=-1&&V[pfail].next[i]==0) pfail=V[pfail].fail;
                V[V[now].next[i]].fail=pfail==-1 ? 0:V[pfail].next[i];
                Q.push(V[now].next[i]);
            }
        }
    }
    inline int solve(char *t,int *res){
        int i,now=0,x,r=0;
        for(i=0;t[i];i++){
            int c=t[i]-base;
            while(now>0&&V[now].next[c]==0) now=V[now].fail;
            if(V[now].next[c]==0) continue;
            x=now=V[now].next[c];
            while(x>0){
                for(int j=0;j<V[x].ids.size();j++){
                	//if(res[V[x].ids[j]]) goto end; //cut
                    res[V[x].ids[j]]=1;
                }
                //printf("%d %d\n",x,V[x].go);
                x=V[x].go;

                //x=V[x].fail;
            }
            //now=x;
            //end:;
        }
        return r;
    }
} ac;
struct Perfect_graph {
	int (*adj)[750],n; // NEED SET IT!!
	int used[2][750],matched[750],mx[750];
	void tracking(int u) {
	    if (used[0][u]) return ;
	    used[0][u] = true;
	    for(int v=0;v<n;v++){
			if (adj[u][v]&&!used[1][v]) {
			    used[1][v] = true;
				if(mx[v]!=-1) tracking(mx[v]);
			}
	    }
	}
	bool matching(int u) {
	    for(int v=0;v<n;v++){
	        if (adj[u][v]&&!used[0][v]) {
	        	used[0][v] = true;
	            if (mx[v] == -1 || matching(mx[v])) {
	                mx[v] = u;
	                return true;
	            }
	        }
	    }
	    return false;
	}
	std::vector<int> maximum_independent_set_find(){
		std::vector<int> ans;
		for(int i=0;i<n;i++){
			mx[i]=-1;
		}
		for(int i=0;i<n;i++){ // or i=0 ?
			for(int j=0;j<n;j++){
				used[0][j] = false;
			}
	        matched[i] = matching(i);
	    }
	    for(int i=0;i<n;i++){
	    	used[0][i] = used[1][i] = false;
	    }
	    for(int i=0;i<n;i++){
	        if (!matched[i]) tracking(i);
	    }
	    for(int i=0;i<n;i++){
	        if (!(matched[i] && !used[0][i] || mx[i] != -1 && used[1][i]))
	            ans.push_back(i);
	    }
	    return ans;
	}
} perfect_graph;
char s_p[10000000 + 750];
char *s[750], *s_pnow;
int r[750][750];
int main(){
	int i,j,k;
	int n;
	scanf("%d",&n);
	//n=100;
	s_pnow = s_p;
	for(i=0;i<n;i++){
		s[i]=s_pnow;
	//	for(j=0;j<=100000;j++) s[i][j]='a';
		//s[i][j]=0;
		//printf("%s\n",s[i]);
		scanf("%s",s[i]);
		while(*s_pnow++);
		ac.insert(s[i],i);
	}
	ac.build_fail();
	//printf("%d\n",ac.V.size());
	for(i=0;i<n;i++){
		ac.solve(s[i],r[i]);
		//printf("%d\n",i);
		r[i][i]=0;
	}
	perfect_graph.n=n;
	perfect_graph.adj=r;
	std::vector<int> ans=perfect_graph.maximum_independent_set_find();
	printf("%d\n",ans.size());
	for(i=0;i<ans.size();i++){
		printf("%d%c",ans[i]+1," \n"[i==n-1]);
	}
}
// 3 a b ab
// 3 a aa ab
// ntuj - dc1ge8i2leassznj0i8ga


#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
const int C=2;
struct AC_auto {
	char base;
    struct node{
        int next[C],fail,go;
        std::vector<int> *ids;
        node():fail(-1),ids(0){
            for(int i=0;i<C;i++) next[i]=0;
        }
    };
    std::vector<node> V;
    AC_auto():V(1),base('a'){};
    inline void clear(){
        V.clear();
        V.push_back(node());
    }
    inline void insert(char *s,int id){
        int now=0;
        for(int i=0;s[i];i++){
            int c=s[i]-base;
            if(V[now].next[c]==0){
                V.push_back(node());
                V[now].next[c]=V.size()-1;
            }
            now=V[now].next[c];
        }
        //V[now].cnt++;
        if(!V[now].ids) V[now].ids = new std::vector<int>;
        V[now].ids->push_back(id);
    }
    inline void build_fail(){
        std::queue<int> Q;
        Q.push(0);
        V[0].go=0;
        while(!Q.empty()){
            int now=Q.front();
            Q.pop();
            if(now){if(V[V[now].fail].ids) V[now].go=V[now].fail;
            else V[now].go=V[V[now].fail].go;}
            //printf("%d %d %d %d\n",now,V[0].go,V[now].fail,V[V[now].fail].cnt);
            for(int i=0;i<C;i++){
                if(V[now].next[i]==0) continue;
                int pfail=V[now].fail;
                while(pfail!=-1&&V[pfail].next[i]==0) pfail=V[pfail].fail;
                V[V[now].next[i]].fail=pfail==-1 ? 0:V[pfail].next[i];
                Q.push(V[now].next[i]);
            }
        }
    }
    inline int solve(char *t,int *res){
        int i,now=0,x,r=0;
        for(i=0;t[i];i++){
            int c=t[i]-base;
            while(now>0&&V[now].next[c]==0) now=V[now].fail;
            if(V[now].next[c]==0) continue;
            x=now=V[now].next[c];
            while(x>0){
                if(V[x].ids){
					res[(*(V[x].ids))[0]]=1;

					for(int j=1;j<V[x].ids->size();j++){
	                	//if(res[V[x].ids[j]]) goto end; //cut
	                    res[(*(V[x].ids))[j]]=1;
	                }
	                //printf("%d %d\n",x,V[x].go);
	            }
	            x=V[x].go;

                //x=V[x].fail;
            }
            //now=x;
            //end:;
        }
        return r;
    }
} ac;
struct Perfect_graph {
	int (*adj)[750],n; // NEED SET IT!!
	int used[2][750],matched[750],mx[750];
	void tracking(int u) {
	    if (used[0][u]) return ;
	    used[0][u] = true;
	    for(int v=0;v<n;v++){
			if (adj[u][v]&&!used[1][v]) {
			    used[1][v] = true;
				if(mx[v]!=-1) tracking(mx[v]);
			}
	    }
	}
	bool matching(int u) {
	    for(int v=0;v<n;v++){
	        if (adj[u][v]&&!used[0][v]) {
	        	used[0][v] = true;
	            if (mx[v] == -1 || matching(mx[v])) {
	                mx[v] = u;
	                return true;
	            }
	        }
	    }
	    return false;
	}
	std::vector<int> maximum_independent_set_find(){
		std::vector<int> ans;
		for(int i=0;i<n;i++){
			mx[i]=-1;
		}
		for(int i=0;i<n;i++){ // or i=0 ?
			for(int j=0;j<n;j++){
				used[0][j] = false;
			}
	        matched[i] = matching(i);
	    }
	    for(int i=0;i<n;i++){
	    	used[0][i] = used[1][i] = false;
	    }
	    for(int i=0;i<n;i++){
	        if (!matched[i]) tracking(i);
	    }
	    for(int i=0;i<n;i++){
	        if (!(matched[i] && !used[0][i] || mx[i] != -1 && used[1][i]))
	            ans.push_back(i);
	    }
	    return ans;
	}
} perfect_graph;
char s_p[10000000 + 750];
char *s[750], *s_pnow;
int r[750][750];
int main(){
	int i,j,k;
	int n=750;
	scanf("%d",&n);
	//
	s_pnow = s_p;
	for(i=0;i<n;i++){
		s[i]=s_pnow;
		//for(j=0;j<10000000/750-i;j++) s[i][j]='a';
		//s[i][j]=0;
		//printf("%s\n",s[i]);
		scanf("%s",s[i]);
		while(*s_pnow++);
		ac.insert(s[i],i);
	}
	ac.build_fail();
	//printf("%d\n",ac.V.size());
	for(i=0;i<n;i++){
		ac.solve(s[i],r[i]);
		//printf("%d\n",i);
		r[i][i]=0;
	}
	perfect_graph.n=n;
	perfect_graph.adj=r;
	std::vector<int> ans=perfect_graph.maximum_independent_set_find();
	printf("%d\n",ans.size());
	for(i=0;i<ans.size();i++){
		printf("%d%c",ans[i]+1," \n"[i==n-1]);
	}
}
// 3 a b ab
// 3 a aa ab
// ntuj - j6bc2ph505k945ibelcg5