CodeEff/ECCO huggingface dataset:
# Original solution
import sys

s = str(sys.stdin.readline())
o = len(s)
for i in range(1000000000000):
    p1 = s.find("01")
    p2 = s.find("10")
    if p1 == -1 and p2 == -1:
        break
    elif p1 == -1:
        i = p2
    elif p2 == -1:
        i = p1
    else:
        i = p1 if p1 < p2 else p2

    s = s[:i] + s[i + 2:]
    
print((o - len(s)))

# Optimized solution
import sys

s = str(sys.stdin.readline())
c0 = s.count('0')
c1 = s.count('1')
r = c0 if c0 < c1 else c1
print((r*2))
# Original solution
l = input().split()
s = l[0]

def get_removals(s):
    ret = []
    for i in range(len(s) - 1):
        if int(s[i]) + int(s[i + 1]) == 1:
            ret.append(i)
    return ret

def remove(s, index):
    if index == 0:
        return s[2:]
    if index == (len(s) - 1):
        return s[:index-1]
    return  s[0:index] + s[index + 2:]

num_removals = []

ones = 0
zeros = 0
for num in s:
    if num == '0':
        ones += 1
    if num == '1':
        zeros += 1
max_candidate = min(ones, zeros) * 2

def process(s, count):
    removals = get_removals(s)
    if len(removals) == 0:
        num_removals.append(count)
        if count == max_candidate:
            print(max_candidate)
            exit()
        return
    count += 2
    max_remove = 0
    ss = []
    for removal in removals:
        s1 = remove(s, removal)
        ss.append(s1)
        num_removes = len(get_removals(s1))
        if max_remove < num_removes:
            max_remove = num_removes
    for s1 in set(ss):
        if len(get_removals(s1)) == max_remove:
            process(s1, count)

process(s, 0)
print((max(num_removals)))


# Optimized solution
l = input().split()
s = l[0]

def get_removals(s):
    ret = []
    for i in range(len(s) - 1):
        if int(s[i]) + int(s[i + 1]) == 1:
            ret.append(i)
    return ret

def remove(s, index):
    if index == 0:
        return s[2:]
    if index == (len(s) - 1):
        return s[:index-1]
    return  s[0:index] + s[index + 2:]

num_removals = []

ones = 0
zeros = 0
for num in s:
    if num == '0':
        ones += 1
    if num == '1':
        zeros += 1
max_candidate = min(ones, zeros) * 2

def process(s, count):
    removals = get_removals(s)
    if len(removals) == 0:
        num_removals.append(count)
        if count == max_candidate:
            print(max_candidate)
            exit()
        return
    count += 2
    max_remove = 0
    ss = []
    for removal in removals:
        s1 = remove(s, removal)
        ss.append(s1)
        num_removes = len(get_removals(s1))
        if max_remove < num_removes:
            max_remove = num_removes
    for s1 in set(ss):
        if len(get_removals(s1)) == max_remove:
            process(s1, count)

# process(s, 0)
print(max_candidate)
# Original solution
import copy

s = input().split()[0]

def get_kouho_list(box_list):
    kouho_list = []
    for i, color in enumerate(box_list[:-1]):
        if box_list[i] != box_list[i+1]:
            kouho_list.append((i, i+1))
    return kouho_list

def tansaku(now_box_list, koremade_step):
    kouho_list = get_kouho_list(now_box_list)
    for kouho in kouho_list:
        next_box_list = copy.copy(now_box_list)
        del next_box_list[kouho[0]:kouho[1]+1]
        tansaku(next_box_list, koremade_step + 1)
    global max_step
    if koremade_step > max_step:
        max_step = koremade_step
    return

max_step = 0
tansaku(list(s), 0)
print((max_step * 2))


# Optimized solution
import collections

s = input().split()[0]

counter = collections.Counter(list(s))
c_0 = counter['0']
c_1 = counter['1']
step = min(c_0, c_1)
print((step * 2))
# Original solution
from sys import stdin
import re

S = stdin.readline().rstrip()

before_S = S

while(True):
    #after_S = S.replace("01", "").replace("10", "")
    after_S = re.sub("(01)+|(10)+", "", S)
    if len(after_S) != len(S):
        S = after_S
    else:
        break

