Harryxun/stf_run huggingface dataset:
import sys

sys.setrecursionlimit(400001)

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

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


def readAB(ia,ib,left_k,nbooks):
    global N,M,nmax

    # print(ia,ib,left_k,N,M,nbooks)

    if nbooks > nmax:
        nmax = nbooks

    if  ia <= N-1:
        if left_k >= A[ia]:
            # print("A")
            readAB(ia+1,ib,left_k-A[ia],nbooks+1)

    if ib <= M-1:
        if left_k >= B[ib]:
            # print("B")
            readAB(ia,ib+1,left_k-B[ib],nbooks+1)

nmax=0
readAB(0,0,K,0)
print(nmax)

### FIXED CODE ###

import sys

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

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

nmax=0

Asum=list()
Asum.append(0)
Bsum=list()
Bsum.append(0)

imax_a = N
for i in range(N):
    s = Asum[i]+A[i]
    Asum.append(s)
    if s > K:
        imax_a = i+1
        break

imax_b = M
for i in range(M):
    s = Bsum[i]+B[i]
    Bsum.append(s)
    if s > K:
        imax_b = i+1
        break
        
for i in range(imax_a+1):
    for j in range(imax_b, -1, -1):
        time = Asum[i]+Bsum[j]
        # print("i=",i,"j=",j,"time=",time)
        if time <= K:
            imax_b = j

            if nmax < i+j:
                nmax = i+j
                # print("i=",i," j=",j," Asum",Asum[i]," Bsum", Bsum[j], " time=",time, " nmax=", nmax)

            break

print(nmax)
int a = input()
  int b = input()
  
  if a*b % 2 == 0:
    print("Even")
  else:
    print("Odd")


### FIXED CODE ###

a, b = map(int, input().split())
print("Odd" if a * b % 2 else "Even")
a, b = map(int, raw_input().split())
if   a < b:
    print "a < b"
else if a > b:
    print "a > b"
else:
    print "a == b"

### FIXED CODE ###

a, b = map(int, raw_input().split())
if   a < b:
    print "a < b"
elif a > b:
    print "a > b"
else:
    print "a == b"
N = int(input())
p = list(map(int,input().split()))
cnt = 0
for i in range(N):
    if p[i] == i+1:
        value = p[i]
        p[i] = p[i+1]
        p[i+1] = value
        cnt += 1
print(cnt)
    

### FIXED CODE ###

N = int(input())
p = list(map(int,input().split()))
cnt = 0
flag = True
for i in range(N):
    if p[i] == i+1:
        if flag:
            cnt += 1
            flag = False
        else:
            flag = True
    else:
        flag = True
print(cnt)
s = input()
a = ascii_lowercase

for i in a:
    if i not in s:
        print(i)
        break
    if i == "z":
        print("None")
        break

### FIXED CODE ###

from string import * 
s = input()
a = ascii_lowercase

for i in a:
    if i not in s:
        print(i)
        break
    if i == "z":
        print("None")
        break
#UnionFindクラス
class UnionFind(object):
 
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0 for i in range(n)]
        self.size=[1 for i in range(n)]
 
    def find(self, x):
  
        if self.par[x] == x:
            return x
        else:
            self.par[x]=self.find(self.par[x])
            return self.par[x]
        
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x]+=self.size[y]
            
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def tree_size(self,x):
        return self.size[self.find(x)]
    
def main():
    n,m = map(int, input().split())
    uf = UnionFind(n)
    for i in range(m):
        x,y,z = map(int, input().split())
        uf.union(x,y)
    res = n
    for i in range(n):
        if uf.par[i] == i:
            res -= 1
    print(res)

if __name__ == '__main__':
    main()

### FIXED CODE ###

#UnionFindクラス
class UnionFind(object):
 
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0 for i in range(n)]
        self.size=[1 for i in range(n)]
 
    def find(self, x):
  
        if self.par[x] == x:
            return x
        else:
            self.par[x]=self.find(self.par[x])
            return self.par[x]
        
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x]+=self.size[y]
            
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def tree_size(self,x):
        return self.size[self.find(x)]
    
def main():
    n,m = map(int, input().split())
    uf = UnionFind(n)
    for i in range(m):
        x, y, z = map(int, input().split())
        x -= 1
        y -= 1
        if not uf.same(x,y):
            uf.union(x,y)
    res = 0
    for i in range(n):
        if uf.par[i] == i:
            res += 1
    print(res)

