Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

def C(n):
    if n < 2: return 0
    return n * (n-1) // 2    
    


n = int(input())
a = list(map(int, input().split()))
E = []

for i in range(n):
    if E.count(a[i]) == 0:
        E.append(a[i])

m = len(E)

num = [0] * m
comb = [0] * m

for i in range(m):
    num[i] = a.count(E[i])
    comb[i] = C(num[i])

count = sum(comb)

for i in range(n):
    l = E.index(a[i])
    print(count - comb[l] + C(num[l]-1))

### FIXED CODE ###


from collections import Counter

def C(n):
    if n < 2: return 0
    return n * (n-1) // 2    
    
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)

count = 0

for i, j in c.items():
    count += C(j)

for i in a:
    m = c[i]
    print(count - m + 1)
### BUGGY CODE ###

import sys
import copy

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

Ls, Rs = [0 for _ in range(M)],  [0 for _ in range(M)]

for i in range(M):
    L, R = map(int,input().split())
    Ls[i] = L
    Rs[i] = R
    
    if i != 0:
        if Rs[i-1] < Ls[i]:
            print(0)
            sys.exit( )
ls = []

for i in range(M):
    l = [k+Ls[i] for k in range(Rs[i]-Ls[i]+1)]
    ls.append(l)
    
if M == 1:
    print(len(l))
else:
    for i in range(M-1):
        l_set = set(ls[i]) & set(ls[i+1])
        ls[i+1] = copy.deepcopy(l_set)

    print(len(l_set))

### FIXED CODE ###

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

Ls, Rs = [0 for _ in range(M)],  [0 for _ in range(M)]

for i in range(M):
    L, R = map(int,input().split())
    Ls[i] = L
    Rs[i] = R
    
L_prime = max(Ls)
R_peime = min(Rs)

if L_prime > R_peime:
    print(0)
else:
    print(R_peime - L_prime + 1)
### BUGGY CODE ###

import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
s = rr()
ans = s.count('R') * s.count('G') * s.count('B')
for i in range(n):
    for j in range(i+1, n):
        k = j + j - i
        if k < n:
            if s[k] != s[j] and s[j] != s[i] and s[k] != s[i]:
                ans -= 1
print(ans)








### FIXED CODE ###

import sys

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))


n = ri()
s = rr()
ans = s.count('R') * s.count('G') * s.count('B')
for i in range(n-2):
    for j in range(i+1, n-1):
        k = j + j - i
        if k < n:
            if s[k] != s[j] and s[j] != s[i] and s[k] != s[i]:
                ans -= 1
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
import numpy as np

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, K: int, Q: int, A: "List[int]"):
    human = np.full(N, K)

    for i in range(Q):
        human = human - 1
        human[A[i]-1] += 1

    for j in range(N):
        if human[j] > 0:
            print(YES)
        else:
            print(NO)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(Q)]  # type: "List[int]"
    solve(N, K, Q, A)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import numpy as np

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, K: int, Q: int, A: "List[int]"):
    human = np.full(N, K)
    score = np.zeros(N)
    #print(human)
    for i in range(Q):
        #print("i =", i)
        # ind = np.ones(N, dtype=bool)
        # ind[A[i]-1] = False
        # human[ind] = human[ind] - 1
        # ind[A[i]-1] = True
        #human[A[i]-1] += 1
        #print('human =', human)
        score[A[i]-1] += 1

    human = human - Q + score

    #print(human)
    human2 = list(map(lambda x: YES if x > 0 else NO, human))
    print('\n'.join(human2))
    '''
    for j in range(N):
        #print(j, human[j])
        if human[j] > 0:
            print(YES)
        else:
            print(NO)
    '''
    return
    

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(Q)]  # type: "List[int]"
    solve(N, K, Q, A)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in input().split()]
def II(): return int(input())

minusinf = -10**18

N=II()
RA=LI()
RB=LI()
GAIN1=[]
GAIN2=[]
for i in range(3):
    if RA[i] < RB[i]:
        GAIN1.append((RA[i], RB[i]-RA[i]))
    if RA[i] > RB[i]:
        GAIN2.append((RB[i], RA[i]-RB[i]))

memo1 = {}
def dp1(n):
    if n == 0: return 0
    if n < 0: return minusinf
    if n in memo1:
        return memo1[n]
    sol = 0
    for cost, g in GAIN1:
        sol = max(dp1(n-cost)+g, sol)
    memo1[n] = sol
    return sol

