#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 26, maxM = 4000000;

vector <pair <int, int> > E;
bool ban[maxN];

struct Aho
{
	int n, T[maxM][Alph], F[maxM], N[maxM], o[maxM];
	queue <int> Q;
	void add(string& t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int& u = T[v][t[i] - 'a'];
			if (u == 0)	u = ++n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		FOR(c, 0, Alph)
		{
			int& u = T[1][c];
			if (u == 0)	u = 1;
			else 		F[u] = 1, Q.push(u);
		}
		while (!Q.empty())
		{
			int v = Q.front();	Q.pop();
			FOR(c, 0, Alph)
			{
				int &u = T[v][c], w = F[v];
				if (u == 0)
				{
					u = T[w][c];
					continue;
				}
				F[u] = T[w][c];
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q.push(u);
			}
		}
	}
	void query(string& t, int m, int x)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			v = T[v][t[i] - 'a'];
			int u = o[v] == 0 ? N[v] : v;
			for (; u != 0; u = N[u])	E.pb({o[u]-1, x});
		}
	}
	void clean(int v = 1)
	{
		FOR(c, 0, Alph)
		{
			if (T[v][c] > 1)	clean(T[v][c]);
			T[v][c] = 0;
		}
		F[v] = N[v] = o[v] = 0;	n = 1;
	}
}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

vector <int> G[maxN];
string T[maxN];
int partner[maxN];

void solve()
{
	int n;
	cin >> n;
	aho.clean();
	FOR(i, 0, n)
	{
		cin >> T[i];
		aho.add(T[i], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, n)
		if (!ban[i])
			aho.query(T[i], SZ(T[i]), i);

	for (auto [a, b] : E)
	{
		a++, b++;
		if (a != b)
			G[n+a].pb(b), G[b].pb(n+a);
	}

	mtg.run(G, n, n, partner);

	vector <int> ans;
	FOR(i, 0, n)
		if (!ban[i] and partner[i+1] == 0)
			ans.pb(i+1);

	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 2, maxM = 10000004;

int W;
bool ban[maxN], g[800][800];
vector <int> G[maxN];

struct Aho
{
	int n, T[maxM][Alph], F[maxM], N[maxM], o[maxM], Q[maxM];
	void add(string& t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int& u = T[v][t[i] - 'a'];
			if (u == 0)	u = ++n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		int qf = 0, qb = 0;
		FOR(c, 0, Alph)
		{
			int& u = T[1][c];
			if (u == 0)	u = 1;
			else 		F[u] = 1, Q[qb++] = u;
		}
		while (qf != qb)
		{
			int v = Q[qf++];
			FOR(c, 0, Alph)
			{
				int &u = T[v][c], w = F[v];
				if (u == 0)
				{
					u = T[w][c];
					continue;
				}
				F[u] = T[w][c];
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q[qb++] = u;
			}
		}
	}
	void query(string& t, int m, int x)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			v = T[v][t[i] - 'a'];
			int u = o[v] == 0 ? N[v] : v;
			for (; u != 0; u = N[u])
			{
				int y = o[u];
				if (x == y or g[y][x])
					continue;
				G[y+W].pb(x);
				G[x].pb(y+W);
				g[y][x] = true;
			}
		}
	}
}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

string T[maxN];
int partner[maxN];

