
import copy

shop_num = int(input().rstrip())

# business hour
shop_data = {}
for i in range(shop_num):
	shop_data[i] = input().rstrip().split(' ')

# benefit
shop_benefit = {}
for i in range(shop_num):
	shop_benefit[i] = input().rstrip().split(' ')

patterns = [0, 1, 2];

targets = []
for pattern1 in patterns:
	list1 = []
	if pattern1 == 1:
		list1.append(0)
	elif pattern1 == 2:
		list1.append(1)
	else:
		list1.append(0)
		list1.append(1)

	for pattern2 in patterns:
		list2 = copy.deepcopy(list1)
		if pattern2 == 1:
			list2.append(2)
		elif pattern2 == 2:
			list2.append(3)
		else:
			list2.append(2)
			list2.append(3)
		for pattern3 in patterns:
			list3 = copy.deepcopy(list2)
			if pattern3 == 1:
				list3.append(4)
			elif pattern3 == 2:
				list3.append(5)
			else:
				list3.append(4)
				list3.append(5)
			for pattern4 in patterns:
				list4 = copy.deepcopy(list3)
				if pattern4 == 1:
					list4.append(6)
				elif pattern4 == 2:
					list4.append(7)
				else:
					list4.append(6)
					list4.append(7)
				for pattern5 in patterns:
					list5 = copy.deepcopy(list4)
					if pattern5 == 1:
						list5.append(8)
					elif pattern5 == 2:
						list5.append(9)
					else:
						list5.append(8)
						list5.append(9)

					targets.append(copy.deepcopy(list5))

ben_list = []
for target in targets:
	ben = 0
	for key in shop_data:
		count = 0
		for time in range(10):
			data = int(shop_data[key][time])
			if time in target:
				if data == 1:
					count += 1
			else:
				if data == 0:
					count += 1

		ben += int(shop_benefit[key][count])

	ben_list.append(ben)

print(max(ben_list))