memo2 = {}
def dp2(n):
    if n == 0: return 0
    if n < 0: return minusinf
    if n in memo2:
        return memo2[n]
    sol = 0
    for cost, g in GAIN2:
        sol = max(dp2(n-cost)+g, sol)
    memo2[n] = sol
    return sol

med = N+dp1(N)
print(med+dp2(med)) 

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in input().split()]
def II(): return int(input())
INTMIN = -9223372036854775808

N=II()
RA=LI()
RB=LI()
GAIN1=[]
GAIN2=[]
for i in range(3):
    if RA[i] < RB[i]:
        GAIN1.append((RA[i], RB[i]-RA[i]))
    if RA[i] > RB[i]:
        GAIN2.append((RB[i], RA[i]-RB[i]))

dp1 = [0]*(N+1)
for i in range(N+1):
    for cost, gain in GAIN1:
        if (i+cost) <= N:
            dp1[i+cost] = max(dp1[i+cost],dp1[i]+gain)

M = dp1[N]+N
dp2 = [0]*(M+1)
for i in range(M+1):
    for cost, gain in GAIN2:
        if (i+cost) <= M:
            dp2[i+cost] = max(dp2[i+cost],dp2[i]+gain)

print(M+dp2[M])
### BUGGY CODE ###

class WarshallFloyd():
    def __init__(self, N):
        self.N = N
        self.d = [[float("inf") for i in range(N)]
                  for i in range(N)]  # d[u][v] : 辺uvのコスト(存在しないときはinf)

    def add(self, u, v, c, directed=False):
        """
        0-indexedであることに注意
        u = from, v = to, c = cost
        directed = Trueなら、有向グラフである
        """
        if directed is False:
            self.d[u][v] = c
            self.d[v][u] = c
        else:
            self.d[u][v] = c

    def WarshallFloyd_search(self):
        # これを d[i][j]: iからjへの最短距離 にする
        # 本来無向グラフでのみ全域木を考えるが、二重辺なら有向でも行けそう
        # d[i][i] < 0 なら、グラフは負のサイクルを持つ
        for k in range(self.N):
            for i in range(self.N):
                for j in range(self.N):
                    self.d[i][j] = min(
                        self.d[i][j], self.d[i][k] + self.d[k][j])
        hasNegativeCycle = False
        for i in range(self.N):
            if self.d[i][i] < 0:
                hasNegativeCycle = True
                break
        for i in range(self.N):
            self.d[i][i] = 0
        return hasNegativeCycle, self.d

n,m,l=map(int,input().split())
ABC=[list(map(int, input().split())) for i in range(m)]
q=int(input())
st=[list(map(int, input().split())) for i in range(q)]

graph=WarshallFloyd(n)
graph2=WarshallFloyd(n)
for a,b,c in ABC:
    graph.add(a-1,b-1,c)
hasNegativeCycle, d = graph.WarshallFloyd_search()
#ans = sorted([[i, max(d[i])] for i in range(n)], key=lambda x: x[0])
ans=graph.WarshallFloyd_search()
#print(ans)
L=[[0,0,0] for _ in range(n**2)]
for i in range(n):
    for j in range(n):
        L[i*n+j][0],L[i*n+j][1],L[i*n+j][2]=i+1,j+1,ans[1][i][j]
#print(L)
#print(L)
for a,b,c in L:
    if 0<c<=l:
        graph2.add(a-1,b-1,1)
ans1=graph2.WarshallFloyd_search()
#print(ans1)
for i,j in st:
    if ans1[1][i-1][j-1]-1!=float('inf'):
        print(ans1[1][i-1][j-1]-1)
    else:
        print(-1)

### FIXED CODE ###

def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


n,m,l= map(int,input().split()) #n:頂点数　w:辺の数

