Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03085 (python)

Fixed submission:
b = input()
if b == 'A':
  print('T')
if b == 'T':
  print('A')
if b == 'G':
  print('C')
if b == 'C':
  print('G')

Buggy submission (verdict: Runtime Error):
b = input()
if b = 'A':
  print('T')
if b = 'T':
  print('A')
if b = 'G':
  print('C')
if b = 'C':
  print('G')
Problem p03102 (python)

Fixed submission:
s = list(map(int, input().split()))
N = s[0]
M = s[1]
C = s[2]
B = list(map(int, input().split()))
x = 0
for i in range(N):
  k = C
  A = list(map(int, input().split()))
  for j in range(M):
    k = k + A[j] * B[j]
  if k > 0:
    x = x + 1
  else:
    pass
print(x)

Buggy submission (verdict: Runtime Error):
s = list(map(int, input().split()))
N = i[0]
M = i[1]
C = i[2]
B = list(map(int, input().split()))
x = 0
for i in range(N):
  k = C
  A = list(map(int, input().split()))
  for j in range(M):
    k = k + A[j] * B[j]
  if k > 0:
    x = x + 1
  else:
    pass
print(x)
Problem p03105 (python)

Fixed submission:
i = list(map(int, input().split()))
A = i[0]
B = i[1]
C = i[2]
D = B // A

if D <= C:
  print(D)
else:
  print(C)

Buggy submission (verdict: Runtime Error):
N = int(input())
s_a = [int(input()) for i in range(N)]
s_b = [0]
s = s_b + s_a
x = 0
y = 0
j = 0

for v in range(N + 1):
    c  = s.count(v)
    if c == 0:
        x = x + v
    if c == 2:
        y = y + v
    if c == 1:
        j = j + 1

if j == N + 1:
    print("Correct")
else:
    print(str(y) + " " + str(x))
Problem p03106 (python)

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

def kcd(A, B, K):
    cd_list = []
    for i in range(1, min(A, B) + 1):
        if A % i == 0 and B % i == 0:
            cd_list.insert(0,i)
    return cd_list[K - 1]

print(kcd(i[0],i[1],i[2]))

Buggy submission (verdict: Runtime Error):
i = list(map(int, input().split()))

def kcd(A, B, K):
    cd_list = []
    for i in range(2, min(A, B) + 1):
        if A % i == 0 and B % i == 0:
            cd_list.insert(0,i)
    return cd_list[K - 1]

print(kcd(i[0],i[1],i[2]))
Problem p03146 (python)

Fixed submission:
s = int(input())
a = [s]
i = 1

f = lambda n: n // 2 if n % 2 == 0 else 3 * n + 1

while True:
    a.append(f(a[i-1]))
    i += 1

    if a[-1] in a[:-1]:
        break

print(i)

Buggy submission (verdict: Runtime Error):
s = int(input())
a = [s]
i = 1

f = lambda n: n // 2 if n % 2 == 0 else 3 * n + 1

while true:
    a.append(f(a[i-1]))
    i += 1

    if a[-1] in a[:-1]:
        break

print(i)
Problem p03992 (python)

Fixed submission:
s = list(input())
s.insert(4, " ")
print("".join(s))

Buggy submission (verdict: Runtime Error):
s = list(input())
K = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"

for i in range(len(s)):
    if K >= 26 or s[i] >= alphabet[-K]:
        K -= ord("z") - ord(s[i]) + 1
        s[i] = "a"

if K > 0:
    K %= 26
    if (chr(ord(s[-1]) + K) <= "z"):
        s[-1] = chr(ord(s[-1]) + K)
    else:
        s[-1] = chr(ord("a") + K)

print("".join(s))

Buggy submission (verdict: Runtime Error):
s = list(input())
K = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"

# need = 0
# for i in range(len(s)):
#     need += ord("z") - ord(s[i]) + 1

