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

Fixed submission:
import sys
from pprint import pprint

from collections import deque

h, w = map(int, sys.stdin.readline().strip().split(" "))
field = []
for _ in range(h):
    field.append(list(sys.stdin.readline().strip()))

# pprint(field)

q = deque()
for i in range(h):
    for j in range(w):
        if field[i][j] == "#":
            q.append((0, i, j))

while q:
    count, y, x = q.popleft()
    for dy, dx in ((-1, 0), (1, 0), (0, 1), (0, -1)):
        if 0 <= y+dy < h and 0 <= x+dx < w:
            # print(y+dy, x+dx, field[y+dy][x+dx])
            if field[y+dy][x+dx] == "#":
                continue
            else:
                field[y+dy][x+dx] = "#"
                q.append((count+1, y+dy, x+dx))

# pprint(field)
print(count)

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque

H, W = map(int, sys.stdin.readline().split())
grid = [["#"] * (W+2)]
for _ in range(H):
    grid.append(["#"] + list(sys.stdin.readline().strip()) + ["#"])
grid.append(["#"] * (W+2))
# print(grid)

q = deque()
for j in range(1, H+1):
    for i in range(1, W+1):
        if grid[i][j] == "#":
            q.append((i, j, 0))

ans = 0
while q:
    x, y, count = q.popleft()
    for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        if grid[x+dx][y+dy] != ".":
            continue
        grid[x+dx][y+dy] = count + 1
        ans = count + 1
        q.append((x+dx, y+dy, count + 1))

# print(grid)
print(ans)
Problem p02629 (python)

Fixed submission:


def main():
    N = int(input())
    digits = []

    while N != 0:
        digits.append(N % 26)
        if digits[-1] == 0:
            digits[-1] = 26
            N //= 26
            N -= 1
        else:
            N //= 26
    digits.reverse()
    for d in digits:
        print(chr(96 + d), end='')
    print()  # 改行


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
"""
手順
1. 必要になる桁数を求め，アルファベットの順番を保存するリスト「ans」を作成する
2. 
"""


N = int(input())  # 変換したい10進数の値
K = 26  # 進数

al = [chr(i) for i in range(97, 97+K)]


def change(N):
    # 手順１の実装
    keta = 0
    # 桁が切り替わる時は26のi乗の時ではなく26のi乗にそれまでの数値を足したものである
    # tmpはi-1乗までの数値を記録する変数として使用
    tmp = 0
    for i in range(10**9):
        if N < K**i + tmp:
            keta = i
            break
        tmp += K**i
    ans = [0] * keta  # 桁数の配列を準備する
    print(tmp)
    # print(ans)  # デバッグ用

    # 手順2の実装
    check = 0
    for i in range(1, keta+1):
        j = N // (K ** (keta - i))
        print(j, N - (j * (K ** (keta - i))))
        if i != keta and N - (j * (K ** (keta - i))) < tmp:
            j -= 1
        if j == 27:
            j -= 1
        N -= j * (K ** (keta - i))
        tmp -= K**(keta - i)
        ans[check] = j
        check += 1
    # print(ans)
    return ans


for i in change(N):
    print(al[i-1], end='')

Buggy submission (verdict: Runtime Error):
"""
手順
1. 必要になる桁数を求め，アルファベットの順番を保存するリスト「ans」を作成する
2. 
"""


N = int(input())  # 変換したい10進数の値
K = 26  # 進数

al = [chr(i) for i in range(97, 97+K)]


def change(N):
    # 手順１の実装（元のプログラムから手を入れてます）
    keta = 0
    # 桁が切り替わる時は26のi乗の時ではなく26のi乗にそれまでの数値を足したものである
    # tmpはi-1乗までの数値を記録する変数として使用
    tmp = 0
    for i in range(10**9):
        if N < K**i + tmp:
            keta = i
            break
        tmp += K**i
    ans = [0] * keta  # 桁数の配列を準備する
    # print(ans)  # デバッグ用

    # 手順2の実装
    check = 0
    for i in range(1, keta+1):
        j = N // (K ** (keta - i))
        if j * (K ** (keta - i)) == N and i != keta:
            j -= 1
        N -= j * (K**(keta-i))
        ans[check] = j
        check += 1
    return ans