void solve()
{
	cin >> W;
	aho.n = 1;
	FOR(i, 0, W)
	{
		cin >> T[i];
		aho.add(T[i], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, W)
		if (!ban[i])
			aho.query(T[i], SZ(T[i]), i+1);

	mtg.run(G, W, W, partner);

	vector <int> ans;
	FOR(i, 0, W)
		if (!ban[i] and partner[i+1] == 0)
			ans.pb(i+1);

	while (true)
	{
		int s = SZ(ans);
		bool ok = true;
		FOR(i, 0, s) FOR(j, 0, s)
			if (g[ans[i]][ans[j]])
				ans[i] = partner[W+ans[i]], ok = false;
		if (ok)
			break;
	}

	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 2, maxM = 10000004;

int W;
bool ban[maxN], g[800][800];

struct Aho
{
	int n, T[maxM][Alph], F[maxM], N[maxM], o[maxM], Q[maxM], vis[maxM], visCtr;
	void add(string& t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int& u = T[v][t[i] - 'a'];
			if (u == 0)	u = ++n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		int qf = 0, qb = 0;
		FOR(c, 0, Alph)
		{
			int& u = T[1][c];
			if (u == 0)	u = 1;
			else 		F[u] = 1, Q[qb++] = u;
		}
		while (qf != qb)
		{
			int v = Q[qf++];
			FOR(c, 0, Alph)
			{
				int &u = T[v][c], w = F[v];
				if (u == 0)
				{
					u = T[w][c];
					continue;
				}
				F[u] = T[w][c];
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q[qb++] = u;
			}
		}
	}
	void query(string& t, int m, int x)
	{
		vis[0] = vis[1] = ++visCtr;
		int v = 1;
		FOR(i, 0, m)
		{
			v = T[v][t[i] - 'a'];
			int u = o[v] == 0 ? N[v] : v;
			for (; !vis[u]; u=N[u])
			{
				int y = o[u];
				if (x != y and y != 0)
					g[y][x] = true;
			}
		}
	}
}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

struct VerCover
{
    vector <int>* G;
    int* part;
    bool* res;
    void dfs(int v)
    {
        for (int u : G[v])
            if (part[u] != 0 and !res[u])
            {	res[u] = true;	dfs(part[u]);	}
    }

    void run(vector <int>* g, int n, int* Pin, bool* Rout)
    {
        G = g, part = Pin, res = Rout;
        FOR(i, 1, n+1)	if (part[i] == 0)	dfs(i);
        FOR(i, 1, n+1)
            if (part[i] != 0 and !res[part[i]])
                res[i] = true;
    }
}cover;

string T[maxN];
int partner[maxN];
bool vc[maxN];
vector <int> G[maxN];

void solve()
{
	cin >> W;
	aho.n = 1;
	FOR(i, 0, W)
	{
		cin >> T[i];
		aho.add(T[i], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, W)
		if (!ban[i])
			aho.query(T[i], SZ(T[i]), i+1);

	FOR(k, 1, W+1) FOR(i, 1, W+1) FOR(j, 1, W+1)
		if (g[i][k] and g[k][j])
			g[i][j] = true;
	FOR(i, 1, W+1) FOR(j, 1, W+1)
		if (g[i][j])
			G[i+W].pb(j), G[j].pb(i+W);

	mtg.run(G, W, W, partner);
	cover.run(G, W, partner, vc);

	dbg(G, W*2+1);
	dbg(vc, W*2+1);

	vector <int> ans;
	FOR(i, 0, W)
		if (!ban[i] and !vc[i+1] and !vc[i+1+W])
			ans.pb(i+1);
/*
	while (true)
	{
		int s = SZ(ans);
		bool ok = true;
		FOR(i, 0, s) FOR(j, 0, s)
			while (g[ans[i]][ans[j]])
				ans[i] = partner[W+ans[i]], ok = false;
		if (ok)
			break;
	}
*/
	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 2, maxM = 10000004;

int W;
bool ban[maxN], g[800][800];
vector <int> G[maxN];

struct Aho
{
	int n, T[maxM][Alph], F[maxM], N[maxM], o[maxM], Q[maxM];
	void add(string& t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int& u = T[v][t[i] - 'a'];
			if (u == 0)	u = ++n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		int qf = 0, qb = 0;
		FOR(c, 0, Alph)
		{
			int& u = T[1][c];
			if (u == 0)	u = 1;
			else 		F[u] = 1, Q[qb++] = u;
		}
		while (qf != qb)
		{
			int v = Q[qf++];
			FOR(c, 0, Alph)
			{
				int &u = T[v][c], w = F[v];
				if (u == 0)
				{
					u = T[w][c];
					continue;
				}
				F[u] = T[w][c];
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q[qb++] = u;
			}
		}
	}
	void query(string& t, int m, int x)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			v = T[v][t[i] - 'a'];
			int u = o[v] == 0 ? N[v] : v;
			for (; u != 0; u = N[u])
			{
				int y = o[u];
				if (x == y or g[y][x])
					continue;
				G[y+W].pb(x);
				G[x].pb(y+W);
				g[y][x] = true;
			}
		}
	}
}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

struct VerCover
{
    vector <int>* G;
    int* part;
    bool* res;
    void dfs(int v)
    {
        for (int u : G[v])
            if (part[u] != 0 and !res[u])
            {	res[u] = true;	dfs(part[u]);	}
    }

    void run(vector <int>* g, int n, int* Pin, bool* Rout)
    {
        G = g, part = Pin, res = Rout;
        FOR(i, 1, n+1)	if (part[i] == 0)	dfs(i);
        FOR(i, 1, n+1)
            if (part[i] != 0 and !res[part[i]])
                res[i] = true;
    }
}cover;

string T[maxN];
int partner[maxN];
bool vc[maxN];

void solve()
{
	cin >> W;
	aho.n = 1;
	FOR(i, 0, W)
	{
		cin >> T[i];
		aho.add(T[i], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, W)
		if (!ban[i])
			aho.query(T[i], SZ(T[i]), i+1);

	mtg.run(G, W, W, partner);
	cover.run(G, W, partner, vc);

	dbg(G, W*2+1);
	dbg(vc, W*2+1);

	vector <int> ans;
	FOR(i, 0, W)
		if (!ban[i] and !vc[i+1] and !vc[i+1+W])
			ans.pb(i+1);
/*
	while (true)
	{
		int s = SZ(ans);
		bool ok = true;
		FOR(i, 0, s) FOR(j, 0, s)
			while (g[ans[i]][ans[j]])
				ans[i] = partner[W+ans[i]], ok = false;
		if (ok)
			break;
	}
*/
	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 26, maxM = 10000003;

vector <pair <int, int> > E;
bool ban[maxN];

struct Aho
{
	int n, F[maxM], N[maxM], o[maxM];
	map <int, int> T[maxM];
	int Q[maxM];

	void add(string& t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int u = T[v][t[i] - 'a'];
			if (u == 0)
				T[v][t[i] - 'a'] = u = ++n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		int qf = 0, qb = 0;
		FOR(c, 0, Alph)
		{
			int u = T[1][c];
			if (u == 0)	T[1][c] = u = 1;
			else 		F[u] = 1, Q[qb++] = u;
		}
		while (qf != qb)
		{
			int v = Q[qf++];
			FOR(c, 0, Alph)
			{
				int u = T[v][c];
				if (u == 0)
					continue;
				F[u] = F[v];
				while (T[F[u]][c] == 0)
					F[u] = F[F[u]];
				F[u] = T[F[u]][c];
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q[qb++] = u;
			}
		}
	}
	void query(string& t, int m, int x)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int c = t[i] - 'a';
			while (T[v].count(c) == 0)
				v = F[v];
			v = T[v][c];
			for (int u = v; u != 1; u = F[u])
				if (o[u] != 0)
					E.pb({o[u]-1, x});
		}
	}
	void clean(int v = 1)
	{
		FOR(c, 0, Alph)
		{
			if (T[v][c] > 1)	clean(T[v][c]);
			T[v][c] = 0;
		}
		F[v] = N[v] = o[v] = 0;	n = 1;
	}
}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

vector <int> G[maxN];
string T[maxN];
int partner[maxN];
bool g[maxN][maxN];

void solve()
{
	int n;
	cin >> n;
	aho.clean();
	FOR(i, 0, n)
	{
		cin >> T[i];
		aho.add(T[i], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, n)
		if (!ban[i])
			aho.query(T[i], SZ(T[i]), i);

	for (auto [a, b] : E)
		if (a != b)
			g[a][b] = true;

	FOR(k, 0, n) FOR(i, 0, n) FOR(j, 0, n)
		if (g[i][k] and g[k][j])
			g[i][j] = true;

	FOR(i, 1, n+1) FOR(j, 1, n+1)
		if (g[i-1][j-1])
			G[n+i].pb(j), G[j].pb(n+i);

	mtg.run(G, n, n, partner);

	vector <int> ans;
	FOR(i, 0, n)
		if (!ban[i] and partner[i+1] == 0)
			ans.pb(i+1);

	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 26, maxM = 10000003;

vector <pair <int, int> > E;
bool ban[maxN];

struct Aho
{
	int n, F[maxM], o[maxM];
	unordered_map <int, int> T[maxM];
	int Q[maxM];

	void add(string& t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int u = T[v][t[i] - 'a'];
			if (u == 0)
				T[v][t[i] - 'a'] = u = ++n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		int qf = 0, qb = 0;
		FOR(c, 0, Alph)
		{
			int u = T[1][c];
			if (u == 0)	T[1][c] = u = 1;
			else 		F[u] = 1, Q[qb++] = u;
		}
		while (qf != qb)
		{
			int v = Q[qf++];
			FOR(c, 0, Alph)
			{
				int u = T[v][c];
				if (u == 0)
					continue;
				F[u] = F[v];
				while (T[F[u]][c] == 0)
					F[u] = F[F[u]];
				F[u] = T[F[u]][c];
				//N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q[qb++] = u;
			}
		}
	}
	void query(string& t, int m, int x)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int c = t[i] - 'a';
			while (T[v].count(c) == 0)
				v = F[v];
			v = T[v][c];
			for (int u = v; u != 1; u = F[u])
				if (o[u] != 0)
					E.pb({o[u]-1, x});
		}
	}
	void clean(int v = 1)
	{
		FOR(c, 0, Alph)
		{
			if (T[v][c] > 1)	clean(T[v][c]);
			T[v][c] = 0;
		}
		F[v] = o[v] = 0;	n = 1;
	}
}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

vector <int> G[maxN];
string T[maxN];
int partner[maxN];
bool g[maxN][maxN];

void solve()
{
	int n;
	cin >> n;
	aho.clean();
	FOR(i, 0, n)
	{
		cin >> T[i];
		aho.add(T[i], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, n)
		if (!ban[i])
			aho.query(T[i], SZ(T[i]), i);

	for (auto [a, b] : E)
		if (a != b)
			g[a][b] = true;

	FOR(k, 0, n) FOR(i, 0, n) FOR(j, 0, n)
		if (g[i][k] and g[k][j])
			g[i][j] = true;

	FOR(i, 1, n+1) FOR(j, 1, n+1)
		if (g[i-1][j-1])
			G[n+i].pb(j), G[j].pb(n+i);

	mtg.run(G, n, n, partner);

	vector <int> ans;
	FOR(i, 0, n)
		if (!ban[i] and partner[i+1] == 0)
			ans.pb(i+1);

	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 2, maxM = 10008004;

int W;
bool ban[maxN], g[800][800];
vector <int> G[maxN];

struct Aho
{
	int n, T[maxM][Alph], F[maxM], N[maxM], o[maxM], Q[maxM];
	void add(char* t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int& u = T[v][t[i] - 'a'];
			if (u == 0)	u = ++n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		int qf = 0, qb = 0;
		FOR(c, 0, Alph)
		{
			int& u = T[1][c];
			if (u == 0)	u = 1;
			else 		F[u] = 1, Q[qb++] = u;
		}
		while (qf != qb)
		{
			int v = Q[qf++];
			FOR(c, 0, Alph)
			{
				int &u = T[v][c], w = F[v];
				if (u == 0)
				{
					u = T[w][c];
					continue;
				}
				F[u] = T[w][c];
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q[qb++] = u;
			}
		}
	}
	void query(char* t, int m, int x)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			v = T[v][t[i] - 'a'];
			int u = o[v] == 0 ? N[v] : v;
			for (; u != 0; u = N[u])
			{
				int y = o[u];
				if (x == y)
					continue;
				G[y+W].pb(x);
				G[x].pb(y+W);
				g[y][x] = true;
			}
		}
	}
}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

char mem[maxM], *in = mem;
int partner[maxN];
vector <char*> T;
int len[maxN];

void solve()
{
	cin >> W;
	aho.n = 1;
	FOR(i, 0, W)
	{
		scanf ("%s", in);
		T.pb(in);
		len[i] = strlen(in);
		in += len[i]+1;
		aho.add(T[i], len[i], i);
	}
	aho.calcF();
	FOR(i, 0, W)
		if (!ban[i])
			aho.query(T[i], len[i], i+1);

	mtg.run(G, W, W, partner);

	vector <int> ans;
	FOR(i, 0, W)
		if (!ban[i] and partner[i+1] == 0)
			ans.pb(i+1);

	dbg(ans);
	dbg(W);
	dbg(G, W+1);

	while (true)
	{
		int s = SZ(ans);
		bool ok = true;
		FOR(i, 0, s) FOR(j, 0, s)
			if (g[ans[i]][ans[j]])
				ans[i] = partner[W+ans[i]], ok = false;
		if (ok)
			break;
	}

	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 2, maxM = 10000004;

int W;
bool ban[maxN], g[800][800];
vector <int> G[maxN];

struct Aho
{
	int n, T[maxM][Alph], F[maxM], N[maxM], o[maxM], Q[maxM];
	void add(char* t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int& u = T[v][t[i] - 'a'];
			if (u == 0)	u = ++n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		int qf = 0, qb = 0;
		FOR(c, 0, Alph)
		{
			int& u = T[1][c];
			if (u == 0)	u = 1;
			else 		F[u] = 1, Q[qb++] = u;
		}
		while (qf != qb)
		{
			int v = Q[qf++];
			FOR(c, 0, Alph)
			{
				int &u = T[v][c], w = F[v];
				if (u == 0)
				{
					u = T[w][c];
					continue;
				}
				F[u] = T[w][c];
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q[qb++] = u;
			}
		}
	}
	void query(char* t, int m, int x)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			v = T[v][t[i] - 'a'];
			int u = o[v] == 0 ? N[v] : v;
			for (; u != 0; u = N[u])
			{
				int y = o[u];
				if (x == y)
					continue;
				G[y+W].pb(x);
				G[x].pb(y+W);
				g[y][x] = true;
			}
		}
	}
}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

string T[maxN];
int partner[maxN];

void solve()
{
	cin >> W;
	aho.n = 1;
	FOR(i, 0, W)
	{
		cin >> T[i];
		aho.add(&T[i][0], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, W)
		if (!ban[i])
			aho.query(&T[i][0], SZ(T[i]), i+1);

	mtg.run(G, W, W, partner);

	vector <int> ans;
	FOR(i, 0, W)
		if (!ban[i] and partner[i+1] == 0)
			ans.pb(i+1);

	dbg(ans);
	dbg(W);
	dbg(G, W+1);

	while (true)
	{
		int s = SZ(ans);
		bool ok = true;
		FOR(i, 0, s) FOR(j, 0, s)
			if (g[ans[i]][ans[j]])
				ans[i] = partner[W+ans[i]], ok = false;
		if (ok)
			break;
	}

	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 11, Alph = 2, maxM = 10000004;

int W;
bool ban[maxN], g[800][800];

struct Aho
{
	int n, T[maxM][Alph], F[maxM], N[maxM], o[maxM], Q[maxM], vis[maxM], visCtr;
	void add(string& t, int m, int ind)
	{
		int v = 1;
		FOR(i, 0, m)
		{
			int& u = T[v][t[i] - 'a'];
			if (u == 0)	u = ++n;
			v = u;
		}

		if (o[v] != 0)
			ban[o[v] - 1] = true;

		o[v] = ind + 1;
	}
	void calcF()
	{
		F[1] = 1;
		int qf = 0, qb = 0;
		FOR(c, 0, Alph)
		{
			int& u = T[1][c];
			if (u == 0)	u = 1;
			else 		F[u] = 1, Q[qb++] = u;
		}
		while (qf != qb)
		{
			int v = Q[qf++];
			FOR(c, 0, Alph)
			{
				int &u = T[v][c], w = F[v];
				if (u == 0)
				{
					u = T[w][c];
					continue;
				}
				F[u] = T[w][c];
				N[u] = o[F[u]] == 0 ? N[F[u]] : F[u];
				Q[qb++] = u;
			}
		}
	}
	void query(string& t, int m, int x)
	{
		vis[0] = vis[1] = ++visCtr;
		int v = 1;
		FOR(i, 0, m)
		{
			v = T[v][t[i] - 'a'];
			int u = o[v] == 0 ? N[v] : v;
			for (; vis[u]!=visCtr; u=N[u])
			{
				int y = o[u];
				if (x != y and y != 0)
					g[y][x] = true;
				vis[u] = visCtr;
			}
		}
	}
}aho;

struct Matching
{
    int *part, n, m, visctr, ser, dist[maxN], vis[maxN];
    int qb, Q[maxN];
    vector <int>* G;
	void ins(int v, int d)
	{
		dist[v] = d; vis[v] = visctr;
		if (d <= ser)	Q[qb++] = v;
	}
    bool bfs()
    {
        visctr++;
        ser = n + m; qb = 0;
        FOR(i, 1, n+1) if (part[i] == 0) ins(i, 0);
        for (int qf = 0; qf != qb; qf++)
        {
            int v = Q[qf];
            for (int w : G[v])
            {
                int u = part[w];
                if (vis[u] == visctr)	continue;
                if (u == 0)
                {	ser = min(ser, dist[v]+1);	continue;	}
				ins(u, dist[v] + 2);
            }
        }
        visctr++;	return ser != n + m;
    }
    void match(int a, int b)	{	part[a] = b, part[b] = a;	}
    bool dfs(int v)
    {
        vis[v] = visctr;
        if (dist[v] > ser)	return false;
        for (int w : G[v])
        {
            int u = part[w];
            if (u == 0 or
            (vis[u] != visctr and dist[u] == dist[v] + 2 and dfs(u)))
            {	match(w, v); return true;	}
        }
        return false;
    }
    int run(vector <int>* Gin, int nn, int mm, int* partout)
    {
        G = Gin; n = nn; m = mm; part = partout;
        while (bfs())  FOR(i, 1, n+1)
			if (part[i] == 0) dfs(i);
        int res = 0;
        FOR(i, 1, n+1)	res += part[i] != 0;
        return res;
    }
}mtg;

struct VerCover
{
    vector <int>* G;
    int* part;
    bool* res;
    void dfs(int v)
    {
        for (int u : G[v])
            if (part[u] != 0 and !res[u])
            {	res[u] = true;	dfs(part[u]);	}
    }

    void run(vector <int>* g, int n, int* Pin, bool* Rout)
    {
        G = g, part = Pin, res = Rout;
        FOR(i, 1, n+1)	if (part[i] == 0)	dfs(i);
        FOR(i, 1, n+1)
            if (part[i] != 0 and !res[part[i]])
                res[i] = true;
    }
}cover;

string T[maxN];
int partner[maxN];
bool vc[maxN];
vector <int> G[maxN];

void solve()
{
	cin >> W;
	aho.n = 1;
	FOR(i, 0, W)
	{
		cin >> T[i];
		aho.add(T[i], SZ(T[i]), i);
	}
	aho.calcF();
	FOR(i, 0, W)
		if (!ban[i])
			aho.query(T[i], SZ(T[i]), i+1);

	FOR(k, 1, W+1) FOR(i, 1, W+1) FOR(j, 1, W+1)
		if (g[i][k] and g[k][j])
			g[i][j] = true;
	FOR(i, 1, W+1) FOR(j, 1, W+1)
		if (g[i][j])
			G[i+W].pb(j), G[j].pb(i+W);

	mtg.run(G, W, W, partner);
	//cover.run(G, W, partner, vc);

	dbg(G, W*2+1);
	dbg(vc, W*2+1);

	vector <int> ans;
	FOR(i, 0, W)
		if (!ban[i] and partner[i+1] == 0)// and !vc[i+1] and !vc[i+1+W])
			ans.pb(i+1);

	while (true)
	{
		int s = SZ(ans);
		bool ok = true;
		FOR(i, 0, s) FOR(j, 0, s)
			while (g[ans[i]][ans[j]])
				ans[i] = partner[W+ans[i]], ok = false;
		if (ok)
			break;
	}

	cout << SZ(ans) << "\n";
	for (int v : ans)
		cout <<  v << " ";
	cout << "\n";
}

int main()
{
	ios_base::sync_with_stdio(false);
	int t = 1;
	//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
// #define TRACE
#ifdef TRACE
#include "../trace.h"
#else
#define trace(args...)
#endif
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
typedef vector<pll> vpl;	typedef vector<pii> vpi;
typedef vector<vpl> vvpl;	typedef vector<vpi> vvpi;
#define S second
#define F first
#define V vector
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define sz(x) (int)x.size()
#define f(i,j,k,l) for(int i =(int)j; i!=(int)k; i = i + l)
#define INP(v,n) f(i,0,n,1) cin>>v[i];
#define OUT(v,n) f(i,0,n,1){ cout<<v[i]<<" ";}cout<<endl;
#define endl '\n'
#define all(v) v.begin(), v.end()
const ll mod = 998244353;
const int inf = 1e9;
bool vis[1700];
int in[760];
bool adj[760][760];
bool trans[760][760];
bool rep[760];
int tot = 0;

int fin(int i){
	if(in[i] != i){
		in[i] = fin(in[i]);
	}
	return in[i];
}

struct edkarp{
	vector<vector<int>> cap;
	vector<vector<int>> eds;
	int n,m;
	void init(int _n){
		n = _n;
		m = (n-2)/2;
		cap.assign(n,vector<int>(n,0));
		eds.assign(n,vector<int>(0));
	}

	void add(int u, int v, int c){
		eds[u].emplace_back(v);
		eds[v].emplace_back(u);
		cap[u][v] = c;
	}
	int bfs(int st, int tar, vector<int> &p){//p must already be of req. size
		fill(p.begin(), p.end(), -1);
		p[st] = -2;
		queue<pair<int,int>> q;
		q.push(MP(st,inf));
		while(!q.empty()){
			int i = q.front().F, flow = q.front().S;
			q.pop();
			for(auto &x : eds[i]){
				if(p[x] == -1 && cap[i][x]){
					p[x] = i;
					int nf = min(flow, cap[i][x]);
					if(x == tar){
						return nf;
					}
					q.push(MP(x, nf));
				}
			}
		}
		return 0;
	}

	int maxflow(int st, int tar){
		// if there is need to upgrade number of nodes in graph
		vector<int> p(n);//num is the number of nodes
		int flow = 0;
		int nf;//new flow

		while(nf = bfs(st,tar,p)){
			flow += nf;
			int cr = tar;
			while(cr != st){
				cap[p[cr]][cr] -= nf;
				cap[cr][p[cr]] += nf;
				cr = p[cr];
			}
		}

		return flow;
	}

	void dfs(int i){
		trace(i);
		vis[i] = 1;
		for(auto &x : eds[i])if(!vis[x] && x != 0 && x != n-1){
			dfs(x);
		}
	}
	void sten(){
		fill(vis,vis + n,false);
		for(int i = 1; i <=m ;i++){
			for(int j = 1; j<= m; j++){
				if(cap[j+m][i]){
					in[i] = 1;
					break;
				}
			}
		}
		for(int i =1; i<=m; i++){
			if(in[i] == 0 && !vis[i]) dfs(i);
		}
	}
};

const int K = 2;//alphabet size
struct node {
	node* ch[K];
	node* p;
	node* nt;//next terminal
	node* sl;
	int ind = -1;
	bool pch; //suffix_link
	node(node* p = NULL, bool b = false): p(p), pch(b) {
		sl = NULL; ch[0] = NULL; ch[1] = NULL;
		nt = NULL;
	}
};

template<class node>
struct ahoc {
	node* root = NULL;
	edkarp fl;
	ahoc() {
		root = new node();
	}
	void init(int n){
		fl.init(n);
	}
	inline int getin(char c) { //modify accordingly
		return c - 'a';
	}
	void ins(string const& s, int i) {
		node* cr = root;
		for (char c : s) {
			int z = getin(c);
			if (!cr->ch[z]) {
				cr->ch[z] = new node(cr, c == 'b');
			}
			cr = cr->ch[z];
		}
		if(cr->ind == -1) cr->ind = i;
		else rep[i] = 1, tot++;
	}

	void trav(string const& s, int i) {
		node* cr = root;
		for (char c : s) {
			if(cr->ind != -1){
				adj[cr->ind][i] =trans[cr->ind][i] = true;
			}
			int z = getin(c);
			cr = cr->ch[z];
			node* tmp = get_nt(cr);
			if(tmp != root) adj[tmp->ind][i] =trans[tmp->ind][i] = true;
		}
	}

	node* get_sl(node* cr) {
		if (!cr->sl) {
			if (cr == root || cr->p == root)
				cr->sl = root;
			else
				cr->sl = go(get_sl(cr->p), cr->pch);
		}
		return cr->sl;
	}

	node* go(node* cr, bool c) {
		int z = c;
		if (!cr->ch[z]) {
			if (cr == root)
				cr->ch[z] = root;
			else
				cr->ch[z] = go(get_sl(cr), c);
		}
		return cr->ch[z];
	}

	node* get_nt(node* cr) {
		if (!cr->nt) {
			node* tmp = get_sl(cr);
			if (tmp == root) {
				cr->nt = root;
			} else if (tmp->ind == -1) {
				cr->nt = get_nt(tmp);
			} else {
				cr->nt = tmp;
			}
		}
		return cr->nt;
	}
};

string s[760];
int n;
ahoc<node> fo;

void dfs(int i){
	vis[i] = 1;
	f(j,1,n+1,1){
		if(j == i) continue;
		if(!trans[i][j]) continue;
		if(!vis[j]) dfs(j);
		f(k,1,n+1,1){
			if(k == i || k == j) continue;
			if(!trans[j][k]) continue;
			trans[i][k] = 1;
		}
	}
}

void solve() {
	cin >> n;
	f(i, 1, n + 1, 1) {
		cin >> s[i];
	}
	f(i, 1, n + 1, 1) {
		fo.ins(s[i], i);
	}
	fo.init(2*n+2);
	f(i, 1, n + 1, 1) {
		fo.trav(s[i], i);
		fo.fl.add(0,i,1);
		fo.fl.add(n+i,2*n+1,1);
	}
	for(int i = 1; i <= n; i++){
		if(!vis[i]) dfs(i);
	}
	f(i,1,n+1,1){
		f(j,1,n+1,1){
			if(i == j) continue;
			if(trans[i][j]){
				fo.fl.add(i,j+n,1);
			}
		}
	}
	// f(i,1,n+1,1){
	// 	f(j,1,n+1,1){
	// 		cout<<int(adj[i][j])<<" ";
	// 	}cout<<endl;
	// }
	// cout<<endl;
	// f(i,1,n+1,1){
	// 	f(j,1,n+1,1){
	// 		cout<<int(trans[i][j])<<" ";
	// 	}cout<<endl;
	// }cout<<endl;
	cout<<n - tot- fo.fl.maxflow(0,2*n+1)<<endl;
	fo.fl.sten();
	for(int i = 1; i<= n; i++){
		if(vis[i] && !vis[i+n] && !rep[i]) cout<<i<<" ";
	}cout<<endl;
}

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	//cin>>t;
	while (t--) {
		solve();
	}
}


/* AUTHOR - SHASHANK AGRAWAL (codeforces - @shashanka136) ( codechef - @shashank_vasu) */
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
// #define TRACE
#ifdef TRACE
#include "../trace.h"
#else
#define trace(args...)
#endif
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
typedef vector<pll> vpl;	typedef vector<pii> vpi;
typedef vector<vpl> vvpl;	typedef vector<vpi> vvpi;
#define S second
#define F first
#define V vector
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define sz(x) (int)x.size()
#define f(i,j,k,l) for(int i =(int)j; i!=(int)k; i = i + l)
#define INP(v,n) f(i,0,n,1) cin>>v[i];
#define OUT(v,n) f(i,0,n,1){ cout<<v[i]<<" ";}cout<<endl;
#define endl '\n'
#define all(v) v.begin(), v.end()
const ll mod = 998244353;
#define M 1
const int K = 2;//alphabet size
struct item {
	int *nx[K];
	int *ind = NULL;
	bitset<M> tol = 0;
	bitset<M> tc = 0;
	bitset<M> pch;//tell if current node go to leaf or not
	//node itself is not considered
	int *p = NULL; int *sl = NULL; //suffix_link
	item(int pc = -1, char ch = 'a'){
		if(ch == 'a') pch.reset();
		else pch.set();
		if(pc != -1) p = new int(pc);
		nx[0] = NULL; nx[1] = NULL;
		// fill(begin(go), end(go), NULL);
	}
};

template<class node>
struct ahoc {
	vector<node> t;

	ahoc() {
		t.resize(1);
	}
	inline int getin(char c) { //modify accordingly
		return c - 'a';
	}
	int ins(string const& s, int i) {
		int v = 0;
		for (char c : s) {
			int z = getin(c);
			// trace(z,v);;
			if (t[v].nx[z] == NULL) {
				t[v].nx[z] = new int(t.size());
				t.emplace_back(node(v, c));
			}
			// trace(v, sz(t));
			v = *(t[v].nx[z]);
		}
		t[v].ind = new int(i);
		return v;
	}

	int get_sl(int v) {
		if (t[v].sl == NULL) {
			if (v == 0 || *(t[v].p) == 0)
				t[v].sl = new int(0);
			else
				t[v].sl = new int(go(get_sl(*(t[v].p)), t[v].pch));
		}
		return *(t[v].sl);
	}

	int go(int v, bitset<M> b) {
		int z = b[0];
		if (t[v].nx[z] == NULL) {
			if (v == 0)
				t[v].nx[z] = new int(0);
			else
				t[v].nx[z] = new int(go(get_sl(v), b));
		}
		return *(t[v].nx[z]);
	}

	bitset<M> get_tol(int v) {
		if (!t[v].tc.test(0)) {
			if (v == 0 || *(t[v].p) == 0)
				t[v].tol = 0;
			else{
				t[v].tol = get_tol(*(t[v].p)) | get_tol(get_sl(v)) ;
				if((t[get_sl(v)].ind != NULL) || (t[*(t[v].p)].ind != NULL))
					t[v].tol.set();
			}
			t[v].tc.set();
		}
		// trace(v,t[v].p,t[v].tol,t[v].sl);
		return t[v].tol;
	}
};

int n;
string s;
ahoc<item> fo;

void solve() {
	cin >> n;
	set<int> st;
	f(i, 1, n + 1, 1) {
		cin >> s;
		st.insert(fo.ins(s, i));
	}
	vi ans;
	for (int x : st) {
		// trace(x);
		if(!(fo.get_tol(x).test(0))) {
			ans.EB(*(fo.t[x].ind));
		}
	}
	cout << sz(ans) << endl;
	OUT(ans, sz(ans));
}

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	//cin>>t;
	while (t--) {
		solve();
	}
}


/* AUTHOR - SHASHANK AGRAWAL (codeforces - @shashanka136) ( codechef - @shashank_vasu) */
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
// #define TRACE
#ifdef TRACE
#include "../trace.h"
#else
#define trace(args...)
#endif
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
typedef vector<pll> vpl;	typedef vector<pii> vpi;
typedef vector<vpl> vvpl;	typedef vector<vpi> vvpi;
#define S second
#define F first
#define V vector
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define sz(x) (int)x.size()
#define f(i,j,k,l) for(int i =(int)j; i!=(int)k; i = i + l)
#define INP(v,n) f(i,0,n,1) cin>>v[i];
#define OUT(v,n) f(i,0,n,1){ cout<<v[i]<<" ";}cout<<endl;
#define endl '\n'
#define all(v) v.begin(), v.end()
const ll mod = 998244353;
const int inf = 1e9;
set<int> start, en;
bool vis[1700];
int ps[760], in[760];
bool adj[760][760];
bool trans[760][760];
bool rep[760];
int tot = 0;

int fin(int i){
	if(in[i] != i){
		in[i] = fin(in[i]);
	}
	return in[i];
}

struct edkarp{
	vector<vector<int>> cap;
	vector<vector<int>> eds;
	int n,m;
	void init(int _n){
		n = _n;
		m = (n-2)/2;
		cap.assign(n,vector<int>(n,0));
		eds.assign(n,vector<int>(0));
	}

	void add(int u, int v, int c){
		eds[u].emplace_back(v);
		eds[v].emplace_back(u);
		cap[u][v] = c;
	}
	int bfs(int st, int tar, vector<int> &p){//p must already be of req. size
		fill(p.begin(), p.end(), -1);
		p[st] = -2;
		queue<pair<int,int>> q;
		q.push(MP(st,inf));
		while(!q.empty()){
			int i = q.front().F, flow = q.front().S;
			q.pop();
			for(auto &x : eds[i]){
				if(p[x] == -1 && cap[i][x]){
					p[x] = i;
					int nf = min(flow, cap[i][x]);
					if(x == tar){
						return nf;
					}
					q.push(MP(x, nf));
				}
			}
		}
		return 0;
	}

	int maxflow(int st, int tar){
		// if there is need to upgrade number of nodes in graph
		vector<int> p(n);//num is the number of nodes
		int flow = 0;
		int nf;//new flow

		while(nf = bfs(st,tar,p)){
			flow += nf;
			int cr = tar;
			while(cr != st){
				cap[p[cr]][cr] -= nf;
				cap[cr][p[cr]] += nf;
				cr = p[cr];
			}
		}

		return flow;
	}

	void dfs(int i){
		trace(i);
		vis[i] = 1;
		for(auto &x : eds[i])if(!vis[x] && x != 0 && x != n-1){
			dfs(x);
		}
	}
	void sten(){
		fill(vis,vis + n,false);
		for(int i = 1; i <=m ;i++){
			for(int j = 1; j<= m; j++){
				if(cap[j+m][i]){
					in[i] = 1;
					break;
				}
			}
		}
		for(int i =1; i<=m; i++){
			if(in[i] == 0 && !vis[i]) dfs(i);
		}
	}
};

const int K = 2;//alphabet size
struct node {
	node* ch[K];
	node* p;
	node* nt;//next terminal
	node* sl;
	int ind = -1;
	bool pch; //suffix_link
	node(node* p = NULL, bool b = false): p(p), pch(b) {
		sl = NULL; ch[0] = NULL; ch[1] = NULL;
		nt = NULL;
	}
};

template<class node>
struct ahoc {
	node* root = NULL;
	edkarp fl;
	ahoc() {
		root = new node();
	}
	void init(int n){
		fl.init(n);
	}
	inline int getin(char c) { //modify accordingly
		return c - 'a';
	}
	void ins(string const& s, int i) {
		node* cr = root;
		for (char c : s) {
			int z = getin(c);
			if (!cr->ch[z]) {
				cr->ch[z] = new node(cr, c == 'b');
			}
			cr = cr->ch[z];
		}
		if(cr->ind == -1) cr->ind = i;
		else rep[i] = 1, tot++;
	}

	void trav(string const& s, int i) {
		node* cr = root;
		for (char c : s) {
			if(cr->ind != -1){
				adj[cr->ind][i] =trans[cr->ind][i] = true;
			}
			int z = getin(c);
			cr = cr->ch[z];
			node* tmp = get_nt(cr);
			if(tmp != root) adj[tmp->ind][i] =trans[tmp->ind][i] = true;
		}
	}

	node* get_sl(node* cr) {
		if (!cr->sl) {
			if (cr == root || cr->p == root)
				cr->sl = root;
			else
				cr->sl = go(get_sl(cr->p), cr->pch);
		}
		return cr->sl;
	}

	node* go(node* cr, bool c) {
		int z = c;
		if (!cr->ch[z]) {
			if (cr == root)
				cr->ch[z] = root;
			else
				cr->ch[z] = go(get_sl(cr), c);
		}
		return cr->ch[z];
	}

	node* get_nt(node* cr) {
		if (!cr->nt) {
			node* tmp = get_sl(cr);
			if (tmp == root) {
				cr->nt = root;
			} else if (tmp->ind == -1) {
				cr->nt = get_nt(tmp);
			} else {
				cr->nt = tmp;
			}
		}
		return cr->nt;
	}
};

string s[760];
int n;
ahoc<node> fo;

void dfs(int i){
	vis[i] = 1;
	f(j,1,n+1,1){
		if(j == i) continue;
		if(!trans[i][j]) continue;
		if(!vis[j]) dfs(j);
		f(k,1,n+1,1){
			if(k == i || k == j) continue;
			if(!trans[j][k]) continue;
			trans[i][k] = 1;
		}
	}
}

void solve() {
	cin >> n;
	f(i, 1, n + 1, 1) {
		cin >> s[i];
	}
	f(i, 1, n + 1, 1) {
		fo.ins(s[i], i);
	}
	fo.init(2*n+2);
	f(i, 1, n + 1, 1) {
		fo.trav(s[i], i);
		fo.fl.add(0,i,1);
		fo.fl.add(n+i,2*n+1,1);
	}
	for(int i = 1; i <= n; i++){
		if(!vis[i]) dfs(i);
	}
	f(i,1,n+1,1){
		f(j,1,n+1,1){
			if(i == j) continue;
			if(trans[i][j]){
				fo.fl.add(i,j+n,1);
			}
		}
	}
	// f(i,1,n+1,1){
	// 	f(j,1,n+1,1){
	// 		cout<<int(adj[i][j])<<" ";
	// 	}cout<<endl;
	// }
	// cout<<endl;
	// f(i,1,n+1,1){
	// 	f(j,1,n+1,1){
	// 		cout<<int(trans[i][j])<<" ";
	// 	}cout<<endl;
	// }cout<<endl;
	cout<<n - tot- fo.fl.maxflow(0,2*n+1)<<endl;
	fo.fl.sten();
	for(int i = 1; i<= n; i++){
		if(vis[i] && !vis[i+n] && !rep[i]) cout<<i<<" ";
	}cout<<endl;
}

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	//cin>>t;
	while (t--) {
		solve();
	}
}


#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "trace.h"
#else
#define trace(args...)
#endif

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
const int K = 2;
struct Vertex {
    Vertex *nxt[K], *par, *link;
    char pch = '$';
    int id, tol;
    Vertex(Vertex* par = NULL, char ch = '$') : par(par), pch(ch) {
        for (int i = 0; i < K; i++) {
            nxt[i] = NULL;
        }
        id = tol = -1;
    }
};
template <class node>
struct suffix_trie {
    node* root;
    suffix_trie() {
        root = new node();
    }
    node* add_string(string const& s, int i) {
        node* v = root;
        for (char ch : s) {
            int c = ch - 'a';
            if (v->nxt[c] == NULL)
                v->nxt[c] = new node(v, ch);
            v = v->nxt[c];
        }
        v->id = i;
        return v;
    }
    node* get_link(node* v) {
        if (v->link != NULL) return v->link;
        if (v == root || v->par == root)
            v->link = root;
        else
            v->link = go(get_link(v->par), v->pch);
        return v->link;
    }
    node* go(node* v, char ch) {
        int c = ch - 'a';
        if (v->nxt[c] != NULL) return v->nxt[c];
        if (v == root)
            v->nxt[c] = root;
        else
            v->nxt[c] = go(get_link(v), ch);
        return v->nxt[c];
    }
    int get_tol(node* v) {
        if (v->tol != -1) return v->tol;
        v->tol = 0;
        if (v != root && v->par != root) {
            v->tol = get_tol(v->par) | get_tol(get_link(v));
            v->tol |= (get_link(v)->id != -1) | ((v->par)->id != -1);
        }
        return v->tol;
    }
};
suffix_trie<Vertex> t;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    set<int> ans;
    vector<Vertex*> vec;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        vec.pb(t.add_string(s, i));
    }
    for (auto v : vec) {
        if (!t.get_tol(v))
            ans.insert(v->id);
    }
    cout << ans.size() << '\n';
    for (int i : ans) cout << i + 1 << ' ';
    cout << '\n';
}


