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

ans = 0
for i in range(N):
    cnt = sum(F[i])
    ans += max(P[i][:cnt + 1])
    
print(ans)