Sticks

No attempts yetTime limit1sMemory limit128 MB

Problem

Little Johnny received a birthday present from his grandparents: a box of sticks of various lengths and colours. Johnny wonders whether he can pick three sticks that form a triangle whose three sides all have different colours. He only cares about non-degenerate triangles, that is, triangles with positive area.

Among all triangles that can be built from three sticks of three pairwise-different colours, find the one with the largest perimeter and report that perimeter.

Input

The first line contains an integer kk (3k503 \le k \le 50), the number of different stick colours. The colours are numbered from 11 to kk.

Each of the next kk lines describes the sticks of one colour. Line i+1i+1 describes the sticks of colour ii: it begins with an integer nin_i (1ni1,000,0001 \le n_i \le 1{,}000{,}000), the number of sticks of that colour, followed on the same line by nin_i integers separated by single spaces, the lengths of those sticks. Every length is a positive integer not exceeding 1,000,000,0001{,}000{,}000{,}000. The total number of sticks does not exceed 1,000,0001{,}000{,}000.

Output

Print a single line.

If at least one triangle with three pairwise-different-coloured sides and positive area can be formed, print the maximum possible perimeter of such a triangle (the sum of its three side lengths).

Otherwise, print -1.

A triangle with sides abca \le b \le c has positive area (is non-degenerate) exactly when a+b>ca + b > c.