#C6844. Heaviest Packages Sum

    ID: 50649 Type: Default 1000ms 256MiB

Heaviest Packages Sum

Heaviest Packages Sum

You are given N layers of packages. Each layer contains a number of packages with various weights. In each layer, identify the package with the maximum weight. If a layer is empty, its maximum weight is considered to be 0.

Your task is to compute the total weight of the heaviest packages across all layers using the formula:

$$S=\sum_{i=1}^{N} \max(L_i)$$

Here, \(L_i\) represents the list of weights in the \(i^{th}\) layer.

Input is provided via standard input and output should be via standard output.

inputFormat

The first line of input contains a single integer N representing the number of layers. The following N lines each describe a layer. Each layer is given as follows: the first integer M indicates the number of packages in that layer, followed by M space-separated integers denoting the weights of the packages. If M = 0, the layer is empty.

outputFormat

Output a single integer representing the total sum of the heaviest packages from each layer. Print the result to standard output.## sample

4
3 4 2 3
3 5 1 2
1 3
2 7 8
20