var n,x,ans,ma,m2,d,m3,da:int64;
var i,j:longint;
var a,b:array[0..1000] of int64;
function max(a,b:int64):int64;
begin
  if a>b then exit(a);exit(b);
end;
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:=-2147483647;d:=-1;
  for i:=1 to n do
  begin
    m2:=-2147483647;
    for j:=0 to 10 do
    begin
      read(x);if j=0 then b[i]:=x;
      if j<=a[i] then
      begin
        if x>m2 then begin m2:=x;d:=max(d,j);end;
        if j>0 then
        //if (x>ma) or ((x=ma) and (ma-b[da]<x-b[i])) then
        if (ma-b[da]<x-b[i]) then begin ma:=x;da:=i;end;
      end;
    end;
    inc(ans,m2);
  end;
  if d=0 then begin dec(ans,b[da]);inc(ans,ma);end;
  writeln(ans);
end.