n = int(input())
f = [input().count("1") for i in range(n)]
p = [input().split()[:f[i]+1] for i in range(n)]
for i in range(n):
  p[i] = [int(x) for x in p[i]]
m=[max(l) for l in p]
d=[p[i].index(m[i]) for i in range(n)]
if sum(d)!=0:
  print(sum(m))
else:
  for i in range(n):
    p[i].pop(d[i])
    m=[max(l) for l in p]
  print(max(m))