Problem:


Score : 300 points

Problem Statement

Joisino is planning to open a shop in a shopping street.

Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods.

There are already N stores in the street, numbered 1 through N.

You are given information of the business hours of those shops, F_{i,j,k}. If F_{i,j,k}=1, Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2.

Let c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}.

Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.

Constraints

1≤N≤100

0≤F_{i,j,k}≤1

For every integer i such that 1≤i≤N, there exists at least one pair (j,k) such that F_{i,j,k}=1.

-10^7≤P_{i,j}≤10^7

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
F_{1,1,1} F_{1,1,2} ... F_{1,5,1} F_{1,5,2}
:
F_{N,1,1} F_{N,1,2} ... F_{N,5,1} F_{N,5,2}
P_{1,0} ... P_{1,10}
:
P_{N,0} ... P_{N,10}

Output

Print the maximum possible profit of Joisino's shop.

Sample Input 1

1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2

Sample Output 1

8

If her shop is open only during the periods when Shop 1 is opened, the profit will be 8, which is the maximum possible profit.

Sample Input 2

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

Sample Output 2

-2

Note that a shop must be open during at least one period, and the profit may be negative.

Sample Input 3

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

Sample Output 3

23



Sample input:
1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2


Sample output:
8

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
lst1 = [list(map(int,readline().split())) for i in range(n)]

lst2 = [list(map(int,readline().split())) for i in range(n)]

#曜日、時刻にどの店が営業しているかを埋め込む
lst3 = [[] for _ in range(10)]
for i in range(n):
    for j in range(10):
        if lst1[i][j] == 1:
            lst3[j].append(i)

#ビット全探索
def bit_search(lst):
    keta = len(lst)
    bit_lst = []
    for i in range(2**keta):
        sub = [0]*10
        for j in range(keta):
            if ((i>>j) &1):
                for k in lst3[j]:
                    sub[k] += 1
        bit_lst.append(sub)
    return bit_lst


dummy = [0]*(10)
all_lst = bit_search(dummy)

ans = -10**9
for i in all_lst[1:]:
    res = 0
    for j in range(n):
        res += lst2[j][i[j]]
    ans = max(res,ans)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
F = []
P = []

for i in range(N):
  f = list(map(int,input().split()))
  F.append(f)
  
for i in range(N):
  p = list(map(int,input().split()))
  P.append(p)
  
value = 0

ans = - (10 ** 9)

def recur(list):
  con = len(list)
  #list = [0,0, ... ~ 0] ~ [1,1, ... ~ 1]
  if con == 10:
    #1がない = 出店していない場合は何も返さない
    if list.count(1) == 0:
        return
    value = 0
    #インデックス番号とF[i] = 店の出店リストを取得
    for n,shop in enumerate(F):
        con = 0
        for j in range(10):
          	#j日に自店が出店し、かつ他店nも出店するならば、カウントする
            if list[j] == 1 and shop[j] == 1:
                con += 1
        #出店リストlistのパターンに応じた店nごとの利益を
        #同時出店日数conから算出し足し合わせる
        value += P[n][con]
 
    global ans
  　
    ans = max(ans, value)
    
  else:
    #出店しない
    recur(list + [0])
    #出店する
    recur(list + [1])
    
recur([])
    
print(ans)

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<vector>
#include<bitset>
#include<algorithm>
#include<cmath>

using namespace std;
typedef vector< vector<int> > vv;

int main(){
  int n;cin >> n;
  vv f(n,vector<int>(10,0));
  for(int i=0;i<n;i++)for(int j=0;j<10;j++)cin >> f[i][j];
  vv p(n,vector<int>(11,0));
  for(int i=0;i<n;i++)for(int j=0;j<=10;j++)cin >> p[i][j];
  int ma=-1000000000;
  int bits=pow(2,10);
  for(int i=1;i<bits;i++){
    bitset<10> bit(i);
    vector<int> v(n);
    for(int j=0;j<10;j++){
      if(bit[j]){
        for(int k=0;k<n;k++){
          v[k]+=f[k][j];
        }
      }
    }
    int ma_sub=0;
    for(int l=0;l<n;l++){
      ma_sub+=p[l][v[l]];
    }
    ma=max(ma,ma_sub);
  }
  cout << ma << endl;
}

Submission status: Runtime Error

