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

Fixed submission:
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N, M = list(map(int, sys.stdin.buffer.readline().split()))
S = sys.stdin.buffer.readline().decode().rstrip()

# 後ろから貪欲
ans = []
S = S[::-1]

pos = [N + 1] * len(S)
p = N + 1
l = N
while p - l <= M and l >= 0:
    pos[l] = p
    l -= 1
p -= 1
while p >= 0:
    if S[p] == '1':
        p -= 1
        continue

    while p - l <= M and l >= 0:
        pos[l] = p
        l -= 1
    p -= 1

i = 0
while i < N:
    me = None
    for j in reversed(range(1, min(M + 1, pos[i] - i + 1))):
        if i + j < len(S) and S[i + j] == '0':
            me = j
            break
    if me is None:
        print(-1)
        exit()
    ans.append(me)
    i += me
print(*ans[::-1])

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

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N, M = list(map(int, sys.stdin.buffer.readline().split()))
S = sys.stdin.buffer.readline().decode().rstrip()

# 後ろから貪欲
ans = []
S = S[::-1]

pos = [N + 1] * len(S)
p = N + 1
l = N
while p - l <= M:
    pos[l] = p
    l -= 1
p -= 1
while p >= 0:
    if S[p] == '1':
        p -= 1
        continue

    while p - l <= M and l >= 0:
        pos[l] = p
        l -= 1
    p -= 1

i = 0
while i < N:
    me = None
    for j in reversed(range(1, min(M + 1, pos[i] - i + 1))):
        if i + j < len(S) and S[i + j] == '0':
            me = j
            break
    if me is None:
        print(-1)
        exit()
    ans.append(me)
    i += me
print(*ans[::-1])
Problem p02971 (python)

Fixed submission:
import itertools
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(N)]

a = list(itertools.accumulate(A, max))
b = list(itertools.accumulate(A[::-1], max))[::-1]

for i in range(len(A)):
    r = 0
    if 0 <= i - 1 < N:
        r = max(r, a[i - 1])
    if 0 <= i + 1 < N:
        r = max(r, b[i + 1])
    print(r)

Buggy submission (verdict: Runtime Error):
import itertools
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(N)]

a = list(itertools.accumulate(A, max))
b = list(itertools.accumulate(A[::-1], max))[::-1]

for i in range(len(A)):
    r = 0
    if 0 <= i - 1 < N:
        r = max(r, a[i - 1])
    if 0 <= i + 1 < N:
        r = max(r, b[i + 1])
    print(r)
Problem p02975 (python)

Fixed submission:
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

ok = False
counts = dict(Counter(A))
keys = counts.keys()
if len(counts) <= 3:
    for k1, k2, k3 in itertools.product(keys, repeat=3):
        cnt = counts.copy()
        s = k1
        cnt[k1] -= 1
        cnt[k2] -= 1
        if k1 ^ k2 != k3:
            continue
        n = 2
        while n < N:
            cnt[k3] -= 1
            k1, k2, k3 = k2, k3, k2 ^ k3
            n += 1
        if s == k3 and not any(cnt.values()):
            ok = True
            break

if ok:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

if len(A) % 3 == 0:
    c = Counter(A)
    k = c.keys()
    s = len(c.keys())
    if len(k) == 3:
        ok = len(Counter(c.values()).keys()) == 1
    if len(k) == 2:
        ok = min(c.values()) * 2 == max(c.values())
    if len(k) == 1:
        ok = True
else:
    ok = False
if ok:
    print('Yes')
else:
    print('No')
Problem p02976 (python)

Fixed submission:
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = list(map(int, sys.stdin.readline().split()))
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]

graph = [[] for _ in range(N + 1)]
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)


def spanning_tree(root, ret=None, seen=None):
    if ret is None:
        ret = [set() for _ in range(N + 1)]
    if seen is None:
        seen = [False] * (N + 1)
        seen[root] = True
    for v in graph[root]:
        if seen[v]:
            continue
        ret[root].add(v)
        seen[v] = True
        ret = spanning_tree(v, ret, seen)
    return ret


if M % 2 == 1:
    print(-1)
    exit()

# 全域木
root = 1
st = spanning_tree(root)

# 出次数
outdeg = [0] * (N + 1)
ans = []
# 使わなかった辺に向きをつける
for a, b in AB:
    if a not in st[b] and b not in st[a]:
        ans.append((a, b))
        outdeg[a] += 1


def dfs(par):
    # 全域木で par 以下の辺に向きをつける
    for v in st[par]:
        if st[v]:
            dfs(v)
        if outdeg[v] % 2 == 0:
            ans.append((par, v))
            outdeg[par] += 1
        else:
            ans.append((v, par))
            outdeg[v] += 1


