program abc080c
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,i,j,profit=-1000000000,cd(0:9)
    integer(int32), allocatable:: f(:,:), p(:,:)

    read*, n
    allocate(f(10,n), p(11,n))
    do i=1,n
        read*, f(:,i)
    end do
    do i=1,n
        read*, p(:,i)
    end do

    do i=1,2**10-1
        do j=0,9
            if (btest(i,j)) then
                cd(j)=1
            else
                cd(j)=0
            end if
        end do
        profit = max(profit,calc_profit(cd))
    end do
    print'(i0)', profit
contains
    function calc_profit(a) result(ret)
        integer(int32):: a(10), ret, shop, day
        integer(int32):: cnt(n)
        cnt(:) = 0
        do shop=1,n
            do day=1,10
                if (a(day)==1 .and. f(day,shop)==1) cnt(shop)=cnt(shop)+1
            end do
        end do
        ret = 0
        do shop=1,n
            ret=ret+p(cnt(shop)+1,shop)
        end do
    end function
end program abc080c