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.


-----Examples-----
Input
2
1 100
2 1 10

Output
101 10

Input
1
9 2 8 6 5 9 4 7 1 3

Output
30 15

Input
3
3 1 3 2
3 5 4 6
2 8 7

Output
18 18

Input
3
3 1000 1000 1000
6 1000 1000 1000 1000 1000 1000
5 1000 1000 1000 1000 1000

Output
7000 7000



-----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.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = '#!/usr/bin/env python3\n\nodd, even = [], []\nplayer1_turn = True\nplayer1 = player2 = 0\npile_number = int(input())\n\nfor _ in range(pile_number):\n    n, *pile = tuple(map(int, input().split()))\n    if n % 2 == 0:\n        even.append(pile)\n    else:\n        odd.append(pile)\n\nfor pile in even:\n    n = len(pile)\n    player1 += sum(pile[:n//2])\n    player2 += sum(pile[n//2:])\n\nfor pile in sorted(odd, reverse=True, key=lambda x: x[len(x)//2]):\n    n = len(pile)\n    top, middle, bottom = pile[:n//2], pile[n//2], pile[n//2+1:]\n    player1 += sum(top)\n    player2 += sum(bottom)\n    if player1_turn:\n        player1 += middle\n        player1_turn = not player1_turn\n    else:\n        player2 += middle\n        player1_turn = not player1_turn\n\nprint(player1, player2)\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13531