#include <bits/stdc++.h>
using namespace std;
int read() {
  int a = 0, fh = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') fh = -1;
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    a = a * 10 + c - 48;
    c = getchar();
  }
  return a * fh;
}
int n;
int add[10000005][2], cnt = 0;
int tag[10000005];
string s[755];
void ins(int id, string s) {
  int now = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (!add[now][s[i] - 'a']) add[now][s[i] - 'a'] = ++cnt;
    now = add[now][s[i] - 'a'];
  }
  tag[now] = id;
}
int q[10000005], fail[10000005], fa[10000005];
int G[755][755];
int mat[755 << 1], vis[755 << 1], ans;
void getfail() {
  int l = 1, r = 0;
  for (int i = 0; i < 2; ++i)
    if (add[0][i]) q[++r] = add[0][i];
  while (l <= r) {
    int first = q[l++];
    fa[first] = tag[fail[first]] ? fail[first] : fa[fail[first]];
    for (int i = 0; i < 2; ++i)
      if (!add[first][i])
        add[first][i] = add[fail[first]][i];
      else {
        q[++r] = add[first][i];
        fail[add[first][i]] = add[fail[first]][i];
      }
  }
}
bool dfs(int first) {
  if (vis[first]) return 0;
  vis[first] = 1;
  for (int i = 1; i <= n; ++i) {
    if (i == first) continue;
    if (G[first][i]) {
      if (!mat[i + n]) {
        mat[first] = i + n;
        mat[i + n] = first;
        ans++;
        return 1;
      } else {
        int v = mat[i + n];
        mat[first] = i + n;
        mat[i + n] = first;
        mat[v] = 0;
        if (dfs(v)) return 1;
        mat[first] = 0;
        mat[i + n] = v;
        mat[v] = i + n;
      }
    }
  }
  return 0;
}
void DFS(int first) {
  if (vis[first]) return;
  vis[first] = 1;
  for (int i = 1; i <= n; ++i) {
    if (G[first][i] && first != i) {
      vis[i + n] = 1;
      DFS(mat[i + n]);
    }
  }
}
signed main() {
  n = read();
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
    ins(i, s[i]);
  }
  getfail();
  for (int i = 1; i <= n; ++i) {
    int now = 0;
    for (int j = 0; j < s[i].size(); ++j) {
      now = add[now][s[i][j] - 'a'];
      G[i][tag[now]] = 1;
      G[i][tag[fa[now]]] = 1;
    }
  }
  for (int k = 1; k <= n; ++k)
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j)
        G[i][j] = max(G[i][j], min(G[i][k], G[k][j]));
  for (int i = 1; i <= n; ++i) {
    dfs(i);
    for (int j = 1; j <= n; ++j) vis[j] = 0;
  }
  for (int i = 1; i <= n; ++i) {
    if (!mat[i]) DFS(i);
  }
  cout << n - ans << endl;
  for (int i = 1; i <= n; ++i) {
    if (vis[i] && (!vis[i + n])) cout << i << " ";
  }
  return 0;
}
