#include <bits/stdc++.h>
namespace modular {
const int MOD = 1000000007;
inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }
inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }
inline int mul(int x, int y) { return 1LL * x * y % MOD; }
inline int qpow(int x, int y) {
  int ans = 1;
  for (; y; y >>= 1, x = mul(x, x))
    if (y & 1) ans = mul(ans, x);
  return ans;
}
};  // namespace modular
namespace Base {
template <typename Tp>
inline Tp input() {
  Tp x = 0, y = 1;
  char c = getchar();
  while ((c < '0' || '9' < c) && c != EOF) {
    if (c == '-') y = -1;
    c = getchar();
  }
  if (c == EOF) return 0;
  while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x *= y;
}
template <typename Tp>
inline void read(Tp &x) {
  x = input<Tp>();
}
template <typename Tp>
inline void chmax(Tp &x, Tp y) {
  x < y ? x = y : 0;
}
template <typename Tp>
inline void chmin(Tp &x, Tp y) {
  x > y ? x = y : 0;
}
};  // namespace Base
using namespace Base;
int N;
int lmc[757], rmc[757];
bool g[757][757], vis[757], lvis[757], rvis[757];
char s[10000007];
std::string str[757];
struct ACAM {
  int sz, ch[10000007][2], fail[10000007], id[10000007];
  std::queue<int> q;
  void ins(char *s, int len, int pos) {
    int p = 0, c;
    for (int i = 1; i <= len; ++i) {
      c = s[i] - 'a';
      if (!ch[p][c]) ch[p][c] = ++sz;
      p = ch[p][c];
    }
    id[p] = pos;
  }
  void getfail() {
    for (int i = 0; i < 2; ++i) {
      if (ch[0][i]) {
        fail[ch[0][i]] = 0;
        q.push(ch[0][i]);
      }
    }
    while (!q.empty()) {
      int x = q.front();
      q.pop();
      for (int i = 0; i < 2; ++i) {
        if (!ch[x][i]) {
          ch[x][i] = ch[fail[x]][i];
          continue;
        }
        int j = fail[x];
        while (j && !ch[j][i]) j = fail[j];
        fail[ch[x][i]] = ch[j][i];
        if (!id[ch[x][i]]) id[ch[x][i]] = id[fail[ch[x][i]]];
        q.push(ch[x][i]);
      }
    }
  }
  void addedge(int pos) {
    int p = 0;
    for (char c : str[pos]) {
      p = ch[p][c - 'a'];
      if (id[p]) g[pos][id[p]] = true;
      if (id[fail[p]]) g[pos][id[fail[p]]] = true;
    }
  }
} tr;
bool dfs(int x) {
  for (int i = 1; i <= N; ++i)
    if (g[x][i] && !vis[i]) {
      vis[i] = true;
      if (!rmc[i] || dfs(rmc[i])) {
        rmc[i] = x, lmc[x] = i;
        return true;
      }
    }
  return false;
}
void dfs2(int x) {
  rvis[x] = true;
  for (int i = 1; i <= N; ++i)
    if (g[i][x] && !lvis[i]) lvis[i] = true, dfs2(lmc[i]);
}
int main() {
  read(N);
  for (int i = 1; i <= N; ++i) {
    scanf("%s", s + 1);
    tr.ins(s, strlen(s + 1), i);
    str[i] = s + 1;
  }
  tr.getfail();
  for (int i = 1; i <= N; ++i) tr.addedge(i);
  for (int k = 1; k <= N; ++k)
    for (int i = 1; i <= N; ++i)
      for (int j = 1; j <= N; ++j) g[i][j] |= g[i][k] & g[k][j];
  for (int i = 1; i <= N; ++i) g[i][i] = false;
  int ans = 0;
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) vis[j] = false;
    ans += dfs(i);
  }
  printf("%d\n", N - ans);
  for (int i = 1; i <= N; ++i)
    if (!rmc[i]) dfs2(i);
  for (int i = 1; i <= N; ++i)
    if (!lvis[i] && rvis[i]) printf("%d ", i);
  puts("");
  return 0;
}
