#include <bits/stdc++.h>

struct Node {
    Node *go[2],*fail,*par;
    int id;

    Node(Node *_par = NULL) {
        go[0] = go[1] = fail = NULL;
        id = -1;
        par = _par;
    }
} pool[10000000 + 1],*alloc,*root;

char str[10000000 + 1];

const int N = 750 + 5;
bool graph[N][N];
int n;

void insert(char *s,int id) {
    Node *p = root;
    for ( ; *s; ++ s) {
        int c = *s - 'a';
        if (p->go[c] == NULL)
            p->go[c] = new(alloc ++) Node(p);
        p = p->go[c];
    }
    if (p->id != -1) {
        graph[p->id][id] = graph[id][p->id] = true;
    }
    p->id = id;
}

int vis[N],stmp;
int left[N];
bool mark[N][2];
bool matched[N];

void dfs(int u,int side) {
    if (mark[u][side])
        return ;
    mark[u][side] = true;
    if (side == 0) {
        for (int v = 0; v < n; ++ v) {
            if (graph[u][v])
                dfs(v,side ^ 1);
        }
    } else if (left[u] != -1) {
        dfs(left[u],side ^ 1);
    }
}

bool expath(int u) {
    for (int v = 0; v < n; ++ v) {
        if (graph[u][v] && vis[v] != stmp) {
            vis[v] = stmp;
            if (left[v] == -1 || expath(left[v])) {
                left[v] = u;
                return true;
            }
        }
    }
    return false;
}

int main() {
    alloc = pool;
    root = new(alloc ++) Node;
    scanf("%d",&n);
    for (int i = 0; i < n; ++ i) {
        scanf("%s",str);
        insert(str,i);
    }
    std::queue<Node*> que;
    que.push(root);
    while (!que.empty()) {
        Node *u = que.front(); que.pop();
        if (u->id != -1) {
            for (Node *v = u->par; v; v = v->par) {
                if (v->id != -1)
                    graph[u->id][v->id] = true;
            }
        }
        if (u->fail && u->fail->id != -1) {
            if (u->id != -1)
                graph[u->id][u->fail->id] = true;
            else
                u->id = u->fail->id;
        }
        for (int c = 0; c < 2; ++ c) {
            if (u->go[c] == NULL) continue;
            Node *f = u->fail;
            while (f && f->go[c] == NULL) f = f->fail;
            u->go[c]->fail = f == NULL ? root : f->go[c];
            que.push(u->go[c]);
        }
    }
    for (int k = 0; k < n; ++ k) {
        for (int i = 0; i < n; ++ i) {
            for (int j = 0; j < n; ++ j) {
                graph[i][j] |= graph[i][k] & graph[k][j];
            }
        }
    }
    for (int i = 0; i < n; ++ i)
        graph[i][i] = false;
    memset(left,-1,sizeof(left));
    for (int i = 0; i < n; ++ i) {
        stmp ++;
        matched[i] = expath(i);
    }
    for (int i = 0; i < n; ++ i) {
        if (!matched[i])
            dfs(i,0);
    }
    std::vector<int> answer;
    for (int i = 0; i < n; ++ i) {
        if (!(matched[i] && !mark[i][0] || mark[i][1]))
            answer.push_back(i);
    }
    printf("%d\n",answer.size());
    for (int i = 0; i < answer.size(); ++ i) {
        if (i) putchar(' ');
        printf("%d",answer[i] + 1);
    }
    puts("");
}


#include <bits/stdc++.h>

struct Node {
    Node *go[2],*fail,*par;
    int id;

    Node(Node *_par = NULL) {
        go[0] = go[1] = fail = NULL;
        id = -1;
        par = _par;
    }
} pool[10000000 + 1],*alloc,*root;

char str[10000000 + 1];

const int N = 750 + 5;
bool graph[N][N];
int n;

void insert(char *s,int id) {
    Node *p = root;
    for ( ; *s; ++ s) {
        int c = *s - 'a';
        if (p->go[c] == NULL)
            p->go[c] = new(alloc ++) Node(p);
        p = p->go[c];
    }
    if (p->id != -1) {
        graph[p->id][id] = graph[id][p->id] = true;
    }
    p->id = id;
}

int vis[N],stmp;
int left[N];
bool mark[N][2];
bool matched[N];

void dfs(int u,int side) {
    if (mark[u][side])
        return ;
    mark[u][side] = true;
    if (side == 0) {
        for (int v = 0; v < n; ++ v) {
            if (graph[u][v] && left[v] != u)
                dfs(v,side ^ 1);
        }
    } else if (left[u] != -1) {
        dfs(left[u],side ^ 1);
    }
}

bool expath(int u) {
    for (int v = 0; v < n; ++ v) {
        if (u != v && graph[u][v] && vis[v] != stmp) {
            vis[v] = stmp;
            if (left[v] == -1 || expath(left[v])) {
                left[v] = u;
                return true;
            }
        }
    }
    return false;
}

int main() {
    alloc = pool;
    root = new(alloc ++) Node;
    scanf("%d",&n);
    for (int i = 0; i < n; ++ i) {
        scanf("%s",str);
        insert(str,i);
    }
    std::queue<Node*> que;
    que.push(root);
    while (!que.empty()) {
        Node *u = que.front(); que.pop();
        if (u->id != -1) {
            for (Node *v = u->par; v; v = v->par) {
                if (v->id != -1)
                    graph[u->id][v->id] = true;
            }
        }
        if (u->fail && u->fail->id != -1) {
            if (u->id != -1)
                graph[u->id][u->fail->id] = true;
            u->id = u->fail->id;
        }
        for (int c = 0; c < 2; ++ c) {
            if (u->go[c] == NULL) continue;
            Node *f = u->fail;
            while (f && f->go[c] == NULL) f = f->fail;
            u->go[c]->fail = f == NULL ? root : f->go[c];
            que.push(u->go[c]);
        }
    }
    for (int k = 0; k < n; ++ k) {
        for (int i = 0; i < n; ++ i) {
            for (int j = 0; j < n; ++ j) {
                graph[i][j] |= graph[i][k] & graph[k][j];
            }
        }
    }
    memset(left,-1,sizeof(left));
    for (int i = 0; i < n; ++ i) {
        stmp ++;
        matched[i] = expath(i);
    }
    for (int i = 0; i < n; ++ i) {
        if (!matched[i])
            dfs(i,0);
    }
    std::vector<int> answer;
    for (int i = 0; i < n; ++ i) {
        if (matched[i] && !mark[i][0] || !matched[i] && mark[i][1])
            answer.push_back(i);
    }
    printf("%d\n",answer.size());
    for (int i = 0; i < answer.size(); ++ i) {
        if (i) putchar(' ');
        printf("%d",answer[i] + 1);
    }
    puts("");
}


#include <bits/stdc++.h>

struct Node {
    Node *go[2],*fail,*par;
    int id;

    Node(Node *_par = NULL) {
        go[0] = go[1] = fail = NULL;
        id = -1;
        par = _par;
    }
} pool[10000000 + 1],*alloc,*root;

char str[10000000 + 1];

const int N = 750 + 5;
bool graph[N][N];
int n;

void insert(char *s,int id) {
    Node *p = root;
    for ( ; *s; ++ s) {
        int c = *s - 'a';
        if (p->go[c] == NULL)
            p->go[c] = new(alloc ++) Node(p);
        p = p->go[c];
    }
    if (p->id != -1) {
        graph[p->id][id] = graph[id][p->id] = true;
    }
    p->id = id;
}

int vis[N],stmp;
int left[N];
bool mark[N][2];
bool matched[N];

void dfs(int u,int side) {
    if (mark[u][side])
        return ;
    mark[u][side] = true;
    if (side == 0) {
        for (int v = 0; v < n; ++ v) {
            if (graph[u][v] && left[v] != u)
                dfs(v,side ^ 1);
        }
    } else if (left[u] != -1) {
        dfs(left[u],side ^ 1);
    }
}

bool expath(int u) {
    for (int v = 0; v < n; ++ v) {
        if (graph[u][v] && vis[v] != stmp) {
            vis[v] = stmp;
            if (left[v] == -1 || expath(left[v])) {
                left[v] = u;
                return true;
            }
        }
    }
    return false;
}

int main() {
    alloc = pool;
    root = new(alloc ++) Node;
    scanf("%d",&n);
    for (int i = 0; i < n; ++ i) {
        scanf("%s",str);
        insert(str,i);
    }
    std::queue<Node*> que;
    que.push(root);
    while (!que.empty()) {
        Node *u = que.front(); que.pop();
        if (u->id != -1) {
            for (Node *v = u->par; v; v = v->par) {
                if (v->id != -1)
                    graph[u->id][v->id] = true;
            }
        }
        if (u->fail && u->fail->id != -1) {
            if (u->id != -1)
                graph[u->id][u->fail->id] = true;
            u->id = u->fail->id;
        }
        for (int c = 0; c < 2; ++ c) {
            if (u->go[c] == NULL) continue;
            Node *f = u->fail;
            while (f && f->go[c] == NULL) f = f->fail;
            u->go[c]->fail = f == NULL ? root : f->go[c];
            que.push(u->go[c]);
        }
    }
    for (int k = 0; k < n; ++ k) {
        for (int i = 0; i < n; ++ i) {
            for (int j = 0; j < n; ++ j) {
                graph[i][j] |= graph[i][k] & graph[k][j];
            }
        }
    }
    memset(left,-1,sizeof(left));
    for (int i = 0; i < n; ++ i) {
        stmp ++;
        matched[i] = expath(i);
    }
    for (int i = 0; i < n; ++ i) {
        if (!matched[i])
            dfs(i,0);
    }
    std::vector<int> answer;
    for (int i = 0; i < n; ++ i) {
        if (matched[i] && !mark[i][0] || mark[i][1])
            answer.push_back(i);
    }
    printf("%d\n",answer.size());
    for (int i = 0; i < answer.size(); ++ i) {
        if (i) putchar(' ');
        printf("%d",answer[i] + 1);
    }
    puts("");
}


#include <bits/stdc++.h>

struct Node {
    Node *go[2],*fail,*par;
    int id;

    Node(Node *_par = NULL) {
        go[0] = go[1] = fail = NULL;
        id = -1;
        par = _par;
    }
} pool[10000000 + 1],*alloc,*root;

char str[10000000 + 1];

const int N = 750 + 5;
bool graph[N][N];
int n;

void insert(char *s,int id) {
    Node *p = root;
    for ( ; *s; ++ s) {
        int c = *s - 'a';
        if (p->go[c] == NULL)
            p->go[c] = new(alloc ++) Node(p);
        p = p->go[c];
    }
    if (p->id != -1) {
        graph[p->id][id] = graph[id][p->id] = true;
    }
    p->id = id;
}

int vis[N],stmp;
int left[N];
bool mark[N][2];
bool matched[N];

void dfs(int u,int side) {
    if (mark[u][side])
        return ;
    mark[u][side] = true;
    if (side == 0) {
        for (int v = 0; v < n; ++ v) {
            if (graph[u][v])
                dfs(v,side ^ 1);
        }
    } else if (left[u] != -1) {
        dfs(left[u],side ^ 1);
    }
}

bool expath(int u) {
    for (int v = 0; v < n; ++ v) {
        if (graph[u][v] && vis[v] != stmp) {
            vis[v] = stmp;
            if (left[v] == -1 || expath(left[v])) {
                left[v] = u;
                return true;
            }
        }
    }
    return false;
}

int main() {
    alloc = pool;
    root = new(alloc ++) Node;
    scanf("%d",&n);
    for (int i = 0; i < n; ++ i) {
        scanf("%s",str);
        insert(str,i);
    }
    std::queue<Node*> que;
    que.push(root);
    while (!que.empty()) {
        Node *u = que.front(); que.pop();
        if (u->id != -1) {
            for (Node *v = u->par; v; v = v->par) {
                if (v->id != -1)
                    graph[u->id][v->id] = true;
            }
        }
        if (u->fail && u->fail->id != -1) {
            if (u->id != -1)
                graph[u->id][u->fail->id] = true;
            else
                u->id = u->fail->id;
        }
        for (int c = 0; c < 2; ++ c) {
            if (u->go[c] == NULL) continue;
            Node *f = u->fail;
            while (f && f->go[c] == NULL) f = f->fail;
            u->go[c]->fail = f == NULL ? root : f->go[c];
            que.push(u->go[c]);
        }
    }
    for (int k = 0; k < n; ++ k) {
        for (int i = 0; i < n; ++ i) {
            for (int j = 0; j < n; ++ j) {
                graph[i][j] |= graph[i][k] & graph[k][j];
            }
        }
    }
    for (int i = 0; i < n; ++ i)
        graph[i][i] = false;
    memset(left,-1,sizeof(left));
    int cnt = 0;
    for (int i = 0; i < n; ++ i) {
        stmp ++;
        matched[i] = expath(i);
        cnt += matched[i];
    }
    for (int i = 0; i < n; ++ i) {
        if (!matched[i])
            dfs(i,0);
    }
    std::vector<int> answer;
    for (int i = 0; i < n; ++ i) {
        if (!(matched[i] && !mark[i][0] || mark[i][1]))
            answer.push_back(i);
    }
    assert(cnt + answer.size() == n);
    printf("%d\n",answer.size());
    for (int i = 0; i < answer.size(); ++ i) {
        if (i) putchar(' ');
        printf("%d",answer[i] + 1);
    }
    puts("");
}


#include <bits/stdc++.h>

struct Node {
    Node *go[2],*fail,*par;
    int id;

    Node(Node *_par = NULL) {
        go[0] = go[1] = fail = NULL;
        id = -1;
        par = _par;
    }
} pool[10000000 + 1],*alloc,*root;

char str[10000000 + 1];

const int N = 750 + 5;
bool graph[N][N];
int n;

void insert(char *s,int id) {
    Node *p = root;
    for ( ; *s; ++ s) {
        int c = *s - 'a';
        if (p->go[c] == NULL)
            p->go[c] = new(alloc ++) Node(p);
        p = p->go[c];
    }
    if (p->id != -1) {
        graph[p->id][id] = graph[id][p->id] = true;
    }
    p->id = id;
}

int vis[N],stmp;
int left[N];
bool mark[N][2];
bool matched[N];

void dfs(int u,int side) {
    if (mark[u][side])
        return ;
    mark[u][side] = true;
    if (side == 0) {
        for (int v = 0; v < n; ++ v) {
            if (graph[u][v] && left[v] != u)
                dfs(v,side ^ 1);
        }
    } else if (left[u] != -1) {
        dfs(left[u],side ^ 1);
    }
}

bool expath(int u) {
    for (int v = 0; v < n; ++ v) {
        if (u != v && graph[u][v] && vis[v] != stmp) {
            vis[v] = stmp;
            if (left[v] == -1 || expath(left[v])) {
                left[v] = u;
                return true;
            }
        }
    }
    return false;
}

