1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

bool tab[500007];
vector<int> usun;

int main()
{

    int k, n;
    cin >> k >> n;
    int ans = n;
    for(int i = 1; i < k; i++)
    {
        int ilwol = ans;
        int ilzer = 0;
        cin >> n;
        for(int j = 0; j < n; j++)
        {
            int a;
            cin >> a;
            if(a == 0) ilzer++;
            else
            {
                if(tab[a] == false)
                {
                    usun.push_back(a);
                    tab[a] = true;
                    ilwol--;
                }
                else
                {
                    ans++;
                }
            }
        }
        ans += max(0, ilzer-ilwol);
        while(usun.size())
        {
            tab[usun[usun.size()-1]] = false;
            usun.pop_back();
        }
        cout << ans << " ";
    }
    cout << ans;
}
//4 3 5 1 1 2 0 0 6 0 2 2 3 4 0 8 2 3 4 4 5 0 0