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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var openTimes = new int[N][];
            var prices = new int[N][];
            for (var i = 0; i < N; i++)
                openTimes[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
            for (var i = 0; i < N; i++)
                prices[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var sol = new Solve(N, openTimes, prices);
            sol.Dfs(0, 1);
            Console.WriteLine(sol.Answer);
        }
    }

    class Solve
    {
        public int N { get; set; }
        public int[][] OpenTimes { get; set; }
        public int[][] Prices { get; set; }
        public int[] MyShop { get; set; }
        public long Answer { get; set; } = 0;
        public long Total { get; set; } = 0;
        public int[] Result { get; set; }

        public Solve(int n, int[][] openTimes, int[][] prices)
        {
            N = n;
            OpenTimes = openTimes;
            Prices = prices;
            MyShop = new int[10];
            Result = new int[N];
        }

        public void Dfs(int x, int bit)
        {
            // 無駄処理は行ってるからあとで直す
            if (x < 10) MyShop[x] = bit;
            if (x == 10)
            {
                for (var i = 0; i < N; i++)
                {
                    var tmp = 0;
                    for (var j = 0; j < 10; j++)
                    {
                        if (MyShop[j] == 1 && OpenTimes[i][j] == 1)
                        {
                            tmp++;
                        }
                        Result[i] = tmp;
                    }
                }
                Total = 0;
                for (var i = 0; i < N; i++)
                {
                    Total += Prices[i][Result[i]];
                }
                Answer = Math.Max(Total, Answer);
                return;
            }

            Dfs(x + 1, 1);
            Dfs(x + 1, 0);
        }
    }
}
