#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#define DEBUG_OUT(...)  (printf(__VA_ARGS__))
#else
#define VS_ENDPAUSE()
#define DEBUG_OUT(...)
#endif

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
//#define int int64

#ifndef INT8_MIN
#define INT8_MIN	(-127)
#endif
#ifndef INT8_MAX
#define INT8_MAX	( 128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX	( 255)
#endif
#ifndef INT16_MIN
#define INT16_MIN	(-32768)
#endif
#ifndef INT16_MAX
#define INT16_MAX	( 32767)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX	( 65535)
#endif
#ifndef INT32_MIN
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#endif
#ifndef INT32_MAX
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#endif
#ifndef UINT32_MAX
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#endif
#ifndef INT64_MIN
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#endif
#ifndef INT64_MAX
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#ifndef UINT64_MAX
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18
#endif

void func(void);
#pragma endregion

int32 main(void)
{
    func();
    VS_ENDPAUSE();
    return 0;
}

//DEBUG_OUT("----\n");


#define MOD		(1000000000 + 7)	// 10^9 + 7
#define T(n)	((n) % (MOD))		// mod 10^9 + 7
#define N_MAX	(100000 + 100)		// 10^5 + α;
uint32 nCr(uint32 n, uint32 r)
{
	static bool initFlg = false;
	static uint32 *factArray;
	static uint32 *factInverseArray;
	if(!initFlg){
		factArray = (uint32 *)calloc(N_MAX, sizeof(uint32));
		factInverseArray = (uint32 *)calloc(N_MAX, sizeof(uint32));
		factArray[0] = 1;
		factInverseArray[0] = 1;
		for(uint64 i=1; i<N_MAX; i++){
			factArray[i] = T(factArray[i-1] * i);

			// 逆元を求める
			uint64 x = factArray[i];
			uint32 n = MOD - 2;
			uint32 ans = 1;
			while(n>0){
				if((n&1) == 1){ ans = T(ans * x); }
				x = T(x*x);
				n >>= 1;
			}
			factInverseArray[i] = ans;
		}
		initFlg = true;
	}

	uint32 ans = T((uint64)factArray[n] * factInverseArray[r]);
	ans  = T((uint64)ans * factInverseArray[n-r]);
	return ans;
}

class Combination
{
private:
    const unsigned int end_r;
    unsigned int current_r;

    Combination *next;

public:
    Combination(unsigned int n, unsigned int r, unsigned int start_r = 1)
        : current_r(start_r), end_r(n-(r-1))
    {
        if(r > 1)
        {
            next = new Combination(n, r-1, start_r+1);
        }
        else
        {
            next = NULL;
        }
    }

    ~Combination()
    {
        if(next)
        {
            delete next;
        }
    }

    bool GetNextPattern(unsigned int dstArray[])
    {
        if(end_r >= current_r)
        {
            dstArray[0] = current_r;
            if(next)
            {
                bool isNextValid = next->GetNextPattern(&dstArray[1]);
                if(!isNextValid)
                {
                    current_r++;
                    dstArray[0] = current_r;
                    next->ResetR(current_r + 1);
                    isNextValid = next->GetNextPattern(&dstArray[1]);
                    if(!isNextValid)
                    {
                        return false;
                    }
                }
            }
            else
            {
                current_r++;
            }
        }
        else
        {
            return false;
        }
        return true;
    }

    void ResetR(unsigned int r)
    {
        current_r = r;
        if(next)
        {
            next->ResetR(r + 1);
        }
    }

};
struct ShopInfo
{
    int week;
    int time;
    bool isOpen;
};
int64 calcPoint(vector<vector<ShopInfo>> &F,
                vector<vector<int>> &P,
                uint32 pattern[],
                int patternLength)
{
    int N = F.size();
    int64 val = 0;
    // 店の数だけループ
    for(int i=0; i<N; i++){
        // その店と同時にオープンする時間帯の個数を求める
        int cnt = 0;
        for(int j=0; j<patternLength; j++){
            uint32 openTime = pattern[j] - 1;
            if(F[i][openTime].isOpen){
                cnt++;
            }
        }
        // 同時にオープンする時間帯数からポイントを求める
        int point = P[i][cnt];
        val += point;
    }
    return val;

}

void func(void)
{
    int N;
    cin >> N;

    vector<vector<ShopInfo>> F(N);
    for(int i=0; i<N; i++){
        for(int j=0; j<5; j++){
            for(int k=0; k<2; k++){
                int x;
                cin >> x;
                ShopInfo si;
                si.isOpen = (x==1) ? true : false;
                si.week = j;
                si.time = k;
                F[i].push_back(si);
            }
        }
    }

    vector<vector<int>> P(N, vector<int>(11));
    for(int i=0; i<N; i++){
        for(int j=0; j<=10; j++){
            cin >> P[i][j];
        }
    }

    int64 maxVal = INT64_MIN;
    for(int r=1; r<=10; r++){
        uint32 *patternArray = new uint32[r];
        Combination *c = new Combination(10, r);
        while(c->GetNextPattern(patternArray)){
            int64 point = calcPoint(F, P, patternArray, r);
            maxVal = max(maxVal, point);
        }
        delete patternArray;
        delete c;
    }

    cout << maxVal << endl;
}


Measured memory_bytes: 256