Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = sorted(list(map(int,input().split())))
print(int(n[0]*n[1]/2))

Fixed submission:
s = input()
print(s[0]+str(len(s)-2)+s[-1])
Buggy python submission (verdict: Runtime Error):
O,E = map(lambda x: [x2 for x2 in x],input().split())
if len(O) - len(E) == 1:
  E.append("")
print("".join([o+e for o,e in zip(O,E)]))

Fixed submission:
from sys import stdin
O,E = map(lambda x: [x2 for x2 in x],stdin.read().splitlines())
if len(O) - len(E) == 1:
  E.append("")
print("".join([o+e for o,e in zip(O,E)]))

Buggy python submission (verdict: Runtime Error):
O,E = map(lambda x: [x2 for x2 in x],input().split())
if len(O) - len(E) == 1:
  E.append("")
print("".join([o+e for o,e in zip(O,E)]))
  

Fixed submission:
from sys import stdin
O,E = map(lambda x: [x2 for x2 in x],stdin.read().splitlines())
if len(O) - len(E) == 1:
  E.append("")
print("".join([o+e for o,e in zip(O,E)]))
Buggy python submission (verdict: Runtime Error):
print(input().replace(/,/g," "))

Fixed submission:
print(input().replace(","," "))
Buggy python submission (verdict: Runtime Error):
A,s,C = input.split()
print(A[0]+s[0]+C[0])

Fixed submission:
A,B,C = tuple(input().split())
print("A"+B[0]+"C")
Buggy python submission (verdict: Runtime Error):
a, b, c = str(input()).split()

if a * b < c:
    print(a * b)
else:
    print(c)

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

if a * b < c:
    print(a * b)
else:
    print(c)
Buggy python submission (verdict: Runtime Error):
import numpy as np

n, d = map(int, input().split())
s = [np.asarray(list(map(int,list(input())))) for i in range(n)]

counter = 0

for i in range(n):
    for j in range(n):
        ans = np.sum((s[i] - s[j]) ** 2)
        if ans == int(ans):
            counter += 1

print(counter)

Fixed submission:
import numpy as np

n, d = map(int, input().split())
s = [np.asarray(list(map(int, input().split()))) for i in range(n)]

counter = 0

for i in range(n):
    for j in range(i+1, n):
        ans = np.sqrt(np.sum((s[i] - s[j]) ** 2))
        if ans == int(ans):
            counter += 1

print(counter)
Buggy python submission (verdict: Time Limit Exceeded):
l, r = map(int, input().split())

if l > r:
    l, r = r, l

mod = 2020

for i in range(l, r+1):
    for j in range(i+1, r+1):
        tmp = i * j % 2019
        if tmp < mod:
            mod = tmp
            if mod == 0:
                break
print(mod)

Fixed submission:
l, r = map(int, input().split())

mod = 2018

if r - l >= 2019:
    print(0)
else:
    for i in range(l, r):
        for j in range(i+1, r+1):
            tmp = i * j % 2019
            if tmp < mod:
                mod = tmp
    print(mod)

Buggy python submission (verdict: Time Limit Exceeded):
l, r = map(int, input().split())

if l > r:
    l, r = r, l

mod = 2020

for i in range(l, r+1):
    for j in range(i+1, r+1):
        tmp = i * j % 2019
        if tmp < mod:
            mod = tmp

print(mod)

Fixed submission:
l, r = map(int, input().split())

mod = 2018

if r - l >= 2019:
    print(0)
else:
    for i in range(l, r):
        for j in range(i+1, r+1):
            tmp = i * j % 2019
            if tmp < mod:
                mod = tmp
    print(mod)
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = map(int, input().split())

count = 0

for i in range(1, n-1):
    if sorted(p[i-1:i+1]).index(p[i]) == 1:
        count += 1

print(count)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))

count = 0

for i in range(1, n-1):
    if sorted(p[i-1:i+2]).index(p[i]) == 1:
        count += 1

