# -*- coding: utf-8 -*-
import itertools
def to_bool(i):
    if i == '1':
        return True
    return False

# 整数の入力
n = int(input())
f = []
for i in range(n):
    f.append(list(to_bool(i) for i in input().split()))

p = []
for i in range(n):
    p.append(list(int(i) for i in input().split()))

print(f)
print(p)

result = -100
for eigyou in itertools.product((True,False), repeat=10):
    if sum(1 for a in zip(eigyou) if a) == 0:
        continue
    goukei = 0
    for i in range(n):
        goukei += p[i][sum(1 for a,b in zip(eigyou,f[i]) if a and b)]
    if result < goukei:
        result = goukei
    
print(result)
