#include <bits/stdc++.h>
using namespace std;
const int N = 10000005, M = 755;
queue<int> Q;
int ne[N][2], q[N], fail[N], pre[N], n, m, at, cnt;
int ans, lp[M], rp[M], flag1[M], flag2[M], a[M][M], flag[M], match[N], id[M];
char s[N];
void build() {
  Q.push(1);
  while (!Q.empty()) {
    int now = Q.front();
    Q.pop();
    for (int i = 0; i < 2; i++)
      if (ne[now][i]) {
        Q.push(ne[now][i]);
        if (now == 1)
          fail[ne[now][i]] = 1;
        else
          fail[ne[now][i]] = ne[fail[now]][i];
        if (!pre[ne[now][i]]) pre[ne[now][i]] = pre[fail[ne[now][i]]];
      } else {
        if (now == 1)
          ne[now][i] = 1;
        else
          ne[now][i] = ne[fail[now]][i];
      }
  }
}
int dfs(int x) {
  for (int i = 1; i <= m; i++)
    if (i != x && a[x][i] && !flag[i]) {
      flag[i] = 1;
      if (!match[i] || dfs(match[i])) {
        match[i] = x;
        return 1;
      }
    }
  return 0;
}
void dfs2(int x) {
  for (int i = 1; i <= m; i++)
    if (i != x && a[x][i] && !flag2[i]) {
      flag2[i] = 1;
      flag1[match[i]] = 0;
      dfs2(match[i]);
    }
}
int main() {
  scanf("%d", &n);
  at = 1;
  for (int i = 1; i <= n; i++) {
    lp[i] = rp[i - 1];
    scanf("%s", s + lp[i]);
    rp[i] = strlen(s + lp[i]) + lp[i];
    int p = 1;
    for (int j = lp[i]; j < rp[i]; j++) {
      int x = s[j] - 'a';
      if (!ne[p][x]) ne[p][x] = ++at;
      p = ne[p][x];
    }
    if (!pre[p]) pre[p] = ++m, id[m] = i;
  }
  build();
  for (int i = 1; i <= m; i++) {
    int x = 1;
    for (int j = lp[id[i]]; j < rp[id[i]]; j++) {
      x = ne[x][s[j] - 'a'];
      if (j != rp[id[i]] - 1)
        a[pre[x]][i] = 1;
      else
        a[pre[fail[x]]][i] = 1;
    }
    a[i][i] = 1;
  }
  for (int k = 1; k <= m; k++)
    for (int i = 1; i <= m; i++)
      for (int j = 1; j <= m; j++) a[i][j] |= a[i][k] & a[k][j];
  for (int i = 1; i <= m; i++) {
    memset(flag, 0, sizeof(flag));
    ans += dfs(i);
  }
  printf("%d\n", m - ans);
  for (int i = 1; i <= m; i++) flag1[match[i]] = 1;
  for (int i = 1; i <= m; i++)
    if (!flag1[i]) dfs2(i);
  for (int i = 1; i <= m; i++)
    if (!flag1[i] && !flag2[i]) printf("%d ", id[i]);
}
