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

Fixed submission:
N, Q = map(int, input().split())
S = str(input())
TD = [list(map(str, input().split())) for i in range(Q)]


def disappear(index, place):
    if index == -1:
        return (False, False)
    else:
        left = False
        right = False
        for t, d in TD:
            cur_chara = place[index]
            if t == cur_chara:
                if d == 'R':
                    index += 1
                else:
                    index -= 1
                if index < 0:
                    left = True
                    break
                elif index > N-1:
                    right = True
                    break
        return (left, right)


def binarySearch(place, direction):
    """
    :param direction; left, right
    :return: 消失する位置
    """
    start, end = -1, N
    if direction == 'left':
        while end - start > 1:
            t = start + (end - start) // 2
            if disappear(t, place)[0]:
                start = t
            else:
                end = t
        return start
    elif direction == 'right':
        while end - start > 1:
            t = start + (end - start) // 2
            if disappear(t, place)[1]:
                end = t
            else:
                start = t
        return start


left = binarySearch(S, direction='left')
right = binarySearch(S, direction='right')
print(right - left)

Buggy submission (verdict: Runtime Error):
import copy
N, Q = map(int, input().split())
s = str(input())
TD = [list(map(str, input().split())) for i in range(Q)]

# どんどん合体していくことだけはわかった
hash = {}
for i in range(N):
    if s[i] in hash.keys():
        hash[s[i]].append(i)
    else:
        hash[s[i]] = [i]

for t, d in TD:
    if d == 'R':
        r_list = [i+1 for i in hash[t]]
        hash[t] = []
        for r in r_list:
            if 0 <= r <= N-1:
                hash[s[r]].append(r)
    else:
        l_list = [i-1 for i in hash[t]]
        hash[t] = []
        for l in l_list:
            if 0 <= l <= N - 1:
                hash[s[l]].append(l)

ans = 0
for d in hash.values():
    ans += len(d)
print(ans)
Problem p03138 (python)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
bits = [0]*41
for i in range(N):
    for j in range(41):
        if A[i] & (1 << j):
            bits[40-j] += 1


bin_K = '0' * (43 - len(bin(K))) + bin(K)[2:]
x = 0
flag = 0  # 0ならX > Kが保証されていない、1なら保証されている
threshold = N // 2 + 1
for i in range(41):
    if flag == 1:
        if bits[i] < threshold:
            x += 1 << (40-i)
    elif flag == 0:
        if bits[i] < threshold and bin_K[i] == '1':
            x += 1 << (40-i)
        elif bits[i] >= threshold and bin_K[i] == '1':
            flag = 1


ans = 0
for i in range(N):
    ans += x ^ A[i]

print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
bits = [0 for i in range(41)]
for i in range(N):
    for j in range(41):
        if A[i] & (1 << j):
            bits[41-j] += 1

bin_K = '0' * (43 - len(bin(K))) + bin(K)[2:]
x = 0
flag = 0
threshold = N // 2 + 1
for i in range(41):
    if flag == 1:
        if bits[i] < threshold:
            x += 1 << (40-i)
    elif flag == 0:
        if bits[i] < threshold and bin_K[i] == '1':
            x += 1 << (40-i)
        elif bits[i] >= threshold and bin_K[i] == '1':
            flag = 1

ans = 0
for i in range(N):
    ans += x ^ A[i]
print(ans)
Problem p03160 (python)

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


dp = [0 for _ in range(N)]
dp[1] = abs(H[1] - H[0])
# dp[i] = i+1につくまでの最小のコスト
for i in range(2, N):
    dp[i] = min((dp[i-1]+abs(H[i-1]-H[i])), (dp[i-2]+abs(H[i-2]-H[i])))


print(dp[-1])

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


dp = [0 for _ in range(N)]
dp[1] = abs(H[1] - H[0])
# dp[i] = i+1につくまでの最小のコスト
for i in range(2, N):
    if i < K:
        A = [dp[i-k] + abs(H[i-k] - H[i]) for k in range(1, i+1)]
        dp[i] = min(A)
    else:
        A = [dp[i - k] + abs(H[i - k] - H[i]) for k in range(1, K+1)]
        dp[i] = min(A)


print(dp[-1])
Problem p03163 (python)

