program shopping_street
  implicit none
  integer, parameter :: ubnd = 2**10 - 1
  integer :: n, f(100,10), p(100,0:10)
  integer :: i, j, k, op, g(ubnd), s(100)
  f = 0
  p = 0
  g = 0
  read(*,*) n
  do i = 1, n
    read(*,*) f(i,1:10)
  end do
  do i = 1, n
    read(*,*) p(i,0:10)
  end do
  do k = 1, ubnd
    s = 0
    do j = 1, 10
      if (btest(k,j-1)) then
        s(1:n) = s(1:n) + f(1:n,j)
      end if
    end do
    do i = 1, n
      g(k) = g(k) + p(i,s(i))
    end do
  end do
  write(*,'(i0)') maxval(g)
end program shopping_street