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


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


def main():
    N, M = map(int, input().split())

    w = [[] for _ in range(10 ** 5)]
    for _ in range(N):
        a, b = map(int, input().split())
        w[a].append(b)

    ans = 0
    hq = []
    for i in range(1, M+1):
        for x in w[i]:
            heapq.heappush(hq, -x)

        if not hq:
            continue

        ans += -heapq.heappop(hq)

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
import heapq


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


def main():
    N, M = map(int, input().split())

    w = [[] for _ in range(10 ** 5 + 1)]
    for _ in range(N):
        a, b = map(int, input().split())
        w[a].append(b)

    ans = 0
    hq = []
    for i in range(1, M+1):
        for x in w[i]:
            heapq.heappush(hq, -x)

        if not hq:
            continue

        ans += -heapq.heappop(hq)

    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import heapq
input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    W = []
    for i in range(N):
        a, b = map(int, input().split())
        W.append((-b, a))

    ans = 0
    for i in range(1, M+1):
        ab = list(filter(lambda x: x[1] <= i, W))
        if len(ab) == 0:
            continue
        heapq.heapify(ab)
        ans -= ab[0][0]
        W.remove(ab[0])

    print(ans)
    return


if __name__ == "__main__":
    main()


Fixed submission:
import sys
import heapq


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


def main():
    N, M = map(int, input().split())

    w = [[] for _ in range(10 ** 5 + 1)]
    for _ in range(N):
        a, b = map(int, input().split())
        w[a].append(b)

    ans = 0
    hq = []
    for i in range(1, M+1):
        for x in w[i]:
            heapq.heappush(hq, -x)

        if not hq:
            continue

        ans += -heapq.heappop(hq)

    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

def solve(N, A):
    def moutain(x):
        sum = 0
        for i in range(N):
            sum += A[(x+i)%N] * (-1) ** (i)
        return sum

    m = [int()] * N
    for i in range(N):
        m[i] = str(moutain(i))

    print(' '.join(m))

def main():
    N = int(input())
    A = list(map(int, input().split()))
    solve(N, A)

if __name__ == "__main__":
    main()

Fixed submission:
import sys

def solve(N, A):
    m = [int()] * (N)
    for i in range(N):
        m[0] += A[i] * (-1)**i

    for i in range(1, N):
        m[i] = ((A[i-1]) * 2 - m[i-1])

    m = map(str, m)
    print(' '.join(m))

def main():
    N = int(input())
    A = list(map(int, input().split()))
    solve(N, A)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
from collections import deque

def solve(N, M, to, start, goal):
    def kenkenpa(f):
        t = []
        for k1 in to[f]:
            for k2 in to[k1]:
                for pa in to[k2]:
                    t.append(pa)
        return t

    new_to = [ [] for _ in range(N+1) ]
    for i in range(1, N+1):
        new_to[i] = kenkenpa(i)
    
    costs = [float('inf')] * (N+1)
    costs[start] = 0

    q = deque()
    q.append(start)

    while len(q) != 0:
        u = q.popleft()
        if u == goal: return costs[u]
        for v in new_to[u]:
            if costs[u] + 1 < costs[v]:
                costs[v] = costs[u] + 1
                q.append(v)
    return -1



def main():
    N, M = map(int, input().split())
    to = [ [] for _ in range(N+1) ]
    for _ in range(M):
        u, v = map(int, input().split())
        to[u].append(v)
    S, T = map(int, input().split())
    print(solve(N, M, to, S, T))

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
from collections import deque

def solve(N, M, to, start, goal):
    costs = [float('inf')] * (3*N+3)
    costs[start] = 0

    q = deque([start])

    while len(q) != 0:
        u = q.popleft()
        for v in to[u]:
            if costs[u] + 1 < costs[v]:
                costs[v] = costs[u] + 1
                if v == goal: return costs[v] // 3
                q.append(v)
    return -1



def main():
    N, M = map(int, input().split())
    to = [ [] for _ in range(3*N+3) ]
    for _ in range(M):
        u, v = map(int, input().split())
        for i in range(3):
            to[u + (N+1)*i].append(v + (N+1) * ((i+1)%3))
    S, T = map(int, input().split())
    print(solve(N, M, to, S, T))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from collections import namedtuple
