Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
import math

x, y = map(int, input().split())

if (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0:
    print(0)
    sys.exit()

k = (2 * x - y) // 3
l = (2 * y - x) // 3

ans = math.factorial(k + l) // (math.factorial(k) * math.factorial(l))

print(ans % (10 ** 9 + 7))


Fixed submission:
fac = [0] * 700000
finv = [0] * 700000
inv = [0] * 700000
mod = 1000000007

fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2, 700000):
    fac[i] = fac[i - 1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i - 1] * inv[i] % mod

x, y = map(int, input().split())

if (x + y) % 3 == 0:
    k = (2 * x - y) // 3
    l = (2 * y - x) // 3
    if k >= 0 and l >= 0:
        print(fac[k + l] * (finv[k] * finv[l] % mod) % mod)
    else:
        print(0)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
def z_algorithm(s):
	"""Z-algorithm O(|S|)
    """
    l = len(s)
    z = [0] * l
    z[0] = l
    i, j = 1, 0
    while i < l:
        while i + j < l and S[j] == S[i+j]:
            j += 1
        z[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while k + z[k] < j:
            z[i+k] = z[k]
            k += 1
        i += k
        j -= k
 
    return z

Fixed submission:
def z_algo(s):
    """Z-algorithm O(|S|)

    Args:
        s (str): 対象文字列
    
    Returns:
        list: lcp配列 (z[i]: sとs[i:]の最長共通接尾辞の長さ)
    """
    n = len(s)
    z = [0] * n
    z[0] = n
    i, j = 1, 0
    while i < n:
        while i + j < n and s[j] == s[i+j]:
            j += 1
        z[i] = j

        if j == 0:
            i += 1
            continue

        k = 1
        while i + k < n and k + z[k] < j:
            z[i+k] = z[k]
            k += 1

        i += k
        j -= k

    return z


n = int(input())
s = input()

res = 0
for i in range(n-1):
    z = z_algo(s[i:])
    for j in range(n-i):
        if z[j] <= j and res < z[j]:
            res = z[j]

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0

for i in range(n):
    ans += i
print(ans)


Fixed submission:
n = int(input())
ans = 0

print((n * (n - 1)) // 2)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0

for i in range(n):
    ans += i
print(ans)


Fixed submission:
n = int(input())
ans = 0

print((n * (n - 1)) // 2)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

n = int(input())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))
ans = 0
pos = [0] * n

while any([(n - 1) - x for x in pos]):
    pos_check = [False] * n
    checker = True
    for i in range(n):
        for j in range(i + 1, n):
            if pos[i] == n - 1 or pos[j] == n - 1:
                continue
            if a[i][pos[i]] == j + 1 and a[j][pos[j]] == i + 1:
                pos_check[i] = True
                pos_check[j] = True
    for i in range(n):
        if pos_check[i]:
            pos[i] += 1
            checker = False
    if checker:
        print(-1)
        sys.exit()
    ans += 1
print(ans)


Fixed submission:
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]

l = [i for i in range(n)]
pos = [0] * n
res = 0
cnt = 0
while True:
    res += 1
    flag = True
    tmp = l.copy()
    l = []
    used = [False] * n
    for v in tmp:
        if used[v] or pos[v] == n - 1:
            continue

        opp = a[v][pos[v]] - 1

        if used[opp] or pos[opp] == n - 1:
            continue

        if a[opp][pos[opp]] - 1 == v:
            pos[v] += 1
            pos[opp] += 1
            l.append(v)
            l.append(opp)
            used[v] = True
            used[opp] = True
            flag = False
            if pos[v] == n - 1:
                cnt += 1
            if pos[opp] == n - 1:
                cnt += 1

    if flag:
        print(-1)
        break

    if cnt == n:
        print(res)
        break
