#include <bits/stdc++.h>
using namespace std;
const int N = 753, MXN = 10000007, SGM = 2;
int n, MC[N * 2];
bool M[N * 2], VC[N * 2], E[N][N];
vector<int> Adj[N * 2];
int ts, C[MXN][SGM], Suf[MXN], Qu[MXN], AC[MXN];
string S[N];
inline void Add(string &ss, int j) {
  int id = 0;
  for (int i = 0; i < (int)ss.size(); i++) {
    if (!C[id][ss[i] - 'a']) C[id][ss[i] - 'a'] = ++ts;
    id = C[id][ss[i] - 'a'];
  }
  AC[id] = j;
}
inline void AhoCorasick() {
  int l = 0, r = 0;
  for (int i = 0; i < SGM; i++)
    if (C[0][i]) Qu[r++] = C[0][i];
  while (r - l) {
    int id = Qu[l++];
    for (int i = 0; i < SGM; i++) {
      if (!C[id][i])
        C[id][i] = C[Suf[id]][i];
      else
        Qu[r++] = C[id][i], Suf[C[id][i]] = C[Suf[id]][i];
    }
    if (!AC[id]) AC[id] = AC[Suf[id]];
  }
}
bool DFS(int v) {
  if (M[v]) return 0;
  M[v] = 1;
  for (int u : Adj[v])
    if (MC[u] == -1 || DFS(MC[u])) return (MC[u] = v, MC[v] = u), 1;
  return 0;
}
void DFS2(int v) {
  VC[v] = 1;
  for (int u : Adj[MC[v]])
    if (MC[u] != -1 && !VC[u]) DFS2(u);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> S[i], Add(S[i], i);
  AhoCorasick();
  for (int i = 1; i <= n; i++) {
    int id = 0;
    for (int j = 0; j < (int)S[i].size(); j++) {
      id = C[id][S[i][j] - 'a'];
      if (AC[id] && AC[id] != i)
        E[i][AC[id]] = 1;
      else if (AC[id] == i && AC[Suf[id]])
        E[i][AC[Suf[id]]] = 1;
    }
  }
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) E[i][j] |= (E[i][k] & E[k][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (i != j && E[i][j]) Adj[i + n].push_back(j), Adj[j].push_back(i + n);
  memset(MC, -1, sizeof(MC));
  while (N) {
    bool NotDone = 0;
    memset(M, 0, sizeof(M));
    for (int i = 1; i <= n + n; i++)
      if (MC[i] == -1 && !M[i]) NotDone |= DFS(i);
    if (!NotDone) break;
  }
  for (int i = 1; i <= n + n; i++)
    if (MC[i] == -1)
      for (int u : Adj[i])
        if (MC[u] != -1) DFS2(u);
  for (int i = 1; i <= n + n; i++)
    if (MC[i] != -1 && !VC[i] && !VC[MC[i]]) VC[i] = 1;
  vector<int> vec;
  for (int i = 1; i <= n; i++)
    if (!VC[i] && !VC[i + n]) vec.push_back(i);
  printf("%d\n", (int)vec.size());
  for (int v : vec) printf("%d ", v);
  return 0;
}
