n=int(input())
f=[sum(list(map(int,input().split()))) for _ in range(n)]
p=[list(map(int,input().split())) for _ in range(n)]
ans=[]
for i in range(n):
  kari=-10**6
  for j in range(f[i]+1):
    kari=max(kari,p[i][j])
  ans.append(kari)
cnt=0
for i in range(n):
  if ans[i]!=p[i][0]:
    break
  else:
    cnt+=1
if cnt<n:
  print(sum(ans))
else:
  a=0
  ans=-10**6
  for i in p:
    a+=i[0]
  for i in range(n):
    b=a
    b-=p[i][0]
    kari=-10**6
    for j in range(1,f[i]+1):
      kari=max(kari,p[i][j])
    b+=kari
    ans=max(ans,b)
  print(ans)