## Problem Description

An Jun is visiting a foreign city for the first time. He uses the city's train network to explore the city.
There are *N* train stations numbered 1 to *N*. Today, An Jun wants to travel from his hotel to
the city park, one of the city's most beautiful landmarks. The hotel is next to train station 1, and the city
park is next to train station *N*.

There are *M* train routes on the train network. The *i*th train route visits *S*_{i} + 1
cities numbered *V*_{i1}, *V*_{i2}, ... , *V*_{iSi + 1}.
Travelling between city *V*_{i1} and city *V*_{i2} takes
*T*_{i1} time, travelling between city *V*_{i2} and city *V*_{i3} takes
*T*_{i2} time, ... , travelling between city *V*_{iSi} and city *V*_{iSi + 1}
takes *T*_{iSi} time for the *i*th train route. An Jun can board a train and alight from a train at any
part of its route, not necessarily at the first or last station. He can switch train routes any number of times, and board a train travelling on a certain train route
more than once if necessary. An unlimited number of trains will travel on each train route, hence a train will be available regardless of when An Jun wants to board a train

An Jun wants his journey to fulfil 2 criterias. First, he must reach his destination in the shortest possible time.
Secondly, among all possible routes with the minimum possible amount of time, he wants the *effective quality* of his
trip to be maximised. When An Jun boards a train at a certain station and alights at another station, the *quality*
of the ride is defined as the square of the time spent travelling on the train. The *effective quality* of the trip is the sum of all the *qualities* of the train rides.

Help An Jun find both the shortest possible time required for him to reach the city park, and the highest *effective quality* that can be achieved.

## Input

The first line of input contains two integers *N* and *M*.

The next *M* lines of input contain the descriptions of the train routes.

The *i*th line begins with an integer *S*_{i}, followed by 2 × *S*_{i} + 1 integers,
*V*_{i1}, *T*_{i1}, *V*_{i2}, *T*_{i2}, ... ,
*V*_{iSi}, *T*_{iSi}, *V*_{iSi + 1}

## Output

Output two integers, the minimum amount of time required to get from city 1 to city *N*, and the highest possible
*effective quality*. It is guaranteed that there is at least one way to get from city 1 to city *N*.

## Limits

For all subtasks, 1 ≤ *M* ≤ 10^{6}. 1 ≤ *T*_{ij} ≤ 1000. 1 ≤ *S*_{i} ≤ 10^{6}. ∑ *S*_{i} ≤ 10^{6}.
Subtask 1 (10%): 2 ≤ *N*_{i} ≤ 10. ∑ *S*_{i} ≤ 20. *S*_{i} = 1.

Subtask 2 (10%): 2 ≤ *N*_{i} ≤ 1000. ∑ *S*_{i} ≤ 1000. *S*_{i} = 1.

Subtask 3 (17%): 2 ≤ *N*_{i} ≤ 1000. ∑ *S*_{i} ≤ 1000.

Subtask 4 (17%): 2 ≤ *N*_{i} ≤ 1000. ∑ *S*_{i} ≤ 100 000.

Subtask 5 (19%): 2 ≤ *N*_{i} ≤ 10 000. ∑ *S*_{i} ≤ 200 000.

Subtask 6 (19%): 2 ≤ *N*_{i} ≤ 200 000. ∑ *S*_{i} ≤ 200 000.

Subtask 7 (8%): 2 ≤ *N*_{i} ≤ 10^{6}. ∑ *S*_{i} ≤ 10^{6}.

Subtask 8 (0%): Sample Testcases

## Sample Testcase 1

### Input

2 1
1 1 3 2

### Output

3 9

### Explanation

There is only one train route, so only this route can be taken.

## Sample Testcase 2

### Input

5 2
4 1 3 2 3 3 5 5 10 4
3 4 2 2 1 3 4 1

### Output

9 35

### Explanation

An Jun can take the first train route from city 1 to city 2, then switch to the second train route and take it from
city 2 to 3, then switch back to the first train route and take it from city 3 to 5. This gives a total of 3^{2} + 1^{2} + 5^{2} = 35 effective satisfaction.

## Sample Testcase 3

### Input

5 2
3 1 1 2 2 3 3 4
3 2 2 3 3 4 4 5

### Output

10 82