# Your code here!

n=gets.to_i


array1=[]
$array2=[]
n.times{
    
    array1<<gets.split.map(&:to_i)}
n.times{
    
    $array2<<gets.split.map(&:to_i)}
    
    
    def tanaka(a,b,c)
        kkkk=Array.new(10,0)
     kkkk[0..a.length-1]=a
     a=kkkk
     
     aa=[a,b].transpose
     cc=aa.count([1,1])  
       
       return $array2[c][cc]
       
       
        
    end
    
kk=1
answer=-100000
1023.times{
    array3=kk.to_s(2).split("").map(&:to_i)
    kouho=0
    ii=0
    
    n.times{
        kouho+=tanaka(array3,array1[ii],ii)
        
        ii+=1
    }
    
    
  if kouho>answer
      answer=kouho
  end
    
  kk+=1  
    
  }
  
  
  
puts answer