#region using directives
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Convert;
#endregion

class Program
{
    static void Main()
    {
        int n = ToInt32(ReadLine());
        var a = new List<int>();
        for (int i = 0; i < n; i++)
        {
            string[] s = (ReadLine().Split());
            int k = 0;
            for (int j = 0; j < s.Length; j++)
                if (s[j] == "1")
                    k++;
            a.Add(k);
        }
        int[,] aa = new int[n, 11];
        for(int i = 0; i < n; i++)
        {
            string[] s = (ReadLine().Split());
            for (int j = 0; j < 11; j++)
                aa[i, j] = ToInt32(s[j]);
        }
        long answ = 0;
        long[] maxes = new long[n];
        for (int i = 0; i < n; i++)
        {
            long ma = ToInt64(-1e10);
            for (int j = 1; j < a[i] + 1; j++)
            {
                if (aa[i, j] > ma)
                    ma = aa[i, j];
            }
            maxes[i] = ma;
        }
        long ma1 = ToInt64(-1e10), mai = 0;
        for (int i = 0; i < n; i++)
        {
            if (maxes[i] > ma1)
            {
                ma1 = maxes[i];
                mai = i;
            }
            else if (maxes[i] == ma1)
            {
                if (aa[i, 0] > aa[mai, 0])
                    mai = i;
            }
        }
        answ = ma1;
        for (int i = 0; i < n; i++)
        {
            if (i == mai)
                continue;
            long ma = ToInt64(-1e10);
            for (int j = 0; j < a[i] + 1; j++)
            {
                if (aa[i, j] > ma)
                    ma = aa[i, j];
            }
            //if (ma > 0)
            answ += ma;
        }
        Console.WriteLine(answ);
    }
}