/* AUTHOR - SHASHANK AGRAWAL (codeforces - @shashanka136) ( codechef - @shashank_vasu) */
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
// #define TRACE
#ifdef TRACE
#include "../trace.h"
#else
#define trace(args...)
#endif
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
typedef vector<pll> vpl;	typedef vector<pii> vpi;
typedef vector<vpl> vvpl;	typedef vector<vpi> vvpi;
#define S second
#define F first
#define V vector
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define sz(x) (int)x.size()
#define f(i,j,k,l) for(int i =(int)j; i!=(int)k; i = i + l)
#define INP(v,n) f(i,0,n,1) cin>>v[i];
#define OUT(v,n) f(i,0,n,1){ cout<<v[i]<<" ";}cout<<endl;
#define endl '\n'
#define all(v) v.begin(), v.end()
const ll mod = 998244353;
const int inf = 1e9;
set<int> start, en;
bool vis[760];
int ps[760], in[760];
bool adj[760][760];
bool trans[760][760];
bool rep[760];

int fin(int i){
	if(in[i] != i){
		in[i] = fin(in[i]);
	}
	return in[i];
}

struct edkarp{
	vector<vector<int>> cap;
	vector<vector<int>> eds;
	int n,m;
	void init(int _n){
		n = _n;
		m = (n-2)/2;
		cap.assign(n,vector<int>(n,0));
		eds.assign(n,vector<int>(0));
	}

