Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def prf(n):
    pf = {}
    for i in range(2, int(n ** 1 / 2) + 1):
        while n % i == 0:
            if not i in pf:
                pf[i] = 0
            pf[i] += 1
            n //= i
    if n > 1:
        pf[n] = 1
    return pf

def comb(n, k):
    k = min(k, n - k)
    result = 1
    for i in range(n, n - k, -1):
        result *= i
    for i in range(1, k + 1):
        result //= i 
    return result

n, m = map(int, input().split())
mod = 10 ** 9 + 7

ans = 1
for i in prf(m).values():
    ans = ans * comb(n - 1 + i, i) % mod
    
print(ans)

Fixed submission:
#素因数分解
def prf(m):
    pf = {}
    for i in range(2, int(m**0.5)+1):
        while m % i == 0:
            pf[i] = pf.get(i, 0)+1
            #get:辞書のkeyを指定し、そのkeyがあればvalueを返し、なければ指定した値を返す
            m //= i
    if m > 1:
        pf[m] = 1
        #mの平方根よりも大きい数が残る場合はその数自体が素因数(m=10=2*5)
    return pf

#組合せ（nCk）
def comb(n, k):
    k = min(k, n - k)
    result = 1
    for i in range(n, n - k, -1):
        result *= i
    for i in range(1, k + 1):
        result //= i 
    return result
 
n, m = map(int, input().split())
mod = 10 ** 9 + 7

ans = 1
for i in prf(m).values():
    ans = ans * comb(n - 1 + i, i) % mod
    #重複組合せ：N-1枚の仕切り（aとaの間の個数に相当）を使って、i（指数）を振り分ける場合の数
print(ans)
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
x_list = list(map(int, input().split()))

x_abs = []
for i in x_list:
    x_abs.append(abs(X - i))

def gcd(i, j):
    if i % j == 0:
        return j
    else:
        k = i % j
        gcd(j, k)

x_abs.sort(reverse=True)
ans = 0
if len(x_abs) == 1:
    ans = x_abs[0]
else:
    for i in range(N-2):
        temp = gcd(x_abs[i], x_abs[i + 1])
        ans = gcd(temp, x_abs[i + 2])
    
print(ans)

Fixed submission:
from fractions import gcd
from functools import reduce
n,x = map(int,input().split())
 
l=list(map(int,input().split()))
l=list(map(lambda i: abs(i-x),l))
 
x = reduce(gcd,l)
print(x)

Buggy python submission (verdict: Runtime Error):
from math import gcd
from functools import reduce

N, X = map(int,input().split()) 
nums=list(map(int,input().split()))
nums=list(map(lambda i: abs(i - X),nums))
 
D = reduce(gcd, nums)
print(D)

Fixed submission:
from fractions import gcd
from functools import reduce
n,x = map(int,input().split())
 
l=list(map(int,input().split()))
l=list(map(lambda i: abs(i-x),l))
 
x = reduce(gcd,l)
print(x)

Buggy python submission (verdict: Runtime Error):
from fractions import gcd
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

N, X = map(int, input().split())
nums = list(map(int, input().split()))
nums.append(X)
nums.sort()
dists = []

for i in range(N):
    dist = nums[i + 1] - nums[i]
    dists.append(dist)
    
D = gcd(*dists)

print(D)

Fixed submission:
from fractions import gcd
from functools import reduce
n,x = map(int,input().split())
 
l=list(map(int,input().split()))
l=list(map(lambda i: abs(i-x),l))
 
x = reduce(gcd,l)
print(x)

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

N, X = map(int, input().split())
nums = list(map(int, input().split()))
nums = list(map(lambda i: abs(i - X), nums))

D = reduce(gcd, nums)
print(D)

Fixed submission:
from fractions import gcd
from functools import reduce
n,x = map(int,input().split())
 
l=list(map(int,input().split()))
l=list(map(lambda i: abs(i-x),l))
 
x = reduce(gcd,l)
print(x)

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

N, X = map(int, input().split())
nums = list(map(int, input().split()))
nums.append(X)
nums.sort()
dists = []

for i in range(N):
    dist = nums[i + 1] - nums[i]
    dists.append(dist)
    
D = gcd(*dists)

print(D)

Fixed submission:
from fractions import gcd
from functools import reduce
n,x = map(int,input().split())
 
l=list(map(int,input().split()))
l=list(map(lambda i: abs(i-x),l))
 
x = reduce(gcd,l)
print(x)
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
A = [[int(i) for i in input().split()] for i in range(h)]
count = 0
B = []