print((len(before_S) - len(S)))

# Optimized solution
from sys import stdin

S = stdin.readline().rstrip()

stack = []
count = 0

for s in S:
    # スタックが空なら
    if not stack:
        stack.append(s)
    # スタックの一番上がsでなければ
    elif stack[-1] != s:
        stack.pop()
        count += 2
    else:
        stack.append(s)

print(count)
# Original solution
from itertools import chain


def f(s):
    l = s.split('01')
    for i in range(len(l)):
        l[i] = l[i].split('10')
    l = list(chain.from_iterable(l))
    return l


s = input().rstrip()

count = 0
while True:
    l = f(s)
    if len(l) == 1:
        break
    count += (len(l) - 1) * 2
    s = ''.join(l)

print(count)


# Optimized solution
s = input().rstrip()

print((2 * min(s.count('0'), s.count('1'))))
# Original solution
class Dice:
    def __init__(self, labels):
        self.labels = labels
    def east(self):
        self.labels[1], self.labels[2], self.labels[3], self.labels[4] = self.labels[3], self.labels[1], self.labels[4], self.labels[2]
    def west(self):
        self.labels[1], self.labels[2], self.labels[3], self.labels[4] = self.labels[2], self.labels[4], self.labels[1], self.labels[3]
    def north(self):
        self.labels[0], self.labels[1], self.labels[4], self.labels[5] = self.labels[1], self.labels[5], self.labels[0], self.labels[4]
    def south(self):
        self.labels[0], self.labels[1], self.labels[4], self.labels[5] = self.labels[4], self.labels[0], self.labels[5], self.labels[1]
    
    def clockwise(self):
        self.labels[1], self.labels[2], self.labels[4], self.labels[3] = self.labels[2], self.labels[4], self.labels[3], self.labels[1]

dice = Dice(list(map(int, input().split())))

for n in range(int(eval(input()))):
    top, foward = list(map(int, input().split()))
    south_cnt = 0

    while True:
        if foward == dice.labels[1] and top == dice.labels[0]:
            break
        if foward == dice.labels[1]:
            dice.east()
        elif top == dice.labels[0]:
            dice.clockwise()
        else:
            if south_cnt == 3:
                dice.east()
            else:
                dice.south()
                south_cnt += 1
    print((dice.labels[2]))




# Optimized solution
class Dice:
    def __init__(self, labels):
        self.labels = labels
    def east(self):
        self.labels[0], self.labels[2], self.labels[5], self.labels[3] = self.labels[3], self.labels[0], self.labels[2], self.labels[5]
    def west(self):
        self.labels[0], self.labels[2], self.labels[5], self.labels[3] = self.labels[2], self.labels[5], self.labels[3], self.labels[0]
    def north(self):
        self.labels[0], self.labels[1], self.labels[5], self.labels[4] = self.labels[1], self.labels[5], self.labels[4], self.labels[0]
    def south(self):
        self.labels[0], self.labels[1], self.labels[5], self.labels[4] = self.labels[4], self.labels[0], self.labels[1], self.labels[5]

dice = Dice(list(map(int, input().split())))

for n in range(int(eval(input()))):
    top, foward = list(map(int, input().split()))
    south_cnt = 0

    while True:
        #print(dice.labels[0], dice.labels[1], dice.labels[2], dice.labels[4], dice.labels[3])
        if foward == dice.labels[1] and top == dice.labels[0]:
            break
        if foward == dice.labels[1]:
            dice.east()
        elif top == dice.labels[0]:
            dice.south()
            dice.east()
            dice.north()
        else:
            if south_cnt == 3:
                dice.east()
            else:
                dice.south()
                south_cnt += 1
    print((dice.labels[2]))
# Original solution
class Dice:

    def __init__(self):
        # 初期値がない場合
        # 上, 南、東、西、北、下にそれぞれ1, 2, 3, 4, 5, 6がくる想定
        self.t = 1
        self.s = 2
        self.e = 3
        self.w = 4
        self.n = 5
        self.b = 6
        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def __init__(self, t, s, e, w, n, b):
        # 初期値が指定される場合
        self.t = t
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.b = b
        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def rot(self, way):
        if way == 0:
            self.t, self.s, self.e, self.w, self.n, self.b = self.n, self.t, self.e, self.w, self.b, self.s
        elif way == 1:
            self.t, self.s, self.e, self.w, self.n, self.b = self.s, self.b, self.e, self.w, self.t, self.n
        elif way == 2:
            self.t, self.s, self.e, self.w, self.n, self.b = self.w, self.s, self.t, self.b, self.n, self.e
        elif way == 3:
            self.t, self.s, self.e, self.w, self.n, self.b = self.e, self.s, self.b, self.t, self.n, self.w
        
        