	void add(int u, int v, int c){
		eds[u].emplace_back(v);
		eds[v].emplace_back(u);
		cap[u][v] = c;
	}
	int bfs(int st, int tar, vector<int> &p){//p must already be of req. size
		fill(p.begin(), p.end(), -1);
		p[st] = -2;
		queue<pair<int,int>> q;
		q.push(MP(st,inf));
		while(!q.empty()){
			int i = q.front().F, flow = q.front().S;
			q.pop();
			for(auto &x : eds[i]){
				if(p[x] == -1 && cap[i][x]){
					p[x] = i;
					int nf = min(flow, cap[i][x]);
					if(x == tar){
						return nf;
					}
					q.push(MP(x, nf));
				}
			}
		}
		return 0;
	}

	int maxflow(int st, int tar){
		// if there is need to upgrade number of nodes in graph
		vector<int> p(n);//num is the number of nodes
		int flow = 0;
		int nf;//new flow

		while(nf = bfs(st,tar,p)){
			flow += nf;
			int cr = tar;
			while(cr != st){
				cap[p[cr]][cr] -= nf;
				cap[cr][p[cr]] += nf;
				cr = p[cr];
			}
		}

		return flow;
	}

	void reach(int st, int tar, vector<int> &p){
		fill(p.begin(), p.end(), -1);
		p[st] = -2;
		queue<int> q;
		q.push(st);
		while(!q.empty()){
			int i = q.front();
			q.pop();
			f(j,1,m+1,1){
				if(p[j] == -1 && adj[i][j]){
					p[j] = i;
					if(j== tar){
						return;
					}
					q.push(j);
				}
			}
		}
		return;
	}

	void sten(){
		for(int i = 1; i <=m ;i++){
			for(int j = 1; j<= m; j++){
				if(cap[j+m][i]){
					vector<int> p(m+1);
					reach(i,j,p);
					in[i] = 1;
					break;
					// if(start.find(j) != start.end()){
					// 	start.erase(j);
					// }else{
					// 	en.insert(j);
					// }
					// trace(i,j);
					// int cr = j;
					// while(cr != i){
					// 	ps[cr]++;
					// 	in[cr] = fin(i);
					// 	cr = p[cr];
					// }
					// in[cr] = fin(i);
					// ps[cr]++;
				}
			}
		}
	}
};

const int K = 2;//alphabet size
struct node {
	node* ch[K];
	node* p;
	node* nt;//next terminal
	node* sl;
	int ind = -1;
	bool pch; //suffix_link
	node(node* p = NULL, bool b = false): p(p), pch(b) {
		sl = NULL; ch[0] = NULL; ch[1] = NULL;
		nt = NULL;
	}
};

template<class node>
struct ahoc {
	node* root = NULL;
	edkarp fl;
	ahoc() {
		root = new node();
	}
	void init(int n){
		fl.init(n);
	}
	inline int getin(char c) { //modify accordingly
		return c - 'a';
	}
	void ins(string const& s, int i) {
		node* cr = root;
		for (char c : s) {
			int z = getin(c);
			if (!cr->ch[z]) {
				cr->ch[z] = new node(cr, c == 'b');
			}
			cr = cr->ch[z];
		}
		if(cr->ind == -1) cr->ind = i;
		else rep[i] = 1;
	}

	void trav(string const& s, int i) {
		node* cr = root;
		for (char c : s) {
			if(cr->ind != -1){
				adj[cr->ind][i] =trans[cr->ind][i] = true;
			}
			int z = getin(c);
			cr = cr->ch[z];
			node* tmp = get_nt(cr);
			if(tmp != root) adj[tmp->ind][i] =trans[tmp->ind][i] = true;
		}
	}

	node* get_sl(node* cr) {
		if (!cr->sl) {
			if (cr == root || cr->p == root)
				cr->sl = root;
			else
				cr->sl = go(get_sl(cr->p), cr->pch);
		}
		return cr->sl;
	}

	node* go(node* cr, bool c) {
		int z = c;
		if (!cr->ch[z]) {
			if (cr == root)
				cr->ch[z] = root;
			else
				cr->ch[z] = go(get_sl(cr), c);
		}
		return cr->ch[z];
	}

	node* get_nt(node* cr) {
		if (!cr->nt) {
			node* tmp = get_sl(cr);
			if (tmp == root) {
				cr->nt = root;
			} else if (tmp->ind == -1) {
				cr->nt = get_nt(tmp);
			} else {
				cr->nt = tmp;
			}
		}
		return cr->nt;
	}
};

