Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.readline

N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0

for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if L[i] + L[j] > L[k]:
                ans += 1
            else:
                break

print(ans)


Fixed submission:
import sys
from bisect import bisect_left
input = sys.stdin.readline

N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0

for i in range(N-2):
    for j in range(i+1, N-1):
        search = L[i] + L[j]
        k = bisect_left(L, search)
        ans += k - j - 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.readline

N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0

for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if L[i] + L[j] > L[k]:
                ans += 1
            else:
                break

print(ans)

Fixed submission:
import sys
from bisect import bisect_left
input = sys.stdin.readline

N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0

for i in range(N-2):
    for j in range(i+1, N-1):
        search = L[i] + L[j]
        k = bisect_left(L, search)
        ans += k - j - 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
input = sys.stdin.readline

N, K = map(int, input().split())
V = deque(list(map(int, input().split())))
score = deque()

for i in range(K+1): #左から
    for j in range(K-i+1): #右から
        hand = deque()
        for n in range(i): #左から
            hand.append(V[n]) 
        for m in range(j): #右から
            hand.append(V[N-m-1])
        for k in range(K-i-j):
            if len(hand) > 0 and min(hand) < 0:
                hand.remove(min(hand)) 
        score.append(sum(hand))

print(max(score))

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

N, K = map(int, input().split())
V = deque(list(map(int, input().split())))
score = deque()

for i in range(K+1): #左から
    for j in range(K-i+1): #右から
        hand = deque()
        if i + j <= N:
            for n in range(i): #左から
                hand.append(V[n]) 
            for m in range(j): #右から
                hand.append(V[N-m-1])
            for k in range(K-i-j):
                if len(hand) > 0 and min(hand) < 0:
                    hand.remove(min(hand)) 
            score.append(sum(hand))

print(max(score))
Buggy python submission (verdict: Runtime Error):
N = input()
V = list(map(int, input().split()))
C = list(map(int, input().split()))
XY = 0
for i in range(len(V)):
    if V[i] - C[i] > 0:
        XY += V[i] - C[i]

print(XY)


Fixed submission:
A, B, T = input().split()
A, B, T = int(A), int(B), int(T)