Fixed submission:
N, W = map(int, input().split())
WV = [list(map(int, input().split())) for i in range(N)]

dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
for i in range(N):
    for j in range(W+1):
        if j < WV[i][0]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - WV[i][0]] + WV[i][1])


print(dp[-1][-1])

Buggy submission (verdict: Runtime Error):
N, W = map(int, input().split())
WV = [list(map(int, input().split())) for i in range(N)]

dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
for j in range(N):
    for i in range(W + 1):
        if j < WV[i][0]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - WV[i][0]] + WV[i][1])
            
  
print(dp[-1][-1])
Problem p03164 (python)

Fixed submission:
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for i in range(N)]
dp = {0: 0}
for i in range(N):
    for j in sorted(dp.keys(), reverse=True):
        w, v = wv[i][0], wv[i][1]
        nw = dp[j] + w
        nv = j + v
        if nw <= W:
            if nv in dp:
                if nw < dp[nv]:
                    dp[nv] = nw
            else:
                dp[nv] = nw


print(max(dp.keys()))

Buggy submission (verdict: Runtime Error):
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for i in range(N)]
dp = {0: 0}
for i in range(N):
    for j in sorted(dp.keys(), reverse=True):
        w, v = wv[i][0], wv[i][1]
        nw = dp[j] + w
        nv = j + v
        if nw <= W:
            if nv < dp[nv]:
                dp[nv] = nw
        else:
            dp[nv] = nw

print(max(dp.keys()))

Buggy submission (verdict: Runtime Error):
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for i in range(N)]
dp = {0: 0}
for i in range(N):
    for j in sorted(dp.keys(), reverse=True):
        w, v = wv[i][0], wv[i][1]
        nw = dp[j] + w
        nv = j + v
        if nw <= W:
            if nv in dp:
                dp[nv] = nw
        else:
            dp[nv] = nw
            
print(max(dp.key()))
Problem p03273 (python)

Fixed submission:
H, W = map(int, input().split())
matrix = [str(input()) for i in range(H)]


matrix_1 = []
for i in range(H):
    if matrix[i] != "." * W:
        matrix_1.append(matrix[i])


matrix_2 = []
for i in range(W):
    a = ""
    for l in range(len(matrix_1)):
        a += matrix_1[l][i]
    matrix_2.append(a)


ans = []
k = len(matrix_1)
for i in range(W):
    if matrix_2[i] != "." * k:
        ans.append(matrix_2[i])


ans_2 = []
for i in range(len(ans[0])):
    a = ""
    for l in range(len(ans)):
        a += ans[l][i]
    ans_2.append(a)


for i in range(len(ans_2)):
    print(ans_2[i])

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
matrix = [str(input()) for i in range(H)]


matrix_1 = []
for i in range(H):
    if matrix[i] != "." * W:
        matrix_1.append(matrix[i])


matrix_2 = []
for i in range(W):
    a = ""
    for l in range(len(matrix_1)):
        a += matrix_1[l][i]
    matrix_2.append(a)


ans = []
k = len(matrix_1)
for i in range(W):
    if matrix_2[i] != "." * k:
        ans.append(matrix_2[i])


ans_2 = []
for i in range(len(ans)):
    a = ""
    for l in range(len(ans[0])):
        a += ans[l][i]
    ans_2.append(a)


for i in range(len(ans_2)):
    print(ans_2[i])
Problem p03281 (python)

Fixed submission:
N = int(input())

prime = [3, 5, 7, 11, 13]

# 約数が8個ということは、素因数分解した時の素因数の個数が0/7, 1/3, 1/1/1以外ありえない
zero_seven = 0
one_three = [a * (b ** 3) for a in prime for b in prime if a != b]
one_three = [i for i in one_three if i <= 200]
one_one_one = [a * b * c for a in prime for b in prime for c in prime
               if a != b and b != c and c != a]
one_one_one = [i for i in one_one_one if i <= 200]

ans = sorted(set(one_three + one_one_one))
if N <= 104:
    print(0)
elif 105 <= N <= 134:
    print(1)
elif 135 <= N <= 164:
    print(2)
elif 165 <= N <= 188:
    print(3)
elif 189 <= N <= 194:
    print(4)
elif 195 <= N:
    print(5)

Buggy submission (verdict: Runtime Error):
N = int(input())

