#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void Read(T &x) {
  int f = 1;
  char t = getchar();
  while (t < '0' || t > '9') {
    if (t == '-') f = -1;
    t = getchar();
  }
  x = 0;
  while (t >= '0' && t <= '9') {
    x = x * 10 + t - '0';
    t = getchar();
  }
  x *= f;
}
template <class T>
inline void chkmin(T &x, T y) {
  if (x > y) x = y;
}
template <class T>
inline void chkmax(T &x, T y) {
  if (x < y) x = y;
}
const int maxn = 1005;
const int maxl = 10000005;
const int maxm = 1000005;
int flag[maxl];
queue<int> q;
struct aho {
  struct node {
    int c[2];
    int fail;
    int last;
    node() { c[0] = c[1] = fail = last = 0; }
  };
  int sz;
  node T[maxl];
  aho() { sz = 1; }
  int insert(string &str, int id);
  void getlink(string &res, int id);
  void build(void);
};
struct graph {
  int n;
  int fst[maxn];
  int v[maxm];
  int nxt[maxm];
  int e_cn;
  bool adj[maxn][maxn];
  int match[maxn << 1];
  bool vis[maxn << 1];
  bool fin[maxn << 1];
  graph() {
    memset(fst, 0, sizeof(fst));
    memset(adj, 0, sizeof(adj));
    memset(match, 0, sizeof(match));
    e_cn = 0;
  }
  void addedge(int x, int y) {
    e_cn++, v[e_cn] = y;
    nxt[e_cn] = fst[x], fst[x] = e_cn;
  }
  bool go(int cn) {
    for (int i = fst[cn]; i; i = nxt[i]) {
      if (!vis[v[i]]) {
        vis[v[i]] = true;
        if (!match[v[i]] || go(match[v[i]])) {
          match[v[i]] = cn;
          match[cn] = v[i];
          return true;
        }
      }
    }
    return false;
  }
  void rebuild() {
    for (int i = 1; i <= n; i++) adj[i][i] = false;
    for (int k = 1; k <= n; k++) {
      for (int i = 1; i <= n; i++) {
        if (!adj[i][k]) continue;
        for (int j = 1; j <= n; j++) {
          adj[i][j] |= (adj[i][k] & adj[k][j]);
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        if (i != j && adj[i][j]) {
          addedge(i, j + n);
        }
      }
    }
  }
  int hungary() {
    int res = 0;
    for (int i = 1; i <= n; i++) {
      memset(vis, 0, sizeof(vis));
      res += go(i);
    }
    return res;
  }
  void dfs(int cn) {
    for (int i = fst[cn]; i; i = nxt[i]) {
      if (!fin[v[i]]) {
        fin[v[i]] = true;
        fin[match[v[i]]] = false;
        dfs(match[v[i]]);
      }
    }
  }
  void printplan() {
    vector<int> ans;
    memset(fin, 0, sizeof(fin));
    for (int i = 1; i <= n; i++) {
      if (match[i]) {
        fin[i] = true;
      }
    }
    for (int i = 1; i <= n; i++) {
      if (!match[i]) {
        dfs(i);
      }
    }
    for (int i = 1; i <= n; i++) {
      if (!fin[i] && !fin[i + n]) {
        ans.push_back(i);
      }
    }
    for (int i = 0; i < (int)ans.size(); i++) {
      printf("%d ", ans[i]);
    }
    printf("\n");
  }
};
int n;
aho s;
string str[maxn];
graph g1;
void input() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> str[i];
    s.insert(str[i], i);
  }
}
int aho::insert(string &str, int id) {
  int cn = 1;
  for (int i = 0; str[i]; i++) {
    if (!T[cn].c[str[i] - 'a']) {
      T[cn].c[str[i] - 'a'] = ++sz;
    }
    cn = T[cn].c[str[i] - 'a'];
  }
  assert(flag[cn] == 0);
  if (!flag[cn]) {
    flag[cn] = id;
  }
  return cn;
}
void aho::getlink(string &str, int id) {
  int cn = 1;
  for (int i = 0; str[i]; i++) {
    cn = T[cn].c[str[i] - 'a'];
    if (flag[cn]) {
      g1.adj[id][flag[cn]] = true;
    }
    if (flag[T[cn].last]) {
      g1.adj[id][flag[T[cn].last]] = true;
    }
  }
}
void aho::build() {
  while (!q.empty()) q.pop();
  for (int i = 0; i < 2; i++) T[0].c[i] = 1;
  q.push(1);
  while (!q.empty()) {
    int cn = q.front();
    q.pop();
    for (int i = 0; i < 2; i++) {
      if (!T[cn].c[i]) {
        T[cn].c[i] = T[T[cn].fail].c[i];
        continue;
      }
      int cur = T[cn].fail;
      while (!T[cur].c[i]) cur = T[cur].fail;
      T[T[cn].c[i]].fail = T[cur].c[i];
      T[T[cn].c[i]].last =
          flag[T[cur].c[i]] ? T[cur].c[i] : T[T[cur].c[i]].last;
      q.push(T[cn].c[i]);
    }
  }
}
void prepare() {
  s.build();
  for (int i = 1; i <= n; i++) s.getlink(str[i], i);
  g1.n = n;
  g1.rebuild();
}
void solve() {
  printf("%d\n", n - g1.hungary());
  g1.printplan();
}
int main() {
  input();
  prepare();
  solve();
  return 0;
}