if __name__ == '__main__':
    main()
t = input()

stack = ''
for s in t:
    if s == '?':
        if stack[-1] == 'P':
            s = 'D'
        else:
            s = 'P'

    stack += s
print(stack)


### FIXED CODE ###

t = input()

stack = ''
for i in range(len(t)):
    word = t[i]
    if word == '?':
        next_word = t[i+1] if i < len(t)-1 else None
        if next_word is None:
            word = 'D'
        else:
            if len(stack) <= 0 and next_word == 'P':
                word = 'D'
            elif len(stack) <= 0 and (next_word == 'D' or next_word == '?'):
                word = 'P'
            elif stack[-1] == 'D' and (next_word == '?' or next_word == 'D'):
                word = 'P'
            else:
                word = 'D'

    stack += word
print(stack)
n, m, k = map(int, input().split())

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

time = 0
count = 0
i = 0
j = 0
for _ in range(n + m):
    if a[i] < b[j]:
        time += a[i]
        i +=1
    elif a[i] > b[j]:
        time += b[j]
        j +=1
    else:
        time += a[i]
        if a[i + 1] < b[j+1]:
            i += 1
        else:
            j += 1
    if time > k:
        break
    else:
        count += 1
print(count)

### FIXED CODE ###

n, m, k = map(int, input().split())

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

a, b = [0], [0]
for  i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i] + B[i])

ans, j = 0, 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)
# from collections import deque
# from collections import defaultdict
# import itertools
# import math
import numpy as np
# from scipy.special import comb
# import heapq


def main():
    N, W = map(int, input().split())
    v = [0] * (N + 1)
    w = [0] * (N + 1)

    for i in range(1, N + 1):
        v[i], w[i] = map(int, input().split())

    values = [[0 for _ in range(W + 1)] for _ in range(N + 1)]

    for i in range(0, N + 1):
        for j in range(0, W + 1):
            non_choice = values[i - 1][j]
            if j >= w[i]:
                choice = values[i - 1][j - w[i]] + v[i]
            else:
                choice = 0
            values[i][j] = max(choice, non_choice)

    print(np.max(np.array(values)))


if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import deque

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

links = [[] for _ in range(N + 1)]

for _ in range(M):
    A, B = map(int, input().split())
    links[A].append(B)
    links[B].append(A)

dist = [-1] * (N + 1)
michi = [-1] * (N + 1)
dist[1] = 0
q = deque([1])

while q:
    now = q.popleft()
    for i in links[now]:
        if dist[i] == -1:
            dist[i] = dist[now] + 1
            michi[i] = now
            q.append(i)

print('Yes')
for i in range(2, N + 1):
    print(michi[i])
s=input()
k=int(input())
d = dict()
for i in range(len(alphabet)):
    d[alphabet[i]]=i
    
def f(s,k):
    s = [s[i] for i in range(len(s))]
    res = s
    L = 0
    for i in range(len(s)):
        l = max(26 - d[s[i]],0)
        if L + l < k:
            res[i] = "a"
            L += l
        else:
            if i==len(s)-1:
                res[i] = alphabet[(d[s[i]] + (k-L)) % 26]
            continue
    return(''.join(res))
f(s,k)

### FIXED CODE ###

s=input()
k=int(input())
d = dict()
alphabet = "abcdefghijklmnopqrstuvwxyz"
for i in range(len(alphabet)):
    d[alphabet[i]]=i
    
def f(s,k):
    s = [s[i] for i in range(len(s))]
    res = s
    L = 0
    for i in range(len(s)):
        l = max((26 - d[s[i]]) % 26, 0)
        if i==len(s)-1:
            res[i] = alphabet[(d[s[i]] + (k-L)) % 26]
        else:
            if L + l <= k:
                res[i] = "a"
                L += l
            else:
                continue
    return(''.join(res))
print(f(s,k))
a = int(input())
b = int(input())

print(a*b,(a+b)*2)

### FIXED CODE ###

a,b=map(int,input().split())
print(a*b,(a+b)*2)
import math

a,b,k=map(int,input().split())
l=[]
g=math.gcd(a,b)
q=g
i=1

if a==1 and b==1:
  print(1)
else:
  for i in range(1,int(g/2)+1):
   
    if q%i==0:
      if int(g/i)==i:
        l.append(i)
      else:
        l.append(int(g/i))
        l.append(i)
  l.sort()
  l=set(l)
  l=list(l)
  print(l[(-1)*k])


