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.
The first line contains an integer k (3≤k≤50), the number of different stick colours. The colours are numbered from 1 to k.
Each of the next k lines describes the sticks of one colour. Line i+1 describes the sticks of colour i: it begins with an integer ni (1≤ni≤1,000,000), the number of sticks of that colour, followed on the same line by ni integers separated by single spaces, the lengths of those sticks. Every length is a positive integer not exceeding 1,000,000,000. The total number of sticks does not exceed 1,000,000.
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 a≤b≤c has positive area (is non-degenerate) exactly when a+b>c.