int main() {
    alloc = pool;
    root = new(alloc ++) Node;
    scanf("%d",&n);
    for (int i = 0; i < n; ++ i) {
        scanf("%s",str);
        insert(str,i);
    }
    std::queue<Node*> que;
    que.push(root);
    while (!que.empty()) {
        Node *u = que.front(); que.pop();
        if (u->id != -1) {
            for (Node *v = u->par; v; v = v->par) {
                if (v->id != -1)
                    graph[u->id][v->id] = true;
            }
        }
        if (u->fail && u->fail->id != -1) {
            if (u->id != -1)
                graph[u->id][u->fail->id] = true;
            u->id = u->fail->id;
        }
        for (int c = 0; c < 2; ++ c) {
            if (u->go[c] == NULL) continue;
            Node *f = u->fail;
            while (f && f->go[c] == NULL) f = f->fail;
            u->go[c]->fail = f == NULL ? root : f->go[c];
            que.push(u->go[c]);
        }
    }
    for (int k = 0; k < n; ++ k) {
        for (int i = 0; i < n; ++ i) {
            for (int j = 0; j < n; ++ j) {
                graph[i][j] |= graph[i][k] & graph[k][j];
            }
        }
    }
    memset(left,-1,sizeof(left));
    for (int i = 0; i < n; ++ i) {
        stmp ++;
        matched[i] = expath(i);
    }
    for (int i = 0; i < n; ++ i) {
        if (!matched[i])
            dfs(i,0);
    }
    std::vector<int> answer;
    for (int i = 0; i < n; ++ i) {
        if (matched[i] && !mark[i][0] || mark[i][1])
            answer.push_back(i);
    }
    printf("%d\n",answer.size());
    for (int i = 0; i < answer.size(); ++ i) {
        if (i) putchar(' ');
        printf("%d",answer[i] + 1);
    }
    puts("");
}


#include <bits/stdc++.h>
using namespace std;

char s[10000007];
int n;
int idcnt = 1, ch[10000007][2], fa[10000007], lst[10000007], up[10000007];
int id[10000007], pos[1003];
int res[1003], ans;
int d[1003][1003];

void ins(int id) {
    int p = 1, len = strlen(s + 1);
    for (int i = 1, c; i <= len; ++i) {
        if (!ch[p][c = s[i] == 'a']) up[ch[p][c] = ++idcnt] = p;
        p = ch[p][c];
    }
    (!::id[p]) ? ::id[pos[id] = p] = id : --ans;
}
queue<int> q;
void getfail() {
    if (ch[1][0]) q.push(ch[1][0]), fa[ch[1][0]] = 1;
    if (ch[1][1]) q.push(ch[1][1]), fa[ch[1][1]] = 1;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int c = 0, v; c < 2; ++c)
            if (v = ch[u][c]) {
                int p = fa[u];
                while (p && !ch[p][c]) p = fa[p];
                fa[v] = p ? ch[p][c] : 1, q.push(v);
                lst[v] = id[fa[v]] ? id[fa[v]] : lst[fa[v]];
            }
    }

    for (int i = 1; i <= n; ++i) {
        int p = pos[i];
        while (p) d[lst[p]][i] = d[id[p]][i] = 1, p = up[p];
    }
}

void floyd() {
    for (int k = 1; k <= n; ++k)
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= n; ++j) d[i][j] |= d[i][k] & d[k][j];
    for (int i = 1; i <= n; ++i) d[i][i] = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j)
            if (d[i][j] & d[j][i]) exit(1);
    }
}

bool vis[1003];
int nxt[1003];
bool dfs(int u) {
    for (int v = 1; v <= n; ++v)
        if (!vis[v] && pos[v] && d[u][v]) {
            vis[v] = 1;
            if (!nxt[v] || dfs(nxt[v])) return nxt[v] = u, 1;
        }
    return 0;
}

int main() {
    scanf("%d", &n), ans = n;
    for (int i = 1; i <= n; ++i) scanf("%s", s + 1), ins(i);
    getfail(), floyd();
    for (int i = 1; i <= n; ++i)
        if (pos[i]) ans -= dfs(i), memset(vis, 0, sizeof vis);
    printf("%d\n", ans);
    ans = 0;
    for (int i = 1; i <= n; ++i)
        if (pos[i]) vis[nxt[i]] = 1;
    for (int i = 1; i <= n; ++i)
        if (pos[i] && !nxt[i]) res[++ans] = i;
    memset(vis, 0, sizeof vis);
    while (1) {
        int flg = 0;
        for (int j = 1; j <= n; ++j)
            if (pos[j] && !vis[j])
                for (int i = 1; i <= ans; ++i)
                    if (pos[i] && d[res[i]][j]) {
                        vis[j] = 1;
                        break;
                    }
        for (int i = 1; i <= ans; ++i)
            if (vis[res[i]]) {
                flg = 1;
                while (vis[res[i]]) res[i] = nxt[res[i]];
            }
        if (!flg) break;
    }
    for (int i = 1; i <= ans; ++i) {
        if (!res[i]) exit(1);
        printf("%d ", res[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

char s[10000007];
int n;
int idcnt = 1, ch[10000007][2], fa[10000007], lst[10000007], up[10000007];
int id[10000007], pos[1003];
int res[1003], ans;
int d[1003][1003];

void ins(int id) {
    int p = 1, len = strlen(s + 1);
    for (int i = 1, c; i <= len; ++i) {
        if (!ch[p][c = s[i] == 'a']) up[ch[p][c] = ++idcnt] = p;
        p = ch[p][c];
    }
    (!::id[p]) ? ::id[pos[id] = p] = id : --ans;
}
queue<int> q;
void getfail() {
    if (ch[1][0]) q.push(ch[1][0]), fa[ch[1][0]] = 1;
    if (ch[1][1]) q.push(ch[1][1]), fa[ch[1][1]] = 1;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int c = 0, v; c < 2; ++c)
            if (v = ch[u][c]) {
                int p = fa[u];
                while (p && !ch[p][c]) p = fa[p];
                fa[v] = p ? ch[p][c] : 1, q.push(v);
                lst[v] = id[fa[v]] ? id[fa[v]] : lst[fa[v]];
            }
    }

    for (int i = 1; i <= n; ++i) {
        int p = pos[i];
        while (p) d[lst[p]][i] = d[id[p]][i] = 1, p = up[p];
    }
}

void floyd() {
    for (int k = 1; k <= n; ++k)
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= n; ++j) d[i][j] |= d[i][k] & d[k][j];
    for (int i = 1; i <= n; ++i) d[i][i] = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j)
            if (d[i][j] & d[j][i]) exit(1);
    }
}

bool vis[1003];
int nxt[1003];
bool dfs(int u) {
    for (int v = 1; v <= n; ++v)
        if (!vis[v] && pos[v] && d[u][v]) {
            vis[v] = 1;
            if (!nxt[v] || dfs(nxt[v])) return nxt[v] = u, 1;
        }
    return 0;
}

int main() {
    scanf("%d", &n), ans = n;
    for (int i = 1; i <= n; ++i) scanf("%s", s + 1), ins(i);
    getfail(), floyd();
    for (int i = 1; i <= n; ++i)
        if (pos[i]) ans -= dfs(i), memset(vis, 0, sizeof vis);
    int tans = ans;
    printf("%d\n", ans);
    ans = 0;
    for (int i = 1; i <= n; ++i)
        if (pos[i]) vis[nxt[i]] = 1;
    for (int i = 1; i <= n; ++i)
        if (pos[i] && !nxt[i]) res[++ans] = i;
    if (tans != ans) exit(1);
    memset(vis, 0, sizeof vis);
    while (1) {
        int flg = 0;
        for (int j = 1; j <= n; ++j)
            if (pos[j] && !vis[j])
                for (int i = 1; i <= ans; ++i)
                    if (pos[i] && d[res[i]][j]) {
                        vis[j] = 1;
                        break;
                    }
        for (int i = 1; i <= ans; ++i)
            if (vis[res[i]]) {
                flg = 1;
                while (vis[res[i]]) res[i] = nxt[res[i]];
            }
        if (!flg) break;
    }
    for (int i = 1; i <= ans; ++i) printf("%d ", res[i]);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

char s[10000007];
int n;
int idcnt = 1, ch[10000007][2], fa[10000007], lst[10000007], up[10000007];
int id[10000007], pos[1003];
int res[1003], ans;
int d[1003][1003];

void ins(int id) {
    int p = 1, len = strlen(s + 1);
    for (int i = 1, c; i <= len; ++i) {
        if (!ch[p][c = s[i] == 'a']) up[ch[p][c] = ++idcnt] = p;
        p = ch[p][c];
    }
    if (!::id[p]) ::id[pos[id] = p] = id;
}
queue<int> q;
void getfail() {
    if (ch[1][0]) q.push(ch[1][0]), fa[ch[1][0]] = 1;
    if (ch[1][1]) q.push(ch[1][1]), fa[ch[1][1]] = 1;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int c = 0, v; c < 2; ++c)
            if (v = ch[u][c]) {
                int p = fa[u];
                while (p && !ch[p][c]) p = fa[p];
                fa[v] = p ? ch[p][c] : 1, q.push(v);
                lst[v] = id[fa[v]] ? id[fa[v]] : lst[fa[v]];
            }
    }

    for (int i = 1; i <= n; ++i) {
        int p = pos[i];
        while (p) d[lst[p]][i] = d[id[p]][i] = 1, p = up[p];
    }
}

void floyd() {
    for (int k = 1; k <= n; ++k)
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= n; ++j) d[i][j] |= d[i][k] & d[k][j];
    for (int i = 1; i <= n; ++i) d[i][i] = 0;
}

bool vis[1003];
int nxt[1003];
bool dfs(int u) {
    for (int v = 1; v <= n; ++v)
        if (!vis[v] && pos[v] && d[u][v]) {
            vis[v] = 1;
            if (!nxt[v] || dfs(nxt[v])) return nxt[v] = u, 1;
        }
    return 0;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%s", s + 1), ins(i);
    getfail(), floyd();
    for (int i = 1; i <= n; ++i)
        if (pos[i]) ans -= dfs(i), memset(vis, 0, sizeof vis);
    printf("%d\n", n + ans);
    for (int i = 1; i <= n + ans; ++i) {
        if (!res[i]) break;
        printf("%d ", res[i]);
    }
    ans = 0;
    for (int i = 1; i <= n; ++i) vis[nxt[i]] = 1;
    for (int i = 1; i <= n; ++i)
        if (!nxt[i]) res[++ans] = i;
    memset(vis, 0, sizeof vis);
    while (1) {
        int flg = 0;
        for (int j = 1; j <= n; ++j)
            if (!vis[j])
                for (int i = 1; i <= ans; ++i)
                    if (d[res[i]][j]) {
                        vis[j] = 1;
                        break;
                    }
        for (int i = 1; i <= ans; ++i)
            if (vis[res[i]]) {
                flg = 1;
                while (vis[res[i]]) res[i] = nxt[res[i]];
            }
        if (!flg) break;
    }
    for (int i = 1; i <= ans; ++i) printf("%d ", res[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

char s[10000007];
int n;
int idcnt = 1, ch[10000007][2], fa[10000007], lst[10000007], up[10000007];
int id[10000007], pos[1003];
int res[1003], ans;
int d[1003][1003];

void ins(int id) {
    int p = 1, len = strlen(s + 1);
    for (int i = 1, c; i <= len; ++i) {
        if (!ch[p][c = s[i] == 'a']) up[ch[p][c] = ++idcnt] = p;
        p = ch[p][c];
    }
    (!::id[p]) ? ::id[pos[id] = p] = id : --ans;
}
queue<int> q;
void getfail() {
    if (ch[1][0]) q.push(ch[1][0]), fa[ch[1][0]] = 1;
    if (ch[1][1]) q.push(ch[1][1]), fa[ch[1][1]] = 1;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int c = 0, v; c < 2; ++c)
            if (v = ch[u][c]) {
                int p = fa[u];
                while (p && !ch[p][c]) p = fa[p];
                fa[v] = p ? ch[p][c] : 1, q.push(v);
                lst[v] = id[fa[v]] ? id[fa[v]] : lst[fa[v]];
            }
    }

    for (int i = 1; i <= n; ++i) {
        int p = pos[i];
        while (p) d[lst[p]][i] = d[id[p]][i] = 1, p = up[p];
    }
}

void floyd() {
    for (int k = 1; k <= n; ++k)
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= n; ++j) d[i][j] |= d[i][k] & d[k][j];
    for (int i = 1; i <= n; ++i) d[i][i] = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j)
            if (d[i][j] & d[j][i]) exit(1);
    }
}

bool vis[1003];
int nxt[1003];
bool dfs(int u) {
    for (int v = 1; v <= n; ++v)
        if (!vis[v] && pos[v] && d[u][v]) {
            vis[v] = 1;
            if (!nxt[v] || dfs(nxt[v])) return nxt[v] = u, 1;
        }
    return 0;
}

int main() {
    scanf("%d", &n), ans = n;
    for (int i = 1; i <= n; ++i) scanf("%s", s + 1), ins(i);
    getfail(), floyd();
    for (int i = 1; i <= n; ++i)
        if (pos[i]) ans -= dfs(i), memset(vis, 0, sizeof vis);
    printf("%d\n", ans);
    ans = 0;
    for (int i = 1; i <= n; ++i)
        if (pos[i]) vis[nxt[i]] = 1;
    for (int i = 1; i <= n; ++i)
        if (pos[i] && !nxt[i]) res[++ans] = i;
    memset(vis, 0, sizeof vis);
    while (1) {
        int flg = 0;
        for (int j = 1; j <= n; ++j)
            if (pos[j] && !vis[j])
                for (int i = 1; i <= ans; ++i)
                    if (pos[i] && d[res[i]][j]) {
                        vis[j] = 1;
                        break;
                    }
        for (int i = 1; i <= ans; ++i)
            if (vis[res[i]]) {
                flg = 1;
                while (vis[res[i]]) res[i] = nxt[res[i]];
            }
        if (!flg) break;
    }
    for (int i = 1; i <= ans; ++i) printf("%d ", res[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

char s[10000007];
int n;
int idcnt = 1, ch[10000007][2], fa[10000007], lst[10000007], up[10000007];
int id[10000007], pos[1003];
int res[1003], ans;
int d[1003][1003];

void ins(int id) {
    int p = 1, len = strlen(s + 1);
    for (int i = 1, c; i <= len; ++i) {
        if (!ch[p][c = s[i] == 'a']) up[ch[p][c] = ++idcnt] = p;
        p = ch[p][c];
    }
    ((::id[p]) ? res[++ans] : ::id[pos[id] = p]) = id;
}
queue<int> q;
void getfail() {
    if (ch[1][0]) q.push(ch[1][0]), fa[ch[1][0]] = 1;
    if (ch[1][1]) q.push(ch[1][1]), fa[ch[1][1]] = 1;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int c = 0, v; c < 2; ++c)
            if (v = ch[u][c]) {
                int p = fa[u];
                while (p && !ch[p][c]) p = fa[p];
                fa[v] = p ? ch[p][c] : 1, q.push(v);
                lst[v] = id[fa[v]] ? id[fa[v]] : lst[fa[v]];
            }
    }

    for (int i = 1; i <= n; ++i) {
        int p = pos[i];
        while (p) d[lst[p]][i] = d[id[p]][i] = 1, p = up[p];
    }
}

void floyd() {
    for (int k = 1; k <= n; ++k)
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= n; ++j) d[i][j] |= d[i][k] & d[k][j];
    for (int i = 1; i <= n; ++i) d[i][i] = 0;
}