for i in change(N):
    print(al[i-1], end='')

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

N=int(input())#変換したい10進数の値
K=26#進数

al = [chr(i) for i in range(97, 97+K)]

def change(N):
    keta=0
    # 桁数を求める
    tmp = 0
    for i in range(10**9):
        if N < K**i + tmp:
             keta = i
             break
        tmp += K**i
    ans=[0]*keta # 桁数の配列を準備する
    check=0
    for i in range(1,keta+1):
        j = N//(K**(keta-i))
        ans[check]=j
        check+=1
        N-=(j)*(K**(keta-i))
    return ans
    
for i in change(N):
    print(al[i-1],end = '')
Problem p02989 (python)

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


def main():
    sc = Scan()
    n = sc.intarr()[0]
    d = sc.intarr()
    d.sort()
    ans = d[n//2] - d[n//2 - 1]
    print(ans)


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()

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


def main():
    sc = Scan()
    n = sc.intarr()[0]
    d = sc.intarr()
    d.sort()
    ans = 0
    if d[n//2] == d[n//2 + 1]:
        print('0')
        exit()
    ans = d[n//2] - d[n//2 - 1]
    print(ans)


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()
Problem p03013 (python)

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


def main():
    MOD = 10 ** 9 + 7
    sc = Scan()
    n, m = sc.intarr()
    w = sc.intarr_ver(m)
    is_safe = [True] * (n+2)
    for a in w:
        is_safe[a + 1] = False
    dp = [0] * (n+2)
    dp[1] = 1
    for i in range(2, n+2):
        if is_safe[i]:
            dp[i] = dp[i-1] + dp[i-2]
            dp[i] %= MOD
        else:
            dp[i] = 0

    print(dp[n+1])


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()

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


def main():
    MOD = 10 ** 9 + 7
    sc = Scan()
    n, m = sc.intarr()
    w = sc.intarr()
    is_safe = [True] * (n+2)
    for a in w:
        is_safe[a + 1] = False
    dp = [0] * (n+2)
    dp[1] = 1
    for i in range(2, n+2):
        if is_safe[i]:
            dp[i] = dp[i-1] + dp[i-2]
            dp[i] %= MOD
        else:
            dp[i] = 0

    print(dp[n+1])


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()

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


def main():
    MOD = 10 ** 9 + 7
    sc = Scan()
    n, m = sc.intarr()[0]
    w = sc.intarr()
    is_safe = [True] * (n+2)
    for a in w:
        is_safe[a + 1] = False
    dp = [0] * (n+2)
    dp[1] = 1
    for i in range(2, n+2):
        if is_safe[i]:
            dp[i] = dp[i-1] + dp[i-2]
            dp[i] %= MOD
        else:
            dp[i] = 0

    print(dp[n+1])


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()
Problem p03805 (python)

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

used = []
connect = []
N = 0
M = 0


def main():
    global used
    global connect
    global N
    global M
    sc = Scan()
    N, M = sc.intarr()
    a = [0] * M
    b = [0] * M
    for i in range(M):
        aa, bb = sc.intarr()
        a[i] = aa - 1
        b[i] = bb - 1
    connect = [[0] * N for i in range(N)]
    used = [0] * N
    for i in range(M):
        connect[a[i]][b[i]] = 1
        connect[b[i]][a[i]] = 1

    print(dfs(0, 1))


def dfs(now, depth):
    global used
    global connect
    if used[now] == 1:
        return 0

    if depth == N:
        return 1
    ans = 0
    used[now] = 1
    for i in range(N):
        if connect[now][i] == 1:
            ans += dfs(i, depth+1)
    used[now] = 0
    return ans


class Scan():

    def intarr(self):
        num_array = list(map(int, input().split()))
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


def gcd(a, b):  # 最大公約数
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):  # 最小公倍数
    return a * b // gcd(a, b)


main()

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

used = []
connect = []
N = 0
M = 0


def main():
    global used
    global connect
    global N
    global M
    sc = Scan()
    N, M = sc.intarr()
    a = [0] * M
    b = [0] * M
    for i in range(M):
        aa, bb = sc.intarr()
        a[i] = aa - 1
        b[i] = bb - 1
    connect = [[0] * M for i in range(M)]
    used = [0] * N
    for i in range(M):
        connect[a[i]][b[i]] = 1
        connect[b[i]][a[i]] = 1

    print(dfs(0, 1))


def dfs(now, depth):
    global used
    global connect
    if used[now] == 1:
        return 0

    if depth == N:
        return 1
    ans = 0
    used[now] = 1
    for i in range(N):
        if connect[now][i] == 1:
            ans += dfs(i, depth+1)
    used[now] = 0
    return ans


class Scan():

    def intarr(self):
        num_array = list(map(int, input().split()))
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


def gcd(a, b):  # 最大公約数
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):  # 最小公倍数
    return a * b // gcd(a, b)


main()
Problem p02624 (python)

Fixed submission:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def rangeI(it, l, r):
    for i, e in enumerate(it):
        if l <= i < r:
            yield e
        elif l >= r:
            break

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

INF = 999999999999999999999999
MOD = 10**9+7

n = int(input())

# factors = [1] * (n+1)

ans = 0
for i in range(1, n+1):
    for j in range(i, n+1, i):
        ans += j

print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def rangeI(it, l, r):
    for i, e in enumerate(it):
        if l <= i < r:
            yield e
        elif l >= r:
            break

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def main():
    
	INF = 999999999999999999999999
	MOD = 10**9+7

	n = int(input())

	ans = 0
	for i in range(1, n+1):
	    for j in range(i, n+1, i):
    	    ans += j

	print(ans)
main()
Problem p02757 (python)

Fixed submission:
import math
from functools import reduce
from collections import deque, defaultdict
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

n,p = get_nums_l()
s = input()
X = list(map(int, list(s)))
n = len(s)

if p in (2,5):
    ans = 0
    for i,x in enumerate(X):
        if x%p == 0:
            ans += i+1
    print(ans)
else:
    ruiseki = [0] * (n+1)
    for i in (range(n-1, -1, -1)):
        ruiseki[i] = (X[i] * pow(10, (n-i-1), p) + ruiseki[i+1]) % p

    # log(ruiseki)

    ans = 0
    count = defaultdict(int)

    for x in ruiseki:
        # log(count[x])
        ans += count[x]
        count[x] += 1
    # log(count)
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

n,p = get_nums_l()
s = input()
X = list(map(int, list(s)))
n = len(s)

if p in (2,5):
    ans = 0
    for i,x in enumerate(X):
        if x%p == 0:
            ans += i+1
    print(ans)
else:
    ruiseki = [0] * (n+1)
    for i in (range(n-1, -1, -1)):
        ruiseki[i] = (X[i] * pow(10, (n-i-1), p) + ruiseki[i+1]) % p

    # log(ruiseki)

    ans = 0
    count = defaultdict(int)

    for x in ruiseki:
        # log(count[x])
        ans += count[x]
        count[x] += 1
    # log(count)
    print(ans)
Problem p02769 (python)

Fixed submission:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def inv(x):
    return pow(x, MOD-2, MOD)

def nPk(n,k):
    
    # x=1
    # for a in range(n-k+1, n+1):
    #     x = x * a % MOD
    # return x
    return kaijo[n] * inv(kaijo[n-k]) % MOD

def nCk(n,k):
    return nPk(n,k) * inv(kaijo[k])

MOD = 10**9+7

kaijo = [0] * 400020
kaijo[0] = 1
for i in range(1, len(kaijo)):
    kaijo[i] = kaijo[i-1] * i % MOD

n,k = get_nums_l()

if k >= n-1:
    print(nCk(n+n-1, n) % MOD)
    exit()

# 0人の部屋=zがk以下であるような人数の並べ方の個数

# z=0 1
# z=1 nC1 * (n-1)**1
# z=2 nC2 * (n-2)**2
# z=3 nC3 * (n-3)**3

ans = 1
for z in range(1,k+1):
    ans += nCk(n,z) * nCk(n-1, z)

print(ans%MOD)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def inv(x):
    return pow(x, MOD-2, MOD)

def nPk(n,k):
    
    # x=1
    # for a in range(n-k+1, n+1):
    #     x = x * a % MOD
    # return x
    return kaijo[n] * inv(kaijo[k-1]) % MOD

def nCk(n,k):
    return nPk(n,k) * inv(kaijo[k])

MOD = 10**9+7

kaijo = [0] * 200005
kaijo[0] = 1
for i in range(1, len(kaijo)):
    kaijo[i] = kaijo[i-1] * i % MOD

n,k = get_nums_l()

if k >= n-1:
    print(nCk(n+n-1, n) % MOD)
    exit()

# 0人の部屋=zがk以下であるような人数の並べ方の個数

# z=0 1
# z=1 nC1 * (n-1)**1
# z=2 nC2 * (n-2)**2
# z=3 nC3 * (n-3)**3

ans = 1
for z in range(1,k+1):
    ans += nCk(n,z) * nCk(n-1, z) % MOD

print(ans%MOD)
Problem p02773 (python)

Fixed submission:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

n = int(input())
sss = []
for _ in range(n):
    sss.append(input())

m = {}
for s in sss:
    if s in m:
        m[s] += 1
    else:
        m[s] = 1

items = m.items()
items = list(sorted(items, key=lambda i:i[0]))
items = list(sorted(items, key=lambda i: i[1], reverse=True))

max_ = items[0][1]
i = 0
while i<len(items) and items[i][1] == max_:
    print(items[i][0])
    i+=1

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

n = int(input())
sss = open(0).read().split()

m = {}
for s in sss:
    if s in m:
        m[s] += 1
    else:
        m[s] = 1

items = m.items()
items = list(sorted(items, key=lambda i:i[0]))
items = list(sorted(items, key=lambda i: i[1], reverse=True))

max_ = items[0][1]
i = 0
while i<len(items) and items[i][1] == max_:
    print(items[i][0])
    i+=1
Problem p03634 (python)

Fixed submission:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

def log(*args):
    print(*args, file=sys.stderr)


n = int(input())
lines = sys.stdin.readlines()
edges = [ [] for _ in range(n+1) ]
for i in range(n-1):
    e = tuple(map(int, lines[i].split(" ")))
    log(e)
    edges[e[0]].append((e[1],e[2]))
    edges[e[1]].append((e[0],e[2]))

q,k = map(int, lines[n-1].split(" "))

ddd = [0] * (n+1)


que = deque()
que.append(k)
def bfs(x):
    for y, d in edges[x]:
        if ddd[y]:
            continue
        ddd[y] = ddd[x] + d
        que.append(y)


while que:
    bfs(que.pop())

for i in range(n, n+q):
    x, y = map(int, lines[i].split(" "))
    log(x,y)
    print(ddd[x] + ddd[y])

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

def log(*args, **kwargs):
    print(*args, **kwargs, file=sys.stderr)


n = int(input())
lines = sys.stdin.readlines()
edges = [ [] for _ in range(n+1) ]
for i in range(n-1):
    e = tuple(map(int, lines[i].split(" ")))
    log(e)
    edges[e[0]].append((e[1],e[2]))
    edges[e[1]].append((e[0],e[2]))

q,k = map(int, lines[n-1].split(" "))

ddd = [0] * (n+1)


que = deque()
que.append(k)
def bfs(x):
    for y, d in edges[x]:
        if ddd[y]:
            continue
        ddd[y] = ddd[x] + d
        que.append(y)


while que:
    bfs(que.pop())

for i in range(n, n+q):
    x, y = map(int, lines[i].split(" "))
    log(x,y)
    print(ddd[x] + ddd[y])
Problem p02551 (python)

Fixed submission:
N,Q = map(int, input().split())
ANS = (N-2)**2
R,C=N,N
RLEN=[]
CLEN=[]
for i in range(Q):
    RC,num = map(int, input().split())
    if RC==1:
        if R>num:
            for j in range(R-num):
                RLEN.append(C)
            ANS-=C-2
            R=num
        else:
            if len(RLEN)>0:
                ANS-=RLEN[N-num-1]-2
            else:
                ANS-=R-2
    else:
        if C>num:
            for j in range(C-num):
                CLEN.append(R)
            ANS-=R-2
            C=num
        else:
            if len(CLEN)>0:
                ANS-=CLEN[N-num-1]-2
            else:
                ANS-=C-2

print(ANS)

Buggy submission (verdict: Runtime Error):
N,Q = map(int, input().split())
ANS = (N-2)**2
R,C=N,N
RLEN=[]
CLEN=[]
for i in range(Q):
    RC,num = map(int, input().split())
    if RC==1:
        if R>num:
            for j in range(R-num-2):
                RLEN.append(C)
            ANS-=C-2
            R=num
        else:
            if len(RLEN)>0:
                ANS-=RLEN[N-num-1]-2
            else:
                ANS-=R-2
    else:
        if C>num:
            for j in range(C-num-2):
                CLEN.append(R)
            ANS-=R-2
            C=num
        else:
            if len(CLEN)>0:
                ANS-=CLEN[N-num-1]-2
            else:
                ANS-=C-2

print(ANS)

Buggy submission (verdict: Runtime Error):
N,Q = map(int, input().split())
ANS = (N-2)**2
R,C=N,N
RLEN=[]
CLEN=[]
for i in range(Q):
    RC,num = map(int, input().split())
    if RC==1:
        if R>num:
            for j in range(R-num-1):
                RLEN.append(C)
            ANS-=C-2
            R=num
        else:
            if len(RLEN)>0:
                ANS-=RLEN[N-num-1]-2
            else:
                ANS-=R-2
    else:
        if C>num:
            for j in range(C-num-1):
                CLEN.append(R)
            ANS-=R-2
            C=num
        else:
            if len(CLEN)>0:
                ANS-=CLEN[N-num-1]-2
            else:
                ANS-=C-2

print(ANS)
Problem p02879 (python)

Fixed submission:
A,B = map(int, input().split())  
if A<=9 and B<=9:
  print(A*B)
else:
  print(-1)

Buggy submission (verdict: Runtime Error):
A,B = map(int, input().split())  
if A<=9 && B<=9:
  print(A*B)
else:
  print(-1)
Problem p02880 (python)

Fixed submission:
def main():
    N = int(input())  
    for i in range(1,10):
        for j in range(1,10):
            if i*j == N:
                print('Yes')
                return
    print('No')

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
N = int(input())  
for i in range(1,10):
  for j in range(1,10):
    if i*j == N:
      print('Yes')
      return
print('No')
Problem p02831 (python)

Fixed submission:
import fractions

a, b = map(int, input().split())
c = fractions.gcd(a, b)


print(a * b // c)

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

n, m = map(int, input().split())

print(n * m // gcd(n, m))
Problem p02847 (python)

Fixed submission:
s = input()
if s == 'MON':
    print(6)
if s == 'TUE':
    print(5)
if s == 'WED':
    print(4)
if s == 'THU':
    print(3)
if s == 'FRI':
    print(2)
if s == 'SAT':
    print(1)
if s == 'SUN':
    print(7)

Buggy submission (verdict: Runtime Error):
s = input()
if s == 'MAN':
    print(6)
if s == 'TUE':
    print(5)
if s == 'WED':
    print(4)
if s == 'THU':
    print(3）
if s == 'FRI':
    print(2)
if s == 'SAT':
    print(1)
if s == 'SUN':
    print(7)