n = int(input())
f = [list(map(int,input().split())) for _ in range(n)]
p = [list(map(int,input().split())) for _ in range(n)]
F = []
ans = []
for i in f:
    a = i.count(1)
    F.append(a)


for i in range(n):
    mx = -10 ** 7
    
    for j in range(1, F[i] + 1):
        mx = max(mx, p[i][j])
    ans.append(mx)
#print(sum(ans))
mxa = sum(ans)
#print(mxa)
cnt = []
#print(ans)
for i in range(n):
    tm = ans
    x = tm[i]
    tm[i] = p[i][0]
    #print(sum(tm))
    cnt.append(sum(tm))
    tm[i] = x
#print(cnt)

#print(mxa)
for i in range(n):
    if mxa < cnt[i]:
        mxa = cnt[i]
print(mxa)