print(B * (T // A))
Buggy python submission (verdict: Runtime Error):
N = input()
V = list(map(int, input().split()))
C = list(map(int, input().split()))
XY = 0
for i in range(len(V)):
    if V[i] - C[i] > 0:
        XY += V[i] - C[i]

print(XY)


Fixed submission:
N = input()
V = list(map(int, input().split()))
C = list(map(int, input().split()))
XY = 0
for i in range(len(V)):
    if V[i] - C[i] > 0:
        XY += V[i] - C[i]

print(XY)
Buggy python submission (verdict: Runtime Error):
from collections import deque
N, Q = map(int, input().split())
S = input()
l = [0 for i in range(Q)]
r = [0 for i in range(Q)]

for i in range(Q):
    l[i], r[i] = map(int, input().split())

for i in range(Q):
    s = S[l[i]-1:r[i]]
    print(s.count('AC'))

Fixed submission:
b = input()
if b == 'A':
    print('T')
if b == 'T':
    print('A')
if b == 'G':
    print('C')
if b == 'C':
    print('G')
Buggy python submission (verdict: Runtime Error):
S = input()
list = []
counter = 0
for i in range(len(S)):
    if S[i] == 'A' or S[i] == 'T' or S[i] == 'G' or S[i] == 'C':
        counter += 1
    else:
        list.append(counter)
        counter = 0
print(max(list))




Fixed submission:
S = input()
list = []
counter = 0
for i in range(len(S)):
    if S[i] == 'A' or S[i] == 'T' or S[i] == 'G' or S[i] == 'C':
        counter += 1
    else:
        counter = 0
    list.append(counter)
print(max(list))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, Q = map(int, input().split())
S = input()
l = [0 for i in range(Q)]
r = [0 for i in range(Q)]

for i in range(Q):
    l[i], r[i] = map(int, input().split())

for i in range(Q):
    print(S[l[i]-1:r[i]].count('AC'))


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

#a[i]:s[0]~s[i]までに何個ACがあったか
a = [0]*n
#end[i]:s[i]がACの'C'か
end = [False]*n
for i in range(1,n):
    if s[i] == 'C' and s[i-1] == 'A':
        a[i] = a[i-1]+1
        end[i] = True
    else:
        a[i] = a[i-1]

for i in range(q):
    L,R = map(int,input().split())
    L,R = L-1,R-1
    if L == 0:
        print(a[R])
    else:
        if end[L]:
            print(a[R]-a[L-1]-1)
        else:
            print(a[R]-a[L-1])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, Q = map(int, input().split())
S = input()
l = [0 for i in range(Q)]
r = [0 for i in range(Q)]

for i in range(Q):
    l[i], r[i] = map(int, input().split())

for i in range(Q):
    s = S[l[i]-1:r[i]]
    print(s.count('AC'))

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

#a[i]:s[0]~s[i]までに何個ACがあったか
a = [0]*n
#end[i]:s[i]がACの'C'か
end = [False]*n
for i in range(1,n):
    if s[i] == 'C' and s[i-1] == 'A':
        a[i] = a[i-1]+1
        end[i] = True
    else:
        a[i] = a[i-1]

for i in range(q):
    L,R = map(int,input().split())
    L,R = L-1,R-1
    if L == 0:
        print(a[R])
    else:
        if end[L]:
            print(a[R]-a[L-1]-1)
        else:
            print(a[R]-a[L-1])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, Q = map(int, input().split())
S = input()
l = [0 for i in range(Q)]
r = [0 for i in range(Q)]
ans = r = [0 for i in range(Q)]
for i in range(Q):
    l[i], r[i] = map(int, input().split())

for i in range(Q):
    s = S[l[i]-1:r[i]]
    print(s.count('AC'))


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

#a[i]:s[0]~s[i]までに何個ACがあったか
a = [0]*n
#end[i]:s[i]がACの'C'か
end = [False]*n
for i in range(1,n):
    if s[i] == 'C' and s[i-1] == 'A':
        a[i] = a[i-1]+1
        end[i] = True
    else:
        a[i] = a[i-1]

for i in range(q):
    L,R = map(int,input().split())
    L,R = L-1,R-1
    if L == 0:
        print(a[R])
    else:
        if end[L]:
            print(a[R]-a[L-1]-1)
        else:
            print(a[R]-a[L-1])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, M = map(int, input().split())

A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = map(int, input().split())

C = deque()

while len(C) < M:
    for j in range(B[A.index(min(A))]):
        if len(C) < M:
            C.append(min(A))
        else:
            break
    B.pop(A.index(min(A)))
    A.remove(min(A))

C = sorted(C)
print(sum(C[:M]))

Fixed submission:
import sys
from collections import deque
from operator import itemgetter
input = sys.stdin.readline
N, M = map(int, input().split())

A = deque()
for i in range(N):
    A.append(list(map(int, input().split())))

A = sorted(A, key=itemgetter(0))

m=0
cost=0

for i in range(N):
    if m >= M:
        break
    buy = min(M - m, A[i][1])
    cost += A[i][0] * buy
    m += buy

print(cost)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, M = map(int, input().split())

A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = map(int, input().split())

C = deque()

while len(C) < M:
    for j in range(B[A.index(min(A))]):
        C.append(min(A))
    B.pop(A.index(min(A)))
    A.remove(min(A))

C = sorted(C)
print(sum(C[:M]))

Fixed submission:
import sys
from collections import deque
from operator import itemgetter
input = sys.stdin.readline
N, M = map(int, input().split())

A = deque()
for i in range(N):
    A.append(list(map(int, input().split())))

A = sorted(A, key=itemgetter(0))

m=0
cost=0

for i in range(N):
    if m >= M:
        break
    buy = min(M - m, A[i][1])
    cost += A[i][0] * buy
    m += buy

print(cost)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, M = map(int, input().split())

A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = map(int, input().split())

C = deque()

for i in range(N):
    for j in range(B[i]):
        C.append(A[i])

C = sorted(C)
print(sum(C[:M]))

Fixed submission:
import sys
from collections import deque
from operator import itemgetter
input = sys.stdin.readline
N, M = map(int, input().split())

A = deque()
for i in range(N):
    A.append(list(map(int, input().split())))

A = sorted(A, key=itemgetter(0))

m=0
cost=0

for i in range(N):
    if m >= M:
        break
    buy = min(M - m, A[i][1])
    cost += A[i][0] * buy
    m += buy

print(cost)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, M = map(int, input().split())

A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = map(int, input().split())

C = deque()

for i in range(N):
    for j in range(B[i]):
        C.append(A[i])

C = sorted(C)
print(sum(C[:M]))

Fixed submission:
import sys
from collections import deque
from operator import itemgetter
input = sys.stdin.readline
N, M = map(int, input().split())

A = deque()
for i in range(N):
    A.append(list(map(int, input().split())))

A = sorted(A, key=itemgetter(0))

m=0
cost=0

for i in range(N):
    if m >= M:
        break
    buy = min(M - m, A[i][1])
    cost += A[i][0] * buy
    m += buy

print(cost)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools
from collections import deque
from operator import itemgetter

input = sys.stdin.readline
S = input()
counter = 0

for i in range(len(S)):
    null = 0
    if '01' in S:
        S = S.replace('01', '', 1)
        counter += 1
    else:
        null +=1
    if '10' in S:
        S = S.replace('10','', 1)
        counter += 1
    else:
        null += 1
    if null == 2:
        break
print(2*counter)

Fixed submission:
import sys
import itertools
from collections import deque
from operator import itemgetter

input = sys.stdin.readline
S = input()
counter = 0

A = S.count('1')
B = S.count('0')
print(2*min(A,B))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools
from collections import deque
from operator import itemgetter

input = sys.stdin.readline
S = input()
counter = 0

for i in range(len(S)//2):
    if '01' in S:
        S = S.replace('01', '', 1)
        counter += 1
    if '10' in S:
        S = S.replace('10','', 1)
        counter += 1
print(2*counter)

Fixed submission:
import sys
import itertools
from collections import deque
from operator import itemgetter

input = sys.stdin.readline
S = input()
counter = 0

A = S.count('1')
B = S.count('0')
print(2*min(A,B))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools
from collections import deque
from operator import itemgetter

input = sys.stdin.readline
S = input()
counter = 0

for i in range(len(S)):
    if '01' in S:
        S = S.replace('01', '', 1)
        counter += 1
    if '10' in S:
        S = S.replace('10','', 1)
        counter += 1
print(2*counter)

Fixed submission:
import sys
import itertools
from collections import deque
from operator import itemgetter

input = sys.stdin.readline
S = input()
counter = 0

A = S.count('1')
B = S.count('0')
print(2*min(A,B))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools
from collections import deque
from operator import itemgetter

input = sys.stdin.readline
S = input()
counter = 0

for i in range(len(S)):
    if '01' in S:
        S = S.replace('01', '', 1)
        counter += 1
    if '10' in S:
        S = S.replace('10','', 1)
        counter += 1
print(2*counter)

Fixed submission:
import sys
import itertools
from collections import deque
from operator import itemgetter

input = sys.stdin.readline
S = input()
counter = 0

A = S.count('1')
B = S.count('0')
print(2*min(A,B))
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
input = sys.stdin.readline

N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10**9

def dfs(cur, a, b, c):
    if cur == N:
        if min(a, b, c) > 0:
            return abs(a-A) + abs(b-B) + abs(c-C) - 30　#最初の三回
        else:
            return INF #長さ0になった場合
    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10**9

def dfs(cur, a, b, c):
    if cur == N:
        if min(a, b, c) > 0:
            return abs(a-A) + abs(b-B) + abs(c-C) - 30
        else:
            return INF #長さ0になった場合
    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))
Buggy python submission (verdict: Runtime Error):
import sys
import math
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

A.sort()

ans = A[0]
for i in range(1, N):
    ans = math.gcd(ans, A[i])
print(ans)



Fixed submission:
import sys

input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z

A.sort()
ans = A[0]
for i in range(1, N):
    ans = gcd(ans, A[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
import math
from functools import reduce
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

print(gcd_list(A))

Fixed submission:
import sys

input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z

A.sort()
ans = A[0]
for i in range(1, N):
    ans = gcd(ans, A[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

diff = deque()

N, M = map(int, input().split())
X = list(map(int, input().split()))
diff = []

if N >= M:
    print(0)
    exit()

X.sort()

for i in range(len(X)-1):
    diff.append(X[i+1]-X[i])

diff.sort()

for i in range(N-1):
    diff.pop()

print(sum(diff))


Fixed submission:
import sys
from collections import deque


diff = deque()

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

if N >= M:
    print(0)
    exit()

X.sort()

for i in range(len(X)-1):
    diff.append(X[i+1]-X[i])

diff = list(diff)
diff.sort()

for i in range(N-1):
    diff.pop()

print(sum(diff))

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

diff = deque()

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

if N >= M:
    print(0)
    exit()

X.sort()

for i in range(len(X)-1):
    diff.append(X[i+1]-X[i])

diff.sort()

for i in range(N-1):
    diff.pop()

print(sum(diff))


Fixed submission:
import sys
from collections import deque


diff = deque()

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

if N >= M:
    print(0)
    exit()

X.sort()

for i in range(len(X)-1):
    diff.append(X[i+1]-X[i])

diff = list(diff)
diff.sort()

for i in range(N-1):
    diff.pop()

print(sum(diff))
Buggy python submission (verdict: Runtime Error):
import sys
intput = sys.stdin.readline()

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')

Fixed submission:
import sys
input = sys.stdin.readline

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):
import sys
input = sys.stdin.readline

N, X = map(int, input().split())
l, p = [1], [1]

def f(N, X):
    for i in range(N):
        if N == 0:
            return 0 if X == 0 else 1
        elif X <= 1 + l[N-1]:
            return f(N-1, X-1)
        else:
            return p[N-1] + 1 + f(N-1, X-2-a[N-1])
    
print(f(N, X))


Fixed submission:
import sys
input = sys.stdin.readline

N, X = map(int, input().split())
l, p = [1], [1]

for i in range(N):
    l.append(l[i]*2 + 3)
    p.append(p[i]*2 + 1)

def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + l[N-1]:
        return f(N-1, X-1)
    else:
        return p[N-1] + 1 + f(N-1, X-2-l[N-1])
    
print(f(N, X))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N, X = map(int, input().split())
l, p = [1], [1]

def f(N, X)
    for i in range(N):
        if N == 0:
            return 0 if X == 0 else 1
        elif X <= 1 + l[N-1]:
            return f(N-1, X-1)
        else:
            return p[N-1] + 1 + f(N-1, X-2-a[N-1])
    
print(f(N, X))


Fixed submission:
import sys
input = sys.stdin.readline

N, X = map(int, input().split())
l, p = [1], [1]

for i in range(N):
    l.append(l[i]*2 + 3)
    p.append(p[i]*2 + 1)

def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + l[N-1]:
        return f(N-1, X-1)
    else:
        return p[N-1] + 1 + f(N-1, X-2-l[N-1])
    
print(f(N, X))
Buggy python submission (verdict: Runtime Error):
import sys
from fractions import gcd

input = sys.stdin.readline

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

if N == 1:
    print(abs(X - x[0]))
    exit()

x.append(X)
x.sort()
diff = []
ans = []

for i in range(N-1):
    diff.append(x[i+1] - x[i])

for i in range(N-2):
    ans.append(gcd(diff[i], diff[i+1]))

print(min(ans))

Fixed submission:
import sys
from fractions import gcd

input = sys.stdin.readline

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

if N == 1:
    print(abs(X - x[0]))
    exit()

x.append(X)
x.sort()
diff = []
ans = []

for i in range(N):
    diff.append(x[i+1] - x[i])

for i in range(N-1):
    ans.append(gcd(diff[i], diff[i+1]))

print(min(ans))

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

input = sys.stdin.readline

N, X = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
diff = []
ans = []

for i in range(N-1):
    diff.append(x[i+1] - x[i])

for i in range(N-2):
    ans.append(gcd(diff[i], diff[i+1]))

print(min(ans))

Fixed submission:
import sys
from fractions import gcd

input = sys.stdin.readline

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

if N == 1:
    print(abs(X - x[0]))
    exit()

x.append(X)
x.sort()
diff = []
ans = []

for i in range(N):
    diff.append(x[i+1] - x[i])

for i in range(N-1):
    ans.append(gcd(diff[i], diff[i+1]))

print(min(ans))
Buggy python submission (verdict: Runtime Error):
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n, k = nm()
x = nl()

if 0 in x:
    k -= 1
if n == 1:
    print(x[0])
    exit()

zero = bisect_left(x, 0)
costs = []

for i in range(min(zero - k, 0) + 1, min(zero + k, n - k)):
    if x[i] < 0 and x[i+k-1] > 0:
        costs.append(-2 * x[i] + x[i+k-1])
        costs.append(-1 * x[i] + 2 * x[i+k-1])
    else:
        costs.append(max(abs(x[i]), abs(x[i+k-1])))
    #print(i, x[i], costs)
print(min(costs))

Fixed submission:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n, k = nm()
x = nl()

if 0 in x:
    k -= 1
if n == 1:
    print(x[0])
    exit()

zero = bisect_left(x, 0)
costs = []
#print(zero, max(zero - k, 0), min(zero + k, n - k) + 1)
for i in range(max(zero - k, 0), min(zero + k, n - k) + 1):
    if x[i] < 0 and x[i+k-1] > 0:
        costs.append(-2 * x[i] + x[i+k-1])
        costs.append(-1 * x[i] + 2 * x[i+k-1])
    else:
        costs.append(max(abs(x[i]), abs(x[i+k-1])))
    #print(i, x[i], costs)
print(min(costs))
Buggy python submission (verdict: Runtime Error):
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

s = ns()
k = ni()
i = 0
while True:
    if s[i] == '1':
        i += 1
    else:
        break

if k <= i:
    ans = 1
else:
    ans = int(s[i])

print(ans)

Fixed submission:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

s = ns()
k = ni()
i = 0
while i < len(s):
    if s[i] == '1':
        i += 1
    else:
        ans = int(s[i])
        break

if k <= i:
    ans = 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()

res = n
for i in range(n+1):
    cash = 0
    t = i
    while t > 0: # 0 ~ iを6で表す
        cash += t % 6
        t //= 6
    t = n - i
    while t > 0: # n-i ~ nを9で表す
        cc += t % 9
        t //= 9
    if res > cash: # cash最小値
        res = cash

print(res)

Fixed submission:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()

res = n
for i in range(n+1):
    cc = 0
    t = i
    while t > 0:
        cc += t % 6
        t //= 6
    t = n - i
    while t > 0:
        cc += t % 9
        t //= 9
    if res > cc:
        res = cc

print(res)