Harryxun/stf_run huggingface dataset:
from operator import itemgetter
n,m = map(int,input().split())
t = [list(map(int,input().split())) for _ in range(m)]
t.sort(key=itemgetter(0))
c = [i[1] for i in t ]
s = [i[0] for i in t]
# print(c)
x = 0
ans = "aaa"
ans = list(ans)
for i in range(3):
    for j in range(len(s)):
        if i==s[j]-1 :
            if str(c[j])!=ans[i] and ans[i]=="a":
                ans[i]=str(c[j])
            elif  str(c[j])!=ans[i] and ans[i]!="a":
                x =1
# print(ans)

if x==1:
    print(-1)
else:
    if ans[3-n]=="a" and max(s)<n and n!=1:
        ans[3-n]="1"
    for i in range(3):
        if ans[i]=="a":
            ans[i]="0"
    # if ans[n-1]=="0" and max(s)<n and n!=1:
    #     ans[n-1]="1"
    # print(ans)
    ans = int("".join(ans))

    print(ans)

### FIXED CODE ###

from operator import itemgetter
n,m = map(int,input().split())
t = [list(map(int,input().split())) for _ in range(m)]
t.sort(key=itemgetter(0))
c = [i[1] for i in t ]
s = [i[0] for i in t]
# print(c)
x = 0

ans = "a"*n
ans = list(ans)
for i in range(n):
    for j in range(len(s)):
        if i==s[j]-1 :
            if str(c[j])!=ans[i] and ans[i]=="a":
                ans[i]=str(c[j])
            elif  str(c[j])!=ans[i] and ans[i]!="a":
                x =1
# print(ans)

if ans[0]=="0" and n!=1:
    x=1
for i in range(len(ans)):
    if ans[i]=="a":
        ans[i]="0"
# print(ans)
if ans[0]=="0"and n!=1:
    ans[0]="1"
if x==0:
    print(int("".join(ans)))
else:
    print(-1)
from sys import stdin
def read():
    return stdin.readline().strip()

dict={}
output=[]

iteration=int(read())

max_val=-1

for _ in range(iteration):
    item=read()
    
    if dict.get(item) is None:
        dict[item]=0 
    dict[item]+=1 
    max_val = max(dict[item],max_val)
#max_val=max(dict.values())
for k,v in dict:
    
    if(max_val==v):
        output.append(k)
    
    
output.sort()
print('\n'.join(output))


### FIXED CODE ###


from sys import stdin
def read():
    return stdin.readline().strip()

dict={}
output=[]

iteration=int(read())

max_val=-1

for _ in range(iteration):
    item=read()
    
    if dict.get(item) is None:
        dict[item]=0 
    dict[item]+=1 
    max_val = max(dict[item],max_val)
#max_val=max(dict.values())
for k,v in dict.items():
    
    if(max_val==v):
        output.append(k)
    
    
output.sort()
print('\n'.join(output))
a, b = map(int, input().split())

