Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import sys

def disscount(disscounts,x,y):
  minDisscounts = 0
  for i in disscounts:
    if int(i[0]) == x and int(i[1]) == y:
      if minDisscounts < int(i[2]):
        minDisscounts = int(i[2])
  return minDisscounts

counts = input().split()
colors = input().split()
hots = input().split()
disscounts = []
for i in range(int(counts[2])):
  disscounts.append(input().split())

minPrice = sys.maxsize
for i in range(0, len(colors)):
  for j in range(0, len(hots)):
    colorPrice = int(colors[i])
    hotPrice = int(hots[j])
    price = colorPrice + hotPrice - disscount(disscounts, i + 1 , j + 1)
    if price < minPrice:
      minPrice = price
print(str(minPrice))

### FIXED CODE ###

import sys

counts = list(map(int,input().split()))
colors = list(map(int,input().split()))
hots = list(map(int,input().split()))

ticketCount = counts[2]

minPrice = sys.maxsize
# first. get disscount consider price
for i in range(ticketCount):
  values = input().split()
  x = int(values[0])
  y = int(values[1])
  dissPrice = int(values[2])
  colorPrice = colors[x-1]
  hotsPrice = hots[y-1]
  validPrice =  colorPrice + hotsPrice - dissPrice
  if minPrice > validPrice:
    minPrice = validPrice

max_color = min(colors)
max_color_idx = colors.index(max_color)
max_hots = min(hots)
max_hots_idx = hots.index(max_hots)
validPrice = max_color + max_hots
if minPrice > validPrice:
  minPrice = validPrice
print(str(minPrice))
### BUGGY CODE ###

import re
a = input()
operations = 0
while re.search("01", a) or re.search("10", a):
    if re.search("01", a):
        a = a.replace("01", "", 1)
        operations += 2
    if re.search("10", a):
        a = a.replace("10", "", 1)
        operations += 2
print(operations)

### FIXED CODE ###

s = input()
print(2*(min(s.count("0"), s.count("1"))))
### BUGGY CODE ###

from functools import reduce
from operator import add

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

for i in range(m):
    idx = alist.index(max(alist))
    alist[idx] //= 2

print(reduce(add, alist))


### FIXED CODE ###

import heapq
from functools import reduce

n, m = map(int, input().split())
h = list(map(lambda a: -int(a), input().split()))
heapq.heapify(h)  # input().split()))

for i in range(m):
    mx = -(-heapq.heappop(h) // 2)
    heapq.heappush(h, mx)

print(-reduce(lambda a, b: a+b, h))
### BUGGY CODE ###

ss = input()
a,b,x = ss.split()
ls = [i for i in range(int(a),int(b)+1) if int(i)%int(x)==0]

print(len(ls))

### FIXED CODE ###

ss = input()
a,b,x = ss.split()
ans = (int(b)//int(x)-(int(a)-1)//int(x))

print(ans)
### BUGGY CODE ###

nk = input().split()
n = int(nk[0])
k = int(nk[1])
a = list(map(int, input().split()))

p = [0] * n
for i in range(k - 1, n):
    if i == k - 1:
        p_i = 1
        for j in range(k):
            p_i *= a[i - j]
        p[i] = p_i
    else:
        p[i] = int(p[i - 1] / a[i - k] * a[i])

for i in range(k - 1, n):
    if i == k - 1:
        continue
    if p[i] > p[i - 1]:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

nk = input().split()
n = int(nk[0])
k = int(nk[1])
a = list(map(int, input().split()))

for i in range(k, n):
    if a[i] > a[i - k]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

N,K=map(int,input().split())
h=sorted(list(int(input()) for i in range(N)))
H=list()
for i in range(0,N-K+1):
    H.append(max(h[i:i+K])-min(h[i:i+K]))
print(min(H))

### FIXED CODE ###

N,K=map(int,input().split())
h=sorted([int(input()) for i in range(N)])
print(min(h[i+K-1]-h[i] for i in range(N-K+1)))
### BUGGY CODE ###

N,K = map(int, input().split())
h = list(int(i) for i in input().split())
dp = [float("inf")]*N
dp[0] = 0
for i in range(1,N):
    for j in range(max(0,i-K),i):
        dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]))
