N = int(input())
F = [[int(i) for i in input().split()] for _ in range(N)]
P = [[int(i) for i in input().split()] for _ in range(N)]

ans = 0
for i in range(N):
    cnt = 0
    vmin = -10E7
    t = 0
    for j in range(sum(F[i])+1):
        if j > 0:
            vmin = max(vmin, P[i][j])
        if P[i][j] > 0:
            t = max(t, P[i][j])
            cnt += 1
    ans += t
if cnt == 0:
    ans += vmin
print(ans)