Harryxun/stf_run huggingface dataset:
n, k = map(int, input().split()) 
a_list = list(map(int, input().split())) 

rireki = [0] * (n+10)
curr_c = 1
rireki[1] = 0

no_loop_count = k
loop_cnt = 0

mugen = False
for i in range(n):
    next_c = a_list[curr_c-1]
    # print(i, curr_c, next_c)
    if next_c == curr_c:
        mugen = True
    if next_c == 1:
        no_loop_count = 0
        loop_cnt = i + 1
        break
    elif rireki[next_c] == 0:
        rireki[next_c] = i+1
    else:
        # print(next_c)
        no_loop_count = rireki[next_c] -1
        loop_cnt = i - no_loop_count
        break
    curr_c = next_c

if loop_cnt ==0:
    loop_cnt = 1



if not mugen:
    if k <= no_loop_count or loop_cnt == 0:
        ans = rireki.index(k)
    else:
        # print('k',k)
        # print('no', no_loop_count)
        # print('lo', loop_cnt)
        ind = (k-1-no_loop_count)%loop_cnt +1
        rireki_fix = [i-no_loop_count for i in rireki]
        # print(ind, 'ind')
        ans = rireki_fix.index(ind)
        # print(rireki_fix)
        print(ans)

### FIXED CODE ###

def main():
    n, k = map(int, input().split()) 
    al = list(map(int, input().split())) 
    city_l = [1]
    city_s = set([1])
    loop_city_l = []
    curr_city = 1
    cnt = 0
    for i in range(1,k+1):
        next_c = al[curr_city-1]
        if next_c in city_s:
            cnt = i
            first_city = city_l.index(next_c)
            loop_city_l = city_l[first_city:]
            break
        else:
            city_s.add(next_c)
            city_l.append(next_c)
        curr_city = next_c
    else:
        print(curr_city)
        return

    # print(loop_city_l)
    remained = k-cnt
    last_pos = remained%len(loop_city_l)
    print(loop_city_l[last_pos])

if __name__ == "__main__":
    main()
n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[]
  y=[]
  for j in range(a):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  

c=0
for i in range(n):
  l=[1]*n
  for j in range(i,n-i):
    if l[j]==0:continue
    for k in range(A[j]):
      b=X[j][k]
      #l[b] *= Y[j][k]

if c < l.count(1):
  c=l.count(1) 
  
        
  
print(c)  
   

### FIXED CODE ###

n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[0]*a
  y=[0]*a
  for j in range(a):
    x[j],y[j]=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
s=0
for i in range(2**n):
  c=0
  d=0
  B=[0]*n
  for j in range(n):
    if((i >> j) & 1):
      c=c+1
      B[j]=1
  for k in range(n):
    if B[k]==1:
      for j in range(A[k]):
        if Y[k][j]!=B[X[k][j]-1]:
          d=-1
          break
    if d<0:
      break
  if s<c and d==0:
    s=c
      
      
print(s)
N = int(input())
D = {i: 0 for i in range(100)}
for i in range(1, N+1):
    if i % 10 != 0:
        s = str(i)
        D[int(s[0])*10+int(s[-1])] += 1
S = 0
for i in range(10):
    for j in range(10):
        S += D[i*10+j] * D[j*10+i]
print(S)


### FIXED CODE ###

N, M = map(int, input().split())
if N == M:
  print('Yes')
else:
  print('No')
import fractions
from functools import reduce

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

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

a_set = list(set(a))

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

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

lcm = lcm_list(a_set)

sum = lcm / 2
ans = 0
while sum <= M:
    if sum > M:
        break
    sum += lcm
    ans += 1
print(ans)

### FIXED CODE ###

import fractions
from functools import reduce

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

def f(x):
    res = 0
    while x % 2 == 0:
        x //= 2
        res += 1
    return res  

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

for i in range(len(a)):
    if a[i] % 2 == 1:
        print(0)
        exit()
    a[i] //= 2

t = f(a[0])
for i in range(len(a)):
    if f(a[i]) != t:
        print(0)
        exit()
    a[i] >>= t #a[i] //= 2 ** t
M >>= t

l = 1
for i in range(N):
    l = lcm(l, a[i])
    if l > M:
        print(0)
        exit()

M //= l
ans = (M+1) // 2
print(ans)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-03-07 21:21:27 +0900
# LastModified: 2020-03-07 22:31:57 +0900
#




