Harryxun/stf_run huggingface dataset:
def wa(h, w, f):
    if not (0 <= h <= H-1 and 0 <= w <= W-1):
        return
    elif mapp[h][w] != f:
        return
    else:
        mapp[h][w] = '$'
        wa(h, w+1, f)
        wa(h-1, w, f)
        wa(h, w-1, f)
        wa(h+1, w, f)

while True:
    H, W = map(int, raw_input().split(' '))
    if H == 0 and W == 0: break
    line = raw_input()
    mapp = [list(line[i*W:i*W+W]) for i in range(H)]
    for line in mapp:
        print line
    count = 0
    for h in range(H):
        for w in range(W):
            if mapp[h][w] == '@':
                wa(h, w, '@')
            elif mapp[h][w] == '#':
                wa(h, w, '#')
            elif mapp[h][w] == '*':
                wa(h, w, '*')
            else:
                continue
            count += 1
    else:
        print count

### FIXED CODE ###

import sys
sys.setrecursionlimit(20000)
def wa(h, w, f):
    if not (0 <= h < H and 0 <= w < W):
        return
    elif mapp[h][w] != f:
        return
    else:
        mapp[h][w] = '$'
        wa(h, w+1, f)
        wa(h-1, w, f)
        wa(h, w-1, f)
        wa(h+1, w, f)

while True:
    H, W = map(int, raw_input().split())
    if H == 0 and W == 0: break
    mapp = [list(raw_input()) for i in range(H)]
    count = 0
    for h in range(H):
        for w in range(W):
            if mapp[h][w] == '@':
                count += 1
                wa(h, w, '@')
            elif mapp[h][w] == '#':
                count += 1
                wa(h, w, '#')
            elif mapp[h][w] == '*':
                count += 1
                wa(h, w, '*')
    else:
        print count
X,A,B = map(int, input().split())

if A + X < B:
    print("dengerous")
if A <= B <= A + X:
    print("safe")
if B < A:
    print("delicious")

### FIXED CODE ###

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

import math
if abs (N - M) > 1:
    print(0)
else:
    if (N + M) % 2 == 0:
        print(math.factorial(N) * math.factorial(M) * 2 % (10 ** 9 + 7))
    else:
        print(math.factorial(N) * math.factorial(M) % (10 ** 9 + 7))
import math
while True:
    n=int(input())
    a=list(map(int,input().split()))
    if n==0:
        break
    m=sum(a)/float(n)
    print("{0:.8f}".format(math.sqrt(sum([(x-m)**2/n for x in a]))))

### FIXED CODE ###

import math
while True:
    n = int(input())
    if n==0: break
    s = list(map(int,input().split()))
    m = sum(s)/float(n)
    print("{0:.8f}".format(math.sqrt(sum([(x-m)**2 for x in s])/n)))
import math

A,B,C,D=[int(x) for x in input().rstrip().split()]
cnt=0


def lcm(x, y):
  if x!=0 and y!=0:
    return (x * y) // math.gcd(x, y)
  else:
    return 0

    
baisuu=lcm(C,D)

u_A=(A-1)-(A-1)//C-(A-1)//D+(A-1)//baisuu

u_B=B-B//C-B//D+B//baisuu

print(u_B-u_A)

### FIXED CODE ###

import fractions
from functools import reduce

A,B,C,D=[int(x) for x in input().rstrip().split()]
cnt=0

import math

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

    
baisuu=lcm(C,D)

u_A=(A-1)-(A-1)//C-(A-1)//D+(A-1)//baisuu

u_B=B-B//C-B//D+B//baisuu

print(u_B-u_A)
s = list(input())

t = list("AKIHABARA")
cnt = 0

for i in range(len(s)):
    if s[i] == t[cnt]:
        cnt += 1
        continue
    else:
        if t[cnt] == "A":
            cnt += 1
            if t[cnt] == s[i]:
                cnt += 1
                continue
            else:
                print("NO")
                eixt()
        else:
            print("NO")
            exit()
            
if cnt >= 7:
    print("YES")
else:
    print("NO")
            

### FIXED CODE ###

s = input()