### FIXED CODE ###

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

a,b,k=map(int,input().split())
l=[]
g=gcd(a,b)

if a==1 and b==1:
  print(1)
else:
  for i in range(1,g):
    if g%i==0:
      l.append(i)
  l.append(g)
  print(l[(-1)*k])
# coding: utf-8
# Your code here!
import math
from functools import reduce

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

if max(l)<K:
    print("IMPOSSIBLE")
else:
    if K%functools.reduce(math.gcd, l)==0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

### FIXED CODE ###

# coding: utf-8
# Your code here!
from fractions import gcd
from functools import reduce

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

if max(l)<K:
    print("IMPOSSIBLE")
else:
    if K%reduce(gcd, l)==0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
S=list(str(input()))
N=len(S)

N1=int((N-1)/2)
N2=int((N+3)/2-1)

S1=list(S[:N1])
S2=list(S[N2:])


S3=list(reversed(S1))
S4=list(reversed(S2))
Sr=list(reversed(S))

if S==Sr:
    if S1==S3:
        if S2==S4:
            print("Yes")
            sys.exit()
print("No")


### FIXED CODE ###

import sys

S=list(str(input()))
N=len(S)

N1=int((N-1)/2)
N2=int((N+3)/2-1)

S1=list(S[:N1])
S2=list(S[N2:])


S3=list(reversed(S1))
S4=list(reversed(S2))
Sr=list(reversed(S))

if S==Sr:
    if S1==S3:
        if S2==S4:
            print("Yes")
            sys.exit()
print("No")
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
suf = 0
for i in range (n):
  suf += b[a[i]]
  if (i != n - 1 )and(a[i]  + 1 == a[i+1]):
    suf += c[a[i]]
print(suf)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
suf = 0
for i in range (n):
  suf += b[i]
  if i >= 1 and a[i - 1]  + 1 == a[i]:
    suf += c[a[i - 1] - 1]
print(suf)
from itertools import accumulate
n,c = map(int,input().split())
wv = [[0,0]]+[list(map(int,input().split())) for i in range(n)]+[[c,0]]
n += 2
ansls = []
for i in range(n):
  if wv[i][0] > c//2:
    spr = i
    break
for sp in spr-1,spr:
  ls = [0]*n
  lsx = [0]*n
  for i in range(1,sp):
    w,v = wv[i]
    w -= wv[i-1][0]
    ls[i] = v-w*2
    lsx[i] = v-w
  for i in range(n-2,sp-1,-1):
    w,v = wv[i]
    w -= wv[i+1][0]
    ls[i] = v+w*2
    lsx[i] = v+w
  alsf = list(accumulate(ls[:sp]))
  alsl = list(accumulate(ls[sp:][::-1]))
  alsxf = list(accumulate(lsx[:sp]))
  alsxl = list(accumulate(lsx[sp:][::-1]))
  ansls.append(max(alsf)+max(alsxl))
  ansls.append(max(alsl)+max(alsxf))
print(max(ansls))

### FIXED CODE ###

from itertools import accumulate
n,c = map(int,input().split())
wv = [[0,0]]+[list(map(int,input().split())) for i in range(n)]+[[c,0]]
n += 2
ansls = []
ls1 = [0]*n
ls2 = [0]*n
ls3 = [0]*n
ls4 = [0]*n
for i in range(1,n):
  w,v = wv[i]
  w -= wv[i-1][0]
  ls1[i] = v-w*2
  ls2[i] = v-w
for i in range(n-2,-1,-1):
  w,v = wv[i]
  w -= wv[i+1][0]
  ls3[n-i-1] = v+w*2
  ls4[n-i-1] = v+w
als1 = list(accumulate(ls1))
als2 = list(accumulate(ls2))
als3 = list(accumulate(ls3))
als4 = list(accumulate(ls4))
als1 = list(accumulate(als1,max))
als2 = list(accumulate(als2,max))
als3 = list(accumulate(als3,max))
als4 = list(accumulate(als4,max))
for i in range(n-1):
  ansls.append(als1[i]+als4[n-2-i])
  ansls.append(als2[i]+als3[n-2-i])
print(max(ansls))
#!/usr/bin
# -*- coding="utf-8" -*-

