using System;
using System.Collections.Generic;

public class Prgram {
	public static void Main(string[] args) {
		int n = int.Parse(Console.ReadLine());
		var f = new List<string[]> ();
		var p = new List<string[]> ();
		int[] openCount = new int[n];
		for (int i = 0; i < n; i++) {
			f.Add(Console.ReadLine().Split(' '));
			int sum = 0;
			for (int fi = 0; fi < f[i].Length; fi++) {
				sum += int.Parse(f[i][fi]);
			}
			openCount[i] = sum;
		}
		for (int i = 0; i < n; i++) {
			p.Add(Console.ReadLine().Split(' '));
		}
		int x = 0;
		for (int i = 0; i < n; i++) {
			int max = -10000000;
			for (int pi = 1; pi <= openCount[i]; pi++) {
				if (int.Parse(p[i][pi]) > max) {
					max = int.Parse(p[i][pi]);
				}
			}
			if (0 < max || x == 0) {
				x += max;
			}
		}
		Console.WriteLine(x);
	}
}