#include <bits/stdc++.h>
int A[10000001][2], B[10000001], D[751], G[751], b[751], l, n, q[10000001], r,
    t, x;
unsigned int E[10000001];
bool a[751][751], c[751], d[751], e[751];
inline bool cmp(int u, int v) { return G[u] - G[u - 1] < G[v] - G[v - 1]; }
inline int add(char* C, int& i) {
  int u = 1;
  for (; C[i]; u = A[u][C[i++]])
    if (!A[u][C[i] -= 97]) A[u][C[i]] = ++t;
  return u;
}
void find(int u) {
  c[u] = true;
  for (int i = 1; i <= n; i++)
    if (a[u][i] && !d[i]) d[i] = true, find(b[i]);
}
bool dfs(int u) {
  c[u] = true;
  for (int i = 1; i <= n; i++)
    if (a[u][i] && (!b[i] || !c[b[i]] && dfs(b[i]))) return b[i] = u;
  return false;
}
char C[10000001];
int main() {
  scanf("%d", &n), *A[0] = A[0][1] = q[r++] = t = 1, x = n;
  for (int i = 1; i <= n; i++)
    scanf("%s", C + G[i - 1]),
        G[E[D[i] = add(C + G[i - 1], G[i])] = i] += G[i - 1];
  while (l < r)
    *A[t = q[l++]] ? B[q[r++] = *A[t]] = *A[B[t]] : *A[t] = *A[B[t]],
                                A[t][1] ? B[q[r++] = A[t][1]] = A[B[t]][1]
                                        : A[t][1] = A[B[t]][1];
  for (int i = 1; i < r; i++)
    if (!E[q[i]]) E[q[i]] = E[B[q[i]]];
  for (int i = 1; i <= n; a[i][i] = true, i++)
    for (int j = G[i - 1], k = 1; j < G[i];)
      if (k = A[k][C[j++]], E[k] == i ? E[B[k]] : E[k])
        a[i][E[k] == i ? E[B[k]] : E[k]] = true;
  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++) a[i][i] = false;
  for (int i = 1; i <= n; i++) memset(c + 1, false, n), x -= e[i] = dfs(i);
  printf("%d\n", x), memset(c + 1, false, n);
  for (int i = 1; i <= n; i++)
    if (!e[i]) find(i);
  for (int i = 1; i <= n; i++)
    if (c[i] && !d[i]) printf("%d%c", i, --x ? ' ' : '\n');
  return 0;
}