Solution code:
n=int(input())
F= [list(map(int,input().split())) for i in range(N)]
#F[i][j]はi行目、すなわち店i+1の時間帯jに対してやっているかどうか
P= [list(map(int,input().split())) for i in range(N)]
#P[i][j]は店i+1が時間jに1で自分も1の時に得られる効果
ans=[]
for k in range(n):
    for i in range(2**10):
        c=0
        for j in range(10):
            if ((i>>j)&1) and F[k][j]==1:
                c+=1
        ans.append(P[k][c])
print(max(ans))

Submission status: Runtime Error

Solution code:
n=int(input())
F= [list(map(int,input().split())) for i in range(N)]
#F[i][j]はi行目、すなわち店i+1の時間帯jに対してやっているかどうか
P= [list(map(int,input().split())) for i in range(N)]
#P[i][j]は店i+1が時間jに1で自分も1の時に得られる効果
ans=[]
for k in range(n):
    for i in range(2**10):
        c=0
        for j in range(10):
            if (i>>j)&1 and F[k][j]==1:
                c+=P[k][j]
        ans.append(c)
print(max(c))

Submission status: Runtime Error

Solution code:
N = int(input())
open = []
for _ in range(N):
    open.append(list(map(int,input().split())))
open = np.array(open)
sales = []
for _ in range(N):
    sales.append(list(map(int,input().split())))
sales = np.array(sales)

ans = -float("inf")
for i in range(1 , 1024):
    sum_val = 0
    mapping = []
    for k in range(N):
        cnt = 0
        for j in range(10):
            if i >> j & 1 and open[k][j] == 1:
                cnt += 1
        mapping.append(cnt)
    for k in range(N):
        sum_val += sales[k][mapping[k]]
    if sum_val > ans:
        ans = sum_val
print(ans)

Submission status: Runtime Error

Solution code:
# ABC080 C - Shopping Street
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n=ni()
f=[nl() for _ in range(n)]
p=[nl() for _ in range(n)]
o = []
ans = -10**8
for i in range(2**10):
    op = [0]*10
    for j in range(10):
        if ((i>>j)&1):
            op[n-1-j]=1
    if not any(op):
        continue
    else:
        o.append(op)

for oo in o:
    value = 0
    for i,ff in enumerate(f):
        t=0
        for j in range(10):
            if oo[j]==1 and ff[j]==1:
                t+=1
        value += p[i][t]
    ans = max(ans,value)

print(ans)

Submission status: Runtime Error

Solution code:
# ABC080 C - Shopping Street
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n=ni()
f=[nl() for _ in range(n)]
p=[nl() for _ in range(n)]
o = []
ans = -10**8
for i in range(2**10):
    op = [0]*10
    for j in range(10):
        if ((i>>j)&1):
            op[n-1-j]=1
    if not any(op):
        continue
    else:
        o.append(op)

for oo in o:
    value = 0
    for i,ff in enumerate(f):
        # 同じ時刻の店
        t=0
        for j in range(10):
            if oo[j]==ff[j]==1:
                t+=1
        value += p[i][t]
    ans = max(ans,value)

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
import numpy as np
# import scipy
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]

def main():
    n=inp()
    f=[]
    for _ in range(n):
        f.append(inpl())
    p=[]
    for _ in range(n):
        p.append(inpl())
    ans=-10**10
    for i in range(1,11):
        for j in combinations(range(10),i):
            do = [0 for _ in range(10)]
            for k in j:
                do[k]=1
            benefit = 0
            for l in range(n):
                s=0
                for u in range(10):
                    s+=f[l][u]*do[u]
                benefit += p[l][s]
            ans=max(ans,benefit)
    print(ans)

if __name__ == "__main__":
    main()from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
import numpy as np
# import scipy
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]

def main():
    n=inp()
    f=[]
    for _ in range(n):
        f.append(inpl())
    p=[]
    for _ in range(n):
        p.append(inpl())
    ans=-10**10
    for i in range(1,11):
        for j in combinations(range(10),i):
            do = [0 for _ in range(10)]
            for k in j:
                do[k]=1
            benefit = 0
            for l in range(n):
                s=0
                for u in range(10):
                    s+=f[l][u]*do[u]
                benefit += p[l][s]
            ans=max(ans,benefit)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
A, B, X = map(int, input().split())
ans = 0

if (X - B * 10) // A > pow(10, 9):
  ans = pow(10, 9)  