string s[760];
int n;
ahoc<node> fo;

void dfs(int i){
	vis[i] = 1;
	f(j,1,n+1,1){
		if(j == i) continue;
		if(!trans[i][j]) continue;
		if(!vis[j]) dfs(j);
		f(k,1,n+1,1){
			if(k == i || k == j) continue;
			if(!trans[j][k]) continue;
			trans[i][k] = 1;
		}
	}
}

void solve() {
	cin >> n;
	f(i, 1, n + 1, 1) {
		cin >> s[i];
	}
	f(i, 1, n + 1, 1) {
		fo.ins(s[i], i);
	}
	fo.init(2*n+2);
	f(i, 1, n + 1, 1) {
		fo.trav(s[i], i);
		fo.fl.add(0,i,1);
		fo.fl.add(n+i,2*n+1,1);
	}
	for(int i = 1; i <= n; i++){
		if(!vis[i]) dfs(i);
	}
	f(i,1,n+1,1){
		f(j,1,n+1,1){
			if(i == j) continue;
			if(trans[i][j]){
				fo.fl.add(i,j+n,1);
			}
		}
	}
	// f(i,1,n+1,1){
	// 	f(j,1,n+1,1){
	// 		cout<<int(adj[i][j])<<" ";
	// 	}cout<<endl;
	// }
	// cout<<endl;
	// f(i,1,n+1,1){
	// 	f(j,1,n+1,1){
	// 		cout<<int(trans[i][j])<<" ";
	// 	}cout<<endl;
	// }cout<<endl;
	cout<<n - fo.fl.maxflow(0,2*n+1)<<endl;
	fo.fl.sten();
	fill(vis,vis+n+1,false);
	f(i,1,n+1,1){
		if(!in[i] && !rep[i]) cout<<i<<" ";
	}cout<<endl;
	// f(i,1,n+1,1){
	// 	if(ps[i] == 0 && !rep[i]) cout<<i<<" ";
	// 	if(!vis[fin(i)] && ps[fin(i)] == 1){
	// 		cout<<fin(i)<<" ";
	// 		vis[fin(i)] = 1;
	// 	}
	// }
	// cout<<endl;
	// for(int x : start){
	// 	cout<<x<<" ";
	// }cout<<endl;
}

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	//cin>>t;
	while (t--) {
		solve();
	}
}


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
// #define TRACE
#ifdef TRACE
#include "../trace.h"
#else
#define trace(args...)
#endif
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
typedef vector<pll> vpl;	typedef vector<pii> vpi;
typedef vector<vpl> vvpl;	typedef vector<vpi> vvpi;
#define S second
#define F first
#define V vector
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define sz(x) (int)x.size()
#define f(i,j,k,l) for(int i =(int)j; i!=(int)k; i = i + l)
#define INP(v,n) f(i,0,n,1) cin>>v[i];
#define OUT(v,n) f(i,0,n,1){ cout<<v[i]<<" ";}cout<<endl;
#define endl '\n'
#define all(v) v.begin(), v.end()
const ll mod = 998244353;
const int inf = 1e9;
set<int> start, en;
bool vis[1700];
int ps[760], in[760];
bool adj[760][760];
bool trans[760][760];
bool rep[760];
int tot = 0;

int fin(int i){
	if(in[i] != i){
		in[i] = fin(in[i]);
	}
	return in[i];
}

struct edkarp{
	vector<vector<int>> cap;
	vector<vector<int>> eds;
	int n,m;
	void init(int _n){
		n = _n;
		m = (n-2)/2;
		cap.assign(n,vector<int>(n,0));
		eds.assign(n,vector<int>(0));
	}

	void add(int u, int v, int c){
		eds[u].emplace_back(v);
		eds[v].emplace_back(u);
		cap[u][v] = c;
	}
	int bfs(int st, int tar, vector<int> &p){//p must already be of req. size
		fill(p.begin(), p.end(), -1);
		p[st] = -2;
		queue<pair<int,int>> q;
		q.push(MP(st,inf));
		while(!q.empty()){
			int i = q.front().F, flow = q.front().S;
			q.pop();
			for(auto &x : eds[i]){
				if(p[x] == -1 && cap[i][x]){
					p[x] = i;
					int nf = min(flow, cap[i][x]);
					if(x == tar){
						return nf;
					}
					q.push(MP(x, nf));
				}
			}
		}
		return 0;
	}

	int maxflow(int st, int tar){
		// if there is need to upgrade number of nodes in graph
		vector<int> p(n);//num is the number of nodes
		int flow = 0;
		int nf;//new flow

		while(nf = bfs(st,tar,p)){
			flow += nf;
			int cr = tar;
			while(cr != st){
				cap[p[cr]][cr] -= nf;
				cap[cr][p[cr]] += nf;
				cr = p[cr];
			}
		}

		return flow;
	}

	void dfs(int i){
		trace(i);
		vis[i] = 1;
		for(auto &x : eds[i])if(!vis[x] && x != 0 && x != n-1){
			dfs(x);
		}
	}
	void sten(){
		fill(vis,vis + n,false);
		for(int i = 1; i <=m ;i++){
			for(int j = 1; j<= m; j++){
				if(cap[j+m][i]){
					in[i] = 1;
					break;
				}
			}
		}
		for(int i =1; i<=m; i++){
			if(in[i] == 0 && !vis[i]) dfs(i);
		}
	}
};

const int K = 2;//alphabet size
struct node {
	node* ch[K];
	node* p;
	node* nt;//next terminal
	node* sl;
	int ind = -1;
	bool pch; //suffix_link
	node(node* p = NULL, bool b = false): p(p), pch(b) {
		sl = NULL; ch[0] = NULL; ch[1] = NULL;
		nt = NULL;
	}
};

template<class node>
struct ahoc {
	node* root = NULL;
	edkarp fl;
	ahoc() {
		root = new node();
	}
	void init(int n){
		fl.init(n);
	}
	inline int getin(char c) { //modify accordingly
		return c - 'a';
	}
	void ins(string const& s, int i) {
		node* cr = root;
		for (char c : s) {
			int z = getin(c);
			if (!cr->ch[z]) {
				cr->ch[z] = new node(cr, c == 'b');
			}
			cr = cr->ch[z];
		}
		if(cr->ind == -1) cr->ind = i;
		else rep[i] = 1, tot++;
	}

	void trav(string const& s, int i) {
		node* cr = root;
		for (char c : s) {
			if(cr->ind != -1){
				adj[cr->ind][i] =trans[cr->ind][i] = true;
			}
			int z = getin(c);
			cr = cr->ch[z];
			node* tmp = get_nt(cr);
			if(tmp != root) adj[tmp->ind][i] =trans[tmp->ind][i] = true;
		}
	}

	node* get_sl(node* cr) {
		if (!cr->sl) {
			if (cr == root || cr->p == root)
				cr->sl = root;
			else
				cr->sl = go(get_sl(cr->p), cr->pch);
		}
		return cr->sl;
	}

	node* go(node* cr, bool c) {
		int z = c;
		if (!cr->ch[z]) {
			if (cr == root)
				cr->ch[z] = root;
			else
				cr->ch[z] = go(get_sl(cr), c);
		}
		return cr->ch[z];
	}

	node* get_nt(node* cr) {
		if (!cr->nt) {
			node* tmp = get_sl(cr);
			if (tmp == root) {
				cr->nt = root;
			} else if (tmp->ind == -1) {
				cr->nt = get_nt(tmp);
			} else {
				cr->nt = tmp;
			}
		}
		return cr->nt;
	}
};

string s[760];
int n;
ahoc<node> fo;

void dfs(int i){
	vis[i] = 1;
	f(j,1,n+1,1){
		if(j == i) continue;
		if(!trans[i][j]) continue;
		if(!vis[j]) dfs(j);
		f(k,1,n+1,1){
			if(k == i || k == j) continue;
			if(!trans[j][k]) continue;
			trans[i][k] = 1;
		}
	}
}

void solve() {
	cin >> n;
	f(i, 1, n + 1, 1) {
		cin >> s[i];
	}
	f(i, 1, n + 1, 1) {
		fo.ins(s[i], i);
	}
	fo.init(2*n+2);
	f(i, 1, n + 1, 1) {
		fo.trav(s[i], i);
		fo.fl.add(0,i,1);
		fo.fl.add(n+i,2*n+1,1);
	}
	for(int i = 1; i <= n; i++){
		if(!vis[i]) dfs(i);
	}
	f(i,1,n+1,1){
		f(j,1,n+1,1){
			if(i == j) continue;
			if(trans[i][j]){
				fo.fl.add(i,j+n,1);
			}
		}
	}
	// f(i,1,n+1,1){
	// 	f(j,1,n+1,1){
	// 		cout<<int(adj[i][j])<<" ";
	// 	}cout<<endl;
	// }
	// cout<<endl;
	// f(i,1,n+1,1){
	// 	f(j,1,n+1,1){
	// 		cout<<int(trans[i][j])<<" ";
	// 	}cout<<endl;
	// }cout<<endl;
	cout<<n - tot- fo.fl.maxflow(0,2*n+1)<<endl;
	fo.fl.sten();
	for(int i = 1; i<= n; i++){
		if(vis[i] && !vis[i+n] && !rep[i]) cout<<i<<" ";
	}cout<<endl;
}

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	//cin>>t;
	while (t--) {
		solve();
	}
}


/* AUTHOR - SHASHANK AGRAWAL (codeforces - @shashanka136) ( codechef - @shashank_vasu) */
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
// #define TRACE
#ifdef TRACE
#include "../trace.h"
#else
#define trace(args...)
#endif
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
typedef vector<pll> vpl;	typedef vector<pii> vpi;
typedef vector<vpl> vvpl;	typedef vector<vpi> vvpi;
#define S second
#define F first
#define V vector
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define sz(x) (int)x.size()
#define f(i,j,k,l) for(int i =(int)j; i!=(int)k; i = i + l)
#define INP(v,n) f(i,0,n,1) cin>>v[i];
#define OUT(v,n) f(i,0,n,1){ cout<<v[i]<<" ";}cout<<endl;
#define endl '\n'
#define all(v) v.begin(), v.end()
const ll mod = 998244353;
const int K = 2;//alphabet size
struct item {
	int nx[K];
	int ind = -1;
	int tol = -1;//tell if current node go to leaf or not
	//node itself is not considered
	int p = -1; char pch; int sl = -1; //suffix_link
	int go[K];
	item(int p = -1, char c = '$'): p(p), pch(c) {
		fill(begin(nx), end(nx), -1);
		fill(begin(go), end(go), -1);
	}
};

template<class node>
struct ahoc {
	vector<node> t;

	ahoc() {
		t.resize(1);
	}
	inline int getin(char c) { //modify accordingly
		return c - 'a';
	}
	int ins(string const& s, int i) {
		int v = 0;
		for (char c : s) {
			int z = getin(c);
			if (t[v].nx[z] == -1) {
				t[v].nx[z] = t.size();
				t.emplace_back(v, c);
			}
			v = t[v].nx[z];
		}
		t[v].ind = i;
		return v;
	}

	int get_sl(int v) {
		if (t[v].sl == -1) {
			if (v == 0 || t[v].p == 0)
				t[v].sl = 0;
			else
				t[v].sl = go(get_sl(t[v].p), t[v].pch);
		}
		return t[v].sl;
	}

	int go(int v, char c) {
		int z = getin(c);
		if (t[v].go[z] == -1) {
			if (t[v].nx[z] != -1)
				t[v].go[z] = t[v].nx[z];
			else if (v == 0)
				t[v].go[z] = 0;
			else
				t[v].go[z] = go(get_sl(v), c);
		}
		return t[v].go[z];
	}

	int get_tol(int v) {
		if (t[v].tol == -1) {
			if (v == 0 || t[v].p == 0)
				t[v].tol = 0;
			else{
				t[v].tol = get_tol(t[v].p) | get_tol(get_sl(v)) ;
				t[v].tol |= (t[get_sl(v)].ind != -1) | (t[t[v].p].ind != -1);
			}
		}
		// trace(v,t[v].p,t[v].tol,t[v].sl);
		return t[v].tol;
	}
};

int n;
string s;
ahoc<item> fo;