Buggy python submission (verdict: Runtime Error):
n = int(input()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0

for i in range(n):
    if a[i] + a[i + 1] < b[i]:
        ans += a[i] + a[i + 1]
        a[i + 1] = 0
    else:
        ans += b[i]
        if a[i] < b[i]:
            a[i + 1] -= b[i] - a[i]

print(ans)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0

for i in range(n):
    if a[i] + a[i + 1] < b[i]:
        ans += a[i] + a[i + 1]
        a[i + 1] = 0
    else:
        ans += b[i]
        if a[i] < b[i]:
            a[i + 1] -= b[i] - a[i]

print(ans)
Buggy python submission (verdict: Runtime Error):
import fractions

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

a_c = (a - 1)//c
a_d = (a - 1) // d
a_cd = (a - 1) // (c * d // math.gcd(c, d))

b_c = b // c
b_d = b // d
b_cd = b // (c * d // math.gcd(c, d))

print((b - b_c - b_d + b_cd) - ((a - 1) - a_c - a_d + a_cd))


Fixed submission:
import fractions

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

a_c = (a - 1) // c
a_d = (a - 1) // d
a_cd = (a - 1) // (c * d // fractions.gcd(c, d))

b_c = b // c
b_d = b // d
b_cd = b // (c * d // fractions.gcd(c, d))

print((b - b_c - b_d + b_cd) - ((a - 1) - a_c - a_d + a_cd))

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

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

a_c = (a - 1) // c
a_d = (a - 1) // d
a_cd = (a - 1) // (c * d // math.gcd(c, d))

b_c = b // c
b_d = b // d
b_cd = b // (c * d // math.gcd(c, d))

print((b - b_c - b_d + b_cd) - ((a - 1) - a_c - a_d + a_cd))


Fixed submission:
import fractions

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

a_c = (a - 1) // c
a_d = (a - 1) // d
a_cd = (a - 1) // (c * d // fractions.gcd(c, d))

b_c = b // c
b_d = b // d
b_cd = b // (c * d // fractions.gcd(c, d))

print((b - b_c - b_d + b_cd) - ((a - 1) - a_c - a_d + a_cd))

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

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

a_c = (a - 1) // c
a_d = (a - 1) // d
a_cd = (a - 1) // (c * d // math.gcd(c, d))

b_c = b // c
b_d = b // d
b_cd = b // (c * d // math.gcd(c, d))

print((b - b_c - b_d + b_cd) - ((a - 1) - a_c - a_d + a_cd))


Fixed submission:
import fractions

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

a_c = (a - 1) // c
a_d = (a - 1) // d
a_cd = (a - 1) // (c * d // fractions.gcd(c, d))

b_c = b // c
b_d = b // d
b_cd = b // (c * d // fractions.gcd(c, d))

print((b - b_c - b_d + b_cd) - ((a - 1) - a_c - a_d + a_cd))

Buggy python submission (verdict: Runtime Error):
import math

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

a_c = (a - 1) // c
a_d = (a - 1) // d
a_cd = (a - 1) // (c * d // math.gcd(c, d))

b_c = b // c
b_d = b // d
b_cd = b // (c * d // math.gcd(c, d))

print((b - b_c - b_d + b_cd) - ((a - 1) - a_c - a_d + a_cd))


Fixed submission:
import fractions

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

a_c = (a - 1) // c
a_d = (a - 1) // d
a_cd = (a - 1) // (c * d // fractions.gcd(c, d))

b_c = b // c
b_d = b // d
b_cd = b // (c * d // fractions.gcd(c, d))

print((b - b_c - b_d + b_cd) - ((a - 1) - a_c - a_d + a_cd))
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
b = [0, 1]
c = []
ans = 1

for _ in range(n):
    b.append(b[-1] + b[-2])

c.append(a[0])
for i in range(m - 1):
    c.append(a[i + 1] - a[i] - 1)
c.append(n - a[m - 1])

for i in c:
    ans *= b[i]

print(ans % 1000000007)


Fixed submission:
n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
b = [0, 1]
c = []
ans = 1

for _ in range(n):
    b.append(b[-1] + b[-2])

if m == 0:
    ans = b[n + 1]
else:
    c.append(a[0])
    for i in range(m - 1):
        c.append(a[i + 1] - a[i] - 1)
    c.append(n - a[m - 1])

    for i in c:
        ans *= b[i]

print(ans % 1000000007)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = [0] * m
c = [0] * m
ans = 0
flag = False
for i in range(m):
    b[i], c[i] = map(int, input().split())

for _ in range(n):
    ans += max(a[-1], max(c))
    if flag == False:
        cnt = b[c.index(max(c))]
    if a[-1] > max(c):
        a.pop()
    else:
        flag = True
        cnt -= 1
        if cnt == 0:
            del b[c.index(max(c))]
            del c[c.index(max(c))]
            flag = False
            

print(ans)

Fixed submission:
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
l = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x:x[1], reverse=True)

