---
# System prepended metadata

title: Untitled

---

```clike
int howManyItem(int n, int recipe[][20]){
    int sum = 0;
    for(int i=0; i<20; i++){
        if(recipe[n][0] == 0){
            return 1;
        }
        else if(recipe[n][i] == 0){
            break;
        }
        else{
            sum += howManyItem(recipe[n][i]-1, recipe);
        }
    }
    return sum;
}

int main(){
    int N;
    scanf("%d",&N);

    int item[N];
    int recipe[20][20] = {0};
    int n, w;
    for(int i=0; i<N; i++){
        scanf("%d", &n);
        if(n == 0){
            recipe[i][0] = 0;
            // printf("%d 0 %d\n", i, recipe[i][0]);
        }
        for(int j=0; j<n; j++){
            scanf("%d", &w);
            recipe[i][j] = w;
            // printf("%d %d %d\n", i, j, recipe[i][j]);
        }
    }
    int count = 0;
    for(int i=0; i<N; i++){
        item[i] = howManyItem(i, recipe);
        // printf("%d %d\n", i, item[i]);
        count += item[i];
    }
    printf("%d", count);
    return 0;
}
```