#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> G[1513];
bool used[1513];
int match[1513];
int E[1513][1513];
const int kind = 2;
struct Node {
  int fail;
  int nxt[kind];
  int cnt;
  int sub;
  Node() {
    fail = 0;
    cnt = 0;
    sub = 0;
    memset(nxt, 0, sizeof(nxt));
  }
};
int q[1000013 * 10];
char str[1000013 * 10 + 1513];
char* strs[1513];
Node node[1000013 * 10];
int nds = 1;
void inst(char* str, int root, int id) {
  int p = root;
  int i = 0, index;
  while (str[i]) {
    index = str[i] - 'a';
    if (node[p].nxt[index] == 0) {
      node[p].nxt[index] = ++nds;
    }
    p = node[p].nxt[index];
    i++;
  }
  node[p].cnt = id;
}
void build_ac_automation(int root) {
  int i;
  int head = 0, tail = 0;
  node[root].fail = 0;
  q[tail++] = root;
  while (head != tail) {
    int temp = q[head++];
    int p = 0;
    for (i = 0; i < kind; i++) {
      if (node[temp].nxt[i] != 0) {
        if (temp == root) {
          node[node[temp].nxt[i]].fail = root;
        } else {
          p = node[temp].fail;
          while (p != 0) {
            if (node[p].nxt[i] != 0) {
              node[node[temp].nxt[i]].fail = node[p].nxt[i];
              break;
            }
            p = node[p].fail;
          }
          if (p == 0) {
            node[node[temp].nxt[i]].fail = root;
          }
        }
        q[tail++] = node[temp].nxt[i];
      }
    }
    node[temp].sub = node[node[temp].fail].sub;
    if (node[temp].cnt) {
      node[temp].sub = node[temp].cnt;
    }
  }
}
bool dfs(int v) {
  used[v] = true;
  for (int i = int(0), __border_righti = int(G[v].size()); i < __border_righti;
       i++) {
    int u = G[v][i], w = match[u];
    if (w < 0 || !used[w] && dfs(w)) {
      match[v] = u;
      match[u] = v;
      return true;
    }
  }
  return false;
}
void check(int v) {
  if (used[v]) {
    return;
  }
  used[v] = true;
  for (int i = int(0), __border_righti = int(G[v].size()); i < __border_righti;
       i++) {
    int u = G[v][i], w = match[u];
    if (!used[u]) {
      used[u] = true;
      check(w);
    }
  }
}
int main() {
  scanf("%d", &N);
  nds = 0;
  int r = ++nds;
  int n = 0;
  for (int i = int(0), __border_righti = int(N); i < __border_righti; i++) {
    scanf("%s", str + n);
    strs[i] = str + n;
    n += strlen(str + n) + 1;
    inst(strs[i], r, i + 1);
  }
  build_ac_automation(r);
  memset(E, 0, sizeof(E));
  for (int i = int(0), __border_righti = int(N); i < __border_righti; i++) {
    int r = 1;
    for (int j = 0; strs[i][j]; j++) {
      r = node[r].nxt[strs[i][j] - 'a'];
      E[i][node[r].sub] = true;
    }
    r = node[r].fail;
    E[i][node[r].sub] = true;
    for (int j = int(0), __border_rightj = int(N); j < __border_rightj; j++) {
      E[i][j] = E[i][j + 1];
    }
  }
  for (int k = int(0), __border_rightk = int(N); k < __border_rightk; k++) {
    for (int i = int(0), __border_righti = int(N); i < __border_righti; i++) {
      for (int j = int(0), __border_rightj = int(N); j < __border_rightj; j++) {
        E[i][j] = E[i][j] || E[i][k] && E[k][j];
      }
    }
  }
  for (int i = int(0), __border_righti = int(N); i < __border_righti; i++) {
    for (int j = int(0), __border_rightj = int(N); j < __border_rightj; j++) {
      if (i != j && E[i][j]) {
        G[i].push_back(j + N);
      }
    }
  }
  int res = N;
  memset(match, -1, sizeof(match));
  std::vector<int> ans;
  for (int v = int(0), __border_rightv = int(N); v < __border_rightv; v++) {
    if (match[v] < 0) {
      memset(used, 0, sizeof(used));
      if (dfs(v)) {
        res--;
      } else {
        ans.push_back(v);
      }
    }
  }
  memset(used, 0, sizeof(used));
  printf("%d\n", res);
  for (int i = int(0), __border_righti = int(res); i < __border_righti; i++) {
    check(ans[i]);
  }
  for (int i = int(0), __border_righti = int(N); i < __border_righti; i++) {
    if (used[i] && !used[i + N]) {
      printf("%d ", i + 1);
    }
  }
  return 0;
}