for i in range(len(s)):
    if K >= 26 or s[i] >= alphabet[-K]:
        K -= ord("z") - ord(s[i]) + 1
        s[i] = "a"

if K > 0:
    K %= 26
    if (chr(ord(s[-1]) + K) <= "z"):
        s[-1] = chr(ord(s[-1]) + K)
    else:
        s[-1] = chr(ord("a") + K)

# if K > 0:
#     K %= 26
#     if (ord(s[-1]) + K <= ord("z")):
#         s[-1] = chr(ord(s[-1]) + K)
#     else:
#         s[-1] = chr(ord("a") + K - (ord("z" - ord(s[-1]))))

print("".join(s))

Buggy submission (verdict: Runtime Error):
s = list(input())
K = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"

# need = 0
# for i in range(len(s)):
#     need += ord("z") - ord(s[i]) + 1

for i in range(len(s)):
    if K >= 26 or s[i] >= alphabet[-K]:
        K -= ord("z") - ord(s[i]) + 1
        s[i] = "a"

if K > 0:
    K %= 26
    if (ord(s[-1]) + K <= ord("z")):
        s[-1] = chr(ord(s[-1]) + K)
    else:
        s[-1] = chr(ord("a") + K - (ord("z" - ord(s[-1]))))

print("".join(s))

Buggy submission (verdict: Runtime Error):
s = list(input())
K = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"

# need = 0
# for i in range(len(s)):
#     need += ord("z") - ord(s[i]) + 1

for i in range(len(s)):
    if K >= 26 or s[i] >= alphabet[-K]:
        K -= ord("z") - ord(s[i]) + 1
        s[i] = "a"

if K > 0:
    K %= 26
    if (ord(s[-1] + K <= ord("z"))):
        s[-1] = chr(ord(s[-1]) + K)
    else:
        s[-1] = chr(ord("a") + K - (ord("z" - ord(s[-1]))))

print("".join(s))
Problem p03994 (python)

Fixed submission:
s = list(input())
k = int(input())

for i in range(len(s)):
    if s[i] == "a": continue

    diff = ord("z") - ord(s[i]) + 1

    if diff <= k:
        k -= diff
        s[i] = "a"

if k > 0:
    k %= 26
    s[i] = chr(ord(s[i]) + k)

print("".join(s))

Buggy submission (verdict: Runtime Error):
s = list(input())
K = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"

for i in range(len(s)):
    if K > 26 or s[i] >= alphabet[-K]:
        K -= ord("z") - ord(s[i]) + 1
        s[i] = "a"

if K > 0:
    K %= 26
    s[-1] = chr(ord(s[-1]) + K)

print("".join(s))

Buggy submission (verdict: Runtime Error):
s = list(input())
K = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"

for i in range(len(s)):
    if K >= 26 or s[i] >= alphabet[-K]:
        K -= ord("z") - ord(s[i]) + 1
        s[i] = "a"

if K > 0:
    K %= 26
    if (chr(ord(s[-1]) + K) <= "z"):
        s[-1] = chr(ord(s[-1]) + K)
    else:
        s[-1] = chr(ord("a") + K)

print("".join(s))

Buggy submission (verdict: Runtime Error):
s = list(input())
K = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"

# need = 0
# for i in range(len(s)):
#     need += ord("z") - ord(s[i]) + 1

for i in range(len(s)):
    if K >= 26 or s[i] >= alphabet[-K]:
        K -= ord("z") - ord(s[i]) + 1
        s[i] = "a"

if K > 0:
    K %= 26
    s[-1] = chr(ord(s[-1]) + K)

print("".join(s))

Buggy submission (verdict: Runtime Error):
s = list(input())
K = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"

need = 0
for i in range(len(s)):
    need += ord("z") - ord(s[i]) + 1

for i in range(len(s)):
    if K >= 26 or s[i] >= alphabet[-K]:
        K -= ord("z") - ord(s[i]) + 1
        s[i] = "a"

if K > 0:
    K %= 26
    s[-1] = chr(ord(s[-1]) + K)

