def main():
    n = int(input())
    F = [input().replace(' ','') for _ in range(n)]
    P = [list(map(int, input().split())) for _ in range(n)]
    ans = -10**12
    for i in range(1, 1032):
        total = 0
        for j in range(n):
            k = int(F[j], 2)
            b = bin(k & i)
            cnt = b.count('1')
            total += P[j][cnt]
        if total>ans:
            ans = total
    print(ans)

if __name__ == '__main__':
    main()
