# bit演算, 全探索で多分いける
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    n = int(input())
    fs = [int(input().replace(' ', ''), 2) for _ in range(n)]
    # print(fs)
    ps = [list(map(int, input().split())) for _ in range(n)]
    # print(ps)
    ans = -float("INF")
    for i in range(1, 2 ** 10 - 1):
        num_simal_stores = [bin(i & f).count('1') for f in fs]
    
        ans_tmp = 0
        for i in range(n):
            ans_tmp += ps[i][num_simal_stores[i]]

        ans = max(ans, ans_tmp)
    
    print(ans)


if __name__ == '__main__':
    main()