for i in range(h):
    for j in range(w):
        if A[i][j] % 2 == 1:
            count += 1
            A[i][j+1] += 1
            B.append([i+1, j+1, i+1, j+2])

for i in range(h-1):
    if A[i][w-1] % 2 == 1:
        count += 1
        A[i+1][w-1] += 1
        B.append([i+1, w, i+2, w])
        
print(count)
for i in range(count):
    print(B[i][0], B[i][1], B[i][2], B[i][3])

Fixed submission:
h,w = map(int,input().split())
coin = [list(map(int,input().split())) for i in range(h)]
ans = []
c = 0
for i in range(h):
  for j in range(w-1):
    if coin[i][j] % 2:
      coin[i][j+1] += 1
      ans.append([i+1,j+1,i+1,j+2])
      c += 1
 
for k in range(h-1):
  if coin[k][w-1] % 2:
    coin[k+1][w-1] += 1
    ans.append([k+1,w,k+2,w])
    c += 1
    
print(c)
for i in range(c):
  print(ans[i][0],ans[i][1],ans[i][2],ans[i][3])
Buggy python submission (verdict: Time Limit Exceeded):
N, M, Q = map(int, input().split())

A = [[0] * (N + 1) for i in range(N + 1)]
for i in range(M):
    l, r = map(int, input().split())
    A[l][r] += 1
    
for i in range(Q):
    p, q = map(int, input().split())
    cnt = 0
    for i in range(p, q + 1):
        cnt += sum(A[i][p : q + 1])
    print(cnt)

Fixed submission:
n, m, q = map(int, input().split())
A = [[0] * (n+2) for i in range(n+2)]

for i in range(m):
    l, r = map(int, input().split())
    A[l][r] += 1

for i in range(n+1):
    for j in range(n+1):
        A[i][j+1] += A[i][j]
        A[i+1][j] += A[i][j]
        A[i+1][j+1] -= A[i][j]

B = []
for i in range(q):
    p, q = map(int, input().split())
    B.append(A[q][q] - A[q][p-1] - A[p-1][q] + A[p-1][p-1])
    
for b in B:
    print(b)
