N = int(input())
store = [int(input().replace(" ",""),2) for _ in range(N)]
pro = [list(map(int,input().split())) for _ in range(N)]
total_pro = 0
ans = -10**7
for joi in range(1,2**10):
  total_pro = 0
  for x in range(N):
    total_pro+= pro[x][bin(joi&store[x]).count("1")]
  ans = max(ans,total_pro)
print(ans) 