Easy Assembly#11324

Easy Assembly

1 second
128 megabytes
Very easy

Emma loves playing with blocks. She has several cubic blocks of the same size that are numbered with distinct integers written on them. She assembles towers from those blocks by stacking them vertically.

A configuration of her game is a set of towers that she has assembled from the blocks. Emma can perform two kinds of operations on a configuration of towers:

Emma wants to stack all the blocks into a single tower so that all blocks come in order sorted by the numbers — from the block with the minimal number at the top to the block with the maximal number at the bottom. Emma wants to do as little of splitting and combining operations as possible. Your task is to find the minimal number of operations she has to make and output how many splits and combines are needed.

Input

The first line contains an integer (1 \leq n \leq 10^4) - the number of towers in the initial configuration. Next lines describe towers. Each tower is described by a line that starts with the number k_i (k_i \geq 1, sum of k_i \leq 10000) - the number of blocks in the tower, followed by k_i numbers b_{i,j} (1 \leq b_{i,j} \leq 10^9) - numbers written on the blocks in the -th tower, listed from top to bottom. All block numbers listed in the input are different.

Output

Output a line with two integers and - the number of split and combine operations Emma should make to get a single tower with blocks sorted by their numbers, so that the total number of operations is minimized.

prb11324.gif

Examples

Example 1

Loading
Loading