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

Fixed submission:
import bisect

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

a.sort()
b.sort()
c.sort()
ans=0
for i in range(n):
	a_l=bisect.bisect_left(a,b[i])
	c_l=bisect.bisect(c,b[i])
	ans+=a_l*(n-c_l)

print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

a.sort()
b.sort()
c.sort()

def binary_search(x,i):
	low = 0
	high = len(x)
	t = (low + high) // 2 
	while (low<=high):
		if (i==x[t]):
			break
		elif (i > x[t]):
			low = t + 1
		elif (i < x[t]):
			high = t - 1
		t = (low + high) // 2
	return t

ans=0
for i in range(n):
  b_l=binary_search(b,a[i])
  for j in range(b_l+1,n):
    c_l=binary_search(c,b[j])
    ans+=n-c_l-1

print(ans)
Problem p03000 (python)

Fixed submission:
import sys

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

if __name__ == "__main__":
    n, x = map(int, input().split())
    llist = list(map(int, input().split()))
    llist.insert(0, 0)

    res = 0
    sum = 0
    for l in llist:
        if (sum + l) <= x:
            res += 1
            sum += l
        else:
            break
    
    print(res)

Buggy submission (verdict: Runtime Error):
import sys

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

if __name__ == "__main__":
    n, x = map(int, input().split())
    l = list(map(int, input().split()))
    l.insert(0, 0)

    num = 0
    sum = 0
    while sum + l[num] <= x:
        sum += l[num]
        num += 1

    print(num)
Problem p03026 (python)

Fixed submission:
import sys
sys.setrecursionlimit(200010)

N = int(input())
tree = [[] for _ in range(N + 1)]
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)
c = [int(s) for s in input().split()]
c.sort(reverse=True)

anst = [0] * (N + 1)
anss = 0


def visit(a, prev):
    global anst, anss
    ans = 0
    for b in tree[a]:
        if b != prev:
            ci = visit(b, a)
            anss += ci
    ci = c.pop()
    anst[a] = ci
    return ci


visit(1, 1)
print(anss)
print(" ".join((str(i) for i in anst[1:])))

Buggy submission (verdict: Runtime Error):
N = int(input())
tree = [[] for _ in range(N + 1)]
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)
c = [int(s) for s in input().split()]
c.sort(reverse=True)

anst = [0] * (N + 1)
anss = 0


def visit(a, prev):
    global anst, anss
    ans = 0
    for b in tree[a]:
        if b != prev:
            ci = visit(b, a)
            anss += ci
    ci = c.pop()
    anst[a] = ci
    return ci


visit(1, 1)
print(anss)
print(" ".join((str(i) for i in anst[1:])))
Problem p03111 (python)

Fixed submission:
try:
    from math import inf
except:
    inf = float("inf")
from collections import deque

N, A, B, C = map(int, input().split())
ls = [0]
for _ in range(N):
    ls.append(int(input()))
ls.sort()

q = deque()
q.append((0, -30, 0, 0, 0))
minmp = inf
while len(q):
    n, mp, a, b, c = q.pop()
    if n == N:
        if min(a, b, c) == 0:
            continue
        minmp = min(minmp, mp + abs(a - A) + abs(b - B) + abs(c - C))
    else:
        q.append((n + 1, mp, a, b, c))
        q.append((n + 1, mp + 10, a + ls[n + 1], b, c))
        q.append((n + 1, mp + 10, a, b + ls[n + 1], c))
        q.append((n + 1, mp + 10, a, b, c + ls[n + 1]))

print(minmp)

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

N, A, B, C = map(int, input().split())
ls = [0]
for _ in range(N):
    ls.append(int(input()))
ls.sort()

q = deque()
q.append((0, -30, 0, 0, 0))
minmp = inf
while len(q):
    n, mp, a, b, c = q.pop()
    if n == N:
        if min(a, b, c) == 0:
            continue
        minmp = min(minmp, mp + abs(a - A) + abs(b - B) + abs(c - C))
    else:
        q.append((n + 1, mp, a, b, c))
        q.append((n + 1, mp + 10, a + ls[n + 1], b, c))
        q.append((n + 1, mp + 10, a, b + ls[n + 1], c))
        q.append((n + 1, mp + 10, a, b, c + ls[n + 1]))

