Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
class UnionFind():
  def __init__(self,n):
    self.n=n
    self.parents=[-1]*n
  def find(self,x):
    if self.parents[x]<0:
      return x
    else:
      self.parents[x]=self.find(self.parents[x])
      return self.parents[x]
  def unite(self,x,y):
    x=self.find(x)
    y=self.find(y)
    if x==y:
      return
    if self.parents[x]>self.parents[y]:
      x,y=y,x
    self.parents[x]+=self.parents[y]
    self.parents[y]=x
  def size(self,x):
    return -size.parents[self.find(x)]
  def same(self,x,y):
    return self.find(x)==self.find(y)
  def members(self,x):
    root=self.find(x)
    return [i for i in range(self.n) if self.find(i)==root]
  def roots(self):
    return [i for i,x in enumerate(self.parents) if x<0]
  def group_count(self):
    return len(self.roots())
  def all_group_members(self):
    return {r:self.members(r) for r in self.roots()}
n,k,l=map(int,input().split())
uf1=UnionFind(n)
for _ in range(k):
  u,v=map(int,input().split())
  uf1.unite(u-1,v-1)
uf2=UnionFind(n)
for _ in range(l):
  u,v=map(int,input().split())
  uf2.unite(u-1,v-1)
r=[[] for i in range(n)]
for i in range(n):
  if len(r[i])==0:
    x=uf1.members(i)
    for j in x:
      r[j]=set(x)
t=[[] for i in range(n)]
for i in range(n):
  if len(t[i])==0:
    x=uf2.members(i)
    for j in x:
      t[j]=set(x)
ans=[]
for i in range(n):
  ans.append(len(r[i]&t[i]))
print(*ans)

Fixed submission:
from collections import defaultdict
class UnionFind():
  def __init__(self,n):
    self.n=n
    self.parents=[-1]*n
  def find(self,x):
    if self.parents[x]<0:
      return x
    else:
      self.parents[x]=self.find(self.parents[x])
      return self.parents[x]
  def unite(self,x,y):
    x=self.find(x)
    y=self.find(y)
    if x==y:
      return
    if self.parents[x]>self.parents[y]:
      x,y=y,x
    self.parents[x]+=self.parents[y]
    self.parents[y]=x
  def size(self,x):
    return -size.parents[self.find(x)]
  def same(self,x,y):
    return self.find(x)==self.find(y)
  def members(self,x):
    root=self.find(x)
    return [i for i in range(self.n) if self.find(i)==root]
  def roots(self):
    return [i for i,x in enumerate(self.parents) if x<0]
  def group_count(self):
    return len(self.roots())
  def all_group_members(self):
    return {r:self.members(r) for r in self.roots()}
n,k,l=map(int,input().split())
uf1=UnionFind(n)
for _ in range(k):
  u,v=map(int,input().split())
  uf1.unite(u-1,v-1)
uf2=UnionFind(n)
for _ in range(l):
  u,v=map(int,input().split())
  uf2.unite(u-1,v-1)
d=defaultdict(int)
for i in range(n):
  d[(uf1.find(i),uf2.find(i))]+=1