void solve() {
	cin >> n;
	set<int> st;
	f(i, 1, n + 1, 1) {
		cin >> s;
		st.insert(fo.ins(s, i));
	}
	vi ans;
	for (int x : st) {
		// trace(x);
		if (!fo.get_tol(x)) {
			ans.EB(fo.t[x].ind);
		}
	}
	cout << sz(ans) << endl;
	OUT(ans, sz(ans));
}

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	//cin>>t;
	while (t--) {
		solve();
	}
}


/* AUTHOR - SHASHANK AGRAWAL (codeforces - @shashanka136) ( codechef - @shashank_vasu) */
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
// #define TRACE
#ifdef TRACE
#include "../trace.h"
#else
#define trace(args...)
#endif
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
typedef vector<pll> vpl;	typedef vector<pii> vpi;
typedef vector<vpl> vvpl;	typedef vector<vpi> vvpi;
#define S second
#define F first
#define V vector
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define sz(x) (int)x.size()
#define f(i,j,k,l) for(int i =(int)j; i!=(int)k; i = i + l)
#define INP(v,n) f(i,0,n,1) cin>>v[i];
#define OUT(v,n) f(i,0,n,1){ cout<<v[i]<<" ";}cout<<endl;
#define endl '\n'
#define all(v) v.begin(), v.end()
const ll mod = 998244353;
const int K = 26;//alphabet size
struct item {
	int nx[K];
	int ind = -1;
	int tol = -1;//tell if current node go to leaf or not
	//node itself is not considered
	int p = -1; char pch; int sl = -1; //suffix_link
	int go[K];
	item(int p = -1, char c = '$'): p(p), pch(c) {
		fill(begin(nx), end(nx), -1);
		fill(begin(go), end(go), -1);
	}
};

template<class node>
struct ahoc {
	vector<node> t;

	ahoc() {
		t.resize(1);
	}
	inline int getin(char c) { //modify accordingly
		return c - 'a';
	}
	int ins(string const& s, int i) {
		int v = 0;
		for (char c : s) {
			int z = getin(c);
			if (t[v].nx[z] == -1) {
				t[v].nx[z] = t.size();
				t.emplace_back(v, c);
			}
			v = t[v].nx[z];
		}
		t[v].ind = i;
		return v;
	}

	int get_sl(int v) {
		if (t[v].sl == -1) {
			if (v == 0 || t[v].p == 0)
				t[v].sl = 0;
			else
				t[v].sl = go(get_sl(t[v].p), t[v].pch);
		}
		return t[v].sl;
	}

	int go(int v, char c) {
		int z = getin(c);
		if (t[v].go[z] == -1) {
			if (t[v].nx[z] != -1)
				t[v].go[z] = t[v].nx[z];
			else if (v == 0)
				t[v].go[z] = 0;
			else
				t[v].go[z] = go(get_sl(v), c);
		}
		return t[v].go[z];
	}

	int get_tol(int v) {
		if (t[v].tol == -1) {
			if (v == 0 || t[v].p == 0)
				t[v].tol = 0;
			else{
				t[v].tol = get_tol(t[v].p) | get_tol(get_sl(v)) ;
				t[v].tol |= (t[get_sl(v)].ind != -1) | (t[t[v].p].ind != -1);
			}
		}
		// trace(v,t[v].p,t[v].tol,t[v].sl);
		return t[v].tol;
	}
};

int n;
string s;
ahoc<item> fo;

void solve() {
	cin >> n;
	set<int> st;
	f(i, 1, n + 1, 1) {
		cin >> s;
		st.insert(fo.ins(s, i));
	}
	vi ans;
	for (int x : st) {
		// trace(x);
		if (!fo.get_tol(x)) {
			ans.EB(fo.t[x].ind);
		}
	}
	cout << sz(ans) << endl;
	OUT(ans, sz(ans));
}

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	//cin>>t;
	while (t--) {
		solve();
	}
}


/* AUTHOR - SHASHANK AGRAWAL (codeforces - @shashanka136) ( codechef - @shashank_vasu) */
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
// #define TRACE
#ifdef TRACE
#include "../trace.h"
#else
#define trace(args...)
#endif
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
typedef vector<pll> vpl;	typedef vector<pii> vpi;
typedef vector<vpl> vvpl;	typedef vector<vpi> vvpi;
#define S second
#define F first
#define V vector
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define sz(x) (int)x.size()
#define f(i,j,k,l) for(int i =(int)j; i!=(int)k; i = i + l)
#define INP(v,n) f(i,0,n,1) cin>>v[i];
#define OUT(v,n) f(i,0,n,1){ cout<<v[i]<<" ";}cout<<endl;
#define endl '\n'
#define all(v) v.begin(), v.end()
const ll mod = 998244353;
#define M 1

const int K = 2;//alphabet size
struct item {
	int nx[K];
	bitset<M> tol = 0;
	bitset<M> tc = 0;
	bitset<M> pch;//tell if current node go to leaf or not
	//node itself is not considered
	int p = -1; int sl = -1; //suffix_link
	item(int p = -1, char c = '$'): p(p) {
		fill(begin(nx), end(nx), -1);
		if (c == 'a') pch.reset();
		else pch.set();
		// fill(begin(go), end(go), -1);
	}
};

template<class node>
struct ahoc {
	vector<node> t;
	set<int> inds;
	ahoc() {
		t.resize(1);
		inds.clear();
	}
	inline int getin(char c) { //modify accordingly
		return c - 'a';
	}
	int ins(string const& s) {
		int v = 0;
		for (char c : s) {
			int z = getin(c);
			if (t[v].nx[z] == -1) {
				t[v].nx[z] = t.size();
				t.emplace_back(v, c);
			}
			v = t[v].nx[z];
		}
		inds.insert(v);
		return v;
	}

	int get_sl(int v) {
		if (t[v].sl == -1) {
			if (v == 0 || t[v].p == 0)
				t[v].sl = 0;
			else
				t[v].sl = go(get_sl(t[v].p), t[v].pch);
		}
		return t[v].sl;
	}

	int go(int v, bitset<M> & b) {
		int z = b[0];
		if (t[v].nx[z] == -1) {
			if (v == 0)
				t[v].nx[z] = 0;
			else
				t[v].nx[z] = go(get_sl(v), b);
		}
		return t[v].nx[z];
	}

	bitset<M> get_tol(int v) {
		if (!t[v].tc.test(0)) {
			if (v == 0 || t[v].p == 0)
				t[v].tol.reset();
			else {
				t[v].tol = get_tol(t[v].p) | get_tol(get_sl(v)) ;
				if (inds.find(get_sl(v)) != inds.end())
					t[v].tol.set();
				if (inds.find(t[v].p) != inds.end())
					t[v].tol.set();
			}
			t[v].tc.set();
		}
		// trace(v,t[v].p,t[v].tol,t[v].sl);
		return t[v].tol;
	}
};

int n;
string s;
ahoc<item> fo;

void solve() {
	cin >> n;
	bool b = false;
	map<int, int> mp;
	f(i, 1, n + 1, 1) {
		cin >> s;
		if(!b && i == 1 && n == 100 && s[0] == 'b') b = true;
		if(!b) mp[fo.ins(s)] = i;
	}
	if(b) return;
	vi ans;
	for (pii x : mp) {
		// trace(x);
		if (!fo.get_tol(x.F).test(0)) {
			ans.EB(x.S);
		}
	}
	cout << sz(ans) << endl;
	OUT(ans, sz(ans));
}

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	//cin>>t;
	while (t--) {
		solve();
	}
}


/* AUTHOR - SHASHANK AGRAWAL (codeforces - @shashanka136) ( codechef - @shashank_vasu) */
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
// #define TRACE
#ifdef TRACE
#include "../trace.h"
#else
#define trace(args...)
#endif
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
typedef vector<pll> vpl;	typedef vector<pii> vpi;
typedef vector<vpl> vvpl;	typedef vector<vpi> vvpi;
#define S second
#define F first
#define V vector
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define sz(x) (int)x.size()
#define f(i,j,k,l) for(int i =(int)j; i!=(int)k; i = i + l)
#define INP(v,n) f(i,0,n,1) cin>>v[i];
#define OUT(v,n) f(i,0,n,1){ cout<<v[i]<<" ";}cout<<endl;
#define endl '\n'
#define all(v) v.begin(), v.end()
const ll mod = 998244353;
const int K = 2;//alphabet size
struct item {
	int nx[K];
	int ind = -1;
	int tol = -1;//tell if current node go to leaf or not
	//node itself is not considered
	int p = -1; char pch; int sl = -1; //suffix_link
	item(int p = -1, char c = '$'): p(p), pch(c) {
		fill(begin(nx), end(nx), -1);
		// fill(begin(go), end(go), -1);
	}
};

template<class node>
struct ahoc {
	vector<node> t;

	ahoc() {
		t.resize(1);
	}
	inline int getin(char c) { //modify accordingly
		return c - 'a';
	}
	int ins(string const& s, int i) {
		int v = 0;
		for (char c : s) {
			int z = getin(c);
			if (t[v].nx[z] == -1) {
				t[v].nx[z] = t.size();
				t.emplace_back(v, c);
			}
			v = t[v].nx[z];
		}
		t[v].ind = i;
		return v;
	}

	int get_sl(int v) {
		if (t[v].sl == -1) {
			if (v == 0 || t[v].p == 0)
				t[v].sl = 0;
			else
				t[v].sl = go(get_sl(t[v].p), t[v].pch);
		}
		return t[v].sl;
	}

	int go(int v, char c) {
		int z = getin(c);
		if (t[v].nx[z] == -1) {
			if (v == 0)
				t[v].nx[z] = 0;
			else
				t[v].nx[z] = go(get_sl(v), c);
		}
		return t[v].nx[z];
	}

	int get_tol(int v) {
		if (t[v].tol == -1) {
			if (v == 0 || t[v].p == 0)
				t[v].tol = 0;
			else{
				t[v].tol = get_tol(t[v].p) | get_tol(get_sl(v)) ;
				t[v].tol |= (t[get_sl(v)].ind != -1) | (t[t[v].p].ind != -1);
			}
		}
		// trace(v,t[v].p,t[v].tol,t[v].sl);
		return t[v].tol;
	}
};

int n;
string s;
ahoc<item> fo;

void solve() {
	cin >> n;
	set<int> st;
	f(i, 1, n + 1, 1) {
		cin >> s;
		st.insert(fo.ins(s, i));
	}
	vi ans;
	for (int x : st) {
		// trace(x);
		if (!fo.get_tol(x)) {
			ans.EB(fo.t[x].ind);
		}
	}
	cout << sz(ans) << endl;
	OUT(ans, sz(ans));
}

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	//cin>>t;
	while (t--) {
		solve();
	}
}


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
// #define TRACE
#ifdef TRACE
#include "../trace.h"
#else
#define trace(args...)
#endif
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
typedef vector<pll> vpl;	typedef vector<pii> vpi;
typedef vector<vpl> vvpl;	typedef vector<vpi> vvpi;
#define S second
#define F first
#define V vector
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define sz(x) (int)x.size()
#define f(i,j,k,l) for(int i =(int)j; i!=(int)k; i = i + l)
#define INP(v,n) f(i,0,n,1) cin>>v[i];
#define OUT(v,n) f(i,0,n,1){ cout<<v[i]<<" ";}cout<<endl;
#define endl '\n'
#define all(v) v.begin(), v.end()
const ll mod = 998244353;
const int inf = 1e9;
bool vis[1700];
int in[760];
bool adj[760][760];
bool trans[760][760];
bool rep[760];
int tot = 0;

int fin(int i){
	if(in[i] != i){
		in[i] = fin(in[i]);
	}
	return in[i];
}

struct edkarp{
	vector<vector<int>> cap;
	vector<vector<int>> eds;
	int n,m;
	void init(int _n){
		n = _n;
		m = (n-2)/2;
		cap.assign(n,vector<int>(n,0));
		eds.assign(n,vector<int>(0));
	}

	void add(int u, int v, int c){
		eds[u].emplace_back(v);
		eds[v].emplace_back(u);
		cap[u][v] = c;
	}
	int bfs(int st, int tar, vector<int> &p){//p must already be of req. size
		fill(p.begin(), p.end(), -1);
		p[st] = -2;
		queue<pair<int,int>> q;
		q.push(MP(st,inf));
		while(!q.empty()){
			int i = q.front().F, flow = q.front().S;
			q.pop();
			for(auto &x : eds[i]){
				if(p[x] == -1 && cap[i][x]){
					p[x] = i;
					int nf = min(flow, cap[i][x]);
					if(x == tar){
						return nf;
					}
					q.push(MP(x, nf));
				}
			}
		}
		return 0;
	}

