#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int n, ch[10000005][2], tot = 1, h[N], cnt, fa[10000005], id[10000005], ans,
                        lk[N], to[N], v[N], ti, mx[N], my[N];
string s[755];
bitset<N> a[N];
struct qwe {
  int ne, to;
} e[N * N];
void add(int u, int v) {
  cnt++;
  e[cnt].ne = h[u];
  e[cnt].to = v;
  h[u] = cnt;
}
bool dfs(int u) {
  for (int i = h[u]; i; i = e[i].ne)
    if (v[e[i].to] != ti) {
      v[e[i].to] = ti;
      if (!lk[e[i].to] || dfs(lk[e[i].to])) {
        lk[e[i].to] = u, to[u] = e[i].to;
        return 1;
      }
    }
  return 0;
}
void wk(int u) {
  if (mx[u]) return;
  mx[u] = 1;
  for (int i = h[u]; i; i = e[i].ne)
    if (!my[e[i].to]) {
      my[e[i].to] = 1;
      wk(lk[e[i].to]);
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    int nw = 1;
    for (int j = 0; j < s[i].length(); j++) {
      if (!ch[nw][s[i][j] - 'a']) ch[nw][s[i][j] - 'a'] = ++tot;
      nw = ch[nw][s[i][j] - 'a'];
    }
    id[nw] = i;
  }
  queue<int> q;
  for (int i = 0; i < 2; i++) {
    if (ch[1][i])
      fa[ch[1][i]] = 1, q.push(ch[1][i]);
    else
      ch[1][i] = 1;
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < 2; i++) {
      if (ch[u][i]) {
        fa[ch[u][i]] = ch[fa[u]][i];
        q.push(ch[u][i]);
        if (!id[ch[u][i]]) id[ch[u][i]] = id[fa[ch[u][i]]];
      } else
        ch[u][i] = ch[fa[u]][i];
    }
  }
  for (int i = 1; i <= n; i++) {
    int nw = 1;
    for (int j = 0; j < s[i].length(); j++) {
      nw = ch[nw][s[i][j] - 'a'];
      if (id[nw] && id[nw] != i) a[i][id[nw]] = 1;
      if (id[fa[nw]] && id[fa[nw]]) a[i][id[fa[nw]]] = 1;
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (a[j][i]) a[j] |= a[i];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (i != j && a[i][j]) add(i, j);
  for (int i = 1; i <= n; i++) {
    ti++;
    if (dfs(i)) ans++;
  }
  printf("%d\n", n - ans);
  for (int i = 1; i <= n; i++)
    if (!to[i]) wk(i);
  for (int i = 1; i <= n; i++)
    if (mx[i] && !my[i]) printf("%d ", i);
  return 0;
}
