using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var F = new int[N];
            var P = new int[N];
            var max = (int)-1e7 - 1;
            var answer = 0;
            var count = 0;
            for (var i = 0; i < N; i++)
            {
                F[i] = Console.ReadLine().Trim().Split(' ').Select(int.Parse).Sum();
            }
            for (var i = 0; i < N; i++)
            {
                var p = Console.ReadLine().Trim().Split(' ').Select(int.Parse).Take(F[i] + 1).ToArray();
                var pmax = (int)-1e7 - 1;
                for (var j = 0; j < p.Length; j++)
                {
                    pmax = Math.Max(pmax, p[j]);
                    if (j > 0 && p[j] < 0) max = Math.Max(max, p[j]);
                }
                P[i] = pmax;
                if (P[i] > 0)
                {
                    answer += P[i];
                    count++;
                }
            }

            if (count == 0) answer = max;
            Console.WriteLine(answer);
        }
    }
}
