Codeforces Round 228 (Div. 1)
C
Fox and Card Game
Codeforces
2000
原题
← BD →
翻译中…

Fox Ciel is playing a card game with her friend Fox Jiro. There are $*n*$ piles of cards on the table. And there is a positive integer on each card.

翻译中…

The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.

翻译中…

Suppose Ciel and Jiro play optimally, what is the score of the game?

翻译中…

Input

翻译中…

The first line contain an integer $*n*$ ($1 ≤ *n* ≤ 100$). Each of the next $*n*$ lines contains a description of the pile: the first integer in the line is $*s*_{*i*}$ ($1 ≤ *s*_{*i*} ≤ 100$) — the number of cards in the $*i*$-th pile; then follow $*s*_{*i*}$ positive integers $*c*_{1}$, $*c*_{2}$, ..., $*c*_{*k*}$, ..., $*c*_{*s*_{*i*}}$ ($1 ≤ *c*_{*k*} ≤ 1000$) — the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.

翻译中…

Output

翻译中…

Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.

翻译中…

Note

翻译中…

In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.

翻译中…

In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.

翻译中…

样例

Input #1
2
1 100
2 1 10
Output #1
101 10
InputCopy OutputCopy
Input #2
1
9 2 8 6 5 9 4 7 1 3
Output #2
30 15
InputCopy OutputCopy
Input #3
3
3 1 3 2
3 5 4 6
2 8 7
Output #3
18 18
InputCopy OutputCopy
Input #4
3
3 1000 1000 1000
6 1000 1000 1000 1000 1000 1000
5 1000 1000 1000 1000 1000
Output #4
7000 7000
InputCopy OutputCopy
题目信息
题号
388C
时间限制
1 s
内存限制
256 MB
标签
博弈论
贪心
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。