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

Fixed submission:
import math
import sys

x = int(input())
y = int(input())

if x == y:
    print("EQUAL")
elif x > y:
    print("GREATER")
else:
    print("LESS")

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

x,y=[int(i) for i in input().split()]

if x == y:
    print("EQUAL")
elif x > y:
    print("GREATER")
else:
    print("LESS")

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

x,y=[int(i) for i in input().split()]

if x > y:
    print("GREATER")
elif x == y:
    print("EQUAL")
else:
    print("LESS")
Problem p03282 (python)

Fixed submission:
s = input()
k = int(input())

index = 0
while s[index] == "1" and index < len(s) - 1:
    index += 1
if k <= index:
    print('1')
else:
    print(s[index])

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

index = 0
while s[index] == "1":
    index += 1
if k <= index:
    print('1')
else:
    print(s[index])

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

index = 0
while s[index] == "1":
    index += 1
if k <= index + 1:
    print('1')
else:
    print(s[index])
Problem p02885 (python)

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

if b*2 >= a:
    print(0)
else:
    print(a - b*2)

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

if a>b:
    print(a-b)
elif a<b:
    print(0)

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

if a>b:
    print(a-b)
elif a<b:
    print(0)
else:
    print(0)
Problem p02639 (python)

Fixed submission:
x = input().split()
print(x.index('0') + 1)

Buggy submission (verdict: Runtime Error):
x, n = map(int, input().split())
if n > 1:
  p = list(map(int, input().split()))
else:
  print(x)
  exit(0)
   
for i in range(n+1):
  if (x-i) not in p:
    print(x-i)
    break
  if (x+i) not in p:
    print(x+i)
    break
Problem p02678 (python)

Fixed submission:
from collections import deque


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

g = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

dist = [-1] * n
prev = [-1] * n
que = deque([0])
dist[0] = 0
while que:
    v = que.popleft()
    d = dist[v]
    for w in g[v]:
        if dist[w] > -1:
            continue
        dist[w] = d + 1
        que.append(w)
        prev[w] = v

print("Yes")
for i in prev[1:]:
    print(i + 1)

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


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