res = 0
pos_1 = 0
pos_2 = 0
for _ in range(n):
    if pos_2 == m or a[pos_1] > l[pos_2][1]:
        res += a[pos_1]
        pos_1 += 1
    else:
        res += l[pos_2][1]
        l[pos_2][0] -= 1
        if l[pos_2][0] == 0:
            pos_2 += 1

print(res)
Buggy python submission (verdict: Runtime Error):
def dfs(now, prev):
    for nxt, w in edge[now]:
        if nxt == prev:
            continue
        
        dist[nxt] = dist[now] + w
        dfs(nxt, now)


n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n-1):
    u, v, w = map(int, input().split())
    edge[u-1].append([v-1, w])
    edge[v-1].append([u-1, w])

dist = [0] * n
dfs(0, -1)

for d in dist:
    if d % 2 == 0:
        print(0)
    else:
        print(1)

Fixed submission:
from sys import setrecursionlimit

setrecursionlimit(10 ** 6)

def dfs(now, prev):
    for nxt, w in edge[now]:
        if nxt == prev:
            continue
        
        dist[nxt] = dist[now] + w
        dfs(nxt, now)


n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n-1):
    u, v, w = map(int, input().split())
    edge[u-1].append([v-1, w])
    edge[v-1].append([u-1, w])

dist = [0] * n
dfs(0, -1)

for d in dist:
    if d % 2 == 0:
        print(0)
    else:
        print(1)
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
n = len(s)
pos = 0
cnt = 0

while pos != n - 1 and n != 0:
    if s[pos] != s[pos + 1]:
        del s[pos]
        del s[pos]
        pos = 0
        n -= 2
        cnt += 2
    else:
        pos += 1

print(cnt)


Fixed submission:
s = input()
a = s.count('0')
b = s.count('1')
print(min(a, b) * 2)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
b = [0] * m
count = 0

for _ in range(n):
    a = list(map(int, input().split()))
    for i in range(1, a[0] + 1):
        b[a[i]] += 1

for i in range(m):
    if b[i] == n:
        count += 1

print(count)

Fixed submission:
n, m = map(int, input().split())
b = [0] * m
count = 0

for _ in range(n):
    a = list(map(int, input().split()))
    for i in range(1, a[0] + 1):
        b[a[i] - 1] += 1

for i in range(m):
    if b[i] == n:
        count += 1

print(count)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
b = [0] * m
count = 0

for _ in range(n):
    a = list(map(int, input().split()))
    for i in range(1, a[0] + 1):
        b[a[i]] += 1

for i in range(m):
    if b[i] == n:
        count += 1

print(count)

Fixed submission:
n, m = map(int, input().split())
b = [0] * m
count = 0

for _ in range(n):
    a = list(map(int, input().split()))
    for i in range(1, a[0] + 1):
        b[a[i] - 1] += 1

for i in range(m):
    if b[i] == n:
        count += 1

print(count)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
dif = []
pos = []
ans = 0

if n >= m:
    print(0)
else:
    for i in range(m - 1):
        dif.append([x[i + 1] - x[i], i])

    dif.sort(reverse = True)

    for i in range(n - 1):
        pos.append(dif[i][1])

    pos.sort()

    ans += x[pos[0]] - x[0]
    if n > 1:
        for i in range(n - 2):
            ans += x[pos[i + 1]] - x[pos[i] + 1]
    ans += x[m - 1] - x[pos[-1] + 1]

    print(ans)


Fixed submission:
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
dif = []
pos = []
ans = 0

if n >= m:
    print(0)