bool vis[1003];
int nxt[1003];
bool dfs(int u) {
    for (int v = 1; v <= n; ++v)
        if (!vis[v] && pos[v] && d[u][v]) {
            vis[v] = 1;
            if (!nxt[v] || dfs(nxt[v])) return nxt[v] = u, 1;
        }
    return 0;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%s", s + 1), ins(i);
    getfail(), floyd();
    for (int i = 1; i <= n; ++i)
        if (pos[i]) ans -= dfs(i), memset(vis, 0, sizeof vis);
    printf("%d\n", n + ans);
    for (int i = 1; i <= n + ans; ++i) {
        if (!res[i]) break;
        printf("%d ", res[i]);
    }
    ans = 0;
    for (int i = 1; i <= n; ++i) vis[nxt[i]] = 1;
    for (int i = 1; i <= n; ++i)
        if (!nxt[i]) res[++ans] = i;
    memset(vis, 0, sizeof vis);
    while (1) {
        int flg = 0;
        for (int j = 1; j <= n; ++j)
            if (!vis[j])
                for (int i = 1; i <= ans; ++i)
                    if (d[res[i]][j]) {
                        vis[j] = 1;
                        break;
                    }
        for (int i = 1; i <= ans; ++i)
            if (vis[res[i]]) {
                flg = 1;
                while (vis[res[i]]) res[i] = nxt[res[i]];
            }
        if (!flg) break;
    }
    for (int i = 1; i <= ans; ++i) printf("%d ", res[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

char s[10000007];
int n;
int idcnt = 1, ch[10000007][2], fa[10000007], lst[10000007], up[10000007];
int id[10000007], pos[1003];
int res[1003], ans;
int d[1003][1003];

void ins(int id) {
    int p = 1, len = strlen(s + 1);
    for (int i = 1, c; i <= len; ++i) {
        if (!ch[p][c = s[i] == 'a']) up[ch[p][c] = ++idcnt] = p;
        p = ch[p][c];
    }
    if (!::id[p]) ::id[pos[id] = p] = id;
}
queue<int> q;
void getfail() {
    if (ch[1][0]) q.push(ch[1][0]), fa[ch[1][0]] = 1;
    if (ch[1][1]) q.push(ch[1][1]), fa[ch[1][1]] = 1;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int c = 0, v; c < 2; ++c)
            if (v = ch[u][c]) {
                int p = fa[u];
                while (p && !ch[p][c]) p = fa[p];
                fa[v] = p ? ch[p][c] : 1, q.push(v);
                lst[v] = id[fa[v]] ? id[fa[v]] : lst[fa[v]];
            }
    }

    for (int i = 1; i <= n; ++i) {
        int p = pos[i];
        while (p) d[lst[p]][i] = d[id[p]][i] = 1, p = up[p];
    }
}

void floyd() {
    for (int k = 1; k <= n; ++k)
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= n; ++j) d[i][j] |= d[i][k] & d[k][j];
    for (int i = 1; i <= n; ++i) d[i][i] = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j)
            if (d[i][j] & d[j][i]) exit(1);
    }
}

bool vis[1003];
int nxt[1003];
bool dfs(int u) {
    for (int v = 1; v <= n; ++v)
        if (!vis[v] && pos[v] && d[u][v]) {
            vis[v] = 1;
            if (!nxt[v] || dfs(nxt[v])) return nxt[v] = u, 1;
        }
    return 0;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%s", s + 1), ins(i);
    getfail(), floyd();
    ans = n;
    for (int i = 1; i <= n; ++i)
        if (pos[i]) ans -= dfs(i), memset(vis, 0, sizeof vis);
    printf("%d\n", ans);
    ans = 0;
    for (int i = 1; i <= n; ++i) vis[nxt[i]] = 1;
    for (int i = 1; i <= n; ++i)
        if (!nxt[i]) res[++ans] = i;
    memset(vis, 0, sizeof vis);
    while (1) {
        int flg = 0;
        for (int j = 1; j <= n; ++j)
            if (!vis[j])
                for (int i = 1; i <= ans; ++i)
                    if (d[res[i]][j]) {
                        vis[j] = 1;
                        break;
                    }
        for (int i = 1; i <= ans; ++i)
            if (vis[res[i]]) {
                flg = 1;
                while (vis[res[i]]) res[i] = nxt[res[i]];
            }
        if (!flg) break;
    }
    for (int i = 1; i <= ans; ++i) printf("%d ", res[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

char s[10000007];
int n;
int idcnt = 1, ch[10000007][2], fa[10000007], lst[10000007], up[10000007];
int id[10000007], pos[1003];
int res[1003], ans;
int d[1003][1003];

void ins(int id) {
    int p = 1, len = strlen(s + 1);
    for (int i = 1, c; i <= len; ++i) {
        if (!ch[p][c = s[i] == 'a']) up[ch[p][c] = ++idcnt] = p;
        p = ch[p][c];
    }
    (!::id[p]) ? ::id[pos[id] = p] = id : --ans;
}
queue<int> q;
void getfail() {
    if (ch[1][0]) q.push(ch[1][0]), fa[ch[1][0]] = 1;
    if (ch[1][1]) q.push(ch[1][1]), fa[ch[1][1]] = 1;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int c = 0, v; c < 2; ++c)
            if (v = ch[u][c]) {
                int p = fa[u];
                while (p && !ch[p][c]) p = fa[p];
                fa[v] = p ? ch[p][c] : 1, q.push(v);
                lst[v] = id[fa[v]] ? id[fa[v]] : lst[fa[v]];
            }
    }

    for (int i = 1; i <= n; ++i) {
        int p = pos[i];
        while (p) d[lst[p]][i] = d[id[p]][i] = 1, p = up[p];
    }
}

void floyd() {
    for (int k = 1; k <= n; ++k)
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= n; ++j) d[i][j] |= d[i][k] & d[k][j];
    for (int i = 1; i <= n; ++i) d[i][i] = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j)
            if (d[i][j] & d[j][i]) exit(1);
    }
}

bool vis[1003];
int nxt[1003];
bool dfs(int u) {
    for (int v = 1; v <= n; ++v)
        if (!vis[v] && pos[v] && d[u][v]) {
            vis[v] = 1;
            if (!nxt[v] || dfs(nxt[v])) return nxt[v] = u, 1;
        }
    return 0;
}

int main() {
    scanf("%d", &n), ans = n;
    for (int i = 1; i <= n; ++i) scanf("%s", s + 1), ins(i);
    getfail(), floyd();
    for (int i = 1; i <= n; ++i)
        if (pos[i]) ans -= dfs(i), memset(vis, 0, sizeof vis);
    int tans = ans;
    printf("%d\n", ans);
    ans = 0;
    for (int i = 1; i <= n; ++i)
        if (pos[i]) vis[nxt[i]] = 1;
    for (int i = 1; i <= n; ++i)
        if (pos[i] && !vis[i]) res[++ans] = i;
    if (tans != ans) exit(1);
    memset(vis, 0, sizeof vis);
    while (1) {
        int flg = 0;
        for (int j = 1; j <= n; ++j)
            if (pos[j] && !vis[j])
                for (int i = 1; i <= ans; ++i)
                    if (pos[i] && d[res[i]][j]) {
                        vis[j] = 1;
                        break;
                    }
        for (int i = 1; i <= ans; ++i)
            if (vis[res[i]]) {
                flg = 1;
                while (vis[res[i]]) res[i] = nxt[res[i]];
            }
        if (!flg) break;
    }
    for (int i = 1; i <= ans; ++i) printf("%d ", res[i]);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

char s[10000007];
int n;
int idcnt = 1, ch[10000007][2], fa[10000007], lst[10000007], up[10000007];
int id[10000007], pos[1003];
int res[1003], ans;
int d[1003][1003];

void ins(int id) {
    int p = 1, len = strlen(s + 1);
    for (int i = 1, c; i <= len; ++i) {
        if (!ch[p][c = s[i] == 'a']) up[ch[p][c] = ++idcnt] = p;
        p = ch[p][c];
    }
    if (!::id[p]) ::id[pos[id] = p] = id;
}
queue<int> q;
void getfail() {
    if (ch[1][0]) q.push(ch[1][0]), fa[ch[1][0]] = 1;
    if (ch[1][1]) q.push(ch[1][1]), fa[ch[1][1]] = 1;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int c = 0, v; c < 2; ++c)
            if (v = ch[u][c]) {
                int p = fa[u];
                while (p && !ch[p][c]) p = fa[p];
                fa[v] = p ? ch[p][c] : 1, q.push(v);
                lst[v] = id[fa[v]] ? id[fa[v]] : lst[fa[v]];
            }
    }

    for (int i = 1; i <= n; ++i) {
        int p = pos[i];
        while (p) d[lst[p]][i] = d[id[p]][i] = 1, p = up[p];
    }
}

void floyd() {
    for (int k = 1; k <= n; ++k)
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= n; ++j) d[i][j] |= d[i][k] & d[k][j];
    for (int i = 1; i <= n; ++i) d[i][i] = 0;
}