check = ["KIHBR","KIHBRA","KIHBAR","KIHBARA","KIHABR","KIHABRA","KIHABAR","KIHABARA","AKIHBR","AKIHBRA","AKIHBAR","AKIHBARA","AKIHABR","AKIHABRA","AKIHABAR","AKIHABARA"]

if s in check:
    print("YES")
else:
    print("NO")
x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int, input().split())))
q = sorted(list(map(int, input().split())))
r = sorted(list(map(int, input().split())))

ps = -1
qs = -1
rs = -1

ans = 0
for i in range(x):
    if (p[ps] > r[rs]):
        ans += p[ps]
        ps -= 1
    else:
        ans += r[rs]
        rs -= 1

for i in range(y):
    if (q[qs] > r[rs]):
        ans += q[qs]
        qs -= 1
    else:
        ans += r[rs]
        rs -= 1

print(ans)

### FIXED CODE ###

x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int, input().split())),reverse = True)
q = sorted(list(map(int, input().split())),reverse = True)
r = sorted(list(map(int, input().split())),reverse = True)

px = p[:x]
qx = q[:y]

aps = sorted(px + qx + r, reverse=True)

print(sum(aps[0:x+y]))
a = input()
b = input()
if a = b[:-1]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a,b = [input() for i in range(2)]
 
if a == b[:-1]:
  print("Yes")
else:
  print("No")
n , m = map(float ,input().split())
n = int(n)
ans = str(n * (m * 100)) // 100

print(ans[:ans.find('.')])

### FIXED CODE ###

a, b = input().split()
a = int(a)
b = int(b.replace(".",""))

c = a * b
ans = c//100
print(ans)
import itertools
result = 10 ** 15
N = int(input())

h = [int(x) for x in input().split()]

numbers = []
for i in range(N):
    numbers.append(1)
for i in range(N/2):
    numbers.append(2)
combination = list(set([seq for i in range(len(numbers), 0, -1) for seq in itertools.combinations(numbers, i) if sum(seq) == N - 1]))
for i in range(len(combination)):
    idouti = 0
    for j in range(len(combination[i]) + 1):
        if j == 0:
            #idouti += abs(h[0] - h[combination[i][j]])
            continue
        a = sum(combination[i][0:j])

        b = sum(combination[i][0:j - 1])

        idouti += abs(h[a] - h[b])
    if result > idouti:
        result = idouti

print(result)


### FIXED CODE ###

N = int(input())
h = [int(x) for x in input().split()]
dp = []
dp1 = 0
dp2 = 0
for i in range(N):
    if i == 0:
        dp.append(0)
        continue

    if i == 1:
        dp.append(abs(h[0] - h[1]))
        continue

    dp1 = dp[i - 1] + abs(h[i] - h[i - 1])
    dp2 = dp[i - 2] + abs(h[i] - h[i - 2])

    if dp1 < dp2:
        dp.append(dp1)
    else:
        dp.append(dp2)
print(dp[-1])
import string
s = str(input())
low = string.ascii_lowercase
fin = ''
for i in range(len(low)):
    if low[i] not in s:
        fin += low[i]
        
print(fin[0])

### FIXED CODE ###

import string
s = str(input())
low = string.ascii_lowercase
fin = ''
for i in range(len(low)):
    if low[i] not in s:
        fin += low[i]
if len(fin) == 0:
    print('None')
else:
    print(fin[0])
from heapq import *
x,y,a,b,c = map(int, input().split())
p = sorted(list(map(int, input().split())),reverse=True)[:x]
q = sorted(list(map(int, input().split())),reverse=True)[:y]
pq = sorted(p + q,reverse=True)

r = sorted(list(map(int, input().split())),reverse=True)
ans = 0
data_pq = [0]
for s in pq:
    data_pq.append(data_pq[-1] + s)

data_r = [0]
for t in r:
    data_r.append(data_r[-1] + t)


for i in range(c+1):
    ans = max(ans,data_r[i] + data_pq[x+y-i])

print(ans)

### FIXED CODE ###