print(count)
Buggy python submission (verdict: Runtime Error):
import numpy as np

# S = list(input())
n, l = list(map(int, input().split()))

RINGO = list(np.array(list(range(1, n+1))) + l - 1)
AJI = list(map(abs, RINGO))

if min(AJI) <= len(RINGO):
    RINGO.remove(min(AJI))
else:
    RINGO = []

print(sum(RINGO))


Fixed submission:
import numpy as np

# S = list(input())
n, l = list(map(int, input().split()))

RINGO = list(np.array(list(range(1, n+1))) + l - 1)
AJI = list(map(abs, RINGO))

RINGO.pop(AJI.index(min(AJI)))
print(sum(RINGO))

Buggy python submission (verdict: Runtime Error):
import numpy as np

# S = list(input())
n, l = list(map(int, input().split()))

RINGO = list(np.array(list(range(1, n+1))) + l - 1)
AJI = list(map(abs, RINGO))

RINGO.remove(min(AJI))
print(sum(RINGO))


Fixed submission:
import numpy as np

# S = list(input())
n, l = list(map(int, input().split()))

RINGO = list(np.array(list(range(1, n+1))) + l - 1)
AJI = list(map(abs, RINGO))

RINGO.pop(AJI.index(min(AJI)))
print(sum(RINGO))
Buggy python submission (verdict: Runtime Error):
n = int(input())
# a, p = list(map(int, input().split()))
# a = list(map(int, input().split()))
# S = [list(map(int, input().split())) for i in range(n)]
S = [list(input().split()) for i in range(n)]

# for i, s in enumerate(S):
#     s.append(i+1)

S = sorted(S, key=lambda x: x[1], reverse=True)
S = sorted(S, key=lambda x: x[0], reverse=False)

for s, p, n in S:
    print(n)

Fixed submission:
n = int(input())
# a, p = list(map(int, input().split()))
# a = list(map(int, input().split()))
# S = [list(map(int, input().split())) for i in range(n)]
S = [list(input().split()) for i in range(n)]

for i, s in enumerate(S):
    s.append(i+1)

S = sorted(S, key=lambda x: int(x[1]), reverse=True)
S = sorted(S, key=lambda x: x[0], reverse=False)

for s, p, n in S:
    print(n)
Buggy python submission (verdict: Runtime Error):
n = int(input())
P_list = list(map(int,(input().split(" "))))
#print(P_list)
count = 0
i = 0
for i in range(n-2):
    if P_list[i] > P_list[i+1] > P_list[i+2] or P_list[i] < P_list[i+1] < P_list[i+2]:
        count = count + 1

#print(n)
#print(P_list)
print(count)


Fixed submission:
#４文字の文字列Sが二種類で2回ずつ現れる判定
S = input()
S_list = set(list(S))
#print(S_list)




if len(S_list) == 2:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

IS = lambda: int(input())
IA = lambda: [int(x) for x in input().split()]

N = IS()
A = IA()

h = N//2
ans = []
for i,_ in enumerate(range(N)):
    t = 0
    s = 1
    for j in range(h):
        t += s * (A[(i+j) % N] + A[i-1-j])
        s *= -1
    t += s * A[(i+h) % N]
    ans.append(t)
print(*ans)

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from itertools import islice

IS = lambda: int(input())
IA = lambda: [int(x) for x in input().split()]

N = IS()
A = IA()

h = N//2

a1 = 0
s = 1
for x,y in islice(zip(A, reversed(A)), h):
    a1 += s * (x + y)
    s *= -1
a1 += s * A[h]

