#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct {
int id;
int numAnswers;
int* answerIds;
} Question;
int main() {
int N;
while (scanf("%d", &N) != EOF) {
int* askId = (int*)malloc(N * sizeof(int));
int* ansNum = (int*)malloc(N * sizeof(int));
int** map = (int**)malloc((N + 1) * sizeof(int*));
for (int i = 0; i <= N; i++) {
map[i] = (int*)calloc(N + 1, sizeof(int));
}
for (int i = 0; i < N; i++) {
scanf("%d %d", &askId[i], &ansNum[i]);
for (int j = 0; j < ansNum[i]; j++) {
int ansId;
scanf("%d", &ansId);
map[askId[i]][ansId] = 1;
}
}
int* cheatIds = (int*)calloc(N + 1, sizeof(int));
int cheatCount = 0;
for (int i = 0; i <= N; i++) {
int count = 0;
for (int j = 0; j <= N; j++) {
if (map[i][j] == 1 && map[j][i] == 1 && i != j) {
if (cheatIds[i] != 1) {
cheatIds[i] = 1;
count++;
}
}
if (map[i][j] == 1 && i != j && cheatIds[j] == 1) {
count++;
}
if (count >= 2 && cheatIds[i] != 1) {
cheatIds[i] = 1;
}
}
if (cheatIds[i] == 1) {
cheatCount++;
}
}
int flag = 0;
printf("%d\n", cheatCount);
for (int i = 0; i <= N; i++) {
if (cheatIds[i] == 1) {
printf("%d ", i);
flag = 1;
}
if ((i == N) && (flag == 1)) {
printf("\n");
}
}
free(askId);
free(ansNum);
for (int i = 0; i <= N; i++) {
free(map[i]);
}
free(map);
free(cheatIds);
}
return 0;
}