Harryxun/stf_run huggingface dataset:
import heapq
n, m = map( int, input().split() )
adj_list = [ [] for i in range( n+1 ) ]
for _ in range( m ):
    a, b, c = map( int, input().split() )
    adj_list[ a ].append( ( b, c ) )
    adj_list[ b ].append( ( a, c ) )

# dijkstra
def dijkstra( start ):
    prev_node = [ -1 ] * ( n + 1 )
    INF = 10 ** 10
    VISITED = 1
    NOT_VISITED = 0
    cost = [ INF ] * ( n + 1 )
    cost[ start ] = 0
    visit = [ NOT_VISITED ] * ( n + 1 )
    queue = [ ( cost[ start ], start ) ]
    while len( queue ) > 0:
        c, v = heapq.heappop( queue )
        visit[ v ] = VISITED
        for u, cost_vu in adj_list[v]:
            if visit[ u ] == VISITED:
                continue
            if cost[u] > cost[v] + cost_vu:
                cost[u] = cost[v] + cost_vu
                heapq.heappush( queue, ( cost[u], u ) )
                prev_node[ u ] = v
    return prev_node

used_edge = [ [ False ] * ( m+1 ) for i in range( m+1 ) ]

used_count = 0
for s in range( 1, n+1 ):
    prev_node = dijkstra( s )
    for i in range( 1, m+1 ):
        j = prev_node[ i ]
        if j == -1:
            continue
        if used_edge[ i ][ j ] == False:
            used_count += 1
            used_edge[ i ][ j ] = True
            used_edge[ j ][ i ] = True

print( m - used_count )

### FIXED CODE ###

import heapq
n, m = map( int, input().split() )
adj_list = [ [] for i in range( n+1 ) ]
for _ in range( m ):
    a, b, c = map( int, input().split() )
    adj_list[ a ].append( ( b, c ) )
    adj_list[ b ].append( ( a, c ) )

# dijkstra
def dijkstra( start ):
    prev_node = [ -1 ] * ( n + 1 )
    INF = 10 ** 10
    VISITED = 1
    NOT_VISITED = 0
    cost = [ INF ] * ( n + 1 )
    cost[ start ] = 0
    visit = [ NOT_VISITED ] * ( n + 1 )
    queue = [ ( cost[ start ], start ) ]
    while len( queue ) > 0:
        c, v = heapq.heappop( queue )
        visit[ v ] = VISITED
        for u, cost_vu in adj_list[v]:
            if visit[ u ] == VISITED:
                continue
            if cost[u] > cost[v] + cost_vu:
                cost[u] = cost[v] + cost_vu
                heapq.heappush( queue, ( cost[u], u ) )
                prev_node[ u ] = v
    return prev_node

used_edge = [ [ False ] * ( n+1 ) for i in range( n+1 ) ]

used_count = 0
for s in range( 1, n+1 ):
    prev_node = dijkstra( s )
    for i in range( 1, n+1 ):
        j = prev_node[ i ]
        if j == -1:
            continue
        if used_edge[ i ][ j ] == False:
            used_count += 1
            used_edge[ i ][ j ] = True
            used_edge[ j ][ i ] = True

print( m - used_count )
x = int(import())

if x == 0:
    print(1)

else:
    print(0)

### FIXED CODE ###

x = int(input())

if x == 0:
    print(1)

else:
    print(0)
# coding=utf-8

line = input().split(" ")
N = int(line[0])
M = int(line[1])

if M==0:
    print("Yes")
    exit()

l = []
for _ in range(M):
    line = input().split(" ")
    l.append((
        int(line[0])-1
        ,int(line[1])-1
        ,int(line[2])
    ))
l.sort()
o = l[0][0]
for i in range(M):
    l[i] = (
        l[i][0]-o
        ,l[i][1]-o
        ,l[i][2]
    )

