401B.md (2937B)
1 Source: https://codeforces.com/problemset/problem/401/B 2 3 B. Sereja and Contests 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds. 22 23 Codesorfes has rounds of two types: *Div*1 (for advanced coders) and *Div*2 (for beginner coders). Two rounds, *Div*1 and *Div*2, can go simultaneously, (*Div*1 round cannot be held without *Div*2) in all other cases the rounds don't overlap in time. Each round has a unique identifier — a positive integer. The rounds are sequentially (without gaps) numbered with identifiers by the starting time of the round. The identifiers of rounds that are run simultaneously are different by one, also the identifier of the *Div*1 round is always greater. 24 25 Sereja is a beginner coder, so he can take part only in rounds of *Div*2 type. At the moment he is taking part in a *Div*2 round, its identifier equals to *x*. Sereja remembers very well that he has taken part in exactly *k* rounds before this round. Also, he remembers all identifiers of the rounds he has taken part in and all identifiers of the rounds that went simultaneously with them. Sereja doesn't remember anything about the rounds he missed. 26 27 Sereja is wondering: what minimum and what maximum number of *Div*2 rounds could he have missed? Help him find these two numbers. 28 29 Input 30 31 The first line contains two integers: *x* (1 ≤ *x* ≤ 4000) — the round Sereja is taking part in today, and *k* (0 ≤ *k* < 4000) — the number of rounds he took part in. 32 33 Next *k* lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding line looks like: "1 *num*2 *num*1" (where *num*2 is the identifier of this *Div*2 round, *num*1 is the identifier of the *Div*1 round). It is guaranteed that *num*1 - *num*2 = 1. If Sereja took part in a usual *Div*2 round, then the corresponding line looks like: "2 *num*" (where *num* is the identifier of this *Div*2 round). It is guaranteed that the identifiers of all given rounds are less than *x*. 34 35 Output 36 37 Print in a single line two integers — the minimum and the maximum number of rounds that Sereja could have missed. 38 39 Examples 40 41 Input 42 43 ``` 44 3 2 45 2 1 46 2 2 47 ``` 48 49 Output 50 51 ``` 52 0 0 53 ``` 54 55 Input 56 57 ``` 58 9 3 59 1 2 3 60 2 8 61 1 4 5 62 ``` 63 64 Output 65 66 ``` 67 2 3 68 ``` 69 70 Input 71 72 ``` 73 10 0 74 ``` 75 76 Output 77 78 ``` 79 5 9 80 ``` 81 82 Note 83 84 In the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual *Div*2 round and the round with identifier 6 will be synchronous with the *Div*1 round. 85 86 The maximum number of rounds equals 3. In this case all unused identifiers belong to usual *Div*2 rounds.