unittest
{
	assert( [ "1",
	          "1 1 0 1 0 0 0 1 0 1",
	          " 3  4  5  6  7  8  9 -2 -3  4 -2" ].parse.expand.solve == 8 );
	assert( [ "2",
	          "1 1 1 1 1 0 0 0 0 0",
	          "0 0 0 0 0 1 1 1 1 1",
	          " 0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1",
	          " 0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1" ].parse.expand.solve == -2 );
	assert( [ "3",
	          "1 1 1 1 1 1 0 0 1 1",
	          "0 1 0 1 1 1 1 0 1 0",
	          "1 0 1 1 0 1 0 1 0 1",
	          "-8  6 -2 -8 -8  4  8  7 -6  2  2",
	          "-9  2  0  1  7 -5  0 -2 -6  5  5",
	          " 6 -6  7 -9  6 -5  8  0 -9 -7 -7" ].parse.expand.solve == 23 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	auto fss = new long[][ n ];
	foreach( ref fs; fss )
	{
		input.popFront;
		fs = input.front.split.to!( long[] );
	}
	auto pss = new long[][ n ];
	foreach( ref ps; pss )
	{
		input.popFront;
		ps = input.front.split.to!( long[] );
	}
	return tuple( fss, pss );
}

auto solve( long[][] fss, long[][] pss )
{
	// 営業時間帯のパターンを生成
	auto oss = genFlags( 10 );
	
	// パターンごとの利益を集計
	auto tt = long.min;
	foreach( os; oss )
	{
		auto t = 0;
		foreach( i, fs; fss )
		{
			auto c = 0;
			foreach( k, f; fs )
			{
				if( os[ k ] && f ) c++;
			}
			t += pss[ i ][ c ];
		}
	
		tt = max( tt, t );
	}
	
	return tt;
}

auto genFlags( long n )
{
	long[][] oss;
	
	oss ~= [ 0 ];
	oss ~= [ 1 ];
	
	foreach( i; 0 .. n - 1 )
	{
		foreach( k; 0 .. oss.length )
		{
			oss ~= oss[ k ].dup;
			oss[ k ] ~= 0;
			oss[ $ - 1 ] ~= 1;
		}
	}
	
	return oss[ 1 .. $ ];		// 全部0のパターンは削る
}