print("".join(s))

Buggy submission (verdict: Runtime Error):
s = list(input())
K = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"

for i in range(len(s)):
    if K > 26 or s[i] >= alphabet[-K]:
        K -= ord("z") - ord(s[i]) + 1
        s[i] = "a"

if K > 0:
    s[-1] = chr(ord(s[-1]) + K)

print("".join(s))
Problem p02985 (python)

Fixed submission:
N, K = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for i in range(N - 1)]

from collections import defaultdict

v = defaultdict(set)

for a, b in AB:
    v[a].add(b)
    v[b].add(a)

M = 10**9+7

import sys
sys.setrecursionlimit(100001)

result = 1

def check(n, b, p):
    global result
    result = result * max(K - b - p, 0) % M
    #print("check:", n, r[n])
    np = min(p + 1, 2)
    for b, x in enumerate(v[n]):
        v[x].remove(n)
        check(x, b, np)

check(1, 0, 0)

print(result)

Buggy submission (verdict: Runtime Error):
N, K = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for i in range(N - 1)]

from collections import defaultdict

v = defaultdict(set)

for a, b in AB:
    v[a].add(b)
    v[b].add(a)

r = [0] * (N + 1)
M = 10**9+7

def check(n, b, p):
    r[n] = K - b - p
    #print("check:", n, r[n])
    b = 0
    for x in v[n]:
        if r[x] == 0:
            check(x, b, min(p + 1, 2))
            b += 1

check(1, 0, 0)

#print(r)

result = 1
for i in range(N):
    result = result * r[i + 1] % M

print(result)
Problem p03006 (python)

Fixed submission:
N = int(input())
XY = [tuple([int(_) for _ in input().split()]) for i in range(N)]

if N == 1:

    result = 1

else:

    XY.sort()

    dxy = [
        (XY[i][0] - XY[j][0], XY[i][1] - XY[j][1])
        for i in range(N)
        for j in range(i + 1, N)
    ]

    from collections import Counter

    cdxy = Counter(dxy)

    m = max(cdxy.values())

    #print(XY)
    #print(dxy)
    #print(cdxy)

    result = N - m

print(result)

Buggy submission (verdict: Runtime Error):
N = int(input())
XY = [[int(_) for _ in input().split()] for i in range(N)]

dxy = [
    (XY[i][0] - XY[j][0], XY[i][1] - XY[j][1])
    for i in range(N)
    for j in range(i + 1, N)
]

from collections import Counter

cdxy = Counter(dxy)

m = max(cdxy.values())

#print(XY)
#print(dxy)
#print(cdxy)

result = N - m
print(result)
Problem p03007 (python)

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

mxs = sorted(x for x in A if x < 0)
pxs = sorted(x for x in A if x >= 0)

if len(mxs) == 0:
    mxs = [pxs[0]]
    pxs = pxs[1:]

if len(pxs) == 0:
    pxs = [mxs[-1]]
    mxs = mxs[:-1]

#print(mxs, pxs)

result = sum(pxs) - sum(mxs)
print(result)

if len(pxs) == 1:
    for y in mxs:
        print(pxs[0], y)
        pxs[0] -= y
else:
    for y in pxs[:-1]:
        print(mxs[0], y)
        mxs[0] -= y
    print(pxs[-1], mxs[0])
    pxs[-1] -= mxs[0]
    for y in mxs[1:]:
        print(pxs[-1], y)
        pxs[-1] -= y

#for i in range

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(_) for _ in input().split()]

mxs = sorted(x for x in A if x < 0)
pxs = sorted(x for x in A if x >= 0)

if len(mxs) == 0:
    mxs = [pxs[0]]
    pxs = pxs[1:]

#print(mxs, pxs)

result = sum(pxs) - sum(mxs)
print(result)

if len(pxs) == 1:
    for y in mxs:
        print(pxs[0], y)
        pxs[0] -= y
