Cards Game
题号:NC15881
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 128 M,其他语言256 M
64bit IO Format: %lld

题目描述

It’s universally acknowledged that there’re innumerable trees in the campus of HUST.

People like to play games under the tree, and SWH is exactly fond of one strange card game. In the game players are given some piles of cards with scores. Two players will take turns to draw a card from one pile and get the score of the card. Each player can choose the pile arbitrarily. However, the strange thing is that the player draws first can only draw a card from the top of one pile, and the player played second from the bottom. The game ends when all piles become empty. Now SWH and his friend LLY is going to play the game and SWH plays first. Both of them want to maximize his own score. Can you tell how many scores they will get finally?

输入描述:

First line you are given an integer n(1≤n≤100), indicating the number of decks. 
Then n line follows. Each i-th line contains an integer m_i (1≤m_i≤100), the number of cards in i-th pile, then m_i number follow , the score of each card. And we see the first card as “top”, the last card as “bottom”.

输出描述:

Two integers, the final score of SWH and LLY.
示例1

输入

复制
2
2 5 10
1 20

输出

复制
25 10