Harryxun/stf_run huggingface dataset:
from operator import itemgetter
def position_zip(a,flag):
  j=0
  d={}
  for i in sorted(a):
    if i in d:continue
    d[i]=j
    j+=1
  if flag==1:return d
  return [d[i] for i in a]
class BinaryIndexedTree:
  def __init__(self,n):
    self.bit=[0]*n
  def add(self,i,x):
    i+=1
    while i<=len(self.bit):
      self.bit[i-1]+=x
      i+=i&-i
  def sum_sub(self,i):
    a=0
    i+=1
    while i:
      a+=self.bit[i-1]
      i-=i&-i
    return a
  def sum(self,i,j):
    a=self.sum_sub(j+1)
    if i!=0:a-=self.sum_sub(i-1)
    return a
n,q=map(int,input().split())
a=list(map(int,input().split()))
a=position_zip(a,0)
k=max(a)+1
ans=[0]*q
queries=[list(map(lambda x:int(x)-1,input().split()))+[i]for i in range(q)]
queries.sort(key=itemgetter(1))
queries.append([0,0,0])
lastAppeared=[-1]*k
bitt=BinaryIndexedTree(n)
j=0
for i in range(n):
  if lastAppeared[a[i]]!=-1:
    bitt.add(lastAppeared[a[i]],-1)
    bitt.add(i,1)
    lastAppeared[a[i]]=i
  else:
    bitt.add(i,1)
    lastAppeared[a[i]]=i
  while queries[j][1]==i:
    l,r,ind=queries[j]
    j+=1
    ans[ind]=bitt.sum(l,r-1)
print(*ans)


### FIXED CODE ###

def main():
  def add(i,x):
    i+=1
    while i<=n:
      bit[i-1]+=x
      i+=i&-i
  def sum_sub(i):
    a=0
    i+=1
    while i:
      a+=bit[i-1]
      i-=i&-i
    return a
  def sum(i,j):
    a=sum_sub(j+1)
    if i!=0:a-=sum_sub(i-1)
    return a
  
  n,q,*x=map(int,open(0).read().split())
  a=x[:n]
  queries=[]
  for i in range(q):
    l,r=x[n+i*2:n+(i+1)*2]
    l-=1
    r-=1
    queries.append(r<<40|l<<20|i)
  ans=[0]*q
  queries.sort()
  for i in range(q):
    ind=queries[i]%(1<<20)
    queries[i]>>=20
    l=queries[i]%(1<<20)
    queries[i]>>=20
    r=queries[i]
    queries[i]=[r,l,ind]
  queries.append([10*20])
  lastAppeared=[-1]*n
  bit=[0]*n
  j=0
  for i in range(n):
    if lastAppeared[a[i]-1]!=-1:
      add(lastAppeared[a[i]-1],-1)
      add(i,1)
      lastAppeared[a[i]-1]=i
    else:
      add(i,1)
      lastAppeared[a[i]-1]=i
    while queries[j][0]==i:
      r,l,ind=queries[j]
      j+=1
      ans[ind]=sum(l,r-1)
  print(*ans)
if __name__ == "__main__":
  main()
n=int(input())
a=list(map(int,input().split()))
ans=0
a_max=max(a)
a_min=min(a)
if a_min>=0:
    adding=a_max
elif a_min<0 and a_max>0:
    if abs(a_max)>=abs(a_min):
        adding=a_max
    else:
        adding=a_min
else:
    adding=a_min
ind=a.index(adding)
proc=[]
for i in range(n):
    ans+=1
    a[i]+=adding
    proc.append([ind+1,i+1])
for i in range(n-1):
    ans+=1
    a[i+1]+=a[i]
    proc.append([i+1,i+2])
print(ans)
for i in range(len(proc)):
    print(proc[i][0],proc[i][1])

### FIXED CODE ###

s = input()
 
print(int(s[0])+int(s[1])+int(s[2]))
K,X = map(int, input().split())

lis = [i for i in range(X-K+1,X+K)]
print(' '.join(map(str,r)))

### FIXED CODE ###

K,X = map(int, input().split())