else:
    for y in pxs[:-1]:
        print(mxs[0], y)
        mxs[0] -= y
    print(pxs[-1], mxs[0])
    pxs[-1] -= mxs[0]
    for y in mxs[1:]:
        print(pxs[-1], y)
        pxs[-1] -= y

#for i in range
Problem p03062 (python)

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

ma = sorted(x for x in A if x < 0)
pa = sorted(x for x in A if x >= 0)

# print(ma, pa)

if len(ma) % 2 == 0:
    result = -sum(ma) + sum(pa)
else:
    x = -ma[-1]
    if len(pa):
        x = min(x, pa[0])
    result = -sum(ma) + sum(pa) - x * 2

print(result)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(_) for _ in input().split()]

ma = sorted(x for x in A if x < 0)
pa = sorted(x for x in A if x >= 0)

# print(ma, pa)

if len(ma) % 2 == 0:
    result = -sum(ma) + sum(pa)
else:
    x = min(-ma[-1], pa[0])
    result = -sum(ma) + sum(pa) - x * 2

print(result)
Problem p03074 (python)

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

S = input()

xs = []

i = 0

while i < N :
    l = 0
    while i < N and S[i] == '1':
        i += 1
        l += 1
    xs.append(l)
    l = 0
    while i < N and S[i] == '0':
        i += 1
        l += 1
    xs.append(l)

xs += [0] * (K * 2)

#print(xs)

result = 0

l = (K * 2) + 1
result = r = sum(xs[0:l])
#print("*", result, r)

i = 0
while i + l + 1 < len(xs):
    r = r - xs[i] - xs[i+1] + xs[i+l] + xs[i+l+1]
    result = max(result, r)
    #print(result, r)
    i += 2

print(result)

Buggy submission (verdict: Runtime Error):
N, K = [int(_) for _ in input().split()]

S = input()

xs = []

i = 0

while i < N :
    l = 0
    while i < N and S[i] == '1':
        i += 1
        l += 1
    xs.append(l)
    l = 0
    while i < N and S[i] == '0':
        i += 1
        l += 1
    xs.append(l)

xs += [0] * (K * 2)

#print(xs)

result = 0

l = (K * 2) + 1
result = r = sum(xs[0:l])
#print("*", result, r)

i = 0
while i + l + 1 < N:
    r = r - xs[i] - xs[i+1] + xs[i+l] + xs[i+l+1]
    result = max(result, r)
    #print(result, r)
    i += 2

print(result)
Problem p03102 (python)

Fixed submission:
N, M, C = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
A = [[int(_) for _ in input().split()] for i in range(N)]

result = 0

for row in A:
    t = C + sum([x * y for x, y in zip(row, B)])
    if t > 0:
        result += 1

print(result)

Buggy submission (verdict: Runtime Error):
N, M, C = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
A = [[int(_) for _ in input().split()] for i in range(N)]

result = len(
    row
    for row in A
    if C + sum([x * y for x, y in zip(row, B)]) > 0
)

print(result)
Problem p03283 (python)

Fixed submission:
N, M, Q = [int(_) for _ in input().split()]
LR = [[int(_) for _ in input().split()] for i in range(M)]
PQ = [[int(_) for _ in input().split()] for i in range(Q)]

from collections import defaultdict
from itertools import accumulate

C = [[0]*(N+1) for i in range(N+2)]

for l, r in LR:
    C[1][r] += 1
    C[l + 1][r] -= 1

#print(C)

T = [list(accumulate(row)) for row in C]
T = [list(accumulate(row)) for row in zip(*T)]

#print(T)

for p, q in PQ:
    print(T[q][p])

Buggy submission (verdict: Runtime Error):
N, M, Q = [int(_) for _ in input().split()]
LR = [[int(_) for _ in input().split()] for i in range(M)]
PQ = [[int(_) for _ in input().split()] for i in range(Q)]

LR = sorted(LR)

W = []
x = 0
for i in range(N):
    while x < M and LR[x][0] < i:
        x += 1
    W.append(x)