d=[[float("inf") for i in range(n)] for i in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(m):
    a,b,c = map(int,input().split())
    d[a-1][b-1]=c
    d[b-1][a-1]=c
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
warshall_floyd(d)

d2=[[float("inf") for i in range(n)] for i in range(n)] 
for i in range(n):
    for j in range(n):
        if d[i-1][j-1]<=l:
            d2[i-1][j-1]=1
            d2[j-1][i-1]=1
warshall_floyd(d2)
q=int(input())
l=[list(map(int, input().split())) for i in range(q)]
for i in range(q):
    if d2[l[i][0]-1][l[i][1]-1]-1!=float('inf'):
        print(d2[l[i][0]-1][l[i][1]-1]-1)
    else:
        print(-1)
### BUGGY CODE ###

import numpy as np
import copy
n = int(input())
integer = list(map(int, input().split()))
length = len(integer)
tmp = []
count = 0
for i in range(length):
  tmp = copy.copy(integer)
  del(tmp[i])
  for j in range(length-2):
    for k in range(j+1, length-1):
      if tmp[j] == tmp[k]:
        count += 1      
  print(count)
  count = 0

### FIXED CODE ###

from collections import Counter

n = int(input())
integer = list(map(int, input().split()))
length = len(integer)
counter = Counter(integer)
keys = counter.keys()
total = 0
for key in keys:
  total += counter[key] * ( counter[key] -1 ) / 2
total = int(total)

for i in integer:
  tmp = total
  tmp -= counter[i] - 1
  print(tmp)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
diff = []
for i in range(N):
    diff.append(A[i] - B[i])
neg_diff = [i for i in diff if i < 0]
pos_diff = [i for i in diff if i > 0]
pos_diff.sort(reverse=True)
if abs(sum(neg_diff)) > abs(sum(pos_diff)):
    print(-1)
    exit(0)
else:
    if sum(neg_diff) == 0:
        print(0)
        exit(0)

for i in range(0,len(pos_diff)+1):
    if abs(sum(pos_diff[0:i])) > abs(sum(neg_diff)):
        print(len(neg_diff)+i)
        exit(0)


### FIXED CODE ###

import numpy
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
diff = []
for i in range(N):
    diff.append(A[i] - B[i])
neg_diff = [i for i in diff if i < 0]
pos_diff = [i for i in diff if i > 0]
pos_diff.sort(reverse=True)
if abs(sum(neg_diff)) > abs(sum(pos_diff)):
    print(-1)
    exit(0)
else:
    if sum(neg_diff) == 0:
        print(0)
        exit(0)

cum_pos_diff = numpy.cumsum(pos_diff)
insert_index = bisect.bisect_left(cum_pos_diff, abs(sum(neg_diff)))
print(len(neg_diff)+insert_index+1)
### BUGGY CODE ###

import math

N, Q = list(map(int, input().split()))
c = list(map(int, input().split()))
l = []
r = []

for i in range(Q):
    li, ri = list(map(int, input().split()))
    l.append(li)
    r.append(ri)

for i in range(Q):
    print(len(set(c[l[i]-1:r[i]])))

### FIXED CODE ###

class BinaryIndexedTree(object):
    def __init__(self, N):
        self.N = N
        self.bit = [0] * (N + 1)

    def bit_add(self, index, num):
        while (index <= self.N):
            self.bit[index] += num
            index += index & -index
        return

    def bit_sum(self,index):
        result = 0
        while (index > 0):
            result += self.bit[index]
            index -= index & -index
        return result

    def bit_sum_range(self, l, r):
        if (l == r):
            return 1
        else:
            return self.bit_sum(r) - self.bit_sum(l - 1)

def main():
    from sys import stdin
    N, Q = list(map(int, input().split()))
    c = list(map(int, input().split()))
    readline = stdin.readline
    query = [list(map(int, readline().split())) + [i] for i in range(Q)]
    query_result = [0 for i in range(Q)]
    collar_pos = [-1] * (N + 1)
    bit = BinaryIndexedTree(N)

    sorted_query = sorted(query, key=lambda query: query[1])

    index = 1
    for query in sorted_query:
        l, r, q = query
        while (index <= r):
            # update BIT
            if (collar_pos[c[index-1]] != -1):
                bit.bit_add(collar_pos[c[index-1]], -1)
            bit.bit_add(index, 1)
            # update collar_pos
            collar_pos[c[index-1]] = index
            index += 1
        query_result[q] = bit.bit_sum_range(l, r)

    print(*query_result, sep='\n')

if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys
N = int(input())
n_list = list(map(int,input().split()))

a = 1
b = 10**18

for i in range(0,N):
  
  a = n_list[i] * a
  #print(a)
 
if a > b:
   print(-1)
else : 
  print(a)

### FIXED CODE ###

import sys
N = int(input())
n_list = list(map(int,input().split()))

a = 1
b = 10**18

if 0 in n_list:
  print(0)
  sys.exit()

for i in range(0,N):
  
  a = n_list[i] * a
  #print(a)
 
  if a > b:
     print(-1)
     sys.exit()

print(a)
### BUGGY CODE ###

import numpy as np
N, K = map(int,input().split())
H = np.array([int(input()) for _ in range(0, N)])
H = np.sort(H)
H_diff = abs(H[1:]-H[:-1])
best = (np.max(H) - np.min(H))*K
for i in range(0, len(H_diff)-K+2):
    if np.sum(H_diff[i:i+K-1]) < best:
        best = np.sum(H_diff[i:i+K-1])
print(best)

### FIXED CODE ###

import numpy as np
N, K = map(int,input().split())
H = np.array([int(input()) for _ in range(0, N)])
H = np.sort(H)
H_diff = np.diff(H)
best = int(np.min(np.convolve((H_diff), np.ones(K-1), mode='valid')))
print(best)
### BUGGY CODE ###

n=int(input())
l=list(map(int,input().split()))
sum=0
for i in range(1,n):
  m=max(l[:i])
  if l[i]<m:
    sum+=m-l[i]
print(sum)

### FIXED CODE ###

n=int(input())
l=list(map(int,input().split()))
sum=0
m=l[0]
for i in range(1,n):
  m=max(m,l[i])
  sum+=m-l[i]
print(sum)
### BUGGY CODE ###

from collections import deque
H, W = map(int, input().split())
cs = []
q = deque()
s = set()
for h in range(H):
    cs.append(input())
    for w in range(W):
        if cs[h][w] == '#':
            s.add((h+1, w+1))
            q.append((h+1, w+1, 0))
vx = [0, 1, 0, -1]
vy = [1, 0, -1, 0]
ans = 0
while q:
    y, x, n = q.popleft()
    for i in range(4):
        ny = y + vy[i]
        nx = x + vx[i]
        if ny >= 1 and ny <= H and nx >= 1 and nx <= W:
            if cs[ny-1][nx-1] == '.' and ((ny, nx) not in s):
                s.add((ny, nx))
                q.append((ny, nx, n+1))
                ans = max(ans, n+1)
print(ans)


### FIXED CODE ###

import numpy as np

H,W = map(int,input().split())
A = []
for i in range(H):
    A.append([0 if i == "#" else H+W for i in list(input())])
A = np.array(A)

for i in range(H-1):
  A[i+1, :] = np.minimum(A[i, :] + 1, A[i+1, :])
for i in range(H-1,0,-1):
  A[i-1,:] = np.minimum(A[i,:]+1,A[i-1,:])
for i in range(W-1):
  A[:,i+1] = np.minimum(A[:,i]+1,A[:,i+1])
for i in range(W-1,0,-1):
  A[:,i-1] = np.minimum(A[:,i]+1,A[:,i-1])
print(np.max(A))
### BUGGY CODE ###

n = int(input())
ar = list(map(int, input().split()))
res = 0
mod = 10 ** 9 + 7
for i in range(60):
    zero = 0
    one = 0
    for j in range(len(ar)):
        if ar[j] % 2 == 0:
            zero += 1
        else:
            one += 1
        ar[j] = ar[j] // 2
    curr = (zero * one * (1 << i)) % mod
    res = (res + curr) % mod
print(res)


### FIXED CODE ###

n = int(input())
ar = list(map(int, input().split()))
res = 0
mod = 10 ** 9 + 7
for i in range(60):
    zero = 0
    one = 0
    for j in range(len(ar)):
        if ar[j] % 2 == 0:
            zero += 1
        else:
            one += 1
        ar[j] = ar[j] // 2
    curr = (zero * one * (1 << i)) % mod
    res = (res + curr) % mod
print(res)
### BUGGY CODE ###

import math

def f(i):
    if i == ns:
        suma, sumb, sumcost = 0, 0, 0
        for j in range(ns):
            if s[j] == 1:
                suma += x[j][0]
                sumb += x[j][1]
                sumcost += x[j][2]
        mincost[suma][sumb] = min(mincost[suma][sumb], sumcost)
        return
    s[i] = 1
    f(i + 1)
    s[i] = 0
    f(i + 1)

def g(i):
    if i == nt:
        global ans
        suma, sumb, sumcost = 0, 0, 0
        for j in range(nt):
            if t[j] == 1:
                suma += y[j][0]
                sumb += y[j][1]
                sumcost += y[j][2]
        k = 1
        while True:
            ss, tt = k * ma - suma, k * mb - sumb
            if 0 <= ss <= l and 0 <= tt <= l:
                ans = min(ans, mincost[ss][tt] + sumcost)
            elif l < ss or l < tt:
                break
            k += 1
        return
    t[i] = 1
    g(i + 1)
    t[i] = 0
    g(i + 1)

n, ma, mb = map(int, input().split())
ns, nt = int(math.ceil(n / 2)), n // 2
l = 10 * ns
mincost = [[114514] * (l + 5) for _ in range(l + 5)]
ans = 114514
x = [list(map(int, input().split())) for _ in range(ns)]
y = [list(map(int, input().split())) for _ in range(nt)]
s = [0] * ns
t = [0] * nt
f(0)
g(0)
print(ans if not ans == 114514 else -1)

### FIXED CODE ###

n, ma, mb = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
x.insert(0, [0, 0, 0])
inf = 114514
dp = [[[inf] * (10 * n + 1) for _ in range(10 * n + 1)] for _ in range(n + 1)]
for i in range(n + 1):
    dp[i][0][0] = 0
suma, sumb = 0, 0
for i in range(1, n + 1):
    suma += x[i][0]
    sumb += x[i][1]
    for j in range(suma + 1):
        for k in range(sumb + 1):
            dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j][k])
            if j >= x[i][0] and k >= x[i][1]:
                dp[i][j][k] = min(dp[i - 1][j][k], dp[i - 1][j - x[i][0]][k - x[i][1]] + x[i][2])
