Harryxun/stf_run huggingface dataset:
import sys

stdin = sys.stdin

na = lambda: list(map(int, ns().split()))
ns = lambda: stdin.readline()

N, Y = na()

ans="-1 -1 -1"
for i in range(N+1, -1, -1):
    if (i * 10000) > Y:
        continue
    for j in range(N+1-i):
        k = n - i - j
        if ((i * 10000) + (j * 5000)) > Y:
            continue
        if (i*10000) + (j*5000) + (k*1000) == Y:
            ans = str(i) + " " + str(j) + " " + str(k)
            break
    else:
        continue
    break

print(ans)


### FIXED CODE ###

import sys

stdin = sys.stdin

na = lambda: list(map(int, ns().split()))
ns = lambda: stdin.readline()

N, Y = na()

ans="-1 -1 -1"
for i in range(N+1):
    if (i * 10000) > Y:
        continue
    for j in range(N+1-i):
        k = N - i - j
        if ((i * 10000) + (j * 5000)) > Y:
            continue
        if (i*10000) + (j*5000) + (k*1000) == Y:
            ans = str(i) + " " + str(j) + " " + str(k)
            break
    else:
        continue
    break

print(ans)
h,w,k = map(int,input().split())
board = [list(input()) for _ in range]
ans = 0
for paint_h in range(2**h):
    for paint_w in range(2**w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if(paint_h>>i)&1==0 and (paint_w>>j)&1==0:
                    cnt += 1
        if cnt == k:    
            ans += 1
print(ans)

### FIXED CODE ###

h,w,k=map(int,input().split())
board=[list(input()) for _ in range(h)]
ans=0
for paint_h in range(2**h): #すべての行の塗りつぶし方を2進数で列挙する
 for paint_w in range(2**w): #すべての列の塗りつぶし方を2進数で列挙する
   cnt=0
   for i in range(h): #すべてのi行目j列目の要素についてみる
     for j in range(w):
       if (paint_h>>i)&1==0 and (paint_w>>j)&1==0: #各行のi番目のビットと各列のj番目のビットがともに0であればそのマスは塗りつぶされない
         if board[i][j]=='#': #塗りつぶされないマスが黒マスであれば個数を+1する
           cnt+=1
   if cnt==k: #塗りつぶされない黒マスの個数がKに等しければ答えを+1する
     ans+=1
print(ans)
n = int(input())
p = [int(i) for i in input().split()]
count = 0
min_value = p[0]
for i in enumerate(p):
    if i <= min_value:
        count += 1
        min_value = i
print(count)

### FIXED CODE ###

n = int(input())
p = [int(i) for i in input().split()]
count = 0
min_value = p[0]
for i in p:
    if i <= min_value:
        count += 1
        min_value = i
print(count)
from itertools import accumulate
N,K = map(int,input().split())
td = [tuple(map(int,input().split())) for i in range(N)]

td.sort(key=lambda x:-x[1])
td = [(x[0]-1,x[1]) for x in td]
t = [-1]*N
for i in range(N):
    t[td[i][0]] = 0
for i in range(K):
    t[td[:K][i][0]] = 1

t_used = [i for i in range(N) if t[i]==1]
t_not_used = [i for i in range(N) if t[i]==0]

d_top = [0]*N
d_top_candi = [0]*N
d_rest = []
d_candi = []

for i in range(K):
    if t[td[i][0]] == 1:
        if d_top[td[i][0]] == 0:
            d_top[td[i][0]] = td[i][1]
        else:
            d_rest.append(td[i][1])
for i in range(K,N):
    if t[td[i][0]] == 0:
        if d_top_candi[td[i][0]] == 0:
            d_top_candi[td[i][0]] = 1
            d_candi.append(td[i][1])

ans = len(t_used)**2+sum(d_top)
d_rest.sort()
d_candi.sort(key=lambda x:-x)

d_rest_cum = list(accumulate(d_rest))
d_candi_cum = list(accumulate(d_candi))
ans += d_rest_cum[-1]

for k in range(min(len(d_rest),len(d_candi))):
    ans = max(ans + (k+1)*(k+1+2*len(t_used)) + d_candi_cum[k] - d_rest_cum[k],ans)

print(ans)

### FIXED CODE ###

a,b,c = map(int,input().split())
print(a*b*c//2//max(a,b,c))
from collections import Counter
sys.setrecursionlimit(10**7)
n, k = map(int, input().split())
A = list(map(lambda x: int(x)-1, input().split()))


visited = [0]*n


def dfs(v):
    if visited[v]+1 == 3:
        return 0
    visited[v] += 1
    dfs(A[v])


dfs(0)

c = Counter(visited)
loop_cnt = c[2]
init_cnt = c[1]
k -= init_cnt
k %= loop_cnt

cnt = 0
visited = [0]*n


ans = 0
for _ in range(k+init_cnt):
    ans = A[ans]
print(ans+1)


### FIXED CODE ###

from collections import Counter
import sys
sys.setrecursionlimit(10**7)
n, k = map(int, input().split())
A = list(map(lambda x: int(x)-1, input().split()))

# A[0]から出発して何回でループするか数える

visited = [0]*n


def dfs(v):
    if visited[v]+1 == 3:
        return 0
    visited[v] += 1
    dfs(A[v])


dfs(0)

c = Counter(visited)
loop_cnt = c[2]
init_cnt = c[1]
k_ = k-init_cnt
k_ %= loop_cnt

cnt = 0
visited = [0]*n


ans = 0
loop = k if k < init_cnt else k_+init_cnt
for _ in range(loop):
    ans = A[ans]
print(ans+1)
s=int(input())
x=a%100
y=a//100
print(("AMBIGUOUS" if 0<x<13 else "MMYY") if 0<y<13 else "YYMM" if 0<x<13 else "NA")

### FIXED CODE ###

s=input()
c=0
if 0<int(s[0])*10+int(s[1])<13:c+=1
if 0<int(s[2])*10+int(s[3])<13:c+=2
print("AMBIGUOUS" if c==3 else "YYMM" if c==2 else "MMYY" if c==1 else "NA")
h = 0
while True:
    x = int(input());
 h += 1
    if x == 0: 
break
    print("Case {}: {}".format(c, x))


### FIXED CODE ###

i=1
x = int(input())
while x != 0 :
    print("Case {0}: {1}".format(i, x))
    x = int(input())
    i=i+1
def retry(list_S, ans, start_ii=0):
    if start_ii > len(list_S) - 3:
        return ans

    for start_i in range(start_ii, len(list_S) - 3):
        for last_i in range(start_i + 3, len(list_S)):
            tmp = ''.join(list_S[start_i:last_i + 1])

            if (int(tmp) % 2019) == 0:
                ans += 1
                return retry(list_S, ans, last_i)

    return ans


def resolve():
    S = input()
    list_S = list(S)
    ans = 0

    print(retry(list_S, ans))


resolve()

### FIXED CODE ###

from collections import defaultdict


def resolve():
    s = input()

    cnt = defaultdict(int)
    cnt[0] += 1
    tmp = 0
    for i, c in enumerate(s[::-1]):
        c = int(c)
        tmp = (tmp + c * pow(10, i, 2019)) % 2019
        cnt[tmp] += 1

    ans = sum(c * (c - 1) // 2 for c in cnt.values())
    print(ans)


resolve()
n , k , q = map(int, input().split())
a = [int(input()) for i in range(q)]
points = [k - q for i in range(n)]
for i in range(n):
    points[i] += a.count(i)
    if points[i] >= 1:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

S = input()

if S == 'Sunny':
    S_tomorrow = 'Cloudy'
elif S == 'Cloudy':
    S_tomorrow = 'Rainy'
else:
    S_tomorrow = 'Sunny'

print(S_tomorrow)
n, k = map(int,input().split())
d = list(map(int,input().split()))

x = 0
y = 0
while x <4:
    if n // (10**x) >0:
        y = x
    x += 1

i = 0
a = [0]
m = 0
while i <= y:
    a.append(((n//(10**(y-i)))%10))
    i +=1

i = 0
t = 0
while i <= y + t:
    j = 0
    while j < k:
        if a[y-i+1] == d[j]:
            a[y-i+1] += 1
        if a[y-i+1] == 10:
            a[y-i+1] = 0
            a[y-i] +=1
        j+=1
    i+=1
    if a[0] == 1 and t == 0:
        a[1] = 0
        a[2] = 0
        a[3] = 0
        a[4] = 0
        i = 0
        t = 1
        continue

i = 0
while i <= y + 1:
    m += a[y-i+1]*(10**(i))
    i+=1


print(m)

### FIXED CODE ###

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

s = 0
while s<k and s == d[s]:
    s += 1

x = 0
y = 0
while x <4:
    if n // (10**x) >0:
        y = x
    x += 1

i = 0
a = [0]
m = 0
while i <= y:
    a.append(((n//(10**(y-i)))%10))
    i +=1

i = 0
t = 0
while i <= y + t:
    j = 0
    while j < k:
        if a[y-i+1] == d[j]:
            a[y-i+1] += 1
            if y-i+1 < y+1:
                a[y-i+2] = s
        if a[y-i+1] == 10:
            a[y-i+1] = 0
            a[y-i] +=1
        j+=1
    i+=1
    if a[0] == 1 and t == 0:
        i = 1
        while i<=y+1:
            a[i] = 0
            i += 1
        i = 0
        t = 1
        continue

i = 0
while i <= y + t:
    m += a[y-i+1]*(10**(i))
    i+=1


print(m)
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=list(map(int, input().split()))
cnt=0
for i,v in enumerate(a):
	cnt += b[v-1]
	if i == 0:continue
	if v-1 == a[i-1]:
		#print(c[v-1])
		cnt += c[v-2]
print(cnt)

### FIXED CODE ###

n=int(input())

print(n**3)
num = int(input())
data = input().rstrip().split(' ')
count = 0
if data.count('P') > 0 or data.count('W') > 0 or data.count('G') > 0 or data.count('Y') > 0:
  count++

if count == 3:
  print('Three')
elif count == 4:
  print('Four')

### FIXED CODE ###

N = int(input())
s = input().split()
if "Y" in s:
    print("Four")
else:
    print("Three")
def f(a):
	q=a[:n];s=sum(q);heapify(q)
	for e in a[n:n-~n]:yield s;s+=e-heappushpop(q,e)
from heapq import*;r=raw_input;n,a=r(),map(int,r());print max(map(sum,zip(f(a),list(f([-e for e in a[::-1]]))[::-1])))

### FIXED CODE ###

from heapq import*
n,*a=map(int,open(0).read().split())
b=a[:n]
c=[-i for i in a[n:][::-1]]
d=c[:n]
e=c[n:]
heapify(b)
heapify(d)
s=sum(b)
t=sum(d)
red=[s]
blue=[t]
for i in range(n,n*2):
    s+=a[i]-heappushpop(b,a[i])
    t+=c[i]-heappushpop(d,c[i])
    red+=[s]
    blue+=[t]
print(max(map(sum,zip(red,blue[::-1]))))

#あｈｊｆｋぁｄｓｈｆｌｋじゃｇはｌｋｊｄｊｇｌｋ；あｊｄｇｌｋ；あｄｓｊｇｌ；あｊｓｄｇｌｋ；あｊｓｄｇｌ；かｓ
a, b, c, d = map(int, input().split())
while True:
	c -= b
	a -= d
    if c <= 0:
        print('Yes')
        break
    if a <= 0:
        print('No')
        break

### FIXED CODE ###

a, b, c, d = map(int, input().split())
while True:
    c -= b
    if c <= 0:
        print('Yes')
        break
    a -= d
    if a <= 0:
        print('No')
        break
import math
n = input()
a = list(map(int, input().split()))
i = 0
cnt = 0
while "A":
    if bin(a[i][0]) == 0:
        a[i] /= 2
        cnt += 1
    else :
        break
print(cnt)


### FIXED CODE ###

import math
n = input()
a = list(map(int, input().split()))
b  = 0
cnt = 0
while "loop":
    for num in a:
        if num % 2 == 1:
            b= 1
    if  b == 0:
            a = [ i	/2 for i in a]
            cnt += 1
    else:
        break
print(cnt)
import collections
n = (int)(input())
l = list(map(int,input().split()))
a = l[::2]
b=l[1::2]

a_c=collections.Counter(a).most_common()
b_c=collections.Counter(b).most_common()
if a_c[0][0]==b_c[0][0]:
    if a_c[0][1]==b_c[0][1]:
        print(n//2)
    elif a_c[0][1]>b_c[0][1]:
        if len(b_c)>1:
            print(n-a_c[0][1]-b_c[1][1])
        else:
            print(n-a_c[0][1])
    else:
        if len(a_c)>1:
            print(n-a_c[1][1]-b_c[0][1])
        else:
            print(n-b_c[0][1])
else:
    print(n-a_c[0][1]-b_c[0][1])


### FIXED CODE ###

s=str(input())
dst=s.translate({
    ord('1'):'9',
    ord('9'):'1',
    })
print(dst)
N = int(input())
A = list(map(int, input()))

print(sum(A) - N)

### FIXED CODE ###

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

print(sum(A) - N)
from itertools import product
s=input()
for b in list(product["+","-"],repeat=3):
    ans=s[0]+b[0]+s[1]+b[1]+s[2]+b[2]+s[3]
    if evel(ans)==7:
        print(ans+"7")
        break

### FIXED CODE ###

from itertools import product
s=input()
for b in list(product(["+","-"],repeat=3)):
    ans=s[0]+b[0]+s[1]+b[1]+s[2]+b[2]+s[3]
    if eval(ans)==7:
        print(ans+"=7")
        break
A, B=map(int, input(). split())
if (A*B)%2==1:
	print(“Yes”)
else:
	print(“No”)


### FIXED CODE ###

A, B=map(int, input(). split())
if A%2==1 and B%2==1:
	print("Yes")
else:
	print("No")
v='aiueo'
if c in v:print('vowel')
else:print('consonant')

### FIXED CODE ###

if input() in 'aiueo':print('vowel')
else:print('consonant')
import numpy as np
n, q = map(int, input().split())

e = np.eye(n+1, dtype=int)
for i in range(n-1):
    a, b = map(int, input().split())
    e[a][b] = 1

for i in reversed(range(2, n+1)):
    if e[i-1][i] == 1:
        e[i-1][i+1:] += e[i][i+1:]
    else:
        continue


point = np.zeros(n, dtype=int)
for i in range(q):
    p, x = map(int, input().split())
    point[p-1] += x

ans = np.dot(point, e[1:, 1:])
print(*ans)

### FIXED CODE ###

from collections import deque
n, q = map(int, input().split())
tree = [[] for _ in range(n+1)]
cnt = [0] * (n+1)

for _ in range(n-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

for _ in range(q):
    p, x = map(int, input().split())
    cnt[p] += x

queue = deque([1])
visited = {1}
while queue:
    now = queue.popleft()
    visited.add(now)
    for t in tree[now]:
        if t in visited:
            pass
        else:
            queue.append(t)
            cnt[t] += cnt[now]

print(*cnt[1:])
N=int(input())
A=list(map(int, input().split()))

ans=0
for i in range(N):
  if (i+1)%2==1 and a[i]%2==1:
    ans+=1
print(ans)

### FIXED CODE ###

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

ans=0
for i in range(N):
  if (i+1)%2==1 and A[i]%2==1:
    ans+=1
print(ans)
N = int(input())
A = list(map(int, input().split()))


diff = [A[i+1] - A[i] for i in range(N-1) if A[i+1]-A[i] != 0]
ans = 1
prev = diff[0]
id = 0
while(id < len(diff)-1):
    if (diff[id]*diff[id+1]) < 0:
        ans += 1
        id += 2
    else:
        id += 1
print(ans)


### FIXED CODE ###

N=int(input())
a=list(map(int,input().split()))
flag=0
ans=1
for i in range(1,N):
  if flag== 0:
    if a[i]>a[i-1]:
      flag=1
      continue
    elif a[i]<a[i-1]:
      flag=-1
      continue
    else:
      continue
  elif flag>0:
    if a[i]<a[i-1]:
      ans+=1
      flag=0
  else:
    if a[i]>a[i-1]:
      ans+=1
      flag=0
print(ans)
import numpy as np
N,M = (int(x) for x in input().split())
H   = np.array([int(x) for x in input().split()])
Way = np.zeros((N,N),dtype=bool)
for T in range(0,M):
    A,B = (int(x) for x in input().split())
    Way[A-1,B-1] = True
    Way[B-1,A-1] = True
    
Count = 0
for TT in range(0,N):
    TrueIndex = [Index for Index,Name in enumerate(Way[TT,:]) if Name==True]
    if np.all(H[TT]>H[TrueIndex]):
        Count = Count+1
print(Count)

### FIXED CODE ###

N,M = (int(x) for x in input().split())
H   = [int(x) for x in input().split()]
Way = [[] for I in range(N)]
for T in range(0,M):
    A,B = (int(x) for x in input().split())
    Way[A-1].append(B)
    Way[B-1].append(A)
    
Count = 0
for TT in range(0,N): 
    if all(H[TT]>Ele for Ele in [H[I-1] for I in Way[TT]]):
        Count = Count+1
print(Count)
s = input()
print(sorted(set([s[i:j+1] for i in range(len(s)) for j in range(i,len(s))]))[int(input())-1])

### FIXED CODE ###

s = input()
K = int(input()) # 1 <= K <= 5

alpha = "abcdefghijklmnopqrstuvwxyz"
substring = ''
L = []
for i in alpha:
    indeces = [key for key, x in enumerate(s) if x == i]
    for j in indeces:
        for k in range(j,j+K):
            substring += s[j:k+1] + ','
    L += substring.split(',')[:-1] 
    if len(set(L)) >= K:
        break
    substring = ""
print(sorted(set(L))[K-1])
n = list(input())
a = 0
for i in n:
  a += i
  
if a % 9 == 0:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

n = list(map(int, input()))
print("Yes" if sum(n) % 9 == 0 else "No")
def main():
    s = str(input())
    sLen = len(s)
    for i in range(sLen - 2):
        if s[i] == s[i + 1]:
            print(i + 1, i + 2)
            return
        elif s[i] == s[i + 2]:
            print(i + 1, i + 3)
            return
    if s[sLen - 2] == s[sLen - 1]:
        print(slen - 1, sLen)
        return

    print("-1 -1")


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    s = str(input())
    sLen = len(s)
    for i in range(sLen - 2):
        if s[i] == s[i + 1]:
            print(i + 1, i + 2)
            return
        elif s[i] == s[i + 2]:
            print(i + 1, i + 3)
            return
    if s[sLen - 2] == s[sLen - 1]:
        print(sLen - 1, sLen)
        return

    print("-1 -1")


if __name__ == "__main__":
    main()
'''input
6
1 2
1 3
1 4
1 5
1 6
'''
# A coding delight
from sys import stdin, stdout
import gc
gc.disable()
input = stdin.readline
from collections import defaultdict


def get_source():
	for i in graph:
		return i


def make(first, second):
	return str(first) + ' ' + str(second)


def dfs(node, visited, color, medges, mx_c):
	visited[node] = True
	c = 1
	for i in graph[node]:
		if i not in visited:
			if color[node] == c:
				c += 1
			color[i] = c
			medges[make(node, i)] = c
			medges[make(i, node)] = c
			mx_c[0] = max(mx_c[0], c)
			c += 1
			dfs(i, visited, color, medges, mx_c)


# main starts
graph = defaultdict(list)
n = int(input().strip())
edges = []
for _ in range(n - 1):
	u, v = list(map(int, input().split()))
	graph[u].append(v)
	graph[v].append(u)
	edges.append([u, v])

s = get_source()
color = dict()
visited = dict()
color[s] = 0
medges = dict()
mx_c =[0]
dfs(s, visited, color, medges, mx_c)

print(mx_c[0])
for i, j in edges:
	print(medges[make(i, j)])


### FIXED CODE ###

'''input
6
1 2
1 3
1 4
1 5
1 6
'''
# A coding delight
from sys import stdin, stdout
import gc
gc.disable()
input = stdin.readline
from collections import defaultdict
import sys, threading


def get_source(graph):
	for i in graph:
		return i


def make(first, second):
	return str(first) + ' ' + str(second)


def dfs(graph, node, visited, color, medges, mx_c):
	visited[node] = True
	c = 1
	for i in graph[node]:
		if i not in visited:
			if color[node] == c:
				c += 1
			color[i] = c
			medges[make(node, i)] = c
			medges[make(i, node)] = c
			mx_c[0] = max(mx_c[0], c)
			c += 1
			dfs(graph, i, visited, color, medges, mx_c)


# main starts
def main():
	graph = defaultdict(list)
	n = int(input().strip())
	edges = []
	for _ in range(n - 1):
		u, v = list(map(int, input().split()))
		graph[u].append(v)
		graph[v].append(u)
		edges.append([u, v])

	s = get_source(graph)
	color = dict()
	visited = dict()
	color[s] = 0
	medges = dict()
	mx_c =[0]
	dfs(graph, s, visited, color, medges, mx_c)

	print(mx_c[0])
	for i, j in edges:
		print(medges[make(i, j)])


if __name__ == '__main__':
	sys.setrecursionlimit(100005)
	threading.stack_size(1 << 27)
	thread = threading.Thread(target = main)
	thread.start()
S = list(int(input()))

c = 0
for i in range(3):
  if S[i] != S[i+1]:
    c += 1
if c == 3:
  print('Good')
else:
  print('Bad')


### FIXED CODE ###

S = list(input())

c = 0
for i in range(3):
  if S[i] != S[i+1]:
    c += 1
if c == 3:
  print('Good')
else:
  print('Bad')
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 8)


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

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


# https://qiita.com/greenteabiscuit/items/31c46ab3ceac07e749d2


n, m = LI()
graph = [[] for _ in range(m)]
v = [False] * n

for i in range(m):
    a, b = LI()
    graph[a - 1].append(b)
    graph[b - 1].append(a)


def dfs(now, depth):
    if v[now - 1]:
        return 0
    if depth == n-1:
        return 1
    ans = 0
    v[now - 1] = True
    for node in graph[now - 1]:
        ans += dfs(node, depth+1)

    v[now - 1] = False
    # ここが大事.上で探索の一つが終わるからリセットしている.

    return ans


print(dfs(1, 0))


### FIXED CODE ###

#Nはノード数、Mはエッジ数
N, M = map(int, input().split())

path_matrix = []

#無向行列の初期化
for n in range(N):
    path_matrix.append([False] * N)

#まず無向グラフを表す行列を作る
for m in range(M):
    line = map(int, input().split())
    paths = [x - 1 for x in line]
    path_matrix[paths[0]][paths[1]] = True
    path_matrix[paths[1]][paths[0]] = True

#最初はvisited、つまり訪問したことのあるノードはひとつもないので、Falseにする
visited = [False] * N


#再帰関数、ここが難しいかもしれない。
def dfs(now, depth):
    if visited[now]:
        return 0
    if depth == N - 1:
        return 1

    visited[now] = True
    total_paths = 0
    for i in range(0, N):
        if path_matrix[now][i]:
            total_paths += dfs(i, depth + 1)

    visited[now] = False

    return total_paths

print(dfs(0, 0))
import numpy as np

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

l = n - k + 1
lis = [0]*l
#0, 1, 2
for i in range(l):
  z = np.prod(a[i:i+k])
  lis[i] = z
print(lis)
for i in range(n - k):
  if lis[i] < lis[i + 1]:
    print("Yes")
  else:
    print("No")

### FIXED CODE ###

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

#0, 1
for i in range(n - k):
  if a[i] < a[i + k]:
    print("Yes")
  else:
    print("No")
s=list(input())
k=int(input())

for i in range(len(s)):
    num_al=ord(s[i])
    a_=123-num_al
    if k==0:break
    if s[i]=='a' and i!=len(s)-1:continue

    if a_<=k and i!=len(s)-1:
        k-=a_
        s[i]='a'
    elif a_>k and i<len(s)-1:continue
    else:
        s[i]=chr(num_al+k) if num_al+k<=122 else chr(num_al+k-122)
        k=0
print(''.join(s))

### FIXED CODE ###

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

for i in range(len(s)):
    if k==0:break

    num=ord(s[i])
    ch_num=123-num
    if i==len(s)-1:
        s[i]=chr(97+(num+k-97)%26) #if num+k>122 else chr(num+k)
        #print(97+(num+k-97)%26)
        k=0
        break
    elif s[i]=='a':continue
    elif ch_num<=k:
        s[i]='a'
        k-=ch_num
print(''.join(s))
import itertools
import sys
import numpy as np
from collections import Counter
import bisect

sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
M = 1000000007
N = int(input())
left = list(map(int, input().split()))

indices = Counter()
for i, x in enumerate(left):
    indices[x] += 1


def dp(t, n1, n2, n3):
    cached = t.get((n1, n2, n3))
    if cached is not None:
        return cached
    remaining = n1 + n2 + n3
    assert remaining > 0
    last_cnt = left[remaining - 1] + 1
    res = 0
    if last_cnt == n1:
        res += dp(t, n1 - 1, n2, n3)
        res %= M
    if last_cnt == n2:
        res += dp(t, n1, n2 - 1, n3)
        res %= M
    if last_cnt == n3:
        res += dp(t, n1, n2, n3 - 1)
        res %= M
    # print(f"{remaining}: ({n1},{n2},{n3}) => {res}")
    if n1 < 200 and n2 < 200 and n3 < 200:
        t[n1, n2, n3] = res
    return res


def solve():
    h = [0, 0, 0]
    for i in range(N):
        k = indices[i]
        if k == 3:
            h[0] = h[1] = h[2] = i + 1
        elif k == 2:
            h[0] = h[1] = i + 1
        elif k == 1:
            h[0] = i + 1
        else:
            break
    assert sum(h) == N
    t = dict()
    t[0, 0, 0] = 1
    res = dp(t, h[0], h[1], h[2])
    return res * len(set(itertools.permutations(h))) % M


print(solve())


### FIXED CODE ###

import itertools
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 9)
M = 1000000007
N = int(sys.stdin.readline())
left = list(map(int, sys.stdin.read().split()))
counter = Counter(left)


def dp(t, ns):
    cached = t.get(ns)
    if cached is not None:
        return cached
    remaining = sum(ns)
    assert remaining > 0
    last_cnt = left[remaining - 1] + 1
    n1, n2, n3 = ns
    res = 0
    if last_cnt == n1:
        res += dp(t, tuple(sorted([n1 - 1, n2, n3])))
        res %= M
    if last_cnt == n2:
        res += dp(t, tuple(sorted([n1, n2 - 1, n3])))
        res %= M
    if last_cnt == n3:
        res += dp(t, tuple(sorted([n1, n2, n3 - 1])))
        res %= M
    # print(f"{remaining}: ({n1},{n2},{n3}) => {res}")
    t[ns] = res
    return res


def solve():
    h = [0, 0, 0]
    for i in range(N):
        k = counter[i]
        if k == 3:
            h[0] = h[1] = h[2] = i + 1
        elif k == 2:
            h[0] = h[1] = i + 1
        elif k == 1:
            h[0] = i + 1
        else:
            break
    if sum(h) != N:
        return 0
    t = dict()
    t[0, 0, 0] = 1
    res = dp(t, tuple(sorted(h)))
    return (res * len(set(itertools.permutations(h)))) % M


print(solve())