#include <bits/stdc++.h>
using namespace std;
string str[755];
int n, ans[755], ch[10000005][2], tot, fa[10000005], fail[10000005],
    wch[10000005], d[755][755];
bool vis[1505];
void insert(int id) {
  int now = 0, m = str[id].size();
  for (int i = 0; i < m; i++) {
    int c = str[id][i] - 'a';
    if (!ch[now][c]) ch[now][c] = ++tot;
    now = ch[now][c];
  }
  fa[now] = now;
  wch[now] = id;
}
template <unsigned N, unsigned M>
struct Maxflow {
  int const inf = 1e9;
  int maxflow, s, t, tot = 1, target[M], pre[M], last[N], cap[M], deep[N],
                     cur[N];
  queue<int> q;
  void add(int x, int y, int z) {
    target[++tot] = y;
    pre[tot] = last[x];
    last[x] = tot;
    cap[tot] = z;
    target[++tot] = x;
    pre[tot] = last[y];
    last[y] = tot;
  }
  bool bfs() {
    for (int i = s; i <= t; i++) deep[i] = 0, cur[i] = last[i];
    q.push(s);
    while (!q.empty()) {
      int now = q.front();
      q.pop();
      for (int i = last[now]; i; i = pre[i]) {
        int tar = target[i];
        if (tar != s && cap[i] && (!deep[tar]))
          deep[tar] = deep[now] + 1, q.push(tar);
      }
    }
    return deep[t];
  }
  int dfs(int x, int lim) {
    if ((!lim) || x == t) return lim;
    int flow = 0;
    for (int i = cur[x]; i; cur[x] = i, i = pre[i]) {
      int tar = target[i];
      if (cap[i] && deep[tar] == deep[x] + 1) {
        int d = dfs(tar, min(lim, cap[i]));
        cap[i] -= d;
        cap[i ^ 1] += d;
        lim -= d;
        flow += d;
        if (!lim) break;
      }
    }
    return flow;
  }
  void dfs2(int x) {
    vis[x] = 1;
    for (int i = last[x]; i; i = pre[i]) {
      int tar = target[i];
      if (tar == s || tar == t || vis[tar] || cap[i]) continue;
      dfs2(tar);
    }
  }
  void dinic() {
    while (bfs()) maxflow += dfs(s, inf);
  }
  void work() {
    for (int i = n + 1; i <= 2 * n; i++) {
      bool flag = 0;
      for (int j = last[i]; j; j = pre[j])
        if (target[j] == t && cap[j]) {
          flag = 1;
          break;
        }
      if (!flag) continue;
      dfs2(i);
    }
    for (int i = 1; i <= n; i++)
      if ((!vis[i]) && vis[i + n]) ans[i] = 1;
  }
};
Maxflow<1505, 5000005> g;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> str[i];
    insert(i);
  }
  queue<int> q;
  for (int i = 0; i <= 1; i++)
    if (ch[0][i]) q.push(ch[0][i]);
  while (q.size()) {
    int now = q.front();
    q.pop();
    if (!wch[now]) fa[now] = fa[fail[now]];
    for (int i = 0; i <= 1; i++)
      if (ch[now][i])
        fail[ch[now][i]] = ch[fail[now]][i], q.push(ch[now][i]);
      else
        ch[now][i] = ch[fail[now]][i];
  }
  for (int i = 1; i <= n; i++) {
    int now = 0;
    for (int j = 0; j < str[i].size(); j++) {
      if (wch[now]) d[i][wch[now]] = 1;
      now = ch[now][str[i][j] - 'a'];
      d[i][wch[fa[fail[now]]]] = 1;
    }
  }
  for (int k = 1; k <= n; k++) d[k][k] = 1;
  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++)
    for (int j = 1; j <= n; j++)
      if (i != j && d[i][j]) g.add(i, j + n, 1);
  g.t = 2 * n + 1;
  for (int i = 1; i <= n; i++) g.add(0, i, 1), g.add(i + n, g.t, 1);
  g.dinic();
  printf("%d\n", n - g.maxflow);
  g.work();
  for (int i = 1; i <= n; i++)
    if (ans[i]) printf("%d ", i);
  return 0;
}
