Hugo

Time limit2sMemory limit128 MB

Problem

Hugo is a game character who moves along the path at the bottom of the screen and tries to catch as many apples falling from trees as possible. The path is divided into N equal squares, numbered from 1 on the left to N on the right. There is one apple tree above each square. From time to time, one apple falls from one of the trees.

At the beginning of the game, Hugo stands on the middle square. N is odd. At the end of each second, if Hugo is on square P, he may move to square P-1, move to square P+1, or stay on square P. Therefore, at time 1 he is still on the starting square. If Hugo is on the square below a tree when an apple falls from it, he catches that apple. Hugo knows in advance when every apple will fall and from which tree.

Compute the maximum number of apples Hugo can catch.

Input

The first line contains an odd integer N, the number of squares. 1 <= N <= 999.

The next N lines describe the falling apples. The information for the M-th tree is given on line M+1. Each of these lines starts with an integer K, followed by K integers in increasing order: the times when apples fall from that tree. 1 <= K <= 3000, and the largest time is at most 100000.

Output

Print one line containing the maximum number of apples Hugo can catch.