elif n == 1:
    print(x[-1] - x[0])
else:
    for i in range(m - 1):
        dif.append([x[i + 1] - x[i], i])

    dif.sort(reverse = True)

    for i in range(n - 1):
        pos.append(dif[i][1])

    pos.sort()

    ans += x[pos[0]] - x[0]
    for i in range(n - 2):
        ans += x[pos[i + 1]] - x[pos[i] + 1]
    ans += x[m - 1] - x[pos[-1] + 1]

    print(ans)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
dif = []
pos = []
ans = 0

if n >= m:
    print(0)
else:
    for i in range(m - 1):
        dif.append([x[i + 1] - x[i], i])

    dif.sort(reverse = True)

    for i in range(n - 1):
        pos.append(dif[i][1])

    pos.sort()

    ans += x[pos[0]] - x[0]
    for i in range(n - 2):
        ans += x[pos[i + 1]] - x[pos[i] + 1]
    ans += x[m - 1] - x[pos[-1] + 1]

    print(ans)


Fixed submission:
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
dif = []
pos = []
ans = 0

if n >= m:
    print(0)
elif n == 1:
    print(x[-1] - x[0])
else:
    for i in range(m - 1):
        dif.append([x[i + 1] - x[i], i])

    dif.sort(reverse = True)

    for i in range(n - 1):
        pos.append(dif[i][1])

    pos.sort()

    ans += x[pos[0]] - x[0]
    for i in range(n - 2):
        ans += x[pos[i + 1]] - x[pos[i] + 1]
    ans += x[m - 1] - x[pos[-1] + 1]

    print(ans)

Buggy python submission (verdict: Runtime Error):
import sys

n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
dif = []
pos = []
ans = 0

if n >= m:
    print(0)
    sys.exit(1)

for i in range(m - 1):
    dif.append([x[i + 1] - x[i], i])

dif.sort(reverse = True)

for i in range(n - 1):
    pos.append(dif[i][1])

pos.sort()

ans += x[pos[0]] - x[0]
for i in range(n - 2):
    ans += x[pos[i + 1]] - x[pos[i] + 1]
ans += x[m - 1] - x[pos[-1] + 1]

print(ans)


Fixed submission:
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
dif = []
pos = []
ans = 0

if n >= m:
    print(0)
elif n == 1:
    print(x[-1] - x[0])
else:
    for i in range(m - 1):
        dif.append([x[i + 1] - x[i], i])

    dif.sort(reverse = True)

    for i in range(n - 1):
        pos.append(dif[i][1])

    pos.sort()

    ans += x[pos[0]] - x[0]
    for i in range(n - 2):
        ans += x[pos[i + 1]] - x[pos[i] + 1]
    ans += x[m - 1] - x[pos[-1] + 1]

    print(ans)
Buggy python submission (verdict: Runtime Error):
s = int(input())

i = 0
a = []
a.append(s)
b = [0] * 1000