c1 = []
c2 = []
q = input().split()
n = [input() for i in range(q[1])]
for j in range(n):
  m = j.split()
  if m[0] == "1":
    c1.append(m[1])
  if m[1] == q[0]:
    c2.append(m[0])
for l in len(c2):
  if c1[l] in c2:
    print("POSSIBLE")
    break
print("INPOSSIBLE")

### FIXED CODE ###

#!/usr/bin
# -*- coding="utf-8" -*-
c1 = []
c2 = []
q = input().split()
n = [input().split() for i in range(int(q[1]))]
 
for m in n:
  if m[0] == "1":
    c1.append(m[1])
  if m[1] == q[0]:
    c2.append(m[0])
if set(c1) & set(c2):
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")
import bisect
I=lambda:map(int,input().split())
N,Q=I()
S=input()
L=[0]*Q
R=[0]*Q
for i in range(Q):
    L[i],R[i] = I()
m=[]
for i in range(N-1):
    if S[i]=='A' and S[i+1]=='C':
        m += [i]
#print(m)
for i in range(Q):
    l=L[i]
    r=R[i]
    li=bisect.bisect_left(m,l-1)
    ri=bisect.bisect_left(m,r-1)
    #print(i,li,ri)
    print(ri-li-1 if m[ri-1]==r else ri-li)


### FIXED CODE ###

ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

N,Q=rl()
S=input()
L,R=[0]*Q,[0]*Q
for i in range(Q):
    L[i],R[i] = rl()
s = [0]*(N+2)
ss = [0]*(N+2)
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        s[i] = 1
        s[i+1] = 1

ss[0] = s[0]
for i in range(1,N):
    ss[i] = ss[i-1] + s[i]

for i in range(Q):
    l,r = L[i],R[i]
    l -= 1
    r -= 1
    res = (ss[r] - ss[l-1])//2
    if s[r]==1 and s[l]==1 and S[r]=='A' and S[l]=='C':
        res -= 1
    print(res)
from collections import deque

def fast_bellman_ford(n, s, graph, edge_n, init_val): #どう？
    d = [init_val] * n
    d[s] = 0
    q = deque([s])
    checker = [-1] * n
    for i in range(n):
        m = len(q)
        for _ in range(m):
            vf = q.popleft()
            for vt, w in graph[vf]:
                if d[vt] > d[vf] + w:
                    d[vt] = d[vf] + w
                    if checker[vt] < i:
                        q.append(vt)
                        checker[vt] = i
        if not q:
            break
    if q: #閉路の存在
        minus_inf = -float('inf')
        i += 1
        while q:
            m = q.count
            for _ in range(m):
                vf = q.popleft()
                for vt, w in graph[vf]:
                    if d[vt] > d[vf] + w:
                        d[vt] = minus_inf
                        if checker[vt] < i:
                            q.append(vt)
                            checker[vt] = i
            i += 1
    return d

n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(m):
    a, b, w = map(int, input().split())
    graph[a-1].append((b-1, -w))
d = fast_bellman_ford(n, 0, graph, 2 * m, float('inf'))
print(-d[-1] if d[-1] != -float('inf') else 'inf')






### FIXED CODE ###

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

edges = []
for i in range(m):
    a, b, w = map(int, input().split())
    edges.append((a-1, b-1, w))

init_val = -10 ** 9 * 1000
d = [init_val] * n
d[0] = 0
for _ in range(n):
    updated = False
    for a, b, w in edges:
        if d[a] != init_val and d[b] < d[a] + w:
            d[b] = d[a] + w
            updated = True
    if not updated:
        break
if updated: #閉路の存在
     for a, b, w in edges:
        if d[a] != init_val and d[b] < d[a] + w:
            d[b] = d[a] + w
            if b == n - 1:
                print('inf')
                quit()
print(d[n-1])
def main():
    n, m = map(int, input().split())
    sc = [list(map(int, input().split())) for _ in range(m)]
    
    sc = sorted(sc)
    ans = ''
    pre_s =  -1
    pre_c = sc[0][1]
    for s, c  in sc:
        if pre_s == s and pre_c == c:
            continue
        if (s == 1 and c == 0) or (pre_s == s and pre_c != c):
            print('-1')
            return
        if pre_s == -1 and s != 1:
            ans += str(1)
            pre_s += 2
        i = s - pre_s - 1
        ans += str(0) * i
        ans += str(c)
        pre_s = s
        pre_c = c
    ans += str(0) * (n - pre_s)
        
    print(int(ans))
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    n, m = map(int, input().split())
    sc = [list(map(int, input().split())) for _ in range(m)]
    
    ans = [-1]* n
    for s, c in sc:
        s -= 1 
        if ans[s] == -1or ans[s] == c:
            ans[s] = c
        else:
            print(-1)
            return
        
    if ans[0] == -1 and n >1:
        ans[0] = 1
    elif ans[0] == 0:
        if n == 1:
            print(0)
        else:
            print(-1)
        return
    
    print(''.join(list(map(str, ans))).replace('-1', '0'))
    