else:
        for i in range(1, 10):
       	    num = (X - i * B) // A
        if i == 10 and num > pow(10, 9):
            ans = pow(10, 9)
        if pow(10, i) > num >= pow(10, i - 1):
            ans = max(ans, num)
        elif num >= pow(10, i):
            ans = max(ans, pow(10, i) - 1)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
F = [int("".join(input().split()), 1) for i in range(N)]
P = [list(map(int, (input().split()))) for i in range(N)]

ans = float('-inf')
for bit in range(1,1024):
    sum_p = 0
    for shop in range(N):
        time = bin(F[shop] & bit).count('1')
        sum_p += P[shop][time]

    ans = max(sum_p, ans)
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
N=int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]

store_str=list(product('01', repeat=10))
store=[[int(i) for i in j] for j in store_str]
store.pop(0)
all_sum=[]
for s in store:#joiの店をあけられる時間帯の組み合わせ
    value_list=[]
    for i,j in zip(F,P): #i番目の店の開いている時間帯のリスト
        l=len([1 for a,b in zip(s,i) if a==1 and b==1])
        value_list.append(j[l])
    value_sum=sum(value_list)
    all_sum.append(value_sum)
print(max(all_sum))

Submission status: Runtime Error

Solution code:
import sys
import itertools


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    f = [list(map(int, readline().split())) for _ in range(n)]
    p = [list(map(int, readline().split())) for _ in range(n)]
    mt = - (10 ** 10)
    for it in itertools.product([True, False], repeat=10):
        if sum(it) != 0:
            ls = [0] * n(n):
                    ls[j] += 1 if f[j][i] == 1 and iv else 0
            t = 0
            for i in range(n):
                t += p[i][ls[i]]
            mt = max(mt, t)
    print(mt)


if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
N=int(input())
F=[int(input()[::2],2)for _ in range(N)]
P=[list(map(int,input().split(" "))) for _ in range(N)]
print(max(sum(p[bin(i&f).count("1")]for f,p in zip(F,P))for i in r(1,1024)))

Submission status: Runtime Error

Solution code:
N = int(input())
F = [list(map(int,input().split())) for _ in range(N)]
P = [list(map(int,input().split())) for _ in range(N)]
print(max(sum([p[bin(f&i).count('1')]for f,p in zip(F,P)])for i in range(1,1024)))

Submission status: Runtime Error

Solution code:
N = int(input())
F = []
P = []
Pre = []
for i in range(N):
  F.append(list(map(int, input().split())))
for i in range(N):
  P.append(list(map(int, input().split())))

for loop in range(1,1024):
  rieki = 0
  Fnum = 0
  f = str(format(loop,"b")).rjust(10,"0") #自店の開店時間帯
  for i in range(N): # 全店舗に対し利益計算
    for j in range(10): # 店舗iと同時に営業する時間帯の数
      Fnum = Fnum + F[i][j] * int(f[j])
    #print("時間帯:{}".format(Fnum))
    rieki = rieki + P[i][Fnum] # P行列参照
  #print("rieki is {}".format(rieki))
  Pre.append(rieki) 
print(max(Pre))

Submission status: Runtime Error

Solution code:
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

max_v = -(10 ** 10)
for i in range(1,2**10):

    S_cnt = [0] * 10
    for j in range(10):
        if i % 2 == 1:
            for k in range(N):
                if F[k][j] == 1:
                    S_cnt[k] += 1
        i //= 2
    print

    tmp_v = 0
    for j in range(N):
        tmp_v += P[j][S_cnt[j]]
    max_v = max(max_v, tmp_v)

print(max_v)

Submission status: Runtime Error

Solution code:
N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]
l = [format(i, 'b').zfill(10) for i in range(1, 2 ** 10)]
ans = []

for i in l:
    c = [0] * 
    for j in range(10):
        if i[j] == '1':
            for k in range(N):
                if F[k][j] == 1:
                    c[k] += 1
                else:
                    continue
        else:
            continue
    temp = 0
    for j in range(N):
        temp += P[j][c[j]]
    ans.append(temp)

print(max(ans))

Submission status: Runtime Error

Solution code:
N = int(input())
F = []
for i in range(N):
    F_temp = list(map(int, input().split()))
    F.append(F_temp)
P = []
for i in range(N):
    P_temp = list(map(int, input().split()))
    P.append(P_temp)

ans = -1000000000

