#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 50;
const int NN = 760;
char s[N];
int nx[N][2], To[N], id[N], fl[N], cnt = 1, n;
int st[NN], ed[NN], mt[NN];
bool mp[NN][NN], vis[NN], tag[NN], use[NN][2];
queue<int> q;
void ins(int st, int l, int ID) {
  int nw = 1;
  for (int i = st; i <= st + l - 1; i++) {
    int ch = s[i] - 'a';
    if (!nx[nw][ch]) nx[nw][ch] = ++cnt;
    nw = nx[nw][ch];
  }
  id[nw] = ID;
}
void getf() {
  q.push(1);
  fl[1] = 1;
  while (!q.empty()) {
    int t = q.front();
    q.pop();
    if (id[fl[t]])
      To[t] = fl[t];
    else
      To[t] = To[fl[t]];
    for (int i = 0; i <= 1; i++)
      if (nx[t][i]) {
        q.push(nx[t][i]);
        fl[nx[t][i]] = t == 1 ? 1 : nx[fl[t]][i];
      } else {
        nx[t][i] = t == 1 ? 1 : nx[fl[t]][i];
      }
  }
}
void build() {
  for (int i = 1; i <= n; i++) {
    for (int nw = 1, j = st[i]; j <= ed[i]; ++j) {
      int ch = s[j] - 'a';
      nw = nx[nw][ch];
      for (int t = id[nw] ? nw : To[nw]; t && !mp[i][id[t]]; t = To[t])
        mp[i][id[t]] = 1;
    }
  }
  for (int i = 1; i <= n; i++) mp[i][i] = 0;
}
bool efind(int x) {
  for (int i = 1; i <= n; i++)
    if (mp[x][i] && !vis[i]) {
      vis[i] = 1;
      if (!mt[i] || efind(mt[i])) {
        mt[i] = x;
        return 1;
      }
    }
  return 0;
}
void mark(int x) {
  if (use[x][0]) return;
  use[x][0] = 1;
  for (int i = 1; i <= n; i++)
    if (mp[x][i] && !use[i][1]) {
      use[i][1] = 1;
      mark(mt[i]);
    }
}
void solve() {
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    memset(vis, 0, sizeof(vis));
    if (efind(i))
      ++ans;
    else
      tag[i] = 1;
  }
  printf("%d\n", n - ans);
  for (int i = 1; i <= n; i++)
    if (tag[i]) mark(i);
  for (int i = 1; i <= n; i++) {
    if (use[i][0] && !use[i][1]) printf("%d ", i);
  }
  puts("");
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    st[i] = ed[i - 1] + 1;
    scanf("%s", s + st[i]);
    int l = strlen(s + st[i]);
    ins(st[i], l, i);
    ed[i] = ed[i - 1] + l;
  }
  getf();
  build();
  solve();
  return 0;
}
