n = int(input())
max_num = -10**8
stores = {}

for i in range(n):
    stores[i] =[int('0b'+''.join(input().split()), 2)]
for i in range(n):
    stores[i].append(list(map(int, input().split())))
for i in range(1, 1024):
    total_sum = 0
    for j in range(n):
        common_open_time = bin(stores[j][0] & i).count('1')
        total_sum += stores[j][1][common_open_time]
    max_num = max(total_sum, max_num)
print(max_num)
    