for i in range(1,1024):
    F0 = [0]*10
    i_temp = i
    for j in range(10):
        F0[j] = i_temp%2
        i_temp = int(i_temp/2)
    
    c = [0]*10
    for j in range(10):
        if F0[j] == 1:
            for k in range(N):
                c[k] += F[k][j]
    
    ans_temp = 0
    for j in range(N):
        ans_temp += P[j][c[j]]
    ans = max(ans, ans_temp)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
F = []

for _ in range(N):
    F.append(list(map(int, input().split())))

P = []

for _ in range(N):
    P.append(list(map(int, input().split())))

c = [0] * 10
ans = - float('inf')
tmp = 0

for i in range(1, 1024):
    ii = format(i, 'b')
    ii = str(ii)
    ii = ii.zfill(10)
    ii = list(ii)
    for j in range(N):
        for k in range(10):
            if str(F[j][k]) == ii[k] and ii[k] == '1':
                c[j] += 1
    for j in range(N):
        tmp += P[j][c[j]]
    if tmp > ans:
        ans = tmp
    tmp = 0
    c = [0] * 10

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
F = []

for _ in range(N):
    F.append(list(map(int, input().split())))

P = []

for _ in range(N):
    P.append(list(map(int, input().split())))

c = [0] * 10
ans = -1000000000
tmp = 0

for i in range(1, 1024):
    ii = format(i, 'b')
    ii = str(ii)
    ii = ii.zfill(10)
    ii = list(ii)
    for j in range(N):
        for k in range(10):
            if str(F[j][k]) == ii[k] and ii[k] == '1':
                c[j] += 1
    for j in range(N):
        tmp += P[j][c[j]]
    if tmp > ans:
        ans = tmp
    tmp = 0
    c = [0] * 10

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
F = []

for _ in range(N):
    F.append(list(map(int, input().split())))

P = []

for _ in range(N):
    P.append(list(map(int, input().split())))

c = [0] * 10
ans = -1000000000
tmp = 0

for i in range(1, 1024):
    ii = format(i, 'b')
    ii = str(ii)
    ii = ii.zfill(10)
    ii = list(ii)
    for j in range(N):
        for k in range(10):
            if str(F[j][k]) == ii[k] == '1':
                c[j] += 1
    for j in range(N):
        tmp += P[j][c[j]]
    if tmp > ans:
        ans = tmp
    tmp = 0
    c = [0] * 10

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
F = []

for _ in range(N):
    F.append(list(input().split()))

P = []

for _ in range(N):
    P.append(list(map(int, input().split())))

c = [0] * 10
ans = -1000000000
tmp = 0

for i in range(1, 1024):
    i = format(i, 'b')
    i = str(i)
    i = i.zfill(10)
    i = list(i)
    for j in range(N):
        for k in range(10):
            if F[j][k] == i[k] == '1':
                c[j] += 1
    for j in range(N):
        tmp += P[j][c[j]]
    if tmp > ans:
        ans = tmp
    tmp = 0
    c = [0] * 10

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

def dfs(i, A, ans):
    if i == 10:
        ans.append(A)
        return ans
    B = A[:]
    B.append(0)
    ans = dfs(i+1, B, ans)
    C = A[:]
    C.append(1)
    ans = dfs(i+1, C, ans)
    return ans

def main()
    D = dfs(0, [], [])
    for ind, A in enumerate(D):
        if ind == 0:
            continue
        gain = 0
        for i in range(N):
            c = 0
            for day in range(10):
                c += F[i][day]*A[day]
            gain += P[i][c]
        if ind == 1:
            ans = gain
            continue
        ans = max(ans, gain)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
f = []
for _ in range(n):
    f.append(list(map(int, input().split())))
p = []
for _ in range(n):
    p.append(list(map(int, input().split())))
ans = - (10 ** 9)
for i in range(1, 2 ** 10):
    store = {lll : 0 for lll in range(10)}
    k = "0" * (10 - len(bin(i)) + 2) + bin(i)[2:]
    for j, kk in enumerate(k):
        if kk == "1":
            for nn in range(n):
                if f[nn][j] == 1:
                    store[nn] += 1
    calc = 0
    for x, y in enumerate(p):
        calc += y[store[x]]
    ans = max(ans, calc)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000000000)

n = int(input())
f = []
for _ in range(n):
    f.append(list(map(int, input().split())))
