Problem: Today is birthday of a Little Dasha — she is now 8 years old! On this occasion, each of her n friends and relatives gave her a ribbon with a greeting written on it, and, as it turned out, all the greetings are different. Dasha gathered all the ribbons and decided to throw away some of them in order to make the remaining set stylish. The birthday girl considers a set of ribbons stylish if no greeting written on some ribbon is a substring of another greeting written on some other ribbon. Let us recall that the substring of the string s is a continuous segment of s.

Help Dasha to keep as many ribbons as possible, so that she could brag about them to all of her friends. Dasha cannot rotate or flip ribbons, that is, each greeting can be read in a single way given in the input.

Input

The first line of the input contains integer n (1 ≤ n ≤ 750) — the number of Dasha's relatives and friends.

Each of the next n lines contains exactly one greeting. Each greeting consists of characters 'a' and 'b' only.

The total length of all greetings won't exceed 10 000 000 characters.

Output

In the first line print the maximum size of the stylish set. In the second line print the numbers of ribbons involved in it, assuming that they are numbered from 1 to n in the order they appear in the input. If there are several stylish sets of the maximum size, print any of them.

Examples

Input

5
abab
aba
aabab
ababb
bab


Output

2
2 5

Note

In the sample, the answer that keeps ribbons 3 and 4 is also considered correct.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
struct AhoCorasick {
  static const int nletter = 2;
  struct node {
    vector<int> keywords;
    node *go[nletter] = {}, *failure = {}, *output = {};
  } *root = new node();
  node *add(int size, int *values, int keywordid) {
    assert(size > 0);
    node *v = root;
    for (int i = 0; i < size; ++i) {
      node *&u = v->go[values[i]];
      if (!u) u = new node();
      v = u;
    }
    v->keywords.push_back(keywordid);
    return v;
  }
  void build() {
    queue<node *> q;
    for (int i = 0; i < nletter; ++i) {
      node *&v = root->go[i];
      if (v) {
        v->failure = root;
        v->output = v->keywords.size() > 0 ? v : nullptr;
        q.push(v);
      } else {
        v = root;
      }
    }
    while (!q.empty()) {
      node *u = q.front();
      q.pop();
      for (int i = 0; i < nletter; ++i) {
        node *v = u->go[i];
        if (v) {
          node *x = u->failure;
          while (!x->go[i]) x = x->failure;
          v->failure = x->go[i];
          v->output = v->keywords.size() > 0 ? v : v->failure->output;
          q.push(v);
        }
      }
    }
  }
  node *iterate(node *v, int value) {
    while (!v->go[value]) v = v->failure;
    return v->go[value];
  }
  vector<int> matches(node *v) {
    vector<int> result;
    for (node *x = v->output; x; x = x->failure->output)
      result.insert(result.end(), x->keywords.begin(), x->keywords.end());
    return result;
  }
};
struct Dinitz {
  int n, source, sink;
  vector<vector<int>> adj;
  struct edge {
    int u, flow, cap;
  };
  vector<edge> edges;
  Dinitz(int n, int source, int sink)
      : n(n), source(source), sink(sink), adj(n) {}
  int add_edge(int a, int b, int abcap, int bacap = 0) {
    int result = edges.size();
    adj[a].push_back(edges.size());
    edges.push_back({b, 0, abcap});
    adj[b].push_back(edges.size());
    edges.push_back({a, 0, bacap});
    return result;
  }
  vector<int> mindist, position;
  bool bfs() {
    queue<int> q;
    fill(mindist.begin(), mindist.end(), INT_MAX / 2);
    mindist[source] = 0;
    q.push(source);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (int edid : adj[v]) {
        edge &ed = edges[edid];
        if (ed.flow < ed.cap && mindist[ed.u] > mindist[v] + 1) {
          mindist[ed.u] = mindist[v] + 1;
          q.push(ed.u);
        }
      }
    }
    return mindist[sink] < n;
  }
  int dfs(int v, int maxf) {
    if (v == sink) return maxf;
    for (int &pos = position[v]; pos < (int)adj[v].size(); ++pos) {
      int edid = adj[v][pos];
      edge &ed = edges[edid], &reved = edges[edid ^ 1];
      if (ed.flow < ed.cap && mindist[ed.u] == mindist[v] + 1) {
        int f = dfs(ed.u, min(maxf, ed.cap - ed.flow));
        if (f > 0) {
          ed.flow += f;
          reved.flow -= f;
          return f;
        }
      }
    }
    return 0;
  }
  int maxflow() {
    int result = 0;
    mindist.resize(n);
    position.resize(n);
    while (bfs()) {
      int extra;
      do {
        fill(position.begin(), position.end(), 0);
        extra = dfs(source, INT_MAX);
        result += extra;
      } while (extra > 0);
    }
    return result;
  }
};
struct BipartiteVertexCover {
  int nleft, nright;
  vector<vector<int>> adj, ids;
  Dinitz din;
  vector<int> other, incover;
  BipartiteVertexCover(int nleft, int nright)
      : nleft(nleft),
        nright(nright),
        adj(nleft + nright),
        ids(nleft),
        din(1 + nleft + nright + 1, 0, 1 + nleft + nright) {
    for (int l = 0; l < nleft; ++l) din.add_edge(0, 1 + l, 1);
    for (int r = 0; r < nright; ++r)
      din.add_edge(1 + nleft + r, 1 + nleft + nright, 1);
  }
  void add_edge(int l, int r) {
    int id = din.add_edge(1 + l, 1 + nleft + r, 1);
    adj[l].push_back(nleft + r);
    ids[l].push_back(id);
    adj[nleft + r].push_back(l);
  }
  void dfs(int v, bool in) {
    if (incover[v] != -1) return;
    incover[v] = in;
    if (in == true) {
      dfs(other[v], false);
    } else {
      for (int u : adj[v]) dfs(u, true);
    }
  }
  vector<pair<int, int>> solve() {
    int n = nleft + nright;
    other = vector<int>(n, -1);
    int matchingsize = din.maxflow();
    for (int l = 0; l < nleft; ++l)
      for (int i = 0; i < (int)adj[l].size(); ++i) {
        int r = adj[l][i] - nleft, id = ids[l][i];
        if (din.edges[id].flow > 0) {
          other[l] = nleft + r;
          other[nleft + r] = l;
        }
      }
    incover = vector<int>(n, -1);
    for (int i = 0; i < n; ++i)
      if (other[i] == -1) dfs(i, 0);
    for (int i = 0; i < n; ++i)
      if (incover[i] == -1) dfs(i, 0);
    vector<pair<int, int>> result;
    for (int i = 0; i < n; ++i)
      if (incover[i]) {
        if (i < nleft)
          result.push_back({0, i});
        else
          result.push_back({1, i - nleft});
      }
    assert(result.size() == matchingsize);
    return result;
  }
};
int adj[750][750];
int main() {
  using node = AhoCorasick::node;
  int n;
  scanf("%d", &n);
  AhoCorasick aho;
  vector<vector<int>> keywords(n);
  for (int i = 0; i < n; ++i) {
    static char str[10000000 + 1];
    scanf("%s", str);
    vector<int> v(strlen(str));
    for (int j = 0; str[j]; ++j) v[j] = str[j] - 'a';
    aho.add(v.size(), &v[0], i);
    keywords[i] = move(v);
  }
  aho.build();
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) adj[i][j] = 0;
  for (int i = 0; i < n; ++i) {
    vector<int> &values = keywords[i];
    node *state = aho.root;
    for (int value : values) {
      state = aho.iterate(state, value);
      node *out = state->output;
      if (out) {
        int id = out->keywords.front();
        if (id == i) {
          out = out->failure->output;
          if (out)
            id = out->keywords.front();
          else
            id = -1;
        }
        if (id != -1) adj[i][id] = 1;
      }
    }
  }
  for (int k = 0; k < n; ++k)
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j) adj[i][j] |= adj[i][k] & adj[k][j];
  BipartiteVertexCover bvc(n, n);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      if (adj[i][j]) bvc.add_edge(i, j);
  vector<bool> inresult(n, true);
  for (pair<int, int> node : bvc.solve()) inresult[node.second] = false;
  vector<int> result;
  for (int i = 0; i < n; ++i)
    if (inresult[i]) result.push_back(i);
  printf("%d\n", (int)result.size());
  for (int i = 0; i < (int)result.size(); ++i) {
    if (i > 0) printf(" ");
    printf("%d", result[i] + 1);
  }
  printf("\n");
  return 0;
}