ans=[d[(uf1.find(i),uf2.find(i))] for i in range(n)]
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,a=map(int,input().split())
x=list(map(int,input().split()))
ans=0
dp=[[[0]*(sum(x)+1) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0]=1
for i in range(n+1):
  for j in range(i+1):
    for k in range(sum(x)+1):
      if i>=1 and k>=x[i-1] and j>=1:
        dp[i][j][k]=dp[i-1][j-1][k-x[i-1]]+dp[i-1][j][k]
      elif i>=1:
        dp[i][j][k]=dp[i-1][j][k]
for j in range(1,n+1):
  for k in range(sum(x)+1):
    if k%j==0 and k//j==a:
      ans+=dp[n][j][k]
print(ans)

Fixed submission:
n,a=map(int,input().split())
x=list(map(int,input().split()))
ans=0
dp=[[[0]*(sum(x)+1) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0]=1
for i in range(n+1):
  for j in range(i+1):
    for k in range(sum(x)+1):
      if i>=1 and k>=x[i-1] and j>=1:
        dp[i][j][k]=dp[i-1][j-1][k-x[i-1]]+dp[i-1][j][k]
      elif i>=1:
        dp[i][j][k]=dp[i-1][j][k]
for j in range(1,n+1):
  for k in range(sum(x)+1):
    if k%j==0 and k//j==a:
      ans+=dp[n][j][k]
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=int(input())
if s==n:
  print(n+1)
  exit()
def f(x):
  m=n
  t=[]
  while m>0:
    y=m%x
    t.append(y)
    m-=m%x
    m//=x
  return sum(t)
for b in range(2,int(n**0.5)+1):
  if f(b)==s:
    print(b)
    exit()
for p in range(1,int(n**0.5)+1):
  if (n-s)%p==0:
    b=(n-s)//p+1
    if f(b)==s:
      print(b)
      exit()
print(-1)

Fixed submission:
n=int(input())
s=int(input())
if s==n:
  print(n+1)
  exit()
def f(x):
  m=n
  t=0
  while m:
    t+=m%x
    m//=x
  return t
for b in range(2,int(n**0.5)+2):
  if f(b)==s:
    print(b)
    exit()
for p in range(1,int(n**0.5))[::-1]:
  q=s-p
  b=(n-s)//p+1
  if 1<=p<b and 0<=q<b and (n-s)%p==0:
    b=(n-s)//p+1
    if f(b)==s:
      print(b)
      exit()
print(-1)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
d=list(map(int,input().split()))
N=list(str(n))
for i in range(len(N)):
  N[i]=int(N[i])
for i in range(n,n*10+1):
  if not N.isdisjoint(d):
    print(i)
    exit()

Fixed submission:
n,k=map(int,input().split())
d=list(map(int,input().split()))
for i in range(n,n*10+1):
  N=list(str(i))
  for j in range(len(N)):
    N[j]=int(N[j])
  N=set(N)
  d=set(d)
  if N.isdisjoint(d):
    print(i)
    exit()
Buggy python submission (verdict: Runtime Error):
L = int(input())
v = (L / 3) ^ 3
print(v)

Fixed submission:
L = int(input())
v = (L / 3) ** 3
print(v)

Buggy python submission (verdict: Runtime Error):
L = int(input())
l = [L / 3 for _ in range(L)]

for i in range(L % 3):
    l[i] += 1

v = l[0] * l[1] * l[2]
print(v)


Fixed submission:
L = int(input())
v = (L / 3) ** 3
print(v)
Buggy python submission (verdict: Runtime Error):
x = input().split()
y = input().split()


a = [int(i) for i in x]
b = [int(i) for i in y]

M = a[1]
s = sum(b)
c = 0

for i in b:
    if i >= int((1/(4*M)*S):
        c += 1
    if c > 1:
        print("Yes")

print("No")


Fixed submission:
x = input().split()
y = input().split()



a = [int(i) for i in x]
b = [int(i) for i in y]

M = a[1]
s = sum(b)
c = 0
f = False

for i in b:
    if i >= ((1/(4*M)*s)):
        c += 1
    if c == M:
        print("Yes")
        f = True
        break

if not f:
    print("No")
Buggy python submission (verdict: Runtime Error):
N=int(input())
a_n=[]
a2_n=[]
a_n = input().split(" ")
count = 0

for i in range(N):
    if int(a_n[i])%400 < 8:
         a2_n.append(int(a_n[i])%400)
    else:
        count += 1

n_min = len(set(a2_n))
if n_min+count >= 8:
    n_max=8
else:
    n_max = n_min+count

print(str(n_min)+" "+str(n_max))

Fixed submission:
r,g,b = input().split(" ")

if (int(r)*100+int(g)*10+int(b))%4==0 :
    print("YES")
else :
    print("NO")

Buggy python submission (verdict: Runtime Error):
 r,g,b = input().split(" ")

if (int(r)*100+int(g)*10+int(b))%4==0 :
    print("YES")
else :
    print("NO")

Fixed submission:
r,g,b = input().split(" ")

if (int(r)*100+int(g)*10+int(b))%4==0 :
    print("YES")
else :
    print("NO")
Buggy python submission (verdict: Runtime Error):
N=int(input())
a_n=[]
a2_n=[]
a_n = input().split(" ")
count = 0

for i in range(N):
    if int(a_n[i])/400 < 8:
         a2_n.append(int(a_n[i])/400)
    else:
        count += 1
if len(a2_n) == 0:
    num = 0
    n_min = 1
else:
    n_min = len(set(a2_n))
n_max = num+count

print(str(n_min)+" "+str(n_max))

Fixed submission:
N=int(input())
a_n=[]
a2_n=[]
a_n = input().split(" ")
count = 0

for i in range(N):
    if int(a_n[i])/400 < 8:
         a2_n.append(int(a_n[i])//400)
    else:
        count += 1

n_min = len(set(a2_n))
n_max = n_min+count

print(max(1, n_min),n_max)

Buggy python submission (verdict: Runtime Error):
N=int(input())
a_n=[]
a_n = input().split(" ")
a_n = x.split(" ")
count = 0

a_n.sort()
for i in range(N):
    if int(a_n[i])/400 < 8:
         a_n[i] = int(a_n[i])/400
    else:
        count += 1

num = len(set(a_n))

print(str(num)+" "+str(num+count))

Fixed submission:
N=int(input())
a_n=[]
a2_n=[]
a_n = input().split(" ")
count = 0

for i in range(N):
    if int(a_n[i])/400 < 8:
         a2_n.append(int(a_n[i])//400)
    else:
        count += 1

n_min = len(set(a2_n))
n_max = n_min+count

print(max(1, n_min),n_max)
Buggy python submission (verdict: Runtime Error):
n = int(input())
k = int(input())
summ = 0
for _ in range(n):
  x = int(input())
  summ += min(2*x, 2*(k-x))
 print(summ)

Fixed submission:
n = int(input())
k = int(input())
summ = 0
x = list(map(int, input().split()))
for i in x:
	summ += min(2*i, 2*(k-i))
print(summ)
Buggy python submission (verdict: Runtime Error):
def check(s):
  for i in range(1, len(s)):
    if i - 1 in s[i:]:
      return "no"
  return "yes"

s = input()
print(check(s))

Fixed submission:
def varied(s):
	for i in range(1, len(s)):
		if s[i-1] in s[i:]:
			return "no"
	return "yes"

s = input()
print(varied(s))
Buggy python submission (verdict: Runtime Error):
n, t = map(int, input().split())
arr = list(map(int, input().split()))
summ = t
for i in range(n-1):
  summ += min(t, arr[i+1] - arr[i])
return summ

Fixed submission:
n, t = map(int, input().split())
arr = list(map(int, input().split()))
summ = t
for i in range(n-1):
  summ += min(t, arr[i+1] - arr[i])
print(summ)
Buggy python submission (verdict: Runtime Error):
import sys

lines = sys.stdin.readlines()

a, b, k = map(int, lines[0].split())

if a => k:
    a = 0
    k = k - a
    if b => k:
        b = 0
        k = k - b
else:
    a = a - k

print(a, b)

Fixed submission:
import sys

lines = sys.stdin.readlines()

a, b, k = map(int, lines[0].split())

if a <= k:
    k = k - a
    a = 0
    if b <= k:
        k = k - b
        b = 0
    else:
        b = b - k
else:
    a = a - k

print(a, b)

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

lines = sys.stdin.readlines()

a, b, k = map(int, lines[0].split())

if a => k:
  a = 0
  k = k - a
  if b => k:
    b = 0
    k = k - b
else:
  a = a - k
  
print(a, b)

Fixed submission:
import sys

lines = sys.stdin.readlines()

a, b, k = map(int, lines[0].split())

if a <= k:
    k = k - a
    a = 0
    if b <= k:
        k = k - b
        b = 0
    else:
        b = b - k
else:
    a = a - k

print(a, b)
Buggy python submission (verdict: Runtime Error):
import sys
from math import gcd

lines = sys.stdin.readlines()

a, b = map(int, lines[0].split())

x = gcd(a, b)

print(x * (a//x) * (b//x))

Fixed submission:
import sys
from fractions import gcd

lines = sys.stdin.readlines()

a, b = map(int, lines[0].split())

x = gcd(a, b)

print(x * (a//x) * (b//x))

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

lines = sys.readlines()

a, b = map(int, lines[0].split())

x = gcd(a, b)

print(x * (a//x) * (b//x))

Fixed submission:
import sys
from fractions import gcd

lines = sys.stdin.readlines()

a, b = map(int, lines[0].split())

x = gcd(a, b)

print(x * (a//x) * (b//x))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

if K == 1:
  res = 0
elif K == 2:
  res = K % 2
else:
  diff = abs(N-K)
  while diff < N:
    N  = diff
    diff = abs(N-K)
 
  res = N
  
  
print(res)
  

Fixed submission:
N, K = map(int, input().split())
rem = N %K
print(min(rem, abs(rem - K)))
Buggy python submission (verdict: Runtime Error):
N, blue, red = map(int, input().split())


def count_blue(N, blue, red):
  
  if blue == 0:
    return 0
  elif N <= blue:
    return N
  elif N <= blue + red:
    return blue
  else:
    return (N // (blue + red) * blue) + count_blue(N // (blue + red), blue, red)
  
  
print(count_blue(N, blue, red))

Fixed submission:
N, blue, red = map(int, input().split())

ans = N // (blue + red) * blue
rem = N % (blue + red)
ans += min(rem, blue)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
per = np.array([0] + [int(i) for i in input().split()])
res = 0
for i in range(1, N+1):
  flag = True
  
  if per[i] > min(per[1:i+1]): 
    pass
  else: 
    res += 1
print(res)

Fixed submission:
N = int(input())
per = [0] + [int(i) for i in input().split()]
res = 0
min_per = per[1]
for i in range(1, N+1):
  min_per = min(min_per, per[i])
  flag = True
  if per[i] > min_per: 
    pass
  else: 
    res += 1
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
per = [0] + [int(i) for i in input().split()]
res = 0
for i in range(1, N+1):
  flag = True
  if per[i] > min(per[1:i+1]): 
    pass
  else: 
    res += 1
print(res)

Fixed submission:
N = int(input())
per = [0] + [int(i) for i in input().split()]
res = 0
min_per = per[1]
for i in range(1, N+1):
  min_per = min(min_per, per[i])
  flag = True
  if per[i] > min_per: 
    pass
  else: 
    res += 1
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
per = [0] + [int(i) for i in input().split()]
res = 0
for i in range(1, N+1):
  flag = True
  for j in range(1, i+1):
    if per[i] > per[j]: 
      flag = False
      break
  
  if flag: res += 1
print(res)

Fixed submission:
N = int(input())
per = [0] + [int(i) for i in input().split()]
res = 0
min_per = per[1]
for i in range(1, N+1):
  min_per = min(min_per, per[i])
  flag = True
  if per[i] > min_per: 
    pass
  else: 
    res += 1
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())
prime = [2]
for i in range(3, 100004):
  for p in prime:
    is_prime = True
    if i % p == 0:
      is_prime = False
      break
  if is_prime: prime.append(i)

print(min([i for i in prime if i >= X]))

Fixed submission:
X = int(input())
ans = 0
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

for i in range(X, 100004, 1):
  if is_prime(i):
    ans = i
    break

print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()

if S == "SAT":
    res = "1"
elif S == "SUN":
    res = "7"
elif S == "MON":
    res = "6"
elif S == "TUE":
    res = "5"
elif S == "WED":
    res = "4"
elif S == "THU":
    res = "3"
elif S == "Fri":
    res = "2"
print(res)

Fixed submission:
S = input()

if S == "SAT":
    res = "1"
elif S == "SUN":
    res = "7"
elif S == "MON":
    res = "6"
elif S == "TUE":
    res = "5"
elif S == "WED":
    res = "4"
elif S == "THU":
    res = "3"
elif S == "FRI":
    res = "2"
print(res)

Buggy python submission (verdict: Runtime Error):
S = input()

if S == "SAT":
    res = "1"
elif S == "SUN":
    res = "7"
elif S == "MON":
    res = "6"
elif S == "TUE":
    res = "5"
elif S == "WED":
    res = "4"
elif S == "THU":
    res = "3"
elif S == "Fri":
    res = "2"
print(res)

Fixed submission:
S = input()

if S == "SAT":
    res = "1"
elif S == "SUN":
    res = "7"
elif S == "MON":
    res = "6"
elif S == "TUE":
    res = "5"
elif S == "WED":
    res = "4"
elif S == "THU":
    res = "3"
elif S == "FRI":
    res = "2"
print(res)
Buggy python submission (verdict: Runtime Error):
import math

n= int(input())
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

res  = []
if is_prime(n):
    res = n - 1
else:
    for t in range(1, int(math.sqrt(n)) + 1):
        if n % t == 0:
                res.append(n//t + t - 2)


print(min(res))


Fixed submission:
import math

n= int(input())
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

i, j = 10**12, 10**12
res  = 0
if is_prime(n):
    res = n - 1
else:
    for t in range(1, int(math.sqrt(n)) + 1):
        if n % t == 0:
            a, b = t, n//t
            if a + b < i + j:
                i, j = a, b
    res = i + j -2


print(res)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
gates = []
res = 0
for _ in range(M):
  L, R = map(int, input().split())
  gates.append((L, R))

for i in range(1, N+1):
  flag = True
  for g in gates:
    if g[0] <= i <= g[1]:
      continue
    else:
      flag = False
      break 
  if flag: res+=1
  
print(res)

Fixed submission:
N, M = map(int, input().split())
res = 0
L_max = 0
R_min = 100000
for _ in range(M):
  L, R = map(int, input().split())
  if L_max < L: L_max = L
  if R < R_min: R_min = R
  
  
print(max(0, (R_min - L_max + 1)))
Buggy python submission (verdict: Runtime Error):
dishes = [int(input()) for i in range(5)] 

d = [abs(d % 10 -10) for d in dishes if d % 10 != 0] # select nums which can be divided by 10
d.remove(max(d)) 
print(sum(dishes) + sum(d))

Fixed submission:
dishes = [int(input()) for i in range(5)] 

d = [abs(d % 10 -10) for d in dishes if d % 10 != 0] # select nums which can be divided by 10
if d: d.remove(max(d)) 
print(sum(dishes) + sum(d))
Buggy python submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
res = set(list(range(A,B+1))) &\
     (set([i for i in range(A, A+K)]) | set([i for i in range(B-K+1, B+1)]))
print(*sorted(res), sep="\n")

Fixed submission:
A, B, K = map(int, input().split())
res = (set([i for i in range(A, A+K) if A<=i<=B]) |\
       set([i for i in range(B-K+1, B+1) if A<=i<=B]))
print(*sorted(res), sep="\n")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n = int(input())
q = deque(map(int, input().split()))
ans = []
for i in q:
  ans.append(i)
  ans = ans[::-1]

print(*ans)

Fixed submission:
from collections import deque
n = int(input())
l = map(int, input().split())
ans = deque()
for idx, v in enumerate(l):
  if idx % 2 == 0:
    ans.append(v)
  else:
    ans.appendleft(v)
if len(ans) % 2 == 1:
  ans.reverse()
            
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = map(int, input().split())
ans = []
for i in l:
  ans.append(i)
  ans = ans[::-1]

print(*ans)

Fixed submission:
from collections import deque
n = int(input())
l = map(int, input().split())
ans = deque()
for idx, v in enumerate(l):
  if idx % 2 == 0:
    ans.append(v)
  else:
    ans.appendleft(v)
if len(ans) % 2 == 1:
  ans.reverse()
            
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
P = list(map(int, input().split()))

ans = 1
for i in range(1, n):
    if min(P[:i+1]) == P[i]:
        ans += 1
print(ans)

Fixed submission:
n = int(input())
P = list(map(int, input().split()))
ans = 1
x = P[0]
for p in P:
    if x > p:
        ans += 1
        x = p
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

[print(A.index(i) + 1, end=' ') for i in range(1, N+1)]

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

B = [0] * N
for i in range(0, N):
    B[A[i]-1] = i+1
[print(x, end=' ') for x in B]

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

for i in range(1, N+1):
    print(A.index(i) + 1, end=' ')

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

B = [0] * N
for i in range(0, N):
    B[A[i]-1] = i+1
[print(x, end=' ') for x in B]
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
ans = 0
while(s.count('W') != 0):
    ans += s.index('W')
    s.remove('W')
print(ans)

Fixed submission:
s = input()
ans = 0
w = 0
for i in range(len(s)):
    if (s[i] == 'W'):
        ans += i - w
        w += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
ans = 0
while(s.count('W') != 0):
    ans += s.index('W')
    s.remove('W')
print(ans)

Fixed submission:
s = input()
ans = 0
w = 0
for i in range(len(s)):
    if (s[i] == 'W'):
        ans += i - w
        w += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
ans = 0
while(s.count('W') != 0):
    ans += s.index('W')
    s.remove('W')
print(ans)

Fixed submission:
s = input()
ans = 0
w = 0
for i in range(len(s)):
    if (s[i] == 'W'):
        ans += i - w
        w += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
a, b = map(int, input().split())
x = ((1-b)//(a-1))
# 出力
print("{}".format(-x)

Fixed submission:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
a, b = map(int, input().split())
x = ((1-b)//(a-1))
# 出力
print("{}".format(-x))

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
a, b = map(int, input().split())
# 出力
print("{}".format( -( (1-b)//(a-1) ) )

Fixed submission:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
a, b = map(int, input().split())
x = ((1-b)//(a-1))
# 出力
print("{}".format(-x))
Buggy python submission (verdict: Runtime Error):
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  string S;
  ll K;
  cin >> S >> K;
  smatch m;
  regex_match(S, m, regex("^(1*)([1-9]*)$"));
  cout << ((m.length(1) >= K) ? '1' : m.str(2).front()) << endl;
  return 0;
}


Fixed submission:
import re

S = input()
K = int(input())

m = re.match(r'\A(1+)([1-9]*)\Z', S)
if m:
    print('1' if len(m.group(1)) >= K else m.group(2)[0])
else:
    print(S[0])
Buggy python submission (verdict: Runtime Error):
def solve(N, Y):
    for x in range(N + 1):
        for y in range(0, N - x + 1):
            z = N - x - y
            elif 10000 * x + 5000 * y + 1000 * z == Y:
                return x, y, z
    return -1, -1, -1


N, Y = list(map(int, input().split()))
x, y, z = solve(N, Y)
print('{} {} {}'.format(x, y, z))


Fixed submission:
N = int(input())

s = set()
for i in range(N):
    d = int(input())
    s.add(d)
print(len(s))
Buggy python submission (verdict: Runtime Error):
def solve(N, Y):
    for x in range(N + 1):
        for y in range(0, N - x + 1):
            z = N - x - y
            elif 10000 * x + 5000 * y + 1000 * z == Y:
                return x, y, z
    return -1, -1, -1
 
 
N, Y = list(map(int, input().split()))
x, y, z = solve(N, Y)
print('{} {} {}'.format(x, y, z))

Fixed submission:
def solve(N, Y):
    for x in range(N+1):
        for y in range(N+1):
            z = N - x - y
            if z < 0:
                continue
            elif 10000 * x + 5000 * y + 1000 * z == Y:
                return x, y, z
    return -1, -1, -1

N, Y = list(map(int, input().split()))
x, y, z = solve(N, Y)
print('{} {} {}'.format(x, y, z))

Buggy python submission (verdict: Time Limit Exceeded):
def solve(N, Y):
    for x in range(N, -1, -1):
        for y in range(N - x, -1, -1):
            for z in range(N - x - y, -1, -1):
                if x + y + z == N and 10000 * x + 5000 * y + 1000 * z == Y:
                    return x, y, z
    return -1, -1, -1

N, Y = list(map(int, input().split()))
x, y, z = solve(N, Y)
print('{} {} {}'.format(x, y, z))

Fixed submission:
def solve(N, Y):
    for x in range(N+1):
        for y in range(N+1):
            z = N - x - y
            if z < 0:
                continue
            elif 10000 * x + 5000 * y + 1000 * z == Y:
                return x, y, z
    return -1, -1, -1

N, Y = list(map(int, input().split()))
x, y, z = solve(N, Y)
print('{} {} {}'.format(x, y, z))