def main():
    A,B = map(int,input().split())
    a_min = (A/0.08)
    a_max = (A+1)/0.08
    b_min = (B/0.1)
    b_max = (B+1)/0.1
    if a_min!=int(a_min):
        a_min = int(A/0.08)+1
    if b_min!=int(b_min):
        b_min = int(B/0.1)+1
    s_a = [i for i in range(int(a_min),int(a_max))]
    s_b = [i for i in range(int(b_min),int(b_max))]
    for common in s_a:
        if common in s_b:
            print(common)
            return
    print(-1)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B
# CreatedDate:  2020-08-30 14:36:32 +0900
# LastModified: 2020-08-30 14:45:15 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    n, a, b = map(int, input().split())
    tmp = n - n // (a+b) * (a+b)
    ans = n//(a+b) * a
    if tmp <= a:
        print(ans+tmp)
    else:
        print(ans+a)


if __name__ == "__main__":
    main()
n = input()
if n==1:
    print("Hello World")
else:
    A = int(input())
    B = int(input())
    print(A+B)

### FIXED CODE ###

N = int(input())
if N==1:
	print('Hello World')
else:
	A = int(input())
	B = int(input())
	print(A+B)
s=input()
if s.sort() == 'abc':
  print('Yes')
else:
  print('No')

### FIXED CODE ###

s=input()
if 'a' in s and 'b' in s and 'c' in s:
  print('Yes')
else:
  print('No')
S = input()
T = input()

N = len(S)
M = len(T)

i_a = 0
for i in reversed(range(N-M+1)):
    ans = 0
    for j in range(M):
        if T[j] == S[i+j] or S[i+j] == '?':
            ans += 1
        else:
            break
    if ans == M:
        for k in range(N):
            if k == i:
                print(T,end='')
            elif k < i or i + M - 1 < k:
                if S[k] == '?':
                    print('a',end='')
                else:
                    print(S[k],end='')
            exit()
    if i == 0:
        print('UNRESTORABLE')
        eixt()
    

### FIXED CODE ###

S = input()
T = input()

N = len(S)
M = len(T)

i_a = 0
for i in reversed(range(N-M+1)):
    ans = 0
    for j in range(M+1):
        if j == M:
            print((S[:i]+T+S[i+M:]).replace('?','a'))
            exit()
        if T[j] == S[i+j] or S[i+j] == '?':
            continue
        else:
            break

print('UNRESTORABLE')
s = input()
t = input()
flag = True
if(len(s) = len(t)-1):
  x = len(s)
  for i in range(x):
    if s[i]!=t[i]:
      flag = False
if(flag):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s = str(input())
t = str(input())
flag = True
if(len(s) == len(t)-1):
  x = len(s)
  for i in range(x):
    if s[i]!=t[i]:
      flag = False
else:
    flag = False
if(flag):
  print("Yes")
else:
  print("No")
import math

N, X = map(int,input().split())
arr = list(map(int,input().split()))

for i in range(len(arr)):
    arr[i] -= X
    
df = []
for i in range(1, len(arr)):
    df.append(arr[i] - arr[i-1])

if(N == 1):
    df.append(arr[0])

ans = 0
for num in df:
    ans = math.gcd(ans, num)
    
print(ans)

### FIXED CODE ###

import fractions
from functools import reduce

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

for i in range(len(a)):
	a[i] = abs(a[i] - x)

print(reduce(fractions.gcd, a))
a = map(int,input(),split())
print((sorted(a))[0:2])

### FIXED CODE ###

a = map(int,input().split())
print(sum((sorted(a))[0:2]))
X, Y = map(int, input().split())
mod = 10 ** 9 + 7


def prime_mod(n, m):
    S = 1
    for i in range(1, n+1):
        S *= i
        S %= m
    return S


