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

Fixed submission:
import sys

rr = lambda: sys.stdin.readline().rstrip()

s = list(rr())
cnt = 0
for i in range(len(s)-1):
  si = s[i]
  si1 = s[i+1]
  if si == si1:
    if si == '0':
      s[i+1] = '1'
    else:
      s[i+1] = '0'
    cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
import sys

rr = lambda: sys.stdin.readline().rstrip()

s = rr()
cnt = 0
for i in range(len(s) - 1):
  si = s[i]
  si1 = s[i+1]
  if si & si1:
    continue
  else:
    s[i+1] = si
    cnt += 1
print(cnt)
Problem p03127 (python)

Fixed submission:
import math
from functools import reduce
_=input()
print(reduce(math.gcd,map(int,input().split())))

Buggy submission (verdict: Runtime Error):
import math
print(reduce(math.gcd,map(int,input().split())))
Problem p03315 (python)

Fixed submission:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

s = rr()
ans = 0
for i in s:
  if i == '+':
    ans += 1
  else:
    ans -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

s = rr()
ans = 0
for i in s:
  ans += 1 if i == '+' else ans -= 1
print(ans)
Problem p03631 (python)

Fixed submission:
s=input()
print('YNeos'[s[0]!=s[2]::2])

Buggy submission (verdict: Runtime Error):
s=rr()
print('YNeos'[s[0]!=s[2]::2])
Problem p02580 (python)

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline

    H, W, M = map(int, input().split())

    H_list = [[0, i] for i in range(H + 1)] 
    W_list = [[0, i] for i in range(W + 1)] 


    S = set()
    S_add = S.add
    INF = 10 ** 6

    for _ in range(M):
        a, b = map(int, input().split())
        tmp = INF * a + b
        S_add(tmp)
        H_list[a][0] += 1
        W_list[b][0] += 1

    ans = 0
    H_list.sort(reverse=True)
    W_list.sort(reverse=True)

    tmp_H = H_list[0][0]
    tmp_W = W_list[0][0]
    tmp_ans = tmp_H + tmp_W

    for h in range(H):
        if H_list[h][0] + 1 < tmp_H:
            continue
        h_ = H_list[h][1]
        H_ = H_list[h][0]
        for w in range(W):
            if W_list[w][0] + H_ + 1 < tmp_ans:
                break
            w_ = W_list[w][1]
            tmp = H_ + W_list[w][0]
            if INF * h_ + w_ in S:
                tmp -= 1
            ans = max(ans, tmp)
            if ans == tmp_ans:
                print (ans)
                return

    print (ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

H, W, M = map(int, input().split())

H_list = [[0, i] for i in range(H + 1)] 
W_list = [[0, i] for i in range(W + 1)] 


G = [[0] * (W + 1) for _ in range(H + 1)]


for _ in range(M):
    a, b = map(int, input().split())
    G[a][b] = 1
    H_list[a][0] += 1
    W_list[b][0] += 1

ans = 0
H_list.sort(reverse=True)
W_list.sort(reverse=True)

tmp_H = H_list[0][0]
tmp_W = W_list[0][0]

for h in range(H):
    if H_list[h][0] + 2 < tmp_H:
        continue
    h_ = H_list[h][1]
    for w in range(W):
        if W_list[w][0] + 2 < tmp_W:
            break
        w_ = W_list[w][1]
        tmp = H_list[h][0] + W_list[w][0] - G[h_][w_]
        ans = max(ans, tmp)

print (ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

H, W, M = map(int, input().split())

H_list = [0] * (H + 1)
W_list = [0] * (W + 1)


G = [[0] * (W + 1) for _ in range(H + 1)]


for _ in range(M):
    a, b = map(int, input().split())
    G[a][b] = 1
    H_list[a] += 1
    W_list[b] += 1

ans = 0
for h in range(1, H + 1):
    for w in range(1, W + 1):
        tmp = H_list[h] + W_list[w] - G[h][w]
        ans = max(ans, tmp)

print (ans)
Problem p02659 (python)

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

a = int(A)
N = len(B)
b = 100 * int(B[:N - 3]) + int(B[N - 2:])

# print (a, b)

ans = a * b // 100

print (ans)

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

def check(lst):
    # print (set(lst))
    if (N == lst[0]) and (len(set(lst[:-1])) == 1):
        return True
    else:
        return False

def move(lst):
    tmp = [0] * (N + 1)
    for i in range(N):
        a = lst[i]
        left = max(0, i - a)
        right = min(N, i + a + 1)
        tmp[left] += 1
        tmp[right] -= 1
    for i in range(N):
        tmp[i + 1] += tmp[i]
    return tmp

for i in range(K):
    A = move(A)
    if check(A):
        # print (i)
        break

print (*A[:-1])
Problem p02661 (python)

Fixed submission:
N = int(input())

A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

A.sort()
B.sort()

if N % 2 == 1:
    ans = B[N // 2] - A[N // 2] + 1
    print (ans)
else:
    a = (A[N // 2 - 1] + A[N // 2])
    b = (B[N // 2 - 1] + B[N // 2])
    print (b - a + 1)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left

N = int(input())

AB = [tuple(map(int, input().split())) for _ in range(N)]
ALL = []
ALL_append = ALL.append
for a, b in AB:
    ALL_append(a)
    ALL_append(b)

ALL.sort()
dic = dict()
for i, x in enumerate(ALL):
    dic[x] = i

lst1 = [0] * (2 * N + 1)
lst2 = [0] * (2 * N + 1)

for a, b in AB:
    lst1[dic[a]] += 1
    lst2[dic[b]] -= 1

for i in range(2 * N):
    lst1[i + 1] += lst1[i]
    lst2[2 * N - 1 - i] += lst2[2 * N - i]

# print (lst1)
# print (lst2)

if N % 2 == 1: #奇数 -->一意に決まる時
    left = bisect_left(lst1, N // 2 + 0.5)
    right = bisect_left(lst2, -((N) // 2) - 0.5) - 1
    # print (left, right)
    upper = ALL[right]
    lower = ALL[left]
    print (upper - lower + 1)
else:
    left = bisect_left(lst1, N // 2 - 0.5)
    right = bisect_left(lst2, -(N // 2) - 0.5)
    # print (left, right)
    upper = ALL[right]
    lower = ALL[left]
    print (upper - lower + 1)
Problem p02693 (python)

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

for i in range(A, B + 1):
    if i % K == 0:
        print ('OK')
        exit()

print ('NG')

Buggy submission (verdict: Runtime Error):
N, M, Q = map(int, input().split())
ABCD = [tuple(map(int, input().split())) for _ in range(Q)]

stack = [i for i in range(1, M + 1)]

for i in range(N - 1):
    tmp = []
    while stack:
        now = stack.pop()
        start = now % 10
        for i in range(start, M + 1):
            tmp.append(now * 10 + i)
    stack = tmp

ans = 0
for tmp in stack:
    point = 0
    tmp1 = str(tmp)
    for a, b, c, d in ABCD:
        if int(tmp1[b - 1]) - int(tmp1[a - 1]) == c:
            point += d
    ans = max(ans, point)

print (ans)
# print (stack)
Problem p02729 (python)

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

ans = (N * (N - 1) // 2) + (M * (M - 1) // 2)

print (ans)

Buggy submission (verdict: Runtime Error):
MOD = 998244353

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

DP = [[[0] * 3 for _ in range(S + 1)] for _ in range(N + 1)]
DP[0][0][0] = 1

for i in range(N):
    DP[i + 1][0][0] = DP[i][0][0] 
    a = A[i]
    for j in range(S + 1):
        if j == 0: #左側を決めて合計0になるのは、
            # DP[i + 1][j][0] = DP[i][j][0] 
            DP[i + 1][j][1] = DP[i][j][0] + DP[i][j][1]
        elif j < a: #左側を決めて合計jになるとき、ただしaはjより大きいので使えない
            # DP[i + 1][j][0] = DP[i][j][0] 
            DP[i + 1][j][1] = DP[i][j][0] + DP[i][j][1] #以前から合計jになっている場合のみOK
        else: #左側を決めて合計j > aになるとき, aだけでは足りない = 左側はこれより前で決まっている
            DP[i + 1][j][1] = DP[i][j][0] + DP[i][j][1] + DP[i][j - a][0] + DP[i][j - a][1]
        # DP[i + 1][j][0] %= MOD
        DP[i + 1][j][0] %= MOD
    DP[i + 1][S][2] = DP[i][S][1] + DP[i][S][2]
    if a <= S:
        DP[i + 1][S][2] += DP[i][S - a][0] + DP[i][S - a][1]
    DP[i + 1][S][2] %= MOD

print (DP[N][S][2])

# for i in range(N + 1):
#     print (DP[i])
Problem p02757 (python)

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

if P != 2 and P != 5:
    count = [0] * P
    ans = 0
    tmp = 0
    for i in range(N - 1, -1, -1):
        tmp += int(S[i]) * pow(10, (N - 1 - i), P)
        tmp %= P
        ans += count[tmp]
        count[tmp] += 1
    ans += count[0]

    # print (count)
    print (ans)

if P == 2:
    count = 0
    for index, s in enumerate(S):
        if int(s) % 2 == 0:
            count += (index + 1)
    print (count)

if P == 5: 
    count = 0
    for index, s in enumerate(S):
        if int(s) % 5 == 0:
            count += (index + 1)
    print (count)

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

if P != 2 and P != 5:
    count = [0] * P
    count[0] = 1
    lst = [0] * (N + 1)
    for i in range(N):
        lst[i + 1] = ((lst[i] * 10) + int(S[i])) % P
        count[lst[i + 1]] += 1

    # print (count)
    ans = 0
    for i in count:
        ans += (i * (i - 1)) // 2

    print (ans)

if P == 2:
    count = 0
    for index, s in enumerate(S):
        if int(s) % 2 == 0:
            count += (index + 1)
    print (count)
    A

if P == 5: 
    count = 0
    for index, s in enumerate(S):
        if int(s) % 5 == 0:
            count += (index + 1)
    print (count)
    A
Problem p02793 (python)

Fixed submission:
def main():
    from fractions import gcd

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

    MOD = 10 ** 9 + 7

    tmp = 1
    for a in A:
        tmp *= a // gcd(tmp, a)

    ans = 0
    for a in A:
        ans += tmp // a
    ans %= MOD

    print (ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from fractions import gcd

MOD = 10 ** 9 + 7

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

tmp = 1
for a in A:
    tmo *= a // gcd(tmp, a)

ans = 0
for a in A:
    ans += (tmp // a) % MOD
    ans %= MOD

print (ans)

Buggy submission (verdict: Runtime Error):
from fractions import gcd

MOD = 10 ** 9 + 7

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

tmp = 1
for a in A:
    tmo *= a // gcd(tmp, a)

ans = 0
for a in A:
    ans += (tmp // a) MOD
    ans %= MOD

print (ans)

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

MOD = 10 ** 9 + 7

N = int(input())

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

B = [1] * (N + 1)

for index, a in enumerate(A):
    tmp = gcd(B[index], a)
    B[index + 1] = B[index] * a // tmp

C = [1] * (N + 1)
for i in range(N - 1, -1, -1):
    tmp =gcd(C[i + 1], A[i])
    C[i] = C[i + 1] * A[i] // tmp

# print (B)
# print (C)

ans = 0
for i in range(N):
    tmp1 = gcd(B[i], C[i + 1])
    tmp2 = B[i] * C[i + 1] // tmp1

    tmp3 = gcd(tmp2, A[i])
    tmp4 = tmp2 * A[i] // tmp3

    ans += (tmp4 // A[i] % MOD)
    ans %= MOD

    # print (ans)

print (ans)

Buggy submission (verdict: Runtime Error):
from math import gcd

MOD = 10 ** 9 + 7

N = int(input())

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

B = [1] * (N + 1)

for index, a in enumerate(A):
    tmp = gcd(B[index], a)
    B[index + 1] = B[index] * a // tmp

C = [1] * (N + 1)
for i in range(N - 1, -1, -1):
    tmp =gcd(C[i + 1], A[i])
    C[i] = C[i + 1] * A[i] // tmp

# print (B)
# print (C)

ans = 0
for i in range(N):
    tmp1 = gcd(B[i], C[i + 1])
    tmp2 = B[i] * C[i + 1] // tmp1

    tmp3 = gcd(tmp2, A[i])
    tmp4 = tmp2 * A[i] // tmp3

    ans += (tmp4 // A[i] % MOD)
    ans %= MOD

    # print (ans)

print (ans)
Problem p02831 (python)

Fixed submission:
from fractions import gcd

A, B = map(int, input().split())

lcm = (A * B) // gcd(A, B)

print (lcm)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

from math import gcd

A, B = map(int, input().split())

print (A * B // gcd(A, B))
Problem p02862 (python)

Fixed submission:
import math
MOD = 10 ** 9 + 7

X, Y = map(int, input().split())

if (X + Y) % 3 != 0:
    print (0)
    exit()

x = X - (X + Y) // 3
y = Y - (X + Y) // 3

if x < 0 or y < 0:
    print (0)
    exit()

if x < y:
    x, y = y, x

# tmp = math.factorial(y)
tmp = 1
for i in range(1, y + 1):
    tmp *= i
    tmp %= MOD

ans = 1
for i in range(x + 1, x + y + 1):
    ans *= i
    ans %= MOD

def modinv(a, m): #mod. m でのaの逆元 a^{-1}を計算する
    b = m
    u = 1
    v = 0
    while b:
        t = a//b
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    
    u %= m
    if u < 0:
        u += m
    return u

tmp = modinv(tmp, MOD)

ans *= tmp

ans %= MOD

print (ans)

# print (x, y)

Buggy submission (verdict: Runtime Error):
import math
MOD = 10 ** 9 + 7

X, Y = map(int, input().split())

if (X + Y) % 3 != 0:
    print (0)
    exit()

x = X - (X + Y) // 3
y = Y - (X + Y) // 3

if x < y:
    x, y = y, x

tmp = math.factorial(y)

ans = 1
for i in range(x + 1, x + y + 1):
    ans *= i
    ans %= MOD

def modinv(a, m): #mod. m でのaの逆元 a^{-1}を計算する
    b = m
    u = 1
    v = 0
    while b:
        t = a//b
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    
    u %= m
    if u < 0:
        u += m
    return u

tmp = modinv(tmp, MOD)

ans *= tmp

ans %= MOD

print (ans)

Buggy submission (verdict: Runtime Error):
import math
MOD = 10 ** 9 + 7

X, Y = map(int, input().split())

if (X + Y) % 3 != 0:
    print (0)
    exit()

x = X - (X + Y) // 3
y = Y - (X + Y) // 3

if x < y:
    x, y = y, x

tmp = math.factorial(y)

ans = 1
for i in range(x + 1, x + y + 1):
    ans *= i

ans //= tmp

ans %= MOD

print (ans)
Problem p02891 (python)

Fixed submission:
S = list(input())
K = int(input())

n = len(S)
start = 0
i = 0
while i < n and S[0] == S[i]:
    start += 1
    i += 1

if i == n:
    print ((n * K) // 2)
    exit()

lst = [start]
count = 1
tmp = i
i += 1
while i < n:
    if S[tmp] == S[i]:
        count += 1
        i += 1
    else:
        lst.append(count)
        count = 1
        tmp = i
        i += 1

lst.append(count)
# print (lst)
if S[0] != S[-1]:
    ans = 0
    for i in lst:
        ans += i // 2
    print (ans * K)
else:
    ans = (lst[0] + lst[-1]) // 2
    for i in lst[1:-1]:
        ans += i //2
    ans *= (K - 1)
    # print (ans)
    for i in lst:
        ans += i //2
    print (ans)

Buggy submission (verdict: Runtime Error):
import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

S = list(input())
K = int(input())

N = len(S)

T = S + S

count1 = 0
for i in range(N - 1):
    if T[i] == T[i + 1]:
        T[i + 1] = '*'
        count1 += 1

count2 = 0
if K >= 2:
    for i in range(N - 1, 2 * N - 1):
        if T[i] == T[i + 1]:
            T[i + 1] = '*'
            count2 += 1
    ans = (count1 + count2) * (K // 2) + count1 * (K % 2)
    if T[0] == T[-1]:
        ans += (K // 2) - 1
    if K % 2 == 1 and T[-1] == T[0] and T[N - 1] == T[0]:
        ans += 1
    print (ans)

else:
    print (error)
    print (count1)

# print (T)
Problem p03018 (python)

Fixed submission:
#再帰回数が多すぎてエラー
import sys

sys.setrecursionlimit(210000)
S = list(input()) + ['D']*100
N = len(S)-10

# print (S)
# print (N)

memo = [-1] * (N+100) 

# print (memo)

def check(k):
    if memo[k] != -1:
        return memo[k]
    if S[k+1] == 'B' and S[k+2] == 'C':
        memo[k] = check(k+2) + 1
        return memo[k]
    if S[k+1] == 'A':
        memo[k] = check(k+1)
        return memo[k]
    memo[k] = 0
    return memo[k]

ans = 0
for i in range(N):
    if S[i] =='A':
        ans += check(i)
print (ans)

Buggy submission (verdict: Runtime Error):
#再帰回数が多すぎてエラー

S = list(input()) + ['D']*100
N = len(S)-10

# print (S)
# print (N)

memo = [-1] * (N+100) 

# print (memo)

def check(k):
    if memo[k] != -1:
        return memo[k]
    if S[k+1] == 'B' and S[k+2] == 'C':
        memo[k] = check(k+2) + 1
        return memo[k]
    if S[k+1] == 'A':
        memo[k] = check(k+1)
        return memo[k]
    memo[k] = 0
    return memo[k]

ans = 0
for i in range(N):
    if S[i] =='A':
        ans += check(i)
print (ans)

Buggy submission (verdict: Runtime Error):
S = list(input()) + ['D']*100
N = len(S)-10
# print (S)
# print (N)
memo = [-1] * (N+100) 
# print (memo)

def check(k):
    if memo[k] != -1:
        return memo[k]
    if S[k+1] == 'B' and S[k+2] == 'C':
        memo[k] = check(k+2) + 1
        return memo[k]
    if S[k+1] == 'A':
        memo[k] = check(k+1)
        return memo[k]
    memo[k] = 0
    return memo[k]

ans = 0
for i in range(N):
    if S[i] =='A':
        ans += check(i)
print (ans)

Buggy submission (verdict: Runtime Error):
S = list(input()) + ['D']*10
N = len(S)-10
# print (S)
# print (N)
memo = [-1] * (N+10) 
# print (memo)

def check(k):
    if memo[k] != -1:
        return memo[k]
    if S[k+1] == 'B' and S[k+2] == 'C':
        memo[k] = check(k+2) + 1
        return memo[k]
    if S[k+1] == 'A':
        memo[k] = check(k+1)
        return memo[k]
    return 0

ans = 0
for i in range(N):
    if S[i] =='A':
        ans += check(i)
print (ans)
Problem p03053 (python)

Fixed submission:
import numpy as np

H, W = map(int, input().split())
max_value = H + W #左上から右下までの最大手数
matrix = []

#黒の場合0, それ以外の場合、max_valueを代入したリストを作成-->arrayへ変換
for _ in range(H):
    matrix.append([0 if i == '#' else max_value for i in list(input())])
matrix = np.array(matrix)

for c in range(W-1):#y座標を増やしていく
    matrix[:,c+1] = np.minimum(matrix[:,c]+1, matrix[:,c+1]) #一個左+1　と　自分自身の値　の小さい方
#print (matrix)
for c in range(W-1,0,-1):
    matrix[:,c-1] = np.minimum(matrix[:,c]+1, matrix[:,c-1]) #一個右+1　と　自分自身の値　の小さい方
#print (matrix)
for c in range(H-1):
    matrix[c+1,:] = np.minimum(matrix[c,:]+1, matrix[c+1,:]) #一個下+1　と　自分自身の値　の小さい方　
#print (matrix)
for c in range(H-1,0,-1):
    matrix[c-1,:] = np.minimum(matrix[c,:]+1, matrix[c-1,:]) #一個上+1　と　自分自身の値　の小さい方
#print (matrix)
print (np.max(matrix))

Buggy submission (verdict: Runtime Error):
#入力
H, W = map(int, input().split())

lst = []
for i in range(H):
    lst += [list(input())]

#print (lst)
INF = 10 ** 9
dp =[[INF] * W for _ in range(H)]

def bfs1(i, j): #右下向き
#    print ('i, j= ', i, j)
    if i < 0 or i == W or j < 0 or j == H:
        return INF
    elif lst[i][j] == '#':
        dp[i][j] = 0
        return 0
    else:
        a = min(bfs1(i+1, j)+1, bfs1(i, j+1)+1)
        dp[i][j] = a
        return a

def bfs2(i, j): #左上向き
#    print ('i, j= ', i, j)
    if i < 0 or i == W or j < 0 or j == H:
        return INF
    elif lst[i][j] == '#':
        return 0
    else:
        b = min(bfs2(i-1, j)+1, bfs2(i, j-1)+1, dp[i][j])
        dp[i][j] = b
        return b


ans1 = INF
ans2 = INF
for x in range(W):
    for y in range(H):
        bfs1(x,y)

for v in range(W):
    for w in range(H):
        bfs2(W-1-v, H-1-w)

c = 0
for a in range(W):
    b = max(dp[a])
    c =max(b, c)
print (c)
#print (ans1)
#print (ans2)

#print ('ans= ', min(ans1, ans2))
#print (min(ans1, ans2))

Buggy submission (verdict: Runtime Error):
#入力
H, W = map(int, input().split())

lst = []
for i in range(H):
    lst += [list(input())]

#print (lst)
INF = 10 ** 9
#dp =[[INF] * W for _ in range(H)]

def bfs1(i, j): #右下向き
#    print ('i, j= ', i, j)
    if i < 0 or i == W or j < 0 or j == H:
        return 0
    elif lst[i][j] == '#':
        return 0
    else:
        return min(bfs1(i+1, j)+1, bfs1(i, j+1)+1)

def bfs2(i, j): #左上向き
#    print ('i, j= ', i, j)
    if i < 0 or i == W or j < 0 or j == H:
        return 0
    elif lst[i][j] == '#':
        return 0
    else:
        return min(bfs2(i-1, j)+1, bfs2(i, j-1)+1)


ans1 = 0
ans2 = 0
for x in range(W):
    for y in range(H):
        ans1 = max(ans1, bfs1(x,y))
#        print (ans1)
        ans2 = max(ans2, bfs2(W-1-x, H-1-y))

#print (ans1)
#print (ans2)

#print ('ans= ', min(ans1, ans2))
print (min(ans1, ans2))
Problem p03108 (python)

Fixed submission:
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]

class UnionFind(object):
    def __init__(self, N):
        self.parent = [-1] * (N)
    
    #Aがどのグループに属しているかを調べる
    def root(self, A):
        if self.parent[A-1] < 0:
            return A
        self.parent[A-1] = self.root(self.parent[A-1])
        return self.parent[A-1]

    #自分がいるグループのチュ点数を調べる    
    def size(self, A):
        return -1 * self.parent[self.root(A)-1]
    
    #AとBをくっ付ける
    def connect(self, A, B):
        A = self.root(A)
        B = self.root(B)
        if A == B:
            return False
        #大きい方(A)に小さい方(B)をくっつけたい
        #大小が逆であればひっくり返す
        if self.size(A) < self.size(B):
            A, B = B, A
        
        self.parent[A-1] += self.parent[B-1]
        self.parent[B-1] = A
        return True

ans = [0] * M
ans[M-1] = N * (N-1) //2
uni = UnionFind(N)
for i in range(M-1, 0, -1):
    if uni.root(ab[i][0]) != uni.root(ab[i][1]):
        ans[i-1] = ans[i] - uni.size(ab[i][0]) * uni.size(ab[i][1])
        uni.connect(ab[i][0], ab[i][1])
    else:
        ans[i-1] = ans[i]


for i in ans:
    print (i)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]

class UnionFind(object):
    def __init__(self, N):
        self.parent = [-1] * (N)
    
    #Aがどのグループに属しているかを調べる
    def root(self, A):
        if self.parent[A-1] < 0:
            return A
        self.parent[A-1] = self.root(self.parent[A-1])
        return self.parent[A-1]

    #自分がいるグループのチュ点数を調べる    
    def size(self, A):
        return self.parent[self.root(A)-1]
    
    #AとBをくっ付ける
    def connect(self, A, B):
        A = self.root(A)
        B = self.root(B)
        if A == B:
            return False
        #大きい方(A)に小さい方(B)をくっつけたい
        #大小が逆であればひっくり返す
        if self.size(A) < self.size(B):
            A, B = B, A
        
        self.parent[A-1] += self.parent[B-1]
        self.parent[B-1] = A
        return True

ans = [0] * M
ans[M-1] = N * (N-1) //2
uni = UnionFind(N)
for i in range(M-1, 0, -1):
    if uni.root(ab[i][0]) != uni.root(ab[i][1]):
        ans[i-1] = ans[i] - uni.size(ab[i][0]) * uni.size(ab[i][1])
        uni.connect(ab[i][0], ab[i][1])


for i in ans:
    print (i)
Problem p03137 (python)

Fixed submission:
import sys
#入力
N, M = map(int, input().split())

lst = list(map(int, input().split()))

lst.sort()
#print (lst)

sa = []

for i in range(M-1):
    sa += [abs(lst[i] - lst[i+1])]

sa.sort(reverse = True)
#print(sa)

ans = -(lst[0] - lst[M-1])
#print (ans)
if not sa ==[]:
    if N <= M:
        for j in range(N-1):
            ans -= sa[j]
    else:
        ans = 0
print (ans)

Buggy submission (verdict: Runtime Error):
import sys
#入力
N, M = map(int, input().split())

lst = list(map(int, input().split()))

lst.sort()

sa = []

for i in range(M-1):
    sa += [abs(lst[i] - lst[i+1])]

sa.sort(reverse = True)

ans = -(lst[0] - lst[M-1])
#print (ans)
if not sa ==[]:
    for j in range(N-1):
        ans -= sa[j]
print (ans)

Buggy submission (verdict: Runtime Error):
import sys
#入力
N, M = map(int, input().split())

lst = list(map(int, input().split()))

lst.sort()

if M == 1:
    print (0)
    sys.exit()

sa = []

for i in range(M-1):
    sa += [abs(lst[i] - lst[i+1])]

sa.sort(reverse = True)

ans = -(lst[0] - lst[M-1])
#print (ans)
for j in range(N-1):
    ans -= sa[j]
print (ans)
Problem p03286 (python)

Fixed submission:
N = int(input())

S = str()
a = True
count = 1
memo = 0
while a:
    amari = N%(2 ** count)
#    print ('amari', amari)
    if (amari- memo) == 2 ** (count-1):
        s = 1
    else:
        s = 0
    memo = memo + s * (-2) **(count-1)
#    print ('momo', memo)
    S = str(s) + S
    count += 1
    if memo == N:
        print (S)
        a = not a

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

S = str()
count = 1
memo = 0
while a:
    amari = N%(2 ** count)
#    print ('amari', amari)
    if (amari- memo) == 2 ** (count-1):
        s = 1
    else:
        s = 0
    memo = memo + s * (-2) **(count-1)
#    print ('momo', memo)
    S = str(s) + S
    count += 1
    if memo == N:
        print (S)
        a = not a