prime = [3, 5, 7, 11, 13]

# 約数が8個ということは、素因数分解した時の素因数の個数が0/7, 1/3, 1/1/1以外ありえない
zero_seven = 0
one_three = [a * (b ** 3) for a in prime for b in prime if a != b]
one_three = [i for i in one_three if i <= 200]
one_one_oen = [a * b * c for a in prime for b in prime for c in prime
               if a != b and b != c and c != a]
one_one_oen = [i for i in one_one_oen if i <= 200]

ans = sorted(set(one_three + one_one_oen))
i = 0
if ans[-1] < N:
    print(len(ans))
else: 
    while ans[i] <= N:
        i += 1
        if ans[i] > N:
            print(i)
            quit()

print(i)

Buggy submission (verdict: Runtime Error):
N = int(input())

prime = [3, 5, 7, 11, 13]

# 約数が8個ということは、素因数分解した時の素因数の個数が0/7, 1/3, 1/1/1以外ありえない
zero_seven = 0
one_three = [a * (b ** 3) for a in prime for b in prime if a != b]
one_three = [i for i in one_three if i <= 200]
one_one_oen = [a * b * c for a in prime for b in prime for c in prime
               if a != b and b != c and c != a]
one_one_oen = [i for i in one_one_oen if i <= 200]

ans = sorted(set(one_three + one_one_oen))
i = 0
while ans[i] <= N:
    i += 1
    if ans[i] > N:
        print(i)
Problem p03282 (python)

Fixed submission:
S = list(input())
K = int(input())
if K == 1:
    print(S[0])
    quit()
    
for i in range(K):
    if S[i] != '1':
        print(S[i])
        quit()

print('1')

Buggy submission (verdict: Runtime Error):
S = str(input())
K = int(input())

if K == 1:
    print(S[0])
elif K >= 2:
    if S[0] != "1":
        print(S[0])
        quit()
    elif S[0:K] == "1" * K:
        print(S[0])
        quit()
    else:
        i = 1
        while S[i] == "1" and len(S) - 2 >= i:
            i += 1
        print(S[i])

Buggy submission (verdict: Runtime Error):
S = str(input())
K = int(input())

if K == 1:
    print(S[0])
elif K >= 2:
    if S[0] != "1":
        print(S[0])
    elif S[0:K] == "1" * K:
        print("1")
    else:
        i = 1
        while S[i] == "1" and len(S) - 2 >= i:
            i += 1
        print(S[i])

Buggy submission (verdict: Runtime Error):
S = str(input())
K = int(input())

if K == 1:
    print(S[0])
elif K >= 2:
    if S[0] != "1":
        print(S[0])
    else:
        i = 1
        while S[i] == "1":
            i += 1
        print(S[i])
Problem p03284 (python)

Fixed submission:
N, K = map(int, input().split())
if N % K == 0:
    ans = 0
else:
    ans = 1
print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
if N >= K:
    ans = N % K
else:
    ans = 1
print(b)
Problem p03287 (python)

Fixed submission:
from collections import defaultdict
N, M = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
hash = defaultdict(int)
hash[0] = 1
i = 0
for a in A:
    i = (i+a) % M
    hash[i] += 1
for h in list(hash.keys()):
    ans += hash[h] * (hash[h]-1) // 2

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
N, M = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
hash = defaultdict(int())
i = 0
for a in A:
    i = (i+a) % M
    hash[i] += 1
for h in list(hash.keys()):
    ans += hash[h] * (hash[h]-1) // 2

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
N, M = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
hash = defaultdict(int())
i = 0
for a in A:
    i = (i+a) % M
    hash[i] += 1
for h in list(hash.keys()):
    ans += hash[h] * (hash[h]-1) // 2

print(ans)

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

import numpy as np
Cumsum = np.cumsum(A)
counter = 0
for l in range(0, N):
    for r in range(l, N):
        if l == r:
            if A[l] % M == 0:
                counter += 1
        elif l != r and l == 0:
            if Cumsum[r] % M == 0:
                counter += 1
        elif l != r and l >= 1:
            if (Cumsum[r] - Cumsum[l-1]) % M == 0:
                counter += 1


print(counter)
Problem p03290 (python)

Fixed submission:
D, G = map(int, input().split())
PC = [list(map(int, input().split())) for i in range(D)]