def main():
    import random

    t,s,e,w,n,b = list(map(int, input().split()))
    dice2 = Dice(t,s,e,w,n,b)
    q = int(eval(input()))
    for _ in range(q):
        top, front = list(map(int, input().split()))
        while True:
            if dice2.t == top and dice2.s == front:
                break
            else:
                seed = random.randint(0, 3)
                dice2.rot(seed)
        print((dice2.e))



if __name__ == '__main__':
    main()



# Optimized solution
rot_set = [
    (1,2,4,3,1), #0
    (0,3,5,2,0), #1
    (0,1,5,4,0), #2
    (0,4,5,1,0), #3
    (0,2,5,3,0), #4
    (1,3,4,2,1)  #5
]

dice_int = list(map(int, input().split()))
q = int(eval(input()))
right_face = []

for _ in range(q):
    a, b = list(map(int, input().split()))
    a_idx = dice_int.index(a)
    b_idx = dice_int.index(b)

    for i in range(6):
        for j in range(4):
            if (a_idx, b_idx) == (rot_set[i][j], rot_set[i][j+1]):
                right_face.append(dice_int[i])

for i in range(q):
    print((right_face[i]))
# Original solution
# coding: utf-8
# ?????????????????¨????????????
class Dice(object):
	def __init__(self):
		# ????????¶???
		self.dice = (2, 5), (3, 4), (1, 6) # x, y, z
		self.ax = [[0, False], [1, False], [2, False]]
		self.axmap = [0, 1, 2]
		self.mm = {"N": (0, 2), "S": (2, 0), "E": (1, 2), "W": (2, 1), "R": (0, 1), "L": (1, 0)}

	def rotate(self, dir):
		def rot(k, r):
			t = self.axmap[r]
			self.axmap[k], self.axmap[r] = t, self.axmap[k]
			self.ax[t][1] = not self.ax[t][1]

		rot(*self.mm[dir])

	def front(self): return self.value(0, True)
	def rear(self): return self.value(0, False)
	def right(self): return self.value(1, True)
	def left(self): return self.value(1, False)
	def top(self): return self.value(2, True)
	def bottom(self): return self.value(2, False)
	def value(self, ax, d):
		a = self.ax[self.axmap[ax]]
		return self.dice[a[0]][a[1] if d else not a[1]]

if __name__=="__main__":
	dice = Dice()
	labels = input().split()
	q = int(eval(input()))
	def tf(p, f, d):
		for _ in range(4):
			if p==f(): break
			dice.rotate(d)

	for _ in range(q):
		a, b = input().split()
		p = labels.index(a) + 1
		f = dice.top
		tf(p, f, "N")
		tf(p, f, "E")
		
		p = labels.index(b) + 1
		f = dice.front
		tf(p, f, "R")

		print((labels[dice.right()-1]))

# Optimized solution
# coding: utf-8
# ?????????????????¨????????????
class Dice(object):
	def __init__(self):
		# ????????¶???
		self.dice = (2, 5), (3, 4), (1, 6) # x, y, z
		self.ax = [[0, False], [1, False], [2, False]]
		self.axmap = [0, 1, 2]
		self.mm = {"N": (0, 2), "S": (2, 0), "E": (1, 2), "W": (2, 1), "R": (0, 1), "L": (1, 0)}

	def rotate(self, dir):
		def rot(k, r):
			t = self.axmap[r]
			self.axmap[k], self.axmap[r] = t, self.axmap[k]
			self.ax[t][1] = not self.ax[t][1]

		rot(*self.mm[dir])

	def front(self): return self.value(0, True)
	def rear(self): return self.value(0, False)
	def right(self): return self.value(1, True)
	def left(self): return self.value(1, False)
	def top(self): return self.value(2, True)
	def bottom(self): return self.value(2, False)
	def value(self, ax, d):
		a = self.ax[self.axmap[ax]]
		return self.dice[a[0]][a[1] if d else not a[1]]

