#include <bits/stdc++.h>
using namespace std;
const int maxm = 1e7 + 9;
const int maxn = 2e6 + 9;
const int N = 1000 + 9;
const int mod = 20100403;
const int inf = 0x3f3f3f3f;
const int base = 131;
const double eps = 1e-4;
int n;
struct Edge {
  int come, to, from, flow;
} edge[maxn];
int last[maxn], cnt = 1;
int S, T, tot = 0;
bool dis[N][N];
int dep[maxn], max_flow;
int ans = 0;
bool v1[maxn], v2[maxn];
int link[maxn];
string B[751];
char A[maxm];
int ch[maxm][2], fail[maxm], num = 0, id[maxm];
int read() {
  int a = 1, b = 0;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') a = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    b = (b << 1) + (b << 3) + (c ^ '0');
    c = getchar();
  }
  return a * b;
}
void print(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
inline void add(int x, int y, int z) {
  edge[++cnt].to = y;
  edge[cnt].flow = z;
  edge[cnt].come = x;
  edge[cnt].from = last[x];
  last[x] = cnt;
}
void insert(char *s, int th) {
  int len = strlen(s), now = 0;
  for (int i = (0); i <= (len - 1); ++i) {
    int j = s[i] - 'a';
    if (!ch[now][j]) ch[now][j] = ++num;
    now = ch[now][j];
  }
  id[now] = th;
}
void getfail() {
  queue<int> q;
  fail[0] = 0;
  for (int i = (0); i <= (1); ++i)
    if (ch[0][i]) q.push(ch[0][i]), fail[ch[0][i]] = 0;
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (int i = (0); i <= (1); ++i) {
      if (!ch[now][i]) {
        ch[now][i] = ch[fail[now]][i];
        continue;
        ;
      }
      q.push(ch[now][i]);
      int j = fail[now];
      while (j && !ch[j][i]) j = fail[j];
      fail[ch[now][i]] = ch[j][i];
      if (!id[ch[now][i]]) id[ch[now][i]] = id[fail[ch[now][i]]];
    }
  }
}
void find(int x) {
  int len = B[x].length(), now = 0;
  for (int i = (0); i <= (len - 1); ++i) {
    int j = B[x][i] - 'a';
    now = ch[now][j];
    if (id[now]) dis[x][id[now]] = 1;
    if (id[fail[now]]) dis[x][id[fail[now]]] = 1;
  }
}
bool bfs() {
  queue<int> q;
  memset(dep, -1, sizeof(dep));
  q.push(S);
  dep[S] = 0;
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (int i = last[now]; i; i = edge[i].from) {
      int to = edge[i].to;
      if (dep[to] == -1 && edge[i].flow) {
        dep[to] = dep[now] + 1;
        q.push(to);
      }
    }
  }
  return dep[T] != -1;
}
int dfs(int now, int lim) {
  if (now == T) return lim;
  int sum = 0;
  for (int i = last[now]; i; i = edge[i].from) {
    int to = edge[i].to;
    if (dep[to] == dep[now] + 1 && edge[i].flow) {
      int tmp = dfs(to, min(lim - sum, edge[i].flow));
      if (tmp) {
        edge[i].flow -= tmp;
        edge[i ^ 1].flow += tmp;
        sum += tmp;
        if (sum == lim) return sum;
      }
    }
  }
  if (sum == 0) dep[now] = -1;
  return sum;
}
void Dinic() {
  max_flow = 0;
  while (bfs()) {
    max_flow += dfs(S, inf);
  }
}
void Dfs(int now) {
  if (v1[now]) return;
  v1[now] = 1;
  for (int i = last[now]; i; i = edge[i].from) {
    if (!v2[edge[i].to - n]) v2[edge[i].to - n] = 1, Dfs(link[edge[i].to]);
  }
}
int main() {
  int x, y;
  n = read();
  for (int i = (1); i <= (n); ++i) {
    scanf("%s", A);
    insert(A, i);
    B[i] = A;
  }
  getfail();
  for (int i = (1); i <= (n); ++i) find(i);
  for (int k = (1); k <= (n); ++k)
    for (int i = (1); i <= (n); ++i)
      for (int j = (1); j <= (n); ++j) dis[i][j] |= dis[i][k] & dis[k][j];
  for (int i = (1); i <= (n); ++i) dis[i][i] = 0;
  S = 2 * n + 1, T = S + 1;
  for (int i = (1); i <= (n); ++i) {
    add(S, i, 1);
    add(i, S, 0);
    add(i + n, T, 1);
    add(T, i + n, 0);
    for (int j = (1); j <= (n); ++j) {
      if (dis[i][j]) {
        add(i, j + n, 1);
        add(j + n, i, 0);
      }
    }
  }
  Dinic();
  ans = n - max_flow;
  int nn;
  print(ans);
  putchar('\n');
  ;
  for (int i = (2); i <= (cnt); ++i) {
    if (edge[i].come <= n && edge[i].to <= 2 * n && edge[i].flow == 0)
      link[edge[i].to] = edge[i].come;
  }
  for (int i = last[S]; i; i = edge[i].from) {
    if (edge[i].flow) Dfs(edge[i].to);
  }
  for (int i = (1); i <= (n); ++i)
    if (v1[i] && !v2[i]) print(i), putchar(' ');
  return 0;
}