def solve(G, i):
    if i <= 0:
        return float('inf')
    n = min(int(G/(100*i)), PC[i-1][0])
    score = 100 * i * n
    if n == PC[i-1][0]:
        score += PC[i-1][1]
    if G > score:
        n += solve(G-score, i-1)
    return min(n, solve(G, i-1))


print(solve(G, D))

Buggy submission (verdict: Runtime Error):
import unionfind
Problem p03311 (python)

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

from statistics import median
A = [a - i - 1 for i, a in enumerate(A)]
m = int(median(A))

print(sum(abs(a - m) for a in A))

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

from itertools import accumulate


ans = float("inf")
if N == 4:
    ans = min(ans, (max(A) - min(A)))
else:
    cs = accumulate(A)
    for i in range(2, N - 2):
        left_cs = cs[:i]
        right_cs = cs[i:]
        for l, v in enumerate(left_cs):
            if v + left_cs[l + 1] >= left_cs[-1]:
                P = left_cs[l]
                Q = left_cs[-1] - P
                break
        for r, v in enumerate(right_cs):
            if v + right_cs[r + 1] >= right_cs[-1]:
                R = right_cs[r]
                S = right_cs[-1] - R
                break
        ans = min(ans, (max(P, Q, R, S) - min(P, Q, R, S)))

print(ans)
Problem p03312 (python)

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

from itertools import accumulate


ans = float("inf")
if N == 4:
    ans = min(ans, (max(A) - min(A)))
else:
    cs = list(accumulate(A))
    l = 0
    r = 0
    for i in range(1, N - 2):
        while cs[i] > cs[l] + cs[l+1]:
            l += 1
        while cs[-1] + cs[i] > cs[r] + cs[r+1]:
            r += 1
        P = cs[l]
        Q = cs[i] - P
        R = cs[r] - P - Q
        S = cs[-1] - cs[r]
        ans = min(ans, (max(P, Q, R, S) - min(P, Q, R, S)))

print(ans)

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

from itertools import accumulate


ans = float("inf")
if N == 4:
    ans = min(ans, (max(A) - min(A)))
else:
    cs = accumulate(A)
    for i in range(2, N - 2):
        left_cs = cs[:i]
        right_cs = cs[i:]
        for l, v in enumerate(left_cs):
            if v + left_cs[l + 1] >= left_cs[-1]:
                P = left_cs[l]
                Q = left_cs[-1] - P
                break
        for r, v in enumerate(right_cs):
            if v + right_cs[r + 1] >= right_cs[-1]:
                R = right_cs[r]
                S = right_cs[-1] - R
                break
        ans = min(ans, (max(P, Q, R, S) - min(P, Q, R, S)))

print(ans)
Problem p03340 (python)

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

ans = 0
r = 0
xor_A = 0
for l in range(N):
    while (r < N and (xor_A ^ A[r]) == (xor_A + A[r])):
        xor_A += A[r]
        r += 1
    ans += r - l
    if l == r:
        r += 1
    else:
        xor_A -= A[l]
print(ans)

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

ans = 0
r = 0
xor_A = 0
for l in range(N):
    while (r < N and (xor_A ^ A[r]) == (xor_A + A[r])):
        r += 1
        xor_A += A[r]
    ans += r - l
    if l == r:
        r += 1
    else:
        xor_A -= A[l]
print(ans)
Problem p03361 (python)

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

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            for i in range(4):
                nh, nw = h+dx[i], w+dy[i]
                if 0 <= nh < H and 0 <= nw < W:
                    if S[nh][nw] == '#' or S[nh][nw] == 'b':
                        S[nh][nw] = 'b'
                        S[h][w] = 'b'

counter = 0
for i in range(H):
    for l in range(W):
        if S[i][l] == "#":
            counter += 1


if counter == 0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = [list(map(str, input().split())) for i in range(H)]

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]
for h in range(H):
    for w in range(W):
        if S[h][w] == '#' or 'b':
            for i in range(4):
                nh, nw = h+dx[i], w+dy[i]
                if 0 <= nh < H and 0 <= nw < W:
                    if S[nh][nw] == '#' or S[nh][nw] == 'b':
                        S[nh][nw] = 'b'
                        S[h][w] = 'b'

