CF216D.Spider's Web

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Paw the Spider is making a web. Web-making is a real art, Paw has been learning to do it his whole life. Let's consider the structure of the web.

There are nn main threads going from the center of the web. All main threads are located in one plane and divide it into nn equal infinite sectors. The sectors are indexed from 11 to nn in the clockwise direction. Sectors ii and i+1i+1 are adjacent for every ii , 1<=i<n . In addition, sectors 11 and nn are also adjacent.

Some sectors have bridge threads. Each bridge connects the two main threads that make up this sector. The points at which the bridge is attached to the main threads will be called attachment points. Both attachment points of a bridge are at the same distance from the center of the web. At each attachment point exactly one bridge is attached. The bridges are adjacent if they are in the same sector, and there are no other bridges between them.

A cell of the web is a trapezoid, which is located in one of the sectors and is bounded by two main threads and two adjacent bridges. You can see that the sides of the cell may have the attachment points of bridges from adjacent sectors. If the number of attachment points on one side of the cell is not equal to the number of attachment points on the other side, it creates an imbalance of pulling forces on this cell and this may eventually destroy the entire web. We'll call such a cell unstable. The perfect web does not contain unstable cells.

Unstable cells are marked red in the figure. Stable cells are marked green.

Paw the Spider isn't a skillful webmaker yet, he is only learning to make perfect webs. Help Paw to determine the number of unstable cells in the web he has just spun.

输入格式

The first line contains integer nn ( 3<=n<=10003<=n<=1000 ) — the number of main threads.

The ii -th of following nn lines describe the bridges located in the ii -th sector: first it contains integer kik_{i} ( 1<=ki<=1051<=k_{i}<=10^{5} ) equal to the number of bridges in the given sector. Then follow kik_{i} different integers pijp_{ij} ( 1<=pij<=105; 1<=j<=ki1<=p_{ij}<=10^{5}; 1<=j<=k_{i} ). Number pijp_{ij} equals the distance from the attachment points of the jj -th bridge of the ii -th sector to the center of the web.

It is guaranteed that any two bridges between adjacent sectors are attached at a different distance from the center of the web. It is guaranteed that the total number of the bridges doesn't exceed 10510^{5} .

输出格式

Print a single integer — the number of unstable cells in Paw the Spider's web.

输入输出样例

  • 输入#1

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

    输出#1

    6
首页