#include <bits/stdc++.h>
using namespace std;
const int maxn = 755;
int n, tr[maxn][maxn];
namespace ACAM {
const int maxp = 10000005;
char s[maxp];
int ed[maxn];
int rt = 1, totp = 1;
int ch[maxp][2], fail[maxp], fa[maxp], pos[maxp];
void insert(char *s, int x) {
  int len = strlen(s + 1);
  int nw = rt;
  for (int i = 1; i <= len; i++) {
    int c = s[i] - 'a';
    if (!ch[nw][c]) {
      ch[nw][c] = ++totp;
      fa[ch[nw][c]] = nw;
    }
    nw = ch[nw][c];
  }
  ed[x] = nw, pos[nw] = x;
}
void getfail() {
  queue<int> Q;
  for (int i = 0; i < 2; i++) {
    if (ch[rt][i])
      fail[ch[rt][i]] = rt, Q.push(ch[rt][i]);
    else
      ch[rt][i] = rt;
  }
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    if (!pos[u]) pos[u] = pos[fail[u]];
    for (int i = 0; i < 2; i++) {
      if (ch[u][i])
        fail[ch[u][i]] = ch[fail[u]][i], Q.push(ch[u][i]);
      else
        ch[u][i] = ch[fail[u]][i];
    }
  }
}
void init() {
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    insert(s, i);
  }
  getfail();
  for (int i = 1; i <= n; i++) {
    if (pos[fail[ed[i]]]) tr[i][pos[fail[ed[i]]]] = 1;
    for (int j = fa[ed[i]]; j != rt; j = fa[j])
      if (pos[j]) tr[i][pos[j]] = 1;
  }
}
}  // namespace ACAM
namespace solver {
const int maxp = maxn << 1;
const int maxm = maxn * maxn;
const int inf = 0x3f3f3f3f;
int last[maxp], Next[maxm << 1], to[maxm << 1], w[maxm << 1], cnt = 1;
inline void addedge(int x, int y, int z) {
  Next[++cnt] = last[x], last[x] = cnt;
  to[cnt] = y, w[cnt] = z;
}
inline void add(int x, int y, int z) { addedge(x, y, z), addedge(y, x, 0); }
int st, ed, dep[maxp];
queue<int> Q;
bool bfs() {
  memset(dep, 0, sizeof(dep));
  dep[st] = 1;
  Q.push(st);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int i = last[u]; i; i = Next[i]) {
      int v = to[i];
      if (w[i] && !dep[v]) {
        dep[v] = dep[u] + 1;
        Q.push(v);
      }
    }
  }
  return dep[ed];
}
int cur[maxp];
int dfs(int x, int low) {
  if (x == ed) return low;
  int add = 0;
  for (int i = cur[x]; i && add < low; i = Next[i]) {
    cur[x] = i;
    int v = to[i];
    if (w[i] && dep[v] == dep[x] + 1) {
      int tmp = dfs(v, min(low - add, w[i]));
      w[i] -= tmp, w[i ^ 1] += tmp;
      add += tmp;
    }
  }
  return add;
}
int dinic() {
  int res = 0;
  while (bfs()) {
    memcpy(cur, last, sizeof(last));
    res += dfs(st, inf);
  }
  return res;
}
int El[maxn], Er[maxn], match[maxn];
int visl[maxn], visr[maxn];
void mark(int x) {
  visr[x] = 1;
  for (int i = 1; i <= n; i++)
    if (tr[i][x] && !visl[i]) visl[i] = 1, mark(match[i]);
}
void solve() {
  ed = n * 2 + 1;
  for (int i = 1; i <= n; i++) {
    add(st, i, 1), El[i] = cnt - 1;
    add(i + n, ed, 1), Er[i] = cnt - 1;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (tr[i][j]) add(i, j + n, 1);
  printf("%d\n", n - dinic());
  for (int i = 1; i <= n; i++)
    if (!w[El[i]]) {
      for (int j = last[i]; j; j = Next[j])
        if (!w[j] && to[j] != st) match[i] = to[j] - n;
    }
  for (int i = 1; i <= n; i++)
    if (w[Er[i]]) mark(i);
  for (int i = 1; i <= n; i++)
    if (!visl[i] && visr[i]) printf("%d ", i);
  puts("");
}
}  // namespace solver
int main() {
  scanf("%d", &n);
  ACAM ::init();
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) tr[i][j] |= (tr[i][k] & tr[k][j]);
  solver ::solve();
  return 0;
}