from itertools import accumulate

for p, q in PQ:
    xs = LR[W[p]:]
    ys = [0] * (N+1)
    for x in xs:
        ys[x[1]] += 1
    zs = list(accumulate(ys))
    print(zs[q])
Problem p03294 (python)

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

def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

#l = 1
#for a in A:
#    l = lcm(l, a)

#r = sum((l - 1) % a for a in A)
r = sum(a - 1 for a in A)

print(r)

Buggy submission (verdict: Runtime Error):
print(-int(input())+sum(map(input().split(),int)))
Problem p03469 (python)

Fixed submission:
import sys

line = sys.stdin.readline().strip()
print(line[:3]+"8"+line[4:])

Buggy submission (verdict: Runtime Error):
import sys
 
N, Y = [int(x) for x in sys.stdin.readline().strip().split()]
 
a = Y // 10000
b = (Y - a * 10000) // 5000
c = (Y - a * 10000 - b * 5000) // 1000
 
t = a + b + c
if N >= t + 9:
    l = (N - t - 9) // 9
    a -= l
    c += l * 10
 
t = a + b + c
if N >= t + 4:
    l = (N - t - 4) // 4
    b -= l
    c += l * 5
 
t = a + b + c
if N >= t:
    l = N - t
    a -= l
    b += l * 2
 
if a + b + c > N and a >= 0 and b >= 0 and c >= 0:
    print("-1 -1 -1")
else:
    print(a, b, c)
Problem p03476 (python)

Fixed submission:
import sys

Q = int(sys.stdin.readline().strip())
LR = []
for i in range(Q):
    LR.append([int(x) for x in sys.stdin.readline().strip().split()])

N = 10**5+1
Primes = list(range(N+1))
Primes[1] = 0

for p in Primes:
    if p * p > N+1: break
    if p == 0: continue
    for i in range(p + p, N+1, p):
        Primes[i] = 0

primes = [p for p in Primes if p > 0]

