Harryxun/stf_run huggingface dataset:
n=int(input())
p=map(int, input().split())
q=map(int, input().split())

import math

a=0
for i in range(n-1):
  a+=(p[i]-1) * math.factorial(n-1-i)
b=0
for i in range(n-1):
  b+=(p[i]-1) * math.factorial(n-1-i)
  
print(abs(a-b))


### FIXED CODE ###

from itertools import permutations
n=int(input())
v=list(permutations(range(1,n+1),n))
print(abs(v.index(tuple(map(int,input().split())))-v.index(tuple(map(int,input().split())))))
N = int(input())
S = input()
K = int(input())
for i in range(N):
    if S[i] != S[K]:
        S = S[:i] + '*' + S[(i+1):]
print(S)

### FIXED CODE ###

N = int(input())
S = input()
K = int(input())
for i in range(N):
    if S[i] != S[K-1]:
        S = S[:i] + '*' + S[(i+1):]
print(S)
a,b = map(int,input().split())
ans =-1
for i in range(10000,-1,-1):
  money0 = int(i*0.08)
  money1= int(i*0.1)
  if money0==a and money1==b:
    
print(ans)

### FIXED CODE ###

a,b = map(int,input().split())
ans =-1
for i in range(10000,-1,-1):
  money0 = int(i*0.08)
  money1= int(i*0.1)
  if money0==a and money1==b:
    ans = i
print(ans)
arr = (list(input().split('\r\n')))
print('{}',arr[0][0] + arr[1][1] + arr[2][2])

### FIXED CODE ###

arr = []
for i in range(3):
    arr.append(input())
print(arr[0][0] + arr[1][1] + arr[2][2])
n i = map(int,input().split())
print(n - i + 1)

### FIXED CODE ###

n, i = map(int,input().split())
print((n - i) + 1)
n,m,l = map(int,input().split(" "))
Ns = input().split(" ")
N = [int (n) for n in Ns]
Ms = input().split(" ")
M = [int(n) for n in Ms]
#print(n,m,l)
#print(N,M)
i = 0
j = 0
total = 0
cnt = 0
while total <= l:
  #print(i,j,total,cnt)
  if  i == n and j == m:
    break
  elif i < n and j == m:
    if total + N[i] <= l:
      total = total + N[i]
      i = i+1
      cnt = cnt + 1
    else:
      break
  elif i == n and j < m:
    if total + M[i] <= l:
      total = total + M[j]
      j = j+1
      cnt = cnt +1
    else:
      break
  elif i < n and j < m and (total+N[i] <= l or total+M[j] <= l):
    if N[i] <= M[j]:
      total = total + N[i]
      i = i+1
      cnt = cnt +1
    elif N[i] > M[j]:
      total = total + M[j]
      j = j+1
      cnt = cnt +1
  else:
    break
print(cnt)#,i,j,total,n,m,l)

### FIXED CODE ###

N,M,K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a,b = [0],[0]
for i in range(N):
  a.append(a[i]+A[i])
for j in range(M):
  b.append(b[j]+B[j])
ans = 0
#print(a,b,N+1)
j = M
for i in range(N+1):
  if a[i] > K:
    break

  while K - a[i] < b[j]:
    j = j-1
  ans = max(ans,i+j)

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

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

power=[0]*n
for i in range(n):
  while a[i]%2==0:
    a[i]//=2
    power[i]+=1
    