def check(l):
    nl = [None for x in range(N)]
    nl[0] = 0

    flag = True
    while flag:
        flag = False
        ll = []
        for c in l:
            if nl[c[0]]!=None and nl[c[0]]>=0 and nl[c[1]]==None:
                nl[c[1]] = nl[c[0]]+c[2]
            elif nl[c[0]]==None and nl[c[1]]!=None and nl[c[1]]>=0:
                nl[c[0]] = nl[c[1]]-c[2]
            elif nl[c[0]]!=None and nl[c[0]]>=0 and nl[c[1]]!=None and nl[c[1]]>=0:
                if nl[c[1]]-nl[c[0]]==c[2]:
                    pass
                else:
                    print("No")
                    exit()
            else:
                ll.append(c)
                flag = True
        if len(l)==len(ll):
            break
        else:
            l = ll.copy()
    for x in nl:
        if x<0:
            print("No")
            exit()
    return l

while len(l)>0:
    l = check(l)
    if len(l)==0:
        break
    l.sort()
    o = l[0][0]
    for i in range(len(l)):
        l[i] = (
            l[i][0]-o
            ,l[i][1]-o
            ,l[i][2]
        )


print("Yes")


### FIXED CODE ###

# -*- coding: utf-8 -*-

class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        # 根への距離を管理
        self.weight = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            # 親への重みを追加しながら根まで走査
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    # 併合
    def unite(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        # xの木の高さ < yの木の高さ
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        # xの木の高さ ≧ yの木の高さ
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            # 木の高さが同じだった場合の処理
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    # 同じ集合に属するか
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # xからyへのコスト
    def diff(self, x, y):
        return self.weight[x] - self.weight[y]

n,m = map(int, input().split())
uf = WeightedUnionFind(n)
for _ in range(m):
    l,r,d = map(int, input().split())
    if uf.same(l,r):
        if uf.diff(l,r) != d:
            print("No")
            exit()
    else:
        uf.unite(l,r,d)

print("Yes")
int main(){
int a,b;
while(true){
scanf("%d %d",&a,&b);
if((a==0)&&(b==0))break;
if(a<=b) printf("%d %d\n",a,b);
if(a>b) printf("%d %d\n",b,a);
}
return 0;
}

### FIXED CODE ###

import sys
 
def main():
    for line in iter(sys.stdin.readline, ""):
        a = line.rstrip("\n").split(" ")
        b = []
        b.append(int(a[0]))
        b.append(int(a[1]))
        if (b[0] == 0 and b[1] == 0):
            return
 
        print(str(min(b)) + " " + str(max(b)))
      
if __name__ == "__main__":
    main()
s=input()
n=len(s)
k=int(input())
st=min(s)

if k==1:
    print(st)
    exit()

ans=[]
x=1
while x<6:
    for i in range(n-x):
        for j in range(i+x,n+x):
            ans.append(s[i:j])
    x+=1
    
ans=list(set(ans))
ans=sorted(ans)
print(ans[k-1])

### FIXED CODE ###

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

lis=[]

for i in range(len(s)):
    for j in range(k):
        tmp=s[i:i+j+1]
        lis.append(tmp)

lis=sorted(list(set(lis)))        
print(lis[k-1])
from collections import deque
N,Q = (int(x) for x in input().split())
ab = [list(map(int, input().split())) for _ in range(N-1)]
px = [list(map(int, input().split())) for _ in range(Q)]
par = [0] * N
ans = [0] * N
par[0] = 500000
for i in ab:
    temp = [par[j-1] for j in i]
    wch = temp.index(0)
    par[i[wch]-1] = i[abs(wch-1)]
def count(vert):
    if vert == 1:
        prev = 0
    else:
        prev = ans[par[vert-1]-1]
    ans[vert-1] = prev + sum([px[i][1] for i in range(Q) if px[i][0] == vert])
q = deque([1])
while len(q) > 0:
    temp = q.popleft()
    if temp is not None:
        count(temp)
        children = [x for x, y in enumerate(par) if y == temp]
        for child in children:
            q.append(child+1)
print(*ans)

### FIXED CODE ###

from collections import deque
N,Q = (int(x) for x in input().split())
connected = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = (int(x) for x in input().split())
    connected[a-1].append(b)
    connected[b-1].append(a)
counter = [0] * N
for _ in range(Q):
    p,x = (int(y) for y in input().split())
    counter[p-1] += x
ans = counter
q = deque([(1,0)])
searched = [0] * N
while q:
    a,p = q.popleft()
    if p != 0:
        ans[a-1] += ans[p-1]
    searched[a-1] = 1
    for child in connected[a-1]:
        if searched[child-1] == 0:
            q.append((child,a))
print(*ans)
s = list(input()).set
a = "abcdefghijklmnopqrstuvwxyz"
for c in s:
  a.remove(c)
print(a[0])

### FIXED CODE ###

s = list(set(list(input())))
a = list("abcdefghijklmnopqrstuvwxyz")
for c in s:
  a.remove(c)
print(a[0]) if len(a)>0 else print("None")
n, x, t = list(map(input()))

if n % x == 0:
  return n / x * t
else n % x != 0:
  return (n // x + 1) * t

### FIXED CODE ###

import math

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

print(math.ceil(a[0] / a[1]) * a[2])
input();l=list(map(int,input().split()).sort();print(l[-1]-l[0])

### FIXED CODE ###

input();l=sorted(list(map(int,input().split())));print(l[-1]-l[0])
while True:
    a, op, b = map(str, input().split(" "))
    if a == 0 and b == 0:
        break
    a, b = int(a), int(b)
    if op == "+":
        c = a + b
    elif op == "-":
        c = a - b
    elif op == "*":
        c = a * b
    else:
        c = a / b
    print(c)


### FIXED CODE ###

while True:
    a, op, b = map(str, input().split(" "))
    if op == "?":
        break
    a, b = int(a), int(b)
    if op == "+":
        c = a + b
    elif op == "-":
        c = a - b
    elif op == "*":
        c = a * b
    else:
        c = a // b
    print(c)
#UnionFind木
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 union(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 same(self, x, y):
        return self.find(x) == self.find(y)

  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]

  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]

  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

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

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

ans = []

A = A[::-1]
B = B[::-1]
uf = UnionFind(N)
total = N*(N-1)//2
ans.append(total)
for i in range(M):
  if uf.same(A[i],B[i]):
    ans.append(total)
    continue
  m = len(uf.members(A[i]))
  n = len(uf.members(B[i]))
  uf.union(A[i],B[i])
  total -= m*n
  ans.append(total)
  
#print(ans)   

print(*ans[:-1][::-1], sep='\n')


### FIXED CODE ###

A, B, C = map(int, input().split())
print(min(B//A,C))
N,D=map(int,input().split())
m=(N-1)//(2D+1)
n=m+1
print(n)

### FIXED CODE ###

n, d = map(int, input().split())
print(1 + n//(2*d+1)) if n%(2*d+1) else print(n//(2*d+1))
n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(1,n-1) :
    if a[i] - a[i-1] >= 0 :
        continue
    else :
        ans += abs(a[i] - a[i-1])
        a[i] += abs(a[i] - a[i-1])
        print(a)
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(n-1) :
    if a[i+1] - a[i] >= 0 :
        continue
    else :
        ans += abs(a[i+1] - a[i])
        a[i+1] += abs(a[i+1] - a[i])
print(ans)
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
def hurui(n):
    """n以下の素数のリストを返す
    """
    l = list(range(2,n+1))
    p = 2
    i = 0
    while True:
        l = [item for item in l if item==p or item%p!=0]
        i += 1
        p = l[i]
        if p*p>n:
            break
    return l
b = [0]*(max(a)+1)
done = False
if max(a)>=10:
    l = hurui(max(a)+1)
else:
    l = [2,3,5,7]
for num in a:
    b[num] += 1
for num in l:
    val = sum(b[i] for i in range(num, len(b), num))
    if val>=2:
        g = a[0]
        for i in range(1,n):
            g = gcd(g, a[i])
            if g==1:
                print("setwise coprime")
                done = True
                break
        else:
            print("not coprime")
            done = True
    if done:
        break
else:
    print("pairwise coprime")

### FIXED CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
from math import gcd
def hurui(n):
    """n以下の素数のリストを返す
    """
    l = list(range(2,n+1))
    p = 2
    i = 0
    while True:
        l = [item for item in l if item==p or item%p!=0]
        i += 1
        p = l[i]
        if p*p>n:
            break
    return l
b = [0]*(max(a)+1)
done = False
if max(a)>=10:
    l = hurui(max(a)+1)
else:
    l = [2,3,5,7]
for num in a:
    b[num] += 1
for num in l:
    val = sum(b[i] for i in range(num, len(b), num))
    if val>=2:
        g = a[0]
        for i in range(1,n):
            g = gcd(g, a[i])
            if g==1:
                print("setwise coprime")
                done = True
                break
        else:
            print("not coprime")
            done = True
    if done:
        break
else:
    print("pairwise coprime")
import sys

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

ls = []

L, R = map(int,input().split())
l = [k+L for k in range(R-L+1)]

if M == 1:
    print(len(l))
else:
  	cs = []
    for i in range(M-1):
        L, R = map(int,input().split())
        if L in l:
            c = l[-1] - L + 1
            if c <= 0:
                print(0)
                sys.exit()
            cs.append(c)

    print(min(cs))

### FIXED CODE ###

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

Ls, Rs = [0 for _ in range(M)],  [0 for _ in range(M)]

for i in range(M):
    L, R = map(int,input().split())
    Ls[i] = L
    Rs[i] = R
    
L_prime = max(Ls)
R_peime = min(Rs)

if L_prime > R_peime:
    print(0)
else:
    print(R_peime - L_prime + 1)
def solve(string):
    a = int(string)
    return str(a + a**2 + a**3)                                                                                         

if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))
~                                                                                                                       ~                                                                                                                       ~                                                                                                                       ~                                                                                                                       ~                                                    

### FIXED CODE ###

def solve(string):
    a = int(string)
    return str(a + a**2 + a**3)                                                                                         

if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))
s,t=map(str,input().spilt())
a,b=map(int,input().split())
u=input()
if u==s:
  print(str(a-1),str(b))
else:
  print(str(a),str(b-1))

### FIXED CODE ###

s, t = map(str, input().split())
a, b = map(int,input().split())
u = input()

if u==s:
    print(a-1, b)

else:
    print(a, b-1)
import numpy as np
import math

N = int(input())
A = list(map(int, input().split()))
if N % 2 == 1 and A.count(0) == 1 and np.all(A.count(i*2+2)==2 for i in range(N//2)):
    print(np.int64(np.remainder(math.pow(2, N//2), (math.pow(10, 9) + 7))))
elif N % 2 == 0 and np.all(A.count(i*2+1)==2 for i in range(N//2)):
    print(np.int64(np.remainder(math.pow(2, N//2), (math.pow(10, 9) + 7))))
else:
    print(0)

### FIXED CODE ###

from collections import Counter
N = int(input())
A = list(map(int, input().split()))
M = N//2
c = Counter(A)
if N % 2 == 1 and A.count(0) == 1 and all(c[i*2+2] == 2 for i in range(M)):
    print((2 ** M) % (10**9+7))
elif N % 2 == 0 and all(c[i*2+1]==2 for i in range(M)):
    print((2 ** M) % (10**9+7))
else:
    print(0)
N=int(input())
As=list(map(int,input().split()))

Ans=1

for A in range(N):
    NewAns=Ans*As[A]
    Ans=NewAns
if Ans>10**18:
    Ans=-1

print(Ans)

### FIXED CODE ###

A,B=map(int,input().split())
print(A*B)
a,b = map(int,input().split())

if a>9 and b>9:
  print(-1)
  else
  print(a*b)
  
  

### FIXED CODE ###

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

if a>9 or b>9:
  print("-1")
else:
  print(a*b)
def make7(i, f, sum):
    if i == 3:
        if sum == 7:
            print(f + "=7")
            exit()
    else:
        make7(i+1, f+"+"+S[i+1], sum+S[i+1])
        make7(i+1, f+"-"+S[i+1], sum+S[i+1])


S = input()
n = len(S)

make7(0, S[0], 0)


### FIXED CODE ###

def make7(i, f, sum):
    if i == 3:
        if sum == 7:
            print(f + "=7")
            exit()
    else:
        make7(i+1, f+"+"+S[i+1], sum+int(S[i+1]))
        make7(i+1, f+"-"+S[i+1], sum-int(S[i+1]))


S = input()
n = len(S)

make7(0, S[0], int(S[0]))
import numpy as np
import math

n = int(input())
A = list(map(int, input().split()))
ans = np.prod(A)
l = int(math.log10(ans)+1)
if l >= 18:
    print(-1)
else:
    print(int(ans))
    

### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
ans = 1
count = 0
if 0 in A:
    print(0)
else:
    for i in range(n):
        ans *= A[i]
        if ans > 10**18:
            count = 1
            print(-1)
            break
    if count == 0:
        print(ans)
list = raw_input().split(" ")
list.sort()
print(" ".join(list))


### FIXED CODE ###

list = raw_input().split(" ")
list.sort()
print(" ".join(list))
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
r = 0
a = 0
for i in range(N)
    r += B[A[i]]
    if A[i] == a+1:
        r += C[i]
    a = A[i]
print(r)
  

### FIXED CODE ###

N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
r = 0
a = 0
for i in range(N):
    r += B[A[i]-1]
    if  A[i]-1 > len(C):
        continue
    elif A[i] == a+1 and A[i] != 1:
        r += C[a-1]
    a = A[i]
print(r)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)

const ll mod = 1e9;
const int INF = 1<<29;

int main(){
    int x;
    cin >> x;
    if (x < 100) cout << 0 << endl;
    else{
        int num = x / 100;
        x %= 100;
        for (int i=5;i>0;i--){
            num -= x / i;
            x %= i;
        }
        if (num >= 0) cout << 1 << endl;
        else cout << 0 << endl;
    }
    return 0;
}

### FIXED CODE ###

import math
import queue
import bisect
import heapq
import time
import itertools

mod = 1e9+7

def swap(a,b):
    return (b,a)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def main():
    x = int(input())
    if x<100:
        print(0)
        return
    buy = x//100
    sur = x%100
    num = (sur+4)//5
    if num<=buy:
        print(1)
    else:
        print(0)
    return

if __name__=='__main__':
    main()
from math import gcd
from functools import reduce


def resolve():
    n = int(input())
    t = list(int(input()) for _ in range(n))
    ans = lcm(t)
    print(ans)


def lcm_base(x, y):
    return x * y // gcd(x, y)


def lcm(numbers):
    return reduce(lcm_base, numbers, 1)


if __name__ == "__main__":
    resolve()


### FIXED CODE ###

from fractions import gcd
from functools import reduce


def resolve():
    n = int(input())
    t = list(int(input()) for _ in range(n))
    res = 1
    for ti in t:
        res = lcm_base(res, ti)
    print(res)


def lcm_base(x, y):
    return x * y // gcd(x, y)


def lcm(numbers):
    return reduce(lcm_base, numbers, 1)


if __name__ == "__main__":
    resolve()
from collections import deque
S = deque(list(input()))
Q = int(input())
f = 0
for _ in range(Q):
  a, *b = input().split()
  f += int(a)
  if a == "2":
    if (int(b[0]) + f) % 2 == 1 :
      S.appendleft(b[1])
    else:
      S.append(b[1])
if  f % 2 == 0 :
  S = "".join(S)
else:
  S = "".joins(S[::-1])
print (S)

### FIXED CODE ###

from collections import deque
S = deque(list(input()))
Q = int(input())
f = 0
for _ in range(Q):
  a, *b = input().split()
  f += int(a)
  if a == "2":
    if (int(b[0]) + f) % 2 == 1 :
      S.appendleft(b[1])
    else:
      S.append(b[1])
D = list(S)
print ("".join(D) if f % 2 == 0 else "".join(D[::-1]))
import sys
from collections import defaultdict


def dfs(tree, p, cnt, visited):
    visited[p] = True
    cnt_here = cnt[p]
    for c in tree[p]:
        if visited[c]:
            continue
        cnt[c] += cnt_here
        dfs(tree, c, cnt, visited)


def main():
    input = sys.stdin.buffer.readline
    n, q = map(int, input().split())
    tree = defaultdict(list)
    for _ in range(n - 1):
        a, b = map(int, input().split())
        tree[a].append(b)
        tree[b].append(a)
    tree = dict(tree)
    cnt = [0] * (n + 1)

    for _ in range(q):
        p, x = map(int, input().split())
        cnt[p] += x
    visited = [False] * (n + 1)
    dfs(tree, 1, cnt, visited)
    print(*cnt[1:])


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
from collections import defaultdict


def dfs(tree, p, cnt, visited):
    visited[p] = True
    cnt_here = cnt[p]
    for c in tree.get(p):
        if visited[c]:
            continue
        cnt[c] += cnt_here
        dfs(tree, c, cnt, visited)


def main():
    input = sys.stdin.buffer.readline
    sys.setrecursionlimit(10 ** 9)
    n, q = map(int, input().split())
    tree = defaultdict(list)
    for _ in range(n - 1):
        a, b = map(int, input().split())
        tree[a].append(b)
        tree[b].append(a)
    tree = dict(tree)
    cnt = [0] * (n + 1)

    for _ in range(q):
        p, x = map(int, input().split())
        cnt[p] += x
    visited = [False] * (n + 1)
    dfs(tree, 1, cnt, visited)
    print(*cnt[1:])


if __name__ == "__main__":
    main()
import math

N = int(input())
A = list(map(int, input().split()))
a_list = []
b_list = []
c_list = []

A.sort()
#print(math.gcd(6, 7))
if 4 <= N:
    a, b, c = math.gcd(A[0], A[1]), math.gcd(A[1], A[2]), math.gcd(A[0], A[2])
    for i in range(3, N):
        a_list.append(math.gcd(A[i], a))
        b_list.append(math.gcd(A[i], b))
        c_list.append(math.gcd(A[i], c))
    a_list.sort()
    b_list.sort()
    c_list.sort()
    ans = max(a_list[0], b_list[0], c_list[0])

elif N == 3:
    ans = max(math.gcd(A[0], A[1]), math.gcd(A[1], A[2]), math.gcd(A[0], A[2]))

elif N == 2:
    ans = max(A[0], A[1])
else:
    ans = 1000000000
    print(N)

print(ans)

### FIXED CODE ###

import fractions


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

gcd_l = [0]
gcd_r = [0]
for i in range(N):
    gcd_l.append(fractions.gcd(gcd_l[i], A[i]))
    gcd_r.append(fractions.gcd(gcd_r[i], A[-(i+1)]))
gcd_r = gcd_r[::-1]

ans = []
for i in range(N):
    ans.append(fractions.gcd(gcd_l[i], gcd_r[i+1]))

print(max(ans))
n=input()
k=int(input())
for i in range(k):
	n=n.strip('1')
print(n[0])

### FIXED CODE ###

n=input()
k=int(input())
c=0
for i in range(len(n)):
	if n[i] is '1':
		c+=1
	else:
		break

if c>=k:
	print('1')
else:
	print(n[c])