bool vis[1003];
int nxt[1003];
bool dfs(int u) {
    for (int v = 1; v <= n; ++v)
        if (!vis[v] && pos[v] && d[u][v]) {
            vis[v] = 1;
            if (!nxt[v] || dfs(nxt[v])) return nxt[v] = u, 1;
        }
    return 0;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%s", s + 1), ins(i);
    getfail(), floyd();
    ans = n;
    for (int i = 1; i <= n; ++i)
        if (pos[i]) ans -= dfs(i), memset(vis, 0, sizeof vis);
    printf("%d\n", ans);
    return 0;
    ans = 0;
    for (int i = 1; i <= n; ++i) vis[nxt[i]] = 1;
    for (int i = 1; i <= n; ++i)
        if (!nxt[i]) res[++ans] = i;
    memset(vis, 0, sizeof vis);
    while (1) {
        int flg = 0;
        for (int j = 1; j <= n; ++j)
            if (!vis[j])
                for (int i = 1; i <= ans; ++i)
                    if (d[res[i]][j]) {
                        vis[j] = 1;
                        break;
                    }
        for (int i = 1; i <= ans; ++i)
            if (vis[res[i]]) {
                flg = 1;
                while (vis[res[i]]) res[i] = nxt[res[i]];
            }
        if (!flg) break;
    }
    for (int i = 1; i <= ans; ++i) printf("%d ", res[i]);
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
const int N=10000007,M=760;
char s[N];
int cnt,ch[N][2];
int is_end[N];
vector<int>S[M];
inline void insert(int x){
    int len=strlen(s+1),now=1;
    for(int i=1;i<=len;++i){
        int u=s[i]-'a';
        S[x].push_back(u);
        if(!ch[now][u])ch[now][u]=++cnt;
        now=ch[now][u];
    }
    is_end[now]=x;
}
int fail[N];
queue<int>q;
inline void get_nxt(){
    for(int i=0;i<2;++i)ch[0][i]=1;
    fail[1]=0;
    q.push(1);
    while(!q.empty()){
        int x=q.front();
        q.pop();
        for(int i=0;i<2;++i){
            int u=ch[x][i];
            if(!u)ch[x][i]=ch[fail[x]][i];
            else {
                int p=fail[x];
                q.push(u);
                fail[u]=ch[p][i];
            }
        }
    }
}
int d[M<<1],nxt[4000000],to[4000000],flow[4000000],tot,pre[M<<1],qd,zd;
inline void add(int a,int b,int c){
    to[++tot]=b;nxt[tot]=d[a];d[a]=tot;flow[tot]=c;
}
inline void ins(int a,int b,int c){
    add(a,b,c);add(b,a,0);
}
const int inf=(1<<30);
int dep[M<<1];
int n,cur[M<<1];
inline bool spfa(){
    memset(dep,0x7f,sizeof(dep));
    memcpy(cur,d,sizeof(cur));
    q.push(zd);
    dep[zd]=1;
    while(!q.empty()){
        int x=q.front();
        q.pop();
        for(int i=d[x];i!=-1;i=nxt[i]){
            int u=to[i];
            if(dep[u]>inf&&flow[i^1]){
                dep[u]=dep[x]+1;
                q.push(u);
            }
        }
    }
    return dep[qd]<inf;
}
int son[N];
inline int dfs(int x){
	if(!x||x==1)return 0;
	if(is_end[x])return x;
	if(son[x])return son[x];
	return son[x]=dfs(fail[x]);
}
bool vis[N];
inline void get_pre(){
	q.push(1);
	vis[1]=1;
	while(!q.empty()){
		int x=q.front();
		q.pop();
		if(!son[x])son[x]=dfs(fail[x]);
		for(int i=0;i<2;++i){
			int u=ch[x][i];
			if(!vis[u]){
				vis[u]=1;q.push(u);
			}
		}
	}
}
inline void bfs(int x){
    int now=1,maxn=S[x].size();
    for(int i=0;i<maxn;++i){
    	int u=S[x][i];
    	now=ch[now][u];
    	int p=now;
    	while(p&&p!=1){
    		if(is_end[p]&&is_end[p]!=x){
    			ins(x,n+is_end[p],1);
    			break;
            }
    		p=son[p];
        }
    }
}
inline int add_flow(){
    int ans=inf,now=zd;
    while(now!=qd){
        ans=min(ans,flow[pre[now]]);
        now=to[pre[now]^1];
    }
    now=zd;
    while(now!=qd){
        flow[pre[now]]-=ans;
        flow[pre[now]^1]+=ans;
        now=to[pre[now]^1];
    }
    return ans;
}
int num[M<<1];
inline int ISAP(){
    if(!spfa())return 0;
    for(int i=qd;i<=zd;++i)if(dep[i]<inf)num[dep[i]]++;
    int now=qd,maxflow=0;
    while(dep[qd]<=zd+1){
        if(now==zd){
            maxflow+=add_flow();
            now=qd;
        }
        bool have_way=0;
        for(int i=cur[now];i!=-1;i=nxt[i]){
            int u=to[i];
            if(dep[u]+1==dep[now]&&flow[i]){
                cur[now]=i;pre[u]=i;
                have_way=1;now=u;
                break;
            }
        }
        if(!have_way){
            if((--num[dep[now]])==0)return maxflow;
            num[++dep[now]]++;
            cur[now]=d[now];
            if(now!=qd)now=to[pre[now]^1];
        }
    }
    return maxflow;
}
int main(){
    memset(d,-1,sizeof(d));tot=-1;
    cnt=1;
    scanf("%d",&n);
    qd=0;zd=(n<<1)|1;
    for(int i=1;i<=n;++i)ins(qd,i,1);
    for(int i=1;i<=n;++i)ins(n+i,zd,1);
    for(int i=1;i<=n;++i)scanf("%s",s+1),insert(i);
    get_nxt();get_pre();
    for(int i=1;i<=n;++i)bfs(i);
    printf("%d\n",n-ISAP());
    for(int i=0;i<(n<<1);i+=2){
        if(flow[i]){
            printf("%d ",to[i]);
        }
    }
    return 0;
}


// #pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<cmath>
// #include<cstdio>
// #include<cctype>
// #include<cstring>
// #include<iomanip>
// #include<iostream>
// #include<algorithm>
using namespace std;
#define maxn 10000010
#define maxm 2000010
#define ll long long
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define rint register ll
#define uint unsigned ll
#define pir pair <ll ,ll >
#define ull unsigned long long

#define fir first
#define sec second
#define LS(x) ((x)<<1)
#define RS(x) ((x)<<1|1)
#define lowbit(i) (i&-i)
#define MID(l,r) ((l)+(r)>>1)

const ll INF=4e18;
const int BASE=131;
const double eps=1e-8;
const int mod=998244353;
const int inf=1061109567;
const double pi=acos(-1);
const int inv2=(mod+1)>>1;

namespace Math{

	inline ll popcount(ll x){
		x = (x&0x55555555) + ((x>>1)&0x55555555);
		x = (x&0x33333333) + ((x>>2)&0x33333333);
		x = (x&0x0F0F0F0F) + ((x>>4)&0x0F0F0F0F);
		x = (x&0x00FF00FF) + ((x>>8)&0x00FF00FF);
		x = (x&0x0000FFFF) + ((x>>16)&0x0000FFFF);
		return x;
	}

	inline ll F(ll x,ll p){return x>=p?x-p:x;}
	inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
	inline ll ksm(ll x,ll t,ll p){
		ll res=1;while(t){
			if(t&1)res=1LL*res*x%p;
			x=1LL*x*x%p;t>>=1;
		}return res;
	}

}

// using Math::popcount;
// using Math::ksm;
// using Math::F;

template < typename tp >
inline void read ( tp & dig ) {
	char ch=getchar();ll flag=0;dig=0;
	while(!isdigit(ch)){ if(ch=='-')flag=1;ch=getchar(); }
	while(isdigit(ch))dig=dig*10+ch-'0',ch=getchar();
	if(flag)dig=-dig;
}

template < typename tp , typename ...Args >
inline void read ( tp & dig , Args & ...args ){
	read(dig);read(args...);
}

int n,cnt,ed[maxn],fa[maxn],son[maxn][2];
int vis[760],mat[760],con[760][760];
int ans,is[760],res[760];
queue <int > que;
string s[760];

inline void insert(int id){
	int now=1,len=s[id].length();
	for(int i=0;i<len;++i){
		int c=s[id][i]-'a';
		if(!son[now][c])son[now][c]=++cnt;
		now=son[now][c];
	}ed[now]=id;
}

inline void get_fail(){
	que.push(1);
	while(!que.empty()){
		int now=que.front();que.pop();
		if(!ed[now])ed[now]=ed[fa[now]];
		for(int i=0;i<2;++i)
			if(son[now][i]){
				int j=fa[now];
				while(!son[j][i])j=fa[j];
				fa[son[now][i]]=son[j][i];
				que.push(son[now][i]);
			}
	}
}

inline void solve(int id){
	int now=1,len=s[id].length();
	for(int i=0;i<len;++i){
		now=son[now][s[id][i]-'a'];
		if(ed[now]^id)con[id][ed[now]]=true;
		else con[id][ed[fa[now]]]=true;
	}
}

inline int dfs(int x,int T){
	for(int i=1;i<=n;++i){
		if(!con[x][i]||vis[i]==T)continue;
		vis[i]=T;
		if(!mat[i]||dfs(mat[i],T)){
			mat[i]=x;return true;
		}
	}return false;
}

int main()
{

#ifndef ONLINE_JUDGE
	freopen("a.in","r",stdin);
	// freopen("a.out","w",stdout);
#endif

	read(n);cnt=1;ans=n;
	for(int i=1;i<=n;++i){
		cin>>s[i];insert(i);
	}son[0][0]=son[0][1]=1;
	get_fail();
	for(int i=1;i<=n;++i)solve(i);
	for(rint k=1;k<=n;++k)
		for(rint i=1;i<=n;++i)
			for(rint j=1;j<=n;++j)con[i][j]|=con[i][k]&con[k][j];
	for(int i=1;i<=n;++i)
		if(dfs(i,i))--ans,is[i]=1;
	printf("%d\n",ans);
	for(int i=1;i<=n;++i)
		if(!is[i])res[++res[0]]=i;
	int flag=1;while(flag){
		flag=0;
		for(int i=1;i<=ans;++i)
			for(int j=1;j<=ans;++j)
				if(con[res[i]][res[j]])vis[res[j]]=n+1;
		for(int i=1;i<=ans;++i)
			if(vis[res[i]]==n+1){
				flag=1;
				while(vis[res[i]]==n+1)
					res[i]=mat[res[i]];
			}
	}for(int i=1;i<=ans;++i)
		printf("%d ",res[i]);
	return 0;

}


#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
cs int N = 755, M = 1e7;
int n, ps[N]; char S[M];
bool a[N][N];
namespace AC{
	int ch[M][2], lk[M], fa[M], trs[M], ed[M], nd;
	void ins(int k){
		scanf("%s",S+1); int len=strlen(S+1), u=0;
		for(int i=1; i<=len; i++){
			int c=S[i]-'a'; if(!ch[u][c])
			ch[u][c]=++nd, fa[nd]=u; u=ch[u][c];
		} ed[u]=k; ps[k]=u;
	}
	void build(){
		queue<int> q;
		for(int i=0; i<2; i++) if(ch[0][i]) q.push(ch[0][i]);
		while(!q.empty()){
			int x = q.front(); q.pop();
			if(ed[lk[x]]) trs[x] = ed[lk[x]];
			else trs[x] = trs[lk[x]];
//			cout<<x<<" "<<lk[x]<<" "<<trs[x]<<" "<<trs[lk[x]]<<" "<<ed[lk[x]]<<endl;
			for(int i=0; i<2; i++)
			if(ch[x][i]) lk[ch[x][i]]=ch[lk[x]][i], q.push(ch[x][i]);
			else ch[x][i]=ch[lk[x]][i];
		}
		for(int i=1; i<=n; i++){
			int x=ps[i];
			while(x){
				if(ed[x]) a[i][ed[x]]=true;
				a[i][trs[x]]=true, x=fa[x];
			}
		}
	}
}
int mch[N], vs[N], TIME;
bool dfs(int u){
	for(int v=1; v<=n; v++) if(a[u][v] && vs[v]!=TIME){
		vs[v]=TIME;
		if(!mch[v]||dfs(mch[v])) return mch[v]=u, true;
	} return false;
}
int main(){
	#ifdef FSYolanda
	freopen("1.in","r",stdin);
	#endif
	scanf("%d",&n);
	for(int i=1; i<=n; i++) AC::ins(i);
	AC::build();
	for(int i=1; i<=n; i++)
	for(int j=1; j<=n; j++) if(!a[i][j])
	for(int k=1; k<=n; k++) 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++,puts(""))
//	for(int j=1; j<=n; j++) cout<<a[i][j]<<" ";
	int as = n;
	for(int i=1; i<=n; i++) ++TIME, as -= dfs(i);
	static bool hv[N];
	vector<int> St; cout<<as<<'\n';
	for(int i=1; i<=n; i++) hv[mch[i]]=true;//, cout<<mch[i]<<endl;
	for(int i=1; i<=n; i++) if(!hv[i]) St.pb(i); // endpos
	memset(hv,0,sizeof(hv)); bool flg=true;
	while(flg){
		flg=false;
		for(int x : St)
		for(int i=1; i<=n; i++) if(a[x][i]) hv[i]=true;
		for(int &x : St) if(hv[x]){
			flg=true; while(hv[x]) x=mch[x];
		}
	} for(int x : St) cout << x << " ";
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define cri const register int
#define re register
using namespace std;
int t[2][10000010];
vector<int>has[10000010];
int tot=1,f[10000010],ised[10000010],eg[800][800];
inline void insert(char *s,cri y){
	for(int i=1,I=strlen(s+1),x=1;i<=I;i++){
		cri in=s[i]-'a';
		if(!t[in][x]) t[in][x]=++tot;
		x=t[in][x];
		has[x].push_back(y);
		if(i==I) ised[x]=y;
	}
	//cout<<y<<endl;
}
int l=1,r=0,que[10000010],sta[10000010],L[800],R[800],n;
inline void build(){
	for(int i=0;i<2;i++)
		if(t[i][1]){
			f[t[i][1]]=1;
			que[++r]=t[i][1];
		}
		else t[i][1]=1;
	while(l<=r){
		cri x=que[l++];
		for(int i=0;i<2;i++)
			if(t[i][x]) {
				f[t[i][x]]=t[i][f[x]];
				que[++r]=t[i][x];
			}
			else t[i][x]=t[i][f[x]];
	}
	ised[1]=-1;
	for(int i=r;i;i--){
		cri x=que[i];int y=f[x],top=0;
		while(!ised[y]) sta[++top]=y,y=f[y];//,cout<<y<<" ";puts("");
		while(top) f[sta[top--]]=y;
		f[x]=y;
		for(int z:has[x]){
			if(ised[x]) eg[z][ised[x]]=1;
			if(y!=1) eg[z][ised[y]]=1;
		}
	}
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++) eg[i][j]|=eg[i][k]&eg[k][j];
	for(int i=1;i<=n;i++) eg[i][i]=0;
}
char s[10000010];
int F[800],v[800],vv[800];
int dfs(cri x){
	for(int i=1;i<=n;i++)
		if(!v[i]&&eg[x][i]){
			v[i]=1;
			if(!F[i]||dfs(f[i])) return F[i]=x,1;
		}
	return 0;
}
void dfss(cri x){
	if(R[x]) return;
	R[x]=1;
	for(int i=1;i<=n;i++) if(eg[x][i]&&!L[i]) L[i]=1,dfss(F[i]);
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) scanf("%s",s+1),insert(s,i);//cout<<1<<endl;
	build();
	int ans=n;
	for(int i=1;i<=n;i++) ans-=dfs(i),memset(v,0,sizeof v);
	cout<<ans<<endl;
	for(int i=1;i<=n;i++) if(!F[i]) dfss(i);
	for(int i=1;i<=n;i++) if(R[i]&&!L[i]) printf("%d ",i);
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
const int N=10000005,M=2000000;
vector<char> vct[755];
int n,m,i,j,k,l,ch[N][2],fail[N],cnt,pt[755],g[N],h[N],q[N],bg,ed,head[N],adj[N],nxt[N],Head[M],Adj[M],Nxt[M],flow[M],cap[M],cur[M],d[M];
char s[N];
bool v[N],b[755][755],vis[755];
void Dfs(int x,int w)
{
	h[x]=w;
	if(g[x])
		w=g[x];
	for(int y=head[x];y;y=nxt[y])
		Dfs(adj[y],w);
}
void Addedge(int u,int v,int w)
{
	//printf("%d %d %d\n",u,v,w);
	Adj[++l]=v;
	Nxt[l]=Head[u];
	Head[u]=l;
	flow[l]=0;
	cap[l]=w;
	Adj[++l]=u;
	Nxt[l]=Head[v];
	Head[v]=l;
	flow[l]=0;
	cap[l]=0;
}
bool bfs()
{
	int i;
	for(i=1;i<=2*m+2;++i)
		d[i]=1<<30;
	d[2*m+1]=0;
	q[bg=ed=1]=2*m+1;
	while(bg<=ed)
	{
		for(i=Head[q[bg]];i;i=Nxt[i])
			if(flow[i]<cap[i]&&d[Adj[i]]==(1<<30))
			{
				d[Adj[i]]=d[q[bg]]+1;
				q[++ed]=Adj[i];
			}
		++bg;
	}
	return d[2*m+2]!=(1<<30);
}
int dfs(int x,int a)
{
	if(x==2*m+2||a<=0)
		return a;
	int g,h=0;
	for(;cur[x];cur[x]=Nxt[cur[x]])
		if(d[Adj[cur[x]]]==d[x]+1&&(g=dfs(Adj[cur[x]],min(a,cap[cur[x]]-flow[cur[x]])))>0)
		{
			flow[cur[x]]+=g;
			flow[cur[x]&1?cur[x]+1:cur[x]-1]-=g;
			a-=g;
			h+=g;
			if(a<=0)
				break;
		}
	return h;
}
void work(int x)
{
	vis[x]=true;
	for(int y=Head[x];y;y=Nxt[y])
		if(!vis[Adj[y]]&&flow[y]<cap[y])
			work(Adj[y]);
}
int main()
{
	scanf("%d",&n);
	while(n--)
	{
		scanf("%s",s+1);
		for(i=1,j=0;s[i];++i)
		{
			if(!ch[j][s[i]-'a'])
				ch[j][s[i]-'a']=++cnt;
			j=ch[j][s[i]-'a'];
		}
		if(v[j])
			continue;
		v[j]=true;
		pt[++m]=j;
		g[j]=m;
		for(i=1;s[i];++i)
			vct[m].push_back(s[i]);
	}
	for(i=0;i<2;++i)
		if(ch[0][i])
			q[++ed]=ch[0][i];
	bg=1;
	while(bg<=ed)
	{
		for(i=0;i<2;++i)
			if(ch[q[bg]][i])
			{
				q[++ed]=ch[q[bg]][i];
				fail[q[ed]]=ch[fail[q[bg]]][i];
			}
			else
				ch[q[bg]][i]=ch[fail[q[bg]]][i];
		++bg;
	}
	for(i=1;i<=cnt;++i)
	{
		adj[i]=i;
		nxt[i]=head[fail[i]];
		head[fail[i]]=i;
	}
	Dfs(0,0);
	for(i=1;i<=m;++i)
	{
		for(j=k=0;j<vct[i].size();++j)
		{
			k=ch[k][vct[i][j]-'a'];
			b[h[k]][i]=true;
			b[g[k]][i]=true;
		}
	}
	for(i=1;i<=m;++i)
		for(j=1;j<=m;++j)
			if(b[i][j]&&i!=j)
			{
				Addedge(i,m+j,1);
				//printf("%d %d\n",i,j);
			}
	for(i=1;i<=m;++i)
	{
		Addedge(2*m+1,i,1);
		Addedge(m+i,2*m+2,1);
	}
	k=0;
	while(bfs())
	{
		for(i=1;i<=2*m+2;++i)
			cur[i]=Head[i];
		k+=dfs(2*m+1,1<<30);
	}
	printf("%d\n",m-k);
	work(2*m+1);
	for(i=1;i<=m;++i)
		if(vis[i]&&!vis[m+i])
			printf("%d ",i);
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#define N 789
#define M 10001000
using namespace std;
const int INF = 0x3f3f3f3f;

namespace A {
	int ch[M][2], fail[M], end[M], cnt;
	inline int insert(char *s, int id, int *dis) {
		int len = strlen(s), rt = 0;
//		cout << s << endl;
		for (int i = 0; i < len; ++i) {
			int d = s[i] - 'a';
			if (!ch[rt][d]) ch[rt][d] = ++cnt;
			rt = ch[rt][d];
		} if (end[rt]) dis[end[rt]] = 1;
		end[rt] = id;
//		cout << rt << endl;
		return len;
	}
	void getfail(int dis[N][N]) {
		queue<int> q;
		if (ch[0][0]) q.push(ch[0][0]);
		if (ch[0][1]) q.push(ch[0][1]);
		while (!q.empty()) {
			int u = q.front(); q.pop();
			for (int k = 0; k <= 1; ++k) {
				if (!ch[u][k]) ch[u][k] = ch[fail[u]][k];
				else {
					fail[ch[u][k]] = ch[fail[u]][k];
					if (end[ch[u][k]] && end[fail[ch[u][k]]])
						dis[end[ch[u][k]]][end[fail[ch[u][k]]]] = 1;
					q.push(ch[u][k]);
				}
			}
		}
	}
	void match(char *s, int len, int *dis) {
		int rt = 0;
//		cout << s << " " << len << " ";
		for (int i = 0; i < len; ++i) {
			rt = ch[rt][s[i] - 'a'];
//			if (end[rt]) cout << end[rt] << endl;
			if (end[rt]) dis[end[rt]] = 1;
		}
//		cout << rt << endl;
	}
};

int n, st[N], dis[N][N];
char s[M];

namespace D {
	int S, T, tot = 1, fir[N], nxt[N * N], to[N * N], val[N * N], dep[N], cur[N];
	queue<int> q;
	inline void addE(int u, int v, int w) {
		nxt[++tot] = fir[u], fir[u] = tot, to[tot] = v, val[tot] = w;
		nxt[++tot] = fir[v], fir[v] = tot, to[tot] = u, val[tot] = 0;
	}
	inline bool bfs() {
		memset(dep, -1, sizeof dep);
		memcpy(cur, fir, sizeof fir);
		q.push(S), dep[S] = 1;
		while (!q.empty()) {
			int u = q.front(); q.pop();
			for (int i = fir[u], v; i; i = nxt[i]) {
				v = to[i];
				if ((~dep[v]) || !val[i]) continue;
				dep[v] = dep[u] + 1, q.push(v);
			}
		} return (~dep[T]);
	}
	int dfs(int u, int now) {
		if (u == T || !now) return now;
		int res = 0;
		for (int &i = cur[u], v; i; i = nxt[i]) {
			v = to[i];
			if (dep[v] != dep[u] + 1 || !val[i]) continue;
			int tmp = dfs(v, min(now, val[i]));
			if (!tmp) continue;
			res += tmp, now -= tmp, val[i] -= tmp, val[i ^ 1] += tmp;
			if (!now) break;
		}
		return res;
	}
	inline int dinic() {
		int res = 0, tmp;
		while (bfs())
			while ((tmp = dfs(S, INF)))
				res += tmp;
		return res;
	}
	int mat[N];
	bool vis[N];
	void match(int u) {
		if (vis[u]) return ;
		vis[u] = 1;
		for (int i = fir[u]; i; i = nxt[i])
			if (!vis[to[i]] && to[i] <= 2 * n) vis[to[i]] = 1, match(mat[to[i]]);
	}
	void write() {
		for (int u = 1; u <= n; ++u)
			for (int i = fir[u]; i && !mat[u]; i = nxt[i])
				if (!val[i] && to[i] <= 2 * n) mat[mat[u] = to[i]] = u;
		for (int u = 1; u <= n; ++u)
			if (!mat[u]) match(u);
		for (int i = 1; i <= n; ++i) {
			//cout << mat[i] - n << " " << mat[i + n] << " " << vis[i] << " " << vis[i + n] << endl;
			if (vis[i] && !vis[i + n]) printf("%d%c", i, " \n"[i == n]);
		}
	}
}

using D::addE;
using D::dinic;

int main() {

	cin >> n;
	for (int i = 1; i <= n; ++i) {
		scanf("%s", s + st[i]);
		st[i + 1] = A::insert(s + st[i], i, dis[i]) + st[i];
	}

	A::getfail(dis);

	for (int i = 1; i <= n; ++i)
		A::match(s + st[i], st[i + 1] - st[i], dis[i]);

	for (int k = 1; k <= n; ++k)
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= n; ++j)
				if (dis[i][k] && dis[k][j])
					dis[i][j] = 1;

/*
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			if (dis[i][j])
				cout << i << " " << j << endl;
*/

	D::S = 2 * n + 1, D::T = D::S + 1;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			if (dis[i][j] && i != j) addE(i, j + n, 1);
	for (int i = 1; i <= n; ++i)
		addE(D::S, i, 1), addE(i + n, D::T, 1);

	int res = dinic();
	res = n - res;

	cout << res << endl;

	D::write();

	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#define N 789
#define M 10001000
using namespace std;
const int INF = 0x3f3f3f3f;

namespace A {
	int ch[M][2], fail[M], end[M], cnt;
	inline int insert(char *s, int id, int *dis) {
		int len = strlen(s), rt = 0;
//		cout << s << endl;
		for (int i = 0; i < len; ++i) {
			int d = s[i] - 'a';
			if (!ch[rt][d]) ch[rt][d] = ++cnt;
			rt = ch[rt][d];
		} if (end[rt]) dis[end[rt]] = 1;
		end[rt] = id;
//		cout << rt << endl;
		return len;
	}
	void getfail(int dis[N][N]) {
		queue<int> q;
		if (ch[0][0]) q.push(ch[0][0]);
		if (ch[0][1]) q.push(ch[0][1]);
		while (!q.empty()) {
			int u = q.front(); q.pop();
			for (int k = 0; k <= 1; ++k) {
				if (!ch[u][k]) ch[u][k] = ch[fail[u]][k];
				else {
					fail[ch[u][k]] = ch[fail[u]][k];
					if (end[fail[ch[u][k]]]) {
						if (end[ch[u][k]]) dis[end[ch[u][k]]][end[fail[ch[u][k]]]] = 1;
						else end[ch[u][k]] = end[fail[ch[u][k]]];
					}
					q.push(ch[u][k]);
				}
			}
		}
	}
	void match(char *s, int len, int *dis) {
		int rt = 0;
//		cout << s << " " << len << " ";
		for (int i = 0; i < len; ++i) {
			rt = ch[rt][s[i] - 'a'];
			if (end[rt]) cout << len << " " << i << "@" << end[rt] << endl;
			if (end[rt]) dis[end[rt]] = 1;
		}
//		cout << rt << endl;
	}
};

int n, st[N], dis[N][N];
char s[M];

namespace D {
	int S, T, tot = 1, fir[N], nxt[N * N], to[N * N], val[N * N], dep[N], cur[N];
	queue<int> q;
	inline void addE(int u, int v, int w) {
		nxt[++tot] = fir[u], fir[u] = tot, to[tot] = v, val[tot] = w;
		nxt[++tot] = fir[v], fir[v] = tot, to[tot] = u, val[tot] = 0;
	}
	inline bool bfs() {
		memset(dep, -1, sizeof dep);
		memcpy(cur, fir, sizeof fir);
		q.push(S), dep[S] = 1;
		while (!q.empty()) {
			int u = q.front(); q.pop();
			for (int i = fir[u], v; i; i = nxt[i]) {
				v = to[i];
				if ((~dep[v]) || !val[i]) continue;
				dep[v] = dep[u] + 1, q.push(v);
			}
		} return (~dep[T]);
	}
	int dfs(int u, int now) {
		if (u == T || !now) return now;
		int res = 0;
		for (int &i = cur[u], v; i; i = nxt[i]) {
			v = to[i];
			if (dep[v] != dep[u] + 1 || !val[i]) continue;
			int tmp = dfs(v, min(now, val[i]));
			if (!tmp) continue;
			res += tmp, now -= tmp, val[i] -= tmp, val[i ^ 1] += tmp;
			if (!now) break;
		}
		return res;
	}
	inline int dinic() {
		int res = 0, tmp;
		while (bfs())
			while ((tmp = dfs(S, INF)))
				res += tmp;
		return res;
	}
	int mat[N];
	bool vis[N];
	void match(int u) {
		if (vis[u]) return ;
		vis[u] = 1;
		for (int i = fir[u]; i; i = nxt[i])
			if (!vis[to[i]] && to[i] <= 2 * n) vis[to[i]] = 1, match(mat[to[i]]);
	}
	void write() {
		for (int u = 1; u <= n; ++u)
			for (int i = fir[u]; i && !mat[u]; i = nxt[i])
				if (!val[i] && to[i] <= 2 * n) mat[mat[u] = to[i]] = u;
		for (int u = 1; u <= n; ++u)
			if (!mat[u]) match(u);
		for (int i = 1; i <= n; ++i) {
			//cout << mat[i] - n << " " << mat[i + n] << " " << vis[i] << " " << vis[i + n] << endl;
			if (vis[i] && !vis[i + n]) printf("%d%c", i, " \n"[i == n]);
		}
	}
}

using D::addE;
using D::dinic;

int main() {

	cin >> n;
	for (int i = 1; i <= n; ++i) {
		scanf("%s", s + st[i]);
		st[i + 1] = A::insert(s + st[i], i, dis[i]) + st[i];
	}

	A::getfail(dis);

	for (int i = 1; i <= n; ++i)
		A::match(s + st[i], st[i + 1] - st[i], dis[i]);

	for (int k = 1; k <= n; ++k)
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= n; ++j)
				if (dis[i][k] && dis[k][j])
					dis[i][j] = 1;

	cout << " # # # # # # # connections: " << endl;

	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			if (dis[i][j])
				cout << i << " " << j << endl;

	D::S = 2 * n + 1, D::T = D::S + 1;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			if (dis[i][j] && i != j) addE(i, j + n, 1);
	for (int i = 1; i <= n; ++i)
		addE(D::S, i, 1), addE(i + n, D::T, 1);

	int res = dinic();
	res = n - res;

	cout << res << endl;

	D::write();

	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1502,M=10001002;
char s[M],t[M];
bool edg[N][N],pp[N];
int n,i,j,k,m,vis[N],Mc[N],L[N],R[N],S;
int q[N],l,r;
struct AC{
	int ch[M][2],id[M],cnt,q[M],fail[M],s,e;
	void insert(char *s,int d){
		int i,j;
		for(i=1,j=0;s[j];j++){
			if(!ch[i][s[j]-97])
				ch[i][s[j]-97]=++cnt;
			i=ch[i][s[j]-97];
		}
		id[i]=d;
	}
	void build(){
		e=-1;
		int i,j;
		for(i=0;i<2;i++)
			if(ch[1][i])
				fail[ch[1][i]]=1,q[++e]=ch[1][i];
			else
				ch[1][i]=1;
		while(s<=e){
			i=q[s++];
			for(j=0;j<2;j++)
				if(ch[i][j])
					fail[ch[i][j]]=ch[fail[i]][j],q[++e]=ch[i][j];
				else
					ch[i][j]=ch[fail[i]][j];
		}
		for(i=1;i<=cnt;i++){
			if(!id[i])
				id[i]=id[fail[i]];
		}
	}
	void extend(char *s,int d){
		int i,j;
		for(i=1,j=0;s[j];j++){
			if(!ch[i][s[j]-97])
				ch[i][s[j]-97]=++cnt;
			i=ch[i][s[j]-97];
			edg[d][id[i]]=1;
			edg[d][id[fail[i]]]=1;
		}
	}
}T;
void init(){
	T.cnt=1;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%s",s);
		T.insert(s,i);
		for(m=0;s[m];m++);
		L[i]=R[i-1];
		for(j=0;j<m;j++)
			t[L[i]+j]=s[j];
		R[i]=L[i]+m;
	}
	T.build();
	for(i=1;i<=n;i++){
		m=R[i]-L[i];
		for(j=0;j<m;j++)
			s[j]=t[L[i]+j];
		s[j]=0;
		T.extend(s,i);
	}
}
bool dfs(int i){
	for(int j=1;j<=n;j++)
		if(edg[i][j]&&vis[j]!=k){
			vis[j]=k;
			if(!Mc[j]||dfs(Mc[j])){
				Mc[j]=i;
				return 1;
			}
		}
	return 0;
}
void work(){
	for(k=1;k<=n;k++)
		for(i=1;i<=n;i++)
			if(edg[i][k])
				for(j=1;j<=n;j++)
					edg[i][j]|=edg[i][k]&edg[k][j];
	for(i=1;i<=n;i++)
		edg[i][i]=0;
	for(k=1;k<=n;k++)
		S+=(pp[k]=dfs(k));
	printf("%d\n",n-S);
	memset(vis,0,sizeof(vis));
	r=-1;
	for(i=1;i<=n;i++)
		if(!pp[i]){
			vis[i]=1;
			q[++r]=i;
		}
	while(l<=r){
		i=q[l++];
		for(j=1;j<=n;j++)
			if(edg[i][j]&&Mc[j]!=i&&!vis[j+n]){
				vis[n+j]=1;
				vis[Mc[j]]=1;
				q[++r]=Mc[j];
			}
	}
	for(i=1;i<=n;i++)
		if(!vis[i]||vis[i+n])
			;
		else
			printf("%d ",i);
}
int main(){
	init();
	work();
	return 0;
}