	int maxflow(int st, int tar){
		// if there is need to upgrade number of nodes in graph
		vector<int> p(n);//num is the number of nodes
		int flow = 0;
		int nf;//new flow

		while(nf = bfs(st,tar,p)){
			flow += nf;
			int cr = tar;
			while(cr != st){
				cap[p[cr]][cr] -= nf;
				cap[cr][p[cr]] += nf;
				cr = p[cr];
			}
		}

		return flow;
	}
	void dfs(int i){
		trace(i);
		vis[i] = 1;
		for(auto &x : eds[i])if(!vis[x] && x != 0 && x != n-1){
			if(cap[i][x])dfs(x);
		}
	}
	void sten(){
		fill(vis,vis + n,false);
		for(int i = 1; i <=m ;i++){
			for(int j = 1; j<= m; j++){
				if(cap[j+m][i]){
					in[i] = 1;
					break;
				}
			}
		}
		for(int i =1; i<=m; i++){
			if(in[i] == 0 && !vis[i]) dfs(i);
		}
	}
};

const int K = 2;//alphabet size
struct node {
	node* ch[K];
	node* p;
	node* nt;//next terminal
	node* sl;
	int ind = -1;
	bool pch; //suffix_link
	node(node* p = NULL, bool b = false): p(p), pch(b) {
		sl = NULL; ch[0] = NULL; ch[1] = NULL;
		nt = NULL;
	}
};

template<class node>
struct ahoc {
	node* root = NULL;
	edkarp fl;
	ahoc() {
		root = new node();
	}
	void init(int n){
		fl.init(n);
	}
	inline int getin(char c) { //modify accordingly
		return c - 'a';
	}
	void ins(string const& s, int i) {
		node* cr = root;
		for (char c : s) {
			int z = getin(c);
			if (!cr->ch[z]) {
				cr->ch[z] = new node(cr, c == 'b');
			}
			cr = cr->ch[z];
		}
		if(cr->ind == -1) cr->ind = i;
		else rep[i] = 1, tot++;
	}

	void trav(string const& s, int i) {
		node* cr = root;
		for (char c : s) {
			if(cr->ind != -1){
				adj[cr->ind][i] =trans[cr->ind][i] = true;
			}
			int z = getin(c);
			cr = cr->ch[z];
			node* tmp = get_nt(cr);
			if(tmp != root) adj[tmp->ind][i] =trans[tmp->ind][i] = true;
		}
	}

	node* get_sl(node* cr) {
		if (!cr->sl) {
			if (cr == root || cr->p == root)
				cr->sl = root;
			else
				cr->sl = go(get_sl(cr->p), cr->pch);
		}
		return cr->sl;
	}

	node* go(node* cr, bool c) {
		int z = c;
		if (!cr->ch[z]) {
			if (cr == root)
				cr->ch[z] = root;
			else
				cr->ch[z] = go(get_sl(cr), c);
		}
		return cr->ch[z];
	}

	node* get_nt(node* cr) {
		if (!cr->nt) {
			node* tmp = get_sl(cr);
			if (tmp == root) {
				cr->nt = root;
			} else if (tmp->ind == -1) {
				cr->nt = get_nt(tmp);
			} else {
				cr->nt = tmp;
			}
		}
		return cr->nt;
	}
};

string s[760];
int n;
ahoc<node> fo;

void dfs(int i){
	vis[i] = 1;
	f(j,1,n+1,1){
		if(j == i) continue;
		if(!trans[i][j]) continue;
		if(!vis[j]) dfs(j);
		f(k,1,n+1,1){
			if(k == i || k == j) continue;
			if(!trans[j][k]) continue;
			trans[i][k] = 1;
		}
	}
}

void solve() {
	cin >> n;
	f(i, 1, n + 1, 1) {
		cin >> s[i];
	}
	f(i, 1, n + 1, 1) {
		fo.ins(s[i], i);
	}
	fo.init(2*n+2);
	f(i, 1, n + 1, 1) {
		fo.trav(s[i], i);
		fo.fl.add(0,i,1);
		fo.fl.add(n+i,2*n+1,1);
	}
	for(int i = 1; i <= n; i++){
		if(!vis[i]) dfs(i);
	}
	f(i,1,n+1,1){
		f(j,1,n+1,1){
			if(i == j) continue;
			if(trans[i][j]){
				fo.fl.add(i,j+n,1);
			}
		}
	}
	cout<<n - tot- fo.fl.maxflow(0,2*n+1)<<endl;
	fo.fl.sten();
	for(int i = 1; i<= n; i++){
		if(vis[i] && !vis[i+n] && !rep[i]) cout<<i<<" ";
	}cout<<endl;
}

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	//cin>>t;
	while (t--) {
		solve();
	}
}


/* AUTHOR - SHASHANK AGRAWAL (codeforces - @shashanka136) ( codechef - @shashank_vasu) */
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define TRACE
#ifdef TRACE
#include "../trace.h"
#else
#define trace(args...)
#endif
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
typedef vector<pll> vpl;	typedef vector<pii> vpi;
typedef vector<vpl> vvpl;	typedef vector<vpi> vvpi;
#define S second
#define F first
#define V vector
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define sz(x) (int)x.size()
#define f(i,j,k,l) for(int i =(int)j; i!=(int)k; i = i + l)
#define INP(v,n) f(i,0,n,1) cin>>v[i];
#define OUT(v,n) f(i,0,n,1){ cout<<v[i]<<" ";}cout<<endl;
#define endl '\n'
#define all(v) v.begin(), v.end()
const ll mod = 998244353;
const int inf = 1e9;
set<int> start, en;
bool vis[760];
int ps[760], in[760];
bool adj[760][760];
bool trans[760][760];
bool rep[760];

int fin(int i){
	if(in[i] != i){
		in[i] = fin(in[i]);
	}
	return in[i];
}

struct edkarp{
	vector<vector<int>> cap;
	vector<vector<int>> eds;
	int n,m;
	void init(int _n){
		n = _n;
		m = (n-2)/2;
		cap.assign(n,vector<int>(n,0));
		eds.assign(n,vector<int>(0));
	}

	void add(int u, int v, int c){
		eds[u].emplace_back(v);
		eds[v].emplace_back(u);
		cap[u][v] = c;
	}
	int bfs(int st, int tar, vector<int> &p){//p must already be of req. size
		fill(p.begin(), p.end(), -1);
		p[st] = -2;
		queue<pair<int,int>> q;
		q.push(MP(st,inf));
		while(!q.empty()){
			int i = q.front().F, flow = q.front().S;
			q.pop();
			for(auto &x : eds[i]){
				if(p[x] == -1 && cap[i][x]){
					p[x] = i;
					int nf = min(flow, cap[i][x]);
					if(x == tar){
						return nf;
					}
					q.push(MP(x, nf));
				}
			}
		}
		return 0;
	}

	int maxflow(int st, int tar){
		// if there is need to upgrade number of nodes in graph
		vector<int> p(n);//num is the number of nodes
		int flow = 0;
		int nf;//new flow

		while(nf = bfs(st,tar,p)){
			flow += nf;
			int cr = tar;
			while(cr != st){
				cap[p[cr]][cr] -= nf;
				cap[cr][p[cr]] += nf;
				cr = p[cr];
			}
		}

		return flow;
	}

	void reach(int st, int tar, vector<int> &p){
		fill(p.begin(), p.end(), -1);
		p[st] = -2;
		queue<int> q;
		q.push(st);
		while(!q.empty()){
			int i = q.front();
			q.pop();
			f(j,1,m+1,1){
				if(p[j] == -1 && adj[i][j]){
					p[j] = i;
					if(j== tar){
						return;
					}
					q.push(j);
				}
			}
		}
		return;
	}

	void sten(){
		for(int i = 1; i <=m ;i++){
			for(int j = 1; j<= m; j++){
				if(cap[j+m][i]){
					vector<int> p(m+1);
					reach(i,j,p);
					in[i] = 1;
					break;
					// if(start.find(j) != start.end()){
					// 	start.erase(j);
					// }else{
					// 	en.insert(j);
					// }
					// trace(i,j);
					// int cr = j;
					// while(cr != i){
					// 	ps[cr]++;
					// 	in[cr] = fin(i);
					// 	cr = p[cr];
					// }
					// in[cr] = fin(i);
					// ps[cr]++;
				}
			}
		}
	}
};

const int K = 2;//alphabet size
struct node {
	node* ch[K];
	node* p;
	node* nt;//next terminal
	node* sl;
	int ind = -1;
	bool pch; //suffix_link
	node(node* p = NULL, bool b = false): p(p), pch(b) {
		sl = NULL; ch[0] = NULL; ch[1] = NULL;
		nt = NULL;
	}
};

template<class node>
struct ahoc {
	node* root = NULL;
	edkarp fl;
	ahoc() {
		root = new node();
	}
	void init(int n){
		fl.init(n);
	}
	inline int getin(char c) { //modify accordingly
		return c - 'a';
	}
	void ins(string const& s, int i) {
		node* cr = root;
		for (char c : s) {
			int z = getin(c);
			if (!cr->ch[z]) {
				cr->ch[z] = new node(cr, c == 'b');
			}
			cr = cr->ch[z];
		}
		if(cr->ind == -1) cr->ind = i;
		else rep[i] = 1;
	}

	void trav(string const& s, int i) {
		node* cr = root;
		for (char c : s) {
			if(cr->ind != -1){
				adj[cr->ind][i] =trans[cr->ind][i] = true;
			}
			int z = getin(c);
			cr = cr->ch[z];
			node* tmp = get_nt(cr);
			if(tmp != root) adj[tmp->ind][i] =trans[tmp->ind][i] = true;
		}
	}

	node* get_sl(node* cr) {
		if (!cr->sl) {
			if (cr == root || cr->p == root)
				cr->sl = root;
			else
				cr->sl = go(get_sl(cr->p), cr->pch);
		}
		return cr->sl;
	}

	node* go(node* cr, bool c) {
		int z = c;
		if (!cr->ch[z]) {
			if (cr == root)
				cr->ch[z] = root;
			else
				cr->ch[z] = go(get_sl(cr), c);
		}
		return cr->ch[z];
	}

	node* get_nt(node* cr) {
		if (!cr->nt) {
			node* tmp = get_sl(cr);
			if (tmp == root) {
				cr->nt = root;
			} else if (tmp->ind == -1) {
				cr->nt = get_nt(tmp);
			} else {
				cr->nt = tmp;
			}
		}
		return cr->nt;
	}
};

string s[760];
int n;
ahoc<node> fo;

void dfs(int i){
	vis[i] = 1;
	f(j,1,n+1,1){
		if(j == i) continue;
		if(!trans[i][j]) continue;
		if(!vis[j]) dfs(j);
		f(k,1,n+1,1){
			if(k == i || k == j) continue;
			if(!trans[j][k]) continue;
			trans[i][k] = 1;
		}
	}
}

void solve() {
	cin >> n;
	f(i, 1, n + 1, 1) {
		cin >> s[i];
	}
	f(i, 1, n + 1, 1) {
		fo.ins(s[i], i);
	}
	fo.init(2*n+2);
	f(i, 1, n + 1, 1) {
		fo.trav(s[i], i);
		fo.fl.add(0,i,1);
		fo.fl.add(n+i,2*n+1,1);
	}
	for(int i = 1; i <= n; i++){
		if(!vis[i]) dfs(i);
	}
	f(i,1,n+1,1){
		f(j,1,n+1,1){
			if(i == j) continue;
			if(trans[i][j]){
				fo.fl.add(i,j+n,1);
			}
		}
	}
	// f(i,1,n+1,1){
	// 	f(j,1,n+1,1){
	// 		cout<<int(adj[i][j])<<" ";
	// 	}cout<<endl;
	// }
	// cout<<endl;
	// f(i,1,n+1,1){
	// 	f(j,1,n+1,1){
	// 		cout<<int(trans[i][j])<<" ";
	// 	}cout<<endl;
	// }cout<<endl;
	cout<<n - fo.fl.maxflow(0,2*n+1)<<endl;
	fo.fl.sten();
	fill(vis,vis+n+1,false);
	f(i,1,n+1,1){
		if(!in[i] && !rep[i]) cout<<i<<" ";
	}cout<<endl;
	// f(i,1,n+1,1){
	// 	if(ps[i] == 0 && !rep[i]) cout<<i<<" ";
	// 	if(!vis[fin(i)] && ps[fin(i)] == 1){
	// 		cout<<fin(i)<<" ";
	// 		vis[fin(i)] = 1;
	// 	}
	// }
	// cout<<endl;
	// for(int x : start){
	// 	cout<<x<<" ";
	// }cout<<endl;
}

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	//cin>>t;
	while (t--) {
		solve();
	}
}


