# coding: utf-8
# Your code here!

import numpy as np
import math

N = int(input().rstrip())
shop_open = []
values = []
for i in range(N):
    shop_open.append(np.asarray(list(map(int,input().rstrip().split())), dtype=np.int))
for i in range(N):
    values.append(np.asarray(list(map(int,input().rstrip().split())), dtype=np.int))

def dfs(open_array,max_sales):
    
    if len(open_array) == 10:
        if open_array.count(1) == 0:
            return max_sales
        sales = calc_sales(open_array)
        if sales > max_sales:
            max_sales = sales
        return max_sales

    flag = [0,1]
    for f in flag:
        tmp_ar = open_array.copy()
        tmp_ar.append(f)
        max_sales = dfs(tmp_ar,max_sales)
        
    return max_sales
        
def calc_sales(open_array):
    global shop_open,values
    sales = 0
    for i,ar in enumerate(shop_open):
        both_open = open_array + ar
        c = np.count_nonzero(both_open == 2)
        sales += values[i][c]
    return sales
    

open_ar = []
max_sales = dfs(open_ar,-10**7)
print(max_sales)