p = []
for _ in range(n):
    p.append(list(map(int, input().split())))
ans = - (10 ** 9)
for i in range(1, 2 ** 10):
    store = {i : 0 for i in range(10)}
    k = "0" * (10 - len(bin(i)) + 2) + bin(i)[2:]
    for j, kk in enumerate(k):
        if kk == "1":
            for nn in range(n):
                if f[nn][j] == 1:
                    store[nn] += 1
    calc = 0
    for x, y in enumerate(p):
        calc += y[store[x]]
    ans = max(ans, calc)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(1000000)

n = int(input())
f = []
for _ in range(n):
    f.append(list(map(int, input().split())))
p = []
for _ in range(n):
    p.append(list(map(int, input().split())))
ans = - (10 ** 9)
for i in range(1, 2 ** 10):
    store = {i : 0 for i in range(10)}
    k = "0" * (10 - len(bin(i)) + 2) + bin(i)[2:]
    for j, kk in enumerate(k):
        if kk == "1":
            for nn in range(n):
                if f[nn][j] == 1:
                    store[nn] += 1
    calc = 0
    for x, y in enumerate(p):
        calc += y[store[x]]
    ans = max(ans, calc)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
f = []
for _ in range(n):
    f.append(list(map(int, input().split())))
p = []
for _ in range(n):
    p.append(list(map(int, input().split())))
ans = - (10 ** 9)
for i in range(1, 2 ** 10):
    store = {i : 0 for i in range(10)}
    k = "0" * (10 - len(bin(i)) + 2) + bin(i)[2:]
    for j, kk in enumerate(k):
        if kk == "1":
            for nn in range(n):
                if f[nn][j] == 1:
                    store[nn] += 1
    calc = 0
    for x, y in enumerate(p):
        calc += y[store[x]]
    ans = max(ans, calc)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
f = []
for _ in range(n):
    f.append(list(map(int, input().split())))
p = []
for _ in range(n):
    p.append(list(map(int, input().split())))
ans = []
for i in range(1, 2 ** 10):
    store = [0 for _ in range(10)]
    k = "0" * (10 - len(bin(i)) + 2) + bin(i)[2:]
    for j, kk in enumerate(k):
        if kk == "1":
            for nn in range(n):
                if f[nn][j] == 1:
                    store[nn] += 1
    calc = 0
    for x, y in enumerate(p):
        calc += y[store[x]]
    ans.append(calc)
print(max(ans))

Submission status: Runtime Error

Solution code:
N = int(input())
opens = [list(map(int, input().split())) for _ in range(N)]
values = [list(map(int, input().split())) for _ in range(N)]

ans = -(10**9)
for time in range(2**N+1):
  sum_v = 0
  for idx, open in enumerate(opens):
    open_str = ''.join(open)
    bin_str = format(time, '010b')
    both_open = bin_str&bin(open_str)
    cnt = 0
    for char in str(both_open):
      if char == '1':
        cnt += 1
    sum_v += values[idx][cnt]
  ans = max(ans, sum_cnt)

Submission status: Runtime Error

Solution code:
import sys
N = int(input())

time_lis = [0] * N
profit = [0] * N
for n in range(N):
    time_lis[n] = list(map(int, input().split()))
for n in range(N):
    profit[n] = list(map(int, input().split()))

ans = 0
always_zero = True
for n in range(N):
    count_1 = len([i for i in time_lis[n] if i == 1])
    tmp= max(profit[n][:count_1 + 1])
    ans += tmp
    if profit[n].index(tmp) != 0:
        always_zero = False
if always_zero:
    max_prof = sorted([(item[0], item[1]) for item in profit], key=lambda x: -x[1])
    print(ans - max_prof[0] + max_prof[1])
    sys.exit()
print(ans)

Submission status: Runtime Error

Solution code:
import sys
N = int(input())

time_lis = [0] * N
profit = [0] * N
for n in range(N):
    time_lis[n] = list(map(int, input().split()))
for n in range(N):
    profit[n] = list(map(int, input().split()))

ans = 0
always_zero = True
for n in range(N):
    count_1 = len([i for i in time_lis[n] if i == 1])
    ans += max(profit[n][:count_1 + 1])
    if profit[n].index(ans) != 0:
        always_zero = False
if always_zero: 
    max_prof = sorted([(item[0], item[1]) for item in profit], key=lambda x: -x[1])
    print(ans - max_prof[0][0] + max_prof[0][1])
    sys.exit()