x,y,a,b,c = map(int, input().split())
p = sorted(list(map(int, input().split())),reverse=True)[:x]
q = sorted(list(map(int, input().split())),reverse=True)[:y]
pq = sorted(p + q,reverse=True)

r = sorted(list(map(int, input().split())),reverse=True)
ans = 0
data_pq = [0]
for s in pq:
    data_pq.append(data_pq[-1] + s)

data_r = [0]
for t in r:
    data_r.append(data_r[-1] + t)


for i in range(c+1):
    if x + y - i < 0:break
    ans = max(ans,data_r[i] + data_pq[x+y-i])

print(ans)
N = int(input())
adj = [ [] for _ in range(N) ]
for _ in range(N-1):
  u,v,w = map(int,input().split())
  u -= 1
  v -= 1
  adj[u].append((v,w))
  adj[v].append((u,w))

def dfs(node, w, color):
  colors[node] = color

  for nei,nw in adj[node]:
    if colors[nei] != -1: continue
    nc = 1 if (w+nw)%2==0 else 0
    dfs(nei, nw, nc)

  return True

colors = [-1] * N
for i in range(N):
  if colors[i] == -1:
    dfs(i, 0, 1)

for c in colors: print(c)

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

N = int(input())
adj_list = { i: [] for i in range(N+1) }
for _ in range(N-1):
  u,v,w = map(int, input().split())
  adj_list[u].append([v,w])
  adj_list[v].append([u,w])

res = [None] * N
visited = [False] * (N+1)
def dfs(node, c, w):
  res[node-1] = c
  visited[node] = True

  for nei, nw, in adj_list[node]:
    if not visited[nei]:
      if (w+nw)%2 == 0:
        dfs(nei, 0, w+nw)
      else:
        dfs(nei, 1, w+nw)

dfs(1, 0, 0)
for r in res: print(r)
n = int(input())
x = [0 for i in range(n)]
y = [0 for i in range(n)]
for i in range(n):
    x[i], y[i] = map(int, input().split())

a = {}
for i in range(n):
    for j in range(i + 1, n):
        v = x[j] - x[i], y[j] - y[i]
        if v not in a:
            a[v] = 1
        else:
            a[v] += 1
ans = n - max(a.values())
print(ans)

### FIXED CODE ###

n = int(input())
x = [0 for i in range(n)]
y = [0 for i in range(n)]
for i in range(n):
    x[i], y[i] = map(int, input().split())

a = {}
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        v = x[j] - x[i], y[j] - y[i]
        if v not in a:
            a[v] = 1
        else:
            a[v] += 1
ans = n
# print("a =", a)
if len(a.values()) > 0:
    ans -= max(a.values())
print(ans)
a,b,c = map(int,input())
print("Yes" a+b>=c else"No")

### FIXED CODE ###

a,b,c = map(int,input().split())
if a+b>=c:
  print("Yes")
else:
  print("No")
N,A,B = list(map(int,input().split()))

item=[]
for i in range(N):
    a,b,c = list(map(int,input().split()))
    item.append([a,b,c])

D = [[[10**27 for i in range(401)] for j in range(401)] for k in range(N+1)]
D[0][0] = 0
for i in range(N):
    for j in range(401):
        for k in range(401):
            if D[j][k]<10**26:
                D[i+1][j][k]=min(D[i+1][j][k],D[i][j][k])
                D[i+1][j+item[i][0]][k+item[i][1]] = min(D[i+1][j+item[i][0]][k+item[i][1]],D[i][j][k]+item[i][2])

i=1
min_cost=10**27
while A*i<=400 and B*i<=400:
    min_cost = min(D[A*i][B*i],min_cost)
    i+=1
if min_cost==10**27:
	print(-1)
else:
	print(min_cost)

### FIXED CODE ###

N,ma,mb = map(int,raw_input().split())

a=[]
b=[]
c=[]
for i in range(N):
	at,bt,ct=map(int,raw_input().split())

	a.append(at)
	b.append(bt)
	c.append(ct)
	

dp = [[[10**10 for i in range(400+1)] for j in range(400+1)] for k in range(N+1)]
dp[0][0][0]=0
for i in range(N):
	for j in range(401):
		for k in range(401):
			if(dp[i][j][k]<10**10):
				dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k])
				dp[i+1][j+a[i]][k+b[i]]=min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i])