if __name__=="__main__":
	dice = Dice()
	labels = input().split()
	q = int(eval(input()))
	def tf(p, f, d):
		for _ in range(4):
			if p==f(): break
			dice.rotate(d)

	for _ in range(q):
		a, b = input().split()
		p = labels.index(a) + 1
		f = dice.top
		tf(p, f, "N")
		if p!=f(): tf(p, f, "E")
		
		p = labels.index(b) + 1
		f = dice.front
		tf(p, f, "R")

		print((labels[dice.right()-1]))
# Original solution
# 2019-11-17 20:44:23(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 


def main():
    s, t = sys.stdin.read().split()

    count = 0
    for i in range(3):
        if s[i] == t[i]:
            count += 1
    print(count)


if __name__ == "__main__":
    main()


# Optimized solution
import sys

s, t = sys.stdin.read().split()

def main():
    cnt = 0
    for i in range(3):
        if s[i] == t[i]:
            cnt += 1
    return cnt
    
if __name__ == '__main__':
    ans = main()
    print(ans)
# Original solution
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return list(map(fn, readline().split()))


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    s = gete()
    t = gete()
    ans = 0
    for i in range(len(s)):
        if s[i] == t[i]:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()

# Optimized solution
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return list(map(fn, readline().split()))


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    s = gete()
    t = gete()

    ans = 0
    for i in range(3):
        if s[i] == t[i]: ans += 1

    print(ans)

if __name__ == "__main__":
    main()
# Original solution
import queue

nv, ne = map(int, input().split(' '))
in_degrees = [[] for _ in range(nv)]
q = queue.Queue()
o = []

for _ in range(ne):
    s, t = map(int, input().split(' '))
    in_degrees[t].append(s)

for i in range(nv):
    if len(in_degrees[i]) == 0: q.put(i)

while not q.empty():
    v = q.get()
    o.append(v)

    for i in range(nv):
        if v in in_degrees[i]:
            in_degrees[i].remove(v)
            if len(in_degrees[i]) == 0: q.put(i)

[print(v) for v in o]


# Optimized solution
import queue

nv, ne = map(int, input().split(' '))
in_degs = [0] * nv
q = queue.Queue()
outs = {}
o = []

for _ in range(ne):
    s, t = map(int, input().split(' '))

    if s in outs: outs[s].append(t)
    else: outs[s] = [t]

    in_degs[t] += 1

for i in range(nv):
    if in_degs[i] == 0: q.put(i)

while not q.empty():
    v = q.get()
    o.append(v)

    if v in outs:
        for out in outs[v]:
            in_degs[out] -= 1
            if in_degs[out] == 0: q.put(out)

[print(v) for v in o]
# Original solution
import queue

nv, ne = map(int, input().split(' '))
in_degs = [0] * nv
q = queue.Queue()
outs = {}
o = []

for _ in range(ne):
    s, t = map(int, input().split(' '))

    if s in outs: outs[s].append(t)
    else: outs[s] = [t]

    in_degs[t] += 1

for i in range(nv):
    if in_degs[i] == 0: q.put(i)

while not q.empty():
    v = q.get()
    o.append(v)

    if v in outs:
        for out in outs[v]:
            in_degs[out] -= 1
            if in_degs[out] == 0: q.put(out)

[print(v) for v in o]


# Optimized solution
nv, ne = map(int, input().split(' '))
in_degs = [0] * nv
q = []
outs = {}
o = []

for _ in range(ne):
    s, t = map(int, input().split(' '))

    if s in outs: outs[s].append(t)
    else: outs[s] = [t]

    in_degs[t] += 1

for i in range(nv):
    if in_degs[i] == 0: q.append(i)

while len(q) > 0:
    v = q.pop(0)
    o.append(v)

    if v in outs:
        for out in outs[v]:
            in_degs[out] -= 1
            if in_degs[out] == 0: q.append(out)

[print(v) for v in o]
# Original solution
nv, ne = map(int, input().split(' '))
in_degs = [0] * nv
q = []
outs = {}
o = []