print(ans)

Submission status: Runtime Error

Solution code:
import sys
N = int(input())

time_lis = [0] * N
profit = [0] * N
for n in range(N):
    time_lis[n] = list(map(int, input().split()))
for n in range(N):
    profit[n] = list(map(int, input().split()))

ans = 0
always_zero = True
for n in range(N):
    count_1 = len([i for i in time_lis[n] if i == 1])
    ans += max(profit[n][:count_1 + 1])
    if profit[n].index(ans) != 0:
        always_zero = False
if always_zero: 
    max_prof = sorted([item[0], item[1] for item in profit], key=lambda x: -x[1])
    print(ans - max_prof[0][0] + max_prof[0][1])
    sys.exit()
print(ans)

Submission status: Runtime Error

Solution code:
import sys
N = int(input())

time_lis = [0] * N
profit = [0] * N
for n in range(N):
    time_lis[n] = list(map(int, input().split()))
for n in range(N):
    profit[n] = list(map(int, input().split()))

ans = 0
always_zero = True
for n in range(N):
    count_1 = len([i for i in time_lis[n] if i == 1])
    tmp= max(profit[n][:count_1 + 1])
    ans += tmp
    if profit[n].index(tmp) != 0:
        always_zero = False
if always_zero:
    max_prof = sorted([item[0], item[1] for item in profit], key=lambda x: -x[1])
    print(ans - max_prof[0] + max_prof[1])
    sys.exit()
print(ans)

Submission status: Runtime Error

Solution code:
import sys
N = int(input())

time_lis = [0] * N
profit = [0] * N
for n in range(N):
    time_lis[n] = list(map(int, input().split()))
for n in range(N):
    profit[n] = list(map(int, input().split()))

ans = 0
always_zero = True
for n in range(N):
    count_1 = len([i for i in time_lis[n] if i == 1])
    ans += max(profit[n][:count_1 + 1])
    if profit[n].index(ans) != 0:
        always_zero = False
if always_zero:
    max_prof = [item[1] for item in profit]
    print(max(max_prof))
    sys.exit()
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
f = [int(input().replace(' ',''),2) for i in range(n)]
p = [list(map(int,input().split())) for i in range(n)]
prof = - 10 ** 10
for i in range(1,1 <<10):
	prof1 = 0
	for j,time in enumerate(f):
		same = bin(i & time).count(1)
		prof1 += p[j][same]
	prof = max(prof,prof1)
print(prof)

Submission status: Runtime Error

Solution code:
N=int(input())
F=[int(input().replace(' ',''),2) for _ in range(N)]
P=[list(map(int,input(),split())) for _ in range(N)]

ans=-10**10
for i in range(1,1<<10):
    prof=0
    for j,f in enumerate(F):
        prof+=P[j][bin(i&f).count("1")]
    ans=max(ans,prof)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
st_con = [[i for i in map(int,input().split())] for j in range(N)]
rieki = [[i for i in map(int,input().split())] for j in range(N)]

ans = -10**9
for i in range(1,2**10):
    a = 0
    count = [0]*10
    for j in range(N):
        for h in range(10):
            if (i>>h) & st_con[j][h] and (i>>h) == 1:
                count[j] += 1
        a += rieki[j][count[j]]
    
    if ans < a : ans = a 
print("{}".format(ans))

Submission status: Runtime Error

Solution code:
N = int(input())
st_con = [[i for i in map(int,input().split())] for j in range(N)]
rieki = [[i for i in map(int,input().split())] for j in range(N)]

ans = []
for i in range(1,2**10):
    a = 0
    count = [0]*10
    for j in range(N):
        for h in range(10):
            if (i>>h) & st_con[j][h] and (i>>h)&1:
                count[j] += 1
        a += rieki[j][count[j]]
    ans.append(a)
    
print("{}".format(max(ans)))

Submission status: Runtime Error

Solution code:
N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]
ans = -10**9
v = [0] * 10

def culc():
    global ans
    score = 0
    index = 0
    if any(v) == False:
        return
    for i in range(N):
        for j in range(10):
            index += F[i][j] * v[j]
        score += P[i][index]
    ans = max(ans, score)
    return

def dfs(pos):
    if pos == 10:
        culc()
        return

    v[pos] = 0
    dfs(pos+1)
    v[pos] = 1
    dfs(pos+1)
    
    return