while True:
    if a[i] % 2 == 0:
        a.append(a[i] // 2)
    else:
        a.append(a[i] * 3 + 1)
    b[a[i]] += 1
    if b[a[i]] == 2:
        break
    i += 1

print(i + 1)

Fixed submission:
s = int(input())

i = 0
a = []
a.append(s)
b = [0] * 10000

while True:
    if a[i] % 2 == 0:
        a.append(a[i] // 2)
    else:
        a.append(a[i] * 3 + 1)
    b[a[i]] += 1
    if b[a[i]] == 2:
        break
    i += 1

print(i + 1)

Buggy python submission (verdict: Runtime Error):
s = int(input())

i = 0
a = []
a.append(s)
b = [0] * 300

while True:
    if a[i] % 2 == 0:
        a.append(a[i] // 2)
    else:
        a.append(a[i] * 3 + 1)
    b[a[i]] += 1
    if b[a[i]] == 2:
        break
    i += 1

print(i + 1)

Fixed submission:
s = int(input())

i = 0
a = []
a.append(s)
b = [0] * 10000

while True:
    if a[i] % 2 == 0:
        a.append(a[i] // 2)
    else:
        a.append(a[i] * 3 + 1)
    b[a[i]] += 1
    if b[a[i]] == 2:
        break
    i += 1

print(i + 1)

Buggy python submission (verdict: Runtime Error):
import sys

s = int(input())

i = 0
a = []
a.append(s)
b = [0] * 300

while True:
    if a[i] % 2 == 0:
        a.append(a[i] // 2)
    else:
        a.append(a[i] * 3 + 1)
    b[a[i]] += 1
    i += 1
    for j in range(300):
        if b[j] == 2:
            print(i)
            sys.exit()


Fixed submission:
s = int(input())

i = 0
a = []
a.append(s)
b = [0] * 10000

while True:
    if a[i] % 2 == 0:
        a.append(a[i] // 2)
    else:
        a.append(a[i] * 3 + 1)
    b[a[i]] += 1
    if b[a[i]] == 2:
        break
    i += 1

print(i + 1)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
h = sorted([int(input()) for _ in range(n)])
ans = 1000000000

for i in range(n - k + 1):
    ans = min(ans, h[i + k - 11] - h[i])

print(ans)


Fixed submission:
n, k = map(int, input().split())
h = sorted([int(input()) for _ in range(n)])
ans = 1000000000

for i in range(n - k + 1):
    ans = min(ans, h[i + k - 1] - h[i])

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
ans = 10000

for i in range(n):
    if abs(a - (t - h[i] * 0.006)) < ans:
           ans = abs(a - (t - h[i] * 0.006))
           b = i
print(b + 1)


Fixed submission:
n = int(input())

if n == 1:
    print("Hello World")
else:
    a = int(input())
    b = int(input())
    print(a + b)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

while True:
    if m % n == 0:
        break
    n += 1
print(m // n)

Fixed submission:
from bisect import bisect_left

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

div = []
i = 1
while i * i <= m:
    if m % i == 0:
        div.append(i)
        div.append(m // i)
    i += 1

div.sort()

print(m // div[bisect_left(div, n)])
Buggy python submission (verdict: Runtime Error):
n = input()

for i in range(len(n)):
    if n[i] == '1':
        n[i] = '9'
    else:
        n[i] = '1'

print(n)


Fixed submission:
n = input()
m = []

for i in range(len(n)):
    if n[i] == "1":
        m.append(9)
    else:
        m.append(1)
for i in m:
    print(i, end = '')
Buggy python submission (verdict: Runtime Error):
n = int(input())
v = list(map(int, input().split()))

if len(set(v)) == 1:
    print(n // 2)
else:
    cnt_even = [0] * 10 ** 5
    cnt_odd = [0] * 10 ** 5
    max_even = 0
    max_odd = 0
    for i in range(n):
        if i % 2 == 0:
            cnt_even[v[i]] += 1
            if cnt_even[v[i]] > cnt_even[max_even]:
                max_even = v[i]
        else:
            cnt_odd[v[i]] += 1
            if cnt_odd[v[i]] > cnt_even[max_odd]:
                max_odd = v[i]
    print(n - cnt_even[max_even] - cnt_odd[max_odd])

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

if len(set(v)) == 1:
    print(n // 2)
else:
    cnt_even = [[0, i] for i in range(10 ** 5 + 1)]
    cnt_odd = [[0, i] for i in range(10 ** 5 + 1)]
    for i in range(n):
        if i % 2 == 0:
            cnt_even[v[i]][0] += 1
        else:
            cnt_odd[v[i]][0] += 1

    cnt_even.sort()
    cnt_odd.sort()

    if cnt_even[-1][1] == cnt_odd[-1][1]:
        print(n - max(cnt_even[-1][0] + cnt_odd[-2][0], cnt_even[-2][0] + cnt_odd[-1][0]))
    else:
        print(n - cnt_even[-1][0] - cnt_odd[-1][0])
Buggy python submission (verdict: Runtime Error):
a. b = map(int, input().split())

if (a * b) % 2 != 0:
    print("Yes")
else:
    print("No")

Fixed submission:
a, b = map(int, input().split())

if (a * b) % 2 != 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
from math import gcd

N, X = map(int, input().split())
x = list(map(int, input().split()))

res = abs(X - x[0])
for v in x[1:]:
    res = gcd(res, abs(X - v))

print(res)

Fixed submission:
from fractions import gcd

N, X = map(int, input().split())
x = list(map(int, input().split()))

res = abs(X - x[0])
for v in x[1:]:
    res = gcd(res, abs(X - v))

print(res)
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]

res = []
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            if a[i][j] % 2 == 1:
                if j < w - 1:
                    a[i][j+1] += 1
                    res.append([i+1, j+1, i+1, j+2])
                else:
                    a[i+1][j] += 1
                    res.append([i+1, j+1, i+2, j+1])
    else:
        for j in range(w-1, -1, -1):
            if a[i][j] % 2 == 1:
                if j > 0:
                    a[i][j-1] += 1
                    res.append([i+1, j+1, i+1, j])
                else:
                    a[i+1][j] += 1
                    res.append([i+1, j+1, i+2, j+1])

print(len(res))
for y1, x1, y2, x2 in res:
    print(y1, x1, y2, x2)

Fixed submission:
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]

cnt = 0
for i in range(h):
    for j in range(w):
        if a[i][j] % 2 == 1:
            cnt += 1

res = []
c = 0
move_flag = False
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            if a[i][j] % 2 == 1:
                c += 1
                if move_flag:
                    move_flag = False
                else:
                    if cnt % 2 == 0 or c != cnt:
                        move_flag = True
            if move_flag:
                if j < w - 1:
                    res.append([i+1, j+1, i+1, j+2])
                else:
                    res.append([i+1, j+1, i+2, j+1])
    else:
        for j in range(w-1, -1, -1):
            if a[i][j] % 2 == 1:
                c += 1
                if move_flag:
                    move_flag = False
                else:
                    if cnt % 2 == 0 or c != cnt:
                        move_flag = True
            if move_flag:
                if j > 0:
                    res.append([i+1, j+1, i+1, j])
                else:
                    res.append([i+1, j+1, i+2, j+1])

print(len(res))
for y1, x1, y2, x2 in res:
    print(y1, x1, y2, x2)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, k = map(int, input().split())

for v in range(a, b+1):
    if v - a < k or b - v < k:
        print(v)

Fixed submission:
a, b, k = map(int, input().split())

if b - a < 2 * k:
    for v in range(a, b+1):
        print(v)
else:
    for v in range(a, a+k):
        print(v)
    for v in range(b-k+1, b+1):
        print(v)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

cnt_white = 0
for row in s:
    cnt_white += row.count('.')

d = deque([[0, 0]])
dist = [[0] * w for _ in range(h)]
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]
goal_flag = False
while d:
    x, y = d.popleft()
    if x == h - 1 and y == w - 1:
        goal_flag = True
        break
    for i in range(4):
        pos_x, pos_y = x + dx[i], y + dy[i]
        if 0 <= pos_x < h and 0 <= pos_y < w and s[pos_x][pos_y] == '.':
            d.append([pos_x, pos_y])
            dist[pos_x][pos_y] = dist[x][y] + 1
    s[x][y] = '#'

if goal_flag:
    print(cnt_white - dist[h-1][w-1] - 1)
else:
    print(-1)

Fixed submission:
from collections import deque

h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

cnt_white = 0
for row in s:
    cnt_white += row.count('.')

d = deque([[0, 0]])
dist = [[-1] * w for _ in range(h)]
dist[0][0] = 0
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]
goal_flag = False
while d:
    x, y = d.popleft()
    if x == h - 1 and y == w - 1:
        goal_flag = True
        break
    for i in range(4):
        pos_x, pos_y = x + dx[i], y + dy[i]
        if 0 <= pos_x < h and 0 <= pos_y < w and s[pos_x][pos_y] == '.' and dist[pos_x][pos_y] == -1:
            d.append([pos_x, pos_y])
            dist[pos_x][pos_y] = dist[x][y] + 1

if goal_flag:
    print(cnt_white - dist[h-1][w-1] - 1)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
print(48 - int(input())

Fixed submission:
print(48 - int(input()))