if power.count(power[0])==n:
  x=1
  for i in range(n):
    x=lcm(x,a[i]//2)

  print((m+x)//(2*x))
else:
  print(0)

### FIXED CODE ###

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

import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
x=1
for i in range(n):
  x=lcm(x,a[i]//2)

power=[0]*n
for i in range(n):
  while a[i]%2==0:
    a[i]//=2
    power[i]+=1
    
if power.count(power[0])==n:  
  print((m+x)//(2*x))
else:
  print(0)
a = int(input())
b = float(input)
b_int = int(b*100)

ans = a*b_int//100
print(ans

### FIXED CODE ###

a, b = map(str, input().split())
a = int(a)
b = int(b.replace('.', ''))

ans = (a*b)//100

print(ans)
a = int(input())

r = a * a * 3,14
r2 = a * 2 * 3.14

print("%.10f %.10f" % (r, r2))

### FIXED CODE ###

import math

a = float(input())

r = a * a * math.pi
r2 = a * 2 * math.pi

print("%.10f %.10f" % (r, r2))
K = int(input())
A, B = map(int,input().split())
tmp = A % k
if(tmp == 0): 
	print('OK')
else:
	if(A + (K-tmp) <= B):
		print('OK')
	else:
		print('NG')

### FIXED CODE ###

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

tmp = A % K
if(tmp == 0): 
	print('OK')
else:
	if(A + (K-tmp) <= B):
		print('OK')
	else:
		print('NG')
N = int(input())
import sympy
num = 0
for i in range(1,N+1):
    num += i*sympy.divisor_count(i)
print(num)

### FIXED CODE ###

N = int(input())
ans = 0
for i in range(1,N+1):
    last = N//i
    ans += ((1+last)*last//2)*i
print(ans)
MOD = 10 ** 9 + 7
fac = [1] * (10 ** 6 + 2)
for i in range(len(fac) - 1):
    fac[i + 1] = fac[i] * (i + 1) % MOD
x, y = map(int, input().split())
t = min(x, y) // 3
a, b = x - t * 3, y - t * 3
if a * 2 == b or b * 2 == a:
    n = t * 2 + min(a, b)
    print((fac[n] * pow(fac[n - t], MOD - 2, MOD)
           * pow(fac[t], MOD - 2, MOD)) % MOD)
else:
    print(0)
    exit(1)


### FIXED CODE ###

import random
MOD = 10 ** 9 + 7
fac = [1] * (10 ** 6 * 2 + 2)
for i in range(len(fac) - 1):
    fac[i + 1] = fac[i] * (i + 1) % MOD
x, y = map(int, input().split())
t = min(x, y) // 3
if (2 * x - y) % 3 or (2 * y - x) % 3 or 2 * x < y or 2 * y < x:
    print(0)
    exit(0)
a, b = (2 * x - y) // 3, (2 * y - x) // 3
k = min(a, b)
n = a + b
print((fac[n] * pow(fac[n - k], MOD - 2, MOD)
       * pow(fac[k], MOD - 2, MOD)) % MOD)
Import sys
my_str = input()

for i in range(len(my_str)):
    if "a"<=my_str[i]<="z":
        sys.stdout.write(my_str[i].upper(),end='')
    elif "A"<=my_str[i]<="Z":
        sys.stdout.write(my_str[i].lower(),end='')
    else:
        sys.stdout.write(my_str[i],end='')
sys.stdout.write("\n")

### FIXED CODE ###

import sys
my_str = input()

for i in range(len(my_str)):
    if "a" <= my_str[i] <= "z":
        sys.stdout.write(my_str[i].upper())
    elif "A" <= my_str[i] <= "Z":
        sys.stdout.write(my_str[i].lower())
    else:
        sys.stdout.write(my_str[i])
sys.stdout.write("\n")
import numpy as np
from math import factorial
import math, sys

N, M = map(int, input().split())
A = [None]*M

for i in range(M):
    A[i] = int(input())

tmp = 0
x = []

for i, a in enumerate(A):
    x.append(a-tmp-1)
    tmp = a + 1

x.append(N - tmp)
    
x = np.array(x)
if x[1:].min()<1:
    print(0)
    sys.exit()

def calc_combi(a):
    ans = 0
    for i in range(int(a/2)+1):
        tmp_n = math.ceil(a/2)+i
        tmp_r = a - tmp_n
        ans += factorial(tmp_n) // factorial(max(tmp_r, tmp_n - tmp_r))                        
    return ans

memo =  list(map(lambda x: calc_combi(x), x))

ans = 1
for m in memo:
    ans = ans * m % 1000000007

### FIXED CODE ###

N, M = map(int, input().split())
A = [None]*M

is_broken = [False] * (N+1)

for i in range(M):
    A[i] = int(input())
    is_broken[A[i]] = True

dp = [0] * (N+1)
dp[0] = 1

for i in range(1, N+1):
    if is_broken[i]:
        continue
    dp[i]  = (dp[i-1] + dp[i-2]) % (10**9 + 7)

print(dp[-1])
K,X = [int(x) for x in stdin.readline().rstrip().split()]
Ks = K * 500
if Ks < X:
  print('No')
else:
  print('Yes')

### FIXED CODE ###

k,x = map(int,input().split())
ks = k * 500
if ks < x:
  print('No')
else:
  print('Yes')
N = int(input())
p = [int(i) for i in input().split()]
ans = 1

if 0 in p:
  print(0)
  exit()
  
for i in range(n):
  ans*=p[i]
  
if ans > 10 ** 18:
  print(-1)
  exit()
  
print(ans)

### FIXED CODE ###

A,B = map(int,input().split())
print(A*B)
n = input()
a = []
a = [input for i in range(n)]
i = 0
j = 1
max = a[j]-a[i]
while n-1 > i:
   j = i+1
   while n-1 > j:
        if max < a[j]-a[i]:
           max = a[j]-a[i]
        j+=1
    i+=1

print max

### FIXED CODE ###

N = int(raw_input())
min = int(raw_input())
max = int(raw_input())

ans = max - min
if max < min:
    min = max
 
for i in range(N - 2):
    R = int(raw_input())
    if R - min > ans:
        ans = R - min
    if R < min:
        min = R
 
print ans
import itertools
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
need = []
iranaiko = []
for a in A:
	if a >= K:
		need.append(a)
	elif a in need:
		need.append(a) 
	elif a in iranaiko:
		pass
	else:
		z = 0
		B = A[:]
		B.remove(a)
		fusoku = [K - i - 1 for i in range(a)]
		for bi,b in enumerate(B):
			if b >= K:
				break
		B = B[:bi + 1]
		for i in range(1,len(B) + 1):
			C = list(itertools.combinations(B,i))
			for c in C:
				if sum(c) in fusoku:
					need.append(a)
					z = 1
					break
			if z == 1:
				break
		if z == 0:
			iranaiko.append(a)
print(N - len(need))


### FIXED CODE ###

# -*- coding: utf-8 -*- 

a,b = input().split()
if a == "H":
	c = 1
else:
	c = -1

if b == "H":
	d = 1
else:
	d = -1
if c * d == 1:
	print("H")
else:
	print("D")
N, K = map(int, input().split())
l = [map(int, input().spilt())]
ans = [i if i >= K for i in l]
print(len(ans))

### FIXED CODE ###

N, K = map(int, input().split())
l = list(map(int, input().split()))
ans = [1 if i >= K else 0 for i in l]
print(sum(ans))
n,d =map(int,input().split())
l= [list(map(int, input().split())) for i in range(N)]
a = 0
ans +=1
for i in range(n):
    for j in range(i+1,n):
        for k in range(d):
            a += l[i][k]**2 - l[j][k]**2
            a **=0.5
            if a.is_integer:
                ans +=1
print(ans)

### FIXED CODE ###

n,d =map(int,input().split())
l= [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n):
    for j in range(i+1,n):
        a = 0
        for k in range(d):
            a += (l[i][k] - l[j][k])**2
        a **=0.5
        if a.is_integer():
            ans +=1
print(ans)
import sys
n = int(input())
a = []
count = [0 for _ in range(2000001)]

for i in range(n):
    next = int(sys.stdin.readline())
    a.append(next)
    count[next]+=1
start = 0
for i in range(20000,0,-1):
    if count[i]>0:
        v1=i
        count[i]-=1
        start = i
        break
for i in range(start,0,-1):
    if count[i]>0:
        v2=i
        count[i]-=1
        start = i
        break
count[v1]+=1
count[v2]+=1
if count[v1]>1:
    for i in range(n):
        sys.stdout.write('{}\n'.format(v1))
else:
    for v in a:
        if v != v1:
            sys.stdout.write('{}\n'.format(v1))
        else:
            sys.stdout.write('{}\n'.format(v2))




### FIXED CODE ###

import sys
n = int(input())
a = []
count = [0 for _ in range(200001)]
for i in range(n):
    next = int(sys.stdin.readline())
    a.append(next)
    count[next]+=1
start = 0
for i in range(200000,0,-1):
    if count[i]>0:
        v1=i
        count[i]-=1
        start = i
        break
for i in range(start,0,-1):
    if count[i]>0:
        v2=i
        count[i]-=1
        break
count[v1]+=1
count[v2]+=1
if count[v1]>1:
    for i in range(n):
        sys.stdout.write('{}\n'.format(v1))
else:
    for v in a:
        if v != v1:
            sys.stdout.write('{}\n'.format(v1))
        else:
            sys.stdout.write('{}\n'.format(v2))
import math
N = int(input())
for i range(N):
  a,t = map(int,input().split())
  if i == 0:
    x,y = a,t
  else:
    xa = math.ceil(x/a)
    yb = math.ceil(y/b)
    c = max(xa,yb)
    x,y = a*c,b*c
print(x+y)

### FIXED CODE ###

N = int(input())
for i in range(N):
  a,t = map(int,input().split())
  if i == 0:
    x,y = a,t
  else:
    xa = x//a if x%a==0 else x//a+1
    yt = y//t if y%t==0 else y//t+1
    c = max(xa,yt)
    x,y = a*c,t*c
print(x+y)
MOD = 10**9 + 7
def Mod_Permutation(n, k, mod):
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret = ret * i % mod
    return ret
N, M = map(int, input().split())
if abs(N - M) > 1:
    print(0)
elif N == M:
    print(int(Mod_Permutation(N, N, MOD) * (2 * Mod_Permutation(N, M, MOD) % MOD) % MOD))
else:
    if N < M:
        swap(N, M)
    print(int(Mod_Permutation(N, N, MOD) * Mod_Permutation(M, M, MOD) % MOD))

### FIXED CODE ###

MOD = 10**9 + 7
def Mod_Permutation(n, k, mod):
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret = ret * i % mod
    return ret
N, M = map(int, input().split())
if abs(N - M) > 1:
    print(0)
elif N == M:
    print(int(Mod_Permutation(N, N, MOD) * (2 * Mod_Permutation(N, M, MOD) % MOD) % MOD))
else:
    if N < M:
        T = N
        N = M
        M = T
    print(int(Mod_Permutation(N, N, MOD) * Mod_Permutation(M, M, MOD) % MOD))
A, B = list(map(int, input().split()))

for x in range(10):
	if (A-1)*x + 1 >= B:
      print(x)
      break


### FIXED CODE ###

import math
A, B = list(map(int, input().split()))
 
print(math.ceil((B-1)/(A-1)))
n=int(input())
a=[int(input()) for _ in range(n)]
print(max(a)-min(a))


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
print(max(a)-min(a))
a, b =(int, input().split())
if (a*b)%2:
  print("Odd")
else:
  print("Even")

### FIXED CODE ###

a, b = map(int, input().split())
print("Odd" if a*b%2 else "Even")
import sys
input = sys.stdin.readline


class unionFind:
    parent = []
    count = []

    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.count = [1 for i in range(N)]

    def root(self, x):
        if self.parent[x] == x:
            return(x)
        else:
            self.parent[x] = self.root(self.parent[x])
            return(self.parent[x])

    def same(self, x, y):
        x, y = x-1, y-1
        return(self.root(x) == self.root(y))

    def unite(self, x, y):
        x, y = x-1, y-1
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        else:
            self.parent[x] = y
            self.count[y] += self.count[x]
            self.count[x] = self.count[y]
            return

    def getCount(self, x):
        y = self.root(x)
        self.count[x] = self.count[y]
        return(self.count[x])


N, M, K = map(int, input().split())
AB = [tuple(map(int, input().split())) for i in range(M)]

CD = [tuple(map(int, input().split())) for i in range(K)]

G = unionFind(N)
for a, b in AB:
    G.unite(a, b)

for i in range(N):
    G.root(i)

ans = [G.getCount(i) - 1 for i in range(N)]
# print(ans)
# print(G.count)
for a, b in AB:
    ans[a-1] -= 1
    ans[b-1] -= 1

for c, d in CD:
    if G.same(c, d):
        ans[c-1] -= 1
        ans[d-1] -= 1

print(*ans)


### FIXED CODE ###


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)


class unionFind:
    parent = []
    count = []

    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.count = [1 for i in range(N)]

    def root(self, x):
        if self.parent[x] == x:
            return(x)
        else:
            self.parent[x] = self.root(self.parent[x])
            return(self.parent[x])

    def same(self, x, y):
        x, y = x-1, y-1
        return(self.root(x) == self.root(y))

    def unite(self, x, y):
        x, y = x-1, y-1
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        else:
            self.parent[x] = y
            self.count[y] += self.count[x]
            self.count[x] = self.count[y]
            return

    def getCount(self, x):
        self.count[x] = self.count[self.root(x)]
        return(self.count[x])


N, M, K = map(int, input().split())
AB = [tuple(map(int, input().split())) for i in range(M)]

CD = [tuple(map(int, input().split())) for i in range(K)]

G = unionFind(N)
for a, b in AB:
    G.unite(a, b)

for i in range(N):
    G.root(i)

ans = [G.getCount(i) - 1 for i in range(N)]
# print(ans)
# print(G.count)
for a, b in AB:
    ans[a-1] -= 1
    ans[b-1] -= 1

for c, d in CD:
    if G.same(c, d):
        ans[c-1] -= 1
        ans[d-1] -= 1

print(*ans)
dp = [[-1 for i in range(3005)] for j in range(3005)]

def f(idx, time):
    if time >= T:
        return 0
    if idx >= N:
        return 0
    if dp[idx][time] != -1:
        return dp[idx][time]
    dp[idx][time] = max(f(idx+1, time), B[idx]+f(idx+1, time+A[idx]))
    return dp[idx][time]

N, T = [int(i) for i in input().split()]
A, B = [], []

for i in range(N):
    a, b = [int(j) for j in input().split()]
    A.append(a)
    B.append(b)

print(f(0, 0))


### FIXED CODE ###

dp = [[-1 for i in range(6005)] for j in range(6005)]


def f(idx, time):
    if time >= T:
        return 0
    if idx >= N:
        return 0
    if dp[idx][time] != -1:
        return dp[idx][time]
    dp[idx][time] = max(f(idx+1, time), B[idx]+f(idx+1, time+A[idx]))
    return dp[idx][time]

N, T = [int(i) for i in input().split()]
data = []
A, B = [], []

for i in range(N):
    a, b = [int(j) for j in input().split()]
    data.append([a,b])
    A.append(a)
    B.append(b)

data.sort()
A, B = [], []
for i, j in data:
    A.append(i)
    B.append(j)

for idx in range(N, -1, -1):
    for time in range(T, -1, -1):
        if time == T:
            dp[idx][time] = 0
            continue
        if idx == N:
            dp[idx][time] = 0
            continue
        if A[idx]+time >= T:
            fval = 0
        else:
            fval = dp[idx+1][time+A[idx]]
        dp[idx][time] = max(dp[idx+1][time], B[idx] + fval)

print(dp[0][0])
from math import gcd
a, b, c, d = map(int, input().split())

#c,d,lcm(c,d)の倍数がa~bの区間にいくつあるか調べる関数
def check(p):
    if a%p==0:
        e = a//p
    else:
        e = (a//p) +1

    if b%p==0:
        f = b//p
    else:
        f = (b//p)
        
    return(f-e+1)
        

lcm = (c*d)//gcd(c,d)
    
ans = b-a+1 -(check(c)+check(d)) +check(lcm)
print(ans)

### FIXED CODE ###

from fractions import gcd
a, b, c, d = map(int, input().split())

#c,d,lcm(c,d)の倍数がa~bの区間にいくつあるか調べる関数
def check(p):
    if a%p==0:
        e = a//p
    else:
        e = (a//p) +1

    if b%p==0:
        f = b//p
    else:
        f = (b//p)
        
    return(f-e+1)
        

lcm = (c*d)//gcd(c,d)
    
ans = b-a+1 -(check(c)+check(d)) +check(lcm)
print(ans)
n=int(input())
a=[int(i) for i in input().split()]
ans=0
a.sort()
a.reverse()
if n%2==0:
    p=n//2
else:
    p=n//2+1
c=1
lp=[]
lm=[]
for i in a:
    if i>0 and c<=p:
        ans+=i
        lp.append(i)
    else:
        ans-=i
        lm.append(i)
    c+=1
print(ans)
llp=len(lp)
llm=len(lm)
q=lm[0]
i=0
j=0
k=0
o=0

for i in range(llp-1):
    print(q,lp[i])
    q=q-lp[i]
print(lp[-1],q)
q=lp[-1]-q
for i in range(1,llm):
    print(q,lm[i])
    q=q-lm[i]

### FIXED CODE ###

n=int(input())
a=[int(j) for j in input().split()]
a.sort()
ans=[]
p=a[0]
q=a[-1]
for i in a[1:-1]:
    if i<0:
        ans.append([q,i])
        q-=i
    else:
        ans.append([p,i])
        p-=i
ans.append([q,p])
print(q-p)
for i,j in ans:
    print(i,j)
S=input()
M=S[5]*10+S[6]
if M>4:
	print("TBD")
else:
	print("Heisei")

### FIXED CODE ###

S=input()

M=int(S[5])*10+int(S[6])
if M>4:
	print("TBD")
else:
	print("Heisei")
X , Y ,Z = int(input())
print(Z, X, Y)

### FIXED CODE ###

X, Y, Z = map(int, input().split())
print(Z, X, Y)
N, M=map(int, input().split())

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

num=["a"]*N
ans=True
for s in S:
  if (num[s[0]-1]!="a") and (num[s[0]-1]!=s[1]):
    ans=False
    break
  else:
    num[s[0]-1]=s[1]
    
if num[0]==0 and len(num)>1:
  ans=False
    
if ans:
  if len(num[0])==1:
    if num[0]=="a":
      print(0)
    else:
      print(num[0])
  else:
    for i in range(N):
      if num[i]=="a":
        if i==0:
          print(1, end="")
        else:
          print(0, end="")
      else:
        print(num[i], end="")
else:
  print(-1)
  

### FIXED CODE ###

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

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

num=["a"]*N
ans=True
for s in S:
  if (num[s[0]-1]!="a") and (num[s[0]-1]!=s[1]):
    ans=False
    break
  else:
    num[s[0]-1]=s[1]
    
if num[0]==0 and len(num)>1:
  ans=False
    
if ans:
  if len(num)==1:
    if num[0]=="a":
      print(0)
    else:
      print(num[0])
  else:
    for i in range(N):
      if num[i]=="a":
        if i==0:
          print(1, end="")
        else:
          print(0, end="")
      else:
        print(num[i], end="")
else:
  print(-1)
n,m = map(int,input().split())
ans = [[1 for j in range(2**m-1)] for i in range(2**n-1)]
for i in range(2**n-1):
  for j in range(2**m-1):
    if i%2 != j%2:
      ans[i][j] = 0
    if (abs(i%8) == 3) ^ (abs(j%8) == 3):
      ans[i][j] = 1
for arr in ans:
  print(*arr,sep="")

### FIXED CODE ###

s = input()
if len(s)%2:
  print("No")
  exit()
flg = 1
for i in range(0,len(s),2):
  if s[i:i+2] != "hi":
    flg = 0
if flg:
  print("Yes")
else:
  print("No")
while True:
    n, m = map(int, input().split())
    if (n, m) == (0, 0):
        break
    dp = [list(map(int, input().split())) for i in range(n)]
    dp = sorted(dp, key=lambda kv:kv[1], reverse=True)
    r = 0
    for d,p in dp:
        if m >= d:
            m -= d
        else:
            r += p*(d-m)
            m = 0
    print(r

### FIXED CODE ###

while True:
    n, m = map(int, input().split())
    dpList = []
    if (n,m) == (0,0):
        break
    for i in range(n):
        row = list(map(int,input().split()))
        dpList.append(row)
    dpList = sorted(dpList, key = lambda x:x[1], reverse = True)
    num = 0
    for i in range(n):
        if m >= dpList[i][0]:
            m -= dpList[i][0]
        else:
            num += (dpList[i][0] - m) * dpList[i][1]
            m = 0
    print(num)
N = int(input())
A = [0]+[int(input()) for _ in range(N)]

v = {1}
x = 1
a = 0
while True:
  x = A[x]
  a += 1
  if x in v:
    print(-1)
    break
  if x == 2:
	print(a)
    break
  v.add(x)

### FIXED CODE ###

N = int(input())
A = [0]+[int(input()) for _ in range(N)]

v = set()
v.add(1)
x = 1
a = 0
while True:
  x = A[x]
  a += 1
  if x in v:
    print(-1)
    break
  if x == 2:
    print(a)
    break
  v.add(x)
# -*- coding: utf-8 -*-
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

ans = 0
tmp = [A, B, C, D, E]
Y = []
Z = []
L = []
for i in range(5):
    Y.append([tmp[i] % 10, tmp[i]])
Y.sort()
#print(Y)
for i in range(5):
    if Y[i][0] != 0:
        Z.append(i)
    else:
        L.append(i)
for i in range(5):
    X = Y[i][1]
    #print(i)
    while X % 10 != 0:
        X += 1
    ans += X
    #print(X)
    #print(ans)
G = Y[Z[0]][1]
while G % 10 != 0:
    G += 1
ans -= G
ans += Y[Z[0]][1]
#print(tmp[0])
print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

ans = 0
tmp = [A, B, C, D, E]
Y = []
Z = []
for i in range(5):
    Y.append([tmp[i] % 10, tmp[i]])
Y.sort()
#print(Y)
for i in range(5):
    if Y[i][0] != 0:
        Z.append(i)
if len(Z) != 0:
    for i in range(5):
        X = Y[i][1]
        #print(i)
        while X % 10 != 0:
            X += 1
        ans += X
        #print(X)
        #print(ans)
    G = Y[Z[0]][1]
    while G % 10 != 0:
        G += 1
    ans -= G
    ans += Y[Z[0]][1]
    #print(tmp[0])
else:
    ans = sum(tmp)
print(ans)
n = int(input())
s = []
for i in range(n):
    tmp = int(input())
    s.append(tmp)
sorted(s)
max_s = sum(s)

if max_s % 10 != 0:
    print(max_s)
else:
    for j in range(n):
        if s[j] % 10 != 0:
            print(max_s - s[j])
            break
if j == n-1:
    print(0)

### FIXED CODE ###

n = int(input())
s = []
for i in range(n):
    tmp = int(input())
    s.append(tmp)
s = sorted(s)
max_s = sum(s)
if max_s % 10 != 0:
    print(max_s)
else:
    for j in range(n):
        if s[j] % 10 != 0:
            print(max_s - s[j])
            break
        elif j == n-1:
            print(0)
n = int(input())
d = {}
mod = 998244353
max_v = 0
for v in list(map(int, input().split())):
    if v not in d:
        d[v] = 1
    else:
        d[v] += 1
    max_v = max(max_v, v)
# 0はひとつだけ
if d[0] > 1:
    print(0)
    exit()
ans = 1
# 木を作ることができるならば1~max_vまでの数字がそれぞれ1つ以上存在する
for i in range(1, max_v + 1):
    if i not in d or i - 1 not in d:
        ans *= 0
    else:
        ans *= pow(d[i - 1], d[i], mod)
        ans %= mod
print(ans)

### FIXED CODE ###

# 最初dは与えられる距離だと思ってて「サンプルケース1は3じゃね？」とか思ってて2時間経過した
# 落ち着いて読んだら最小の辺の数だった

from collections import Counter

n = int(input())
arr = list(map(int, input().split()))
if arr[0] != 0:
    print(0)
    exit()
arr = sorted(list(Counter(arr).items()), key=lambda x: x[0])
if arr[0][1] > 1:
    print(0)
    exit()

mod = 998244353
ans = 1
tmp = 1
for i in range(1, len(arr)):
    if arr[i][0] != i:
        print(0)
        exit()
    ans *= pow(tmp, arr[i][1])
    ans %= mod
    tmp = arr[i][1]

print(ans)