ans=10**10

for i in range(1,401):
	for j in range(1,401):
		if i*mb==j*ma:
			ans=min(ans,dp[N][i][j])

if ans>=10**10:
	print -1
else:
	print ans
n, q = map(int, raw_input().split())
s = raw_input()
td = [raw_input().split() for _ in range(q)];
left, right = 0, n
for t, d in reversed(td):
    if d == 'L':
        if left < n and s[left] == t:
            left += 1
        if right < n and s[right] == t:
            right += 1
    elif d == 'R':
        if left > 0 and s[left - 1] == t:
            left -= 1
        if right > 0 and s[right - 1] == t:
            right -= 1
print(max(0, right - left))

### FIXED CODE ###

n, q = map(int, raw_input().split())
s = raw_input()
td = [raw_input().split() for _ in range(q)];
left, right = 0, n
for t, d in reversed(td):
    if d == 'L':
        if left < n and s[left] == t:
            left += 1
        if right < n and s[right] == t:
            right += 1
    elif d == 'R':
        if left > 0 and s[left - 1] == t:
            left -= 1
        if right > 0 and s[right - 1] == t:
            right -= 1
print max(0, right - left)
# ABC132 D Blue and Red Balls

from math import factorial

def comb(n, r):
    ''' 組み合わせ '''
    return factorial(n) // (factorial(n - r) * factorial(r))

N, K = map(int, input().split())
MOD = int(1e9)+7

for i in range(1, K+1):
    temp = comb(N-K+1, i) * comb(K-1, i-1)
    print(int(temp % MOD))

### FIXED CODE ###

# ABC132 D Blue and Red Balls

def comb(n, r):
    if n == 0 or r == 0:
        return 1
    if n < r:
        return 0
    a = b = 1
    r = min(n-r, r)
    for i in range(n-r+1,n+1):
        a*=i
    for i in range(1,r+1):
        b*=i
    
    return a//b

N, K = map(int, input().split())
MOD = int(1e9)+7

for i in range(1, K+1):
    temp = comb(N-K+1, i) * comb(K-1, i-1)
    print(int(temp % MOD))
class Dice:
    def _init_ (self,data):
        self.data = data

    def move(self,direction):
        if direction == 'E':
            self.data[0],self.data[3],self.data[5],self.data[2] = \
                    self.data[3].self.data[5],self.data[2],self.data[0]

            """tmp = self.data[0]
            self.data[0] = self.data[3]
            self.data[3] = self.data[5]
            self.data[5] = self.data[2]
            self.data[2] = tmp"""
        elif direction == 'N':
            self.data[0],self.data[4],self.data[5],self.data[1] = \
                    self.data[4].self.data[5],self.data[1],self.data[0]
        elif direction == 'S':
            self.data[0],self.data[1],self.data[5],self.data[4] = \
                    self.data[4].self.data[0],self.data[1],self.data[5]
        elif firection == 'W':
            self.data[0],self.data[2],self.data[5],self.data[3] = \
                    self.data[2].self.data[5],self.data[3],self.data[0]

    def getTop(self):
        return self.data[0]

dice = Dice.Dice(input().split())
cmd = input()
for i in range(len(cmd)):
    dice.move(cmd[i])
    print(dice.getTop())

### FIXED CODE ###

class Dice:
    def __init__ (self,data):
        self.data = data

    def move(self,direction):
        if direction == 'E':
            self.data[0],self.data[3],self.data[5],self.data[2] = \
                    self.data[3],self.data[5],self.data[2],self.data[0]
        elif direction == 'N':
            self.data[0],self.data[4],self.data[5],self.data[1] = \
                    self.data[1],self.data[0],self.data[4],self.data[5]
        elif direction == 'S':
            self.data[0],self.data[1],self.data[5],self.data[4] = \
                    self.data[4],self.data[0],self.data[1],self.data[5]
        elif direction == 'W':
            self.data[0],self.data[2],self.data[5],self.data[3] = \
                    self.data[2],self.data[5],self.data[3],self.data[0]

    def getTop(self):
        return self.data[0]