print(dp[-1])

### FIXED CODE ###

N, K = map(int, input().split())
h = [int(i) for i in input().split()]
INF = 10**9

c = [INF] * N
c[0] = 0

for i in range(N):
  tmp = []
  for j in range(1, min(K, i)+1):
    c[i] = min(c[i-j] + abs(h[i] - h[i-j]), c[i])
print(c[-1])
### BUGGY CODE ###

from sys import stdin
import sys

l = stdin.readline().rstrip().split(' ')
a = stdin.readline().rstrip().split(' ')
b = stdin.readline().rstrip().split(' ')
k = int(l[2])
n = int(l[0])
m = int(l[1])
ia = 0
ib = 0
b_sum = 0
count = 0
a_sum = 0
res = []

for bt in b:
    b_sum += int(bt)
    if b_sum <= k:
        count += 1
    else:
        break
res.append(count)
count = 0
for at in a:
    a_sum = a_sum + int(at)
    if k < a_sum:
        #res.append(count)
        print(max(res))
        sys.exit()
    else:
        count = ia + 1
    b_sum = a_sum
    for bt in b:
        b_sum += int(bt)
        if b_sum <= k:
            count += 1
        else:
            break
    ia += 1
    res.append(count)
print(max(res))

### FIXED CODE ###

from sys import stdin
import sys

l = stdin.readline().rstrip().split(' ')
A = list(map(int, input().split()))
B = list(map(int, input().split()))
k = int(l[2])
n = int(l[0])
m = int(l[1])

sum = 0
a = [0]
for i in range(n):
    sum += A[i]
    a.append(sum)
sum = 0

b = [0]
for i in range(m):
    sum += B[i]
    b.append(sum)
#print(b)

ans = 0
j = m
for i in range(n+1):
    if a[i] > k:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)
### BUGGY CODE ###

N = int(input())
A = [int(a) for a in input().split()]
I = 0
J = 0
K = 0
for a in A:
    if a == 1:
        J += 1
        K += 1
    elif a == 2:
        K += 1

X = [[[0.0] * (j+1) for j in range(k+1)] for k in range(N+1)]

for k in range(N+1)[::-1]:
    for j in range(k+1)[::-1]:
        for i in range(j+1)[::-1]:
            if i == N:
                X[k][j][i] = 0
            else:
                X[k][j][i] = N/(N-i)
                if i < j:
                    X[k][j][i] += X[k][j][i+1] * (j-i) / (N-i)
                if j < k:
                    X[k][j][i] += X[k][j+1][i] * (k-j) / (N-i)
                if k < N:
                    X[k][j][i] += X[k+1][j][i] * (N-k) / (N-i)

print(X[K][J][I])

### FIXED CODE ###

N = int(input())
A = [int(a) for a in input().split()]
I = 0
J = 0
K = 0
for a in A:
    if a == 1:
        J += 1
        K += 1
    elif a == 2:
        K += 1

X = [[[0.0] * (j+1) for j in range(k+1)] for k in range(N+1)]

for k in range(N+1)[::-1]:
    for j in range(k+1)[::-1]:
        for i in range(j+1)[::-1]:
            if i == N:
                X[k][j][i] = 0
            else:
                X[k][j][i] = N/(N-i)
                if i < j:
                    X[k][j][i] += X[k][j][i+1] * (j-i) / (N-i)
                if j < k:
                    X[k][j][i] += X[k][j+1][i] * (k-j) / (N-i)
                if k < N:
                    X[k][j][i] += X[k+1][j][i] * (N-k) / (N-i)

print(X[K][J][I])
### BUGGY CODE ###

S = input()

dp = [[0 for j in range(13)] for i in range(len(S)+1)]
dp[0][0] = 1
M = 10**9+7

for i in range(len(S)):
    if S[-i-1] == "?":
        for k in range(10):
            r = k*10**i
            for j in range(13):
                dp[i+1][(r+j)%13] += dp[i][j]
    else:
        r = int(S[-i-1])*10**i
        for j in range(13):
            dp[i+1][(r+j)%13] += dp[i][j]

ans = dp[-1][5] % M
print(ans)

### FIXED CODE ###

