package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func stringLineScan() string {
	sc.Scan()
	return sc.Text()
}

var ans int

func main() {
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(stringLineScan())
	f := make([][]int, n)
	for i := 0; i < n; i++ {
		t := make([]int, 10)
		for j := 0; j < 10; j++ {
			t[j], _ = strconv.Atoi(stringLineScan())
		}
		f[i] = t
	}
	p := make([][]int, n)
	for i := 0; i < n; i++ {
		t := make([]int, 11)
		for j := 0; j < 11; j++ {
			t[j], _ = strconv.Atoi(stringLineScan())
		}
		p[i] = t
	}
	ans := -100000000
	repeat := make([]int, 2)
	repeat[0], repeat[1] = 0, 1
	seed := make([]int, 0)
	ret := make([][]int, 0)
	all := allcomb(10, repeat, seed, ret)
	for _, list := range all[1:] {
		s := 0
		for i := 0; i < n; i++ {
			c := 0
			for j := 0; j < 10; j++ {
				c += list[j] * f[i][j]
			}
			s += p[i][c]
		}
		ans = larger(ans, s)
	}
	fmt.Println(ans)
}
func allcomb(n int, repeat []int, seed []int, ret [][]int) [][]int {
	if len(seed) == n {
		x := make([]int, n)
		copy(x, seed)
		ret = append(ret, x)
		return ret
	} else {
		for _, i := range repeat {
			ret = allcomb(n, repeat, append(seed, i), ret)
		}
	}
	return ret
}
func larger(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}
