Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
def inpl(): return list(map(int, input().split()))

N = int(input())
XY = sorted([inpl() for _ in range(N)])
D = defaultdict(int)
for i in range(N):
    for j in range(i+1, N):
        D[(XY[j][0] - XY[i][0]), (XY[j][1] - XY[i][1])] += 1
print(N - max(D.values()))

Fixed submission:
from collections import Counter, deque, defaultdict
from operator import itemgetter, xor, mul

import sys
#input = sys.stdin.readline
from sys import setrecursionlimit
setrecursionlimit(10**9)

def inpl(): return list(map(int, input().split()))
g0 = itemgetter(0)
N = int(input())
X, Y = [0]*N, [0]*N
P = []
for i in range(N):
    P.append(inpl())
P = sorted(P)
for i in range(N):
    X[i], Y[i] = P[i]

U = [(X[i]-X[j], Y[i] - Y[j])for i in range(N) for j in range(N) if i != j]
D = defaultdict(int)
for i in range(N):
    D[(X[i], Y[i])] = i+1

ans = N
for ux, uy in U:
    if ux < 0:
        continue
    tmp = 0
    searched = [0]*(N)
    for i in range(N):
        if not searched[i]:
            tmp += 1
            searched[i] = 1
        j = D[(X[i]+ux), (Y[i]+uy)]
        if j:
            searched[j-1] = 1
    ans = min(tmp, ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict, deque
import sys
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))
N = int(input())
A = sorted(inpl())

print(sum(map(abs, A[1:])) - A[0])
for i in range(N-2, 0, -1):
  a = A[i]
  if a > 0:
    print(A[0], a)
    A[0] -= a
    else:
      print(A[-1], a)
      A[-1] -= a
      print(A[-1], A[0])

Fixed submission:
from itertools import accumulate
from bisect import bisect, bisect_left
from functools import reduce
from itertools import accumulate, product
from operator import itemgetter, xor, mul
from math import sqrt
from random import randint, random
from heapq import heappop, heappush

from fractions import gcd
from collections import Counter, deque, defaultdict

import sys
input = sys.stdin.readline
from sys import setrecursionlimit
setrecursionlimit(10**9)

def inpl(): return list(map(int, input().split()))
N = int(input())
A = sorted(inpl())
l = bisect_left(A, 0)
if l == 0:
    ans = []
    for i in range(N-2, 0, -1):
        ans.append("{} {}".format(str(A[0]), str(A[i])))
        A[0] -= A[i]
    ans.append("{} {}".format(str(A[-1]), str(A[0])))
    score = A[-1] - A[0]

elif l == N:
    ans = []
    for i in range(N-1):
        ans.append("{} {}".format(str(A[-1]), str(A[i])))
        A[-1] -= A[i]
    score = A[-1]

else:
    ans = []
    for i in range(l, N-1):
        ans.append("{} {}".format(str(A[0]), str(A[i])))
        A[0] -= A[i]
    for i in range(l):
        ans.append("{} {}".format(str(A[-1]), str(A[i])))
        A[-1] -= A[i]
    score = A[-1]
print(score)
print(*ans, sep="\n")
Buggy python submission (verdict: Runtime Error):
def inpl(): return list(map(int, input().split()))
X, A = inpl()
if X < A:
    print(0)
else:
    print(10)

Fixed submission:
def inpl(): return map(int, input().split())
P, Q, R = inpl()
print(min(P+Q, Q+R, R+P))
Buggy python submission (verdict: Runtime Error):
from fractions import gcd
setrecursionlimit(10**9)

def inpl(): return list(map(int, input().split()))
N, A, B, C = inpl()

MOD = 10**9 + 7
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

size = 2*100000 + 1
g1, g2, inverse = [0]*size, [0]*size, [0]*size

g1[:2] = [1, 1] # 元テーブル
g2[:2] = [1, 1] #逆元テーブル
inverse[:2] = [0, 1] #逆元テーブル計算用テーブル
 