import functools

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, t: "List[int]", x: "List[int]", y: "List[int]"):
    for i in range(N):
        min_length = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i])
        travel_time = t[i+1] - t[i]

        if min_length > travel_time:
            return NO
        elif min_length == travel_time:
            next
        elif (travel_time - min_length) % 2 == 0:
            next
        else:
            return NO

    return YES


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    t = [int()] * (N)  # type: "List[int]" 
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        t[i] = int(next(tokens))
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    t.insert(0, 0)
    x.insert(0, 0)
    y.insert(0, 0)
    print(solve(N, t, x, y))

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys


def solve(S: str):
    for i in range(len(S) - 1):
        if S[i] == S[i+1]:
            return 'Bad'
    return 'Good'


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = str(next(tokens))  # type: str
    print(solve(S))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
import math

def solve(A: int, B: int, C: int, D: int):
    def can_div_by(x: int):
        return (B // x) - (A - 1) // x

    c = can_div_by(C)
    d = can_div_by(D)
    cd = can_div_by(C*D // math.gcd(C, D))
    return B - A + 1 - (c + d - cd)

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    print(solve(A, B, C, D))

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
import fractions

def solve(A: int, B: int, C: int, D: int):
    def can_div_by(x: int):
        return (B // x) - (A - 1) // x

    c = can_div_by(C)
    d = can_div_by(D)
    cd = can_div_by(C*D // fractions.gcd(C, D))
    return B - A + 1 - (c + d - cd)

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    print(solve(A, B, C, D))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline


def main():
    N, W = map(int, input().split())
    w = [0] * N
    v = [0] * N
    for i in range(N):
        w[i], v[i] = map(int, input().split())

    dp = [[0]*(W+1) for _ in range(N+1)]

    for j in range(W+1):
        dp[0][j] = 0

    for i in range(0, N):
        for j in range(W+1):
            if j < w[i]:
                dp[i+1][j] = dp[i][j]
            else:
                dp[i+1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i])

    print(dp[N][W])


if __name__ == "__main__":
    main()


Fixed submission:
import sys
import numpy as np
input = sys.stdin.readline


def main():
    N, W = map(int, input().split())
    w = np.zeros(N, dtype=int)
    v = np.zeros(N, dtype=int)
    for i in range(N):
        w[i], v[i] = map(int, input().split())

    dp = np.zeros((N+1, W+1), dtype=np.int64)

    for i in range(0, N):
        dp[i+1][:w[i]] = dp[i][:w[i]]
        dp[i+1][w[i]:] = np.maximum(dp[i][w[i]:], dp[i][:-w[i]] + v[i])

    print(dp[N][W])


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
from functools import reduce

def solve():
    pass

def main():
    N = int(input())
    a = list(map(int, input().split()))
    colors = [0] * 9 # 8色 + 任意の1色
    for rate in a:
        colors[rate // 400] += 1

    mn = 0
    for c in colors[0:8]:
        if c != 0:
            mn += 1

    mx = mn + min(8 - mn, colors[8])
    print(mn, mx)

if __name__ == "__main__":
    main()

Fixed submission:
import sys

def main():
    N = int(input())
    a = list(map(int, input().split()))
    colors = [0] * 9 # 8色 + 任意の1色
    for rate in a:
        colors[min(rate // 400, 8)] += 1

    used = 0
    for c in colors[0:8]:
        if c != 0:
            used += 1

    mn = max(used, 1)
    mx = used + colors[8]
    print(mn, mx)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
print(min(m * a, b))

Fixed submission:
n, a, b = map(int, input().split())
print(min(n * a, b))
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    n = int(input())
    al = [int(i) for i in input().split()]
    a = n // 2
    s = sum(al)
    ans = [0] * n
    for i in range(n):
        f = s
        for j in range(a):
            f -= 2 * al[(i - (1 + 2 * (j + 1)) + n) % n]
        ans[i] = str(f)
    print(" ".join([i for i in ans[1:]]) + " " + ans[0])

if __name__=="__main__":
    solve()


Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    n = int(input())
    al = [int(i) for i in input().split()]
    a = n // 2
    s = sum(al)
    ans = [0] * n
    for j in range(a):
        s -= 2 * al[(0 - (1 + 2 * (j + 1)) + n) % n]
    ans[n - 1] = s
    for i in range(n - 2, -1, -1):
        ans[i] = 2 * al[i] - ans[i + 1]
    print(" ".join([str(i) for i in ans]))

if __name__=="__main__":
    solve()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    n = int(input())
    al = [int(i) for i in input().split()]
    a = n // 2
    s = sum(al)
    ans = [0] * n
    for i in range(n):
        f = s
        for j in range(a):
            f -= 2 * al[(i - (1 + 2 * (j + 1)) + n) % n]
        ans[i] = f
    ans = ans[1:] + [ans[0]]
    print(" ".join([str(i) for i in ans]))

if __name__=="__main__":
    solve()


Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    n = int(input())
    al = [int(i) for i in input().split()]
    a = n // 2
    s = sum(al)
    ans = [0] * n
    for j in range(a):
        s -= 2 * al[(0 - (1 + 2 * (j + 1)) + n) % n]
    ans[n - 1] = s
    for i in range(n - 2, -1, -1):
        ans[i] = 2 * al[i] - ans[i + 1]
    print(" ".join([str(i) for i in ans]))

if __name__=="__main__":
    solve()
Buggy python submission (verdict: Runtime Error):
n, m, c = map(int, input().split())
bl = [int(i) for i in input().split()]
ans = 0
for i in range(n):
  al = [int(j) for j in input().split()]
  ans += sum([bl[j] * al[j] for j in range(m)) + c > 0
print(ans)

Fixed submission:
n, m, c = map(int, input().split())
bl = [int(i) for i in input().split()]
ans = 0
for i in range(n):
  al = [int(j) for j in input().split()]
  ans += sum([bl[j] * al[j] for j in range(m)]) + c > 0
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = 0
d = { 'JPY': 1, 'BTC': 380000.0}
for _ in range(n):
  a, b = input().split()
  ans += int(a) * d[b]
print(ans)

Fixed submission:
n = int(input())
ans = 0
d = { 'JPY': 1, 'BTC': 380000.0}
for _ in range(n):
  a, b = input().split()
  ans += float(a) * d[b]
print(ans)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import defaultdict
import itertools

def solve():
    t = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
    dt = {0:0, 1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

    n, m = map(int, input().split())
    al = [int(i) for i in input().split()]
    al.sort(reverse=True)
    d = defaultdict(list)
    for i in al:
        d[dt[i]].append(i)
    k = list(sorted(d.keys()))
    ans = ''
    if n % k[0] == 0:
        ans += str(d[k[0]][0]) * (n // k[0])
    else:
        p = n % k[0]
        s = []
        k1 = k[1:]
        for i in range(9, 0, -1):
            if i > len(k1):
                continue
            for j in list(itertools.combinations(k1, i)):
                l = [dt[w] for w in j]
                if p == sum(l) % k[0]:
                    s.append(list(j))
        mt, ma, mx = 10 ** 20, [0] * 5, 0
        tans = [None] * len(s)
        for idx, i in enumerate(s):
            i.sort(reverse=True)
            _tans = ''.join([str(d[w][0]) for w in i])
            _tans += str(d[k[0]][0]) * ((n - sum(i)) // k[0])
            _tans = list(_tans)
            _tans.sort(reverse=True)
            tans[idx] = (''.join(_tans))
        ans = 0
        for i in tans:
            ans = max(ans, int(i))
        ans = str(ans)
    ans = list(ans)
    ans.sort(reverse=True)
    print(''.join(ans))


if __name__=="__main__":
    solve()


Fixed submission:
a, b = map(int, input().split())
print((a + b) if b % a == 0 else (b - a))
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import bisect

def solve():
    n = int(input())
    al = [int(i) for i in input().split()]
    al.sort()
    while len(al) > 1:
        p = al[-1] % sum(al[:-1])
        q = al[-1]
        al = al[:-1]
        if p == 0:
            continue
        if p == q:
            q -= al[-1]
            if q <= 0:
                continue
            p = q
        bisect.insort(al, p)
    print(al[0])

if __name__=="__main__":
    solve()


Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def gcd(a, b):
    if a < b:
        a,b = b,a
    while b > 0:
        r = a % b
        a,b = b,r
    return a

def arrgcd(a):
    alen = len(a)
    if alen == 3:
        return gcd(a[0], gcd(a[1], a[2]))
    elif alen == 2:
        return gcd(a[0], a[1])
    elif alen == 1:
        return a[0] # 最初から1つ
    elif alen == 0:
        return 0
    else:
        return gcd(arrgcd(a[:alen//2]), arrgcd(a[alen//2:]))

def solve():
    n = int(input())
    al = [int(i) for i in input().split()]
    print(arrgcd(al))

if __name__=="__main__":
    solve()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

al = [0, 5] + [0] * 49
bl = [0, 3] + [0] * 49


def solve2(ans, x, idx, cnt):
    if idx == 1:
        return ans + (0, 0, 1, 2, 3, 3, 3)[x] + [0, 1][cnt >= 1]
    if x == (al[idx] // 2) + 1:
        return ans + bl[idx - 1] + 1 + [0, 1][cnt >= 1]
    elif x > (al[idx] // 2) + 1:
        ans += bl[idx - 1]
        x -= (al[idx] // 2)
        cnt += 1
    return solve2(ans, x, idx - 1, cnt)


def solve():
    n, x = map(int, input().split())
    for i in range(2, n + 1):
        al[i] = al[i - 1] * 2 + 3
        bl[i] = bl[i - 1] * 2 + 1
    ans = solve2(0, x, n, 0)
    print(ans)


if __name__ == "__main__":
    solve()


Fixed submission:
d = int(input())
if d == 25:
  print("Christmas")
elif d == 24:
  print("Christmas Eve")
elif d == 23:
  print("Christmas Eve Eve")
elif d == 22:
  print("Christmas Eve Eve Eve")
Buggy python submission (verdict: Runtime Error):
n = int(input())
al = [int(input()) for _ in range(n)]
m = max(al)
s, f = 0, True
for i in range(n):
  if al[i] == m and flag:
    s += al[i] // 2
    f = False
  else:
    s += al[i]
print(s)


Fixed submission:
n = int(input())
al = [int(input()) for _ in range(n)]
m = max(al)
s, f = 0, True
for i in range(n):
  if al[i] == m and f:
    s += al[i] // 2
    f = False
  else:
    s += al[i]
print(s)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
hl = [int(input()) for _ in range(n)]
hl.sort()
print(min([hl[k - 1 + i] - hl[i] for i in range(0, n - k + 1)))


Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def solve():
    n, k = map(int, input().split())
    hl = [int(input()) for _ in range(n)]
    hl.sort()
    diff = hl[k - 1] - hl[0]
    for i in range(0, n - k + 1):
        td = hl[k - 1 + i] - hl[i]
        diff = min(td, diff)
    print(diff)


if __name__ == "__main__":
    solve()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import defaultdict


def solve():
    n = int(input())
    v = [int(i) for i in input().split()]
    d1 = defaultdict(int)
    d2 = defaultdict(int)
    for i in range(n):
        if i % 2 == 0:
            d1[v[i]] += 1
        else:
            d2[v[i]] += 1
    rd1 = defaultdict(list)
    rd2 = defaultdict(list)
    for k, v in d1.items():
        rd1[v].append(k)
    for k, v in d2.items():
        rd2[v].append(k)
    a1 = [i for i in sorted(rd1.keys(), reverse=True)]
    a2 = [i for i in sorted(rd2.keys(), reverse=True)]
    ans = n
    la1 = len(a1) - 1
    la2 = len(a2) - 1
    for h in range(3):
        for i in range(3):
            aa1 = rd1[a1[min(h, la1)]]
            aa2 = rd2[a2[min(i, la2)]]
            for j in aa1:
                for k in aa2:
                    if j != k:
                        ans = min(
                            ans, (n // 2) - a1[min(h, la1)] + (n // 2) - a2[min(i, la2)])
                    else:
                        ans = min(ans, (n // 2) - a1[min(h, la1)] + (n // 2) - a2[min(i, la2)]
                                  + min(a1[min(h, la1)], a2[min(i, la2)]))
    print(ans)


if __name__ == "__main__":
    solve()


Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import defaultdict


def solve():
    n = int(input())
    v = [int(i) for i in input().split()]
    d1 = defaultdict(int)
    d2 = defaultdict(int)
    for i in range(n):
        if i % 2 == 0:
            d1[v[i]] += 1
        else:
            d2[v[i]] += 1
    rd1 = defaultdict(list)
    rd2 = defaultdict(list)
    for k, v in d1.items():
        rd1[v].append(k)
    for k, v in d2.items():
        rd2[v].append(k)
    a1 = [i for i in sorted(rd1.keys(), reverse=True)]
    a2 = [i for i in sorted(rd2.keys(), reverse=True)]
    ans = n
    la1 = len(a1) - 1
    la2 = len(a2) - 1
    for h in range(3):
        for i in range(3):
            aa1 = rd1[a1[min(h, la1)]]
            aa2 = rd2[a2[min(i, la2)]]
            s1 = set(aa1)
            s2 = set(aa2)
            if len(s1) > 1 or len(s2) > 1 or (s1 - s2) or (s2 - s1):
                ans = min(
                    ans, (n // 2) - a1[min(h, la1)] + (n // 2) - a2[min(i, la2)])
            else:
                ans = min(ans, (n // 2) - a1[min(h, la1)] + (n // 2) - a2[min(i, la2)]
                          + min(a1[min(h, la1)], a2[min(i, la2)]))
    print(ans)


if __name__ == "__main__":
    solve()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import bisect


def solve():
    n, k = map(int, input().split())
    al = [int(i) for i in input().split()]

    ans = sum(abs(i) for i in al)
    flag0 = 0 in al
    if flag0:
        k -= 1
        n -= 1
        if k == 0:
            print(0)
            return
        al.remove(0)
    nc = bisect.bisect_left(al, 0)
    for i in range(n):
        if i < 0 or i + k - 1 >= n:
            break
        if al[i] < 0 and al[i + k - 1] < 0:
            t1 = min(abs(al[i], al[i + k - 1]))
        else:
            t1 = min(abs(al[i]) * 2 + abs(al[i + k - 1]),
                     abs(al[i]) + abs(al[i + k - 1]) * 2)
        if al[i] > 0 and al[i + k - 1] > 0:
            t2 = min(abs(al[i], al[i + k - 1]))
        else:
            t2 = min(abs(al[i]) * 2 + abs(al[i + k - 1]),
                     abs(al[i]) + abs(al[i + k - 1]) * 2)
        t = min(t1, t2)
        ans = min(ans, t)
    for i in range(n - 1, -1, -1):
        if i - k + 1 < 0 or i >= n:
            break
        if al[i] < 0 and al[i - k + 1] < 0:
            t1 = abs(al[i - k + 1], al[i])
        else:
            t1 = min(abs(al[i - k + 1]) * 2 + abs(al[i]),
                     abs(al[i - k + 1]) + abs(al[i]) * 2)
        if al[i] > 0 and al[i - k + 1] > 0:
            t2 = abs(al[i - k + 1], al[i])
        else:
            t2 = min(abs(al[i - k + 1]) * 2 + abs(al[i]),
                     abs(al[i - k + 1]) + abs(al[i]) * 2)
        t = min(t1, t2)
        ans = min(ans, t)
    print(ans)


if __name__ == "__main__":
    solve()


Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import bisect


def solve():
    n, k = map(int, input().split())
    al = [int(i) for i in input().split()]

    ans = sum(abs(i) for i in al)
    flag0 = 0 in al
    if flag0:
        k -= 1
        n -= 1
        if k == 0:
            print(0)
            return
        al.remove(0)
    nc = bisect.bisect_left(al, 0)
    for i in range(n):
        if i < 0 or i + k - 1 >= n:
            break
        if al[i] < 0 and al[i + k - 1] < 0:
            t1 = abs(al[i])
        else:
            t1 = min(abs(al[i]) * 2 + abs(al[i + k - 1]),
                     abs(al[i]) + abs(al[i + k - 1]) * 2)
        if al[i] > 0 and al[i + k - 1] > 0:
            t2 = abs(al[i + k - 1])
        else:
            t2 = min(abs(al[i]) * 2 + abs(al[i + k - 1]),
                     abs(al[i]) + abs(al[i + k - 1]) * 2)
        t = min(t1, t2)
        ans = min(ans, t)
    for i in range(n - 1, -1, -1):
        if i - k + 1 < 0 or i >= n:
            break
        if al[i] < 0 and al[i - k + 1] < 0:
            t1 = abs(al[i - k + 1])
        else:
            t1 = min(abs(al[i - k + 1]) * 2 + abs(al[i]),
                     abs(al[i - k + 1]) + abs(al[i]) * 2)
        if al[i] > 0 and al[i - k + 1] > 0:
            t1 = abs(al[i])
        else:
            t2 = min(abs(al[i - k + 1]) * 2 + abs(al[i]),
                     abs(al[i - k + 1]) + abs(al[i]) * 2)
        t = min(t1, t2)
        ans = min(ans, t)
    print(ans)


if __name__ == "__main__":
    solve()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def solve():
    s = input()
    n = int(input())
    idx = 0
    while s[idx] == "1":
        idx += 1
    if idx == len(s):
        print(1)
    else:
        print(s[idx])


if __name__ == "__main__":
    solve()


Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def solve():
    s = input()
    n = int(input())
    idx = 0
    slen = len(s)
    while idx < slen and s[idx] == "1":
        idx += 1
        if idx == n:
            print(1)
            return
    if idx == slen:
        print(1)
    else:
        print(s[idx])


if __name__ == "__main__":
    solve()