N = int(input())
F = list()
P = list()
for i in range(N):
	f = list(map(int, input().split()))
	#F.append([f[0:2],f[2:4],f[4:6],f[6:8],f[8:10]])
	F.append(f)
for i in range(N):
	p = list(map(int, input().split()))
	P.append(p)


count = [0] * N

n_range = [sum(F[i]) for i in range(N)]
index = []
score = []
for i in range(N):
	s = max(P[i][:n_range[i]+1])
	score.append(s)
	index.append(P[i].index(s))

if sum(index) == 0:
	s = [P[i][1] for i in range(N)]
	print(max(s))
else:
	print(sum(score))