if __name__ == '__main__':
    main()
#!/bin/usr/python

n = input()

s = [0 for i in range(100)]
a = 0

for i in range(n):
  s[i] = input()
  a += s[i]

flag = True
if a % 10 == 0:
  s = sorted(s)
  for i in range(n):
    if s[-1*n + i] % 10 != 0:
      a -= s[-1*n + i]
      break

if a % 10 == 0:
  a = 0

print(a)

### FIXED CODE ###

#!/bin/usr/python

n = input()

s = [0 for i in range(100)]
a = 0

for i in range(n):
  s[i] = input()
  a += s[i]

flag = True
if a % 10 == 0:
  s = sorted(s)
  for i in range(n):
    if s[-1*n + i] % 10 != 0:
      a -= s[-1*n + i]
      break

if a % 10 == 0:
  a = 0

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

s = int(input())

a = 0
t = []

while s > 0:
    d = s // 10
    r = s % 10
    t.append(r)
    s = d

if p == 2:
    for i in range(len(t)):
        if t[i] % 2 == 0:
            a += len(t) - i 
elif p == 5:
        if t[i] % 5 == 0:
            a += len(t) - i 

else:
    u = []
    k = 1
    for i in range(len(t)):
        u.append(t[i]*k % p)
        k *= 10

    for i in range(len(u)):
        for j in range(i, len(u)):
            if sum(u[i:j+1]) % p == 0:
                a += 1

print(a)




### FIXED CODE ###

from collections import Counter

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

s = input()


a = 0
t = list(map(int, list(s)))
t.reverse()


if p == 2:
    for i in range(n):
        if t[i] % 2 == 0:
            a += len(t) - i 
elif p == 5:
    for i in range(n):
        if t[i] % 5 == 0:
            a += len(t) - i 

else:
    u = []
    k = 1
    l = 0
    for i in t:
        l = (l + i*k) % p
        u.append(l)
        k = k * 10 % p

    c = Counter(u)
    a += c[0]
    for i in c.values():
        if i > 1:
            a += i * (i-1) // 2


print(a)
import sys
input = sys.stdin.readline

n,m = (int(x) for x in input().split())
a = list(map(int, input().split()))

b = [0]*(n**2)
idx = 0

for i in range(n):
	for j in range(n):
		b[i*n+j] = a[i]+a[j]

b.sort(reverse=True)

print(sum(b[:m]))

### FIXED CODE ###

import sys
input = sys.stdin.readline
# 昇順ソートされた配列の挿入位置indexを返す O(logN)
from bisect import bisect_left

def isOver(a,n,x):
	cnt = 0
	for i in range(n):
		cnt += n-bisect_left(a,x-a[i])
	return cnt

def calX(a,n,m,l,r):
	while r-l>1:
		# x: 握手で得たい最低パワー値
		x = (l+r)//2
		if isOver(a,n,x) >= m:
			l = x
		else: #握手する限界回数すら満たせないほど大きいxなら
			r = x 
	return l

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

#累積和の下準備
a.sort()
s = [0]*(n+1)
for i in range(n):
	s[i+1] = s[i]+a[i]

x = calX(a,n,m,a[0]*2,a[n-1]*2)

out = 0
for i in range(n):
	idx = bisect_left(a,x-a[i])
	out += s[n]-s[idx]+a[i]*(n-idx)

out -= (isOver(a,n,x)-m)*x

print(out)
n = int(input())
h = list(map(int, input().split()))

ans = [0] * (n-1)

for i in range(n-1):
    for j in range(i,n-1):
        if h[j] >= h[j+1]:
            ans[i] += 1
        else:
            break           

print(max(ans))

### FIXED CODE ###

n = int(input())
h = list(map(int, input().split()))
t = 0
result = 0
for i in range(n - 1):
  if h[i + 1] <= h[i]:
    t += 1
  else:
    result = max(t, result)
    t = 0