dice = Dice(input().split())
cmd = input()
for i in range(len(cmd)):
    dice.move(cmd[i])
print(dice.getTop())
N, A = map(int, input().split())
X = list(map(lambda x: int(x) - A, input().split()))
maxn = max(max(X), A)
 
dp = [[0 for _ in range(2 * N * maxn + 1)] for _ in range(N + 1)]
dp[0][N * maxn] = 1
 
for i in range(N):
    for k in range(2 * N * maxn + 1):
        dp[i + 1][k] = dp[i][k]
        if 0 <= k - X[i] <= 2 * N * maxn:
            dp[i + 1][k] += dp[i][k - X[i]]
 
print(dp[N][N * maxn] - 1)
N, A = map(int, input().split())
X = list(map(lambda x: int(x) - A, input().split()))
maxn = max(max(X), A)

dp = [[0 for _ in range(2 * N * maxn + 1)] for _ in range(N + 1)]
dp[0][N * maxn] = 1

for i in range(N):
    for k in range(2 * N * maxn + 1):
        dp[i + 1][k] = dp[i][k]
        if 0 <= k - X[i] <= 2 * N * maxn:
            dp[i + 1][k] += dp[i][k - X[i]]

print(dp[N][N * maxn] - 1)


### FIXED CODE ###

N, A = map(int, input().split())
X = list(map(lambda x: int(x) - A, input().split()))
maxn = max(max(X), A)
 
dp = [[0 for _ in range(2 * N * maxn + 1)] for _ in range(N + 1)]
dp[0][N * maxn] = 1
 
for i in range(N):
    for k in range(2 * N * maxn + 1):
        dp[i + 1][k] = dp[i][k]
        if 0 <= k - X[i] <= 2 * N * maxn:
            dp[i + 1][k] += dp[i][k - X[i]]
 
print(dp[N][N * maxn] - 1)
N = int(input())
a = N[-1]

if a == 2, 4, 5, 7, 9:
  print('hon')
if a == 0, 1, 6, 8:
  print('pon')
else:
  print('bon')

### FIXED CODE ###

N = int(input())
a = N%10
 
if a==3:
  print("bon")
elif a==0 or a==1 or a==6 or a==8:
  print("pon")
else:
  print("hon")
s = input()
t = input()
if t.starttswith(s) and len(s) + 1 == len(t):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s = input()
t = input()
if t.startswith(s) and len(s) + 1 == len(t):
  print("Yes")
else:
  print("No")
import numpy as np
from math import sqrt

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

if np.isclose(sqrt(a) +sqrt(b),sqrt(c),rtol=0,atol=1e-10):
  print("No")
elif sqrt(a) +sqrt(b) < sqrt(c):
  print("Yes")
else:
  print("No")


### FIXED CODE ###

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

if c-a-b>0 and 4*a*b<(c-a-b)**2:
  print("Yes")
else:
  print("No")
s =input()
ary = []
for c in s:
    if c == 'B':
        if len(ary) > 0:
            ary.pop()
    else:
        ary.append(c)
print(''join(ary))

### FIXED CODE ###

s =input()
ary = []
for c in s:
    if c == 'B':
        if len(ary) > 0:
            ary.pop()
    else:
        ary.append(c)
print(''.join(ary))
s = str(input())
ans = 0
if s[0] == 'A':
    for i in range(3, len(s)-1):
        if s[i] == 'C':
            ans += 1
        if s[i].isupper() or s[1].isuuper():
            print('WA')
            exit()
    
    if ans == 1:
        print('AC')
        exit()
else:
    print('WA')

### FIXED CODE ###

s = str(input())
if s[0] == 'A' and s[2:-1].count('C') == 1 and (s[1:s.find('C')]+s[s.find('C')+1:]).islower():
    print('AC')
else:
    print('WA')
s=input()
if s=-'ARC':
    print('ABC')
else:
    print('ARC')

### FIXED CODE ###

s=input()
if s=='ARC':
    print('ABC')
else:
    print('ARC')
from math import factorial
MOD = 10 ** 9 + 7

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