ans = 114514
for i in range(1, 10 * n + 1):
    for j in range(1, 10 * n + 1):
        if i * mb == j * ma:
            ans = min(ans, dp[n][i][j])
print(ans if not ans == 114514 else -1)
### BUGGY CODE ###

n = int(input())
line = list(map(int,input().split()))
ans = 1
for i in range(n):
  ans *= line[i]
if ans > 10**18:
  print("-1")
else:
  print(ans)

### FIXED CODE ###

n = int(input())
line = list(map(int,input().split()))
ans = 1
for i in range(n):
  if line[i] == 0:
    print(0)
    exit()
for i in range(n):
  ans *= line[i]
  if ans > 10**18:
    ans = -1
    break
print(ans)
### BUGGY CODE ###

n,a,b,k=[int(i) for i in input().split()]
c=a+b
mod=998244353
ans=0

g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  #逆元テーブル
inverse = [0, 1]  #逆元テーブル計算用テーブル

for i in range(2,300003):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

#以下のcom関数を用いて組み合わせを計算
def com(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

for i in range(n+1):
    if (k-b*i)%a==0 and k-b*i>=0:
        n_a=(k-b*i)//a
        n_b=i
        n_c=min(n_a,n_b)
        n_a, n_b=n_a-min(n_a,n_b), n_b-min(n_a,n_b)
        count=0
        while n_a + n_b + n_c <=n and n_c>=0 and n_b>=0 and n_a>=0:
            ans+=com(n, n_c, mod) * com(n-n_c, n_b, mod) * com(n-n_c-n_b, n_a, mod) %mod

            n_c-=1
            n_b+=1
            n_a+=1

print(ans%mod)

### FIXED CODE ###

n,a,b,k=[int(i) for i in input().split()]
c=a+b
mod=998244353
ans=0

g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  #逆元テーブル
inverse = [0, 1]  #逆元テーブル計算用テーブル

for i in range(2,300003):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

#以下のcom関数を用いて組み合わせを計算
def com(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

for i in range(n+1):
    if (k-b*i)%a==0 and k-b*i>=0:
        n_a=(k-b*i)//a
        n_b=i
        if  max(n_a, n_b) <=n:
            ans+=com(n, n_a, mod) * com(n, n_b, mod)  %mod

print(ans%mod)
### BUGGY CODE ###

#inputは文字列として取得
input1=input()
input2=input()
#splitする必要がある
input2=input2.split(" ")

N=int(input1)
D=[int(s) for s in input2]

ans=None


if D.count(0)==1 and D[0]==0:

    mul=1
    n=1

    for i in range(1,max(D)+1):
        m=D.count(i)
        mul=mul*pow(n,m,998244353)
        n=m
    
    ans=mul%998244353

else:
    ans=0

print(int(ans))

### FIXED CODE ###

#inputは文字列として取得
input1=input()
input2=input()
#splitする必要がある
input2=input2.split(" ")

N=int(input1)
D=[int(s) for s in input2]

ans=None


if D.count(0)==1 and D[0]==0:

    L=[0]*(max(D)+1)

    for i in range(len(D)):
        L[D[i]]+=1

    mul=1

    for i in range(len(L)-1):
        mul*=L[i]**L[i+1]%998244353
    
    ans=mul%998244353

else:
    ans=0

print(int(ans))
### BUGGY CODE ###

import bisect

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


a.sort()
b.sort()
c.sort()


bi = bisect.bisect_right

result = 0
for i in range(n):
    a_bi_in_b = bi(b, a[i])
    for j in range(a_bi_in_b, n):
        b_bi_in_c = bi(c, b[j])
        result += n - b_bi_in_c
        
        
print(result)

### FIXED CODE ###

import bisect

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


a.sort()
b.sort()
c.sort()


result = 0
for i in range(n):
    b_bisect_in_a = bisect.bisect_left(a, b[i])
    b_bisect_in_c = bisect.bisect_right(c, b[i])
    result += b_bisect_in_a * (n - b_bisect_in_c)
        
        
print(result)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

weight = []

N, W = map(int, input().split())
for i in range(N):
    array = list(map(int, input().split()))
    weight.append(array)

dp = [[0 for i in range(W+1)] for i in range(N+1)]

for i in range(N):
    for j in range(W+1):
        if j >= weight[i][0]:
            dp[i+1][j] = max(dp[i][j-weight[i][0]] + weight[i][1], dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]

print(dp[N][W])

### FIXED CODE ###

n, w = map(int ,input().split())
items = []
for i in range(n):
    array = list(map(int, input().split()))
    items.append(array)
# dp = np.zeros((n+1, w+1))
dp = [[0 for _ in range(w+1)] for _ in range(n+1)]

for i in range(1, n+1):
    weight = items[i-1][0]
    for j in range(0, w+1):
        if j >= weight:
            dp[i][j] = max((dp[i - 1][j - weight] + items[i - 1][1]), dp[i - 1][j])
        else:
            dp[i][j] = dp[i-1][j]


print(int(dp[i][j]))
### BUGGY CODE ###

from functools import reduce
import sys
import numpy as np
MOD = 1000000007
def culc(s, h, w, x, y):
	count = 1
	return count

h, w = map(int, input().split())
s = np.zeros((h, w), int)
for i in range(h):
	s2 = input()
	for j in range(len(s2)):
		s[i][j] = (1 if s2[j] == "#" else 0)

max = 0
left = np.zeros((h, w), int)
right = np.zeros((h, w), int)
up = np.zeros((h, w), int)
down = np.zeros((h, w), int)
for i in range(h):
	for j in range(w):
		left[i][j] = 0 if s[i][j] == 1 else 1 if j <= 0 else left[i][j - 1] + 1
		right[i][w - j - 1] = 0 if s[i][w - j - 1] == 1 else 1 if j <= 0 else right[i][w - j] + 1
		up[i][j] = 0 if s[i][j] == 1 else 1 if i <= 0 else up[i - 1][j] + 1
		down[h - i - 1][j] = 0 if s[h - i - 1][j] == 1 else 1 if i <= 0 else down[h - i][j] + 1
			
for i in range(h):
	for j in range(w):
		tmp = left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3
		if max < tmp:
			max = tmp

print(max)

### FIXED CODE ###

from functools import reduce
import sys
import numpy as np
MOD = 1000000007

buffer = sys.stdin.buffer
H, W = list(map(int,buffer.readline().split()))
S = np.frombuffer(buffer.read(H*(W+1)), dtype="B") == ord(".")
S = S.reshape((H,W+1))[:,:-1]
L = np.empty((H,W), dtype="i4")
R = np.empty((H,W), dtype="i4")
U = np.empty((H,W), dtype="i4")
D = np.empty((H,W), dtype="i4")
 
L[:,0] = S[:,0]
for i in range(1,W):
    L[:,i] = (L[:,i-1] + 1) * S[:,i]
 
R[:,-1] = S[:,-1]
for i in range(1,W):
    R[:,-1-i] = (R[:,-i] + 1) * S[:,-1-i]
 
U[0] = S[0]
for i in range(1,H):
    U[i] = (U[i-1] + 1) * S[i]
 
D[-1] = S[-1]
for i in range(1,H):
    D[-1-i] = (D[-i] + 1) * S[-1-i]
 
score = L + R + U + D - 3
print(int(score.max()))