result = max(t, result)
print(result)
import sys
input = sys.stdin.readline
N=int(input())
strings=list("".join(sorted(input())) for _ in range(N))
string_set = set()
counts = {}
count = 0
for string in strings:
    if string in string_set:
        count += counts[string]
        counts[string] += 1
    else:
        counts[string] = 1

print(count)

### FIXED CODE ###

A,B = map(int,input().split())
print(max(A+B,A-B,A*B))
# coding: utf-8
W, H, N = map(int, input().split())
min_x, max_x = 0, W
min_y, max_y = 0, H

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if max_x <= x:
            min_x, max_x = 0, 0
        elif min_x <= x:
            min_x = x
    elif a == 2:
        if min_x >= x:
            min_x, max_x = 0, 0
        elif x <= max_x:
            max_x = x
    elif a == 3:
        if max_y <= y:
            min_y, max_y = 0, 0
        elif min_y <= y:
            min_y = y
    else:
        if y <= min_y:
            min_y, max_y = 0, 0
        elif y <= max_y:
            max_y = T
diff_x = max_x - min_x
diff_y = max_y - min_y
print(diff_x * diff_y)


### FIXED CODE ###

# coding: utf-8
W, H, N = map(int, input().split())
min_x, max_x = 0, W
min_y, max_y = 0, H

for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if max_x <= x:
            min_x, max_x = 0, 0
        elif min_x <= x:
            min_x = x
    elif a == 2:
        if min_x >= x:
            min_x, max_x = 0, 0
        elif x <= max_x:
            max_x = x
    elif a == 3:
        if max_y <= y:
            min_y, max_y = 0, 0
        elif min_y <= y:
            min_y = y
    else:
        if y <= min_y:
            min_y, max_y = 0, 0
        elif y <= max_y:
            max_y = y
diff_x = max_x - min_x
diff_y = max_y - min_y
print(diff_x * diff_y)
N, M = map(int, input().split())
a = [0]*N
for i in range(M):
    s, c = map(int, input().split())
    if a[s-1] =! 0:
        a[s-1] = min(c, a[s-1])
if M == 0:
    if N == 1:
        print(0)
    elif N == 2:
        print(10)
    else:
        print(100)
else:
    if a[0] != 0:
        print(*a, sep="") 
    else:
        print("-1")

### FIXED CODE ###

N, M = map(int, input().split())
A=[]
for j in range(M):
    s, c = map(int, input().split())
    A.append([s-1, str(c)])
if N == 1:
    b = 0
elif N == 2:
    b= 10
else:
    b = 100
ans=[]
for i in range(b, 1000):
    a = 0
    for j in range(M):
        x=str(i)
        if len(x) < N:
            break 
        if A[j][1] == x[A[j][0]]:
            a += 1
    if a == M:
        ans.append(i)
if ans == []:
    print(-1)
else:
    print(min(ans))
n = int(input())
print('Yes' if n[0] == n[2] else 'No')


### FIXED CODE ###

n = input()
print('Yes' if n[0] == n[-1] else 'No')
s, w = list(map(int, input().split(" ")))
if s >= w:
  print("unsafe")
else:
  print("safe)

### FIXED CODE ###

s, w = list(map(int, input().split(" ")))
if s <= w:
  print("unsafe")
else:
  print("safe")
a,b=map(int,input().split())

n=1
while (a-1)n+1 <= b:
  n+=1
  
print(n)


### FIXED CODE ###

a,b=map(int,input().split())
 
n=0
while (a-1)*n+1 < b:
  n+=1
  
print(n)
if __name__=="__main__":
    s,t=input.split()
    print(t+s)

### FIXED CODE ###

if __name__=="__main__":
    s,t=input().split()
    print(t+s)
s = input()
k = (int)(input())

if k <= 5000000000000000:
  for n in s:
    if k == 0:
      print(n)
    elif n == '1':
      k = k-1
    else:
      print(n)

else:
  for n in s:
    if n == '1':
      k = k-1
    elif n == '2':
      if k >= 2ae0i0:
      else:
        print(n)
    else:
    print(n)


### FIXED CODE ###

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

c = 0
for ch in s:
  if not ch == '1':
    break
  c += 1
n = s[c] if c < len(s) else None
a = n if n and c < k else s[0]
print(a)