for i in range(2, size):
    g1[i] =  ( g1[i-1] * i ) % MOD 
    inverse[i] = (-inverse[MOD % i] * (MOD//i) ) % MOD 
    g2[i] =  (g2[i-1] * inverse[i]) % MOD

P = 0
Q = pow(100-C, 2*N, MOD)*(100-C)%MOD

for x in range(N):
    P = (P + cmb(N+x-1, x, MOD) * (N+x) * pow(100-C, N-x, MOD) * (pow(inverse[A], N-x, MOD) + pow(inverse[B], N-x, MOD)))%MOD
P = P*100*pow(A, N, MOD)*pow(B, N, MOD)%MOD

gcd_ = gcd(P, Q)
P = P//gcd_
Q = Q//gcd_

if A*B == 0:
    print(N*100*pow(100-C, MOD-2, MOD)%MOD)
else:
    print(P*pow(Q, MOD-2, MOD)%MOD)

Fixed submission:
from fractions import gcd

def inpl(): return list(map(int, input().split()))
N, A, B, C = inpl()

MOD = 10**9 + 7
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

size = 2*100000 + 1
g1, g2, inverse = [0]*size, [0]*size, [0]*size

g1[:2] = [1, 1] # 元テーブル
g2[:2] = [1, 1] #逆元テーブル
inverse[:2] = [0, 1] #逆元テーブル計算用テーブル
 
for i in range(2, size):
    g1[i] =  ( g1[i-1] * i ) % MOD 
    inverse[i] = (-inverse[MOD % i] * (MOD//i) ) % MOD 
    g2[i] =  (g2[i-1] * inverse[i]) % MOD

P = 0
Q = pow(100-C, 2*N, MOD)*(100-C)%MOD

for x in range(N):
    P = (P + cmb(N+x-1, x, MOD) * (N+x) * pow(100-C, N-x, MOD) * (pow(inverse[A], N-x, MOD) + pow(inverse[B], N-x, MOD)))%MOD
P = P*100*pow(A, N, MOD)*pow(B, N, MOD)%MOD

gcd_ = gcd(P, Q)
P = P//gcd_
Q = Q//gcd_

if A*B == 0:
    print(N*100*pow(100-C, MOD-2, MOD)%MOD)
else:
    print(P*pow(Q, MOD-2, MOD)%MOD)
Buggy python submission (verdict: Runtime Error):
def inpl(): return list(map(int, input().split()))
Q = int(input())
 
MOD = 10**6 + 3
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
 
size = MOD + 1
g1, g2, inverse = [0]*size, [0]*size, [0]*size
 
g1[:2] = [1, 1] # 元テーブル
g2[:2] = [1, 1] #逆元テーブル
inverse[:2] = [0, 1] #逆元テーブル計算用テーブル

for i in range(2, size):
    g1[i] =  ( g1[i-1] * i ) % MOD 
    inverse[i] = (-inverse[MOD % i] * (MOD//i) ) % MOD 
    g2[i] =  (g2[i-1] * inverse[i]) % MOD

for _ in range(Q):
    x, d, n = inpl()
    print((g1[n] * cmb((x*inverse[d] + n - 1)%MOD, n, MOD) * pow(d, n, MOD))%MOD)

Fixed submission:
import sys
#input = sys.stdin.readline

def inpl(): return list(map(int, input().split()))
Q = int(input())
 
MOD = 10**6 + 3
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
 
size = MOD + 1
g1, g2, inverse = [0]*size, [0]*size, [0]*size
 
g1[:2] = [1, 1] # 元テーブル
g2[:2] = [1, 1] #逆元テーブル
inverse[:2] = [0, 1] #逆元テーブル計算用テーブル

for i in range(2, size):
    g1[i] =  ( g1[i-1] * i ) % MOD 
    inverse[i] = (-inverse[MOD % i] * (MOD//i) ) % MOD 
    g2[i] =  (g2[i-1] * inverse[i]) % MOD

for _ in range(Q):
    x, d, n = inpl()
    xd = x*inverse[d]%MOD
    if d != 0:
        if n < ((MOD-x)*inverse[d] + 1)%MOD:
            n = n%MOD
            print((g1[(xd + n - 1)%MOD] * g2[(xd-1)%MOD] * pow(d, n, MOD))%MOD)
        else:
            print(0)
    else:
        print(pow(x, n, MOD))
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
def inpl(): return list(map(int, input().split()))

N, M = inpl()
A = sorted(inpl())
B, C = [], []
BC = sorted([inpl() for _ in range(M)], key=lambda x: x[1])
i = 0
while BC:
    b, c = BC.pop()
    while b:
        if A[i] < c:
            A[i] = c
            i += 1
            b -=1
        else:
            break
print(sum(A))

Fixed submission:
from itertools import accumulate
def inpl(): return list(map(int, input().split()))

N, M = inpl()
A = sorted(inpl())
BC = sorted([inpl() for _ in range(M)], key=lambda x: x[1])
i = 0
while BC:
    b, c = BC.pop()
    while b and i < N:
        if A[i] < c:
            A[i] = c
            i += 1
            b -=1
        else:
            break
print(sum(A))
Buggy python submission (verdict: Runtime Error):
setrecursionlimit(10**9)
#input = sys.stdin.readline
from itertools import accumulate
def inpl(): return list(map(int, input().split()))
MOD = 10**9 + 7
N, M, K = inpl()

X = sum([n*(n+1)//2 for n in range(1, N)])*M*(M)%MOD
Y = sum([m*(m+1)//2 for m in range(1, M)])*N*(N)%MOD


def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N*M + 1 ):
    g1.append( ( g1[-1] * i ) % MOD )
    inverse.append( ( -inverse[MOD % i] * (MOD//i) ) % MOD )
    g2.append( (g2[-1] * inverse[-1]) % MOD )

print((X+Y)*cmb(N*M-2, K-2, MOD)%MOD)


Fixed submission:
from itertools import accumulate
def inpl(): return list(map(int, input().split()))
MOD = 10**9 + 7
N, M, K = inpl()

X = sum([n*(n+1)//2 for n in range(1, N)])*M*(M)%MOD
Y = sum([m*(m+1)//2 for m in range(1, M)])*N*(N)%MOD


def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N*M + 1 ):
    g1.append( ( g1[-1] * i ) % MOD )
    inverse.append( ( -inverse[MOD % i] * (MOD//i) ) % MOD )
    g2.append( (g2[-1] * inverse[-1]) % MOD )

print((X+Y)*cmb(N*M-2, K-2, MOD)%MOD)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict, deque, Counter
def inpl(): return list(map(int, input().split()))

R, G, B, N = inpl()
ans = 0
for r in range(N//R + 1):
    for g in range(N//G + 1):
        tmp = N - R*r - G*g
        if tmp < 0:
            break
        if (tmp%B == 0):
            ans += 1
print(ans)


Fixed submission:
from collections import defaultdict, deque, Counter
def inpl(): return list(map(int, input().split()))

N, K = inpl()
print(N-K+1)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict, deque, Counter
def inpl(): return list(map(int, input().split()))

R, G, B, N = inpl()
ans = 0
for r in range(N//R + 1):
    for g in range(N//G + 1):
        tmp = N - R*r - G*g
        if tmp >= 0 and (tmp%B == 0):
            ans += 1
print(ans)

Fixed submission:
from collections import defaultdict, deque, Counter
def inpl(): return list(map(int, input().split()))

R, G, B, N = inpl()
ans = 0
for r in range(N//R + 1):
    for g in range(N//G + 1):
        tmp = N - R*r - G*g
        if tmp < 0:
            break
        if (tmp%B == 0):
            ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict, deque, Counter
from math import sqrt
def inpl(): return list(map(int, input().split()))

N = int(input())
A = inpl()
S = []
x = 0
for i in range(N):
    x ^= A[i]
    S.append(x)
if S[-1] != 0:
    print(2**(S.count(S[-1])-1))
else:
    raise

Fixed submission:
from collections import defaultdict
from math import sqrt
def inpl(): return list(map(int, input().split()))
MOD = 10**9 + 7
N = int(input())
S = []

x = 0
for a in map(int, input().split()):
    x ^= a
    S.append(x)

A = defaultdict(int)
B = defaultdict(int)
L = defaultdict(int)
Z = 0

if S[-1] != 0:
    sr = S[-1]
    a, b = 0, 0
    for s in S:
        if s == sr:
            b =  (b + a + 1)%MOD
        elif s == 0:
            a = (a + b)%MOD
    print(a+1)
else:
    for s in S:
        if s == 0:
            Z += 1
        else:
            A[s] = (A[s] + (Z - L[s])*B[s])%MOD
            B[s] = (A[s] + B[s] + 1)%MOD
            L[s] = Z
    print((sum(B.values()) + pow(2, Z-1, MOD))%MOD)
Buggy python submission (verdict: Time Limit Exceeded):

from bisect import bisect, bisect_left
from collections import defaultdict
def inpl(): return list(map(int, input().split()))

H, W = inpl()
#A = [[int(s == "#") for s in input()] for _ in range(H)]

check = set()
colored = set()
for h in range(H):
    for w, c in enumerate(input()):
        if c == "#":
            check.add((h, w))
colored.update(check)

ans = 0
while True:
    check2 = set()
    for (h, w) in check:
        for dh, dw in [(0, 1), (1, 0), (-1, 0), (0, -1)]:
            nh, nw = min(max(h+dh, 0), H-1), min(max(w+dw, 0), W-1)
            if not (nh, nw) in colored:
                check2.add((nh, nw))
    check = check2
    if len(check):
        colored.update(check)
        ans += 1
    else:
        print(ans)
        break

Fixed submission:

from collections import defaultdict, deque
def inpl(): return list(map(int, input().split()))

H, W = inpl()
searched = [[10**9]*(W+2) for _ in range(H+2)]

for h in range(H+2):
    searched[h][0] = 0
    searched[h][-1] = 0
for w in range(W+2):
    searched[0][w] = 0
    searched[-1][w] = 0

Q = deque()
for h in range(H):
    for w, c in enumerate(input()):
        if c == "#":
            searched[h+1][w+1] = 0
            Q.append((h+1, w+1, 0))

while Q:
    h, w, c = Q.popleft()
    if searched[h][w] < c:
        continue
    for dh, dw in [(0, 1), (1, 0), (-1, 0), (0, -1)]:
        nh, nw = h+dh, w+dw
        if searched[nh][nw] > c+1:
            searched[nh][nw] = c+1
            Q.append((nh, nw, c+1))

print(max(map(max, searched)))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
from collections import defaultdict
def inpl(): return list(map(int, input().split()))
N = int(input())
A = inpl()

def primes(N):
    sieve = [1]*(N+1)
    sieve[:2] = [0, 0]
    P = []
    for i in range(2, N+1):
        if sieve[i]:
            for j in range(2*i, N, i):
                sieve[j] = 0
            P.append(i)
    return P

P = primes(32000)
D = defaultdict(list)

for a in A:
    for p in P:
        cnt = 0
        while a%p==0:
            cnt += 1
            a //= p
        if cnt:
            D[p].append(cnt)
    if a > 1:
        D[a].append(1)

D = {k:[0]*(len(v) == N-1) + sorted(v) for k, v in D.items() if len(v) >= N-1}

ori = 1
for k, v in D.items():
    ori *= k**v[0]

ans = max(ori, 1)
for a in A:
    tmp = 1 * ori
    for p in D.keys():
        cnt = 0
        while a%p==0:
            cnt += 1
            a //= p
        if cnt == D[p][0]:
            tmp *= p**(D[p][1] - D[p][0])
    ans = max(ans, tmp)
print(ans)
            



Fixed submission:
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
A, B, T = inpl()
ans = 0
for i in range(1, T+1):
    if i%A == 0:
        ans += B
print(ans)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
from collections import defaultdict
from sys import setrecursionlimit
setrecursionlimit(100000)
def inpl(): return list(map(int, input().split()))
N = int(input())
A = inpl()

def calc(i):
    if i == N-2:
        return (A[i], A[i+1]), (-A[i], -A[i+1])
    else:
        X, Y = calc(i+1)
        return ([A[i], max(X[0] + X[1], Y[0] + Y[1])],
                [-A[i], max(-X[0] + X[1], -Y[0] + Y[1])])

print(max(map(sum, calc(0))))

Fixed submission:
# -*- coding: utf-8 -*-
from collections import defaultdict
from sys import setrecursionlimit
setrecursionlimit(10**9)
def inpl(): return list(map(int, input().split()))
N = int(input())
A = inpl()

def calc(i):
    if i == N-2:
        return (A[i], A[i+1]), (-A[i], -A[i+1])
    else:
        X, Y = calc(i+1)
        return ([A[i], max(X[0] + X[1], Y[0] + Y[1])],
                [-A[i], max(-X[0] + X[1], -Y[0] + Y[1])])

print(max(map(sum, calc(0))))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
from heapq import merge
from bisect import bisect
def inpl(): return list(map(int, input().split()))

X, Y, Z, K = inpl()
A = inpl()
B = inpl()
C = sorted(inpl(), reverse=True)

AB = sorted([a+b for a in A for b in B])[-K:]
ans = [-1] * K

for c in C:
    if ans[0] > AB[-1] * c:
        break
    tmp = [ab + c for ab in AB][-K:]
    ans = list(merge(ans, tmp))[-K:]

print(*ans[::-1], sep="\n")


Fixed submission:
# -*- coding: utf-8 -*-
from itertools import product
from collections import defaultdict
def inpl(): return list(map(int, input().split()))

X = [0]*6
for i in range(6):
    X[i] = int(input())
a, b, c, d, e, k = X

for l, r in product(X[:5], repeat=2):
    if abs(l-r) > k:
        print(":(")
        break
else:
    print("Yay!")
Buggy python submission (verdict: Runtime Error):
def inpl(): return list(map(int, input().split()))
from bisect import bisect
from collections import defaultdict

N, Q = inpl()
S = [ord(s) - 65 for s in input()]

X = [[] for i in range(26)]
T = [[] for i in range(26)]

for i in range(Q):
    t, d = input().split()
    q = ord(t) - 65
    X[q].append(i)
    T[q].append(d == "R")

ranswer = set()

def dig(q, x):
    #print(q, x)
    global ranswer
    s = S[x]
    if X[s][0] == q:
        ranswer.add(x)

    if x > 0:
        s = S[x-1]
        i = bisect(X[s], q-1) - 1
        if i >= 0 and T[s][i] == True:
            dig(X[s][i], x-1)
    if x < N-1:
        s = S[x+1]
        i = bisect(X[s], q-1) - 1
        if i >= 0 and T[s][i] == False:
            dig(X[s][i], x+1)

for q, t in zip(X[S[0]], T[S[0]]):
    if t == False:
        dig(q, 0)
for q, t in zip(X[S[N-1]], T[S[N-1]]):
    if t == True:
        dig(q, N-1)

print(N - len(ranswer))

Fixed submission:
def inpl(): return list(map(int, input().split()))

N, Q = inpl()
S = input()
T = [""]*(Q)
D = [-1]*(Q)
for i in range(Q):
    t, d = input().split()
    T[i] = t
    D[i] += 2*(d == "R")

def checkL(ix):
    for i in range(Q):
        if T[i] == S[ix]:
            ix += D[i]
        if ix == N:
            return True
        if ix < 0:
            return False
    return True

def checkR(ix):
    for i in range(Q):
        if T[i] == S[ix]:
            ix += D[i]
        if ix == N:
            return False
        if ix < 0:
            return True
    return True

OK = N
NG = -1
while abs(OK-NG)>1:
    mid = (OK+NG)//2
    if checkL(mid):
        OK = mid
    else:
        NG = mid

Lans = OK*1

OK = -1
NG = N
while abs(OK-NG)>1:
    mid = (OK+NG)//2
    if checkR(mid):
        OK = mid
    else:
        NG = mid
print(max(OK-Lans+1, 0))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import numpy as np
def inpl(): return list(map(int, input().split()))
N, M, C = inpl()
B = np.array(inpl(), dtype=np.int64)
ans = 0
for _ in range(N):
    A = np.array(inpl(), dtype=np.int64)
    ans += np.sum(A*B)+C > 0
print(ans)


Fixed submission:
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))

H, W = inpl()
h, w = inpl()

print(H*W - h*W - H*w + h*w)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import numpy as np
N, M, C = inpl()
B = np.array(inpl(), dtype=np.int64)
ans = 0
for _ in range(N):
    A = np.array(inpl(), dtype=np.int64)
    ans += np.sum(A*B)+C > 0
print(ans)

Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np
def inpl(): return list(map(int, input().split()))

N, M, C = inpl()
B = np.array(inpl(), dtype=np.int64).reshape(1, -1)
A = np.zeros((N, M), dtype=np.int64)

for i in range(N):
    A[i] = inpl()

print(((A*B).sum(axis=1) + C >0).sum())
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
def  inpl(): return list(map(int, input().split()))
N, M = inpl()
A = sorted(inpl())
cost = [1e9, 2, 5, 5, 4, 5, 6, 3, 7, 6]
mincost = min([cost[a] for a in A])
maxcost = max([cost[a] for a in A])

DP = [0]*N
for a in A:
    if N - cost[a] >= 0:
        DP[N-cost[a]] = a

ans = DP[0]
for j in range(N//2 + 1):
    DP2 = [0]*N
    ok = False
    for i in range(max(0, N-maxcost*(j+1)), N-mincost*j):
        v = DP[i]
        if v == 0:
            continue
        for a in A:
            nk = i - cost[a]
            if nk >= 0:
                ok = True
                DP2[nk] = max(DP2[nk], 10*v + a)
    ans = max(ans, DP2[0])
    DP = DP2
    if ok == False:
        break

print(ans)


Fixed submission:
def  inpl(): return list(map(int, input().split()))

A, B = inpl()

if B%A == 0:
    print(A+B)
else:
    print(B-A)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
def  inpl(): return list(map(int, input().split()))
N, M = inpl()
A = sorted(inpl())
cost = [1e9, 2, 5, 5, 4, 5, 6, 3, 7, 6]
mincost = min([cost[a] for a in A])
maxcost = max([cost[a] for a in A])

DP = [0]*N
for a in A:
    if N - cost[a] >= 0:
        DP[N-cost[a]] = a

ans = DP[0]
for j in range(N//2 + 1):
    DP2 = [0]*N
    for i in range(max(0, N-maxcost*(j+1)), N-mincost*j):
        v = DP[i]
        if v == 0:
            continue
        for a in A:
            nk = i - cost[a]
            if nk >= 0:
                DP2[nk] = max(DP2[nk], 10*v + a)
    ans = max(ans, DP2[0])
    DP = DP2
    if sum(DP) == 0:
        break

print(ans)


Fixed submission:
def  inpl(): return list(map(int, input().split()))

A, B = inpl()

if B%A == 0:
    print(A+B)
else:
    print(B-A)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
def  inpl(): return list(map(int, input().split()))
N, M = inpl()
A = sorted(inpl())
cost = [1e9, 2, 5, 5, 4, 5, 6, 3, 7, 6]
mincost = min([cost[a] for a in A])
maxcost = max([cost[a] for a in A])

DP = [0]*N
for a in A:
    if N - cost[a] >= 0:
        DP[N-cost[a]] = a

ans = DP[0]
for j in range(N//2 + 1):
    DP2 = [0]*N
    for i in range(max(0, N-maxcost*(j+1)), N-mincost*j):
        v = DP[i]
        if v == 0:
            continue
        for a in A:
            nk = i - cost[a]
            if nk >= 0:
                DP2[nk] = max(DP2[nk], 10*v + a)
    ans = max(ans, DP2[0])
    DP = DP2

print(ans)

Fixed submission:
def  inpl(): return list(map(int, input().split()))

A, B = inpl()

if B%A == 0:
    print(A+B)
else:
    print(B-A)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
def tqdm(iterable): return iterable
def inpl(): return list(map(int, input().split()))
MOD = 998244353

S = input()
N = len(S)
B = [0]*N
R = [0]*N

for i in range(N):
    b = int(S[i])
    B[i] = b
    R[i] = 2 - b

DP = defaultdict(int)
DP[(B[0], R[0])] = 1

for i in tqdm(range(1, N)):
    DP2 = defaultdict(int)
    b1, r1 = B[i], R[i]
    for (b0, r0), v in DP.items():
        b2, r2 = b0+b1, r0+r1
        if b0:
            DP2[(b2-1, r2)] = (DP2[(b2-1, r2)] + v)%MOD
        if r0:
            DP2[(b2, r2-1)] = (DP2[(b2, r2-1)] + v)%MOD
    DP = DP2

for _ in tqdm(range(N+1)):
    DP2 = defaultdict(int)
    for (b, r), v in DP.items():
        if b:
            DP2[(b-1, r)] = (DP2[(b-1, r)] + v)%MOD
        if r:
            DP2[(b, r-1)] = (DP2[(b, r-1)] + v)%MOD
    DP = DP2

print(sum(DP.values()))

Fixed submission:
from collections import defaultdict
def inpl(): return list(map(int, input().split()))
MOD = 998244353

S = input()
N = len(S)
B = [0]*N
R = [0]*N

for i in range(N):
    b = int(S[i])
    B[i] = b
    R[i] = 2 - b

DP = defaultdict(int)
DP[(B[0], R[0])] = 1

for i in range(1, N):
    DP2 = defaultdict(int)
    b1, r1 = B[i], R[i]
    for (b0, r0), v in DP.items():
        b2, r2 = b0+b1, r0+r1
        if b0:
            DP2[(b2-1, r2)] = (DP2[(b2-1, r2)] + v)%MOD
        if r0:
            DP2[(b2, r2-1)] = (DP2[(b2, r2-1)] + v)%MOD
    DP = DP2

for _ in range(N+1):
    DP2 = defaultdict(int)
    for (b, r), v in DP.items():
        if b:
            DP2[(b-1, r)] = (DP2[(b-1, r)] + v)%MOD
        if r:
            DP2[(b, r-1)] = (DP2[(b, r-1)] + v)%MOD
    DP = DP2

print(sum(DP.values()))
Buggy python submission (verdict: Runtime Error):
from collections import deque
def inpl(): return list(map(int, input().split()))

N, M = inpl()
G = {i:[] for i in range(N)}
X = [0]*(N)
searched = [0]*(N)
pairents = [-1]*N

for _ in range(N-1+M):
    a, b = inpl()
    G[a-1].append(b-1)
    X[b-1] += 1

q = X.index(0)

Q = deque([q])
while Q:
    p = Q.popleft()
    for q in G[p]:
        if searched[q] <= searched[p]:
            searched[q] = searched[p] + 1
            Q.append(q)

for a in range(N):
    for b in G[a]:
        if searched[b] == searched[a] + 1:
            pairents[b] = a
for p in pairents:
    print(p+1)
    


Fixed submission:
from string import ascii_lowercase
def inpl(): return list(map(int, input().split()))
N, A, B = inpl()
if A + B <= N:
    C = 0
else:
    abs(A - B)

print(min(A, B), max(A + B - N, 0))