#include <bits/stdc++.h>
using namespace std;
char s[10000007];
int n;
int idcnt = 1, ch[10000007][2], fa[10000007], lst[10000007], up[10000007];
int id[10000007], pos[1003];
int res[1003], ans;
int d[1003][1003];
void ins(int id) {
  int p = 1, len = strlen(s + 1);
  for (int i = 1, c; i <= len; ++i) {
    if (!ch[p][c = s[i] == 'a']) up[ch[p][c] = ++idcnt] = p;
    p = ch[p][c];
  }
  (!::id[p]) ? ::id[pos[id] = p] = id : --ans;
}
queue<int> q;
void getfail() {
  if (ch[1][0]) q.push(ch[1][0]), fa[ch[1][0]] = 1;
  if (ch[1][1]) q.push(ch[1][1]), fa[ch[1][1]] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int c = 0, v; c < 2; ++c)
      if (v = ch[u][c]) {
        int p = fa[u];
        while (p && !ch[p][c]) p = fa[p];
        fa[v] = p ? ch[p][c] : 1, q.push(v);
        lst[v] = id[fa[v]] ? id[fa[v]] : lst[fa[v]];
      }
  }
  for (int i = 1; i <= n; ++i) {
    int p = pos[i];
    while (p) d[lst[p]][i] = d[id[p]][i] = 1, p = up[p];
  }
}
void floyd() {
  for (int k = 1; k <= n; ++k)
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j) d[i][j] |= d[i][k] & d[k][j];
  for (int i = 1; i <= n; ++i) d[i][i] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j)
      if (d[i][j] & d[j][i]) exit(1);
  }
}
bool vis[1003];
int nxt[1003];
bool dfs(int u) {
  for (int v = 1; v <= n; ++v)
    if (!vis[v] && pos[v] && d[u][v]) {
      vis[v] = 1;
      if (!nxt[v] || dfs(nxt[v])) return nxt[v] = u, 1;
    }
  return 0;
}
int main() {
  scanf("%d", &n), ans = n;
  for (int i = 1; i <= n; ++i) scanf("%s", s + 1), ins(i);
  getfail(), floyd();
  for (int i = 1; i <= n; ++i)
    if (pos[i]) ans -= dfs(i), memset(vis, 0, sizeof vis);
  int tans = ans;
  printf("%d\n", ans);
  ans = 0;
  for (int i = 1; i <= n; ++i)
    if (pos[i]) vis[nxt[i]] = 1;
  for (int i = 1; i <= n; ++i)
    if (pos[i] && !vis[i]) res[++ans] = i;
  if (tans != ans) exit(1);
  memset(vis, 0, sizeof vis);
  while (1) {
    int flg = 0;
    for (int j = 1; j <= n; ++j)
      if (pos[j] && !vis[j])
        for (int i = 1; i <= ans; ++i)
          if (pos[i] && d[res[i]][j]) {
            vis[j] = 1;
            break;
          }
    for (int i = 1; i <= ans; ++i)
      if (vis[res[i]]) {
        flg = 1;
        while (vis[res[i]]) res[i] = nxt[res[i]];
      }
    if (!flg) break;
  }
  for (int i = 1; i <= ans; ++i) printf("%d ", res[i]);
  return 0;
}