g = [[] for i in range(m)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

dist = [-1] * n
prev = [-1] * n
que = deque([0])
dist[0] = 0
while que:
    v = que.popleft()
    d = dist[v]
    for w in g[v]:
        if dist[w] > -1:
            continue
        dist[w] = d + 1
        que.append(w)
        prev[w] = v

print("Yes")
for i in prev[1:]:
    print(i + 1)
Problem p02684 (python)

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

d = {}
for i in range(1, n + 1):
    d[i] = a[i - 1]

did = set()
route = [1]

now = 1
for i in range(k):
    now = d[now]
    route.append(now)
    if now in did:
        break
    did.add(now)

if k < 10 ** 6:
    now = 1
    for i in range(k):
        now = d[now]

    print(now)

else:
    for i in range(len(route)):
        if route[i] == route[-1]:
            roop = route[i:-1]
            break

    print(roop[(k - i) % len(roop)])

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

d = {}
for i in range(1, n + 1):
    d[i] = a[i - 1]

did = set()
route = [1]

now = 1
for i in range(k):
    now = d[now]
    route.append(now)
    if now in did:
        break
    did.add(now)

for i in range(len(route)):
    if route[i] == route[-1]:
        roop = route[i:-1]
        break

print(roop[(k - i) % len(roop)])
Problem p02732 (python)

Fixed submission:
from collections import Counter
from operator import mul
from functools import reduce


def nCr(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


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

ac = dict(Counter(a))

ans = 0
for k, v in ac.items():
    if v < 2:
        ac[k] = (v, 0, 0)
    else:
        c = nCr(v, 2)
        ans += c
        if v - 1 < 2:
            ac[k] = (v, c, 0)
        else:
            ac[k] = (v, c, nCr(v - 1, 2))

for i in a:
    v = ac[i]
    if v[0] - 1 < 2:
        print(ans - v[1])
    else:
        print(ans - v[1] + v[2])

Buggy submission (verdict: Runtime Error):
from collections import Counter
from operator import mul
from functools import reduce


def nCr(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


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

ac = dict(Counter(a))

ans = 0
for k, v in ac.items():
    if v < 2:
        ac[k] = (v, 0)
    else:
        c = nCr(v, 2)
        ac[k] = (v, c)
        ans += c

for i in a:
    v = ac[i]
    if v[0] - 1 < 2:
        print(ans - v[1])
    else:
        print(ans - v[1] + nCr(v[0] - 1, 2))
from collections import Counter
import math


def nCr(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

ac = dict(Counter(a))

ans = 0
for k, v in ac.items():
    if v < 2:
        ac[k] = (v, 0)
    else:
        c = nCr(v, 2)
        ac[k] = (v, c)
        ans += c

for i in a:
    v = ac[i]
    if v[0] - 1 < 2:
        print(ans - v[1])
    else:
        print(ans - v[1] + nCr(v[0] - 1, 2))
Problem p02796 (python)

Fixed submission:
from operator import itemgetter

n = int(input())
xl = []

for i in range(n):
    x, l = map(int, input().split())
    xl.append([x - l, x + l])

xl = sorted(xl, key=itemgetter(1))

ans = 0
m = -float("inf")
for left, right in xl:
    if left < m:
        ans += 1
    else:
        m = max(m, right)

print(n - ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
xl = sorted([list(map(int, input().split())) for i in range(n)])

prev_right = -float("inf")
ans = 0
for i in range(n):
    now_left = xl[i][0] - xl[i][1]
    if prev_right > now_left:
        ans += 1
    else:
        prev_right = xl[i][0] + xl[i][1]

xl = reversed(xl)

prev_right = -float("inf")
ans_ = 0
for i in range(n):
    now_left = xl[i][0] - xl[i][1]
    if prev_right > now_left:
        ans_ += 1
    else:
        prev_right = xl[i][0] + xl[i][1]

print(n - min(ans, ans_))
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline


def dfs(v, par):
    for nv in tree[v]:
        if nv == par:
            continue
        add[nv] += add[v]
        dfs(nv, v)


n, q = map(int, input().split())
tree = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    tree[b].append(a)
    tree[a].append(b)
add = [0] * n
for i in range(q):
    p, x = map(int, input().split())
    p -= 1
    add[p] += x
dfs(0, -1)
print(*add)

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
tree = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    tree[b].append(a)
    tree[a].append(b)
add = [0] * n
for i in range(q):
    p, x = map(int, input().split())
    p -= 1
    add[p] += x
    

def dfs(v, par):
    for nv in tree[v]:
        if nv == par:
            continue
        add[nv] += add[v]
        dfs(nv, v)


dfs(0, -1)
print(*add)

Buggy submission (verdict: Runtime Error):
def dfs(v, par):
    for nv in tree[v]:
        if nv == par:
            continue
        add[nv] += add[v]
        dfs(nv, v)


n, q = map(int, input().split())
tree = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    tree[b].append(a)
    tree[a].append(b)
add = [0] * n
for i in range(q):
    p, x = map(int, input().split())
    p -= 1
    add[p] += x
dfs(0, -1)
print(*add)
Problem p03000 (python)

Fixed submission:
n, x = map(int, input().split())
L = list(map(int, input().split()))
if sum(L) <= x:
    print(n + 1)
else:
    i = 0
    d = 0
    while d <= x:
        d += L[i]
        i += 1
    print(i)

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
L = list(map(int, input().split()))
if sum(L) < x:
    print(n + 1)
else:
    i = 0
    d = 0
    while d <= x:
        d += L[i]
        i += 1
    print(i)

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
L = list(map(int, input().split()))
i = 0
d = 0
while d <= x:
    d += L[i]
    i += 1
print(i)
Problem p03074 (python)

Fixed submission:
n, k = map(int, input().split())
s = input()
if s.count("1") == n or s.count("0") == n:
    print(n)
    exit()
zero = 0
flag = 0
for i in s:
    if i == "0":
        flag = 1
    else:
        if flag:
            zero += 1
        flag = 0
if flag:
    zero += 1
k = min(zero, k)
renzoku = []
count = 0
flag = 0
for i in range(n):
    if s[i] == "1":
        if flag:
            count += 1
        else:
            renzoku.append(count)
            count = 1
        flag = 1
    else:
        if flag:
            renzoku.append(count)
            count = 1
        else:
            count += 1
        flag = 0
renzoku.append(count)
renzoku_t = [0]
for i in range(len(renzoku)):
    renzoku_t.append(renzoku[i] + renzoku_t[i])
ans = 0
if k == zero:
    print(n)
    exit()
if s[0] == "0":
    ans = renzoku_t[0 + k + k] - renzoku_t[0]
for i in range(1, len(renzoku) - k - k + 1, 2):
    if i == 0 or i == len(renzoku) - k - k:
        ans = max(ans, renzoku_t[i + k + k] - renzoku_t[i])
    else:
        ans = max(ans, renzoku_t[i + k + k + 1] - renzoku_t[i])
print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input()
if s.count("1") == n or s.count("0") == n:
    print(n)
    exit()
renzoku = []
count = 0
flag = 0
for i in range(n):
    if s[i] == "1":
        if flag:
            count += 1
        else:
            renzoku.append(count)
            count = 1
        flag = 1
    else:
        if flag:
            renzoku.append(count)
            count = 1
        else:
            count += 1
        flag = 0
renzoku.append(count)
renzoku_t = [0]
for i in range(len(renzoku)):
    renzoku_t.append(renzoku[i] + renzoku_t[i])
ans = 0
if s[0] == "0":
    ans = renzoku_t[0 + k + k] - renzoku_t[0]
for i in range(1, len(renzoku) - k - k + 1, 2):
    if i == 0 or i == len(renzoku) - k - k:
        ans = max(ans, renzoku_t[i + k + k] - renzoku_t[i])
    else:
        ans = max(ans, renzoku_t[i + k + k + 1] - renzoku_t[i])
print(ans)
Problem p03109 (python)

Fixed submission:
s = input()
s = list(map(int, s.split("/")))
if s[0] <= 2019 and s[1] <= 4 and s[2] <= 30:
    print("Heisei")
else:
    print("TBD")

Buggy submission (verdict: Runtime Error):
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if(s.compareTo("2019/04/30") <= 0){
            System.out.println("Heisei");
        } else {
            System.out.println("TBD");
        }
    }
}
Problem p03111 (python)

Fixed submission:
def dfs(i, A, B, C):
    global ans
    if i == n:
        if A and B and C:
            s = 0
            ABC = [A, B, C]
            for i in range(3):
                s += (len(ABC[i]) - 1) * 10 + abs(sum(ABC[i]) - abc[i])
            ans = min(ans, s)
    else:
        dfs(i + 1, A + [l[i]], B, C)
        dfs(i + 1, A, B + [l[i]], C)
        dfs(i + 1, A, B, C + [l[i]])
        dfs(i + 1, A, B, C)

n, a, b, c = map(int, input().split())
l = [int(input()) for i in range(n)]
abc = [a, b, c]
ans = float("inf")
dfs(0, [], [], [])
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
import itertools

n, a, b, c = map(int, input().split())
l = sorted([int(input()) for i in range(n)])
ABC = [a, b, c]
ans = float("inf")

def dfs(i, abc):
    global ans
    sum_a = 0
    l1 = l[:]
    if i == 3:
        for k in itertools.permutations([0, 1, 2], 3):
            for j in k:
                index = bisect.bisect_left(l1, ABC[j])
                if abc[j] == 0:
                    if index < len(l1):
                        sum_a += l1[index] - ABC[j]
                        l1.remove(l1[index])
                    else:
                        sum_a += float("inf")
                elif abc[j] == 1:
                    if index > 0:
                        sum_a += ABC[j] - l1[index - 1]
                        l1.remove(l1[index - 1])
                    else:
                        sum_a += float("inf")
                else:
                    sum_ = float("inf")
                    for x in range(2, len(l1) + 1):
                        for y in itertools.combinations(l1, x):
                            if sum_ > abs(sum(y) - ABC[j]):
                                sum_ = abs(sum(y) - ABC[j]) + (x - 1) * 10
                                l2 = l1[:]
                                for z in y:
                                    l2.remove(z)
                    l1 = l2[:]
                    sum_a += sum_
            ans = min(ans, sum_a)
        return 0
    dfs(i + 1, abc[:i] + [abc[i]] + abc[i + 1:])
    dfs(i + 1, abc[:i] + [abc[i] + 1] + abc[i + 1:])
    dfs(i + 1, abc[:i] + [abc[i] + 2] + abc[i + 1:])

dfs(0, [0, 0, 0])
print(ans)
Problem p03231 (python)

Fixed submission:
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return (a * b) // gcd(a, b)

n, m = map(int, input().split())
s = input()
t = input()
L = lcm(n, m)
l = lcm(L // n, L // m)
for i in range(0, L, l):
    if s[i // (L // n)] != t[i // (L // m)]:
        print(-1)
        exit()
print(L)

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return (a * b) // gcd(a, b)

n, m = map(int, input().split())
s = input()
t = input()
l = lcm(n, m)
ans = [""] * l
for i in range(n):
    ans[i * l // n] = s[i]
for i in range(m):
    if ans[i * l // m] and ans[i * l // m] != t[i]:
        print(-1)
        exit()
print(l)
Problem p03240 (python)

Fixed submission:
import itertools

n = int(input())
x = []
y = []
h = []
for i in range(n):
    X, Y, H = map(int, input().split())
    x.append(X)
    y.append(Y)
    h.append(H)
for t in range(n):
    if h[t] >= 1:
        break
for cx, cy in itertools.product(range(101), range(101)):
    H = h[t] + abs(x[t] - cx) + abs(y[t] - cy)
    if H < 1:
        continue
    for i in range(n + 1):
        if i == n:
            break
        if max(H - abs(x[i] - cx) - abs(y[i] - cy), 0) != h[i]:
            break
    if i == n:
        break
print("{} {} {}".format(cx, cy, H))

Buggy submission (verdict: Runtime Error):
import itertools

n = int(input())
x = []
y = []
h = []
for i in range(n):
    X, Y, H = map(int, input().split())
    x.append(X)
    y.append(Y)
    h.append(H)
for cx, cy in itertools.product(range(101), range(101)):
    H = []
    for i in range(n):
        if h[i] == 0:
            continue
        H.append(h[i] + abs(x[i] - cx) + abs(y[i] - cy))
    if len(set(H)) == 1 and H[0] >= 1:
        for j in range(n + 1):
            if i == n:
                break
            if max(H[0] - abs(x[j] - cx) - abs(y[j] - cy), 0) != h[j]:
                break
        if n == 1:
            break
print("{} {} {}".format(cx, cy, H[0]))
Problem p03241 (python)

Fixed submission:
n, m = map(int, input().split())
ans = 1
for i in range(1, int(m ** .5) + 1):
    if m % i == 0:
        b = m // i
        if i * n <= m:
            ans = max(ans, i)
        if b * n <= m:
            ans = max(ans, b)
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
for i in range(1, m):
    if m % i == 0:
        if m // i >= n:
            ans = i
        else:
            break
print(ans)
Problem p03244 (python)

Fixed submission:
import collections

n = int(input())
v = list(map(int, input().split()))
a = v[::2]
b = v[1::2]
ac = collections.Counter(a)
bc = collections.Counter(b)
ac = sorted(ac.items(), key=lambda x: x[1], reverse=True)
bc = sorted(bc.items(), key=lambda x: x[1], reverse=True)
if ac[0][0] == bc[0][0]:
    if len(ac) == len(bc) and len(ac) == 1:
        print(ac[0][1])
        exit()
    i = 0
    while ac[i][1] == bc[i][1]:
        i += 1
        if i == len(ac) - 1 or i == len(bc) - 1:
            break
    if ac[i][1] > bc[i][1]:
        ac.remove(ac[i])
        bc.remove(bc[0])
    elif ac[i][1] < bc[i][1]:
        ac.remove(ac[0])
        bc.remove(bc[i])
    else:
        ac.remove(ac[0])
        bc.remove(bc[1])
else:
    ac.remove(ac[0])
    bc.remove(bc[0])
ans = 0
for i in range(len(ac)):
    ans += ac[i][1]
for i in range(len(bc)):
    ans += bc[i][1]
print(ans)

Buggy submission (verdict: Runtime Error):
import collections

n = int(input())
v = list(map(int, input().split()))
a = v[::2]
b = v[1::2]
ac = collections.Counter(a).most_common(2)
bc = collections.Counter(b).most_common(2)
if ac[0][0] != bc[0][0]:
    print(n - ac[0][1] - bc[0][1])
else:
    print(n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1]))

Buggy submission (verdict: Runtime Error):
import collections

n = int(input())
v = list(map(int, input().split()))
a = v[::2]
b = v[1::2]
ac = collections.Counter(a)
bc = collections.Counter(b)
ac = sorted(ac.items(), key=lambda x: x[1], reverse=True)
bc = sorted(bc.items(), key=lambda x: x[1], reverse=True)
if ac[0][0] == bc[0][0]:
    if len(ac) == len(bc) and len(ac) == 1:
        print(ac[0][1])
        exit()
    i = 0
    while ac[i][1] == bc[i][1]:
        i += 1
    if ac[i][1] > bc[i][1]:
        ac.remove(ac[i])
        bc.remove(bc[0])
    elif ac[i][1] < bc[i][1]:
        ac.remove(ac[0])
        bc.remove(bc[i])
else:
    ac.remove(ac[0])
    bc.remove(bc[0])
ans = 0
for i in range(len(ac)):
    ans += ac[i][1]
for i in range(len(bc)):
    ans += bc[i][1]
print(ans)
Problem p03263 (python)

Fixed submission:
h, w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
ans = 0
ansl = []
for i in range(h):
    for j in range(w):
        if a[i][j] % 2 == 1 and a[i][j] >= 1:
            if j + 1 < w:
                a[i][j + 1] += 1
                a[i][j] -= 1
                ans += 1
                ansl.append([i + 1, j + 1, i + 1, j + 2])
for k in range(h):
    if a[k][-1] % 2 == 1:
        if k + 1 < h:
            a[k + 1][-1] += 1
            a[k][-1] -= 1
            ans += 1
            ansl.append([k + 1, w, k + 2, w])
print(ans)
for i in ansl:
    i = list(map(str, i))
    print(" ".join(i))

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
ans = 0
ansl = []
for i in range(h):
    for j in range(w - 1):
        if a[i][j] % 2 == 1 and a[i][j] >= 1:
            a[i][j + 1] += 1
            a[i][j] -= 1
            ans += 1
            ansl.append([i + 1, j + 1, i + 1, j + 2])
for k in range(h):
    if a[k][-1] % 2 == 1:
        a[i + 1][j] += 1
        a[i][j] -= 1
        ans += 1
        ansl.append([i + 1, j + 1, i + 2, j + 1])
print(ans)
for i in ansl:
    i = list(map(str, i))
    print(" ".join(i))
Problem p03274 (python)

Fixed submission:
import bisect
n, k = map(int, input().split())
x = list(map(int, input().split()))
z = bisect.bisect_left(x, 0)
a = sorted(map(abs, x[:z]))
b = x[z:]
ans = float("inf")
if a and b:
    for i in range(min(k, len(a))):
        if k - i - 2 >= len(b):
            continue
        ans = min(ans, min(a[i], b[k - i - 2]) * 2 + max(a[i], b[k - i - 2]))
    print(ans)
elif a:
    print(a[k - 1])
else:
    print(b[k - 1])

Buggy submission (verdict: Runtime Error):
import bisect
n, k = map(int, input().split())
x = list(map(int, input().split()))
z = bisect.bisect_left(x, 0)
a = sorted(map(abs, x[:z]))
b = x[z:]
ans = float("inf")
if a and b:
    for i in range(min([k, len(a), len(b)])):
        ans = min(ans, min(a[i], b[k - i - 2]) * 2 + max(a[i], b[k - i - 2]))
    print(ans)
elif a:
    print(a[k - 1])
else:
    print(b[k - 1])
Problem p03282 (python)

Fixed submission:
s = list(map(int, list(str(input()))))
k = int(input())
i = 0
if s.count(1) == len(s):
  print(1)
else:
  while s[i] == 1:
    i += 1
  if k <= i:
    print(1)
  else:
    print(s[i])

Buggy submission (verdict: Runtime Error):
s = list(map(int, list(str(input()))))
k = int(input())
i = 0
while s[i] == 1:
  i += 1
if k <= i:
  print(1)
else:
  print(s[i])
Problem p03294 (python)

Fixed submission:
n = int(input())
print(sum(list(map(int, input().split()))) - n)

Buggy submission (verdict: Runtime Error):
from functools import reduce

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

def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a % b)

def lcm_base(a, b):
  return a * b / gcd(a, b)

def lcm(n):
  return reduce(lcm_base, n)

f = 0
for i in a:
  f += (lcm(a) - 1) % i

print(int(f))

Buggy submission (verdict: Runtime Error):
from functools import reduce

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

def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a % b)

def lcm_base(a, b):
  return a * b / gcd(a, b)

def lcm(n):
  return reduce(lcm_base, n)

f = 0
for i in a:
  f += lcm(a) - 1 % i

print(int(f))

Buggy submission (verdict: Runtime Error):
from functools import reduce

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

def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a % b)

def lcm_base(a, b):
  return a * b / gcd(a, b)

def lcm(n):
  return reduce(lcm_base, n)

f = 0
m = lcm(a) - 1
for i in a:
  f += m % i

print(int(f))
Problem p03309 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
B = []
ans = 0
for i in range(n):
  B.append(a[i] - i - 1)
b = sorted(B)[len(B) // 2]
for i in range(n):
  ans += abs(B[i] - b)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
ans = []
for b in range(-(n // 2), n // 2):
  total = 0
  for i in range(n):
    total += abs(a[i] - (b + i + 1))
  ans.append(total)
print(min(ans))
Problem p03316 (python)

Fixed submission:
s = input()
if int(s) % sum(map(int, list(s))):
  print("No")
else:
  print("Yes")

Buggy submission (verdict: Runtime Error):
s = input()
if s % sum(map(int, list(s))):
  print("No")
else:
  print("Yes")
Problem p03353 (python)

Fixed submission:
s = input()
k = int(input())
sub = []
for i in range(len(s)):
    for j in range(i, i + k + 1):
        sub.append(s[i:j])
print(sorted(set(sub))[k])

Buggy submission (verdict: Runtime Error):
s = list(input())
k = int(input())
a = set()
for i in range(len(s)):
  for j in range(i, len(s)):
    a.add(s[i:j + 1])
a = sorted(a)
print(a[k - 1])
Problem p03360 (python)

Fixed submission:
a, b, c = map(int, input().split())
k = int(input())
for i in range(k):
  if a >= b and a >= c:
    a *= 2
  elif b >= a and b >= c:
    b *= 2
  else:
    c *= 2
print(sum([a, b, c]))

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
k = int(input())
for i in range(k):
  if a >= b and a >= c:
    a *= 2
  elif b >= a and b >= c:
    b *= 2
  else:
    c *= 2
print(sum(a, b, c))
Problem p03386 (python)

Fixed submission:
a, b, k = map(int, input().split())
if (b - a + 1) > 2 * k:
  for i in range(a, a + k):
    print(i)
  for j in range(b - k + 1, b + 1):
    print(j)
else:
  for n in range(a, b + 1):
    print(n)

Buggy submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
n = list(range(a, b + 1))
s = set()
for i in n[:k]:
  s.add(i)
for j in n[-k:]:
  s.add(j)
for k in sorted(list(s)):
  print(k)