시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 8 4 4 57.143%

## 문제

Given is a sequence of n boxes. In each box, there are several balls. On each ball is written one whole number. We choose some (1, 2, ...,, or all) boxes and take one ball from each one of the chosen boxes, keeping the order of the boxes. Then we arrange all taken balls in a line, according to the order of the boxes. Sometimes, the numbers written on the taken balls may form a non-decreasing sequence. Write program maxsum, which computes what may be the largest sum of these numbers.

## 입력

The first line contains the value of n. It is followed by n lines, each corresponding to a box. Each of these lines begins with the quantity of balls in the box and then – the numbers written on the balls in this box.

0 < n < 500. In each box, there are no more than 50 balls, but at least one. Any whole number, written on a ball, is in a range from 1 till 1000.

## 출력

One integer equals to the maximum sum, as is described above.

## 예제 입력

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


## 예제 출력

25


## 힌트

The sequence of taken balls is 2 + 2 + 3 + 5 + 5 + 8. From the 5th, 6th, 7th and 10th boxes, nothing is taken.