dfs(root)
for r in ans:
    print(*r)

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

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = list(map(int, sys.stdin.readline().split()))
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]

graph = [[] for _ in range(N + 1)]
counts = defaultdict(int)
for i, (a, b) in enumerate(AB):
    graph[a].append((b, i))
    graph[b].append((a, i))
    counts[a] += 1
    counts[b] += 1

# 偶数なら全部出す
ans = []
used = [False] * (N + 1)
p = -1
while p != len(ans):
    p = len(ans)
    for v in range(1, N + 1):
        if counts[v] % 2 == 0:
            for u, i in graph[v]:
                if used[i]:
                    continue
                ans.append((v, u))
                used[i] = True
                counts[v] -= 1
                counts[u] -= 1
if len(ans) == M:
    for a in ans:
        print(*a)
else:
    print(-1)
Problem p02991 (python)

Fixed submission:
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18

N, M = list(map(int, sys.stdin.readline().split()))
UV = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]
S, T = list(map(int, sys.stdin.readline().split()))

graph = [[] for _ in range(N + 1)]
for u, v in UV:
    graph[u].append(v)

que = deque()
que.append((S, 0))
reached = np.zeros((N + 1, 3), dtype=bool)
reached[S, 0] = True

while que:
    u, step = que.popleft()
    for v in graph[u]:
        s = step + 1
        if not reached[v, s % 3]:
            reached[v, s % 3] = True
            que.append((v, s))
        if v == T and s % 3 == 0:
            print(s // 3)
            exit()
print(-1)

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

import numpy as np
from functools import lru_cache

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18

N, M = list(map(int, sys.stdin.readline().split()))
UV = [list(map(int, sys.stdin.readline().split())) for _ in range(M)]
S, T = list(map(int, sys.stdin.readline().split()))

graph = np.zeros((N + 1, N + 1), dtype=bool)
for u, v in UV:
    graph[u][v] = True


@lru_cache(maxsize=None)
def dest(v, count):
    if count <= 1:
        return graph[v]
    ret = np.zeros((N + 1), dtype=bool)
    for u in np.where(graph[v])[0]:
        ret |= dest(u, count - 1)
    return ret


checked = np.zeros(N + 1, dtype=bool)
vs = np.zeros(N + 1, dtype=bool)
vs[S] = True
i = 0
prev = 0
while True:
    i += 1
    s = np.zeros(N + 1, dtype=bool)
    for v in np.where(vs)[0]:
        s |= dest(v, 3)
    checked |= vs
    if s[T]:
        print(i)
        break
    if checked.sum() == prev:
        print(-1)
        break
    vs = s ^ checked
    prev = checked.sum()
Problem p02995 (python)

Fixed submission:
import math
import os
import sys
from decimal import *
from fractions import gcd

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

A, B, C, D = list(map(int, sys.stdin.readline().split()))
A = Decimal(A)
B = Decimal(B)
C = Decimal(C)
D = Decimal(D)


def count(n):
    st = math.ceil(A / n)
    en = math.floor(B / n)
    return max(0, en - st + 1)


print(B - A + 1 - (count(C) + count(D) - count(C * D // gcd(C, D))))

#
# N = int(sys.stdin.readline())
# A, B = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(N)]))

Buggy submission (verdict: Runtime Error):
import math
import os
import sys
from fractions import gcd
from decimal import *

from libs.debug import debug

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

A, B, C, D = list(map(int, sys.stdin.readline().split()))
A = Decimal(A)
B = Decimal(B)
C = Decimal(C)
D = Decimal(D)


def count(n):
    st = math.ceil(A / n)
    en = math.floor(B / n)
    return max(0, en - st + 1)


print(B - A + 1 - (count(C) + count(D) - count(C * D // gcd(C, D))))

#
# N = int(sys.stdin.readline())
# A, B = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(N)]))
Problem p03078 (python)

Fixed submission:
import heapq

x, y, z, k = map(int, input().split())
ali = list(reversed(sorted(map(int, input().split()))))
bli = list(reversed(sorted(map(int, input().split()))))
cli = list(reversed(sorted(map(int, input().split()))))

done = {}
count = 0

heap = []


def main(a, b, c):
    global count
    if '{}'.format((a, b, c)) in done:
        return
    done['{}'.format((a, b, c))] = True
    count += 1
    print(ali[a] + bli[b] + cli[c])
    if a + 1 < x:
        heapq.heappush(heap, (-(ali[a + 1] + bli[b] + cli[c]), a + 1, b, c))
    if b + 1 < y:
        heapq.heappush(heap, (-(ali[a] + bli[b + 1] + cli[c]), a, b + 1, c))
    if c + 1 < z:
        heapq.heappush(heap, (-(ali[a] + bli[b] + cli[c + 1]), a, b, c + 1))


main(0, 0, 0)
while count < k:
    s, a, b, c = heapq.heappop(heap)
    main(a, b, c)

Buggy submission (verdict: Runtime Error):
import heapq

x, y, z, k = map(int, input().split())
ali = list(reversed(sorted(map(int, input().split()))))
bli = list(reversed(sorted(map(int, input().split()))))
cli = list(reversed(sorted(map(int, input().split()))))

done = {}
count = 0

heap = []


def main(a, b, c):
    global count
    if f'{a, b, c}' in done:
        return
    done[f'{a, b, c}'] = True
    count += 1
    print(ali[a] + bli[b] + cli[c])
    if a + 1 < x:
        heapq.heappush(heap, (-(ali[a + 1] + bli[b] + cli[c]), a + 1, b, c))
    if b + 1 < y:
        heapq.heappush(heap, (-(ali[a] + bli[b + 1] + cli[c]), a, b + 1, c))
    if c + 1 < z:
        heapq.heappush(heap, (-(ali[a] + bli[b] + cli[c + 1]), a, b, c + 1))


main(0, 0, 0)
while count < k:
    s, a, b, c = heapq.heappop(heap)
    main(a, b, c)
Problem p03079 (python)

Fixed submission:
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")


a, b, c = list(map(int, sys.stdin.readline().split()))
if a==b==c:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")


a, b, c = list(map(int, sys.stdin.readline().split()))
if a==b==c:
    print('Yes')
else:
    print('No')
Problem p03128 (python)

Fixed submission:
n, _ = map(int, input().split())
numbers = list(map(int, input().split()))
reqs = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
}

memo = {}


def max_counts(a, b):
    """
    a と b 大きい方を返す
    :param a: solve() の返り値
    :param b: solve() の返り値
    :return:
    """
    if a is None:
        return b
    if b is None:
        return a
    # 桁数は大きいほうが大きい
    if sum(a) > sum(b):
        return a
    if sum(a) < sum(b):
        return b
    # 桁数が同じなら、大きい数字の多いほうが大きい
    for a_c, b_c in zip(reversed(a), reversed(b)):
        if a_c > b_c:
            return a
        if a_c < b_c:
            return b
    return a


# https://atcoder.jp/contests/abc118/submissions/4911280
# DP 版
memo[0] = [0 for _ in range(10)]
for i in range(n):
    if i in memo:
        for num in numbers:
            next_n = i + reqs[num]
            next_counts = memo[next_n] if next_n in memo else None
            if next_n <= n:
                memo[next_n] = max_counts(
                    next_counts,
                    memo[i][:num] + [memo[i][num] + 1] + memo[i][num + 1:]
                )

ans = ''
for num in range(9, 0, -1):
    for _ in range(memo[n][num]):
        ans += str(num)
print(ans)

Buggy submission (verdict: Runtime Error):
n, _ = map(int, input().split())
numbers = list(map(int, input().split()))
reqs = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
}

memo = {}


def max_counts(a, b):
    """
    a と b 大きい方を返す
    :param a: solve() の返り値
    :param b: solve() の返り値
    :return:
    """
    if a is None:
        return b
    if b is None:
        return a
    # 桁数は大きいほうが大きい
    if sum(a) > sum(b):
        return a
    if sum(a) < sum(b):
        return b
    # 桁数が同じなら、大きい数字の多いほうが大きい
    for a_c, b_c in zip(reversed(a), reversed(b)):
        if a_c > b_c:
            return a
        if a_c < b_c:
            return b
    return a


def solve(n):
    """
    n 本のマッチを使ったときの最大の整数の 0 から 9 までの使用回数をリストで返す
    :param n:
    :rtype: list of int
    """
    if n in memo:
        return memo[n]
    if n == 0:
        return [0 for _ in range(10)]
    if n < 0:
        return None

    res = None
    for num in numbers:
        counts = solve(n - reqs[num])
        if counts:
            res = max_counts(res, counts[:num] + [counts[num] + 1] + counts[num + 1:])

    memo[n] = res
    return res


result_counts = solve(n)
ans = ''
for num in range(9, 0, -1):
    for _ in range(result_counts[num]):
        ans += str(num)
print(ans)
Problem p03148 (python)

Fixed submission:
import heapq

INF = float('inf')
n, k = map(int, input().split())
sushi = {}

for _ in range(n):
    t, d = map(int, input().split())
    if t not in sushi:
        sushi[t] = []
    sushi[t].append(d)

for s in sushi.values():
    s.sort(reverse=True)

eat_counts = {s: 0 for s in sushi.keys()}

# まだ食べてないやつ
news = []
# リピート
repeats = []
# 食べた履歴
eats = []

# 各寿司の一番おいしいやつを heap へ
for name, deli_li in sushi.items():
    # (-おいしさ, name)
    heapq.heappush(news, (-deli_li[0], name))

sum_deli = 0
variety = 0

for _ in range(k):
    # おいしいやつから食べる
    if news and (not repeats or news[0] <= repeats[0]):
        deli, name = heapq.heappop(news)
        variety += 1
    else:
        deli, name = heapq.heappop(repeats)

    sum_deli += -deli
    eat_counts[name] += 1
    heapq.heappush(eats, (-deli, name))
    if eat_counts[name] < len(sushi[name]):
        heapq.heappush(repeats, (-sushi[name][eat_counts[name]], name))

# 美味しいやつから順に食べた
# 種類増やしたらもっと得点上がるか確かめる
ans = sum_deli + variety ** 2
while True:
    if not news or not eats:
        break

    # 食べたやつポイント小さいやつから置き換えたい
    ate_min_deli, ate_min_name = heapq.heappop(eats)
    eat_counts[ate_min_name] -= 1
    if eat_counts[ate_min_name] <= 0:
        # これは種類減っちゃうからだめ
        continue

    sum_deli -= ate_min_deli

    deli, name = heapq.heappop(news)
    variety += 1
    sum_deli += -deli
    eat_counts[name] += 1

    ans = max(ans, sum_deli + variety ** 2)

print(ans)

Buggy submission (verdict: Runtime Error):
import heapq

INF = float('inf')
n, k = map(int, input().split())
sushi = {}

for _ in range(n):
    t, d = map(int, input().split())
    if t not in sushi:
        sushi[t] = []
    sushi[t].append(d)

for s in sushi.values():
    s.sort(reverse=True)

eat_counts = {s: 0 for s in sushi.keys()}

# まだ食べてないやつ
news = []
# リピート
repeats = []
# 食べた履歴
eats = []

# 各寿司の一番おいしいやつを heap へ
for name, deli_li in sushi.items():
    # (-おいしさ, name)
    heapq.heappush(news, (-deli_li[0], name))

sum_deli = 0
variety = 0

for _ in range(k):
    # おいしいやつから食べる
    if news and (not repeats or news[0] <= repeats[0]):
        deli, name = heapq.heappop(news)
        variety += 1
    else:
        deli, name = heapq.heappop(repeats)

    sum_deli += -deli
    eat_counts[name] += 1
    heapq.heappush(eats, (-deli, name))
    if eat_counts[name] < len(sushi[name]):
        heapq.heappush(repeats, (-sushi[name][eat_counts[name]], name))

# 美味しいやつから順に食べた
# 種類増やしたらもっと得点上がるか確かめる
ans = sum_deli + variety ** 2
while True:
    if not news:
        break

    # 食べたやつポイント小さいやつから置き換えたい
    ate_min_deli, ate_min_name = heapq.heappop(eats)
    eat_counts[ate_min_name] -= 1
    if eat_counts[ate_min_name] <= 0:
        # これは種類減っちゃうからだめ
        continue

    sum_deli -= ate_min_deli

    deli, name = heapq.heappop(news)
    variety += 1
    sum_deli += -deli
    eat_counts[name] += 1

    ans = max(ans, sum_deli + variety ** 2)

print(ans)
Problem p03219 (python)

Fixed submission:
import functools
import math

import os

INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


def inl():
    return list(map(int, input().split()))


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        ret = fn(*args, **kwargs)
        print(ret)
        return ret

    return wrapper


x, y = inl()
print(x+y // 2)

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

import os

INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


def inl():
    return list(map(int, input().split()))


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        ret = fn(*args, **kwargs)
        print(ret)
        return ret

    return wrapper


print(inp() + inp() // 2)
Problem p03238 (python)

Fixed submission:
import functools
import math

import os

INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


def inl():
    return list(map(int, input().split()))


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        ret = fn(*args, **kwargs)
        print(ret)
        return ret

    return wrapper


n = inp()
if n == 1:
    print ("Hello World")
    exit()

a = inp()
b = inp()
print(a+b)

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

import os

INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


def inl():
    return list(map(int, input().split()))


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        ret = fn(*args, **kwargs)
        print(ret)
        return ret

    return wrapper


n = inp()
if n == 1:
    print ("Hello World")

a = inp()
b = inp()
print(a+b)
Problem p03282 (python)

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


count1 = 0
for c in S:
    if c == '1':
        count1 += 1
    else:
        break
next_c = c

if K <= count1:
    print('1')
else:
    print(next_c)

Buggy submission (verdict: Runtime Error):
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


S = sys.stdin.buffer.readline().decode().rstrip()
K = int(sys.stdin.buffer.readline())

i = 0
while S[i] == '1':
    i += 1
if K <= i:
    print('1')
else:
    print(S[i])