def prime_inv_mod(n, m):
    invs = [0] * (n + 1)
    invs[1] = 1
    for i in range(2, n + 1):
        invs[i] = m - invs[m % i] * (m//i) % m
    return invs


a = 2 * Y - X
b = 2 * X - Y
if a % 3 != 0 or b % 3 != 0:
    print(0)
else:
    a //= 3
    b //= 3
    upper = prime_mod(a+b, mod)
    mod_inv = prime_inv_mod(max(a, b), mod)

    lower1 = 1
    for i in range(1, max(a, b)+1):
        lower1 *= mod_inv[i]
        lower1 %= mod
        if i == min(a, b):
            lower2 = lower1
    print((upper*lower1*lower2) % mod)


### FIXED CODE ###


X, Y = map(int, input().split())
mod = 10 ** 9 + 7


def prime_mod(n, m):
    S = 1
    for i in range(1, n+1):
        S *= i
        S %= m
    return S


def prime_inv_mod(n, m):
    invs = [0] * (n + 1)
    invs[1] = 1
    for i in range(2, n + 1):
        invs[i] = m - invs[m % i] * (m//i) % m
    return invs


a = 2 * Y - X
b = 2 * X - Y
if a % 3 != 0 or b % 3 != 0 or a < 0 or b < 0:
    print(0)
else:
    a //= 3
    b //= 3
    upper = prime_mod(a+b, mod)
    mod_inv = prime_inv_mod(max(a, b), mod)

    lower1 = 1
    lower2 = 1
    for i in range(1, a + 1):
        lower1 *= mod_inv[i]
        lower1 %= mod
    for i in range(1, b + 1):
        lower2 *= mod_inv[i]
        lower2 %= mod

    print((upper*lower1*lower2) % mod)
if int(input()) < 1000:
    print('ABC')
else:
    print('ABD')


### FIXED CODE ###

a, b = map(int, input().split())
n = b-a #右の塔はｎ本目
hidari = n*(n-1) / 2 #右（ｎ－１本目）の塔の高さ
ans = hidari - a
print(int(ans))
from fraction import gcd
a,b,c,d=map(int,input().split())
if abs(c-a)==0 or abs(d-b)==0:
  print(0)
else:
  x,y=abs(c-a),abs(d-b)
  g=gcd(x,y)
  print(x+y-g)

### FIXED CODE ###

from fractions import gcd
a,b,c,d=map(int,input().split())
if abs(c-a)==0 or abs(d-b)==0:
  print(0)
else:
  x,y=abs(c-a),abs(d-b)
  g=gcd(x,y)
  print(x+y-g)
a, b = map(int, input())
ans = (a+b)%24
print(ans)

### FIXED CODE ###

a, b = map(int, input().split())
ans = (a+b)%24
print(ans)
import sympy

n = int(input())

sum_v = 0
for i in range(1, n):
    v = (n - 1) // i
    sum_v += v

print(sum_v)

### FIXED CODE ###

n = int(input())

sum_v = 0
for i in range(1, n):
    v = (n - 1) // i
    sum_v += v

print(sum_v)
print("Yes" if [4*x+11*y for x in range(26) for y in range(9)].count(a) else "NO")


### FIXED CODE ###

a=int(input())
print("Yes" if [4*x+7*y for x in range(101) for y in range(101)].count(a) else "No")
N, K = list(map(int, input().split()))

Alist = [int(i) for i in input().split(' ')]
import math

#print(Alist)
my_list = [9,8,7,4,7,1,3]

Alist=sorted(Alist, reverse=True)

def insert_list(list, value):
	start=0
	end=len(list)-1

	if value<list[len(list)-1]:
		list.insert(len(list), value)
		return list
	if value>list[0]:
		list.insert(0, value)
		return list
	while True:
		mid_point=int((start+end)/2)
		if value>list[mid_point]:
			if (end-start)<2:
				list.insert(start, value)
				return list
			else:
				end=mid_point
		else:
			if (end-start)<2:
				list.insert(end, value)
				return list
			else:
				start=mid_point

for i in range(K):
   Alist[0]=Alist[0]/2
   value=Alist.pop(0)
   Alist=insert_list(Alist,value)
sum=0
#print(Alist)
for i in Alist:
   sum+=math.floor(i) 
print(int(sum))

### FIXED CODE ###

from heapq import heappush, heappop
import math
 
N,M = [int(i) for i in input().split(' ')]
inputList = [int(i) for i in input().split(' ')]
list = []
 
for i in inputList:
    heappush(list, -i)
 
for _ in range(M):
    heappush(list, math.ceil(heappop(list)/2))
    
print(-sum(list))
N = int(input())
A = list(map(int, input().split())) 
s = [0]*(N-1)
 
for n in range(N-1):
  s[n] = A[n] - A[n+1]
  if s[n] <= 0: 
    continue
  else:
    A[n+1] += s[n]

print(sum(int(s)))

### FIXED CODE ###

import math
N, X, T = map(int, input().split())

print(math.ceil(N / X)*T)
from collections import deque 
n,m = list(map(int,input().split()))
e = [[] for _ in range(m+1)]
for i in range(m):
    a,b = list(map(int,input().split()))
    e[a].append(b)
    e[b].append(a)

q = deque()
q.append(1)

s = [[(10**5+1) for _ in range(2)] for _ in range(n+1)]
s[1][0] = 0
while len(q):
    node = q.pop()
    step = s[node][0]
    for i in range(len(e[node])):
        nex = e[node][i]

        if s[nex][0] > step +1:
            q.append(nex)
            s[nex][0] = step + 1
            s[nex][1] = node
# print(s,t,e)
print("Yes")
for i in range(2,n+1):
    print(s[i][1])

### FIXED CODE ###

from collections import deque

n,m = list(map(int,input().split()))
e = [[] for _ in range(n+1)]

for i in range(m):
    a,b = list(map(int,input().split()))
    e[a].append(b)
    e[b].append(a)
q = deque()
q.append(1)
t = [-1 for _ in range(n+1)]

while len(q):
    node = q.popleft()

    for i in range(len(e[node])):
        nex = e[node][i]
        if t[nex] == -1:
            q.append(nex)
            t[nex] = node
print("Yes")
for i in range(2,n+1):
    print(t[i])
a,b,c=map(int,input())
if (b*10+c)%4==0:print("YES")
else:print("NO")

### FIXED CODE ###

a,b,c=map(int,input().split())
if (b*10+c)%4==0:print("YES")
else:print("NO")
N = int(input())
fmax = int(N/4)
smax = int(N/7)
for i in range(fmax +1):
  for j in range(smax + 1):
	if 4*i + 7*j == N:
	  print("Yes")
	  exit()
print("No")


### FIXED CODE ###

N = int(input())
fmax = int(N/4)+1
smax = int(N/7)+1
for i in range(fmax+1):
  for j in range(smax+1):
    if (4*i+7*j) == N:
      print('Yes')
      exit()
print('No')
def isinteger(x):
    if isinstance(x, float):
        return x == int(x)


import numpy as np
N,D = list(map(int,input().split()))
 
lis =[list(map(int,input().split())) for i in range(N)]
lis_np = np.array(lis)
counter = 0
for i in range(N-1):
    for j in range(i+1,N):
        kyori = (sum((lis_np[:][i] - lis_np[:][j])**2))**0.5
        if isinteger(kyori):
            counter += 1
print(counter)

### FIXED CODE ###

import numpy as np
N,D = list(map(int,input().split()))
 
lis =[list(map(int,input().split())) for i in range(N)]
lis_np = np.array(lis)
counter = 0
for i in range(N-1):
    for j in range(i+1,N):
        kyori = (sum((lis_np[:][i] - lis_np[:][j])**2))**0.5
        if kyori == int(kyori):
            counter += 1
        
print(counter)
#python 2.7
n,m=map(int,input().split())
ab=[list(map(int,input().split()))]
ab=sorted(ab,key=lambda x:x[0])
res=ans=0
for i in range(n):
  if res+ab[i][1]>=m:
    ans+=(ab[i][0])*(m-res)
    break
  else:
    ans+=(ab[i][0])*ab[i][1]
    res+=ab[i][1]
print(ans)

### FIXED CODE ###

#import sys
#import numpy as np
#import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
n,m=map(int,input().split())
b=[list(map(int,input().split())) for _ in range(n)]
res=0
ans=0
b.sort(key=lambda x: x[0])
for i in range(n):
    if res+b[i][1]<=m:
        ans+=b[i][0]*b[i][1]
        res+=b[i][1]
    else:
        ans+=b[i][0]*(m-res)
        break
print(ans)
s[1] = "a"
while s[1] != "?":
    s = raw_input().split()
    if s[1] == "?":
        break
    a = int(s[0])
    b = int(s[2])
    if s[1] == "+":
        print a + b
    if s[1] =="-":
        print a - b
    if s[1] == "*":
        print a * b
    if s[1] == "/":
        print a / b

### FIXED CODE ###

while True:
    s = raw_input().split()
    a = int(s[0])
    b = int(s[2])
    if s[1] == "?":
        break
    elif s[1] == '+':
        print a + b
    elif s[1] == '-':
        print a - b
    elif s[1] == '*':
        print a * b
    elif s[1] == '/':
        print a / b
def test():
    nums = list(map(int, list(input())))
    for i in range(2 ** 3):
        ans = nums[0]
        res = f'{nums[0]}'
        for j in range(3):
            if (i >> j) & 1:
                ans += nums[j+1]
                res += f'+{nums[j+1]}'
            else:
                ans -= nums[j+1]
                res += f'-{nums[j+1]}'
        if ans == 7:
            print(f'{res}=7')
            exit(1)

if __name__ == '__main__':
    test()

### FIXED CODE ###

def test():
    nums = list(map(int, list(input())))
    end = False
    for i in range(2 ** 3):
        ans = nums[0]
        res = '{}'.format(nums[0])
        for j in range(3):
            if (i >> j) & 1:
                ans += nums[j+1]
                res += '+{}'.format(nums[j+1])
            else:
                ans -= nums[j+1]
                res += '-{}'.format(nums[j+1])
        if ans == 7:
            end = True
            break
    print('{}=7'.format(res))

if __name__ == '__main__':
    test()
h, w = map(int, input().split())
mat = []
count = 0
for i in range(h):
  a = list(map(int, input().split()))
  mat.append(a)
for i in range(h):
  b = list(map(int, input().split()))
  for j in range(w):
    mat[i][j] = abs(mat[i][j]-b[j])
    count += mat[i][j]

dp = [[[False]*(count) for i in range(w)] for k in range(h)]
dp[0][0][mat[0][0]] = True
for y in range(h):
  for x in range(w):
      for k in range(count):
        if x > 0 and dp[y][x-1][k] or y > 0 and dp[y-1][x][k]:
          d = dp[y][x]
          d[k+mat[y][x]] = True
          d[abs(k-mat[y][x])] = True

for k in range(count):
  if dp[h-1][w-1][k]:
    print(k)
    exit()


### FIXED CODE ###

h, w = map(int, input().split())
mat = []
for i in range(h):
  a = list(map(int, input().split()))
  mat.append(a)
for i in range(h):
  b = list(map(int, input().split()))
  for j in range(w):
    mat[i][j] = abs(mat[i][j]-b[j])
m = max(map(max, mat))
dp = [[0b0 for i in range(w)] for k in range(h)]
dp[0][0] |= 0b1 << mat[0][0]
for y in range(h):
  for x in range(w):
        if x > 0:
          dp[y][x] |= dp[y][x-1] << mat[y][x]
          dp[y][x] |= dp[y][x-1] >> mat[y][x]
          anded = dp[y][x-1] & int('1'*(mat[y][x]+1), 2)
          reverse = format(anded, "0"+str(mat[y][x]+1)+"b")[::-1]

          dp[y][x] |= int(reverse, 2)
        if y > 0:
          dp[y][x] |= dp[y-1][x] << mat[y][x]
          dp[y][x] |= dp[y-1][x] >> mat[y][x]
          anded = dp[y-1][x] & int('1'*(mat[y][x]+1), 2)
          reverse = format(anded, "0"+str(mat[y][x]+1)+"b")[::-1]

          dp[y][x] |= int(reverse, 2)
        #print(bin(dp[y][x]))

keta = 0
while dp[h-1][w-1] % 2 == 0:
  keta += 1
  dp[h-1][w-1] //= 2
print(keta)
from collections import deque
s = input()
q_ = int(input())
query = [input().split() for _ in range(q_)]
l = deque([s])

for q in query:
    if q[0] == '1':
        l = [''.join(l)[::-1]]
    elif q[0] == '2':
        if q[1] == '1':
            l.appendleft(q[2])
        else:
            l.append(q[2])

print(''.join(l))

### FIXED CODE ###

from collections import deque
import copy
s = input()
q_ = int(input())
query = [input().split() for _ in range(q_)]
l = deque(s)
flag = 0

for q in query:
    if q[0] == '1':
        flag += 1
        continue
    elif q[0] == '2':
        if (int(q[1]) + flag) % 2 == 1:
            l.appendleft(q[2])
        else:
            l.append(q[2])

if flag % 2 == 1:
    l.reverse()

print(''.join(l))
n = int(input())

if n == 1:
    print("Hello World")
else:
    a, b = map(int, input().split())
    ans = a+b
    print(ans)
    

### FIXED CODE ###

n = int(input())

if n == 1:
    print("Hello World")
elif n ==2:
    a = int(input())
    b = int(input())
    ans = a+b
    print(ans)
numMultiples=0
S=input()
N=len(S)
seenRemainders=[set()]*(100000)
for i in range(N):
    remainder = 0
    prefixesFound = 0
    for j in range(i,N):
        remainder = (10 * remainder + int (S[j]) ) % 2019
        # if remainder in seenRemainders[j]:
        #     break
        seenRemainders[j].add(remainder)
        if remainder == 0:
            prefixesFound+=1
    numMultiples += prefixesFound * (prefixesFound + 1) / 2
print(int(numMultiples))

### FIXED CODE ###

S=input()[::-1]
l=len(S)
t=0
p=0
 
ss=[0]*2019
ss[0]=1
d=1
for i in S:
    p=(p+int(i)*d)%2019
    d*=10
    d%=2019
    ss[p]+=1
 
for c in ss:
    t+=c*(c-1)//2
print(t)
#n = int(input())
x, y = map(int, input().split())
#l = list(map(int, input().split()))
#s = input()
ans = "Yes"
for i in range(x+1):
    if 2*i+4*x == y:
        ans = "No"

print(ans)


### FIXED CODE ###

#n = int(input())
#n, k = map(int, input().split())
l = list(map(int, input().split()))
#s = input()

for i in range(len(l)):
    if l[i] == 0:
        print (i+1)
N=input()
def digitsum(N) :
  s = str(N)
  array = list(map(int, list(s)))
  T = sum(array) 
  return T

U = digitsum(N)

if N % U ==0 :
  print("Yes")
else:
  print("No")

### FIXED CODE ###

N=int(input())
def digitsum(N) :
  s = str(N)
  array = list(map(int, list(s)))
  T = sum(array) 
  return T

U = digitsum(N)

if N % U ==0 :
  print("Yes")
else:
  print("No")
S,T = input().split()
A,B = map(int,input().split())
U = input()

if S == U :
    print(f"{A-1} {B}")
else :
    print(f"{A} {B-1}")

### FIXED CODE ###

S,T = input().split()
A,B = map(int,input().split())
U = input()

if S == U :
    print("{} {}".format(A-1,B))
else :
    print("{} {}".format(A,B-1))
N = int(input())

sum_list = []

def findSumOfDigit(n):
    s = 0
    while(n > 0):
        s += n % 10
        n = int(n / 10)N = int(input())

sum_list = []

def findSumOfDigit(n):
    s = 0
    while(n > 0):
        s += n % 10
        n = int(n / 10)
    return s

for a in range(1, N-1):
    b = N - a
    sum_list.append(findSumOfDigit(a) + findSumOfDigit(b))

print(min(sum_list))

    return s

for a in range(2, N):
    b = N - a
    sum_list.append(findSumOfDigit(a) + findSumOfDigit(b))

print(min(sum_list))


### FIXED CODE ###

N = int(input())

sum_list = []

def findSumOfDigit(n):
    s = 0
    while(n > 0):
        s += n % 10
        n = int(n / 10)
    return s

for a in range(1, N):
    b = N - a
    sum_list.append(findSumOfDigit(a) + findSumOfDigit(b))

print(min(sum_list))
a, v = [int(i) for i in input().split()]
b, w = [int(i) for i in input().split()]
t = int(input())
if abs(a-b)/abs(v-w) <= t:
  print("YES")
else:
  print("NO")a, v = [int(i) for i in input().split()]
b, w = [int(i) for i in input().split()]
t = int(input())
if (v-w) > 0 and abs(a-b)/abs(v-w) <= t:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

a, v = [int(i) for i in input().split()]
b, w = [int(i) for i in input().split()]
t = int(input())
if (v-w) > 0 and abs(a-b)/abs(v-w) <= t:
  print("YES")
else:
  print("NO")
import sys
inputs = sys.stdin.readlines()
from collections import Counter

n = int(inputs[0])
D = list(map(int, inputs[1].split()))
MOD = 998244353
cnt = Counter(D)
if (D[0] != 0 or c[0] > 1):
    print(0)
else:
    ans = 1
    for i in range(1, max(D)+1):
        ans *= pow(cnt[i-1], cnt[i], MOD) % MOD
    print(ans)

### FIXED CODE ###

from collections import Counter
inputs = open(0).readlines()

n = int(inputs[0])
*D, = map(int, inputs[1].split())
mod = 998244353

nbs = [0] * (max(D)+1)
for k, v in Counter(D).items():
    nbs[k] = v

if D[0] != 0 or nbs[0] != 1:
    print(0)
else:
    ans = 1
    for n0, n1 in zip(nbs, nbs[1:]):
        ans = ans * pow(n0, n1, mod) % mod
    print(ans)