counter = 0
for i in range(H):
    for l in range(W):
        if S[i][l] == "#":
            counter += 1


if counter == 0:
    print("Yes")
else:
    print("No")
Problem p03402 (python)

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

white = '.'
black = '#'
grid = [[black * 100] for i in range(50)] + [[white * 100] for i in range(50)]

for i in range(A-1):
    grid[(i // 50)*2][0] = grid[(i // 50)*2][0][:(i % 50) * 2] + white + grid[(i // 50)*2][0][(i % 50) * 2 + 1:]

for i in range(B-1):
    grid[(i // 50)*2 + 51][0] = grid[(i // 50)*2 + 51][0][:(i % 50) * 2] + black + grid[(i // 50)*2 + 51][0][(i % 50) * 2 + 1:]

print(100, 100)
for g in grid:
    print(g[0])

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())

white = '.'
black = '#'
grid = [[black * 100] for i in range(50)] + [[white * 100] for i in range(50)]

for i in range(A-1):
    grid[(i % 50) * 2][0] = grid[(i % 50) * 2][0][:(i % 50) * 2] + white + grid[(i % 50) * 2][0][(i % 50) * 2 + 1:]

for i in range(B-1):
    grid[(i % 50) * 2+49][0] = grid[(i % 50) * 2+49][0][:(i % 50) * 2] + black + grid[(i % 50) * 2+49][0][(i % 50) * 2 + 1:]

print(100, 100)
for g in grid:
    print(g[0])

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())

white = '.'
black = '#'
grid = [[black * 100] for i in range(50)] + [[white * 100] for i in range(50)]

for i in range(A-1):
    grid[(i % 50) * 2][0] = grid[(i % 50) * 2][0][:(i % 50) * 2] + white + grid[(i % 50) * 2][0][(i % 50) * 2 + 1:]

for i in range(B-1):
    grid[(i % 50) * 2+49][0] = grid[(i % 50) * 2+49][0][:(i % 50) * 2] + black + grid[(i % 50) * 2+49][0][(i % 50) * 2 + 1:]

print(100, 100)
for g in grid:
    print(g)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())

white = '.'
black = '#'
grid = [[black * 100] for i in range(50)] + [[white * 100] for i in range(50)]

for i in range(A-1):
    print(grid[(i % 50) * 2][0][:(i % 50) * 2])
    grid[(i % 50) * 2][0] = grid[(i % 50) * 2][0][:(i % 50) * 2] + white + grid[(i % 50) * 2][0][(i % 50) * 2 + 1:]

for i in range(B-1):
    print(grid[(i % 50) * 2+49][0][:(i % 50) * 2])
    grid[(i % 50) * 2+49][0] = grid[(i % 50) * 2+49][0][:(i % 50) * 2] + black + grid[(i % 50) * 2+49][0][(i % 50) * 2 + 1:]

print(100, 100)
for g in grid:
    print(g)
Problem p03410 (python)

Fixed submission:
import numpy as np
bisect_left = np.searchsorted
N = input()
a = np.int32(input().split())
b = np.int32(input().split())
ans = 0
for k in range(29):
    low = pow(2, k)
    high = pow(2, k + 1)
    x = a % high
    y = b % high
    y.sort()
    y = np.hstack((y - high, y))  # 配列を横に連結
    left = bisect_left(y, low - x)
    right = bisect_left(y, high - x)
    if np.sum(right - left) % 2:
        ans += low
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
bisect_left = np.searchsorted
N = input()
a = np.int32(input().split())
b = np.int32(input().split())
ans = 0
for k in range(29):
    low = pow(2, k)
    high = pow(2, k + 1)
    x = a % high
    y = b % high
    y.sort()
    y = np.hstack((y - high, y))  # 配列を横に連結
    left = bisect_left(y, low - x)
    right = bisect_left(y, high - x)
    if np.sum(right - left) % 2:
        ans += low
print(ans)
Problem p03457 (python)

Fixed submission:
n = int(input())
travel_plan = []
for i in range(n):
    travel_plan.append(tuple(map(int, input().split())))
travel_plan = [(0, 0, 0)] + travel_plan

for i in range(n):
    t1 = travel_plan[i][0]
    x1 = travel_plan[i][1]
    y1 = travel_plan[i][2]
    t2 = travel_plan[i+1][0]
    x2 = travel_plan[i+1][1]
    y2 = travel_plan[i+1][2]
    x = abs(x1 - x2)
    y = abs(y1 - y2)
    t = t2 - t1
    if x + y > t or (x + y) % 2 != t % 2:
        print("No")
        exit()
print("Yes")

Buggy submission (verdict: Runtime Error):
n = int(input())
travel_plan = [tuple(map(int, input().split())) for i in range(n)]
travel_plan = [(0, 0, 0)] + travel_plan

for i in range(n+1):
    t1 = travel_plan[i][0]
    x1 = travel_plan[i][1]
    y1 = travel_plan[i][2]
    t2 = travel_plan[i+1][0]
    x2 = travel_plan[i+1][1]
    y2 = travel_plan[i+1][2]
    x = abs(x1 - x2)
    y = abs(y1 - y2)
    t = t2 - t1
    if x + y < t or (x + y + t) % 2:
        print("No")
        exit()
print("Yes")

Buggy submission (verdict: Runtime Error):
n = int(input())
travel_plan = list(tuple(map(int, input().split())))
travel_plan = [(0, 0, 0)] + travel_plan
for i in range(n+1):
    t1, x1, y1 = travel_plan[i][0] + travel_plan[i][1] + travel_plan[i][2]
    t2, x2, y2 = travel_plan[i+1][0] + travel_plan[i+1][1] + travel_plan[i+1][2]
    x = abs(x1 - x2)
    y = abs(y1 - y2)
    t = t2 - t1
    if x + y < t or (x + y + t) % 2:
        print("No")
        exit()
print("Yes")
Problem p03545 (python)

Fixed submission:
S = str(input())
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])


