N = int(input())
lst_F = [list(map(int, input().split())) for _ in range(N)]
lst_P = [list(map(int, input().split())) for _ in range(N)]
n_timetable = len(lst_F[0])
lst_joisino = [0] * n_timetable


def score(src, F, P):
    cnt = 0
    for i, j in zip(src, F):
        if i == j == 1:
            cnt += 1
    return P[cnt]
# print(score([1,1,0,1,0,0,0,1,0,1], lst_F[0], lst_P[0]))


def dfs(pos):
    if pos == n_timetable:
        ret = 0
        for i in range(N):
            if lst_joisino == [0] * n_timetable:
                continue
            p = score(lst_joisino, lst_F[i], lst_P[i])
            ret += p
        return ret
    lst_joisino[pos] = 0
    ret0 = dfs(pos + 1)
    lst_joisino[pos] = 1
    ret1 = dfs(pos + 1)
    return max(ret0, ret1)


print(dfs(0))