#include <bitset>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>

#define pb push_back
#define ppb pop_back

const int N=755;

const int L=1e7+5;

char s[L];

int n,pos[N],vis[N],lk[N];

int rt,node_cnt,ch[L][2],fa[L],fail[L],_end[L];

std::bitset<N> f[N];

bool dfs(int x){
	for(int y=1;y<=n;++y) if(f[x][y]&&!vis[y]){
		vis[y]=1; if(!lk[y]||dfs(lk[y])) return lk[y]=x,1;
	}
	return 0;
}

int main(){
	scanf("%d",&n); rt=++node_cnt;
	for(int i=1;i<=n;++i){
		scanf("%s",s); int len=strlen(s),u=rt;
		for(int j=0;j<len;++j){
			int c=s[j]-'a';
			if(!ch[u][c]) ch[u][c]=++node_cnt;
			fa[ch[u][c]]=u; u=ch[u][c];
		}
		_end[u]=i; pos[i]=u;
	}
	std::queue<int> Q;
	for(int c=0;c<2;++c){
		if(!ch[rt][c]) ch[rt][c]=rt;
		else{	fail[ch[rt][c]]=rt; Q.push(ch[rt][c]); }
	}
	while(!Q.empty()){
		int u=Q.front(); Q.pop();
		for(int c=0;c<2;++c){
			if(!ch[u][c]) ch[u][c]=ch[fail[u]][c];
			else{ fail[ch[u][c]]=ch[fail[u]][c]; Q.push(ch[u][c]); }
		}
	}
	_end[rt]=-1; std::vector<int> q;
	for(int i=1;i<=n;++i) for(int u=pos[i];u!=rt;u=fa[u]){
		int p=fail[u]; q.clear(); for(;!_end[p];p=fail[p]) q.pb(p);
		for(;!q.empty();q.ppb()) fail[q.back()]=p; fail[u]=p;
		if(u!=pos[i]&&_end[u]) p=u; if(p!=1) f[i][_end[p]]=1;
	}
	for(int k=1;k<=n;++k) for(int i=1;i<=n;++i) if(f[i][k]) f[i]|=f[k];
	for(int i=1;i<=n;++i) f[i][i]=0; int ans=n;
	for(int i=1;i<=n;++i) memset(vis,0,sizeof(vis)),ans-=dfs(i);
	printf("%d\n",ans); memset(vis,0,sizeof(vis));
	for(int i=1;i<=n;++i) vis[lk[i]]=1;
	std::vector<int> s; for(int i=1;i<=n;++i) if(!vis[i]) s.pb(i);
	for(bool flag=1;flag;){
		flag=0; memset(vis,0,sizeof(vis));
		for(auto x: s) for(int y=1;y<=n;++y) if(f[x][y]) vis[y]=1;
		for(auto &x: s) if(vis[x]){ flag=1; while(vis[x]) x=lk[x]; }
	}
	for(auto x: s) printf("%d ",x); printf("\n");
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define cri const register int
#define re register
using namespace std;
int t[2][10000010];
vector<int>has[10000010];
int tot=1,f[10000010],ised[10000010],eg[800][800];
inline void insert(char *s,cri y){
	for(int i=1,I=strlen(s+1),x=1;i<=I;i++){
		cri in=s[i]-'a';
		if(!t[in][x]) t[in][x]=++tot;
		x=t[in][x];
		has[x].push_back(y);
		if(i==I) ised[x]=y;
	}
	//cout<<y<<endl;
}
int l=1,r=0,que[10000010],sta[10000010],L[800],R[800],n;
inline void build(){
	for(int i=0;i<2;i++)
		if(t[i][1]){
			f[t[i][1]]=1;
			que[++r]=t[i][1];
		}
		else t[i][1]=1;
	while(l<=r){
		cri x=que[l++];
		for(int i=0;i<2;i++)
			if(t[i][x]) {
				f[t[i][x]]=t[i][f[x]];
				que[++r]=t[i][x];
			}
			else t[i][x]=t[i][f[x]];
	}
	ised[1]=-1;
	for(int i=r;i;i--){
		cri x=que[i];int y=f[x],top=0;
		while(!ised[y]) sta[++top]=y,y=f[y];//,cout<<y<<" ";puts("");
		while(top) f[sta[top--]]=y;
		f[x]=y;
		for(int z:has[x]){
			if(ised[x]) eg[z][ised[x]]=1;
			if(y!=1) eg[z][ised[y]]=1;
		}
	}
	for(int i=1;i<=n;i++) eg[i][i]=0;
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++) eg[i][j]|=eg[i][k]&eg[k][j];
}
char s[10000010];
int F[800],v[800],vv[800];
int dfs(cri x){
	for(int i=1;i<=n;i++)
		if(!v[i]&&eg[x][i]){
			v[i]=1;
			if(!F[i]||dfs(f[i])) return F[i]=x,1;
		}
	return 0;
}
void dfss(cri x){
	if(R[x]) return;
	R[x]=1;
	for(int i=1;i<=n;i++) if(eg[x][i]&&!L[i]) L[i]=1,dfss(F[i]);
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) scanf("%s",s+1),insert(s,i);//cout<<1<<endl;
	build();
	int ans=n;
	for(int i=1;i<=n;i++) ans-=dfs(i),memset(v,0,sizeof v);
	cout<<ans<<endl;
	for(int i=1;i<=n;i++) if(!F[i]) dfss(i);
	for(int i=1;i<=n;i++) if(L[i]&&!R[i]) printf("%d ",i);
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>

