#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
inline void write(int x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
const int MAXM = 10000005, MAXN = 760;
int n;
bool G[MAXN][MAXN];
char s[MAXM];
int ch[MAXM][2], ed[MAXM], tot, pos[MAXN], fa[MAXM], fail[MAXM];
int fa_[MAXM];
inline void ins(char *s, int id) {
  int len = strlen(s), p = 1;
  for (int i = 0; i < len; i++) {
    if (!ch[p][s[i] - 'a']) {
      ch[p][s[i] - 'a'] = ++tot;
      fa[ch[p][s[i] - 'a']] = p;
    }
    p = ch[p][s[i] - 'a'];
  }
  ed[p] = id, pos[id] = p;
}
inline int findf(int x) { return x == fa_[x] ? x : (fa_[x] = findf(fa_[x])); }
inline void build() {
  queue<int> q;
  for (int i = 0; i < 2; i++)
    if (ch[1][i]) fail[ch[1][i]] = 1, q.push(ch[1][i]);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    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];
    }
  }
  for (int i = 1; i <= tot; i++) fa_[i] = ed[i] ? i : fail[i];
  for (int i = 1; i <= n; i++) {
    int p = pos[i];
    if (ed[findf(fail[p])]) G[i][ed[findf(fail[p])]] = 1;
    p = fa[p];
    while (p) {
      if (ed[p]) {
        G[i][ed[p]] = 1;
        break;
      }
      if (ed[findf(p)]) G[i][ed[findf(p)]] = 1;
      p = fa[p];
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      for (int k = 1; k <= n; k++) G[j][k] |= G[j][i] & G[i][k];
}
int match_rev[MAXN];
int match_for[MAXN];
bool vis[MAXN];
bool vis1[MAXN], vis2[MAXN];
bool Hungary(int x) {
  if (vis[x]) return false;
  vis[x] = true;
  for (int i = 1; i <= n; i++)
    if (G[x][i] && (!match_rev[i] || Hungary(match_rev[i])))
      return match_rev[i] = x, true;
  return false;
}
void dfs(int x) {
  if (vis1[x]) return;
  vis1[x] = true;
  for (int i = 1; i <= n; i++)
    if (G[x][i] && match_for[x] != i && !vis2[i]) {
      vis2[i] = true;
      if (match_rev[i]) dfs(match_rev[i]);
    }
}
int ans[MAXN], cnt;
int main() {
  register int i, j, k;
  scanf("%d", &n);
  for (tot = i = 1; i <= n; ++i) scanf("%s", s), ins(s, i);
  build();
  for (int i = 1; i <= n; i++) memset(vis, false, sizeof(vis)), Hungary(i);
  for (int i = 1; i <= n; i++)
    if (match_rev[i]) match_for[match_rev[i]] = i;
  for (int i = 1; i <= n; i++)
    if (!match_for[i]) dfs(i);
  for (int i = 1; i <= n; i++)
    if (vis1[i] && !vis2[i]) ans[++cnt] = i;
  printf("%d\n", cnt);
  for (int i = 1; i <= cnt; i++) printf("%d ", ans[i]);
  return 0;
}
