You are given a sequence of $n$ boxes. Each box contains several balls, and every ball has a whole number written on it.
You choose some of the boxes (one, several, or all of them) and take exactly one ball from each chosen box, keeping the boxes in their original order. Arranging the taken balls in that order gives a sequence of numbers. Consider only the choices for which this sequence is non-decreasing (each number is at least the previous one), and compute the largest possible sum of the taken numbers.
The first line contains $n$. Each of the following $n$ lines describes one box: it begins with the number of balls in that box, followed by the numbers written on those balls.
Output a single integer: the maximum sum described above.
$0 < n < 500$. Each box contains at least one ball and no more than $50$ balls. Every number written on a ball is between $1$ and $1000$, inclusive.