590_E. Birthday

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.

Example input:
5
abab
aba
aabab
ababb
bab


Example output:
2
2 5 

Tags: graph matchings
strings
Difficulty rating: 3200

Solution:
#include <bits/stdc++.h>
int A[10000001][2], B[10000001], D[751], G[751], b[751], l, n, q[10000001], r,
    t, x;
unsigned int E[10000001];
bool a[751][751], c[751], d[751], e[751];
inline bool cmp(int u, int v) { return G[u] - G[u - 1] < G[v] - G[v - 1]; }
inline int add(char* C, int& i) {
  int u = 1;
  for (; C[i]; u = A[u][C[i++]])
    if (!A[u][C[i] -= 97]) A[u][C[i]] = ++t;
  return u;
}
void find(int u) {
  c[u] = true;
  for (int i = 1; i <= n; i++)
    if (a[u][i] && !d[i]) d[i] = true, find(b[i]);
}
bool dfs(int u) {
  c[u] = true;
  for (int i = 1; i <= n; i++)
    if (a[u][i] && (!b[i] || !c[b[i]] && dfs(b[i]))) return b[i] = u;
  return false;
}
char C[10000001];
int main() {
  scanf("%d", &n), *A[0] = A[0][1] = q[r++] = t = 1, x = n;
  for (int i = 1; i <= n; i++)
    scanf("%s", C + G[i - 1]),
        G[E[D[i] = add(C + G[i - 1], G[i])] = i] += G[i - 1];
  while (l < r)
    *A[t = q[l++]] ? B[q[r++] = *A[t]] = *A[B[t]] : *A[t] = *A[B[t]],
                                A[t][1] ? B[q[r++] = A[t][1]] = A[B[t]][1]
                                        : A[t][1] = A[B[t]][1];
  for (int i = 1; i < r; i++)
    if (!E[q[i]]) E[q[i]] = E[B[q[i]]];
  for (int i = 1; i <= n; a[i][i] = true, i++)
    for (int j = G[i - 1], k = 1; j < G[i];)
      if (k = A[k][C[j++]], E[k] == i ? E[B[k]] : E[k])
        a[i][E[k] == i ? E[B[k]] : E[k]] = true;
  for (int k = 1; k <= n; k++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) a[i][j] |= a[i][k] & a[k][j];
  for (int i = 1; i <= n; i++) a[i][i] = false;
  for (int i = 1; i <= n; i++) memset(c + 1, false, n), x -= e[i] = dfs(i);
  printf("%d\n", x), memset(c + 1, false, n);
  for (int i = 1; i <= n; i++)
    if (!e[i]) find(i);
  for (int i = 1; i <= n; i++)
    if (c[i] && !d[i]) printf("%d%c", i, --x ? ' ' : '\n');
  return 0;
}