likes = []
r = 0
for n in range(N):
    if n%2 == 1 and Primes[n] > 0 and Primes[n//2+1] > 0:
        r += 1
    likes.append(r)

for i in range(Q):
    print(likes[LR[i][1]] - likes[LR[i][0]-1])

Buggy submission (verdict: Runtime Error):
import sys

Q = int(sys.stdin.readline().strip())
LR = []
for i in range(Q):
    LR.append([int(x) for x in sys.stdin.readline().strip().split()])

N = 10**5
Primes = list(range(N+1))
Primes[1] = 0

for p in Primes:
    if p * p > N+1: break
    if p == 0: continue
    for i in range(p + p, N+1, p):
        Primes[i] = 0

primes = [p for p in Primes if p > 0]

likes = []
r = 0
for n in range(N):
    if n%2 == 1 and Primes[n] > 0 and Primes[n//2+1] > 0:
        r += 1
    likes.append(r)

for i in range(Q):
    print(likes[LR[i][1] + 1] - likes[LR[i][0]-1])
Problem p03480 (python)

Fixed submission:
import sys

def solve1(s):
    n = len(s)
    i = 0
    while i <= n // 2:
        if s[n // 2] != s[n // 2 - i]:
            break
        if s[(n - 1) // 2] != s[(n - 1) // 2 + i]:
            break
        i += 1
    return (n - 1) // 2 + i


line = sys.stdin.readline().strip()
print(solve1(list(line)))

Buggy submission (verdict: Runtime Error):
import sys

def solve(s, cache={}):
    if s in cache:
        return cache[s]
    n = len(s)
    if n == 1:
        return 1
    if s == "0" * n or s == "1" * n:
        return n
    r1 = solve("0" + s[1:-1])
    r2 = solve("1" + s[1:-1])
    r3 = solve(s[1:-1] + "0")
    r4 = solve(s[1:-1] + "1")
    r = max(r1, r2, r3, r4)
    cache[s] = r
    return r

line = sys.stdin.readline().strip()

print(solve(line))
Problem p03488 (python)

Fixed submission:
import sys

def check(s, x, y):

    while s and s[0] == "F":
        s = s[1:]
        x -= 1
    while s and s[-1] == "T":
        s = s[:-1]

    d = 0
    vxs = []
    vys = []
    while s:
        while s and s[0] == "T":
            s = s[1:]
            d ^= 1
        l = 0
        while s and s[0] == "F":
            s = s[1:]
            l += 1
        if d:
            vys.append(l)
        else:
            vxs.append(l)

    def check1(vs, t):
        a = 0
        for v in sorted(vs, reverse=True):
            if t < a:
                a -= v
            else:
                a += v
        return a == t

    r = check1(vxs, x) and check1(vys, y)
    return r

if __name__ == "__main__":
    s = sys.stdin.readline().strip()
    x, y = [int(n) for n in sys.stdin.readline().strip().split()]
    if check(s, x, y):
        print("Yes")
    else:
        print("No")

Buggy submission (verdict: Runtime Error):
import sys

def check(s, x, y):

    while s and s[0] == "F":
        s = s[1:]
        x -= 1
    while s and s[-1] == "T":
        s = s[:-1]

    d = 0
    vxs = []
    vys = []
    while s:
        while s and s[0] == "T":
            s = s[1:]
            d ^= 1
        l = 0
        while s and s[0] == "F":
            s = s[1:]
            l += 1
        if d:
            vys.append(l)
        else:
            vxs.append(l)

    def check1(vs, t):
        def check2(i, p, cache={}):
            if i == 0:
                return p == t
            if (i, p) in cache:
                return cache[i, p]
            r =  check2(i - 1, p - vs[i-1]) or check2(i - 1, p + vs[i-1])
            cache[i, p] = r
            return r
        return check2(len(vs), 0)

    r = check1(vxs, x) and check1(vys, y)
    return r

if __name__ == "__main__":
    s = sys.stdin.readline().strip()
    x, y = [int(n) for n in sys.stdin.readline().strip().split()]
    if check(s, x, y):
        print("Yes")
    else:
        print("No")
Problem p03503 (python)

Fixed submission:
import sys

line = sys.stdin.readline()
N = int(line.strip())

F = {}
for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()]
    for j in range(10):
        F[i, j] = xs[j]

f = [sum((1 << j) for j in range(10) if F[i,j]) for i in range(N)]

pt = [sum(((i >> j) & 1) for j in range(10)) for i in range(2**10)]

P = {}
for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()]
    for j in range(11):
        P[i, j] = xs[j]


rr = -100000000000000000000

for i in range(1, 2**10):
    r = sum([P[j, pt[f[j] & i]] for j in range(N)])
    if rr < r:
        rr = r

print(rr)

Buggy submission (verdict: Runtime Error):
import sys

line = sys.stdin.readline()
N = int(line.strip())

F = {}
for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()]
    for j in range(10):
        F[i, j] = xs[j]

f = [sum((1 << j) for j in range(10) if F[i,j]) for i in range(N)]

pt = [sum(((i >> j) & 1) for j in range(10)) for i in range(2**10)]

P = {}
for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()]
    for j in range(10):
        P[i, j] = xs[j]


rr = -100000000000000000000

for i in range(1, 2**10):
    r = sum([P[j, pt[f[j] & i]] for j in range(N)])
    if rr < r:
        rr = r

print(rr)

Buggy submission (verdict: Runtime Error):
import sys

line = sys.stdin.readline()
N = int(line.strip())

F = {}
for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()]
    for j in range(10):
        F[i, j] = xs[j]

f = [sum((1 << j) for j in range(10) if F[i,j]) for i in range(N)]

pt = [sum(((i >> j) & 1) for j in range(10)) for i in range(2**10)]

P = {}
for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()]
    for j in range(10):
        P[i, j] = xs[j]


