n = int(input())
f = [list(input().split()) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
print(max(sum(p[j][sum(f[j][x] == "1" and format(i, "010b")[x] == "1" for x in range(10))] for j in range(n)) for i in range(1, 2 ** 10)))