print(minmp)
Problem p03138 (python)

Fixed submission:
N, K = map(int, input().split())
A = [int(s) for s in input().split()]


def cntbit(bit):
    cnt = 0
    for a in A:
        if a & bit:
            cnt += 1
    return cnt


def getans(bink):
    if len(bink) == 1:
        if bink == "0":
            return cntbit(1)
        else:
            return N - cntbit(1)

    ans = 0
    bit = 1 << (len(bink) - 1)
    if bink[0] == "0":
        return bit * cntbit(bit) + getans(bink[1:])
    else:
        ans1 = bit * (N - cntbit(bit)) + getans(bink[1:])
        ans2 = 0
        ans2 += bit * cntbit(bit)
        for i in range(len(bink) - 1):
            bit = 1 << i
            cnt = cntbit(bit)
            ans2 += bit * max(cnt, N - cnt)
        return max(ans1, ans2)


bink = bin(K)[2:]
bink = "0" * (40 - len(bink)) + bink
print(getans(bink))

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

N, K = map(int, input().split())
A = [int(s) for s in input().split()]


def cntbit(bit):
    cnt = 0
    for a in A:
        if a & bit:
            cnt += 1
    return cnt


def getans(bink):
    if len(bink) == 1:
        if bink == "0":
            return cntbit(1)
        else:
            return N - cntbit(1)

    ans = 0
    bit = 1 << (len(bink) - 1)
    if bink[0] == "0":
        return bit * cntbit(bit) + getans(bink[1:])
    else:
        ans1 = bit * (N - cntbit(bit)) + getans(bink[1:])
        ans2 = 0
        ans2 += bit * cntbit(bit)
        for i in range(len(bink) - 1):
            bit = 1 << i
            cnt = cntbit(bit)
            ans2 += bit * max(cnt, N - cnt)
        return max(ans1, ans2)


bink = bin(K)[2:]
bink = "0" * (40 - len(bink)) + bink
print(getans(bink))
Problem p03187 (python)

Fixed submission:
L, N = map(int, input().split())
X = [0]
for _ in range(N):
    X.append(int(input()))

s = [0] * (N + 1)
t = [0] * (N + 1)
for i in range(1, N + 1):
    s[i] = s[i-1] + X[i]
    t[i] = t[i-1] + (L - X[N - i + 1])
Y = [0] + [L - X[N - i] for i in range(N)]

# i >= 1


def get_d(s, x, i):
    if i == N:
        return x[N]
    a = i + (N - i) // 2
    return (
        2 * (s[a] - s[i-1] + L * (N - a) - s[N] + s[a]) -
        (x[a] if (N - i) % 2 == 0 else (L - x[a + 1]))
    )


ans = 0
for i in range(1, N + 1):
    ans = max(ans, get_d(s, X, i), get_d(t, Y, i))

print(ans)

Buggy submission (verdict: Runtime Error):
L, N = map(int, input())
X = []
for _ in range(N):
    X.append(int(input()))
X.sort()

