QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 512 MB 總分: 100 可 Hack ✓

#16262. Music Festival

统计

Vitya loves listening to music. He closely follows the updates from his favorite bands, so he knows that $n$ albums are to be released this Friday, the $i$-th of which contains $k_i$ tracks. Naturally, as the most devoted fan, Vitya has already listened to all the tracks that are about to be released and knows that in the $i$-th album, the coolness of the $j$-th track is $a_{i,j}$.

Vitya has a friend, Masha, whom he really wants to invite to a festival where his favorite bands are performing. However, for his friend to agree, she must first evaluate the new releases. Vitya knows that if Masha listens to a track that is cooler than all previous ones, she will receive 1 unit of impression. Unfortunately, albums can only be listened to in their entirety, without changing the order of the songs within them.

Help Vitya find an order of albums such that Masha's impression is as high as possible, ensuring she will definitely go to the festival with him.

Input

The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of albums.

The descriptions of the albums follow. Each album description consists of two lines: The first line contains a single integer $k_i$ ($1 \le k_i \le 200\,000$) — the number of tracks in the $i$-th album. The next line contains $k_i$ integers $a_{i,1}, a_{i,2}, a_{i,3}, \dots, a_{i,k_i}$ ($1 \le a_{i,j} \le 200\,000$) — the coolness of the tracks in the $i$-th album.

Let $\sum k_i$ denote the sum over all $k_i$. It is guaranteed that $\sum k_i \le 200\,000$.

Output

Output a single integer — the maximum impression Masha can receive.

Examples

Input 1

4
5
4 9 4 6 8
1
7
2
8 6
1
1

Output 1

4

Input 2

4
4
2
3 4
2
1 8
2
2 8
2
7 9

Output 2

4

Note

In the first example, the optimal order is to listen to the 4th, 2nd, 3rd, and 1st albums. In this case, Masha will listen to the tracks in the following order: 1; 7; 8, 6; 4, 9, 4, 6, 8 and will receive 4 units of impression.

In the second example, it is necessary to listen to the 1st album first, then the 4th, and then the 2nd and 3rd in any order. In this case, Masha will receive the maximum impression, specifically for each song in the 1st and 4th albums, and nothing for the 2nd and 3rd.

Subtasks

The tests for this problem consist of 7 groups. Points for each group are awarded only if all tests in the group and all tests of certain previous groups are passed. Note that passing the example tests is not required for some groups.

Group Points $n$ $k_i$ $a_{i,j}$ Required Groups Comment
0 0 Example tests.
1 14 $n \le 7$ $\sum k_i \le 1000$ 0
2 9 $a_{i,j} \le 2$
3 12 $a_{i,j} \le 10$ 0, 2
4 15 $k_i \le 2$
5 13 $n \le 1000$ $a_{i,j} \le 1000$ 0
6 13 $n \le 30\,000$ $a_{i,j} \le 30\,000$ 0, 5
7 24 0 – 6

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.