for i in range(0, 2):
    for j in range(0, 2):
        for k in range(0, 2):
            ans = ''
            if i == 0:
                AB = A + B
                ans += str(A) + '+' + str(B)
            else:
                AB = A - B
                ans += str(A) + '-' + str(B)
            if j == 0:
                ABC = AB + C
                ans += '+' + str(C)
            else:
                ABC = AB - C
                ans += '-' + str(C)
            if k == 0:
                ABCD = ABC + D
                ans += '+' + str(D)
            else:
                ABCD = ABC - D
                ans += '-' + str(D)
            if ABCD == 7:
                ans += '=7'
                print(ans)
                quit()

Buggy submission (verdict: Runtime Error):
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u32 = read();
    let a: u32 = read();
    let b: u32 = read();
    let mut ans = 0;
    for i in 1..n+1 {
        let s = i/10000+(i%10000)/1000+(i%1000)/100+(i%100)/10+(i%10);
        if s >= a && s <= b {
            ans += i
        }
    }
    println!("{}", ans);
}
Problem p03627 (python)

Fixed submission:
from collections import defaultdict


N = int(input())
A = list(map(int, input().split()))

lengthNumberDict = defaultdict(int)
for a in A:
    lengthNumberDict[a] += 1

lengthNumberList = [a for a in list(lengthNumberDict.items()) if a[1] >= 2]
lengthNumberList = sorted(lengthNumberList, key=lambda x: x[0], reverse=True)
if len(lengthNumberList) == 0:
    print(0)
    quit()
if len(lengthNumberList) == 1 and lengthNumberList[0][1] <= 3:
    print(0)
    quit()

if lengthNumberList[0][1] >= 4:
    print(lengthNumberList[0][0] ** 2)
else:
    print(lengthNumberList[0][0] * lengthNumberList[1][0])

Buggy submission (verdict: Runtime Error):
from collections import defaultdict


N = int(input())
A = list(map(int, input().split()))

lengthNumberDict = defaultdict(int)
for a in A:
    lengthNumberDict[a] += 1

lengthNumberList = [a for a in list(lengthNumberDict.items()) if a[1] >= 2]
lengthNumberList = sorted(lengthNumberList, key=lambda x: x[0], reverse=True)

if len(lengthNumberList) <= 1 and lengthNumberList[0][1] <= 3:
    print(0)
    quit()

if lengthNumberList[0][1] >= 4:
    print(lengthNumberList[0][0] ** 2)
else:
    print(lengthNumberList[0][0] * lengthNumberList[1][0])