using namespace std;

const int MAXN = 750 + 10;
const int MAXM = 1e07 + 10;

struct LFS { int to, next; };
LFS Link[MAXN * MAXN];
int Head[MAXM]= {0}, size = 0;
void Insert (int u, int v) {
	Link[++ size].to = v;
	Link[size].next = Head[u];

	Head[u] = size;
}

LFS Lk[MAXM << 1];
int Hd[MAXM], sze = 0;
void iInsert (int u, int v) {
	Lk[++ sze].to = v;
	Lk[sze].next = Hd[u];

	Hd[u] = sze;
}

vector<int> G[MAXN];

int N;
char str[MAXM];
vector<int> sve[MAXN];

int tr[MAXM][2]= {0}, m = 0;

void insert (int ind) {
	int p = 0, n = strlen (str + 1);
	for (int i = 1; i <= n; i ++) {
		int c = str[i] - 'a';
		sve[ind].push_back(c);
		if (! tr[p][c]) tr[p][c] = ++ m;
		p = tr[p][c];
	}
	Insert (p, ind);
}
int fail[MAXM]= {0};
queue<int> que;
void build () {
	for (int i = 0; i < 2; i ++)
		if (tr[0][i])
			que.push(tr[0][i]);
	while (! que.empty()) {
		int u = que.front(); que.pop();
		iInsert (fail[u], u);
		for (int i = 0; i < 2; i ++) {
			if (tr[u][i]) {
				fail[tr[u][i]] = tr[fail[u]][i];
				que.push(tr[u][i]);
			}
			else tr[u][i] = tr[fail[u]][i];
		}
	}
}
int lastp[MAXM]= {0};
void DFS (int u, int lp) {
	lastp[u] = lp;
	for (int i = Hd[u]; ~ i; i = Lk[i].next) {
		int v = Lk[i].to;
		DFS (v, Head[u] ? u : lp);
	}
}
int indeg[MAXN]= {0};
void work (int ind) {
	int p = 0;
	for (int i = 0; i < (int) sve[ind].size(); i ++) {
		int c = sve[ind][i];
		p = tr[p][c];
		/*for (int j = p; j; j = fail[j]) {
			bool in = false;
			for (int k = Head[j]; k; k = Link[k].next) {
				int v = Link[k].to;
				if (v == ind) continue;
				in = true;
				G[v].push_back(ind); indeg[ind] ++;
				cout << v << ' ' << ind << endl;
			}
			if (in) break;
		}*/
		for (int k = Head[lastp[p]]; k; k = Link[k].next) {
			int v = Link[k].to;
			if (v == ind) continue;
			G[v].push_back(ind); indeg[ind] ++;
		}
	}
}

vector<int> anss;

int main () {
	memset (Hd, - 1, sizeof (Hd));
	scanf ("%d", & N);
	for (int i = 1; i <= N; i ++) {
		scanf ("%s", str + 1);
		insert (i);
	}
	build ();
	DFS (0, 0);
	for (int i = 1; i <= N; i ++) work (i);
	int ans = 0;
	for (int i = 1; i <= N; i ++)
		if (! indeg[i]) {
			ans ++;
			anss.push_back(i);
		}
	printf ("%d\n", ans);
	for (int i = 0; i < (int) anss.size(); i ++) {
		if (i > 0) putchar (' ');
		printf ("%d", anss[i]);
	}
	puts ("");

	return 0;
}

/*
5
abab
aba
aabab
ababb
bab
*/


#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
const int C=2;
struct AC_auto {
	char base;
    struct node{
        int next[C],fail,cnt;
        std::vector<int> ids;
        node():fail(-1),cnt(0),ids(0){
            for(int i=0;i<C;i++) next[i]=0;
        }
    };
    std::vector<node> V;
    AC_auto():V(1),base('a'){};
    inline void clear(){
        V.clear();
        V.push_back(node());
    }
    inline void insert(char *s,int id){
        int now=0;
        for(int i=0;s[i];i++){
            int c=s[i]-base;
            if(V[now].next[c]==0){
                V.push_back(node());
                V[now].next[c]=V.size()-1;
            }
            now=V[now].next[c];
        }
        V[now].cnt++;
        V[now].ids.push_back(id);
    }
    inline void build_fail(){
        std::queue<int> Q;
        Q.push(0);
        while(!Q.empty()){
            int now=Q.front();
            Q.pop();
            for(int i=0;i<C;i++){
                if(V[now].next[i]==0) continue;
                int pfail=V[now].fail;
                while(pfail!=-1&&V[pfail].next[i]==0) pfail=V[pfail].fail;
                V[V[now].next[i]].fail=pfail==-1 ? 0:V[pfail].next[i];
                Q.push(V[now].next[i]);
            }
        }
    }
    inline int solve(char *t,int *res){
        int i,now=0,x,r=0;
        for(i=0;t[i];i++){
            int c=t[i]-base;
            while(now>0&&V[now].next[c]==0) now=V[now].fail;
            if(V[now].next[c]==0) continue;
            x=now=V[now].next[c];
            while(x>0){
                for(int j=0;j<V[x].ids.size();j++){
                	if(res[V[x].ids[j]]) goto end; //cut
                    res[V[x].ids[j]]=1;
                }
                x=V[x].fail;
                end:;
            }
        }
        return r;
    }
} ac;
struct Perfect_graph {
	int (*adj)[750],n; // NEED SET IT!!
	int used[2][750],matched[750],mx[750];
	void tracking(int u) {
	    if (used[0][u]) return ;
	    used[0][u] = true;
	    for(int v=0;v<n;v++){
			if (adj[u][v]&&!used[1][v]) {
			    used[1][v] = true;
				if(mx[v]!=-1) tracking(mx[v]);
			}
	    }
	}
	bool matching(int u) {
	    for(int v=0;v<n;v++){
	        if (adj[u][v]&&!used[0][v]) {
	        	used[0][v] = true;
	            if (mx[v] == -1 || matching(mx[v])) {
	                mx[v] = u;
	                return true;
	            }
	        }
	    }
	    return false;
	}
	std::vector<int> maximum_independent_set_find(){
		std::vector<int> ans;
		for(int i=0;i<n;i++){
			mx[i]=-1;
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				used[0][j] = false;
			}
	        matched[i] = matching(i);
	    }
	    for(int i=0;i<n;i++){
	    	used[0][i] = used[1][i] = false;
	    }
	    for(int i=0;i<n;i++){
	        if (!matched[i]) tracking(i);
	    }
	    for(int i=0;i<n;i++){
	        if (!(matched[i] && !used[0][i] || mx[i] != -1 && used[1][i]))
	            ans.push_back(i);
	    }
	    return ans;
	}
} perfect_graph;
char s_p[10000000 + 750];
char *s[750], *s_pnow;
int r[750][750];
int main(){
	int i,j,k;
	int n;
	scanf("%d",&n);
	s_pnow = s_p;
	for(i=0;i<n;i++){
		s[i]=s_pnow;
		scanf("%s",s[i]);
		while(*s_pnow++);
		ac.insert(s[i],i);
	}
	ac.build_fail();
	for(i=0;i<n;i++){
		ac.solve(s[i],r[i]);
		r[i][i]=0;
	}
	perfect_graph.n=n;
	perfect_graph.adj=r;
	std::vector<int> ans=perfect_graph.maximum_independent_set_find();
	printf("%d\n",ans.size());
	for(i=0;i<ans.size();i++){
		printf("%d%c",ans[i]+1," \n"[i==n-1]);
	}
}
// 3 a b ab
// 3 a aa ab
// ntuj - 7srkhr9x8clgyuu4d5t8f


#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
const int C=2;
struct AC_auto {
	char base;
    struct node{
        int next[C],fail,go;
        int id;
        node():fail(-1),id(-1){
            for(int i=0;i<C;i++) next[i]=0;
        }
    };
    std::vector<node> V;
    AC_auto():V(1),base('a'){};
    inline void clear(){
        V.clear();
        V.push_back(node());
    }
    inline void insert(char *s,int id){
        int now=0;
        for(int i=0;s[i];i++){
            int c=s[i]-base;
            if(V[now].next[c]==0){
                V.push_back(node());
                V[now].next[c]=V.size()-1;
            }
            now=V[now].next[c];
        }
        //V[now].cnt++;
        V[now].id = id;
    }
    inline void build_fail(){
        std::queue<int> Q;
        Q.push(0);
        V[0].go=0;
        while(!Q.empty()){
            int now=Q.front();
            Q.pop();
            if(now){if(V[V[now].fail].id>=0) V[now].go=V[now].fail;
            else V[now].go=V[V[now].fail].go;}
            //printf("%d %d %d %d\n",now,V[0].go,V[now].fail,V[V[now].fail].cnt);
            for(int i=0;i<C;i++){
                if(V[now].next[i]==0) continue;
                int pfail=V[now].fail;
                while(pfail!=-1&&V[pfail].next[i]==0) pfail=V[pfail].fail;
                V[V[now].next[i]].fail=pfail==-1 ? 0:V[pfail].next[i];
                Q.push(V[now].next[i]);
            }
        }
    }
    inline int solve(char *t,int *res){
        int i,now=0,x,r=0;
        for(i=0;t[i];i++){
            int c=t[i]-base;
            while(now>0&&V[now].next[c]==0) now=V[now].fail;
            if(V[now].next[c]==0) continue;
            x=now=V[now].next[c];
            while(x>0){
                /*if(V[x].ids){
					res[(*(V[x].ids))[0]]=1;

					for(int j=1;j<V[x].ids->size();j++){
	                	//if(res[V[x].ids[j]]) goto end; //cut
	                    res[(*(V[x].ids))[j]]=1;
	                }
	                //printf("%d %d\n",x,V[x].go);
	            } */
				if(V[x].id>=0) res[V[x].id]++;
	            x=V[x].go;

                //x=V[x].fail;
            }
            //now=x;
            //end:;
        }
        return r;
    }
} ac;
struct Perfect_graph {
	int (*adj)[750],n; // NEED SET IT!!
	int used[2][750],matched[750],mx[750];
	void tracking(int u) {
	    if (used[0][u]) return ;
	    used[0][u] = true;
	    for(int v=0;v<n;v++){
			if (adj[u][v]&&!used[1][v]) {
			    used[1][v] = true;
				if(mx[v]!=-1) tracking(mx[v]);
			}
	    }
	}
	bool matching(int u) {
	    for(int v=0;v<n;v++){
	        if (adj[u][v]&&!used[0][v]) {
	        	used[0][v] = true;
	            if (mx[v] == -1 || matching(mx[v])) {
	                mx[v] = u;
	                return true;
	            }
	        }
	    }
	    return false;
	}
	std::vector<int> maximum_independent_set_find(){
		std::vector<int> ans;
		for(int i=0;i<n;i++){
			mx[i]=-1;
		}
		for(int i=0;i<n;i++){ // or i=0 ?
			for(int j=0;j<n;j++){
				used[0][j] = false;
			}
	        matched[i] = matching(i);
	    }
	    for(int i=0;i<n;i++){
	    	used[0][i] = used[1][i] = false;
	    }
	    for(int i=0;i<n;i++){
	        if (!matched[i]) tracking(i);
	    }
	    for(int i=0;i<n;i++){
	        if (!(matched[i] && !used[0][i] || mx[i] != -1 && used[1][i]))
	            ans.push_back(i);
	    }
	    return ans;
	}
} perfect_graph;
char s_p[10000000 + 750];
char *s[750], *s_pnow;
int r[750][750];
int main(){
	int i,j,k;
	int n=750;
	scanf("%d",&n);
	//
	s_pnow = s_p;
	for(i=0;i<n;i++){
		s[i]=s_pnow;
		//for(j=0;j<10000000/750-i;j++) s[i][j]='a';
		//s[i][j]=0;
		//printf("%s\n",s[i]);
		scanf("%s",s[i]);
		while(*s_pnow++);
		ac.insert(s[i],i);
	}
	ac.build_fail();
	//printf("%d\n",ac.V.size());
	for(i=0;i<n;i++){
		ac.solve(s[i],r[i]);
		//printf("%d\n",i);
		r[i][i]=0;
	}
	perfect_graph.n=n;
	perfect_graph.adj=r;
	std::vector<int> ans=perfect_graph.maximum_independent_set_find();
	printf("%d\n",ans.size());
	for(i=0;i<ans.size();i++){
		printf("%d%c",ans[i]+1," \n"[i==n-1]);
	}
}
// 3 a b ab
// 3 a aa ab
// ntuj - 6lpm72b59vx0tkvu6eac8