Buggy python submission (verdict: Runtime Error):
import fractions
a = int(input())
print((a * 2 ) // math.gcd(a, 2))

Fixed submission:
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x

n = int(input())
print((n * 2) // gcd(n, 2))

Buggy python submission (verdict: Runtime Error):
import math
a = int(input())
print((a * 2 ) // math.gcd(a, 2))

Fixed submission:
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x

n = int(input())
print((n * 2) // gcd(n, 2))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
B = []

for i in range(n):
    b = A[i] - (i + 1)
    B.append(b)
    
ans = 10 ** 9
    
for b in B:
    Sum = 0
    for i in range(n):
        Sum += abs(A[i] - (b + (i + 1))) 
    ans = min(ans, Sum)
    
print(ans)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
B = []

for i in range(n):
    b = A[i] - (i + 1)
    B.append(b)

B.sort()
medianB = B[n // 2]

Sum = 0
for i in range(n):
    Sum += abs(A[i] - (medianB + (i + 1))) 
    
print(Sum)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = 0

while any(A[i] % 2 == 0 for i in range(n)):
    count = 0
    for i in range(n):
        if A[i] % 2 == 0:
            if count == 0:
                A[i] = A[i] // 2
                count += 1
            else:
                A[i] = A[i] * 3
        else:
            A[i] = A[i] * 3
    A.sort(reverse=True)
    ans += 1
        
print(ans)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
A2 = []

for i in range(n):
    if A[i] % 2 == 0:
        A2.append(A[i])
        
count = 0
for a in A2:
    while a % 2 == 0:
        a = a // 2
        count += 1
        
print(count)
Buggy python submission (verdict: Runtime Error):
def f(x):
    if x == 1:
        return 1
    return x + f(x - 1)

a, b = map(int, input().split())
x = b - a
ans = f(x) - b

print(ans)

Fixed submission:
a, b = map(int, input().split())
n = b - a

ans = 0
for i in range(1, n + 1):
    ans += i
    
print(ans - b)

Buggy python submission (verdict: Runtime Error):
def f(x):
    if x == 0:
        return 0
    return x + f(x - 1)

a, b = map(int, input().split())
x = b - a
ans = f(x) - b

print(ans)

Fixed submission:
a, b = map(int, input().split())
n = b - a

ans = 0
for i in range(1, n + 1):
    ans += i
    
print(ans - b)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(input())
sumC = []

for i in range(n):
    countW = 0
    countE = 0
    for j in range(0, i):
        if A[j] == 'W':
            countW += 1
    for k in range(i + 1, n):
        if A[k] == 'E':
            countE += 1
    sumC.append(countW + countE)

print(min(sumC))

Fixed submission:
n = int(input())
S = input()
ans = n
temp = 0

for i in range(1, n):
    if S[i] =='E':
        temp += 1
ans = min(ans, temp)

for i in range(1, n):
    if S[i - 1] == 'W':
        temp += 1
    if S[i] == 'E':
        temp -= 1
    ans = min(ans, temp)        

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, c, k = map(int, input().split())

if a == b and b == c:
    ans = 0
else:
    dp = [a, b, c]
    for i in range(k):
        if abs(dp[0] - dp[1]) > 10 ** 18:
            ans = 'Unfair'
            break
        else:
            dp[0], dp[1], dp[2] = dp[1] + dp[2], dp[0] + dp[2], dp[0] + dp[1]
    else:
        ans = dp[0] - dp[1]

print(ans)

Fixed submission:
a, b, c, k = map(int, input().split())

if a == b and b == c:
    ans = 0
elif a - b > 10 ** 18:
    ans = 'Unfair'
else:
    if k % 2 == 0:
        ans = a - b
    else:
        ans = b - a
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
k = int(input())
A = []

for i in range(len(S) + 1):
    for j in range(i + 1, len(S) + 1):
        A.append(S[i:j])
        
ans = sorted(list(set(A)))
print(ans[k - 1])

Fixed submission:
S = input()
k = int(input())
A = []

for i in range(len(S)):
    for j in range(1, k + 1):
        A.append(S[i : i + j])
        
ans = sorted(list(set(A)))
print(ans[k - 1])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
k = int(input())
n = len(S)
A = [[0] * n for _ in range(n)]

A[0][0] = S[0]
for i in range(1, n):
    A[0][i] = A[0][i - 1] + S[i]
    
for i in range(1, n):
    for j in range(0, n):
        A[i][j] = A[i - 1][j][1:]
        

flatA = []
for a in A:
    flatA.extend(a)

flatA.sort()
setA = set(flatA)

if '' in setA:
    setA.remove('')

finalA = list(setA)
finalA.sort()

print(finalA[k - 1])

Fixed submission:
S = input()
k = int(input())
A = []

for i in range(len(S)):
    for j in range(1, k + 1):
        A.append(S[i : i + j])
        
ans = sorted(list(set(A)))
print(ans[k - 1])
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
P = [int(i) for i in input().split()]

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [-1 for _ in range(n)]
        
    def same(self, x, y):
        return self.root(x)==self.root(y)
 
    def unite(self,x,y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
 
        if self.par[x] > self.par[y]:
            x,y = y,x
 
        self.par[x] += self.par[y]
        self.par[y] = x
        
uf = UnionFind(N)

for i in range(M):
    x, y = map(int, input().split())
    uf.unite(x - 1, y - 1)
    
cnt = 0
for i in range(N):
    if uf.same(i, P[i] - 1):
        cnt += 1
        #print(i, P[i])
        
print(cnt)

Fixed submission:
N, M = map(int, input().split())
P = [int(i) for i in input().split()]

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [-1 for _ in range(n)]
        
    def same(self, x, y):
        return self.root(x)==self.root(y)
 
    def root(self, x):
        if self.par[x]<0:
            return x
        self.par[x] = self.root(self.par[x])
        return self.par[x]
 
    def unite(self,x,y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
 
        if self.par[x] > self.par[y]:
            x,y = y,x
 
        self.par[x] += self.par[y]
        self.par[y] = x
        
uf = UnionFind(N)

for i in range(M):
    x, y = map(int, input().split())
    uf.unite(x - 1, y - 1)
    
cnt = 0
for i in range(N):
    if uf.same(i, P[i] - 1):
        cnt += 1
        #print(i, P[i])
        
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = [int(i) for i in input().split()]

cnt = 0
for i in range(n):
    dp = 0
    for j in range(i, n):
        dp += A[j]
        if dp == 0:
            cnt += 1
            
print(cnt)

Fixed submission:
from collections import Counter

def comb(n, k):
    k = min(k, n - k)
    result = 1
    for i in range(n, n - k, -1):
        result *= i
    for i in range(1, k + 1):
        result //= i 
    return result

n = int(input())
A = [int(i) for i in input().split()]

S = [0] * (n + 1)
for i in range(1, n + 1):
    S[i] = S[i - 1] + A[i - 1]
    
S = Counter(S)
ans = 0
for v in S.values():
    if v > 1:
        ans += comb(v, 2)
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = [int(i) for i in input().split()]

cnt = 0
for i in range(n):
    for j in range(i + 1, n + 1):
        if sum(A[i : j]) == 0:
            cnt += 1
            
print(cnt)

Fixed submission:
from collections import Counter

def comb(n, k):
    k = min(k, n - k)
    result = 1
    for i in range(n, n - k, -1):
        result *= i
    for i in range(1, k + 1):
        result //= i 
    return result

n = int(input())
A = [int(i) for i in input().split()]

S = [0] * (n + 1)
for i in range(1, n + 1):
    S[i] = S[i - 1] + A[i - 1]
    
S = Counter(S)
ans = 0
for v in S.values():
    if v > 1:
        ans += comb(v, 2)
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

for i in range(n):
    A2 = A.copy()
    A2.pop(i)
    A2.sort()
    print(A2[(n // 2) - 1])

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
sortA = sorted(A)

for i in range(n):
    if A[i] <= sortA[(n // 2) - 1]:
        print(sortA[n // 2])
    else:
        print(sortA[(n // 2) - 1])
Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
r = list(range(a, b + 1))
for i in sorted(set(r[:k]) | set(r[- k:])):
    print(i)

Fixed submission:
a, b, k = map(int, input().split())

if b - a < 2 * k:
    for i in range(a, b + 1):
        print(i)

else:
    ans = []
    for i in range(k):
        ans.append(a + i)
    for i in range(k-1, -1, -1):
        ans.append(b - i)

    for i in ans:
        print(i)
Buggy python submission (verdict: Runtime Error):
M = 'abcdefghijklmnopqrstuvwxyz'
S = input()

if len(S) != 26:
    print(S + sorted(list(set(M) - set(S)))[0])
else:
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        for i in range(26):
            if S[i] != M[i]:
                if S[i] == 'z':
                    ans = S[: i - 1] + M[i]
                    break
                else:
                    ans = S[: i] +str(list(M)[list(M).index(S[i]) + 1])
                    break
        print(ans)

Fixed submission:
S = input()
 
chars = "abcdefghijklmnopqrstuvwxyz"
char_set = set(chars)
 
if len(S) == 26:
    for i in range(len(S)-1, -1, -1):
        x = chars.index(S[i])
        y = sorted(set(chars[x+1:])-set(S[:i]))
        # print(i, y)
        if len(y):
            print(S[:i]+y[0])
            exit()
else:
    t = sorted(set(chars)-set(S))[0]
    print(S+t)
    exit()
print(-1)

Buggy python submission (verdict: Runtime Error):
M = 'abcdefghijklmnopqrstuvwxyz'
S = input()

if len(S) != 26:
    print(S + sorted(list(set(M) - set(S)))[0])
else:
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        for i in range(26):
            if S[i] != M[i]:
                ans = S[: i - 1] + M[i]
                break
        print(ans)

Fixed submission:
S = input()
 
chars = "abcdefghijklmnopqrstuvwxyz"
char_set = set(chars)
 
if len(S) == 26:
    for i in range(len(S)-1, -1, -1):
        x = chars.index(S[i])
        y = sorted(set(chars[x+1:])-set(S[:i]))
        # print(i, y)
        if len(y):
            print(S[:i]+y[0])
            exit()
else:
    t = sorted(set(chars)-set(S))[0]
    print(S+t)
    exit()
print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
H, W, D = map(int, input().split())
A = [[int(i) for i in input().split()] for i in range(H)]

L = [[] for i in range(H * W)]
for i in range(H):
    for j in range(W):
        L[A[i][j] - 1] = [i + 1, j + 1]


Q = int(input())
for i in range(Q):
    ans = 0
    l, r = map(int, input().split())
    if l == r:
        print(ans)
        continue
    a, b = L[l - 1]
    while L[r - 1] != L[l + D - 1]:
        c, d = L[l - 1 + D]
        ans += abs(a - c) + abs(b - d)
        a, b = L[l + D - 1]
        l = l + D
    e, f = L[r - 1]
    ans += abs(a - e) + abs(b - f)
    print(ans)

Fixed submission:
H, W, D = map(int, input().split())
A = [[int(i) for i in input().split()] for i in range(H)]

L = [[] for i in range(H * W + 1)]
for i in range(H):
    for j in range(W):
        L[A[i][j]] = [i + 1, j + 1]
        
d = [0] * (H * W + 1)
for i in range(D + 1, H * W + 1):
    d[i] = d[i - D] + abs(L[i][0] - L[i - D][0]) + abs(L[i][1] - L[i - D][1])

Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    print(d[r] - d[l])
Buggy python submission (verdict: Time Limit Exceeded):
n, y = map(int, input().split())

ans =[-1, -1, -1]
for i in range(n + 1):
    for j in range(n + 1 - i):
        for k in range(n + 1 - i - j):
            if i * 10000 + j * 5000 + k * 1000 == y and i + j + k == n:
                ans = [i, j, k]
                break
print(' '.join(map(str, ans)))

Fixed submission:
n, y = map(int, input().split())
 
ans =[-1, -1, -1]
for i in range(n + 1):
    for j in range(n + 1 - i):
            if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
                ans = [i, j, n - i - j]
                break
print(' '.join(map(str, ans)))

Buggy python submission (verdict: Runtime Error):
n, y = map(int, input().split())
s = min(n, y // 10000)
t = min(n, y // 5000)
u = min(n, y // 1000)

ans =[-1, -1, -1]
for i in range(s, -1, -1):
    for j in range(t, -1, -1):
        for u in range(u, -1, -1):
            if i * 10000 + j * 5000 + k * 1000 == y and i + j + k == n:
                ans = [i, j, k]
                break
print(' '.join(map(str, ans)))

Fixed submission:
n, y = map(int, input().split())
 
ans =[-1, -1, -1]
for i in range(n + 1):
    for j in range(n + 1 - i):
            if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
                ans = [i, j, n - i - j]
                break
print(' '.join(map(str, ans)))
Buggy python submission (verdict: Time Limit Exceeded):
def sieve(n):
    p = 0
    prime = [0] * n
    is_prime = [True] * (n + 1)
    is_prime[0], is_prime[1] = False, False
    for i in range(2, n + 1):
        if is_prime[i]:
            prime[p] = i
            p += 1
            for j in range(2 * i, n + 1, i):
                is_prime[j] = False
            
    return prime[:p]

N = 10 ** 5
pn = sieve(N + 1)

dp = [0] * (N + 1)
for i in pn:
    if (i + 1) // 2 in pn:
        dp[i] += 1
        
Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    print(sum(dp[l : r + 1]))

Fixed submission:
def sieve(n):
    p = 0
    prime = [0] * n
    is_prime = [True] * (n + 1)
    is_prime[0], is_prime[1] = False, False
    for i in range(2, n + 1):
        if is_prime[i]:
            prime[p] = i
            p += 1
            for j in range(2 * i, n + 1, i):
                is_prime[j] = False
            
    return prime[:p]

N = 10 ** 5
pn = sieve(N + 1)

dp = [0] * (N + 1)
for i in pn:
    if (i + 1) // 2 in pn:
        dp[i] += 1
        
for i in range(1, N + 1):
    dp[i] += dp[i - 1] 
        
Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    print(dp[r] - dp[l - 1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = [int(i) for i in input().split()]
if all(A[i] % 2 == 0 for i in range(n)):
    ans = 10 ** 9
    for i in range(n):
        count = 0
        while A[i] % 2 == 0:
            A[i] //= 2
            count += 1
        ans = min(ans, count)
print(ans)

Fixed submission:
n = int(input())
A = [int(i) for i in input().split()]
ans = 10 ** 9
if all(A[i] % 2 == 0 for i in range(n)):
    for i in range(n):
        count = 0
        while A[i] % 2 == 0:
            A[i] //= 2
            count += 1
        ans = min(ans, count)
else:
    ans = 0
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
F = [[int(i) for i in input().split()] for i in range(n)]
P = [[int(i) for i in input().split()] for i in range(n)]

def f(x):
    if x % 2 == 0:
        return 1
    else:
        return 0
    
ans = -10 ** 10
for i in range(1, 2 ** 10):
    for j in range(10):
        A[j] = f(i // (2 ** (10 - i)))

    temp = 0
    for s in range(n):
        count = 0
        for t in range(10):
            if F[s][t] == 1 and A[t] == 1:
                count += 1
        temp += P[s][count]
    ans = max(ans, temp)
        
print(ans)

Fixed submission:
n = int(input())
F = [[int(i) for i in input().split()] for i in range(n)]
P = [[int(i) for i in input().split()] for i in range(n)]

ans = -10 ** 10
for i in range(1, 2 ** 10):
    tmp = i
    A = []
    while tmp:
        A.append(tmp % 2)
        tmp //= 2
    while len(A) != 10:
        A.append(0)

    temp = 0
    for s in range(n):
        count = 0
        for t in range(10):
            if F[s][t] == 1 and A[t] == 1:
                count += 1
        temp += P[s][count]
    ans = max(ans, temp)
        
print(ans)