#include <bits/stdc++.h>
using namespace std;
const int N = 755;
const int M = 10000005;
const int inf = 1e9;
const long long Inf = 1e10;
const int P = 1000000007;
int tre[M][2], n, cnt = 1, don[N];
bitset<N> G[N];
int en[M], fa[M], ne[M], S[M], st[N], ed[N], len;
int Q[M], r;
int DFS(int x) {
  if (en[x]) return en[x];
  if (ne[x]) return ne[x];
  return ne[x] = DFS(fa[x]);
}
void ACbuild() {
  for (int i = (int)(0); i < (int)(2); i++)
    if (!tre[1][i])
      tre[1][i] = 1;
    else
      fa[Q[++r] = tre[1][i]] = 1;
  for (int i = (int)(1); i <= (int)(r); i++) {
    int u = Q[i];
    for (int j = (int)(0); j < (int)(2); j++) {
      int &v = tre[u][j];
      if (v)
        fa[Q[++r] = v] = tre[fa[u]][j];
      else
        v = tre[fa[u]][j];
    }
  }
  ne[1] = -1;
  for (int i = (int)(2); i <= (int)(r); i++) {
    int u = Q[i];
    ne[u] = DFS(fa[u]);
  }
}
void work(int x) {
  if (don[x]) return;
  don[x] = 1;
  if (x == 5) x = 5;
  for (int y = (int)(st[x]); y <= (int)(ed[x]); y++) {
    int u = S[y];
    if (en[u] && en[u] != x) G[x][en[u]] = 1;
    int p = ne[u];
    if (p >= 0) {
      work(p);
      G[x] |= G[p];
      G[x][p] = 1;
    }
  }
}
int mat[N], vis[N], Vis[N];
int Do(int x) {
  if (!x) return 1;
  for (int i = (int)(1); i <= (int)(n); i++)
    if (G[x][i]) {
      if (vis[i]) continue;
      vis[i] = 1;
      if (Do(mat[i])) {
        mat[i] = x;
        return 1;
      }
    }
  return 0;
}
int V[N][2], F[N];
void dfs(int x, int y) {
  if (V[x][y]) return;
  V[x][y] = 1;
  for (int i = (int)(1); i <= (int)(n); i++) {
    if (!y && G[x][i]) dfs(i, 1);
    if (y && mat[x] == i) dfs(i, 0);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = (int)(1); i <= (int)(n); i++) {
    char ch = getchar();
    int p = 1;
    st[i] = len + 1;
    while (ch < 'a' || ch > 'b') ch = getchar();
    while (ch >= 'a' && ch <= 'b') {
      int x = ch - 'a';
      int &v = tre[p][x];
      if (!v) v = ++cnt;
      p = v;
      S[++len] = p;
      ch = getchar();
    }
    ed[i] = len, en[p] = i;
  }
  ACbuild();
  for (int i = (int)(1); i <= (int)(n); i++) work(i);
  int ans = n;
  for (int i = (int)(1); i <= (int)(n); i++) {
    for (int j = (int)(1); j <= (int)(n); j++) vis[j] = 0;
    if (Do(i)) {
      F[i] = 1;
      ans--;
    }
  }
  for (int i = (int)(1); i <= (int)(n); i++)
    if (!F[i]) dfs(i, 0);
  for (int i = (int)(1); i <= (int)(n); i++) {
    if (F[i] && !V[i][0]) Vis[i] = 1;
    if (mat[i] && V[i][1]) Vis[i] = 1;
  }
  printf("%d\n", ans);
  for (int i = (int)(1); i <= (int)(n); i++)
    if (!Vis[i]) printf("%d ", i);
  return 0;
}