s=input()
l=len(s)
mod=10**9+7
dp=[[0 for j in range(13)] for i in range(l+1)]
dp[0][0]=1
for i in range(1,l+1):
  if s[i-1]=='?':
    for j in range(10):
      for k in range(13):
        dp[i][(k*10+j)%13]+=dp[i-1][k]%mod
  else:
    for k in range(13):
      dp[i][(k*10+int(s[i-1]))%13]+=dp[i-1][k]%mod
print(dp[-1][5]%mod)
### BUGGY CODE ###

import sys

def isEmpty(S):
  if len(S) == 0:
    return True

def isFull(S):
  if len(S) >= 100000:
    return True

def enqueue(x):
  if isFull(x_list_list):
    print 'Error'
  x_list_list.append(x)

def dequeue(x_list_list):
  if isEmpty(x_list_list):
    print 'Error'
  del_list = x_list_list[0]
  x_list_list.pop(0)
  return(del_list)

y = sys.stdin.readline()
a, b = y.split(" ")
a = int(a)
b = int(b)

S = []
x_list_list = []

for i in range(a):
  text = raw_input()
  x_list = text.split()
  x_list[1] = int(x_list[1])
  x_list.append(0)
  x_list_list.append(x_list)

flag = a
while flag != 0:
  if int(x_list_list[0][1]) > b:
    x_list_list[0][1] -= int(b)
    for j in range(flag):
      x_list_list[j][2] += b
    del_list = dequeue(x_list_list)
    enqueue(del_list)
  else:
    for j in range(flag):
      x_list_list[j][2] += x_list_list[0][1]
    x_list_list[0][1] = 0
    flag -= 1
    print x_list_list[0][0],x_list_list[0][2]
    dequeue(x_list_list)
    

### FIXED CODE ###

import sys

def isEmpty(S):
  if len(S) == 0:
    return True

def isFull(S):
  if len(S) >= 100000:
    return True

def enqueue(x):
  if isFull(x_list_list):
    print 'Error'
  x_list_list.append(x)

def dequeue(x_list_list):
  if isEmpty(x_list_list):
    print 'Error'
  del_list = x_list_list[0]
  x_list_list.pop(0)
  return(del_list)

y = sys.stdin.readline()
a, b = y.split(" ")
a = int(a)
b = int(b)

S = []
x_list_list = []
run_time = 0

for i in range(a):
  text = raw_input()
  x_list = text.split()
  x_list[1] = int(x_list[1])
  x_list.append(0)
  x_list_list.append(x_list)

flag = a
while flag != 0:
  if x_list_list[0][1] > b:
    x_list_list[0][1] -= int(b)
    run_time += b
    del_list = dequeue(x_list_list)
    enqueue(del_list)
  else:
    run_time += x_list_list[0][1]
    x_list_list[0][2] = run_time
    x_list_list[0][1] = 0
    flag -= 1
    print x_list_list[0][0],x_list_list[0][2]
    dequeue(x_list_list)
### BUGGY CODE ###

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

MOD = 998244353

class Comb:
    def __init__(self, N):
        self.fac = [1] * (N+1)
        for i in range(2, N+1): self.fac[i] = self.fac[i-1] * i % MOD

    def comb(self, n, r):
        if r < 0 or r > n: return 0
        return (self.fac[n] * pow(self.fac[r], MOD-2, MOD)) % MOD * pow(self.fac[n-r], MOD-2, MOD) % MOD

    def permutation(self, n, r):
        if r == 0: return 1
        return self.fac[n] * pow(self.fac[n-r], MOD-2, MOD) % MOD

comb = Comb(N)

ans = 0

for i in range(K+1):
    n = comb.comb(N-1, i) * M * pow(M-1, N-1-i, MOD) % MOD
    ans += n
    ans %= MOD

print(ans)

### FIXED CODE ###