#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
const int C=2;
struct AC_auto {
	char base;
    struct node{
        int next[C],fail,go;
        int id;
        node():fail(-1),id(-1){
            for(int i=0;i<C;i++) next[i]=0;
        }
    };
    std::vector<node> V;
    AC_auto():V(1),base('a'){};
    inline void clear(){
        V.clear();
        V.push_back(node());
    }
    inline void insert(char *s,int id){
        int now=0;
        for(int i=0;s[i];i++){
            int c=s[i]-base;
            if(V[now].next[c]==0){
                V.push_back(node());
                V[now].next[c]=V.size()-1;
            }
            now=V[now].next[c];
        }
        //V[now].cnt++;
        V[now].id = id;
    }
    inline void build_fail(){
        std::queue<int> Q;
        Q.push(0);
        V[0].go=0;
        while(!Q.empty()){
            int now=Q.front();
            Q.pop();
            if(now){if(V[V[now].fail].id>=0) V[now].go=V[now].fail;
            else V[now].go=V[V[now].fail].go;}
            //printf("%d %d %d %d\n",now,V[0].go,V[now].fail,V[V[now].fail].cnt);
            for(int i=0;i<C;i++){
                if(V[now].next[i]==0) continue;
                int pfail=V[now].fail;
                while(pfail!=-1&&V[pfail].next[i]==0) pfail=V[pfail].fail;
                V[V[now].next[i]].fail=pfail==-1 ? 0:V[pfail].next[i];
                Q.push(V[now].next[i]);
            }
        }
    }
    inline int solve(char *t,int *res){
        int i,now=0,x,r=0;
        for(i=0;t[i];i++){
            int c=t[i]-base;
            while(now>0&&V[now].next[c]==0) now=V[now].fail;
            if(V[now].next[c]==0) continue;
            x=now=V[now].next[c];
            while(x>0){
                /*if(V[x].ids){
					res[(*(V[x].ids))[0]]=1;

					for(int j=1;j<V[x].ids->size();j++){
	                	//if(res[V[x].ids[j]]) goto end; //cut
	                    res[(*(V[x].ids))[j]]=1;
	                }
	                //printf("%d %d\n",x,V[x].go);
	            } */
				if(V[x].id>=0) {
					if(res[V[x].id]) break;
					res[V[x].id]++;
				}
	            x=V[x].go;

                //x=V[x].fail;
            }
            //now=x;
            //end:;
        }
        return r;
    }
} ac;
struct Perfect_graph {
	int (*adj)[750],n; // NEED SET IT!!
	int used[2][750],matched[750],mx[750];
	void tracking(int u) {
	    if (used[0][u]) return ;
	    used[0][u] = true;
	    for(int v=0;v<n;v++){
			if (adj[u][v]&&!used[1][v]) {
			    used[1][v] = true;
				if(mx[v]!=-1) tracking(mx[v]);
			}
	    }
	}
	bool matching(int u) {
	    for(int v=0;v<n;v++){
	        if (adj[u][v]&&!used[0][v]) {
	        	used[0][v] = true;
	            if (mx[v] == -1 || matching(mx[v])) {
	                mx[v] = u;
	                return true;
	            }
	        }
	    }
	    return false;
	}
	std::vector<int> maximum_independent_set_find(){
		std::vector<int> ans;
		for(int i=0;i<n;i++){
			mx[i]=-1;
		}
		for(int i=0;i<n;i++){ // or i=0 ?
			for(int j=0;j<n;j++){
				used[0][j] = false;
			}
	        matched[i] = matching(i);
	    }
	    for(int i=0;i<n;i++){
	    	used[0][i] = used[1][i] = false;
	    }
	    for(int i=0;i<n;i++){
	        if (!matched[i]) tracking(i);
	    }
	    for(int i=0;i<n;i++){
	        if (!(matched[i] && !used[0][i] || mx[i] != -1 && used[1][i]))
	            ans.push_back(i);
	    }
	    return ans;
	}
} perfect_graph;
char s_p[10000000 + 750];
char *s[750], *s_pnow;
int r[750][750];
int main(){
	int i,j,k;
	int n=750;
	scanf("%d",&n);
	//
	s_pnow = s_p;
	for(i=0;i<n;i++){
		s[i]=s_pnow;
		//for(j=0;j<10000000/750-i;j++) s[i][j]='a';
		//s[i][j]=0;
		//printf("%s\n",s[i]);
		scanf("%s",s[i]);
		while(*s_pnow++);
		ac.insert(s[i],i);
	}
	ac.build_fail();
	//printf("%d\n",ac.V.size());
	for(i=0;i<n;i++){
		ac.solve(s[i],r[i]);
		//printf("%d\n",i);
		r[i][i]=0;
	}
	perfect_graph.n=n;
	perfect_graph.adj=r;
	std::vector<int> ans=perfect_graph.maximum_independent_set_find();
	printf("%d\n",ans.size());
	for(i=0;i<ans.size();i++){
		printf("%d%c",ans[i]+1," \n"[i==n-1]);
	}
}
// 3 a b ab
// 3 a aa ab
// ntuj - gor3ska44qn3ad6t7sx8b


#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
const int C=2;
struct AC_auto {
	char base;
    struct node{
        int next[C],fail,go;
        std::vector<int> *ids;
        node():fail(-1),ids(0){
            for(int i=0;i<C;i++) next[i]=0;
        }
    };
    std::vector<node> V;
    AC_auto():V(1),base('a'){};
    inline void clear(){
        V.clear();
        V.push_back(node());
    }
    inline void insert(char *s,int id){
        int now=0;
        for(int i=0;s[i];i++){
            int c=s[i]-base;
            if(V[now].next[c]==0){
                V.push_back(node());
                V[now].next[c]=V.size()-1;
            }
            now=V[now].next[c];
        }
        //V[now].cnt++;
        if(!V[now].ids) V[now].ids = new std::vector<int>;
        V[now].ids->push_back(id);
    }
    inline void build_fail(){
        std::queue<int> Q;
        Q.push(0);
        V[0].go=0;
        while(!Q.empty()){
            int now=Q.front();
            Q.pop();
            if(now){if(V[V[now].fail].ids) V[now].go=V[now].fail;
            else V[now].go=V[V[now].fail].go;}
            //printf("%d %d %d %d\n",now,V[0].go,V[now].fail,V[V[now].fail].cnt);
            for(int i=0;i<C;i++){
                if(V[now].next[i]==0) continue;
                int pfail=V[now].fail;
                while(pfail!=-1&&V[pfail].next[i]==0) pfail=V[pfail].fail;
                V[V[now].next[i]].fail=pfail==-1 ? 0:V[pfail].next[i];
                Q.push(V[now].next[i]);
            }
        }
    }
    inline int solve(char *t,int *res){
        int i,now=0,x,r=0;
        for(i=0;t[i];i++){
            int c=t[i]-base;
            while(now>0&&V[now].next[c]==0) now=V[now].fail;
            if(V[now].next[c]==0) continue;
            x=now=V[now].next[c];
            while(x>0){
                if(V[x].ids){
					(*(V[x].ids))[0]=1;

					for(int j=1;j<V[x].ids->size();j++){
	                	//if(res[V[x].ids[j]]) goto end; //cut
	                    res[(*(V[x].ids))[j]]=1;
	                }
	                //printf("%d %d\n",x,V[x].go);
	            }
	            x=V[x].go;

                //x=V[x].fail;
            }
            //now=x;
            //end:;
        }
        return r;
    }
} ac;
struct Perfect_graph {
	int (*adj)[750],n; // NEED SET IT!!
	int used[2][750],matched[750],mx[750];
	void tracking(int u) {
	    if (used[0][u]) return ;
	    used[0][u] = true;
	    for(int v=0;v<n;v++){
			if (adj[u][v]&&!used[1][v]) {
			    used[1][v] = true;
				if(mx[v]!=-1) tracking(mx[v]);
			}
	    }
	}
	bool matching(int u) {
	    for(int v=0;v<n;v++){
	        if (adj[u][v]&&!used[0][v]) {
	        	used[0][v] = true;
	            if (mx[v] == -1 || matching(mx[v])) {
	                mx[v] = u;
	                return true;
	            }
	        }
	    }
	    return false;
	}
	std::vector<int> maximum_independent_set_find(){
		std::vector<int> ans;
		for(int i=0;i<n;i++){
			mx[i]=-1;
		}
		for(int i=0;i<n;i++){ // or i=0 ?
			for(int j=0;j<n;j++){
				used[0][j] = false;
			}
	        matched[i] = matching(i);
	    }
	    for(int i=0;i<n;i++){
	    	used[0][i] = used[1][i] = false;
	    }
	    for(int i=0;i<n;i++){
	        if (!matched[i]) tracking(i);
	    }
	    for(int i=0;i<n;i++){
	        if (!(matched[i] && !used[0][i] || mx[i] != -1 && used[1][i]))
	            ans.push_back(i);
	    }
	    return ans;
	}
} perfect_graph;
char s_p[10000000 + 750];
char *s[750], *s_pnow;
int r[750][750];
int main(){
	int i,j,k;
	int n=750;
	scanf("%d",&n);
	//
	s_pnow = s_p;
	for(i=0;i<n;i++){
		s[i]=s_pnow;
		//for(j=0;j<10000000/750-i;j++) s[i][j]='a';
		//s[i][j]=0;
		//printf("%s\n",s[i]);
		scanf("%s",s[i]);
		while(*s_pnow++);
		ac.insert(s[i],i);
	}
	ac.build_fail();
	//printf("%d\n",ac.V.size());
	for(i=0;i<n;i++){
		ac.solve(s[i],r[i]);
		//printf("%d\n",i);
		r[i][i]=0;
	}
	perfect_graph.n=n;
	perfect_graph.adj=r;
	std::vector<int> ans=perfect_graph.maximum_independent_set_find();
	printf("%d\n",ans.size());
	for(i=0;i<ans.size();i++){
		printf("%d%c",ans[i]+1," \n"[i==n-1]);
	}
}
// 3 a b ab
// 3 a aa ab
// ntuj - 4ppsdzv8bj6gk7gtd9s3m


#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
const int C=2;
struct AC_auto {
	char base;
    struct node{
        int next[C],fail,cnt;
        std::vector<int> ids;
        node():fail(-1),cnt(0),ids(0){
            for(int i=0;i<C;i++) next[i]=0;
        }
    };
    std::vector<node> V;
    AC_auto():V(1),base('a'){};
    inline void clear(){
        V.clear();
        V.push_back(node());
    }
    inline void insert(char *s,int id){
        int now=0;
        for(int i=0;s[i];i++){
            int c=s[i]-base;
            if(V[now].next[c]==0){
                V.push_back(node());
                V[now].next[c]=V.size()-1;
            }
            now=V[now].next[c];
        }
        V[now].cnt++;
        V[now].ids.push_back(id);
    }
    inline void build_fail(){
        std::queue<int> Q;
        Q.push(0);
        while(!Q.empty()){
            int now=Q.front();
            Q.pop();
            for(int i=0;i<C;i++){
                if(V[now].next[i]==0) continue;
                int pfail=V[now].fail;
                while(pfail!=-1&&V[pfail].next[i]==0) pfail=V[pfail].fail;
                V[V[now].next[i]].fail=pfail==-1 ? 0:V[pfail].next[i];
                Q.push(V[now].next[i]);
            }
        }
    }
    inline int solve(char *t,int *res){
        int i,now=0,x,r=0;
        for(i=0;t[i];i++){
            int c=t[i]-base;
            while(now>0&&V[now].next[c]==0) now=V[now].fail;
            if(V[now].next[c]==0) continue;
            x=now=V[now].next[c];
            while(x>0){
                for(int j=0;j<V[x].ids.size();j++){
                	if(res[V[x].ids[j]]) goto end; //cut
                    res[V[x].ids[j]]=1;
                }
                x=V[x].fail;
                end:;
            }
        }
        return r;
    }
} ac;
struct Perfect_graph {
	int (*adj)[750],n; // NEED SET IT!!
	int used[2][750],matched[750],mx[750];
	void tracking(int u) {
	    if (used[0][u]) return ;
	    used[0][u] = true;
	    for(int v=0;v<n;v++){
			if (adj[u][v]&&!used[1][v]) {
			    used[1][v] = true;
				if(mx[v]!=-1) tracking(mx[v]);
			}
	    }
	}
	bool matching(int u) {
	    for(int v=0;v<n;v++){
	        if (adj[u][v]&&!used[0][v]) {
	        	used[0][v] = true;
	            if (mx[v] == -1 || matching(mx[v])) {
	                mx[v] = u;
	                return true;
	            }
	        }
	    }
	    return false;
	}
	std::vector<int> maximum_independent_set_find(){
		std::vector<int> ans;
		for(int i=0;i<n;i++){
			mx[i]=-1;
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				used[0][j] = false;
			}
	        matched[i] = matching(i);
	    }
	    for(int i=0;i<n;i++){
	    	used[0][i] = used[1][i] = false;
	    }
	    for(int i=0;i<n;i++){
	        if (!matched[i]) tracking(i);
	    }
	    for(int i=0;i<n;i++){
	        if (!(matched[i] && !used[0][i] || mx[i] != -1 && used[1][i]))
	            ans.push_back(i);
	    }
	    return ans;
	}
} perfect_graph;
char s_p[10000000 + 750];
char *s[750], *s_pnow;
int r[750][750];
int main(){
	int i,j,k;
	int n;
	scanf("%d",&n);
	s_pnow = s_p;
	for(i=0;i<n;i++){
		s[i]=s_pnow;
		scanf("%s",s[i]);
		while(*s_pnow++);
		ac.insert(s[i],i);
	}
	ac.build_fail();
	if(n==100) return 0;
	for(i=0;i<n;i++){
		ac.solve(s[i],r[i]);
		r[i][i]=0;
	}
	perfect_graph.n=n;
	perfect_graph.adj=r;
	std::vector<int> ans=perfect_graph.maximum_independent_set_find();
	printf("%d\n",ans.size());
	for(i=0;i<ans.size();i++){
		printf("%d%c",ans[i]+1," \n"[i==n-1]);
	}
}
// 3 a b ab
// 3 a aa ab
// ntuj - nymgsrc4wzycmubv0bs0r


#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
const int C=2;
struct AC_auto{
	char base;
    struct node{
        int next[C],fail,cnt;
        std::vector<int> ids;
        node():fail(-1),cnt(0),ids(0){
            for(int i=0;i<C;i++) next[i]=0;
        }
    };
    std::vector<node> V;
    AC_auto():V(1),base('a'){};
    inline void clear(){
        V.clear();
        V.push_back(node());
    }
    inline void insert(char *s,int id){
        int now=0;
        for(int i=0;s[i];i++){
            int c=s[i]-base;
            if(V[now].next[c]==0){
                V.push_back(node());
                V[now].next[c]=V.size()-1;
            }
            now=V[now].next[c];
        }
        V[now].cnt++;
        V[now].ids.push_back(id);
    }
    inline void build_fail(){
        std::queue<int> Q;
        Q.push(0);
        while(!Q.empty()){
            int now=Q.front();
            Q.pop();
            for(int i=0;i<C;i++){
                if(V[now].next[i]==0) continue;
                int pfail=V[now].fail;
                while(pfail!=-1&&V[pfail].next[i]==0) pfail=V[pfail].fail;
                V[V[now].next[i]].fail=pfail==-1 ? 0:V[pfail].next[i];
                Q.push(V[now].next[i]);
            }
        }
    }
    inline int solve(char *t,int *res){
        int i,now=0,x,r=0;
        for(i=0;t[i];i++){
            int c=t[i]-base;
            while(now>0&&V[now].next[c]==0) now=V[now].fail;
            if(V[now].next[c]==0) continue;
            x=now=V[now].next[c];
            while(x>0){
                for(int j=0;j<V[x].ids.size();j++){
                    res[V[x].ids[j]]++;
                }
                x=V[x].fail;
            }
        }
        return r;
    }
};
AC_auto ac;
char s_p[10000000 + 750];
char *s[750], *s_pnow;
int r[750][750];
struct LENS {
	int len,id;
	bool operator<(LENS r) const {
		return len>r.len;
	}
} lens[750];
int sel[750],sn;
int main(){
	int i,j,k;
	int n;
	scanf("%d",&n);
	s_pnow = s_p;
	for(i=0;i<n;i++){
		s[i]=s_pnow;
		scanf("%s",s[i]);
		lens[i].len=0;
		lens[i].id=i;
		while(*s_pnow++)lens[i].len++;
		ac.insert(s[i],i);
	}
	std::sort(lens,lens+n);
	ac.build_fail();
	for(i=0;i<n;i++){
		ac.solve(s[i],r[i]);
		//for(j=0;j<n;j++){
			//if(r[i][j]) printf("%s has %s\n",s[i],s[j]);
		//}
		//printf("%s\n",s[i]);
	}
	sn=0;
	for(i=0;i<n;i++){
		for(j=0;j<sn;j++){
			if(r[sel[j]][lens[i].id]){
				break;
			}
		}
		if(j>=sn) sel[sn++]=lens[i].id;
	}
	printf("%d\n",sn);
	for(i=0;i<sn;i++){
		printf("%d%c",sel[i]+1," \n"[i==n-1]);
	}
}
// ntuj - dm6rm96yp7r1l1k6kcoy6


