# encoding: utf-8
N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]

def Fidx(i, j): return 2 * i + j

def bc10(num):
    num_tmp = num
    ret = 0
    for i in range(10):
        if num_tmp % 2: ret += 1
        num_tmp = num_tmp >> 1
    return ret

# re-arrange enemy infomation
F_mask = [0] * N
for i, F_row in enumerate(F): F_mask[i] += sum([(2 ** j) * item for j, item in enumerate(F_row)])

ans = - (10 ** 7) * N
for case in range(3 ** 5):
    # decide joisino-onechan's status
    joisino = 0
    case_tmp = case
    for i in range(5):
        joisino += ((case_tmp % 3 + 1) << (2 * i)) # 01, 10, 11
        case_tmp = case_tmp // 3
    # calc profit
    profit = 0
    for i, enemy in enumerate(F_mask): profit += P[i][bc10(joisino & enemy)]
    # update
    if ans < profit: ans = profit

print(ans)