Y = [L - x for x in X]
ans = 2*sum(X[:(N-1)//2+1]) + 2*sum(Y[-1:(N-1)//2:-1]) - min(X[(N-1)//2], Y[N//2])

print(ans)
Problem p03231 (python)

Fixed submission:
# from math import gcd
from fractions import gcd
import sys

N, M = map(int, input().split())
S = input()
T = input()

d = gcd(N, M)
m = N * M // d

for i in range(d):
    if S[i * (N // d)] != T[i * (M // d)]:
        print(-1)
        sys.exit()

print(m)

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

N, M = map(int, input().split())
S = input()
T = input()

d = gcd(N, M)
m = N * M // d

for i in range(d):
    if S[i * (N // d)] != T[i * (M // d)]:
        print(-1)
        sys.exit()

print(m)

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

N, M = map(int, input().split())
S = input()
T = input()

d = gcd(N, M)
m = N * M // d

for i in range(d):
    if S[i * (N // d)] != T[i * (M // d)]:
        print(-1)
        sys.exit()

print(m)
Problem p03240 (python)

Fixed submission:
import sys

def get_height(h, x, y, cx, cy):
	for i in range(len(h)):
		if h[i] == 0:
			continue
		return h[i] + abs(x[i] - cx) + abs(y[i] - cy)

n = int(input())
x = []
y = []
h = []
for _ in range(n):
	xi, yi, hi = map(int, input().split())
	x.append(xi)
	y.append(yi)
	h.append(hi)

for cx in range(101):
	for cy in range(101):
		height = get_height(h, x, y, cx, cy)
		for i in range(n):
			if h[i] != max(0, height - abs(x[i] - cx) - abs(y[i] - cy)):
				break
		else:
			print(cx, cy, height)
			sys.exit()

Buggy submission (verdict: Runtime Error):
import sys

def get_height(h, x, y, cx, cy):
	return h + abs(x - cx) + abs(y - cy)

n = int(input())
x = []
y = []
h = []
for _ in range(n):
	xi, yi, hi = map(int, input().split())
	if hi == 0:
		continue
	x.append(xi)
	y.append(yi)
	h.append(hi)

for cx in range(101):
	for cy in range(101):
		height = get_height(h[0], x[0], y[0], cx, cy)
        is_valid = True
		for i in range(1, len(x)):
			if height != get_height(h[i], x[i], y[i], cx, cy):
            	is_valid = False
				break
		if is_valid:
			print(cx, cy, height)
			sys.exit()
Problem p03262 (python)

Fixed submission:
from functools import reduce
# Python < 3.5
# from math import gcd
# Python >= 3.5
from fractions import gcd

N, X = map(int, input().split())
d = [abs(int(s) - X) for s in input().split()]

print(reduce(gcd, d, 0))

Buggy submission (verdict: Runtime Error):
import sys
# Python < 3.5
# from math import gcd
# Python >= 3.5
from fractions import gcd

def gcdall(*args):
  if len(args) == 1:
    return args[0]
  return gcdall(gcd(args[0], args[1]), *args[2:])

N, X = map(int, input().split())
d = [abs(int(s) - X) for s in input().split()]

print(gcdall(*d))
Problem p03386 (python)

Fixed submission:
A, B, K = map(int, input().split())
if B - A < 2 * K:
    # ans = [*range(A, B + 1)]
    ans = list(range(A, B + 1))
else:
    # ans = [*range(A, A + K), *range(B - K + 1, B + 1)]
    ans = list(range(A, A + K)) + list(range(B - K + 1, B + 1))
for v in ans:
    print(v)

Buggy submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
if B - A < 2 * K:
    ans = [*range(A, B + 1)]
else:
    ans = [*range(A, A + K), *range(B - K + 1, B + 1)]
for v in ans:
    print(v)

Buggy submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
if B - A < 2 * K:
    # print(*range(A, B + 1))
    print(*list(range(A, B + 1)))
else:
    # print(*range(A, A + K), *range(B - K + 1, B + 1))
    print(*list(range(A, A + K)), *list(range(B - K + 1, B + 1)))

Buggy submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
if B - A < 2 * K:
    print(*range(A, B + 1))
else:
    print(*range(A, A + K), *range(B - K + 1, B + 1))
Problem p03590 (python)

Fixed submission:
import sys
N, K = map(int, input().split())

AB = []
for _ in range(N):
    AB.append([int(s) for s in input().split()])

ans = 0
kbin = bin(K)[2:]
for a, b in AB:
    if K | a == K:
        ans += b
for i in range(1, len(kbin)):
    if kbin[i - 1] == "0":
        continue
    kl = list(kbin)
    kl[i - 1] = "0"
    for j in range(i, len(kbin)):
        kl[j] = "1"
    km = int("".join(kl), 2)
    anscand = 0
    for a, b in AB:
        if km | a == km:
            anscand += b
    if ans < anscand:
        ans = anscand
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from math import log2

N, K = map(int, input().split())

AB = []
for _ in range(N):
    AB.append([int(s) for s in input().split()])

ans = sum([b for a, b in AB if K | a == K])
for i in range(int(log2(K) // 1), 0, -1):
    if not K & (1 << i):
        continue
    km = K & ~(1 << i) | (1 << i) - 1
    anscand = sum([b for a, b in AB if km | a == km])
    ans = max(ans, anscand)
print(ans)
Problem p03600 (python)

Fixed submission:
inf = float("inf")
N = int(input())
A = []
for _ in range(N):
    a = [int(s) for s in input().split()]
    A.append(a)
d = [a[:] for a in A]
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        dmin = min([inf] + [d[i][k] + d[k][j]
                            for k in range(N) if k not in (i, j)])
        if d[i][j] > dmin:
            print(-1)
            exit()
        if d[i][j] != dmin:
            ans += d[i][j]
print(ans)

Buggy submission (verdict: Runtime Error):
inf = float("inf")
N = int(input())
A = []
for _ in range(N):
    a = [int(s) for s in input().split()]
    A.append(a)
d = [a[:] for a in A]
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        dmin = min([d[i][k] + d[k][j] for k in range(N) if k not in (i, j)])
        if d[i][j] > dmin:
            print(-1)
            exit()
        if d[i][j] != dmin:
            ans += d[i][j]
print(ans)
Problem p03760 (python)

Fixed submission:
from itertools import zip_longest
print("".join(sum(zip_longest(input(), input(), fillvalue=""), tuple())))

Buggy submission (verdict: Runtime Error):
from itertools import zip_longest
print("".join(sum(zip_longest(input(), input()), tuple())))
Problem p02983 (python)

Fixed submission:
#!/usr/bin/env python
l, r = map(int, input().split())

mod = 2019
if r >= l+mod-1:
    r = l+mod-1
X = [x%mod for x in list(range(l, r+1))]

ans = mod
for i in range(len(X)):
    for j in range(i+1, len(X)):
        ans = min(ans, (X[i] * X[j])%mod)
print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
l, r = map(int, input().split())
mod = 2019
X = [x%mod for x in list(range(l, r+1))]
X.sort()
ans = X[0]*X[1]
ans %= mod
print(ans)
Problem p03001 (python)

Fixed submission:
#!/usr/bin/env python
W, H, x, y = map(int, input().split())
a = W*H/2

if 2*x == W and 2*y == H:
    b = 1
else:
    b = 0
print(a, b)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
W, H, x, y = map(int, input().split())

if x == W/2:
    print(H*W/2, 0)
else:
    b = (H-W)/2
    a = (y-b)/x
    print((a*W+2*b)*W/2, 1)
Problem p03005 (python)

Fixed submission:
#!/usr/bin/env python
n, k = map(int, input().split())
if k == 1:
    print(0)
else:
    print(n-k)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
N = int(input())
A = [int(i) for i in input().split()]
if N == 2:
    print(max(A) - min(A))
    print(max(A), min(A))
else:
    A.sort()
    As = []
    t = A[0]
    for a in A[1:-1]:
        As.append([t, a])
        t = t - a
    ans = A[-1] - t
    As.append([A[-1], t])
    print(ans)
    for a in As:
        print(*a)
Problem p03061 (python)

Fixed submission:
#!/usr/bin/env python
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))

L = []
R = []
k = 0
for i in range(N):
    k = gcd(k, A[i])
    L.append(k)
k = 0
for j in range(N)[::-1]:
    k = gcd(k, A[j])
    R.append(k)
R[:] = R[::-1]

ans = 0
for i in range(N):
    if i == 0:
        ans = R[1]
    elif i == N-1:
        ans = max(ans, L[N-2])
    else:
        ans = max(ans, gcd(L[i-1], R[i+1]))
print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
import math
N = int(input())
A = list(map(int, input().split()))
A.sort()

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse=True)
    return divisors

if N == 2:
    print(max(A))
else:
    min1 = min(A)
    div1 = make_divisors(min1)
    c = 0
    for i in div1:
        for a in A:
            if a % i == 0:
                c += 1
        if c == N-1 or c == N:
            g = i
            break
        c = 0

    m = 0
    for i in range(1, N-1):
        gcd = math.gcd(A[i], A[i+1])
        if gcd > m:
            m = gcd
    print(max(g, m))
Problem p03076 (python)

Fixed submission:
#!/usr/bin/env python

A = [input() for i in range(5)]
m = 9
flag = True
for a in A:
    if int(a[-1]) == 0:
        pass
    elif int(a[-1]) <= m:
        flag = False
        m = int(a[-1])
        min_dish = a
B = [int(i) for i in A]
if flag:
    min_dish = str(min(B))
sum = int(min_dish)
A.remove(min_dish)
for a in A:
    if int(a[-1]) == 0:
        sum += int(a)
    else:
        sum += int(a) + int(10) - int(a[-1])
print(int(sum))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python

A = [input() for i in range(5)]
m = 9
flag = True
for a in A:
    if int(a[-1]) == 0:
        pass
    elif int(a[-1]) <= m:
        flag = False
        m = int(a[-1])
        min_dish = a
B = [int(i) for i in A]
if flag:
    min_dish = min(B)

sum = int(min_dish)
A.remove(min_dish)
for a in A:
    if int(a[-1]) == 0:
        sum += int(a)
    else:
        sum += int(a) + int(10) - int(a[-1])
print(int(sum))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python

A = [input() for i in range(5)]
min = 9
for a in A:
    if int(a[-1]) <= min and int(a[-1]) != 0:
        min = int(a[-1])
        min_dish = a
sum = int(min_dish)
A.remove(min_dish)
for a in A:
    if a[-1] == '0':
        sum += int(a)
    else:
        sum += int(a) + int(10) - int(a[-1])
print(int(sum))

Buggy submission (verdict: Runtime Error):
A = [input() for i in range(5)]
min = 9
min_dish = ''
for a in A:
    if int(a[-1]) < min and int(a[-1]) != 0:
        min = int(a[-1])
        min_dish = a
sum = int(min_dish)
A.remove(min_dish)
for a in A:
    if a[-1] == '0':
        sum += int(a)
    else:
        sum += int(a) + int(10) - int(a[-1])
print(int(sum))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python

A = [input() for i in range(5)]
min = 9
min_dish = ''
for a in A:
    if int(a[-1]) < min and int(a[-1]) != 0:
        min = int(a[-1])
        min_dish = a
sum = int(min_dish)
A.remove(min_dish)
for a in A:
    if a[-1] == '0':
        sum += int(a)
    else:
        sum += int(a) + 10 - int(a[-1])
print(int(sum))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
import math

A = [input() for i in range(5)]
min = 9
min_dish = ''
for a in A:
    if int(a[-1]) < min and int(a[-1]) != 0:
        min = int(a[-1])
        min_dish = a
sum = int(min_dish)
A.remove(min_dish)
for a in A:
    if a[-1] == '0':
        sum += int(a)
    else:
        sum += int(a) + 10 - int(a[-1])
print(int(sum))
Problem p03078 (python)

Fixed submission:
#!/usr/bin/env python
import numpy as np
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
D = []
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
for i in range(min(K,X)):
    for j in range(min((K//(i+1),Y))):
        for k in range(min(((K//(i+1)+1)//(j+1)),Z)):
            D.append(A[i]+B[j]+C[k])
D.sort(reverse=True)
for i in range(K):
    print(int(D[i]))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
import numpy as np
x, y, z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
D = []
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
for i in range(min(K,X)):
    for j in range(min((K//(i+1),Y))):
        for k in range(min(((K//(i+1)+1)//(j+1)),Z)):
            D.append(A[i]+B[j]+C[k])
D.sort(reverse=True)
for i in range(K):
    print(int(D[i]))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
x, y, z, k = map(int, input().split())
A = list(map(int, input().split())).sort(reverse=True)
B = list(map(int, input().split())).sort(reverse=True)
C = list(map(int, input().split())).sort(reverse=True)
D = []
E = []
for b in B:
    for c in C:
        D.append(b+c)
D.sort(reverse=True)
for a in A:
    for d in D[:k]:
       E.append(a+d)
E.sort(reverse=True)
for e in E[:k]:
    print(e)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
x, y, z, k = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)
D = []
E = []
for b in B:
    for c in C:
        D.append(b+c)
D.sort(reverse=True)[:k]
n = 0
for a in A:
    for d in D:
       E.append(a+d)
E.sort(reverse=True)
for e in E[:k]:
    print(e)
Problem p03263 (python)

Fixed submission:
#!/usr/bin/env python
H, W = map(int, input().split())
A_raw = [[int(i) for i in input().split()] for j in range(H)]

c = 1
A = []
d = {}
for h in range(H):
    if h % 2 == 0:
        for a in A_raw[h]:
            A.append(a)
        d.update(zip(range(c, c + W), [(h+1, w) for w in range(1, W+1)]))
    else:
        for a in A_raw[h][::-1]:
            A.append(a)
        d.update(zip(range(c, c + W), [(h+1, w) for w in range(1, W+1)[::-1]]))
    c += W

c = 0
ans = []
for i in range(len(A)-1):
    if A[i] % 2 == 1:
        A[i+1] += 1
        A[i] -= 1
        c += 1
        ans.append([d[i+1], d[i+2]])
print(c)
for x in ans:
    print(x[0][0], x[0][1], x[1][0], x[1][1])

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
H, W = map(int, input().split())
A_raw = [[int(i) for i in input().split()] for j in range(H)]

c = 1
A = []
d = {}
for h in range(H):
    if h % 2 == 0:
        for a in A_raw[h]:
            A.append(a)
        d.update(zip(range(c, c + W), [(h+1, w) for w in range(1, W+1)]))
    else:
        for a in A_raw[h][::-1]:
            A.append(a)
        d.update(zip(range(c, c + W), [(h+1, w) for w in range(1, W+1)[::-1]]))
    c += W

c = 0
ans = []
for i in range(len(A)-1):
    if A[i] % 2 == 1:
        A[i+1] += 1
        A[i] -= 1
        c += 1
        ans.append([*d[i+1], *d[i+2]])
print(c)
for x in ans:
    print(*x)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
from itertools import chain
H, W = map(int, input().split())
A_raw = [[int(i) for i in input().split()] for j in range(H)]

c = 1
A = []
d = {}
for h in range(H):
    if h % 2 == 0:
        A.append(A_raw[h])
        d.update(zip(range(c, c + W), [(h+1, w) for w in range(1, W+1)]))
    else:
        A.append(A_raw[h][::-1])
        d.update(zip(range(c, c + W), [(h+1, w) for w in range(1, W+1)[::-1]]))
    c += W
A = list(chain.from_iterable(A))

c = 0
ans = []
for i in range(len(A)-1):
    if A[i] % 2 == 1:
        A[i+1] += 1
        A[i] -= 1
        c += 1
        ans.append([*d[i+1], *d[i+2]])
print(c)
for x in ans:
    print(*x)
Problem p02995 (python)

Fixed submission:
import sys
from fractions import gcd

input = sys.stdin.readline
A, B, C, D = map(int, input().split(' '))
num = B - A + 1
div_c = B // C - (A - 1) // C
div_d = B // D - (A - 1) // D
lcd = C * D // gcd(C, D)
div_cd = B // lcd - (A - 1) // lcd
print(num - div_c - div_d + div_cd)

Buggy submission (verdict: Runtime Error):
import sys, math

input = sys.stdin.readline
gcd = math.gcd
A, B, C, D = map(int, input().split(' '))
num = B - A + 1
div_c = B // C - (A - 1) // C
div_d = B // D - (A - 1) // D
lcd = C * D // gcd(C, D)
div_cd = B // lcd - (A - 1) // lcd
print(num - div_c - div_d + div_cd)

Buggy submission (verdict: Runtime Error):
import math
 
A, B, C, D = map(int, input().split(' '))
num = B - A + 1
div_c = B // C - (A - 1) // C
div_d = B // D - (A - 1) // D
lcd = C * D // math.gcd(C, D)
div_cd = B // lcd - (A - 1) // lcd
print(num - div_c - div_d + div_cd)

Buggy submission (verdict: Runtime Error):
import math

A, B, C, D = map(int, input().split(' '))
num = B - A + 1
div_c = B // C - (A - 1) // C
div_d = B // D - (A - 1) // D
lcd = C * D // math.gcd(C, D)
div_cd = B // lcd - (A - 1) // lcd
print(num - div_c - div_d + div_cd)
Problem p03067 (python)

Fixed submission:
A, B, C = map(int, input().strip().split(' '))
message = ''
if A > B:
  message = 'Yes' if A > C > B else 'No'
else:
  message = 'Yes' if B > C > A else 'No'
print(message)

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

index = 0
counter = 0
while index < N:
    if S[index] == '#':
        offset = 1
        while index + offset < N and S[index + offset] == '#':
            offset += 1

        if index + offset >= N:
            break
        else:
            count = 1
            memory = offset
            offset += 1
            while index + offset < N and S[index + offset] == '.':
                count += 1
                offset += 1
            counter += count if count < memory else memory
            index += offset-1
    else:
        index += 1
print(str(counter))