peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
S = input()
count = 0
try:
    for i in range(0, len(S) - 3):
        if len(S[i:]) <= 4:
            break
        for l in range(i + 3, len(S)):
            if int(S[i]) == 0:
                continue
            elif int(S[i:l]) % 2019 == 0:
                count += 1
except IndexError:
    pass
print(count)
# Judge status: Accepted
N=int(input())
a=list(map(int,input().split()))
#a=[i+1 for i in range(3*N)]
a.sort(reverse=True)
c=0
for i in range(N):
    c=c+a[2*i+1]
print(c)
# Judge status: Accepted
S = input()
S = S.replace('eraser', ' ').replace('erase', ' ').replace('dreamer', ' ').replace('dream', ' ').replace(' ', '')
if S == '':
    print('YES')
else:
    print('NO')
# Judge status: Wrong Answer
n,bl,re = map(int,input().split())
ans = 0
while n > 0:
  n = n - bl -re
  ans += bl
if bl == 0 or n < 0:
  print(round(ans))
elif bl >= n:
  ans = ans + n
  print(round(ans))
# Judge status: Accepted
N = input()

print(str(int(N[0]) + 1) * 3 if int(N[0] * 3) < int(N) else N[0] * 3)
# Judge status: Wrong Answer
A, B, C, D = map(int, input().split())
S = A*B//2
if A%2==1 and B%2==1:
  S += 0.5

ans = 0
if C == A//2 and D == B//2:
  ans = 1
print(S,ans)
# Judge status: Accepted
x = int(input())

if x % 11 == 0:
    ans = x//11 * 2
elif x % 11 > 6:
    ans = x//11 * 2 + 2
else:
    ans = x//11 * 2 + 1
print(ans)
# Judge status: Accepted
n=int(input())
l=list(map(int,input().split()))

l.sort(reverse=True)
if l[0]<sum(l)-l[0]:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
import bisect

N = int(input())
INF = (10**5)+1
A = {}
for i in range(N):
    a = int(input())
    A[i] = a

B = [A[N-1]]
for i in range(N-2,-1,-1):
    a = A[i]
    if B[-1] <= a:
        B.append(a)
    else:
        B[bisect.bisect_left(B,a)] = a



print(len(B))
# Judge status: Accepted
n = int(input())
S = list(int(input()) for _ in range(n))

cnt = 0
res = 0
t = []
for i in range(n):
    if S[i] % 10 == 0:
        cnt += 1
    else:
        t.append(S[i])
    res += S[i]

if cnt == n:
    print(0)
else:
    if res % 10 != 0:
        print(res)
    else:
        print(res - min(t))
# Judge status: Wrong Answer
l = list(map(int,input().split()))
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]
if a >= l or b >= l:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
# A
S = input()
T = input()
ans = 'No'
if S == T[:-1]:
    ans = 'Yes'
print(ans)
# Judge status: Wrong Answer
s = input()
n = len(s)
n //= 2
ans = 0
for i in range(n):
    if not s[i] == s[n-i-1]:
        ans += 1

print(ans)
# Judge status: Wrong Answer
a=list(input())
for i in range(4):
  a[i]=int(a[i])
x=sum(a)-7
dict={0:'+',1:'-'}
for i in range(2):
  for j in range(2):
    for k in range(2):
        if x==(i*a[1]+j*a[2]+k*a[3])*2:
          print(a[0],dict[i],a[1],dict[j],a[2],dict[k],a[3],'=7',sep='')
          break
# Judge status: Accepted
al = list(map(int, input().split()))

print(al[2], al[0], al[1])
# Judge status: Accepted
#create date: 2020-05-02 21:18

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    a, b, n = na()
    x = min(n, b - 1)
    ans = a * x // b - a * ( x // b)
    print(ans)

if __name__ == "__main__":
    main()
# Judge status: Accepted
N = int(input())
#6
B = [int(i) for i in input().split()]
# 153 10 10 23

A = [0]*N

A[0] = B[0]
A[N-1] = B[N-2]