for _ in range(ne):
    s, t = map(int, input().split(' '))

    if s in outs: outs[s].append(t)
    else: outs[s] = [t]

    in_degs[t] += 1

for i in range(nv):
    if in_degs[i] == 0: q.append(i)

while len(q) > 0:
    v = q.pop(0)
    o.append(v)

    if v in outs:
        for out in outs[v]:
            in_degs[out] -= 1
            if in_degs[out] == 0: q.append(out)

[print(v) for v in o]


# Optimized solution
nv, ne = map(int, input().split(' '))
in_degs = [0] * nv
q = []
outs = {}
o = []

for _ in range(ne):
    s, t = map(int, input().split(' '))

    if s in outs: outs[s].append(t)
    else: outs[s] = [t]

    in_degs[t] += 1

for i in range(nv):
    if in_degs[i] == 0: q.append(i)

while q:
    v = q.pop(0)
    o.append(v)

    if v in outs:
        for out in outs[v]:
            in_degs[out] -= 1
            if in_degs[out] == 0: q.append(out)

[print(v) for v in o]
# Original solution
def bfs(s):
    que = [s]
    used[s] = True
    while que:
        u = que.pop(0)
        ans.append(u)

        for v in G[u]:
            indeg[v] -= 1
            if indeg[v] == 0 and not used[v]:
                used[v] = True
                que.append(v)

def tsort():
    for u in range(V):
        if indeg[u] == 0 and not used[u]:
            bfs(u)

V, E = list(map(int, input().split()))
indeg = [0] * V
used = [False] * V
G = [[] for i in range(V)]
ans = []

for i in range(E):
    s, t = list(map(int, input().split()))
    indeg[t] += 1
    G[s].append(t)

tsort()
for i in ans:
    print(i)

# Optimized solution
def tsort(G):
    def bfs(s):
        que = [s]
        used[s] = True
        while que:
            u = que.pop(0)
            res.append(u)

            for v in G[u]:
                indeg[v] -= 1
                if indeg[v] == 0 and not used[v]:
                    used[v] = True
                    que.append(v)

    indeg = [0] * V
    used = [False] * V
    res = []
    for u in range(V):
        for v in G[u]:
            indeg[v] += 1
    for u in range(V):
        if indeg[u] == 0 and not used[u]:
            bfs(u)
    return res


V, E = list(map(int, input().split()))
G = [[] for i in range(V)]
for i in range(E):
    s, t = list(map(int, input().split()))
    G[s].append(t)

ans = tsort(G)
for i in ans:
    print(i)
# Original solution
#!/usr/bin/env python3
# ????????????????????°???????????°????????????????????\??????????????¢?????´???????????¨??????????§???????

import array
import collections


class TopologicalSortError(Exception):
    pass


def topological_sort(num_vs, adj_vs):
    in_deg = array.array("L", (0 for _ in range(num_vs)))
    for dests in adj_vs:
        for dest in dests:
            in_deg[dest] += 1
    visited = array.array("B", (False for _ in range(num_vs)))
    sorted_vs = array.array("L")
    for s in range(num_vs):
        if in_deg[s] == 0 and not visited[s]:
            q = collections.deque()
            q.append(s)
            visited[s] = True
            while q:
                u = q.popleft()
                sorted_vs.append(u)
                for v in adj_vs[u]:
                    in_deg[v] -= 1
                    if in_deg[v] == 0 and not visited[v]:
                        visited[v] = True
                        q.append(v)
    if all(x == 0 for x in in_deg):
        return sorted_vs
    else:
        raise TopologicalSortError("The graph has a cycle")


def main():
    v, e = list(map(int, input().split()))
    adj_vs = [set() for _ in range(v)]
    for _ in range(e):
        s, t = list(map(int, input().split()))
        adj_vs[s].add(t)
    for u in topological_sort(v, adj_vs):
        print(u)


if __name__ == '__main__':
    main()

# Optimized solution
#!/usr/bin/env python3

import array
import heapq