dfs(0)

print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
F=[]
for i in range(N):
    tem = list(map(int,input().split()))
    F.append(tem)
P=[]
for i in range(N):
    tem = list(map(int,input().split()))
    P.append(tem)


max_benef =-float("inf")

for d in range(1,2**10):
    op = ["-"] * 10  # あらかじめ ["-", "-", "-"] というリストを作っておく
    for j in range(10):
        if ((d >> j) & 1):
            op[10 - 1 - j] = "+"  # フラグが立っていた箇所を "+" で上書き
    
    m =0
    count=[0 for t in range(10)]
    for t in range(10):
        if op[t]=="+":
            for s in range(10):
                if F[s][t]==1:
                    count[s]+=1
        for s in range(10):
            m += P[s][count[s]]
        ans = max(m,ans)
    
    print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
f = [input().split(' ') for _ in range(n)]
p = [input().split(' ') for _ in range(n)]
res = -10**8
for num in range(1, 1024):
  tmp = 0
  for index in range(0, n):
    tmp += int(p[index][len([True for x in range(0, 10) if f[index][x]==f'{num:010b}'[x]=='1'])])
  res = max(tmp, res)

print(res)

Submission status: Runtime Error

Solution code:
N=int(input())
F=[list(map(int,input().split())) for _ in range(N)] #0-9
P=[list(map(int,input().split())) for _ in range(N)] #0-10

INF=10**9
ans=-INF

for i in range(1,2**10):
    tmp=[0]*10
    tmpans=0
    for j in range(0,10):
        bit=i>>j&1
        for n in range(N):
            tmp[n]+=F[n][j]*bit
    for n in range(N):
        tmpans+=P[n][tmp[n]]

    ans=max(ans,tmpans)

print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
F=[list(map(int,input().split())) for _ in range(N)] #0-9
P=[list(map(int,input().split())) for _ in range(N)] #0-10
INF=10**9
ans=-INF


for i in range(1,2**10):
    tmp=[0]*10
    tmpans=0
    for j in range(0,10):
        bit=i>>j&1
        for n in range(N):
            tmp[n]+=F[n][j]*bit
    for n in range(N):
        tmpans+=P[n][tmp[n]]

    ans=max(ans,tmpans)

print(ans)

Submission status: Runtime Error

Solution code:
from itertools import product
import numpy as np


def solve(string):
    n, *fp = map(int, string.split())
    # f = np.asarray(fp[:10 * n]).reshape((n, 10))
    f = fp[:10 * n]
    p = fp[10 * n:]
    ans = -n * 10**7
    """
    for o in product([0, 1], repeat=10):
        if sum(o) == 0:
            continue
        # tmp = np.dot(f, np.asanyarray(o).T)
        tmp = [sum([for ]) for _f in f]
        ans = max(ans, sum([p[11 * i + t] for i, t in enumerate(tmp)]))
    return str(ans)
    """
    int_f = [int("".join(map(str, f[10 * i:10 * (i + 1)])), 2) for i in range(n)]
    for o in range(1, 2**10):
        tmp = [sum(map(int, f"{o & _f:b}")) for _f in int_f]
        ans = max(ans, sum([p[11 * i + t] for i, t in enumerate(tmp)]))
    return str(ans)


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(2 * n)])))

Submission status: Runtime Error

Solution code:
from itertools import product
import numpy as np


def solve(string):
    n, *fp = map(int, string.split())
    # f = np.asarray(fp[:10 * n]).reshape((n, 10))
    f = fp[:10 * n]
    p = fp[10 * n:]
    ans = -n * 10**7
    """
    for o in product([0, 1], repeat=10):
        if sum(o) == 0:
            continue
        # tmp = np.dot(f, np.asanyarray(o).T)
        tmp = [sum([for ]) for _f in f]
        ans = max(ans, sum([p[11 * i + t] for i, t in enumerate(tmp)]))
    return str(ans)
    """
    int_f = [int("".join(map(str, f[10 * i:10 * (i + 1)])), 2) for i in range(n)]
    for o in range(1, 2**10):
        tmp = [sum(map(int, f"{o & _f:b}")) for _f in int_f]
        print(tmp)
        ans = max(ans, sum([p[11 * i + t] for i, t in enumerate(tmp)]))
    return str(ans)


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(2 * n)])))