lis = [i for i in range(X-K+1,X+K)]
print(' '.join(map(str,lis)))
N = int(input())
P = list(map(float, input().split()))
prob_memo = [[-1]*(N+1) for _ in range(N+1)]
prob_memo[0] = [1] + [0]*N

def prob(n,k):
  if prob_memo[n][k]==-1:
    prob_memo[n][k] = prob(n-1,k-1)*P[n-1] + prob(n-1,k)*(1-P[n-1])
  return prob_memo[n][k]

def prob_ret():
  ret = 0
  for k in range(N//2+1,N+1):
    ret += prob(N,k)
  return ret

print(prob_ret())

### FIXED CODE ###

N = int(input())
P = list(map(float, input().split()))
import numpy as np
def prob_ret():
  prob = [0.0]*(N+1)
  prob[0] = 1
  prob=np.array(prob)
  for n in range(N):
    p = prob[:N]*P[n]
    prob = prob * (1-P[n])
    prob[1:] = prob[1:] + p
  return sum(prob[N//2+1:])
print(prob_ret())
def main():
    N=int(input())
    A=int(input())
    B=int(input())
    C=int(input())
    D=int(input())
    E=int(input())
    for i in (A,B,C,D,E):
        min_num=min(i,min_num)
    print((N//min_num+1)+4)
    
if __name__=="__main__":
    main()

### FIXED CODE ###

import math
def main():
    N=int(input())
    A=int(input())
    B=int(input())
    C=int(input())
    D=int(input())
    E=int(input())
    min_num=N+1
    for i in (A,B,C,D,E):
        min_num=min(i,min_num)
    print(math.ceil(N/min_num)+4)
    
if __name__=="__main__":
    main()
import numpy as np
N, D = map(int, input().split())

X = [[int(i) for i in input().split()] for i in range(N)]

ans = 0
for i in range(N):
    for j in range(i + 1 , N):
        tmp = 0
        for k in range(D):
            tmp += (X[i][k] - X[j][k]) ** 2
        if np.sqrt(tmp) % 1 == 0:
            ans += 1
            
print(ans)

### FIXED CODE ###

import numpy as np
N, D = map(int, input().split())

X = [[int(i) for i in input().split()] for i in range(N)]

ans = 0
for i in range(N):
    for j in range(i + 1 , N):
        tmp = 0
        for k in range(D):
            tmp += (X[i][k] - X[j][k]) ** 2
        if np.sqrt(tmp) % 1 == 0:
            ans += 1
            
print(ans)
N,A,B = map(int,input().split())

if (abs(A-B)==1):
    return min(A,B)
elif: abs(A-B)==2:
    return abs(A-B)-1

### FIXED CODE ###

N,A,B = map(int,input().split())
ans = 0
if (B-A)%2 == 0:
    print(int((B-A)//2))
else:
    print(min(A-1,N-B)+1+int((B-A-1)//2))
N = int(input())
H = input().split()
maxH = H[0]
look = 1
for i in range(N-1):
	if N == 1:
    	print(1)
	elif H[i+1] >= maxH:
    	look = look + 1
    	maxH = H[i+1]
  	else:
    	maxH = maxH
print(look)

### FIXED CODE ###

N = int(input())
H = list(map(int,input().strip().split(" ")))
maxH = H[0]
look = 1
for i in range(N-1):
  if H[i+1] >= maxH:
    look = look + 1
    maxH = H[i+1]
print(look)
a,b=map(int,input().split())
if a*b%2==0:
	print(Even")
else:
    print(Odd")

### FIXED CODE ###

a,b=map(int,input().split())
if a*b%2==0:
	print("Even")
else:
    print("Odd")
n, W = map(int, input().split())
w = []
v = []
for i in range(n):
    w_, v_ = map(int, input().split())
    w.append(w_)
    v.append(v_)

if sum(w) <= W:
    print(sum(v))
else:
    dp = [[0] * (W + 1) for i in range(n + 1)]  # DP テーブル

    for i in range(n - 1, -1, -1):
        for j in range(w[0], W + 1):
            if j < w[i]:
                dp[i][j] = dp[i + 1][j]
            else:
                dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i])

    print(dp[0][W])

### FIXED CODE ###

N, W = map(int, input().split())
w = []
v = []
for i in range(N):
    wi, vi = map(int, input().split())
    w.append(wi)
    v.append(vi)
ww = [w[0], w[0]+1, w[0]+2, w[0]+3]
d = {}
for i in range(4):
    d[ww[i]] = []
for i in range(N):
    d[w[i]].append(v[i])
for i in range(4):
    d[ww[i]] = sorted(d[ww[i]], reverse=True)
    
ans = 0
for i in range(N+1):
    if len(d[ww[0]]) < i:
        # print('break i: {}'.format(i))
        break
    for j in range(N+1):
        if i + j > N or len(d[ww[1]]) < j:
            # print('break i, j: {}, {}'.format(i, j))
            break
        for k in range(N+1):
            if i + j + k > N or len(d[ww[2]]) < k:
                # print('break i, j, k: {}, {}, {}'.format(i, j, k))
                break
            for l in range(N+1):
                # print(ww[0] * i + ww[1] * j + ww[2] * k + ww[3] * l)

                if i + j + k + l > N or\
                        len(d[ww[3]]) < l or\
                        ww[0] * i + ww[1] * j +\
                        ww[2] * k + ww[3] * l > W:
                    # print('break i, j, k: {}, {}, {}, {}'.format(i, j, k, l))
                    break

                av = sum([d[ww[0]][p] for p in range(i)])
                bv = sum([d[ww[1]][p] for p in range(j)])
                cv = sum([d[ww[2]][p] for p in range(k)])
                dv = sum([d[ww[3]][p] for p in range(l)])
                ans = max(ans, av+bv+cv+dv)
print(ans)
h,w=map(int,input().split())

m=[input() for i in range(w)]


cnt=[[1000000 for i in range(h)]for j in range(w)]


if m[0][0]=="#":
    cnt[0][0]=1
else:
    cnt[0][0]=0

for y in range(w):
    for x in range(h):
        if x!=0:
            if m[y][x-1]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1])
        if y!=0:
            if m[y-1][x]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x])


print(cnt[w-1][h-1])

### FIXED CODE ###

h,w=map(int,input().split())

m=[input() for i in range(h)]


cnt=[[1000000 for i in range(w)] for j in range(h)]

if m[0][0]=="#":
    cnt[0][0]=1
else:
    cnt[0][0]=0

for y in range(h):
    for x in range(w):
        if x>0:
            if m[y][x-1]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y][x-1])
        if y>0:
            if m[y-1][x]=="." and m[y][x]=="#":
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x]+1)
            else:
                cnt[y][x]=min(cnt[y][x],cnt[y-1][x])


print(cnt[h-1][w-1])
s = list(1:n)
s = s.lower(k)
print(s)


### FIXED CODE ###

N, K = (int(i) for i in input().split())
S = list(input())

S[K - 1] = S[K - 1].lower()
print(''.join(S))
# 頂点n個 辺iは頂点aiとbiを結ぶ 各頂点には初期値0のカウンターがある
# 操作j: 頂点pjを根とする部分木に含まれるすべてのカウンターにxj足す
# Q回の操作のあと各カウンターの数値を求める

n, q = map(int, input().split())
connect = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    connect[a-1].append(b-1)
    connect[b-1].append(a-1)

count = [0 for _ in range(n)]
for _ in range(q):
    p, x = map(int, input().split())
    count[p-1] += x


def dfs(now=0, prev=-1):
    for i in range(len(connect[now])):
        kid = connect[now][i]
        if kid == prev:
            continue
        count[kid] += count[now]
        dfs(kid, now)


dfs()

for i in range(n):
    print(count[i])


### FIXED CODE ###

# 頂点n個 辺iは頂点aiとbiを結ぶ 各頂点には初期値0のカウンターがある
# 操作j: 頂点pjを根とする部分木に含まれるすべてのカウンターにxj足す
# Q回の操作のあと各カウンターの数値を求める

# 方針: 操作の際に最初に部分木の根にだけ点を加え最後に親の点を子に与えていく
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

n, q = map(int, input().split())
connect = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    connect[a-1].append(b-1)
    connect[b-1].append(a-1)

count = [0 for _ in range(n)]
for _ in range(q):
    p, x = map(int, input().split())
    count[p-1] += x


def dfs(now=0, prev=-1):
    kids = connect[now]
    for kid in kids:
        if kid == prev:
            continue
        count[kid] += count[now]
        dfs(kid, now)


dfs()

for i in range(n):
    print(count[i])
# 出力
# a, b = map(int, input().split())
a = int(input())
b = int(input())

# 処理&出力
if (a + b) / 3 >= 1 :
    print('Possible')
else:
    print('Impossible')

### FIXED CODE ###


# 出力
a, b = map(int, input().split())

# 処理&出力
if (a + b) % 3 == 0:
    print('Possible')
elif a % 3  == 0:
    print('Possible')
elif b % 3 == 0:
    print('Possible')
else:
    print('Impossible')
n = int(raw_input())
A = map(int, raw_input().split())
sorted(A)

q = int(raw_input())
M = map(int, raw_input().split())
sorted(M)

result = []
for i in range(q):
    result.append('no ')

for i in range(n-1):
    sum_n = A[i]
    M_clone = M[:]
    flag = False
    for j in range(n-1-i):
        if flag:
            break
        sum_n += A[i+1+j]
        for k in range(len(M)):
            if M_clone[k] == sum_n:
                result[k] = 'yes '
                M.pop(k)
                flag = True
                break
            elif M_clone[k] < sum_n:
                M_clone.pop(k)

for i in range(q):
    print result[i]

### FIXED CODE ###


n = int(raw_input())
A = map(int, raw_input().split())

q = int(raw_input())
M = map(int, raw_input().split())

result = []
for i in range(q):
    result.append('no')

def adder(axis = 0, nums = [0], M = [0], q = 0):
    for i in range(q):
        if M[i] == axis:
            result[i] = 'yes'
    length = len(nums)
    if length != 0:
        for i in range(length):
            sum_n = axis + nums[i]
            adder(sum_n, nums[i+1:], M, q)

for i in range(n):
    adder(A[i], A[i+1:], M, q)

for i in result:
    print(i)
File Edit Options Buffers Tools Python Help                                                
#!/usr/bin/env python3                                                                     
#run by python3                                                                            

class Node:
    def __init__(self, key):
        self.key = key
        self.right = None
        self.left = None

def insert(T, z): #z is node which you would like to insert                                
        #initialization                                                                    
    y = None #parent of x                                                                  
    x = T

        #search                                                                            
    while(x!=None):
        y = x
        if(z.key < x.key):
            x = x.left
        else:
            x = x.right

        #insert                                                                            
    if(y==None):
	T = z
    elif(z.key < y.key):
        y.left = z
    else:
        y.right = z

    return T


def inorder_walk(node):
    if node.left:
        inorder_walk(node.left)
    print ('', node.key, end='')
    if node.right:
        inorder_walk(node.right)


def preorder_walk(node):
    print ('', node.key,end='')
    if node.left:
        preorder_walk(node.left)
    if node.right:
        preorder_walk(node.right)

if __name__ == '__main__':

    T = None
    num = int(input())

    for _ in range(num):
        cmd = input()
        if(cmd.startswith('i')):
            n = Node(int(cmd[7:]))
            T = insert(T, n)
        else:
            inorder_walk(T)
            print()
            preorder_walk(T)
            print()

### FIXED CODE ###

#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
 
 
class Node(object):
    def __init__(self, key=None):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None
 
 
def tree_insert(top, z):
    y = None
    x = top
    while isinstance(x, Node):
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y
    if y is None:
        top = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z
    return top
 
 
def inorder_walk(node):
    if node.left:
        inorder_walk(node.left)
    print('', node.key, end='')
    if node.right:
        inorder_walk(node.right)
 
 
def preorder_walk(node):
    print('', node.key, end='')
    if node.left:
        preorder_walk(node.left)
    if node.right:
        preorder_walk(node.right)
 
 
n = int(stdin.readline())
 
top = None
for _ in range(n):
    cmd = stdin.readline()
    if cmd.startswith('i'):
        key = int(cmd[7:])
        #assert -2000000000 <= key <= 2000000000
        top = tree_insert(top, Node(key))
    else:
        inorder_walk(top)
        print()
        preorder_walk(top)
        print()
X, N = map(int,input().split())
if N == 0:
    print(X)
    exit()
else:
    P = list(map(int,input().split()))
L = [i for i in range(0,101) if i not in P]

if X in L:
    ANS = X
else:
    L.append(X)
    L = sorted(L)
    n = L.index(X)
    l = len(L)

    if (0 < n < l):
        if (L[n+1]-L[n] < L[n] - L[n-1]):
            ANS = L[n+1]
        else:
            ANS = L[n - 1]
    elif (n == 0):
        ANS = L[1]
    elif (n == l):
        ANS = L[l - 1]

print(ANS)

### FIXED CODE ###

X, N = map(int,input().split())
if N == 0:
    print(X)
    exit()
else:
    P = list(map(int,input().split()))
L = [i for i in range(0,102) if i not in P]

if X in L:
    ANS = X
else:
    L.append(X)
    L = sorted(L)
    n = L.index(X)
    l = len(L) - 1


    if (0 < n < l):
        if (L[n+1]-L[n] < L[n] - L[n-1]):
            ANS = L[n+1]
        else:
            ANS = L[n - 1]
    elif (n == l):
        ANS = L[l - 1]

print(ANS)
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = input()
n = len(s)
snx = []

for i in range(n):
    if s[i] != 'x':
        snx.append(s[i])
ln = len(snx)
for i in range(ln//2):
    if snx[i] != snx[ln-i-1]:
        print(-1)
        quit()

j = 0
if ln%2:
    for l in range(n):
        if s[l] == snx[j]:
            j += 1
            if j >= ln//2+1:  
                break
    print(n-l-l-1)
else:
    for l in range(n):
        if s[l] == snx[j]:
            j += 1
            if j >= ln//2:  
                break 
    j = ln-1
    for r in range(n)[::-1]:
        if s[r] == snx[j]:
            j -= 1
            if j <= ln//2-1:
                break

    print(abs(n-r-l-1))

### FIXED CODE ###

from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = input()
n = len(s)
l = 0
r = n-1
res = 0
while l < r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    elif s[l] == 'x':
        res += 1
        l += 1
    elif s[r] == 'x':
        res += 1
        r -= 1
    else:
        print(-1)
        break
else:
    print(res)
from heapq import *
n, m = map(int, input().split())
pay = []
for _ in range(n):
    a, b = map(int, input().split())
    pay.append((a, b))
pay = sorted(pay, reverse=True)
print(pay)
q = []
ans = 0
for i in range(1, m+1):
    while pay and pay[-1][0] <= i:
        a, b = pay.pop()
        heappush(q, -b)
    print(q)
    if q:
        b = -heappop(q)
        ans += b
print(ans)

### FIXED CODE ###

from heapq import *
n, m = map(int, input().split())
pay = []
for _ in range(n):
    a, b = map(int, input().split())
    pay.append((a, b))
pay = sorted(pay, reverse=True)
q = []
ans = 0
for i in range(1, m+1):
    while pay and pay[-1][0] <= i:
        a, b = pay.pop()
        heappush(q, -b)
    if q:
        b = -heappop(q)
        ans += b
print(ans)
import math
from functools import reduce


def gcd_list(numbers):
    return reduce(math.gcd, numbers)
n,x=map(int,input().split())
l=[abs(c-x) for c in list(map(int,input().split()))]
del l[l.index(0)]
print(gcd_list(l) if len(l)>1 else l[0])

### FIXED CODE ###

def gcd(a,b):
        while b:
            a,b=b,a%b
        return a
def solve(lis,x):
    if len(lis)==1:
        return abs(lis[0]-x)
    lis=[abs(c-x) for c in lis]
    ans=gcd(lis[0],lis[1])
    for x in lis[2:]:
        if x!=0:
            ans=gcd(ans,x)
    return ans 
n,x=map(int,input().split())
l=list(map(int,input().split()))
print(solve(l,x))
n,k = map(int, input().split())
p=k
for i in range(n-1):
  p *= k-1
print(p)
  

### FIXED CODE ###

paint = map(int,input().split())
print(len(set(paint)))
k,X=list(map(int,input().split()))
if(K*500>=X):
  print('Yes')
else:
  print('No')

### FIXED CODE ###

K,X=list(map(int,input().split()))
if(K*500>=X):
  print('Yes')
else:
  print('No')
n = int(input())
a = list(map(int, input().split()))
alist = [0]*n

for i in range(1, n+1):
    alist[a[i]-1] =str(i+1)

print(" ".join(alist))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
alist = [0]*n

for i in range(n):
    alist[a[i]-1] = str(i+1)

print(" ".join(alist))
n, k=map(int, input().split());print(0 if n%k==o else 1)

### FIXED CODE ###

n, k=map(int, input().split());print(0 if n%k==0 else 1)
import heapq
from collections import defaultdict
N = int(input())
nums  = list(map(int, input().split(" ")))
# 正の数、負の数の個数で操作をコントロール？
p_count = 0
m_count = 0
pos = []
minus = []
for num in nums:
    if num < 0:
        m_count += 1
        minus.append(num)
    else:
        p_count += 1
        pos.append(num)
pos.sort()
minus.sort() #小さい順番
途中式 = []
if N == 2:
    print(max(nums) - min(nums))
else:
    #正の数を一つにして、そこから引きまくる
    if m_count == 0: #マイナスが無かったら作る
        x = min(pos)
        y = max(pos)
        途中式.append((x, y))
        minus.append(x - y)
        pos.remove(x)
        pos.remove(y)
        p_count -=2
        m_count += 1

    if p_count > 1: # 正が複数あったら、マイナスから引くことで減らしていく
        for i in range(p_count - 1):
            #マイナスから正が1個になるまで引いていく
            x = minus.pop()
            y = pos.pop()
            途中式.append((x,y))
            minus.append(x- y)
    elif p_count == 0 : #正が一つも無かったら、作る
        x = minus.pop()
        y = minus.pop()
        途中式.append((x, y))
        pos.append(x - y)

    x = pos.pop()
    for i in minus:
        y = i
        途中式.append((x, y))
        x -=y
print(x)
for temp in 途中式:
    x,y = temp
    print(x,y)

### FIXED CODE ###

import heapq
from collections import defaultdict
N = int(input())
nums  = list(map(int, input().split(" ")))
# 正の数、負の数の個数で操作をコントロール？
p_count = 0
m_count = 0
pos = []
minus = []
for num in nums:
    if num < 0:
        m_count += 1
        minus.append(num)
    else:
        p_count += 1
        pos.append(num)
pos.sort()
minus.sort() #小さい順番
途中式 = []
if N == 2:
    x = max(nums) 
    y = min(nums)
    print(max(nums) - min(nums))
    print(x, y)
else:
    #正の数を一つにして、そこから引きまくる
    if m_count == 0: #マイナスが無かったら作る
        x = min(pos)
        y = max(pos)
        途中式.append((x, y))
        minus.append(x - y)
        pos.remove(x)
        pos.remove(y)
        p_count -=2
        m_count += 1

    if p_count > 1: # 正が複数あったら、マイナスから引くことで減らしていく
        for i in range(p_count - 1):
            #マイナスから正が1個になるまで引いていく
            x = minus.pop()
            y = pos.pop()
            途中式.append((x,y))
            minus.append(x- y)
    elif p_count == 0 : #正が一つも無かったら、作る
        x = minus.pop()
        y = minus.pop()
        途中式.append((x, y))
        pos.append(x - y)

    x = pos.pop()
    for i in minus:
        y = i
        途中式.append((x, y))
        x -=y
    print(x)
    for temp in 途中式:
        x,y = temp
        print(x,y)
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)


### FIXED 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, 1<<10):
    store = {lll : 0 for lll in range(10)}
    k = "0" * (10 - len(bin(i)) + 2) + bin(i)[2:]
    calc = 0
    for nn in range(n):
        count = 0
        for j, kk in enumerate(k):
            if kk == "1":
                if f[nn][j] == 1:
                    count += 1
        calc += p[nn][count]
    ans = max(ans, calc)
print(ans)