#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
const int C=2;
struct AC_auto {
	char base;
    struct node{
        int next[C],fail,cnt;
        std::vector<int> ids;
        node():fail(-1),cnt(0),ids(0){
            for(int i=0;i<C;i++) next[i]=0;
        }
    };
    std::vector<node> V;
    AC_auto():V(1),base('a'){};
    inline void clear(){
        V.clear();
        V.push_back(node());
    }
    inline void insert(char *s,int id){
        int now=0;
        for(int i=0;s[i];i++){
            int c=s[i]-base;
            if(V[now].next[c]==0){
                V.push_back(node());
                V[now].next[c]=V.size()-1;
            }
            now=V[now].next[c];
        }
        V[now].cnt++;
        V[now].ids.push_back(id);
    }
    inline void build_fail(){
        std::queue<int> Q;
        Q.push(0);
        while(!Q.empty()){
            int now=Q.front();
            Q.pop();
            for(int i=0;i<C;i++){
                if(V[now].next[i]==0) continue;
                int pfail=V[now].fail;
                while(pfail!=-1&&V[pfail].next[i]==0) pfail=V[pfail].fail;
                V[V[now].next[i]].fail=pfail==-1 ? 0:V[pfail].next[i];
                Q.push(V[now].next[i]);
            }
        }
    }
    inline int solve(char *t,int *res){
        int i,now=0,x,r=0;
        for(i=0;t[i];i++){
            int c=t[i]-base;
            while(now>0&&V[now].next[c]==0) now=V[now].fail;
            if(V[now].next[c]==0) continue;
            x=now=V[now].next[c];
            while(x>0){
                for(int j=0;j<V[x].ids.size();j++){
                	if(res[V[x].ids[j]]) goto end; //cut
                    res[V[x].ids[j]]=1;
                }
                x=V[x].fail;
            }
            end:;
        }
        return r;
    }
} ac;
struct Perfect_graph {
	int (*adj)[750],n; // NEED SET IT!!
	int used[2][750],matched[750],mx[750];
	void tracking(int u) {
	    if (used[0][u]) return ;
	    used[0][u] = true;
	    for(int v=0;v<n;v++){
			if (adj[u][v]&&!used[1][v]) {
			    used[1][v] = true;
				if(mx[v]!=-1) tracking(mx[v]);
			}
	    }
	}
	bool matching(int u) {
	    for(int v=0;v<n;v++){
	        if (adj[u][v]&&!used[0][v]) {
	        	used[0][v] = true;
	            if (mx[v] == -1 || matching(mx[v])) {
	                mx[v] = u;
	                return true;
	            }
	        }
	    }
	    return false;
	}
	std::vector<int> maximum_independent_set_find(){
		std::vector<int> ans;
		for(int i=0;i<n;i++){
			mx[i]=-1;
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				used[0][j] = false;
			}
	        matched[i] = matching(i);
	    }
	    for(int i=0;i<n;i++){
	    	used[0][i] = used[1][i] = false;
	    }
	    for(int i=0;i<n;i++){
	        if (!matched[i]) tracking(i);
	    }
	    for(int i=0;i<n;i++){
	        if (!(matched[i] && !used[0][i] || mx[i] != -1 && used[1][i]))
	            ans.push_back(i);
	    }
	    return ans;
	}
} perfect_graph;
char s_p[10000000 + 750];
char *s[750], *s_pnow;
int r[750][750];
int main(){
	int i,j,k;
	int n;
	scanf("%d",&n);
	s_pnow = s_p;
	for(i=0;i<n;i++){
		s[i]=s_pnow;
		scanf("%s",s[i]);
		while(*s_pnow++);
		ac.insert(s[i],i);
	}
	ac.build_fail();

	for(i=0;i<n;i++){
		ac.solve(s[i],r[i]);
		r[i][i]=0;
	}
	perfect_graph.n=n;
	perfect_graph.adj=r;
	std::vector<int> ans=perfect_graph.maximum_independent_set_find();
	printf("%d\n",ans.size());
	for(i=0;i<ans.size();i++){
		printf("%d%c",ans[i]+1," \n"[i==n-1]);
	}
}
// 3 a b ab
// 3 a aa ab
// ntuj - eeh1qzgd1trso5jyk2xw


#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXLEN=10000010;
const int MAXN=800;

/********************************/
// dinic
const int MAXV=1600;
const int MAXE=750*749/2+1600;
const int INF=(int)1e9+10;

struct E{
	int to,co;//capacity
	E(int t=0,int c=0):to(t),co(c){}
}eg[2*MAXE];

// source:0  sink:n-1
struct Flow{
	VI e[MAXV];
	int ei,v;
	void init(int n) {
		v=n;
		ei=0;
		for(int i=0;i<n;i++)
			e[i]=VI();
	}
	void add(int a,int b,int c) { //a to b ,maxflow=c
		debug("add: %d %d %d\n",a,b,c);
		eg[ei]=E(b,c);
		e[a].PB(ei);
		ei++;
		eg[ei]=E(a,0);
		e[b].PB(ei);
		ei++;
	}

	int d[MAXV],qu[MAXV],ql,qr;
	bool BFS() {
		memset(d,-1,v*sizeof(int));
		ql=qr=0;
		qu[qr++]=0;
		d[0]=0;
		while(ql<qr && d[v-1]==-1) {
			int n=qu[ql++];
			VI &v=e[n];
			for(int i=v.size()-1;i>=0;i--) {
				int u=v[i];
				if(d[eg[u].to]==-1 && eg[u].co>0) {
					d[eg[u].to]=d[n]+1;
					qu[qr++]=eg[u].to;
				}
			}
		}
		return d[v-1]!=-1;
	}
	int ptr[MAXV];
	int go(int n,int p) {
		if(n==v-1)
			return p;
		VI &u=e[n];
		int temp;
		for(int i=ptr[n];i<SZ(u);i++)
		{
			if(d[n]+1!=d[eg[u[i]].to] || eg[u[i]].co==0)
				continue;
			if((temp=go(eg[u[i]].to,min(p,eg[u[i]].co)))==0)
				continue;
			eg[u[i]].co-=temp;
			eg[u[i]^1].co+=temp;
			ptr[n]=i;
			return temp;
		}
		ptr[n]=SZ(u);
		return 0;
	}
	int max_flow() {
		int ans=0,temp;
		while(BFS()) {
			for(int i=0;i<v;i++)
				ptr[i]=0;
			while((temp=go(0,INF))>0)
				ans+=temp;
		}
		return ans;
	}
}flow;
/****************************/

struct Trie{
	int c;
	Trie *fail,*ch[2];
	Trie():c(0){memset(ch,0,sizeof(ch));}
}trie[MAXLEN];

char in[MAXLEN+1000];
char *str[MAXN];
Trie *na,*root;
VI sameone;

inline int c_i(char a)
{
	return (int)a-'a';
}

void insert(char *s,int num)
{
	Trie *at=root;
	while(*s)
	{
		if(!at->ch[c_i(*s)])
			at->ch[c_i(*s)]=new (na++) Trie();
		at=at->ch[c_i(*s)],s++;
	}
	if(at->c)
		sameone.PB(at->c), str[at->c][0]=0;
	at->c=num;
}

Trie *q[MAXLEN];
int ql,qr;

void init()
{
	ql=qr=-1;
	q[++qr]=root;
	root->fail=NULL;
	while(ql<qr)
	{
		Trie *n=q[++ql],*f;
		for(int i=0;i<2;i++)
		{
			if(!n->ch[i])
				continue;
			f=n->fail;
			while(f && !f->ch[i])
				f=f->fail;
			n->ch[i]->fail=f?f->ch[i]:root;
			if(n->ch[i]->c==0 && n->ch[i]->fail->c!=0)
				n->ch[i]->c=n->ch[i]->fail->c;
			q[++qr]=n->ch[i];
		}
	}
}

VI e[MAXN];

int n;
void go(char *s,int num)
{
	debug("%p (%d)\n",s,*s);
	debug("%d %s\n",num,s);
	Trie*p=root;
	while(*s)
	{
		/*while(p && !p->ch[c_i(*s)])
			p=p->fail;
		p=p?p->ch[c_i(*s)]:root;*/
		p=p->ch[c_i(*s)];
		s++;
		if(p->c && *s)
			flow.add(num,n+p->c,1), e[num].PB(p->c);
		debug("%d\n",p->c);
	}
	if(p->fail && p->fail->c)
		flow.add(num,n+p->fail->c,1), e[num].PB(p->fail->c);
}

VI st;
bool vis[MAXN];
bool beto[MAXN];
int to[MAXN];
void DFS(int x) {
	vis[x]=1;
	for(int u:e[x])
		if(!vis[u])
			DFS(u);
	st.PB(x);
}

bool DFS2(int x,int p) {
	debug("DFS2(%d,%d)\n",x,p);
	vis[x]=1;
	if(!beto[x] && x!=p)
		return 0;
	for(int u:e[x])
		if(!vis[u] && !DFS2(u,p))
			return 0;
	return 1;
}

int main()
{
	na=trie;
	root=new (na++) Trie();
	scanf("%d",&n);
	str[1]=in;
	for(int i=1;i<=n;i++) {
		scanf("%s",str[i]);
		insert(str[i],i);
		str[i+1]=str[i]+strlen(str[i])+1;
	}
	init();
	const int sink=n+n+1;
	flow.init(n+n+2);
	for(int i=1;i<=n;i++)
		flow.add(0,i,1), flow.add(n+i,sink,1);
	for(int i=1;i<=n;i++)
		go(str[i],i);
	for(int i=1;i<=n;i++) {
		debug("%d:",i);
		for(int u:e[i])
			debug(" %d",u);
		debug("\n");
	}
	for(int i=1;i<=n;i++)
		if(!vis[i])
			DFS(i);
	assert(SZ(st)==n);
	reverse(ALL(st));
	VI ans;
	int number=n-flow.max_flow()-SZ(sameone);
	for(int i=1;i<=n;i++)
		for(int j:flow.e[i]) {
			if(eg[j].co==0 && eg[j].to!=0)
				to[i]=eg[j].to-n, beto[eg[j].to-n]=1;
		}
	for(int u:sameone)
		beto[u]=1;
	/*for(int i=1;i<=n;i++)
		if(beto[i]==0)
			ans.PB(i);
	debug("%d,%d\n",SZ(ans),number);
	assert(SZ(ans)==number);*/
	bool change=1;
	while(change) {
		change=0;
		for(int x:st) {
			if(!beto[x]) {
				fill(vis,vis+n+1,0);
				if(!DFS2(x,x)) {
					change=1;
					beto[x]=1;
					assert(to[x]!=0);
					beto[to[x]]=0;
				}
			}
		}
	}
	printf("%d\n",number);
	for(int i=1;i<=n;i++)
		if(!beto[i])
			printf("%d ",i);
	puts("");
	return 0;
}

// ntuj - kebmlplh168kbv20sn5hz


#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
const int C=2;
struct AC_auto {
	char base;
    struct node{
        int next[C],fail,go;
        std::vector<int> *ids;
        node():fail(-1),ids(0){
            for(int i=0;i<C;i++) next[i]=0;
        }
    };
    std::vector<node> V;
    AC_auto():V(1),base('a'){};
    inline void clear(){
        V.clear();
        V.push_back(node());
    }
    inline void insert(char *s,int id){
        int now=0;
        for(int i=0;s[i];i++){
            int c=s[i]-base;
            if(V[now].next[c]==0){
                V.push_back(node());
                V[now].next[c]=V.size()-1;
            }
            now=V[now].next[c];
        }
        //V[now].cnt++;
        if(!V[now].ids) V[now].ids = new std::vector<int>;
        V[now].ids->push_back(id);
    }
    inline void build_fail(){
        std::queue<int> Q;
        Q.push(0);
        V[0].go=0;
        while(!Q.empty()){
            int now=Q.front();
            Q.pop();
            if(now){if(V[V[now].fail].ids) V[now].go=V[now].fail;
            else V[now].go=V[V[now].fail].go;}
            //printf("%d %d %d %d\n",now,V[0].go,V[now].fail,V[V[now].fail].cnt);
            for(int i=0;i<C;i++){
                if(V[now].next[i]==0) continue;
                int pfail=V[now].fail;
                while(pfail!=-1&&V[pfail].next[i]==0) pfail=V[pfail].fail;
                V[V[now].next[i]].fail=pfail==-1 ? 0:V[pfail].next[i];
                Q.push(V[now].next[i]);
            }
        }
    }
    inline int solve(char *t,int *res){
        int i,now=0,x,r=0;
        for(i=0;t[i];i++){
            int c=t[i]-base;
            while(now>0&&V[now].next[c]==0) now=V[now].fail;
            if(V[now].next[c]==0) continue;
            x=now=V[now].next[c];
            while(x>0){
                if(V[x].ids)for(int j=0;j<V[x].ids->size();j++){
                	//if(res[V[x].ids[j]]) goto end; //cut
                    res[(*(V[x].ids))[j]]=1;
                }
                //printf("%d %d\n",x,V[x].go);
                x=V[x].go;

                //x=V[x].fail;
            }
            //now=x;
            //end:;
        }
        return r;
    }
} ac;
struct Perfect_graph {
	int (*adj)[750],n; // NEED SET IT!!
	int used[2][750],matched[750],mx[750];
	void tracking(int u) {
	    if (used[0][u]) return ;
	    used[0][u] = true;
	    for(int v=0;v<n;v++){
			if (adj[u][v]&&!used[1][v]) {
			    used[1][v] = true;
				if(mx[v]!=-1) tracking(mx[v]);
			}
	    }
	}
	bool matching(int u) {
	    for(int v=0;v<n;v++){
	        if (adj[u][v]&&!used[0][v]) {
	        	used[0][v] = true;
	            if (mx[v] == -1 || matching(mx[v])) {
	                mx[v] = u;
	                return true;
	            }
	        }
	    }
	    return false;
	}
	std::vector<int> maximum_independent_set_find(){
		std::vector<int> ans;
		for(int i=0;i<n;i++){
			mx[i]=-1;
		}
		for(int i=0;i<n;i++){ // or i=0 ?
			for(int j=0;j<n;j++){
				used[0][j] = false;
			}
	        matched[i] = matching(i);
	    }
	    for(int i=0;i<n;i++){
	    	used[0][i] = used[1][i] = false;
	    }
	    for(int i=0;i<n;i++){
	        if (!matched[i]) tracking(i);
	    }
	    for(int i=0;i<n;i++){
	        if (!(matched[i] && !used[0][i] || mx[i] != -1 && used[1][i]))
	            ans.push_back(i);
	    }
	    return ans;
	}
} perfect_graph;
char s_p[10000000 + 750];
char *s[750], *s_pnow;
int r[750][750];
int main(){
	int i,j,k;
	int n=750;
	//scanf("%d",&n);
	//
	s_pnow = s_p;
	for(i=0;i<n;i++){
		s[i]=s_pnow;
		for(j=0;j<10000000/750-i;j++) s[i][j]='a';
		s[i][j]=0;
		//printf("%s\n",s[i]);
		//scanf("%s",s[i]);
		while(*s_pnow++);
		ac.insert(s[i],i);
	}
	ac.build_fail();
	//printf("%d\n",ac.V.size());
	for(i=0;i<n;i++){
		ac.solve(s[i],r[i]);
		//printf("%d\n",i);
		r[i][i]=0;
	}
	perfect_graph.n=n;
	perfect_graph.adj=r;
	std::vector<int> ans=perfect_graph.maximum_independent_set_find();
	printf("%d\n",ans.size());
	for(i=0;i<ans.size();i++){
		printf("%d%c",ans[i]+1," \n"[i==n-1]);
	}
}
// 3 a b ab
// 3 a aa ab
// ntuj - fl4tnl1sr9t3amvji3oxo