#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const long long mod = 998244353;
const int inf = 1e9;
bool vis[1700];
int in[760];
bool adj[760][760];
bool trans[760][760];
bool rep[760];
int tot = 0;
int fin(int i) {
  if (in[i] != i) {
    in[i] = fin(in[i]);
  }
  return in[i];
}
struct edkarp {
  vector<vector<int>> cap;
  vector<vector<int>> eds;
  int n, m;
  void init(int _n) {
    n = _n;
    m = (n - 2) / 2;
    cap.assign(n, vector<int>(n, 0));
    eds.assign(n, vector<int>(0));
  }
  void add(int u, int v, int c) {
    eds[u].emplace_back(v);
    eds[v].emplace_back(u);
    cap[u][v] = c;
  }
  int bfs(int st, int tar, vector<int>& p) {
    fill(p.begin(), p.end(), -1);
    p[st] = -2;
    queue<pair<int, int>> q;
    q.push(make_pair(st, inf));
    while (!q.empty()) {
      int i = q.front().first, flow = q.front().second;
      q.pop();
      for (auto& x : eds[i]) {
        if (p[x] == -1 && cap[i][x]) {
          p[x] = i;
          int nf = min(flow, cap[i][x]);
          if (x == tar) {
            return nf;
          }
          q.push(make_pair(x, nf));
        }
      }
    }
    return 0;
  }
  int maxflow(int st, int tar) {
    vector<int> p(n);
    int flow = 0;
    int nf;
    while (nf = bfs(st, tar, p)) {
      flow += nf;
      int cr = tar;
      while (cr != st) {
        cap[p[cr]][cr] -= nf;
        cap[cr][p[cr]] += nf;
        cr = p[cr];
      }
    }
    return flow;
  }
  void dfs(int i) {
    ;
    vis[i] = 1;
    for (auto& x : eds[i])
      if (!vis[x] && x != 0 && x != n - 1) {
        if (cap[i][x]) dfs(x);
      }
  }
  void sten() {
    fill(vis, vis + n, false);
    for (int i = 1; i <= m; i++) {
      for (int j = 1; j <= m; j++) {
        if (cap[j + m][i]) {
          in[i] = 1;
          break;
        }
      }
    }
    for (int i = 1; i <= m; i++) {
      if (in[i] == 0 && !vis[i]) dfs(i);
    }
  }
};
const int K = 2;
struct node {
  node* ch[K];
  node* p;
  node* nt;
  node* sl;
  int ind = -1;
  bool pch;
  node(node* p = NULL, bool b = false) : p(p), pch(b) {
    sl = NULL;
    ch[0] = NULL;
    ch[1] = NULL;
    nt = NULL;
  }
};
template <class node>
struct ahoc {
  node* root = NULL;
  edkarp fl;
  ahoc() { root = new node(); }
  void init(int n) { fl.init(n); }
  inline int getin(char c) { return c - 'a'; }
  void ins(string const& s, int i) {
    node* cr = root;
    for (char c : s) {
      int z = getin(c);
      if (!cr->ch[z]) {
        cr->ch[z] = new node(cr, c == 'b');
      }
      cr = cr->ch[z];
    }
    if (cr->ind == -1)
      cr->ind = i;
    else
      rep[i] = 1, tot++;
  }
  void trav(string const& s, int i) {
    node* cr = root;
    for (char c : s) {
      if (cr->ind != -1) {
        adj[cr->ind][i] = trans[cr->ind][i] = true;
      }
      int z = getin(c);
      cr = cr->ch[z];
      node* tmp = get_nt(cr);
      if (tmp != root) adj[tmp->ind][i] = trans[tmp->ind][i] = true;
    }
  }
  node* get_sl(node* cr) {
    if (!cr->sl) {
      if (cr == root || cr->p == root)
        cr->sl = root;
      else
        cr->sl = go(get_sl(cr->p), cr->pch);
    }
    return cr->sl;
  }
  node* go(node* cr, bool c) {
    int z = c;
    if (!cr->ch[z]) {
      if (cr == root)
        cr->ch[z] = root;
      else
        cr->ch[z] = go(get_sl(cr), c);
    }
    return cr->ch[z];
  }
  node* get_nt(node* cr) {
    if (!cr->nt) {
      node* tmp = get_sl(cr);
      if (tmp == root) {
        cr->nt = root;
      } else if (tmp->ind == -1) {
        cr->nt = get_nt(tmp);
      } else {
        cr->nt = tmp;
      }
    }
    return cr->nt;
  }
};
string s[760];
int n;
ahoc<node> fo;
void dfs(int i) {
  vis[i] = 1;
  for (int j = (int)1; j != (int)n + 1; j = j + 1) {
    if (j == i) continue;
    if (!trans[i][j]) continue;
    if (!vis[j]) dfs(j);
    for (int k = (int)1; k != (int)n + 1; k = k + 1) {
      if (k == i || k == j) continue;
      if (!trans[j][k]) continue;
      trans[i][k] = 1;
    }
  }
}
void solve() {
  cin >> n;
  for (int i = (int)1; i != (int)n + 1; i = i + 1) {
    cin >> s[i];
  }
  for (int i = (int)1; i != (int)n + 1; i = i + 1) {
    fo.ins(s[i], i);
  }
  fo.init(2 * n + 2);
  for (int i = (int)1; i != (int)n + 1; i = i + 1) {
    fo.trav(s[i], i);
    fo.fl.add(0, i, 1);
    fo.fl.add(n + i, 2 * n + 1, 1);
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i);
  }
  for (int i = (int)1; i != (int)n + 1; i = i + 1) {
    for (int j = (int)1; j != (int)n + 1; j = j + 1) {
      if (i == j) continue;
      if (trans[i][j]) {
        fo.fl.add(i, j + n, 1);
      }
    }
  }
  cout << n - tot - fo.fl.maxflow(0, 2 * n + 1) << '\n';
  fo.fl.sten();
  for (int i = 1; i <= n; i++) {
    if (vis[i] && !vis[i + n] && !rep[i]) cout << i << " ";
  }
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
