N = int(input())
F = []
for i in range(N):
  F.append(list(map(int,input().split())))
P = []
for i in range(N):
  P.append(list(map(int,input().split())))
ans = 0
max_lst = []
for i,f in enumerate(F):
  num = max(P[i][:sum(F[i])+1])
  if (num > 0):
    ans += num
  else:
    max_lst.append(max(P[i][1:sum(F[i])+1]))
if (ans == 0):
  ans = max(max_lst)
print(ans)
      