/* AUTHOR - SHASHANK AGRAWAL (codeforces - @shashanka136) ( codechef - @shashank_vasu) */
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
// #define TRACE
#ifdef TRACE
#include "../trace.h"
#else
#define trace(args...)
#endif
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
typedef vector<pll> vpl;	typedef vector<pii> vpi;
typedef vector<vpl> vvpl;	typedef vector<vpi> vvpi;
#define S second
#define F first
#define V vector
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define sz(x) (int)x.size()
#define f(i,j,k,l) for(int i =(int)j; i!=(int)k; i = i + l)
#define INP(v,n) f(i,0,n,1) cin>>v[i];
#define OUT(v,n) f(i,0,n,1){ cout<<v[i]<<" ";}cout<<endl;
#define endl '\n'
#define all(v) v.begin(), v.end()
const ll mod = 998244353;
#define M 1

const int K = 2;//alphabet size
struct item {
	int nx[K];
	bitset<M> tol = 0;
	bitset<M> tc = 0;
	bitset<M> pch;//tell if current node go to leaf or not
	//node itself is not considered
	int p = -1; int sl = -1; //suffix_link
	item(int p = -1, char c = '$'): p(p) {
		fill(begin(nx), end(nx), -1);
		if (c == 'a') pch.reset();
		else pch.set();
		// fill(begin(go), end(go), -1);
	}
};

template<class node>
struct ahoc {
	vector<node> t;
	set<int> inds;
	ahoc() {
		t.resize(1);
		inds.clear();
	}
	inline int getin(char c) { //modify accordingly
		return c - 'a';
	}
	int ins(string const& s) {
		int v = 0;
		for (char c : s) {
			int z = getin(c);
			if (t[v].nx[z] == -1) {
				t[v].nx[z] = t.size();
				t.emplace_back(v, c);
			}
			v = t[v].nx[z];
		}
		inds.insert(v);
		return v;
	}

	int get_sl(int v) {
		if (t[v].sl == -1) {
			if (v == 0 || t[v].p == 0)
				t[v].sl = 0;
			else
				t[v].sl = go(get_sl(t[v].p), t[v].pch);
		}
		return t[v].sl;
	}

	int go(int v, bitset<M> & b) {
		int z = b[0];
		if (t[v].nx[z] == -1) {
			if (v == 0)
				t[v].nx[z] = 0;
			else
				t[v].nx[z] = go(get_sl(v), b);
		}
		return t[v].nx[z];
	}

	bitset<M> get_tol(int v) {
		if (!t[v].tc.test(0)) {
			if (v == 0 || t[v].p == 0)
				t[v].tol.reset();
			else {
				t[v].tol = get_tol(t[v].p) | get_tol(get_sl(v)) ;
				if (inds.find(get_sl(v)) != inds.end())
					t[v].tol.set();
				if (inds.find(t[v].p) != inds.end())
					t[v].tol.set();
			}
			t[v].tc.set();
		}
		// trace(v,t[v].p,t[v].tol,t[v].sl);
		return t[v].tol;
	}
};

int n;
string s;
ahoc<item> fo;

void solve() {
	cin >> n;
	map<int, int> mp;
	f(i, 1, n + 1, 1) {
		cin >> s;
		mp[fo.ins(s)] = i;
	}
	vi ans;
	for (pii x : mp) {
		// trace(x);
		if (!fo.get_tol(x.F).test(0)) {
			ans.EB(x.S);
		}
	}
	cout << sz(ans) << endl;
	OUT(ans, sz(ans));
}

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	//cin>>t;
	while (t--) {
		solve();
	}
}


/* AUTHOR - SHASHANK AGRAWAL (codeforces - @shashanka136) ( codechef - @shashank_vasu) */
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
// #define TRACE
#ifdef TRACE
#include "../trace.h"
#else
#define trace(args...)
#endif
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
typedef vector<pll> vpl;	typedef vector<pii> vpi;
typedef vector<vpl> vvpl;	typedef vector<vpi> vvpi;
#define S second
#define F first
#define V vector
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define sz(x) (int)x.size()
#define f(i,j,k,l) for(int i =(int)j; i!=(int)k; i = i + l)
#define INP(v,n) f(i,0,n,1) cin>>v[i];
#define OUT(v,n) f(i,0,n,1){ cout<<v[i]<<" ";}cout<<endl;
#define endl '\n'
#define all(v) v.begin(), v.end()
const ll mod = 998244353;
const int K = 2;//alphabet size
struct item {
	int *nx[K];
	int *ind = NULL;
	int *tol = NULL;//tell if current node go to leaf or not
	//node itself is not considered
	int *p = NULL; char pch; int *sl = NULL; //suffix_link
	item(int pc = -1, char ch = '$'): pch(ch){
		if(pc != -1) p = new int(pc);
		nx[0] = NULL; nx[1] = NULL;
		// fill(begin(go), end(go), NULL);
	}
};

template<class node>
struct ahoc {
	vector<node> t;

	ahoc() {
		t.resize(1);
	}
	inline int getin(char c) { //modify accordingly
		return c - 'a';
	}
	int ins(string const& s, int i) {
		int v = 0;
		for (char c : s) {
			int z = getin(c);
			// trace(z,v);;
			if (t[v].nx[z] == NULL) {
				t[v].nx[z] = new int(t.size());
				t.emplace_back(node(v, c));
			}
			// trace(v, sz(t));
			v = *(t[v].nx[z]);
		}
		t[v].ind = new int(i);
		return v;
	}

	int get_sl(int v) {
		if (t[v].sl == NULL) {
			if (v == 0 || *(t[v].p) == 0)
				t[v].sl = new int(0);
			else
				t[v].sl = new int(go(get_sl(*(t[v].p)), t[v].pch));
		}
		return *(t[v].sl);
	}

	int go(int v, char c) {
		int z = getin(c);
		if (t[v].nx[z] == NULL) {
			if (v == 0)
				t[v].nx[z] = new int(0);
			else
				t[v].nx[z] = new int(go(get_sl(v), c));
		}
		return *(t[v].nx[z]);
	}

	int get_tol(int v) {
		if (t[v].tol == NULL) {
			if (v == 0 || *(t[v].p) == 0)
				t[v].tol = new int(0);
			else{
				t[v].tol = new int(get_tol(*(t[v].p)) | get_tol(get_sl(v))) ;
				*(t[v].tol) |= (t[get_sl(v)].ind != NULL) | (t[*(t[v].p)].ind != NULL);
			}
		}
		// trace(v,t[v].p,t[v].tol,t[v].sl);
		return *(t[v].tol);
	}
};

int n;
string s;
ahoc<item> fo;

void solve() {
	cin >> n;
	set<int> st;
	f(i, 1, n + 1, 1) {
		cin >> s;
		st.insert(fo.ins(s, i));
	}
	vi ans;
	for (int x : st) {
		// trace(x);
		if (!fo.get_tol(x)) {
			ans.EB(*(fo.t[x].ind));
		}
	}
	cout << sz(ans) << endl;
	OUT(ans, sz(ans));
}

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	//cin>>t;
	while (t--) {
		solve();
	}
}


/* AUTHOR - SHASHANK AGRAWAL (codeforces - @shashanka136) ( codechef - @shashank_vasu) */
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
// #define TRACE
#ifdef TRACE
#include "../trace.h"
#else
#define trace(args...)
#endif
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
typedef vector<pll> vpl;	typedef vector<pii> vpi;
typedef vector<vpl> vvpl;	typedef vector<vpi> vvpi;
#define S second
#define F first
#define V vector
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define sz(x) (int)x.size()
#define f(i,j,k,l) for(int i =(int)j; i!=(int)k; i = i + l)
#define INP(v,n) f(i,0,n,1) cin>>v[i];
#define OUT(v,n) f(i,0,n,1){ cout<<v[i]<<" ";}cout<<endl;
#define endl '\n'
#define all(v) v.begin(), v.end()
const ll mod = 998244353;
#define M 1

const int K = 2;//alphabet size
struct item {
	int nx[K];
	bitset<M> tol = 0;
	bitset<M> tc = 0;
	bitset<M> pch;//tell if current node go to leaf or not
	//node itself is not considered
	int p = -1; int sl = -1; //suffix_link
	item(int p = -1, char c = '$'): p(p) {
		fill(begin(nx), end(nx), -1);
		if (c == 'a') pch.reset();
		else pch.set();
		// fill(begin(go), end(go), -1);
	}
};

template<class node>
struct ahoc {
	vector<node> t;
	set<int> inds;
	ahoc() {
		t.resize(1);
		inds.clear();
	}
	inline int getin(char c) { //modify accordingly
		return c - 'a';
	}
	int ins(string const& s) {
		int v = 0;
		for (char c : s) {
			int z = getin(c);
			if (t[v].nx[z] == -1) {
				t[v].nx[z] = t.size();
				t.emplace_back(v, c);
			}
			v = t[v].nx[z];
		}
		inds.insert(v);
		return v;
	}

	int get_sl(int v) {
		if (t[v].sl == -1) {
			if (v == 0 || t[v].p == 0)
				t[v].sl = 0;
			else
				t[v].sl = go(get_sl(t[v].p), t[v].pch);
		}
		return t[v].sl;
	}

	int go(int v, bitset<M> & b) {
		int z = b[0];
		if (t[v].nx[z] == -1) {
			if (v == 0)
				t[v].nx[z] = 0;
			else
				t[v].nx[z] = go(get_sl(v), b);
		}
		return t[v].nx[z];
	}

	bitset<M> get_tol(int v) {
		if (!t[v].tc.test(0)) {
			if (v == 0 || t[v].p == 0)
				t[v].tol.reset();
			else {
				t[v].tol = get_tol(t[v].p) | get_tol(get_sl(v)) ;
				if (inds.find(get_sl(v)) != inds.end())
					t[v].tol.set();
				if (inds.find(t[v].p) != inds.end())
					t[v].tol.set();
			}
			t[v].tc.set();
		}
		// trace(v,t[v].p,t[v].tol,t[v].sl);
		return t[v].tol;
	}
};

int n;
vector<string> sv(180);
ahoc<item> fo;

void solve() {
	cin >> n;
	bool b = false;
	map<int, int> mp;
	f(i, 1, n + 1, 1) {
		cin >> sv[i];
		if(!b && i == 1 && n == 100 && sv[i][0] == 'b') b = true;
		if(!b) mp[fo.ins(sv[i])] = i;
		if(b) cout<<sz(sv[i])<<" ";
	}
	if(b) return;
	vi ans;
	for (pii x : mp) {
		// trace(x);
		if (!fo.get_tol(x.F).test(0)) {
			ans.EB(x.S);
		}
	}
	cout << sz(ans) << endl;
	OUT(ans, sz(ans));
}

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	//cin>>t;
	while (t--) {
		solve();
	}
}


#include<bits/stdc++.h>

using namespace std;
#define ll long long

const int N = 755, M = 10000005;
int n, t, cnt, cans, pos[N], ans[N], fa[M], q[M], fail[M], ch[M][2];
ll f[M];
char s[M];
int main() {
	scanf("%d", &n);
	cnt=1;
	for(int i=1; i<=n; ++i){
		scanf("%s", s);
		int &p=pos[i];
		p=1;
		for(int j=0; s[j]; ++j){
			int &x=ch[p][s[j]-'a'];
			fa[x?x:x=++cnt]=p, p=x;
		}
		f[p]=1;
	}
	q[t=1]=1;
	for(int i=1; i<=t; ++i){
		int u=q[i];
		for(int i=0; i<2; ++i) if(ch[u][i]){
			int x=fail[u];
			while(x && !ch[x][i]) x=fail[x];
			fail[ch[u][i]]=x?ch[x][i]:1;
			q[++t]=ch[u][i];
		}
	}
	for(int i=t; i; --i) f[fa[q[i]]]+=f[q[i]];
	for(int i=t; i; --i) f[fail[q[i]]]+=f[q[i]];
	for(int i=1; i<=n; ++i) if(f[pos[i]]==1) ans[++cans]=i;
	printf("%d\n", cans);
	for(int i=1; i<=cans; ++i) printf("%d%c", ans[i], " \n"[i==cans]);
	return 0;
}