print(max(0, a-2*b)
      

### FIXED CODE ###

a, b = map(int, input().split())

print(max(0, a-2*b))
from operator import itemgetter

N, M = map(int, input().split(" "))
A = list(map(int, input().split(" ")))
BC = [list(map(int, input().split(" "))) for _ in range(M)]

A = sorted(A)
BC = sorted(BC, key=itemgetter(1), reverse=True)
now = 0
count = 0
flag = False

for b, c in BC:
    while True:
        # print(A[now], c)
        if A[now] >= c:
            break
            flag = True
        count += c-A[now]
        b -= 1
        now += 1
        if b <= 0:
            break
        if now >= N:
            break
    if flag:
        break
print(sum(A) + count)


### FIXED CODE ###

from operator import itemgetter

N, M = map(int, input().split(" "))
A = list(map(int, input().split(" ")))
BC = [list(map(int, input().split(" "))) for _ in range(M)]

A = sorted(A)
BC = sorted(BC, key=itemgetter(1), reverse=True)
now = 0
count = 0
flag = False

for b, c in BC:
    while True:
        # print(A[now], c)
        if A[now] >= c:
            flag = True
            break
        count += c-A[now]
        b -= 1
        now += 1
        if now >= N:
            flag = True
            break
        if b <= 0:
            break
    if flag:
        break
print(sum(A) + count)
n=int(input())
c=input().split();d=c[:]
for i in range(n-1):
 for j in range(0,n-i-1):
  if c[j][1]>c[j+1][1]:c[j],c[j+1]=c[j+1],c[j]
 m=i
 for j in range(i,n):
  if d[m][1]>d[j][1]:m=j
 d[i],d[m]=d[m],d[i]
print(*c);print("Stable")
print(*d)
print(['Not s','S'][b==s]+'table')


### FIXED CODE ###

n=int(input())
c=input().split();d=c[:]
for i in range(n-1):
 for j in range(n-i-1):
  if c[j][1]>c[j+1][1]:c[j:j+2]=c[j+1],c[j]
 m=i
 for j in range(i,n):
  if d[m][1]>d[j][1]:m=j
 d[i],d[m]=d[m],d[i]
print(*c);print("Stable")
print(*d);print(['Not s','S'][c==d]+'table')
T = input()
count = 0

for i in range(len(S)):
  if S[i]==T[i]:
    count += 1
    
print(count)

### FIXED CODE ###

S = input()
T = input()
count = 0

for i in range(len(S)):
  if S[i]==T[i]:
    count += 1
    
print(count)
def get_difference():
	# get input from raw_input()
	n, k = map(int, raw_input().split(' '))
	l = [int(e) for e in raw_input().split(' ')]

	gcd_v = reduce(gcd, l)
	if not k % gcd_v and k <= max(l):
		print "POSSIBLE"
	else:
		print "IMPOSSIBLE"


if __name__ == "__main__":
	get_difference()

### FIXED CODE ###

from fractions import gcd
N, K = map(int, raw_input().split(' '))
A = map(int, raw_input().split(' '))
 
M = max(A)
G = reduce(gcd, sorted(A))
 
if not K % G and K <= M:
    print 'POSSIBLE'
else:
    print 'IMPOSSIBLE'
maxnum = 10000

# エラトステネスのふるい
is_prime = [x for x in range(maxnum)]
for prime in is_prime:
    if prime == 0 or prime == 1:
        is_prime[prime] = 0
        continue
    for non_prime in range(prime * 2, maxnum, prime):
        is_prime[non_prime] = 0

is_like = [False] * maxnum
for i in range(maxnum):
    if (is_prime[i] and is_prime[(i + 1) // 2]):
        is_like[i] =  True

like_sum = [0] * maxnum
for i in range(1, maxnum):
    like_sum[i] = like_sum[i - 1]
    if (is_like[i]):
        like_sum[i] += 1

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(like_sum[r] - like_sum[l - 1])


### FIXED CODE ###

maxnum = 100000

# エラトステネスのふるい
is_prime = [x for x in range(maxnum)]
for prime in is_prime:
    if prime == 0 or prime == 1:
        is_prime[prime] = 0
        continue
    for non_prime in range(prime * 2, maxnum, prime):
        is_prime[non_prime] = 0

is_like = [False] * maxnum
for i in range(maxnum):
    if (is_prime[i] and is_prime[(i + 1) // 2]):
        is_like[i] =  True

like_sum = [0] * maxnum
for i in range(3, maxnum):
    like_sum[i] = like_sum[i - 1]
    if (is_like[i]):
        like_sum[i] += 1

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(like_sum[r] - like_sum[l - 1])
N, M = map(int, input().split())
Edge = [[] for i in range(M)]
for i in range(M):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    Edge[a].append(b)
    Edge[b].append(a)

Visited = [False for i in range(N)]
Visited[0] = True
ans = 0
def DFS(i):
    allvisited = True
    for j in range(N):
        if Visited[j] == False:
            allvisited = False
    if allvisited:
        return 1
    else:
        ret = 0
        for node in Edge[i]:
            if Visited[node] == False:
                Visited[node] = True
                ret += DFS(node)
                Visited[node] = False
        return ret

print(DFS(0))

### FIXED CODE ###

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

Visited = [False for i in range(N)]
Visited[0] = True
ans = 0
def DFS(i):
    allvisited = True
    for j in range(N):
        if Visited[j] == False:
            allvisited = False
    if allvisited:
        return 1
    else:
        ret = 0
        for node in Edge[i]:
            if Visited[node] == False:
                Visited[node] = True
                ret += DFS(node)
                Visited[node] = False
        return ret

print(DFS(0))
a,b,c = map(int,input.split())
if 10*b+c%4==0:
  return 'YES'

else:
  return 'NO'

### FIXED CODE ###

a,b, c = map(int, input().split())
if (10*b+c)%4 ==0:
  print('YES')
     
else:
  print('NO')
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[a-x::]
q=sorted(list(map(int,input().split())))[b-y::]
r=sorted(list(map(int,input().split())))[::-1]
if c<x+y:
  r+=[0]*(x+y-c)
i=0
j=0
ans=0
for k in range(x+y):
  if r[k]>p[i] and i<x and p[i]<=q[j]:
    ans+=r[k]
    i+=1
  elif r[k]>q[j] and j<y:
    ans+=r[k]
    j+=1
  else:
    break
print(ans+sum(p[i:])+sum(q[j:]))

### FIXED CODE ###

x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())))[a-x::]
q=sorted(list(map(int,input().split())))[b-y::]
r=sorted(list(map(int,input().split())))[::-1]
p.append(10**9)
q.append(10**9)
if c<x+y:
  r+=[0]*(x+y-c)
i=0
j=0
ans=0
for k in range(x+y):
  if r[k]>p[i] and i<x and p[i]<=q[j]:
    ans+=r[k]
    i+=1
  elif r[k]>q[j] and j<y:
    ans+=r[k]
    j+=1
  else:
    break
if i==x:
  p1=0
else:
  p1=sum(p[i:x])
if j==y:
  q1=0
else:
  q1=sum(q[j:y])
print(ans+p1+q1)
K =int(input())
odd_num = (k-1)//2 +1
even_num = k//2
print((odd_num)*(even_num))

### FIXED CODE ###

k =int(input())
odd_num = (k-1)//2 +1
even_num = k//2
print((odd_num)*(even_num))
n = int(input())
arr = [int(i) for i in list(input().split())]
dp = [-1]*n
def helper(arr, end):
	global dp
	if end <= 0:
		return 0 
	if end == 1:
		return abs(arr[1] - arr[0])
	if dp[end] != -1:
		return dp[end]
	way1 = abs(arr[end] - arr[end-1]) + helper(arr, end - 1)
	way2 = abs(arr[end] - arr[end-2]) + helper(arr, end - 2)
	dp[end] = min(way1, way2)
	return dp[end]

print(helper(arr, n - 1 ))

# def helper(arr):
# 	if len(arr) <= 1:
# 		return 0
# 	if len(arr) == 2:
# 		return abs(arr[1] - arr[0])
# 	way1 = abs(arr[-1] - arr[-2]) + helper(arr[:-1])
# 	way2 = abs(arr[-1] - arr[-3]) + helper(arr[:-2])
# 	return min(way1, way2 )



# if n == 1:
# 	print(0)
# elif n == 2:
# 	print(abs(arr[1] - arr[0]))
# else:
# 	dp = [0]*n
# 	dp[0] = 0
# 	dp[1] = abs(arr[1] - arr[0])
# 	for i in range(2,len(arr)):
# 		dp[i] = min(dp[i-1] + abs(arr[i] - arr[i-1]), dp[i-2] + abs(arr[i] - arr[i-2]))
# 	print(dp[n-1])
# print(helper(arr))

### FIXED CODE ###

n = int(input())
arr = [int(i) for i in list(input().split())]
def helper(arr):
	if len(arr) <= 1:
		return 0
	if len(arr) == 2:
		return abs(arr[1] - arr[0])
	way1 = abs(arr[-1] - arr[-2]) + helper(arr[:-1])
	way2 = abs(arr[-1] - arr[-3]) + helper(arr[:-2])
	return min(way1, way2 )

if n == 1:
	print(0)
elif n == 2:
	print(abs(arr[1] - arr[0]))
else:
	dp = [0]*n
	dp[0] = 0
	dp[1] = abs(arr[1] - arr[0])
	for i in range(2,len(arr)):
		dp[i] = min(dp[i-1] + abs(arr[i] - arr[i-1]), dp[i-2] + abs(arr[i] - arr[i-2]))
	print(dp[n-1])
# print(helper(arr))
import sys
from collections import defaultdict
import collections


class UnionFind2:
    def __init__(self, size):
        # 負の値はルート (集合の代表)
        # 正の値は次の要素を表す
        self.table = [-1 for _ in range(size)]

    # 集合の代表を求める
    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            # 経路の圧縮
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    # 併合
    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            self.table[s2] = s1
            return True
        return False


N, M = map(int, input().split())
uf = UnionFind2(N+1)

for i in range(M):
    A, B = map(int, input().split())
    uf.union(A, B)

hoge = [uf.find(i) for i in range(N+1)]

#print(hoge)
hogehoge = collections.Counter(hoge).most_common()

print(hogehoge[0][1])

### FIXED CODE ###

import sys
from collections import defaultdict
import collections

sys.setrecursionlimit(1000000)

class UnionFindPathCompression():
    def __init__(self, n):
        self.parents = list(range(n))

    def find(self, x):
        if self.parents[x] == x:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        self.parents[y] = x


N, M = map(int, input().split())
uf = UnionFindPathCompression(N)

for i in range(M):
    A, B = map(int, input().split())
    uf.union(A - 1, B - 1)

hoge = [uf.find(i) for i in range(N)]

#print(hoge)
hogehoge = collections.Counter(hoge).most_common()

print(hogehoge[0][1])
import sys
input = sys.stdin.readline
import math
if __name__ == '__main__':
    # test
    A, B = map(int, input().rstrip().split())
    print(math.ceil(A * B / math.gcd(A, B)))

### FIXED CODE ###

import sys
input = sys.stdin.readline
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
def print_ans(A, B):
    """Test Case
    >>> print_ans(2, 3)
    6
    >>> print_ans(123, 456)
    18696
    >>> print_ans(100000, 99999)
    9999900000
    """
    print(A * B // gcd(A, B))
if __name__ == '__main__':
    # test
    A, B = map(int, input().rstrip().split())
    print_ans(A, B)
s=input()
if s[2]=s[3] and s[4]=s[5]:
    print("Yes")
else:
    print("No")    

### FIXED CODE ###

s=input()
if s[2]==s[3] and s[4]==s[5]:
    print("Yes")
else:
    print("No")
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n = int(input())
T = [[] for _ in range(n+1)]
for _ in range(n-1):
  a, b = map(int, input().split())
  T[a].append(b)
  T[b].append(a)
k = int(input())
VP = tuple(tuple(map(int, input().split())) for _ in range(k))
P = [-1]*(n+1)
A = [-1]*(n+1)
r, c = PV[0]
for v, p in VP:
  P[v] = p
C = [None]*(n+1)
def dfs1(v, par=-1, color=c%2):
  if P[v] == -1:
    l = -float("inf")
    r = float("inf")
  else:
    l = P[v]
    r = P[v]
  for nv in T[v]:
    if nv == par:
      continue
    nl, nr = dfs1(nv, v, color^1)
    l = max(l, nl-1)
    r = min(r, nr+1)
  if l ^ color:
    l += 1
  if r ^ color:
    r -= 1
  if l > r:
    print("No")
    exit()
  P[v] = (l, r)
  return P[v]
dfs1(r)
def dfs2(v, ini, par=-1):
  l, r = P[v]
  if l <= ini-1 <= r:
    A[v] = ini-1
  else:
    A[v] = ini+1
  for nv in T[v]:
    if nv == par:
      continue
    dfs2(nv, A[v], v)
dfs2(r, P[r][0])
print("Yes")
print(*A[1:], sep="\n")

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

INF = 10**10
n = int(input())
T = [[] for _ in range(n+1)]
for _ in range(n-1):
  a, b = map(int, input().split())
  T[a].append(b)
  T[b].append(a)
k = int(input())
VP = tuple(tuple(map(int, input().split())) for _ in range(k))
P = [-1]*(n+1)
A = [-1]*(n+1)
r, c = VP[0]
for v, p in VP:
  P[v] = p
def dfs1(v, par=-1, color=c%2):
  if P[v] == -1:
    l = -INF
    r = INF
  else:
    l = P[v]
    r = P[v]
  for nv in T[v]:
    if nv == par:
      continue
    nl, nr = dfs1(nv, v, color^1)
    l = max(l, nl-1)
    r = min(r, nr+1)
  if l&1 ^ color:
    l += 1
  if r&1 ^ color:
    r -= 1
  if l > r:
    print("No")
    exit()
  P[v] = (l, r)
  return P[v]
dfs1(r)
def dfs2(v, ini, par=-1):
  l, r = P[v]
  if l == r:
    A[v] = l
  else:
    if l <= ini-1 <= r:
      A[v] = ini-1
    else:
      A[v] = ini+1
  for nv in T[v]:
    if nv == par:
      continue
    dfs2(nv, A[v], v)
dfs2(r, P[r][0])
print("Yes")
print(*A[1:], sep="\n")
count = input()
data = [int(i) for i in input().sprit()]

print(min(data), max(data), sum(data))

### FIXED CODE ###

count = input()
data = [int(i) for i in input().split()]

print(min(data), max(data), sum(data))
from collections import Counter
import math

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

dic = Counter(a)

ans = 0

memo = {}

def seachPrimeNum(N):
    max = int(np.sqrt(N))
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum

primeNum = set(seachPrimeNum(10**6))

for ai in a:
    cnt = 0
    f = 1
    if ai not in memo:
        if ai not in primeNum:
            for i in range(1, int(math.sqrt(ai))+1):
                if ai % i == 0:
                    d = i
                    if d in dic:
                        cnt += dic[d]
                    if d == ai:
                        cnt -= 1
                    if cnt > 0:
                        f = 0
                        break
                    if i != ai // i:
                        d = ai // i
                        if d in dic:
                            cnt += dic[d]
                        if d == ai:
                            cnt -= 1
                        if cnt > 0:
                            f = 0
                            break
    else:
        f = memo[ai]
    ans += f
    memo[ai] = f

print(ans)
    

            




### FIXED CODE ###

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

a.sort()
am = a[-1]

memo = [0] * (am+1)

for ai in a:
    memo[ai] = 1

p = -1

for ai in a:
    if ai == p:
        memo[ai] = 0
        continue
    for j in range(2, am // ai + 1):
        memo[ai * j] = 0
    p = ai

print(sum(memo))
total_minute=D/S

if total_minute<=T:
  print("Yes")
else:
  print("No

### FIXED CODE ###

info=input().split()
 
D=int(info[0])
S=int(info[1])
T=int(info[2])
 
if D/S<=T:
  print('Yes')
else:
  print('No')
def gcd(a,b):
    if b == 0:
        return a
    elif a%b == 0:
        return b
    else:
        return gcd(b,a%b)

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

L = [0]*N
R = [0]*N

L[0] = A[0]
R[N-1] = A[N-1]

for n in range(1,N):
    L[n] = gcd(L[n-1],A[n])
    R[N-1-n] =gcd(R[N-n],A[N-1-n])

for n in range(N):
    GCDs[n] = gcd(L[n], R[N-1-n])

print(max(GCDs))

### FIXED CODE ###

def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

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

L = [0]
R = [0]
for n in range(N-1):
    L.append(gcd(L[-1],A[n]))
    R.append(gcd(R[-1],A[N-n-1]))
    
GCDs = []
for n in range(N):
    GCDs.append(gcd(L[n], R[N-n-1]))
    
print(max(GCDs))
import sys
import clipboard

if sys.platform == 'ios':
	input = clipboard.get()
else:
	input = input()

arr = input.split()

X, Y, Z = arr
print(Z, X, Y)

	

### FIXED CODE ###

x, y, z = input().split()
print(z, x, y)
import sys
sys.setrecursionlimit(10 ** 5)

n = int(input())
edge = [tuple(map(int, input().split())) for _ in range(n-1)]
connect = [set() for _ in range(n)]
for a, b in edge:
    connect[a-1].add(b-1)
    connect[b-1].add(a-1)

d1 = [0] * n
dn = [0] * n

def dfs(v, ng, dis, d):
    d[v] = dis
    ng.add(v)
    for n in connect[v]:
        if n not in ng:
            dfs(n, ng, dis+1, d)

dfs(0, set(), 0, d1)
dfs(n-1, set(), 0, dn)

black = 0
white = 0
for i in range(n):
    if d1[i] < dn[i]:
        black += 1
    else:
        white += 1
if black > white:
    print('Fennec')
else:
    print('Snuke')

### FIXED CODE ###

import sys
sys.setrecursionlimit(2 * 10 ** 5)

n = int(input())
edge = [tuple(map(int, input().split())) for _ in range(n-1)]
connect = [set() for _ in range(n)]
for a, b in edge:
    connect[a-1].add(b-1)
    connect[b-1].add(a-1)

d1 = [0] * n
dn = [0] * n

def dfs(v, ng, dis, d):
    d[v] = dis
    ng.add(v)
    for n in connect[v]:
        if n not in ng:
            dfs(n, ng, dis+1, d)

dfs(0, set(), 0, d1)
dfs(n-1, set(), 0, dn)

black = 0
white = 0
for i in range(n):
    if d1[i] <= dn[i]:
        black += 1
    else:
        white += 1
if black > white:
    print('Fennec')
else:
    print('Snuke')
n,k = map(int,input().split())
a_list = list(map(int,input().split()))
a_list_2 = a_list + a_list
first_count = 0
p = 10** + 7
for i in range(1,n):
  if  a_list[i] < a_list[i-1]:
    first_count += 1
second_count = 0    
for a in range(1,2*n):
  if a_list[a] < a_list[a-1]:
    secount_count += 1
ans = first_count * k  + 1//2 * (k-1) * k * second_count
print(int(ans) % p)
    

  

### FIXED CODE ###

n,k = map(int,input().split())
a_list = list(map(int,input().split()))
a_list_2 = a_list + a_list
first_count = 0
p = 10**9 + 7
for i in range(n-1):
  for j in range(i+1,n):
     if  a_list[j] < a_list[i]:
      first_count += 1
second_count = 0    
for a in a_list:
  for i in range(n):
    if a > a_list[i]:
      second_count += 1
ans = first_count * k  +  (k-1) * k * second_count //2
print(ans % p)
/*test*/
#include<bits/stdc++.h>

using namespace std;

int main() {
    int i = 0,b = 0, bko = 0, sum = 0;
    string s;
    cin >> s;
    for (i = 0; i < s.size(); i++) {
        if (s[i] == 'B') {
            b += bko;
            bko += 1;
            sum += s.size() - 1 - i;
        }
    }
    cout << sum - b << endl;
    return 0;
}

### FIXED CODE ###

s=list(input())
n=len(s)
ans=0
w=0
for index,value in enumerate(s):
    if value=="W":
        ans+=index-w
        w+=1
print(ans)
def rec(i, j):
    flag = False
    flag_ = False
    tmp = dp[i][j] + A[i+j][0] * abs(A[i+j][1] - i)
    if tmp > dp[i+1][j]:
        dp[i+1][j] = tmp
        flag = True
    tmp_ = dp[i][j] + A[i+j][0] * abs(A[i+j][1] - N + j + 1)
    if tmp_ > dp[i][j+1]:
        dp[i][j+1] = tmp_ if tmp_ > dp[i][j+1] else dp[i][j+1]
        flag_ = True
    if i + j == N - 1:
        return
    if flag:
        rec(i + 1, j)
    if flag_:
        rec(i, j + 1)
    
N = int(input())
A = sorted([(int(j),i) for i, j in enumerate(input().split())])[::-1]

dp = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
rec(0, 0)
ans = -1
for i in range(N):
    for j in range(N):
        if dp[i][j] > ans:
            ans = dp[i][j]
print(ans)

### FIXED CODE ###

from collections import deque

N = int(input())
A = sorted([(int(j),i) for i, j in enumerate(input().split())])[::-1]
d = deque([(0,0)])
dp = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
while(len(d)>0):
    i, j = d.pop()
    if i + j > N - 1:
        continue
    tmp = dp[i][j] + A[i+j][0] * abs(A[i+j][1] - i)
    if tmp > dp[i+1][j]:
        if dp[i+1][j] == 0:
            d.appendleft((i+1,j))
        dp[i+1][j] = tmp
    tmp = dp[i][j] + A[i+j][0] * abs(A[i+j][1] - N + j + 1)
    if tmp > dp[i][j+1]:
        if dp[i][j+1] == 0:
            d.appendleft((i,j+1))
        dp[i][j+1] = tmp
        
ans = -1
for i in range(N):
    for j in range(N):
        if dp[i][j] > ans:
            ans = dp[i][j]
print(ans)
H, W = map(int, input().split())

l = [int(input()) for i in range(H)]

y = [False] * H
x = [False] * W

for i in range(H):
    flg = True
    for j in range(W):
        if l[i][j] != '.':
            flg = False
            break
    if flg:
        y[i] = True

for i in range(W):
    flg = True
    for j in range(H):
        if l[j][i] != '.':
            flg = False
            break
    if flg:
        x[i] = True

for i in range(H):
    if y[i]:
        continue
    for j in range(W):
        if x[j]:
            continue
        print(l[i][j], end='')
    print()


### FIXED CODE ###

H, W = map(int, input().split())

l = []

for i in range(H):
    l.append(input())

y = [False] * H
x = [False] * W

for i in range(H):
    flg = True
    for j in range(W):
        if l[i][j] != '.':
            flg = False
            break
    if flg:
        y[i] = True

for i in range(W):
    flg = True
    for j in range(H):
        if l[j][i] != '.':
            flg = False
            break
    if flg:
        x[i] = True

for i in range(H):
    if y[i]:
        continue
    for j in range(W):
        if x[j]:
            continue
        print(l[i][j], end='')
    print()
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0

for re1 in range(a +1):
    for re2 in range(b + 1):
        for re3 in range(c + 1):
            if re1*500 + re2*100 + re3*50 == x:
                ans += 1

### FIXED CODE ###

x, a, b = [int(input()) for i in range(3)]

print((x - a) % b)
def main():
    s = input()
    k = int(input())

    m = 0
    ans = ""

    for i in range(len(s)):
        if s[i] != "1":
            m = i
            ans = s[i]
            break
    
    if k < i:
        print(1)
    else:
        print(int(ans))



if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    s = input()
    k = int(input())

    m = 0
    ans = ""

    for i in range(len(s)):
        if s[i] != "1":
            m = i+1
            ans = s[i]
            break
    
    if k < m:
        print(1)
    elif m == 0:
        print(1)
    else:
        print(int(ans))



if __name__ == "__main__":
    main()