for i in range(1,N-1):
	A[i] = min(B[i],B[i-1])

print(sum(A))
# Judge status: Wrong Answer
a,b,c,d = list(map(int,input().split()));

if a//d < c//b :
    print('Yes');
else :
    print('No');
# Judge status: Accepted
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    r = A[0]
    for i in range(1, N//2):
        r += 2 * A[i]
    if N % 2 == 1:
        r += A[N//2]
    return r
print(main())
# Judge status: Accepted
import sys
A, B, C = map(int, input().split())
N = A
while N < A * B:
    if N % B == C:
        print('YES')
        sys.exit()
    N += A
print('NO')
# Judge status: Accepted
s = input()
t = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i in t:
    if s == i:
        print("A")
        break
else:
    print("a")
# Judge status: Accepted
s = input()

while len(s) > 2:
    s = s[:-2]
    n = len(s) // 2
    if s[:n] == s[n:]:
        print(len(s))
        exit(0)
print(1)
# Judge status: Accepted
import itertools
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(Q)]
ans = 0
for A in itertools.combinations_with_replacement(range(1, M+1), N):
  score = []
  for i in range(Q):
    a = abcd[i][0]
    b = abcd[i][1]
    c = abcd[i][2]
    d = abcd[i][3]
    if A[b-1]-A[a-1] == c:
      score.append(d)
  ans = max(ans,sum(score))
print(ans)
# Judge status: Wrong Answer
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 0

    for i in range(N - 1):
        diff = A[i] - A[i - 1]
        if diff > 0:
            ans += diff
    print(ans)


if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
n=int(input())

judge_list=[]
for i in range(n):
    a=input()
    judge_list.append(a)
    
ac=judge_list.count('AC')
ac=str(ac)
wa=judge_list.count('WA')
wa=str(wa)
tle=judge_list.count('TLE')
tle=str(tle)
re=judge_list.count('RE')
re=str(re)

print("AC"+" "+"×"+" "+ac)
print("WA"+" "+"×"+" "+wa)
print("TLE"+" "+"×"+" "+tle)
print("RE"+" "+"×"+" "+re)
# Judge status: Wrong Answer
from random import randint
#整数a,bをそれぞれ定義
a =randint(0, 10000)
b =randint(0, 10000)
#整数a,bの積を定義
P = (a * b)
#for文による倍数判定
if P % 2 == 0:
  print("Even")
else: print("Odd")
# Judge status: Wrong Answer
n = int(input())
s = list(input())

l = [0]*n
l[n-1] = s[:n-1].count('W')
for i in range(n-1):
  w_side = s[:i].count('W')
  e_side = s[i+1:].count('E')
  l[i] = w_side + e_side
  
print(l,min(l))
# Judge status: Accepted
n, m, k = map(int, input().split())

for row in range(n+1):
    for col in range(m+1):
        if row * m + col * n - 2 * (row * col) == k:
            print('Yes')
            exit()

print('No')
# Judge status: Wrong Answer
N, K = map(int, input().split())
S = input()

happy = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        happy += 1

m = 0
for i in range(1, N-1):
    if S[i] == 'R' and S[i+1] == 'L':
        m += 1

if K <= m:
    happy += 2*K
else:
    happy += 2*m + 1
print(happy)
# Judge status: Wrong Answer
n = int(input())
h = list(map(int, input().split()))

ans = 'Yes'
is_e = False
i = 0
while i < n-1:
    if h[i+1] == h[i]:
        is_e = True
    elif h[i+1] > h[i]:
        is_e = False
    elif h[i+1] == h[i]-1 and is_e is False:
        is_e = True
    else:
        ans = 'No'
        break
    i += 1
print(ans)
# Judge status: Accepted
#wakaran!
n = int(input())
ans = 0
for i in range(1, n+1):
  ans += int(len(str(i)) % 2 != 0)
print(ans)
# Judge status: Accepted
a = input()
a = int(a)

if a == 7 or a == 5 or a == 3:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
n = int(input())
v = list(map(int, input().split()))
v_new = sorted(v)
while len(v_new) > 1:
    s = [(v_new[0] + v_new[1]) / 2]
    v_new = s + v_new[2:]
print(sum(v_new))
# Judge status: Accepted
n=int(input())
nm=[0]*(n+1)

for i in range(1,n+1):
    for j in range(1,n+1):
        if i%j==0:
            nm[i]+=1
l=[1 for i in range(1,n+1) if nm[i]==8 and i%2]
print(sum(l))
# Judge status: Accepted
n=int(input())
A=list(map(int,input().split()))
q=int(input())
coun=[0]*10**5
A_=sum(A)
for i in A:
  coun[i-1]+=1
for _ in range(q):
  b,c=map(int,input().split())
  A_+=(c-b)*coun[b-1]
  coun[c-1]+=coun[b-1]
  coun[b-1]=0
  print(A_)
# Judge status: Wrong Answer
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
  b.append(0)
k = 0
if(n%2==1):
  k = (n-1)//2
else:
  k = n//2
for i in range(n):
  if(i%2==0):
    b[k+i//2]=a[i]
  else:
    b[k-(i+1)//2]=a[i]
ans = ""
for i in range(n):
  ans += str(b[i])+" "
print(ans)
# Judge status: Accepted
n = int(input())
h = list(map(int, input().split()))
ans ='Yes'
mah = 0
for i in h:
    mah = max(i, mah)
    if i < mah - 1:
        ans = 'No'
        break
print(ans)
# Judge status: Accepted
#!/usr/bin/env python3
import math

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

index = a.index(1)

pre = index
post = n-index-1

ans = 10**10
for i in range(0, k):
    ans_tmp = 0
    pre_tmp = max(0, pre-i)
    post_tmp = max(0, post-(k-1-i))
    ans_tmp += math.ceil(pre_tmp/(k-1))
    ans_tmp += math.ceil(post_tmp/(k-1))
    ans = min(ans, ans_tmp)
    # print(pre_tmp, post_tmp, ans)

print(ans+1)
# Judge status: Accepted
N,K=map(int,input().split())
A=[~-int(x) for x in input().split()]

p,c=[-1]*N,0
for i in range(N+1):
  if p[c]==-1:
    p[c]=i
    c=A[c]
  else:
    break

print(1+p.index(p[c]+(K-p[c])%(i-p[c]) if K>=p[c] else K))
# Judge status: Wrong Answer
n = int(input())
l = list(map(int, input().split()))

res = 0
for i in range(n-1):
	if l[i+1] < l[i]:
		res += 1

print(res+1)
# Judge status: Wrong Answer
N=int(input())
c=-1
for i in range(N):
  i=str(i)
  for j in range(N):
    j=str(j)
    if i[0]==j[-1] and i[-1]==j[0]:
      c+=1
print(c)
# Judge status: Accepted
n = int(input())
p_li = list(map(int,input().split()))
dum = 0
ans = 0
flag = 0
count = 0
for i in range(n):
    if i+1 == p_li[i]:
        ans += 1
        if flag == 1:
            if dum == i-1:
                count += 1
                flag = 0
        else:
            flag = 1
        dum = i

#div,mod = divmod(dum,2)
print(ans-count)
# Judge status: Accepted
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def input():
    return sys.stdin.readline()


def resolve():
    s = input().rstrip()

    if s == "ABC":
        print("ARC")
    else:
        print("ABC")


if __name__ == "__main__":
    resolve()
# Judge status: Accepted
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from fractions import gcd
from functools import reduce

N,*A = map(int,read().split())

MOD = 10 ** 9 + 7

lcm = reduce(lambda x,y: y//gcd(x,y)*x, A)

answer = sum(lcm//x for x in A)
answer %= MOD
print(answer)
# Judge status: Wrong Answer
a,b,c=map(int,input().split())
if a==b and a==c:
    ans=-1
for i in range(1,100000):
    x=a//2
    y=b//2
    z=c//2
    a=y+z
    b=x+z
    c=x+y
    print("{}-{}-{}".format(a,b,c))
    if a%2==1 or b%2==1 or c%2==1:
        ans=i
        break
print(ans)
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))

AA = [0] * (N)
for i in range(N):
    AA[i] = list(format(A[i], 'b'))

ans = [0] * 42
for i in range(N):
    AA[i].reverse()
    for j in range(len(AA[i])):
        ans[j] += int(AA[i][j])

ret = []
for i in range(N):
    temp = 0
    for j in range(len(AA[i])):
        if (ans[j] + int(AA[i][j])) & 1 == 1:
            temp += 1 << j

    ret.append(temp)

print(*ret)
# Judge status: Accepted
N, M, Q = map(int, input().split())

ABCD = [list(map(int, input().split())) for i in range(Q)]

import itertools

max_point = 0
for i in itertools.combinations_with_replacement(range(1, M+1), N):
    # print(i)
    point = 0
    for abcd in ABCD:
        if i[abcd[1]-1] - i[abcd[0]-1] == abcd[2]:
            point += abcd[3]
    max_point = max(max_point, point)
print(max_point)
# Judge status: Accepted
INF = int(10e20)


def main():
    N, K = tuple([int(_x) for _x in input().split()])

    minval = N
    sub = N // K - 5
    if sub > 0:
        N = N - K * sub

    for i in range(20):
        N = abs(N - K)
        minval = min(N, minval)

    print(minval)


main()
# Judge status: Wrong Answer
X = list(map(int,input()))
sn = []
for i in range(len(X)):
  sn.append(sum(X[0:i+1]))
ssn = []
for i in range(len(X)):
  ssn.append(sn[i]-1 + 9*(len(X)-1-i))
print(max(ssn))
# Judge status: Wrong Answer
import sys
input = sys.stdin.buffer.readline

from itertools import product

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

ABCD = [list(map(int, input().split())) for _ in range(q)]

kumiawase = list(product(range(1, m + 1), repeat=n))

ans = 0
for kumi in kumiawase:
    A = [0] + list(kumi)
    temp = 0
    for abcd in ABCD:
        a, b, c, d = abcd
        if A[b] - A[a] == c:
            temp += d
    ans = max(ans, temp)

print(ans)
# Judge status: Accepted

n = int(input())
x = int(n / 1.08)

if int(x * 1.08) == n:
    print(x)
elif int((x-1) * 1.08) == n:
    print(x-1)
elif int((x+1) * 1.08) == n:
    print(x+1)
else:
    print(":(")
# Judge status: Accepted
n = int(input())
if (n%2 == 0):
    print(0.5)
else:
    print((n//2+1)/n)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))

ans = [0] * N
for i in range(N)[:: -1]:
    a = A[i]
    cnt = 0
    for j in range(i, N, (i + 1)):
        cnt += ans[j]
    if cnt % 2 != a % 2:
        ans[i] = 1

M = sum(ans)
print(M)
if M > 0:
    print(*[i for i, a in enumerate(ans, start=1) if a > 0])
# Judge status: Accepted
import numpy as np
def main():
    N, M = map(int, input().split())
    maxl = -float('inf')
    minr = float('inf')
    for _ in range(M):
        l, r = map(int, input().split())
        if l >= maxl:
            maxl = l
        if r <= minr:
            minr = r
    val = minr - maxl + 1
    if val >= 0:
        print(val)
    else:
        print(0)
main()
# Judge status: Wrong Answer
n, t = map(int, input().split())
c = 999
for i in range(n):
    tmp = input().split()
    if int(tmp[1]) > t:
        pass
    elif int(tmp[1]) <= t:
        if int(tmp[0]) < int(c):
            c = tmp[0]
    else:
        pass
if i == n-1 and c == 999:
    print('TLE')
    exit()
else:
    print(c)
# Judge status: Accepted
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a = [int(input()) for _ in range(5)]
    b = [(x + 9) // 10 * 10 for x in a]

    ans = INF
    for i in range(5):
        ans = min(ans,sum(b) - b[i] + a[i])

    print(ans)


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
s = input()
s_modified = s.replace('7','8')
print(s_modified)
# Judge status: Accepted
a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
print((a-c)//(b+c))
# Judge status: Accepted
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7

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


def lcm(a, b):
    return a * b // gcd(a, b)


def resolve():
    n = int(input())
    T = list(int(input()) for _ in range(n))

    res = 1
    for i in range(n):
        res = lcm(res, T[i])

    print(res)


if __name__ == '__main__':
    resolve()
# Judge status: Accepted
def How_many_times_devide(n):
    count = 0
    while n %2 == 0:
        n/= 2
        count += 1

    return count

N = int(input())
num_max = 1
count_max = 0
for i in range(1,N+1):
    count = How_many_times_devide(i)
    if count_max < count:
        count_max = count
        num_max = i

print(num_max)
# Judge status: Accepted
k = int(input())
a, b = map(int, input().split())

list_ab = [i for i in range(a,b+1)]
ans = 'NG'

for j in range(len(list_ab)):
  if list_ab[j] % k ==0:
    ans = 'OK'
    break

print(ans)
# Judge status: Accepted
n,m,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
ca=[0]*(n+1)
ca[1]=a[0]
for i in range(n):
  ca[i+1]=ca[i]+a[i]
cb=[0]*(m+1)
cb[1]=b[0]
for i in range(m):
  cb[i+1]=cb[i]+b[i]
j=m
ans=0
for i in range(n+1):
  t=ca[i]
  while j>=0:
    if t+cb[j]>k:
      j-=1
    else:
      ans=max(ans,i+j)
      break
print(ans)
# Judge status: Wrong Answer
num = int(input())
stn = list(input())
num_W = stn.count('W')
num_R = stn.count('R')
cnt = 0

if num_W >= num_R:
    for i in range(num_R):
        if stn[i] == "W":
            cnt += 1

else:
    for i in range(num_W):
        if stn[-i] == "R":
            cnt += 1

print(cnt)
# Judge status: Accepted
k, x = map(int, input().split())
print(['No','Yes'][k * 500 >= x])
# Judge status: Accepted
from collections import deque
n = int(input())
a = list(map(int, input().split()))
b = deque()
for i in range(n):
    if i % 2 == n % 2:
        b.append(a[i])
    else:
        b.appendleft(a[i])

print(*list(b))
# Judge status: Accepted
#!/usr/bin/env python3
def main():
    import sys
    import numpy as np

    read = sys.stdin.read

    N, W = map(int, input().split())
    products = map(int, read().split())

    dp = np.zeros(W + 1, dtype=np.int64)
    for can_w, can_v in zip(products, products):
        dp[can_w:] = np.maximum(dp[can_w:], dp[:-can_w] + can_v)

    print(dp[-1])


if __name__ == '__main__':
    main()
# Judge status: Accepted
n = int(input())

total = 0

for i in range(1, 10**6 + 1):
    for j in range(1, 10**6 + 1):
        m = n - i * j
        if m > 0:
            total += 1
        else:
            break

print(total)
# Judge status: Accepted
N = int(input())
ABC = [list(map(int, input().split())) for _ in range(N)]
dp = [[0] * 3 for _ in range(N+1)]
for i in range(N):
    dp[i+1][0] = max(dp[i][1]+ABC[i][0], dp[i][2]+ABC[i][0])
    dp[i+1][1] = max(dp[i][0]+ABC[i][1], dp[i][2]+ABC[i][1])
    dp[i+1][2] = max(dp[i][0]+ABC[i][2], dp[i][1]+ABC[i][2])

print(max(dp[-1]))
# Judge status: Wrong Answer
x,y,a,b,c = map(int,input().split())
dx = list(map(int,input().split()))
dy = list(map(int,input().split()))
r = list(map(int,input().split()))
r.sort()
dx.sort()
dy.sort()
dx = dx[-x:]
dy = dy[-y:]
print(sum(dx+dy))
# Judge status: Accepted
r = int(input())
ans = r ** 2
print(ans)
# Judge status: Wrong Answer
n = int(input())
pos = [list(map(int, input().split())) for _ in range(n)]

def func(n, pos):
    c_t, c_x, c_y = 0, 0, 0

    for i in pos:
        d_t = i[0] - c_t
        z = (i[1] - c_x) + (i[2] - c_y)

        if z > d_t or (d_t - z) % 2 != 0:
            return "No"
        else:
            c_t, c_x, c_y = i[0], i[1], i[2]

    return "Yes"


print(func(n, pos))
# Judge status: Accepted
sx,sy,tx,ty=map(int,input().split())
tempx=tx-sx
tempy=ty-sy
ans=["R"]*tempx+["U"]*tempy+["L"]*tempx+["D"]*tempy+["D"]+["R"]*(tempx+1)+["U"]*(tempy+1)+["L"]+["U"]+["L"]*(tempx+1)+["D"]*(tempy+1)+["R"]
print("".join(ans))
# Judge status: Accepted
from itertools import accumulate
n=int(input())
List=list(map(int,input().split()))
List=list(accumulate(List))
ans=float('inf')
# print(List)
for i in range(n):
    ans=min({ans,abs(List[i]-abs(List[n-1]-List[i]))})
print(int(ans))
# Judge status: Accepted
a, b = map(int, input().split())
s = a * b
if s % 2 == 0:
  print("Even")
else:
  print("Odd")
# Judge status: Wrong Answer
dic = dict()
for a in range(int(input())):
    i = input()
    if not i in dic:
        dic[i] = 1
    else:
        dic[i] = dic[i]+1
for b in range(int(input())):
    i = input()
    if not i in dic:
        dic[i] = -1
    else:
        dic[i] = dic[i]-1
print(max(max([a for a in dic.values()]), 1))
# Judge status: Accepted
N, x = map(int, input().split())
A = sorted(map(int, input().split()))

if sum(A) == x:
    print(N)

else:
    c = 0
    for ai in A:
        x -= ai
        if x <= 0:
            break
        c += 1

    if c == N:
        print(N - 1)
    else:
        print(c + 1 if x == 0 else c)
# Judge status: Wrong Answer
n = int(input())
h = list(map(int, input().split()))
l = []
cnt = 0
ans = 0
for i in reversed(range(1, n)):
  if h[i]<=h[i-1]:
    cnt += 1
  else:
    l.append(cnt)
    cnt = 0
    ans = max(l)
print(ans)
# Judge status: Accepted
n = int(input())
a = [int(input()) for _ in range(n)]
b = sorted(a)
for v in a:
  print(b[(v<b[-1])-2])
# Judge status: Wrong Answer
n,k=map(int,input().split())
if n<10:
  c=100*(10-n)
  print(k-c)
else:
  print(k)
# Judge status: Accepted
N,K = map(int,input().split())
S = input()
score = 0
for i in range(N-1):
    if S[i]==S[i+1]:
        score+=1
print(min(score+2*K, N-1))
# Judge status: Accepted
N = int(input())

ans = 0
for i in range(1,N+1):
  if((i%3 != 0)and(i%5 != 0)):
    ans += i
print(ans)
# Judge status: Accepted
a,b = map(int,input().split())
if a <= 0 <= b:
    print("Zero")
elif a > 0:
    print("Positive")
else:
    if (b - a) % 2 == 0:
        print("Negative")
    else:
        print("Positive")
# Judge status: Accepted
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    s = input()
    k = int(input())

    ichi = 0
    for i in range(len(s)):
        if s[i] == '1':
            ichi += 1
        else:
            break
    if ichi >= k:
        print(1)
    else:
        print(s[ichi])



if __name__ == '__main__':
  main()
# Judge status: Accepted
N = int(input())
S = input()

RN = S.count('R')
GN = S.count('G')
BN = S.count('B')

ans = RN * GN * BN

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

print(ans)
# Judge status: Accepted
ss = input()

even, odd = [], []

for i, s in enumerate(ss):
    if i%2==1:
        even.append(s)
    else:
        odd.append(s)

if ('L' in odd) or ('R' in even):
    print('No')

else:
    print('Yes')
# Judge status: Accepted
a,b,c=map(int,input().split())

if (a==b and a!=c) or (a==c and a!=b) or (c==b and a!=c):
  print("Yes")
else:
  print("No")
# Judge status: Accepted
INF = 10 ** 20
 
N = int(input())
coin_list = [1] + [6**i for i in range(1, 7)] + [9**i for i in range(1, 6)]
dp = [INF]*(N+1)
dp[0] = 0
 
for i in range(1,N+1):
	for coin in coin_list:
	    if i-coin >= 0: dp[i] = min(dp[i], dp[i-coin]+1)
 
print(dp[N])
# Judge status: Wrong Answer
text_list = input().split()
n = 0
a = int(text_list[0])
b = a + int(text_list[1])
c = b + int(text_list[2])
for i in range(int(text_list[3])):
    if i < int(text_list[0]) + int(text_list[1]):
        continue
    elif i < int(text_list[0]):
        n += 1
    elif i < int(text_list[0]) + int(text_list[1]) + int(text_list[2]):
        n -= 1

print(n)
# Judge status: Accepted
N = int(input())
S = input()
x = 0
ans = 0
for s in S:
    if s == "I":
        x += 1
    else:
        x -= 1
    if x > ans:
        ans = x
print(ans)
# Judge status: Accepted
def resolve():
    N = int(input())
    _xmin, _xmax = float("inf"), -float("inf")
    _ymin, _ymax = float("inf"), -float("inf")
    for i in range(N):
        x, y = list(map(int, input().split()))
        _x, _y = x - y, x + y
        _xmin = min(_x, _xmin)
        _xmax = max(_x, _xmax)
        _ymin = min(_y, _ymin)
        _ymax = max(_y, _ymax)
    print(max(_xmax-_xmin, _ymax-_ymin))


if '__main__' == __name__:
    resolve()
# Judge status: Accepted
N = int(input())

p_dic = {}
i=2
while i ** 2 <= N:
  if N % i == 0:
    p_dic[i] = 0
    while N % i == 0:
      p_dic[i] += 1
      N /= i
  i += 1

if N > 1:
  p_dic[N] = 1
  
def foo(x):
  r = 0
  base = 1
  while x >= base:
    x -= base
    r+=1
    base += 1
  return r

ans = 0
for v in p_dic.values():
#  print(v, foo(v))
  ans += foo(v)

print(ans)
# Judge status: Wrong Answer
N,x = map(int, input().split())
A = list(map(int, input().split()))

A.sort()

ans = 0
for i in range(N):
  if x > A[i]:
    ans += 1
    x -= A[i]
  elif x == A[i]:
    print(ans+1)
    break
  elif i+1 == N:
    print(ans -1)
    break
  else:
    print(ans)
    break
# Judge status: Accepted
from math import gcd
X, Y = [int(i) for i in input().split()]
lcm = X * Y // gcd(X, Y)
if lcm == X:
    print(-1)
else:
    print(X)
# Judge status: Accepted
n,a,b = map(int, input().split())

ans = pow(2,n,10**9+7)

nm= 1
dn = 1

for i in range(a):
  nm = (nm * (n-i)) % (10**9+7)
  dn = (dn * (i+1)) % (10**9+7)

ans = (ans - nm*pow(dn,-1,10**9+7) - 1) % (10**9+7)

for i in range(a,b):
  nm = (nm * (n-i)) % (10**9+7)
  dn = (dn * (i+1)) % (10**9+7)

ans = (ans - nm*pow(dn,-1,10**9+7)) % (10**9+7)

print(ans)
# Judge status: Wrong Answer
from collections import deque
que = deque()
s = input()
n = len(s)
for i in range(n):
    if s[i] == '0':
        que.appendleft('0')
    if s[i] == '1':
        que.append('1')
    if s[i] == 'B':
        if len(que)==0:
            continue
        k = que.pop()
li = list(que)
print(''.join(li))