def rep_perm(n, k):
    if n == 0:
        return 1
    
    ans = factorial(n + k - 1) % MOD
    ans *= pow(factorial(n - 1), MOD - 2, MOD)
    ans %= MOD
    ans *= pow(factorial(k), MOD - 2, MOD)
    ans %= MOD
    return ans

for i in range(1, K + 1):
    ans = rep_perm(i + 1, N - K - i + 1)
    if i != 1:
        ans *= (K - i + 1)
    print(ans)





### FIXED CODE ###

MOD = 10 ** 9 + 7
N, K = map(int, input().split())

def comb(n, k):
    ret = 1
    for i in range(1, k + 1):
        ret = ret * (n - i + 1) % MOD        
        ret = ret * pow(i, MOD - 2, MOD) % MOD
    return ret

for i in range(1, K + 1):
    n = i - 1 + 2
    k = N - K - (i - 1)
    if k < 0:
        print(0)
    else:
        ans = comb(n + k - 1, k) * comb(K - 1, i - 1) % MOD
        print(ans)
n, k = map(int, input().split())
A = list(map(int,input().split()))
mod = 10**9 + 7

ans = 1
if k == n:
    for i in A:
        ans*=i
elif sum([A[i]<0 for i in range(n)]) == n and k%2 ==1:
    A = sorted(A, key=abs)
    for i in range(k):
        ans *= A[i]
else:
    nega = []
    posi = []
    for i in A:
        if i>0:
            posi.append(i)
        else:
            nega.append(i)
    posi.sort(reverse=True)
    nega.sort()
    ctr = 0
    pi=0
    ni=0
    if k%2 == 1:
        ans*=posi[pi]
        pi+=1
        ctr+=1
        
    if ctr <k:
        tmp_p = posi[pi]*posi[pi+1]
        tmp_n = nega[ni]*nega[ni+1]
    while ctr < k:
        if tmp_p >= tmp_n:
            ans *= tmp_p
            pi += 2
            ctr+=2
            if ctr<k:
                tmp_p = posi[pi]*posi[pi+1]
        else:
            ans *= tmp_n
            ni += 2
            ctr+=2
            if ctr<k:
                tmp_n = nega[ni]*nega[ni+1]
    

ans %=mod 
print(ans)


### FIXED CODE ###

