implicit none
integer, parameter :: ubnd = 2**10 - 1
integer N
integer,allocatable,dimension(:,:)::f, p
integer,allocatable,dimension(:)::s
integer :: i, j, k, op, g(ubnd)
  read*, n
  allocate(f(n,10),p(n,0:10),s(n))
  do i = 1, n
    read*, f(i,:)
  end do
  do i = 1, n
    read*, p(i,:)
  end do
  g=0
  do k = 1, ubnd
    s = 0
    do j = 1, 10
      if (btest(k,j-1))s = s + f(:,j)
    end do
    do i = 1, n
      g(k) = g(k) + p(i,s(i))
    end do
  end do
  print"(i0)",maxval(g)
end