Code Submission Evaluation System Login

BOI 2016, day 1

Start:2016-05-12 09:00:00
End:2016-05-12 14:00:00
 

Tasks | Scoreboard | Statistics


CSES - BOI 2016, day 1 - BossesCSES - Bosses

Bosses

Time limit:1.50 s
Memory limit:256 MB

A company of $n$ employees is due for a restructuring. In the resulting hierarchy, represented as a rooted tree, every node will be the boss of its children.

Each employee has a list of bosses they will accept. In addition, all employees must be assigned a salary. The salary must be a positive integer, and the salary of each boss must be larger than the sum of salaries of their immediate subordinates.

Your task is to structure the company so that all above conditions hold, and the sum of all the salaries is as small as possible.

Input

The first input line contains an integer $n$: the number of employees. The employees are numbered $1,2,\ldots,n$.

After this, the input contains $n$ lines that describe the preferences of the employees. The $i$th such line contains an integer $k_i$, followed by a list of $k_i$ integers. The list consists of all employees that the $i$th employee accepts as their boss.

Output

You should output the lowest total salary among all valid restructurings. You can assume that at least one solution exists.

Example

Input:
4
1 4
3 1 3 4
2 1 2
1 3


Output:
8

Subtask 1 (22 points)
Subtask 2 (45 points)
Subtask 3 (33 points)