ri = -1
rr = -100000

for i in range(1, 2**10):
    r = sum([P[j, pt[f[j] & i]] for j in range(N)])
    if rr < r:
        rr = r
        ri = i

print(rr)

Buggy submission (verdict: Runtime Error):
import sys

line = sys.stdin.readline()
N = int(line.strip())

F = {}
for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()]
    for j in range(10):
        F[i, j] = xs[j]

f = [sum((1 << j) for j in range(10) if F[i,j]) for i in range(N)]

pt = [sum(((i >> j) & 1) for j in range(10)) for i in range(2**10)]

P = {}
for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()]
    for j in range(10):
        P[i, j] = xs[j]


ri = -1
rr = -100000

for i in range(1, 2**10):
    r = sum([P[j, pt[f[j] & i]] for j in range(N)])
    if rr < r:
        rr = r
        ri = i

print(rr)
Problem p03550 (python)

Fixed submission:
import sys
line = sys.stdin.readline().strip()
n, z, w = map(int, line.split()[:3])
line = sys.stdin.readline().strip()
a = list(map(int, line.split()[:n]))
#print(n, z, w)
#print(a)

if n > 2:
  result = max(
    abs(a[-1] - w),
    abs(a[-2] - a[-1])
  )
else:
  result = abs(a[-1] - w)

print(result)

Buggy submission (verdict: Runtime Error):
import sys
line = sys.stdin.readline().strip()
n, z, w = map(int, line.split()[:3])
line = sys.stdin.readline().strip()
a = list(map(int, line.split()[:n]))
#print(n, z, w)
#print(a)

def think_x(z, w, a, turn):
    if len(a) == 0:
        return abs(z - w)
    result = 0
    result_i = None
    for i in range(len(a)):
        r = think_y(a[i], w, a[i+1:], turn + 1)
        if r >= result:
            result = r
            result_i = i
    #print("# X", turn, result_i, result)
    return result

def think_y(z, w, a, turn):
    if len(a) == 0:
        return abs(z - w)
    result = 9999999999999999999999
    result_i = None
    for i in range(len(a)):
        r = think_x(z, a[i], a[i+1:], turn + 1)
        if r <= result:
            result = r
            result_i = i
    #print("# Y", turn, result_i, result)
    return result

print(think_x(z, w, a, 1))
Problem p03600 (python)

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

def calc(N, A):
    r = 0
    if N == 1:
        return 0
    if N == 2:
        return A[0][1]
    for i in range(0, N):
        for j in range(i + 1, N):
            a = A[i][j]
            d = min(A[i][k] + A[k][j] for k in range(0, N) if k != i and k != j)
            if a > d:
                return -1
            if a < d:
                r += a
    return r

print(calc(N, A))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [[int(_) for _ in input().split()] for i in range(N)]

def calc(N, A):
    r = 0
    for i in range(0, N):
        for j in range(i + 1, N):
            a = A[i][j]
            d = min(A[i][k] + A[k][j] for k in range(0, N) if k != i and k != j)
            if a > d:
                return -1
            if a < d:
                r += a
    return r
    
print(calc(N, A))
Problem p03741 (python)

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

def calc(A, y):
    result = abs(A[0] - y)
    t = y
    if t == 0:
        return 10**30
    for a in A[1:N]:
        tt = t + a
        if t * tt >= 0:
            m =  -t // abs(t)
            result += abs(m - tt)
            tt = m
        t = tt
    return result

result = min(calc(A, A[0]), calc(A, -1),  calc(A, +1))

print(result)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(_) for _ in input().split()]

def calc(A, y):
    result = abs(A[0] - y)
    t = y
    for a in A[1:N]:
        tt = t + a
        if t * tt >= 0:
            m =  -t // abs(t)
            result += abs(m - tt)
            tt = m
        t = tt
    return result

result = min(calc(A, A[0]), calc(A, -A[1]-1),  calc(A, -A[1]+1))

print(result)