#include <bits/stdc++.h>
using namespace std;
int g[760][760], n, cc, f[10000010], t[10000010][2], ed[10000010], po[760],
    ff[10000010], vi[760], v1[760], v2[760], mt[760], fa[10000010], m2[760], ct,
    ans[760];
char s[10000010];
int st[10000010], cg;
int fd(int x) {
  while (f[x] != x) {
    st[++cg] = x;
    x = f[x];
  }
  while (cg) {
    f[st[cg]] = x;
    cg--;
  }
  return x;
}
void ins(char *s, int i) {
  int x = 1;
  for (int i = 0; s[i]; i++) {
    if (!t[x][s[i] - 'a']) {
      t[x][s[i] - 'a'] = ++cc;
      ff[cc] = x;
    }
    x = t[x][s[i] - 'a'];
  }
  ed[x] = i;
  po[i] = x;
}
void bd() {
  queue<int> q;
  fa[1] = 1;
  for (int i = 0; i < 2; i++)
    if (t[1][i]) {
      q.push(t[1][i]);
      fa[t[1][i]] = 1;
    }
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = 0; i < 2; i++) {
      if (t[x][i]) {
        fa[t[x][i]] = t[fa[x]][i];
        q.push(t[x][i]);
      } else
        t[x][i] = t[fa[x]][i];
    }
  }
}
int fv(int x) {
  if (vi[x]) return 0;
  vi[x] = 1;
  for (int i = 1; i <= n; i++)
    if (g[x][i])
      if (!mt[i] || fv(mt[i])) {
        mt[i] = x;
        return 1;
      }
  return 0;
}
void fz(int x) {
  if (v1[x]) return;
  v1[x] = 1;
  for (int i = 1; i <= n; i++)
    if (g[x][i] && m2[x] != i && !v2[i]) {
      v2[i] = 1;
      if (mt[i]) fz(mt[i]);
    }
}
int main() {
  cc = 1;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    ins(s, i);
  }
  bd();
  for (int i = 1; i <= cc; i++) {
    if (ed[i])
      f[i] = i;
    else
      f[i] = fa[i];
  }
  for (int i = 1; i <= n; i++) {
    int x = po[i];
    if (ed[fd(fa[x])]) g[i][ed[fd(fa[x])]] = 1;
    x = ff[po[i]];
    while (x) {
      if (ed[x]) {
        g[i][ed[x]] = 1;
        break;
      }
      if (ed[fd(x)]) g[i][ed[fd(x)]] = 1;
      x = ff[x];
    }
  }
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) g[i][j] |= (g[i][k] && g[k][j]);
  for (int i = 1; i <= n; i++) {
    memset(vi, 0, sizeof(vi));
    fv(i);
  }
  for (int i = 1; i <= n; i++)
    if (mt[i]) m2[mt[i]] = i;
  for (int i = 1; i <= n; i++)
    if (!m2[i]) fz(i);
  for (int i = 1; i <= n; i++)
    if (v1[i] && !v2[i]) ans[++ct] = i;
  printf("%d\n", ct);
  for (int i = 1; i <= ct; i++) printf("%d ", ans[i]);
}