ans = [a1]
for a in A[:-1]:
    ans.append((a - ans[-1] // 2) * 2)

print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
def g(i, left):
    if left <= 0: return None
    ret = set()
    for j in range(i, n+1):
        r = g(j+1, left)
        if r: ret |= r
        r = g(j+1, left-j)
        if r: ret |= set((j,) + x for x in r)
        if j == left: ret |= {(j,),}
    return ret

def f(s, i, d):
    left = s - sum(d.get(i, [0]))
    if left < 0: return None
    if left == 0: return d
    for j in g(i, left):
        e = dict(d)
        for k in j:
            e.setdefault(k, []).append(i)
        r = f(s, i+1, e)
        if r: return r
    return None

n = int(input())
n = 100
for i in range(100):
    s = n + i
    r = f(s, 1, {})
    if r:
        print(sum(len(x) for x in r.values()))
        for k,v in r.items():
            for x in v:
                print(k, x)
        break

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

N = int(input())

phi = 0 if N & 1 else 1
print(N * (N - 1) // 2 - N // 2)
for i in range(N):
    for j in range(i+1, N):
        k, l = i+1, j+1
        if l != N - k + phi:
            print(k, l)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import numpy as np

IA = lambda: [int(x) for x in input().split()]
IM = lambda N: [IA() for _ in range(N)]
N, M, C = IA()
B = IA()
A = IM(N)
print(((np.matmul(A, B) + C) > 0).sum())

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from itertools import chain
from functools import reduce
from collections import OrderedDict, Counter, deque
import operator

import numpy as np

N, M, C = map(int, input().split())
B = np.array(list(map(int, input().split())))
ans = 0
for _ in range(N):
    A = np.array(list(map(int, input().split())))
    if sum(A * B) + C > 0:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
def f():
    # A枚に達する
    a = A - 1
    # 増殖に使える時間
    b = K - a
    # A->Bにd回変換
    d, m = divmod(b, 2)
    return A + (B - A) * d + m

def g():
    return 1 + K

if (A + 2) < B:
    print(f())
else:
    print(g())

Fixed submission:
K, A, B = map(int, input().split())

def f():
    # A枚に達する
    a = A - 1
    # 増殖に使える時間
    b = K - a
    # A->Bにd回変換
    d, m = divmod(b, 2)
    return A + (B - A) * d + m

def g():
    return 1 + K

if (A + 2) < B:
    print(f())
else:
    print(g())
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = [int(input()) for _ in range(n)]

p.sort()
print(sum(p[:-1] + p[-1] // 2))

Fixed submission:
n = int(input())
p = [int(input()) for _ in range(n)]

p.sort()
print(sum(p[:-1]) + p[-1] // 2)
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = [int(x) for x in input().split()]

from collections import Counter
import operator
def f():
    a, b = Counter(A[::2]), Counter(A[1::2])
    ac, bc = a[0][1], b[0][1]
    ret = n - (ac + bc)
    if a[0][0] == b[0][0]:
        bc_2 = b[1][1] if len(b) != 1 else 0
        ac_2 = a[1][1] if len(a) != 1 else 0
        ret = n - max(ac + bc_2, ac_2 + bc)
    return ret
print(f())

Fixed submission:
n = int(input())
A = [int(x) for x in input().split()]

from collections import Counter
import operator
def f():
    evn = Counter(A[::2])
    odd = Counter(A[1::2])

    a = sorted(odd.most_common(2), key=operator.itemgetter(1, 0), reverse=True)
    b = sorted(evn.most_common(2), key=operator.itemgetter(1, 0), reverse=True)

    ac = (n // 2) - a[0][1]
    bc = (n // 2) - b[0][1]
    ret = ac + bc
    if a[0][0] == b[0][0]:
        bc_2 = n // 2 - (b[1][1] if len(b) != 1 else 0)
        ac_2 = n // 2 - (a[1][1] if len(a) != 1 else 0)
        ret = min(ac + bc_2, ac_2 + bc)
    return ret
print(f())
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from itertools import chain
from functools import reduce
from collections import OrderedDict, Counter, deque
import operator, math
from bisect import *

N, x = map(int, input().split())
X = [int(x) for x in input().split()]

def f():
    X.sort()
    L = len(X)
    if L == 1:
        return abs(X[0] - L)
    
    i = bisect_left(X, x)
    
    d = [t - u for t,u in zip(X[1:], X[:-1])]
    s = None
    if i == 0:
        s = set(d)
        s.add(x[0] - x)
    elif i == len(X):
        s = set(d)
        s.add(x - X[-1])
    else:
        s = set(d[:i - 1])
        s.update(d[i+1:])
        s.update({x - X[i-1], X[i] - x})
    return reduce(lambda a,x: math.gcd(a, x), s)

print(f())

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from itertools import chain
from functools import reduce
from collections import OrderedDict, Counter, deque
import operator, fractions
from bisect import *

N, x = map(int, input().split())
X = [int(x) for x in input().split()]

def f():
    X.sort()
    L = len(X)
    if L == 1:
        return abs(X[0] - x)
    
    i = bisect_left(X, x)
    
    d = [t - u for t,u in zip(X[1:], X[:-1])]
    s = None
    if i == 0:
        s = set(d)
        s.add(x[0] - x)
    elif i == len(X):
        s = set(d)
        s.add(x - X[-1])
    else:
        s = set(d[:i - 1])
        s.update(d[i+1:])
        s.update({x - X[i-1], X[i] - x})
    return reduce(fractions.gcd, s)

print(f())
Buggy python submission (verdict: Runtime Error):
A, B = input().split()
print((A-1)*(B-1))

Fixed submission:
A, B = map(int, input().split())
print((A-1)*(B-1))
Buggy python submission (verdict: Runtime Error):
N = input()
print("No" if N % sum(int(x) for x in N) else "Yes")

Fixed submission:
N = input()
print("No" if int(N) % sum(int(x) for x in N) else "Yes")
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())

from heapq import *
def f(s, K):
    known = set()
    for i in range(len(s)):
        for j in range(len(s), i, -1):
            ss = s[i:j]
            if ss in known:
                break
            known.add(ss)
    return sorted(known)[K -1]

print(f(s, K))

Fixed submission:
s = input()
K = int(input())

def f(s, K):
    known = set()
    for i in range(len(s)):
        for j in range(min(len(s), i + 5), i, -1):
            ss = s[i:j]
            if ss in known:
                break
            known.add(ss)
    return sorted(known)[K -1]

print(f(s, K))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())

known = set()
from heapq import *
hq = []
for i in range(len(s)):
    for j in range(len(s), i, -1):
        ss = s[i:j]
        if ss in known:
            break
        heappush(hq, ss)
        known.add(ss)
for i in range(K-1):
    heappop(hq)
print(heappop(hq))

Fixed submission:
s = input()
K = int(input())

def f(s, K):
    known = set()
    for i in range(len(s)):
        for j in range(min(len(s), i + 5), i, -1):
            ss = s[i:j]
            if ss in known:
                break
            known.add(ss)
    return sorted(known)[K -1]

print(f(s, K))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())

known = set()
from heapq import *
hq = []
for i in range(len(s)):
    for j in range(i + 1, len(s) + 1):
        ss = s[i:j]
        if ss not in known:
            heappush(hq, ss)
            known.add(ss)
for i in range(K-1):
    heappop(hq)
print(heappop(hq))

Fixed submission:
s = input()
K = int(input())

def f(s, K):
    known = set()
    for i in range(len(s)):
        for j in range(min(len(s), i + 5), i, -1):
            ss = s[i:j]
            if ss in known:
                break
            known.add(ss)
    return sorted(known)[K -1]

print(f(s, K))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(x) for x in input().split()]

sa = sorted(A)
import math
from bisect import *
hv = sa[-1] / 2
hl, hr = math.floor(hv), math.ceil(hv)
ri = bisect_right(sa, hv)

import operator
import functools
def dist(x):
    if x <= hl:
        return functools.reduce(operator.imul, range(hl, x, -1)) / functools.reduce(operator.imul, range(hr, hr + (hl - x) + 1))
    else:
        return functools.reduce(operator.imul, range(hr, hr + (x - hr) + 1)) / functools.reduce(operator.imul, range(x, hl, -1))

if ri == 0:
    print(sa[-1], sa[ri])
elif len(sa) == 2:
    print(sa[1], sa[0])
else:
    print(sa[-1], sa[ri - 1] if dist(sa[ri - 1]) > dist(sa[ri]) else sa[ri])

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]

sa = sorted(A)
from bisect import *
hv = sa[-1] / 2
ri = bisect_right(sa, hv)

if ri == 0:
    print(sa[-1], sa[ri])
elif len(sa) == 2:
    print(sa[1], sa[0])
else:
    print(sa[-1], sa[ri - 1] if abs(sa[ri - 1] - hv) < abs(sa[ri] - hv) else sa[ri])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
R = [tuple([int(x) for x in input().split()]) for _ in range(N)]
B = [tuple([int(x) for x in input().split()]) for _ in range(N)]

xl = [set() for _ in range(2 * N + 1)]
yl = [set() for _ in range(2 * N + 1)]

for b in B:
    x, y = b
    for i in range(x):
        xl[i].add(b)
    for j in range(y):
        yl[j].add(b)

cands = []
for r in R:
    x, y = r
    s = xl[x].intersection(yl[y])
    cands.append([r, len(s), s])

def f(cands, used, n):
    if not cands:
        return n
    ret = 0
    hd, tl = cands[0], cands[1:]
    r, _, s = hd
    for t in s - used:
        u = used.union({t})
        ret = max(ret, f(tl, u, n + 1))
    ret = max(ret, f(tl, used, n))
    return ret

import operator
cands.sort(key=operator.itemgetter(1))
print(f(cands, set(), 0))

Fixed submission:
N = int(input())
R = [[int(x) for x in input().split()] for _ in range(N)]
B = [[int(x) for x in input().split()] for _ in range(N)]

import operator
R.sort(key=operator.itemgetter(1), reverse=True)
B.sort()

ans = 0
for b in B:
    xb, yb = b
    for r in R:
        xr, yr = r
        if xr < xb and yr < yb:
            ans += 1
            R.remove(r)
            break
print(ans)
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = [input() for _ in range(H)]

import heapq
def dijkstra(adj, n, st=1):
    dj = [2**64] * (n)
    dj[st] = 0
    q = []
    heapq.heappush(q, (0, st))
    while q:
        fc, fn = heapq.heappop(q)
        if dj[fn] < fc: continue
        for tn, lc in adj[fn]:
            if dj[fn] + lc < dj[tn]:
                dj[tn] = dj[fn] + lc
                heapq.heappush(q, (dj[tn], tn))
    return dj

def cid(x):
    return x[0] * W + x[1]

def cl(adj, x, y):
    xid = cid(x)
    yid = cid(y)
    links = adj.setdefault(xid , [])
    links.append((yid, 1))
    links = adj.setdefault(yid, [])
    links.append((xid, 1))

adj = {}
for i in range(H):
    for j in range(W):
        if S[i][j] == "#": continue
        ni = i + 1
        if ni < H and S[ni][j] == ".":
            cl(adj, (i, j), (ni, j))
        nj = j + 1
        if nj < W and S[i][nj] == ".":
            cl(adj, (i, j), (i, nj))

c = dijkstra(adj, H*W, cid((0,0)))
hwc = c[cid((H-1,W-1))]
print(-1 if hwc == 2**64 else H * W - sum(s.count("#") for s in S) - hwc - 1)

Fixed submission:
H, W = map(int, input().split())
S = [input() for _ in range(H)]

import heapq
def dijkstra(adj, n, st=1):
    dj = [2**64] * (n)
    dj[st] = 0
    q = []
    heapq.heappush(q, (0, st))
    while q:
        fc, fn = heapq.heappop(q)
        if dj[fn] < fc: continue
        for tn, lc in adj[fn]:
            if dj[fn] + lc < dj[tn]:
                dj[tn] = dj[fn] + lc
                heapq.heappush(q, (dj[tn], tn))
    return dj

def cid(x):
    return x[0] * W + x[1]

def cl(adj, x, y):
    xid = cid(x)
    yid = cid(y)
    adj[xid].append((yid, 1))
    adj[yid].append((xid, 1))

adj = dict([(x, []) for x in range(H*W)])
for i in range(H):
    for j in range(W):
        if S[i][j] == "#": continue
        ni = i + 1
        if ni < H and S[ni][j] == ".":
            cl(adj, (i, j), (ni, j))
        nj = j + 1
        if nj < W and S[i][nj] == ".":
            cl(adj, (i, j), (i, nj))

c = dijkstra(adj, H*W, cid((0,0)))
hwc = c[cid((H-1,W-1))]
print(-1 if hwc == 2**64 else H * W - sum(s.count("#") for s in S) - hwc - 1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

def f():
    lb = 0
    ub = N - 1
    
    print(lb, flush=True)
    lba = input()
    if lba == 'Vacant': return
    
    print(ub, flush=True)
    uba = input()
    if uba == 'Vacant': return
    
    while lb < ub:
        qry = (lb + ub) // 2
        print(qry, flush=True)
        qa = input()
        if qa == 'Vacant': return
        if (not ((lb ^ qry) & 1) and lba == qa) or (((lb ^ qry) & 1) and lba != qa):
            lb = qry
            lba = qa
        else:
            ub = qa

f()

Fixed submission:
N = int(input())

def f():
    lb = 0
    ub = N - 1
    
    print(lb, flush=True)
    lba = input()
    if lba == 'Vacant': return
    
    print(ub, flush=True)
    uba = input()
    if uba == 'Vacant': return
    
    while lb < ub:
        qry = (lb + ub) // 2
        print(qry, flush=True)
        qa = input()
        if qa == 'Vacant': return
        if (not ((lb ^ qry) & 1) and lba == qa) or (((lb ^ qry) & 1) and lba != qa):
            lb = qry
            lba = qa
        else:
            ub = qry

f()
Buggy python submission (verdict: Time Limit Exceeded):
Q = int(input())

import math
def primes():
    n = 10**5
    sieve = [True] * (n + 1)
    for x in range(2, math.ceil(math.sqrt(n))):
        y = x * 2
        while y <= n:
            sieve[y] = False
            y += x
    return [i for (i, x) in enumerate(sieve[2:], 2) if x]

import bisect
def sub_p(l, r):
    li = bisect.bisect_left(list_p, l)
    ri = bisect.bisect_left(list_p, r)
    return list_p[li:ri+1]

list_p = primes()
set_p = set(list_p)

for _ in range(Q):
    l, r = map(int, input().split())
    sp = sub_p(l, r)
    
    ans = 0
    for p in sp:
        ans += ((p + 1) // 2) in set_p
    print(ans)


Fixed submission:
Q = int(input())

n = 10**5

import math
def primes():
    sieve = [True] * (n + 1)
    for x in range(2, math.ceil(math.sqrt(n))):
        y = x * 2
        while y <= n:
            sieve[y] = False
            y += x
    return [i for (i, x) in enumerate(sieve[2:], 2) if x]

list_p = primes()
set_p = set(list_p)

tbl = [0] * (n + 1)
for p in list_p:
    tbl[p] = 1 if ((p + 1) // 2) in set_p else 0

import itertools
tbl = list(itertools.accumulate(tbl))

for _ in range(Q):
    l, r = map(int, input().split())
    print(tbl[r] - tbl[l - 1])
Buggy python submission (verdict: Runtime Error):
import math
import numpy as np
N = int(input())
F = [[int(x) for x in input().split()] for _ in range(N)]
P = [[int(x) for x in input().split()] for _ in range(N)]

f = np.array(F)
ans = -math.inf
for n in range(1, 2**10):
    a = np.array([int(x) for x in bin(n)[2:].rjust(10, '0')])
    p = sum([P[i][x] for i,x in enumerate(np.sum(f * a, axis=1))])
    ans = max(ans, p)
print(ans)

Fixed submission:
import numpy as np
N = int(input())
F = [[int(x) for x in input().split()] for _ in range(N)]
P = [[int(x) for x in input().split()] for _ in range(N)]

f = np.array(F)
ans = float('-inf')
for n in range(1, 2**10):
    a = np.array([int(x) for x in bin(n)[2:].rjust(10, '0')])
    p = sum([P[i][x] for i,x in enumerate(np.sum(f * a, axis=1))])
    ans = max(ans, p)
print(ans)
Buggy python submission (verdict: Runtime Error):
import bisect, functools
N = int(input())
A = sorted(int(x) for x in input().split())
B = sorted(int(x) for x in input().split())
C = sorted(int(x) for x in input().split())

@functools.lru_cache(maxsize=None)
def a(n):
    return bisect.bisect_left(A, n)

@functools.lru_cache(maxsize=None)
def b_i(i):
    if i >= 1:
        return b_i(i - 1) + a(B[i - 1])
    return 0

@functools.lru_cache(maxsize=None)
def b(n):
    return b_i(min(len(B), bisect.bisect_left(B, n)))

def c():
    return sum(b(x) for x in C)

print(c())

Fixed submission:
K = int(input())

import heapq
def dijkstra(adj, n, start):
    dj = [10**6] * (n + 1)
    dj[start] = 0
    q = []
    heapq.heappush(q, (0, start))
    while q:
        fc, fn = heapq.heappop(q)
        if dj[fn] < fc: continue
        for tn, lc in adj[fn]:
            if dj[tn] > dj[fn] + lc:
                dj[tn] = dj[fn] + lc
                heapq.heappush(q, (dj[tn], tn))
    return dj

adj = {}
for i in range(K):
    t = adj.setdefault(i, [])
    t.append(((i + 1) % K, 1))
    t.append(((i * 10) % K, 0))

costs = dijkstra(adj, K - 1, 1)
print(costs[0] + 1)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
xy = [[int(x) for x in input().split()] for _ in range(N)]

from itertools import combinations

ans = float('inf')
for s in combinations(xy, K):
    x, y = zip(*s)
    ans = min(ans, (max(x) - min(x)) * (max(y) - min(y)))
print(ans)

Fixed submission:
N, K = map(int, input().split())
xy = [[int(x) for x in input().split()] for _ in range(N)]

xs, ys = tuple(zip(*xy))
cmpx = sorted(xs)
cmpy = sorted(ys)

x2cmp = dict((x, i) for i,x in enumerate(cmpx))
y2cmp = dict((x, i) for i,x in enumerate(cmpy))

sm = [[0] * (N + 1) for _ in range(N + 1)]
for x, y in xy:
    sm[x2cmp[x]][y2cmp[y]] = 1

for i in range(N):
    for j in range(N):
        sm[i][j] += sm[i][j - 1]
for j in range(N):
    for i in range(N):
        sm[i][j] += sm[i - 1][j]

ans = float('inf')
for x1 in range(N):
    for y1 in range(N):
        for x2 in range(x1 + 1, N):
            for y2 in range(y1 + 1, N):
                k = sm[x2][y2] - sm[x2][y1 - 1] - sm[x1 - 1][y2] + sm[x1 - 1][y1 - 1]
                if k == K:
                    area = (cmpx[x2] - cmpx[x1]) * (cmpy[y2] - cmpy[y1])
                    ans = min(ans, area)

print(ans)