fun main(args: Array<String>) {

    val numN = readLine().orEmpty().toInt()
    var fList = mutableListOf<List<Int>>()
    val pList = mutableListOf<List<Int>>()

    for(i in 0 until numN){
        val schedule = readLine()!!.split(" ").map(String::toInt)
        fList.add(schedule)
    }
    for(i in 0 until numN){
        val price = readLine()!!.split(" ").map(String::toInt)
        pList.add(price)
    }

    var maxProfit = 0
    for(i in 1 until 1024){

        var iBStr = Integer.toBinaryString(i)
        if(iBStr.length < 10){
            for(j in 0 until 10 - iBStr.length){
                iBStr = "0$iBStr"
            }
        }
        var profit = 0
        var l = 0
        fList.forEach {
            var result = 0 // 営業被りの数
            var k = 0
            it.forEach{it2 ->
                if(it2 == 1 && iBStr[k] == '1'){
                    result += 1
                }
                k += 1
            }
            if(l == 0){
                profit = pList[l][result]
            }else{
                profit += pList[l][result]
            }
            l += 1
        }
        if(i == 1){
            maxProfit = profit
        }else if(maxProfit < profit){
            maxProfit = profit
        }

    }

    println(maxProfit)


}