import sys
input=sys.stdin.readline

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

    MOD = 998244353

    class Comb:
        def __init__(self, N):
            self.fac = [1] * (N+1)
            for i in range(2, N+1): self.fac[i] = self.fac[i-1] * i % MOD

        def __call__(self, n, r):
            return self.comb(n, r)

        def comb(self, n, r):
            if r < 0 or r > n: return 0
            return (self.fac[n] * pow(self.fac[r], MOD-2, MOD)) % MOD * pow(self.fac[n-r], MOD-2, MOD) % MOD

        def permutation(self, n, r):
            if r == 0: return 1
            return self.fac[n] * pow(self.fac[n-r], MOD-2, MOD) % MOD

    comb = Comb(N)

    ans = 0

    for i in range(K+1):
        n = (comb(N-1, i) * M) % MOD * pow(M-1, N-1-i, MOD) % MOD
        ans += n
        ans %= MOD

    print(ans)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

N = int(input())
d_array = list(map(int, input().split()))
#小さい順に並べ替え
for k in range(len(d_array)):
  for l in range(k):
    if d_array[l] > d_array[k]:
      d_array[k],  d_array[l] = d_array[l], d_array[k]

#真ん中の要素の差を取るとそれが答え
ans = d_array[N // 2] - d_array[N // 2 - 1]
print(ans)

### FIXED CODE ###

N = int(input())
d_array = list(map(int, input().split()))
#小さい順に並べ替え
list.sort(d_array)
#真ん中の要素の差を取るとそれが答え
ans = d_array[N // 2] - d_array[N // 2 - 1]
print(ans)
### BUGGY CODE ###

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

n=int(input())
abc=n
ans=0
for c in range(1,n):
  ab=abc-c
  ans+=len(make_divisors(ab))

print(ans)

### FIXED CODE ###

n=int(input())
ans=0
for i in range(1,n):
  ans+=(n-1)//i
print(ans)
### BUGGY CODE ###

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

m = []
for i in range(n):
    m.append(l[i]-i)

b = set(m)
max = 0
index = 0
for i in b:
    if max < m.count(i):
        max = m.count(i)
        index = i

ans = 0
for i in range(n):
    ans += abs(l[i]-index-i)

print(ans)


### FIXED CODE ###

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

m = []
for i in range(n):
    m.append(l[i]-i-1)

m.sort()
index = n//2

b = m[index]

ans = 0
for i in range(n):
    ans += abs(l[i]-b-i-1)

print(ans)
### BUGGY CODE ###

def main():
    s = input()
    si = tuple(int(c) for c in s)  # integers of one digit
    # ms = {2019 * x for x in range(10 ** 200000 - 1 // 2019)}
    ans = 0
    lg = len(si)
    # to slice till the last letter, +1 is needed.
    for i in range(lg + 1):
        for j in range(i + 4, lg + 1):
            # 2019 = 673 * 3
            if sum(si[i:j]) % 3 != 0:
                continue
            if int(s[i:j]) % 673 == 0:
                ans += 1

    return ans


if __name__ == '__main__':
    print(main())


### FIXED CODE ###

# https://www.hamayanhamayan.com/entry/2020/04/26/232032
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力
### BUGGY CODE ###

N = int(input())
S = list(input())

res = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        if S[i] == S[j]:
            continue
        for k in range(j+1, N):
            if j - i == k - j:
                continue
            if S[j] != S[k] and S[i] != S[k]:
                res += 1

print(res)


### FIXED CODE ###

N = int(input())
S = list(input())

r = len([s for s in S if s == "R"])
g = len([s for s in S if s == "G"])
b = len([s for s in S if s == "B"])

res = r * g * b

for i in range(N-2):
    for j in range(i+1, N-1):
        k = j + (j - i)
        if k >= N:
            break
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            res -= 1

print(res)
### BUGGY CODE ###

while True:
  n,m = map(int,input().split())
  if not n and not m: break
  lst = []
  lst2 = []
  for i in range(n):
    lst.append(int(input()))
  for i in lst:
    for j in lst:
      lst2.append(i + j)
  lst2 = lst2 + lst
  lst2.sort()
  ans = 0
  def search(x, l, r):
    y = len(l)
    if y == 0:
      return r
    elif y == 1:
      if x >= l[0]:
        return l[0]
      else:
        return r
    elif l[y//2] == x:
      return x
    elif l[y//2] > x:
      return search(x, l[:y//2], r)
    elif l[y//2] < x:
      r = l[y//2]
      return search(x, l[y//2 + 1:], r)
  for i in lst2:
    if i <= m:
      ans = max(ans, i + search(m - i, lst2, 0))
    else:
      break
  print(ans)





### FIXED CODE ###

def solve():
  while True:
    n,m = map(int,input().split())
    if not n and not m: break
    
    lst = [int(input()) for _ in range(n)]
    lst.append(0)
    lst = sorted(lst)
    lst2 = [i + j for i in lst for j in lst if i <= j]
    lst2 = sorted(lst2)
    A = []
    index = len(lst2) - 1
    for i in lst2:
      if i + lst2[-1] <= m:
        A.append(i + lst2[-1])
      elif i <= m:
        while True:
          if i + lst2[index] <= m:
            break
          index -= 1
        A.append(i + lst2[index])
      else:
        break
    print(max(A))
solve()
### BUGGY CODE ###

# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np

# N = int(input())
S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

Q = int(input())
query = [list(input().split()) for _ in range(Q)]
direction = 1
for l in query:
    if l[0] == "1":
        direction *= -1
    else:
        if (l[1] == "1" and direction == 1) or (l[1] == "2" and direction == -1):
            S = l[2] + S
        else:
            S += l[2]

if direction == 1:
    print(S)
else:
    print(S[::-1])

### FIXED CODE ###

# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np

# N = int(input())
S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

Q = int(input())
query = [list(input().split()) for _ in range(Q)]
direction = 1
S_front = ""
S_back = ""
for l in query:
    if l[0] == "1":
        direction *= -1
    else:
        if (l[1] == "1" and direction == 1) or (l[1] == "2" and direction == -1):
            S_front += l[2]
        else:
            S_back += l[2]

if direction == 1:
    print(S_front[::-1] + S + S_back)
else:
    print(S_back[::-1] + S[::-1] + S_front)
### BUGGY CODE ###



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

PY = []
P_Y = [[] for i in range(N)]


for i in range(M):
    p,y = list(map(int,input().split()))
    P_Y[p-1].append(y)
    PY.append([p,y])
    
import numpy as np

P_Y_arg = [[] for i in range(N)]
for i in range(N):
    pys=list(np.sort(P_Y[i]))
    for y in P_Y[i]:
        
        P_Y_arg[i].append(pys.index(y))
    
p_count = [0 for i in range(N)]

for i in range(M):
    ps = str(1000000+PY[i][0])
    ys = str(1000000+P_Y_arg[PY[i][0]-1][p_count[PY[i][0]-1]] + 1)
    p_count[PY[i][0]-1]+=1
    print(ps[1:]+ys[1:])
    
    


### FIXED CODE ###

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

PY = []
P_Y = [[] for i in range(N)]

p_count = [0 for i in range(N)]

for i in range(M):
    p,y = list(map(int,input().split()))
    P_Y[p-1].append(y)
    p_count[p-1]+=1
    PY.append([p,y])
    
import numpy as np

P_Y_arg = []
for i in range(N):
    P_Y_arg.append(np.array(P_Y[i]).argsort().argsort())

    
p_count = [0 for i in range(N)]

for i in range(M):
    ps = str(1000000+PY[i][0])
    ys = str(1000000+int(P_Y_arg[PY[i][0]-1][p_count[PY[i][0]-1]])+1)
    p_count[PY[i][0]-1]+=1
    print(ps[1:]+ys[1:])
### BUGGY CODE ###

import fractions


MOD = 10**9+7
N = input()
i = 0
arrs = list(map(int, input().split()))
result = 0
lcms =1
for number in arrs:
    lcms = (((number * lcms)) / (fractions.gcd(number, lcms)))
for arr in arrs:
    result += (lcms/arr)
result = result%MOD
ans = str(result).replace('.0','')
print(ans)

### FIXED CODE ###


from fractions import gcd
MOD = 10**9+7
N = input()
i = 0
arrs = list(map(int, input().split()))
result = 0
lcms = 1
for number in arrs:
    lcms = (((number * lcms)) //(gcd(number, lcms)))
for arr in arrs:
    result += (lcms//arr)
result = result%MOD
ans = str(result).replace('.0','')
print(ans)
### BUGGY CODE ###

import copy
import math

d,g = map(int,input().split())
P = []
C = []
for i in range(d):
    p,c = map(int,input().split())
    P.append(p)
    C.append(c)

m = 10**9
def score(point = 0, n = 0, now=0, done=[]):
    global m
    if point >= g:
        if m > n: m = n
    elif point+100*(now+1)*P[now] >= g:
        n += math.ceil((g-point)/(100*(now+1)))
        if m > n: 
            m = n
    else:
        done.append(now)
        for i in range(d):
            if not i in done:
                score(point+P[now]*100*(now+1) + C[now], n + P[now], i, copy.copy(done))

for i in range(d):
    done = []
    score(0,0,i,done)
print(m)

### FIXED CODE ###

import math
 
d,g = [int(i) for i in input().split()]
P = []
C = []
for i in range(d):
    p,c = [int(i) for i in input().split()]
    P.append(p)
    C.append(c)

# cnt = 0
# def count():
#     global cnt
#     cnt+=1
#     print(cnt)

def flag(point,P,now):
    if point+100*(now+1)*(P-1) >= g: return 1
    elif point+100*(now+1)*P + C[now] >= g: return 2
    else: return 0

m = 10**9
def score(point = 0, n = 0, now=-1, remain = list(range(d))):
    global m
    if m <= n: return
    elif now == -1:
        for i in remain:
            score(point, n, i, remain)
    elif point >= g: m = n
    elif flag(point,P[now],now) == 1:
        n += math.ceil((g-point)/(100*(now+1)))
        if m > n: m = n
    elif flag(point,P[now],now) == 2:
        n += P[now]
        if m > n: m = n
    else:
        if m <= n+P[now]: return
        else:
            remain = remain[:]
            remain.remove(now)
            nxtp = point + P[now]*100*(now+1) + C[now]
            for i in remain:
                score(nxtp, n + P[now], i, remain)

score()
print(m)
### BUGGY CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))

ans = 0

for i in range(n-k+1):
    ans = max(ans, sum(p[i:i+k]))

print((ans+k)/2)

### FIXED CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))

a= sum(p[0:k])
ans = a

for i in range(n-k):
    a -= p[i]
    a += p[i+k]
    ans = max(ans,a)

print((ans+k)/2)
### BUGGY CODE ###

n = int(input())
s = str(input())
ans = 0
for i in range(n):
    for j in range(i, n):
        if s[i] == s[j]:
            continue
        for k in range(j, n):
            if s[j] != s[k] and s[i] != s[k] and j-i != k-j:
                ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
s = str(input())
r, g, b = map(s.count, "RGB")
ans = r*g*b
for i in range(n):
    for j in range(i+1, n):
        k = 2*j - i
        if k<n and len(set([s[i], s[j], s[k]])) == 3:
            ans -= 1
print(ans)
### BUGGY CODE ###

import sys
from collections import Counter
def input():
    return sys.stdin.readline()[:-1]
def main():
    N = int(input())
    A = sorted(list(map(int,input().split())))
    C = Counter(A)
    U = set()
    ans = 0
    for e in A:
        if C[e] > 1:
            U.add(e)
        else:
            flag = 1
            for f in U:
                if e%f == 0:
                    flag = 0
                    break
            if flag == 1:
                ans += 1
            U.add(e)
    print(ans)
if __name__ == '__main__':
    main()


### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
U = [0]*(10**6+1)
for e in A:
    U[e] += 1
ans = 0
for k in range(1,10**6+1):
    if U[k] == 1:
        ans += 1
    if U[k] > 0:
        for l in range(2*k,10**6+1,k):
            if U[l] > 0:
                U[l] += 1
print(ans)
### BUGGY CODE ###

s = input()
k = int(input())


def do(s):
    s_n =""
    for c in s:
        c_int= int(c)
        s_n+=(c*c_int)
    return s_n

while True:
    s_n=do(s)[:min(len(s)+1,k+1)]
    #print(s)
    if s_n==s:
        break
    else:s=s_n

#print(len(s))
print(s[k-1])

### FIXED CODE ###

s = input()
k = int(input())

i=0
for c in s:
    if c!="1":
        res=c
        #print(i,res)
        break
    i+=1

if k>i:
    print(res)
else:
    print(1)