def solve(n,k,a):
    mod = 10**9 + 7
    ans = 1
    l = 0
    r = n-1
    a.sort()
    
    if k%2 == 1:
        ans *= a[r]
        r-=1
    
    if ans < 0:
        ans = 1
        for i in range(k):
            ans*= a[n-i-1]
            ans%= mod
        return ans
    
    for i in range(k//2):
        tmp_min=a[l]*a[l+1]
        tmp_max=a[r]*a[r-1]
        if tmp_max> tmp_min:
            ans*=tmp_max
            ans%=mod
            r-=2
        else:
            ans*= tmp_min
            ans%=mod
            l+=2
    return ans


n, k = map(int, input().split())
A = list(map(int,input().split()))
ans = solve(n,k,A)
print(ans)
n=int(input())
dat = list(map(int, input().split()))

for e in dat:
    e = str(bin(e))

for e in dat:
    e = e[::-1]

#print(min(dat)-1)



### FIXED CODE ###

import sys

def main():
    N = int(input())
    A = [int(_) for _ in input().split()]

    t = 0
    while True:
        for i in range(N):
            if A[i] % 2 == 0:
                A[i] //= 2
            else:
                print(t)
                sys.exit()
        t += 1

main()
s=input()
n=len(s)
ls=[0]*26

for i in range(n):
  ls[ord(s[i])-97]=i+1
if n<26:
  for i in range(26):
    if ls[i]==0:
      x=i
      break
  print(s+chr(x+97))
else:
  for i in range(24,-1,-1):
    if ls[i+1]>ls[i]:
      

### FIXED CODE ###

from bisect import bisect
s=input()
n=len(s)
ls=[0]*26
if s == "zyxwvutsrqponmlkjihgfedcba":
  print(-1)
  exit()
if n<26:
  for i in range(n):
    ls[ord(s[i])-97]=i+1
  for i in range(26):
    if ls[i]==0:
      x=i
      break
  print(s+chr(x+97))
else:
  for i in range(n):
    ls[i] = ord(s[i])-97
  if ls[25]>ls[24]:
    print(s[:24]+s[25])
  else:
    tmp = []
    for i in range(24,-1,-1):
      tmp.append(ls[i+1])
      if ls[i+1]>ls[i]:
        tmps = sorted(tmp)
        x = bisect(tmps,ls[i])
        print(s[:i]+chr(tmps[x]+97))
        break
for i in range(1, n+1):
    if i % 2 == 1:
        count = 0
        for j in range(1, i+1):
            if i % j == 0:
                count += 1
            else:
                continue
        if count == 8:
            ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
count = 0
ans = 0
for i in range(1, n+1):
    if i % 2 == 1:
        count = 0
        for j in range(1, i+1):
            if i % j == 0:
                count += 1
        if count == 8:
            ans += 1
        else:
            continue
    else:
        continue
print(ans)
import math

s = list(input())
t = list(input())
s.reverse()
s=''.join(s)
t.reverse()
t=''.join(t)
#print(s)
n = s.index(t[0])
#print(n)
res = len(t)
num =0
while len(s)!=0:
    if len(s)<=len(t) and s[0] != t[0]:break
    n = s.index(t[0])
    for i in range(len(t)):
        if t[i]!=s[i+n]:
            num+=1
    res = min(res,num)
    s = s[n+len(t):]
print(res)

### FIXED CODE ###

import math

s = input()
t = input()
res = len(t)
num =0
for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if t[j]!=s[i+j]:
            num+=1
    res = min(res,num)
    num = 0
print(res)
import math
from operator import mul
from functools import reduce

def comb(n, r):
  r = min(r, n-r)
  if r==0: return 1
  over = reduce(mul, range(n, n-r, -1))
  under = reduce(mul, range(1, r+1))
  return over//under

n, k = map(int, input().split())
mod = 10**9+7

for i in range(1, k+1):
  if i <= n-k+1:
    ans = comb(n-k+1, i) * comb(k-1, i-1)
    ans %= mod
  else:
    ans = 0
  print(ans)

### FIXED CODE ###

n = int(input())
*d, = map(int, input().split())

d.sort()

print(d[n//2] - d[n//2-1])
a = input()
if a = 'AAA' or 'BBB':
  print('No')
else:
  print('Yes')

### FIXED CODE ###

a = input()
if a in ('AAA','BBB'):
  print('No')
else:
  print('Yes')
from math import gcd
K=int(input())
if K%7==0:
  K=K//7
if gcd(10,K)!=1:
  print(-1)
  retur
x=1%K
cnt=1
while x!=0:
  x=(10*x+1)%K
  cnt+=1
print(cnt)

### FIXED CODE ###

K = int(input())
x = 7 % K #mod(K)
if K == 1 or K == 7:
  print(1)
  exit()
ans = 1
i = 0
while i < K:
  ans += 1
  x = (x * 10 + 7) % K
  
  
  if x == 0:
    print(ans)
    exit()
  i += 1
print('-1')
a, b, c = input1
k = int(input())

for i in range(k):
    if a >= b:
        b *= 2
    elif b >= c:
        c *= 2
    else:
        c *= 2

if a < b < c:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

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

for i in range(k):
    if a >= b:
        b *= 2
    elif b >= c:
        c *= 2
    else:
        c *= 2

if a < b < c:
    print("Yes")
else:
    print("No")
#B問題
n = int(input())

# ある整数に対し、各桁の和を与える

sum = 0
while n > 0:
    sum += n % 10
    n = int(n / 10)
    
ans = sum % 9
    
if ans == 0:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

#B問題

#ABSの定石使うとなぜかRE

#今回はPython解説サイト参照

#①入力を文字列で受け取る→②一文字ずつ整数に変換して、forループで回しながら足し算する

N = input()
cur = 0

for i in N:
    cur += int(i)

if cur % 9 == 0:
    print("Yes")
else:
    print("No")