n=int(input())
F=[int("0b"+"".join(input().split()),0) for _ in range(n)]
P=[list(map(int,input().split())) for _ in range(n)]
ans=-10e9
for i in range(1,2**10):
	m=0
	for f,p in zip(F,P):
		m+=p[bin(i&f).count("1")]
	ans=max(ans,m)
print(ans)