#include <bits/stdc++.h>
using namespace std;
const int MAXN = 755;
string words[MAXN];
int n, ct = 0;
struct Node {
  Node *c[2], *f, *out;
  bool vis;
  vector<int> num;
  Node() {
    c[0] = c[1] = f = out = 0;
    vis = 0;
  }
};
Node *root;
void makeTrie() {
  root = new Node();
  for (int j = 0; j < n; ++j) {
    Node *here = root;
    string g = words[j];
    for (int i = 0; i < g.length(); ++i) {
      if (here->c[g[i] - 'a'] == 0) here->c[g[i] - 'a'] = new Node();
      here = here->c[g[i] - 'a'];
    }
    here->num.push_back(j);
  }
  for (int i = 0; i < 2; ++i) {
    if (root->c[i] == 0) root->c[i] = root;
  }
}
void makeFail() {
  queue<Node *> q;
  root->out = root;
  root->vis = 1;
  for (int i = 0; i < 2; ++i) {
    if ((root->c[i] != 0) && (root->c[i] != root)) {
      root->c[i]->f = root;
      root->c[i]->out = root;
      q.push(root->c[i]);
    }
  }
  while (!q.empty()) {
    Node *v = q.front();
    q.pop();
    for (int i = 0; i < 2; ++i) {
      if (v->c[i] == 0) continue;
      Node *here = v->c[i];
      Node *prev = v->f;
      while (prev->c[i] == 0) {
        prev = prev->f;
      }
      here->f = prev->c[i];
      here->out = (here->f->num.size() > 0) ? (here->f) : here->f->out;
      q.push(here);
    }
  }
}
bool poset[MAXN][MAXN];
void makePoset() {
  for (int i = 0; i < n; ++i) {
    string g = words[i];
    vector<Node *> clean;
    Node *here = root;
    for (int j = 0; j < g.length(); ++j) {
      while (here->c[g[j] - 'a'] == 0) here = here->f;
      here = here->c[g[j] - 'a'];
      Node *here2 = here;
      while (here2->vis == 0) {
        for (int k : here2->num) {
          poset[i][k] = 1;
          here2->vis = 1;
          clean.push_back(here2);
        }
        here2 = here2->out;
      }
    }
    for (Node *k : clean) k->vis = 0;
  }
}
bool visited[MAXN];
int match[MAXN], matchr[MAXN];
vector<int> adj[MAXN];
bool dfs(int x) {
  visited[x] = 1;
  for (int i : adj[x]) {
    if (match[i] == -1 || (!visited[match[i]] && dfs(match[i]))) {
      match[i] = x;
      return 1;
    }
  }
  return 0;
}
int matching() {
  int ans = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) {
      if (poset[i][j]) {
        if (poset[j][i] && j >= i) continue;
        adj[j].push_back(i);
      }
    }
  for (int i = 0; i < n; ++i) match[i] = matchr[i] = -1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) visited[j] = 0;
    ans += dfs(i);
  }
  for (int i = 0; i < n; ++i)
    if (match[i] != -1) matchr[match[i]] = i;
  return ans;
}
vector<int> antichain;
bool elim[MAXN];
bool chk[MAXN];
bool inside[MAXN];
void makeAntichain() {
  queue<int> last;
  for (int i = 0; i < n; ++i) {
    if (matchr[i] == -1) {
      last.push(i);
      inside[i] = true;
    }
  }
  int ct = 0;
  while (true) {
    if (ct >= 2000) break;
    int t = last.front();
    last.pop();
    if (elim[t]) {
      ct = 0;
      continue;
    }
    if (chk[t]) {
      last.push(t);
      ct++;
      continue;
    }
    chk[t] = true;
    ct = 0;
    for (int x : adj[t]) {
      elim[x] = true;
      if (match[x] != -1 && !inside[match[x]]) {
        last.push(match[x]);
        inside[match[x]] = true;
      }
    }
    last.push(t);
  }
  while (!last.empty()) {
    antichain.push_back(last.front());
    last.pop();
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> words[i];
  makeTrie();
  makeFail();
  makePoset();
  cout << n - matching() << endl;
  makeAntichain();
  for (int i = 0; i < antichain.size(); ++i) {
    cout << antichain[i] + 1 << ' ';
  }
  cout << endl;
}
