#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e7 + 3;
queue<int> q;
char s[maxn];
int ch[maxn][2], f[maxn], tag[maxn], tott;
int head[2002], tot = 1, deep[2002], cur[2002], l[2002], r[2002], ans, n;
int su[maxn];
bool a[752][752];
inline long long rd() {
  long long x = 0;
  char c = getchar();
  bool f = 0;
  while (!isdigit(c)) {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return f ? -x : x;
}
struct edge {
  int n, to, l;
} e[2002 * 2002];
inline void add(int u, int v, int l) {
  e[++tot].n = head[u];
  e[tot].to = v;
  head[u] = tot;
  e[tot].l = l;
  e[++tot].n = head[v];
  e[tot].to = u;
  head[v] = tot;
  e[tot].l = 0;
}
inline bool bfs(int s, int t) {
  memset(deep, 0, sizeof(deep));
  memcpy(cur, head, sizeof(cur));
  q.push(s);
  deep[s] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i; i = e[i].n) {
      int v = e[i].to;
      if (!deep[v] && e[i].l) {
        deep[v] = deep[u] + 1;
        q.push(v);
      }
    }
  }
  return deep[t];
}
int dfs(int u, int t, int l) {
  if (u == t || !l) return l;
  int f, flow = 0;
  for (int &i = cur[u]; i; i = e[i].n) {
    int v = e[i].to;
    if (deep[u] + 1 == deep[v] && (f = dfs(v, t, min(l, e[i].l)))) {
      flow += f;
      e[i].l -= f;
      e[i ^ 1].l += f;
      l -= f;
      if (!l) break;
    }
  }
  return flow;
}
inline void insert(int id, int n) {
  int now = 0;
  l[id] = r[id - 1] + 1;
  r[id] = r[id - 1];
  for (int i = 1; i <= n; ++i) {
    if (!ch[now][s[i] - 'a']) ch[now][s[i] - 'a'] = ++tott;
    now = ch[now][s[i] - 'a'];
    su[++r[id]] = now;
  }
  tag[now] = id;
}
inline void get_fail() {
  for (int i = 0; i < 2; ++i)
    if (ch[0][i]) q.push(ch[0][i]);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < 2; ++i) {
      if (ch[u][i]) {
        f[ch[u][i]] = ch[f[u]][i];
        q.push(ch[u][i]);
        if (!tag[ch[u][i]] && tag[f[ch[u][i]]]) {
          tag[ch[u][i]] = tag[f[ch[u][i]]];
        }
      } else
        ch[u][i] = ch[f[u]][i];
    }
  }
}
inline void work(int id) {
  for (int i = l[id]; i <= r[id]; ++i) {
    int x = su[i];
    if (tag[x]) a[id][tag[x]] = 1;
  }
  if (f[su[r[id]]]) a[id][tag[f[su[r[id]]]]] = 1;
}
int main() {
  n = rd();
  for (int i = 1; i <= n; ++i) {
    scanf("%s", s + 1);
    insert(i, strlen(s + 1));
  }
  get_fail();
  for (int i = 1; i <= n; ++i) {
    work(i);
  }
  for (int k = 1; k <= n; ++k)
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j) a[i][j] |= a[i][k] & a[k][j];
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j)
      if (i != j && a[i][j]) {
        add(i, j + n, 1);
      }
  }
  for (int i = 1; i <= n; ++i) {
    add(0, i, 1);
    add(i + n, 2 * n + 1, 1);
  }
  while (bfs(0, 2 * n + 1)) ans += dfs(0, 2 * n + 1, 1e9);
  printf("%d\n", n - ans);
  for (int i = 1; i <= n; ++i) {
    if (deep[i] && !deep[i + n]) printf("%d ", i);
  }
  return 0;
}
