#include <bits/stdc++.h>
using namespace std;
void io() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(15);
}
const int MAXC = 2;
struct Node {
  Node* child[MAXC];
  Node* link;
  Node* prev_patt;
  int pch;
  Node* par;
  int ends;
  int node_num;
};
const int MAX = 1e7 + 5;
int foo = -1;
const int MAXN = 755;
int n;
vector<Node*> pathnodes[MAXN];
Node* new_node() {
  Node* ptr = new Node();
  for (int i = 0; i < MAXC; i++) {
    ptr->child[i] = NULL;
  }
  ptr->link = ptr->par = NULL;
  ptr->pch = ptr->ends = 0;
  ptr->node_num = ++foo;
  ptr->prev_patt = NULL;
  return ptr;
}
Node* root;
void add_string(string& s, int idx) {
  Node* cur = root;
  for (auto c : s) {
    Node*& v = cur->child[c - 'a'];
    if (v == NULL) {
      v = new_node();
      v->par = cur;
      v->pch = c - 'a';
    }
    cur = v;
    pathnodes[idx].push_back(cur);
  }
  cur->prev_patt = cur;
  cur->ends = idx;
}
int G[MAXN][MAXN];
queue<Node*> q;
void bfs() {
  root->link = root;
  for (int i = 0; i < MAXC; i++) {
    Node*& v = root->child[i];
    if (v != NULL) {
      v->link = root;
      q.push(v);
      if (v->prev_patt == NULL) {
        v->prev_patt = root;
      }
    }
  }
  root->prev_patt = root;
  while (!q.empty()) {
    Node* u = q.front();
    q.pop();
    for (int ch = 0; ch < MAXC; ch++) {
      Node*& v = u->child[ch];
      if (v != NULL) {
        Node* cur = u->link;
        while (cur != root && cur->child[ch] == NULL) cur = cur->link;
        if (cur != root) {
          v->link = cur->child[ch];
        } else if (cur->child[ch] == NULL) {
          v->link = root;
        } else {
          v->link = cur->child[ch];
        }
        q.push(v);
        if (v->prev_patt == NULL) {
          v->prev_patt = v->link->prev_patt;
        }
      }
    }
  }
}
string s;
class HopcraftKarp {
 public:
  bool reverse;
  int n, m;
  int dis[2 * MAXN];
  int match[2 * MAXN];
  vector<int> adj[2 * MAXN];
  HopcraftKarp(int a, int b) {
    n = a;
    m = b;
    reverse = false;
    if (n > m) {
      reverse = true;
      swap(n, m);
    }
    for (int i = 0; i <= n; ++i) {
      match[i] = 0;
    }
  }
  void reset(int a, int b) {
    n = a;
    m = b;
    reverse = false;
    if (n > m) {
      reverse = true;
      swap(n, m);
    }
    for (int i = 0; i <= n; ++i) {
      match[i] = 0;
    }
    for (int i = 0; i <= (2 * n); i++) {
      dis[i] = 0;
      match[i] = 0;
      adj[i].clear();
    }
  }
  void add_edge(int a, int b) {
    if (reverse) {
      adj[a + n].push_back(b);
      adj[b].push_back(a + n);
    } else {
      adj[a].push_back(b + n);
      adj[b + n].push_back(a);
    }
  }
  bool bfs() {
    queue<int> q;
    for (int i = 1; i <= n; ++i) {
      if (match[i] == 0) {
        dis[i] = 0;
        q.push(i);
      } else {
        dis[i] = INT_MAX;
      }
    }
    dis[0] = INT_MAX;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      if (u != 0) {
        for (size_t i = 0; i < adj[u].size(); ++i) {
          int v = adj[u][i];
          if (dis[match[v]] == INT_MAX) {
            dis[match[v]] = dis[u] + 1;
            q.push(match[v]);
          }
        }
      }
    }
    return dis[0] != INT_MAX;
  }
  int dfs(int u) {
    if (u != 0) {
      for (size_t i = 0; i < adj[u].size(); ++i) {
        int v = adj[u][i];
        if (dis[match[v]] == dis[u] + 1) {
          if (dfs(match[v])) {
            match[v] = u;
            match[u] = v;
            return true;
          }
        }
      }
      dis[u] = INT_MAX;
      return false;
    }
    return true;
  }
  int max_matching() {
    int matching = 0;
    while (bfs()) {
      for (int i = 1; i <= n; ++i) {
        if (match[i] == 0 && dfs(i)) {
          ++matching;
        }
      }
    }
    return matching;
  }
  void print_matches() {
    for (int i = 1; i <= n; ++i) {
      if (match[i] != 0) {
        printf("%d matches with %d\n", i, match[i] - n);
      }
    }
  }
};
HopcraftKarp bpm(0, 0);
vector<int> g[2 * MAXN];
bool mark[2 * MAXN];
bool inVc[2 * MAXN];
void dfs_vc(int u) {
  mark[u] = 1;
  for (auto v : g[u]) {
    if (!mark[v]) {
      dfs_vc(v);
    }
  }
}
int main(int argc, char* argv[]) {
  io();
  root = new_node();
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    add_string(s, i);
  }
  bfs();
  Node* prev_str = NULL;
  for (int i = 1; i <= n; i++) {
    for (auto node : pathnodes[i]) {
      prev_str = node->prev_patt;
      if (prev_str->ends == i) {
        prev_str = node->link->prev_patt;
      }
      if (prev_str != root) {
        assert(prev_str->ends != 0);
        G[i][prev_str->ends] = 1;
      }
    }
  }
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        G[i][j] |= (G[i][k] && G[k][j]);
      }
    }
  }
  bpm.reset(n, n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (G[i][j]) {
        bpm.add_edge(i, j);
      }
    }
  }
  int max_len_antichain = (n - bpm.max_matching());
  cout << max_len_antichain << '\n';
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (G[i][j]) {
        if (bpm.match[i] == j + n) {
          g[j + n].push_back(i);
        } else {
          g[i].push_back(j + n);
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (bpm.match[i] == 0) {
      dfs_vc(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (bpm.match[i] != 0) {
      if (!mark[i]) {
        inVc[i] = 1;
      }
      if (mark[bpm.match[i]]) {
        inVc[bpm.match[i]] = 1;
      }
    }
  }
  int cntr = 0;
  for (int i = 1; i <= n; i++) {
    if (inVc[i] || inVc[i + n]) continue;
    cout << i << " ";
    cntr++;
  }
  assert(cntr == (max_len_antichain));
  return 0;
}
