uses math;
var n,i,j,x,y,ans,ma,m2,d:longint;
var a:array[0..1000] of longint;
begin
  read(n);
  for i:=1 to n do
    for j:=1 to 10 do begin read(x);if x=1 then inc(a[i]);end;
  ma:=-maxlongint;d:=-1;
  for i:=1 to n do
  begin
    m2:=-maxlongint;
    for j:=0 to 10 do begin read(x);if j<=a[i] then
    begin if x>m2 then begin m2:=x;d:=max(d,j);end;
    if j>0 then ma:=max(ma,x);end;end;
    inc(ans,m2);
  end;
  if d=0 then inc(ans,ma);
  writeln(ans);
end.