var i,j:longint;
    num:array[0..250]of longint;
    c:array[0..250,0..20]of longint;
    x,cut,toinc,where:longint;
    use:boolean;
    n:longint;
    ans:int64;
function max(a,b:longint):longint;
begin
  if a>b then exit(a)  else exit(b);
end;
begin
  read(n);
  for i:=1 to n do
    for j:=1 to 10 do
    begin
      read(x);
      inc(num[i],x);
    end;
  for i:=1 to n do
    for j:=0 to 10 do
    read(c[i,j]);
  toinc:=-maxlongint;
  for i:=1 to n do
  begin
    x:=-maxlongint;
    for j:=0 to num[i] do
    begin
      if x<c[i,j] then
      begin
        x:=c[i,j];
        where:=j;
      end;
    end;
    if where=0 then
    begin
      for j:=1 to num[i] do
      if -x+c[i,j]>toinc then toinc:=-x+c[i,j];
    end;
    if where<>0 then use:=true;
    inc(ans,x);
  end;
  if not use then ans:=ans+toinc;
  writeln(ans);
end.