def topological_sort(num_vs, adj_vs):
    """ Performs topological sorting of the given DAG.

    This function computes the lexicographically least
    topological order of the given DAG.

    :param num_vs int: The number of vertices.
    :param adj_vs list: The adjacency list.
    :return: The lexicographically least topological order.
    :rtype: :obj:`array.array`
    :raises TopologicalSortError: if the given graph is not a DAG
    """
    in_deg = array.array("L", (0 for _ in range(num_vs)))
    for dests in adj_vs:
        for dest in dests:
            in_deg[dest] += 1
    sorted_vs = array.array("L")
    pq = []
    for s in range(num_vs):
        if in_deg[s] == 0:
            heapq.heappush(pq, s)
    while pq:
        u = heapq.heappop(pq)
        sorted_vs.append(u)
        for v in adj_vs[u]:
            in_deg[v] -= 1
            if in_deg[v] == 0:
                heapq.heappush(pq, v)
    if all(x == 0 for x in in_deg):
        return sorted_vs
    else:
        raise TopologicalSortError("The graph has a cycle")


def main():
    v, e = list(map(int, input().split()))
    adj_vs = [set() for _ in range(v)]
    for _ in range(e):
        s, t = list(map(int, input().split()))
        adj_vs[s].add(t)
    for u in topological_sort(v, adj_vs):
        print(u)


if __name__ == '__main__':
    main()
# Original solution
#!/usr/bin/env python3
import itertools

def main():
    N = int(eval(input()))
    F = [list(map(int,input().split())) for _ in range(N)]
    P = [list(map(int,input().split())) for _ in range(N)]
    bit_list = list(itertools.product([0, 1], repeat=10))
    bit_list.pop(0)
    answer = -10**9-1
    for b in bit_list:
        profit = 0
        for i in range(N):
            a = 0 ## 一致してる営業時間の数
            for j in range(10):
                if b[j]==1 and F[i][j]==1:
                    a+=1
            profit+=P[i][a]

        answer = max(answer,profit)

    print(answer)
    return 

if __name__ == '__main__':
    main()



# Optimized solution
#!/usr/bin/env python3
import itertools

def main():
    N = int(eval(input()))
    F = [int(input().replace(' ',''),2) for _ in range(N)]
    P = [list(map(int,input().split())) for _ in range(N)]
    answer = -float('inf')

    for bit in range(1,1<<10):
        tmp_profit = 0
        for i in range(N):
            count = format(bit&F[i],'b').count("1")
            tmp_profit += P[i][count]
        answer = max(answer,tmp_profit)
    print(answer)
    return 

if __name__ == '__main__':
    main()
# Original solution
#from collections import Counter
N=int(eval(input()))
F=list(list(map(int,input().split())) for i in range(N))
P=list(list(map(int,input().split())) for i in range(N))
ans=-(1<<40)
for bit in range(1,1<<10):
    tmp = 0
    for i in range(N):
        c=0
        for j in range(10):
            if bit&(1<<j) and F[i][j]:
                c+=1
        tmp+=P[i][c]
    ans = max(ans,tmp)
print(ans)

# Optimized solution
#from collections import Counter
N=int(eval(input()))
F=list(int(input().replace(" ",""),2) for i in range(N))
P=list(list(map(int,input().split())) for i in range(N))
ans=-(1<<40)
for bit in range(1,1<<10):
    tmp = 0
    for i in range(N):
        tmp+=P[i][bin(bit&F[i]).count('1')]
    ans = max(ans,tmp)
print(ans)
# Original solution
N=int(eval(input()))
H=['']*N
W=['']*N
x=[]
for i in range(N):
    H[i]=list(map(int,input().split()))
for j in range(N):
    W[j]=list(map(int,input().split()))
for k in range(1,1024):
    t=[]
    for ii in range(10):
        if k&(1<<ii):
            t+=[1]
        else:
            t+=[0]
    ans=0
    for jj in range(N):
        s=0
        for kk in range(10):
            s+=H[jj][kk]*t[kk]
        ans+=W[jj][s]
    x.append(ans)
print((max(x)))    

# Optimized solution
N=int(eval(input()))
ans=-10**9
s=["".join(list(input().split())) for i in range(N)]
t=[list(map(int,input().split())) for i in range(N)]
for j in range(1,1024):
    q=0
    for i in range(len(s)):
        q+=t[i][(bin(int(s[i],2)&j)).count("1")]
    ans=max(ans,q)
print(ans)