ZhenlongDai/ACPR huggingface dataset:
Problem: p02866
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
MM = 998244353
n, = map(int, input().split())
xs = list(map(int, input().split()))
mm = max(xs)
cc = [0] * n
for x in xs:
    cc[x] += 1
for i in range(mm+1):
    if cc[i] == 0:
        print(0)
        sys.exit()
r = 1
for i in range(mm):
    r = r * pow(cc[i], cc[i+1]) % MM
    print(i, r)
print(r)

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
0 1
1 2
2


Fixed submission (verdict: Accepted):
import sys
MM = 998244353
n, = map(int, input().split())
xs = list(map(int, input().split()))
mm = max(xs)
cc = [0] * n
if xs[0] != 0:
    print(0)
    sys.exit()
for x in xs:
    cc[x] += 1
for i in range(mm+1):
    if cc[i] == 0:
        print(0)
        sys.exit()
if cc[0] != 1:
    print(0)
    sys.exit()
r = 1
for i in range(mm):
    r = (r * pow(cc[i], cc[i+1])) % MM
print(r)

Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N = input()
    D_list = list(map(int, input().split()))

    if D_list[0] != 0:
        ans = 0
    
    else:
        maxD = max(D_list)
        count_ele_Dlist = [0] * (maxD + 1)

        if count_ele_Dlist[0] == 1:
            ans = 1
            for i in D_list:
                count_ele_Dlist[i] = count_ele_Dlist[i] + 1

            for i in range(1, maxD + 1):
                ans = (ans * count_ele_Dlist[i - 1] ** count_ele_Dlist[i]) % 998244353
        else:
            ans = 0
        
    print(ans)

if __name__ == "__main__":
    main()

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
0


Fixed submission (verdict: Accepted):
def main():
    N = input()
    D_list = list(map(int, input().split()))

    if D_list[0] != 0:
        ans = 0
    
    else:
        maxD = max(D_list)
        count_ele_Dlist = [0] * (maxD + 1)

        for i in D_list:
            count_ele_Dlist[i] = count_ele_Dlist[i] + 1

        if count_ele_Dlist[0] == 1:
            ans = 1
            for i in range(1, maxD + 1):
                ans = (ans * count_ele_Dlist[i - 1] ** count_ele_Dlist[i]) % 998244353
        else:
            ans = 0
        
    print(ans)

if __name__ == "__main__":
    main()

Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
d=list(map(int,input().split()))

if d[0] != 0:
  print(0)
  exit()

ans=1

a=[0]*(n+1)

for i in d:
  a[i] += 1

for j in range(n):
  if j!=0 and a[j] == 0:
    for k in range(j+1,n):
      if a[k] != 0:
        print(0)
        exit()
    break
  else:
    ans*=(a[j]**a[j+1])

print(ans,a)

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
2 [1, 2, 1, 0, 0]


Fixed submission (verdict: Accepted):
n=int(input())
d=list(map(int,input().split()))

if d[0] != 0:
  print(0)
  exit()

ans=1

a=[0]*(n+1)

for i in d:
  a[i] += 1

if a[0] != 1:
  print(0)
  exit()

for j in range(n):
  if j!=0 and a[j] == 0:
    for k in range(j+1,n):
      if a[k] != 0:
        print(0)
        exit()
    break
  else:
    ans*=(a[j]**a[j+1])
    ans%=998244353

print(ans)
Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
d = list(map(int, input().split()))
lis = [0 for i in range(10*5+100)]
ans = 1
if lis[0] != 1 or d[0] != 0:
    print(0)
else:
    mx = -1
    for i in d:
        lis[i] += 1
        if i > mx:
            mx = i
    for i in range(1, mx+1):
        for j in lis[i]:
            ans *= lis[i-1]
    print(ans%998244353)


Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
d = list(map(int, input().split()))
lis = [0 for i in range(10**5+100)]
ans = 1
mx = -1
for i in d:
    lis[i] += 1
    if i > mx:
        mx = i
if lis[0] != 1 or d[0] != 0:
    print(0)
else:
    for i in range(1, mx+1):
        ans *= lis[i-1]**lis[i]
    print(ans%998244353)

Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

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


dict = {}

for i in range(len(D)):
    if D[i] not in dict:
        dict[D[i]] = 1
    else:
        dict[D[i]] += 1

for i in range(max(D)):
    if i not in dict:
        dict[i] = 0
    
for key in dict:
    if dict[key] != 0:
        print(0)
        exit()
    if dict[key] == 0:
        print(0)
        exit()
sum = 1
n = 0


dict_dm = sorted(dict)


flg = 0
for i in range(len(dict_dm)):
    if i == 1:
        
        n = dict[i]
    elif i >=1:
        
        sum = (sum * n**dict[i])%998244353
        n = dict[i]

print(sum%998244353)

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
0


Fixed submission (verdict: Accepted):
import math

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

if D[0] != 0:
    print(0)
    exit()

dict = {}

for i in range(len(D)):
    if D[i] not in dict:
        dict[D[i]] = 1
    else:
        dict[D[i]] += 1

for i in range(max(D)):
    if i not in dict:
        dict[i] = 0
    
for key in dict:
    if key == 0:
        if dict[key] != 1:
            print(0)
            exit()       
    if dict[key] == 0:
        print(0)
        exit()
sum = 1
n = 0


dict_dm = sorted(dict)


flg = 0
for i in range(len(dict_dm)):
    if i == 1:
        
        n = dict[i]
    elif i >=1:
        
        sum = (sum * n**dict[i])%998244353
        n = dict[i]

print(sum%998244353)

Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
d = list(map(int, input().split()))
lis = [0 for i in range(10*5+100)]
ans = 1
if lis[0] != 1:
    print(0)
else:
    for i in d:
        lis[i] += 1
    for i in range(1, len(lis)):
        for j in lis[i]:
            ans *= lis[i-1]
    print(ans%998244353)


Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
d = list(map(int, input().split()))
lis = [0 for i in range(10**5+100)]
ans = 1
mx = -1
for i in d:
    lis[i] += 1
    if i > mx:
        mx = i
if lis[0] != 1 or d[0] != 0:
    print(0)
else:
    for i in range(1, mx+1):
        ans *= lis[i-1]**lis[i]
    print(ans%998244353)
Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    n=int(input())
    D=[int(_) for _ in input().split()]
    dc=Counter(D)
    dci=list(dc.items())
    dci.sort()
    mod,ans=998244353,1
    if D[0]!=0:
        print(0)
        sys.exit()

    for i,dcii in enumerate(dci):
        if i>2:
            ans*=dci[i-1][1]**dci[i][1]%mod
    print(ans%mod)

if __name__=='__main__':
    main()

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
1


Fixed submission (verdict: Accepted):
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    n=int(input())
    D=[int(_) for _ in input().split()]
    dc=Counter(D)
    mod,ans=998244353,1
    if D[0]!=0 or dc[0]!=1:
        print(0)
        sys.exit()
    for i,_ in enumerate(list(dc.items())):
        if i>1:
            ans*=dc[i-1]**dc[i]%mod
    print(ans%mod)

if __name__=='__main__':
    main()

Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
D = list(map(int,input().split()))
from collections import Counter
print(0)
c = Counter(D)
max_D = max(D)
if c[0]!=1:
  print(0)
  
elif max_D<=1:
  print(1)
  
else:
  answer=1
  for i in range(2,max_D+1):
    c_i2 = c[i]
    c_i1=c[i-1]
    answer *= c_i1**c_i2
    
  print(answer%998244353)

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
0
2


Fixed submission (verdict: Accepted):
N = int(input())
D = list(map(int,input().split()))
from collections import Counter
 
mod = 998244353
c = Counter(D)
max_D = max(D)
if c[0]!=1:
  print(0)
  
elif D[0]!=0:
  print(0)
  
elif max_D<=1:
  print(1)
  
else:
  answer=1
  for i in range(2,max_D+1):
    c_i2 = c[i]
    c_i1=c[i-1]
    answer = ((answer % mod) * ((c_i1**c_i2) % mod)) % mod
    
  print(answer%998244353)

Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
D=list(map(int,input().split()))
MOD=998244353

import collections
dic = collections.Counter(D)

maxkey = max(dic.keys())

ans=dic[0]
if ans == 0:
    for i in range(1,maxkey): 
        ans=ans*dic[i]**dic[i+1]
    print(ans%MOD)
else:
    print(0)

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
0


Fixed submission (verdict: Accepted):
N=int(input())
D=list(map(int,input().split()))
MOD=998244353

import collections
dic = collections.Counter(D)

maxkey = max(dic.keys())

ans=dic[0]
if ans == 1 and D[0] == 0:
    for i in range(1,maxkey): 
        ans=ans*(dic[i]**dic[i+1])%MOD
    print(ans)
else:
    print(0)
Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

_n = int(input())
_dlist = list(map(int, input().split()))


def chker(n, dlist):
    if dlist[0] != 0:
        print(0)
        return

    ds = dlist[1:]
    ds.sort()
    cntlist = [0] * n
    if ds[0] == 1:
        print(0)
        return

    cntlist[ds[0]] = 1
    for i in range(1, n - 1):
        if ds[i] <= ds[i - 1] + 1:
            cntlist[ds[i]] += 1
        else:
            print(0)
            return

    ans = 1
    for i in range(2, n):
        ans = (ans * cntlist[i - 1] ** cntlist[i]) % 998244353

    print(ans)


chker(_n, _dlist)


Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
0


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline

_n = int(input())
_dlist = list(map(int, input().split()))


def chker(n, dlist):
    if dlist[0] != 0:
        print(0)
        return

    ds = dlist[1:]
    ds.sort()
    cntlist = [0] * n
    if ds[0] != 1:
        print(0)
        return

    cntlist[ds[0]] = 1
    for i in range(1, n - 1):
        if ds[i] <= ds[i - 1] + 1:
            cntlist[ds[i]] += 1
        else:
            print(0)
            return

    ans = 1
    for i in range(2, n):
        ans = (ans * cntlist[i - 1] ** cntlist[i]) % 998244353

    print(ans)


chker(_n, _dlist)

Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
from collections import defaultdict
INF = 998244353
N = int(input())
dl = list(map(int, input().split()))
if dl[0] != 0:
    print(0)
    sys.exit()
d = defaultdict(int)

for i in range(1, N):
    d[dl[i]] += 1

d = sorted(d.items(), key=lambda x: x[0])

if len(d) == 1:
    print(0)
    sys.exit()

ans = 1
for i in range(len(d) - 1, 0, -1):
    if d[i][0] == d[i - 1][0] - 1:
        ans *= (d[i - 1][1] ** d[i][1])
        ans = ans % INF
    else:
        print(0)
        sys.exit()

print(ans)

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
0


Fixed submission (verdict: Accepted):
import sys
from collections import defaultdict
INF = 998244353
N = int(input())
dl = list(map(int, input().split()))
if dl[0] != 0:
    print(0)
    sys.exit()
d = defaultdict(int)

for i in range(N):
    d[dl[i]] += 1

d = sorted(d.items(), key=lambda x: x[0])

if d[0][1] != 1:
    print(0)
    sys.exit()

ans = 1
for i in range(len(d) - 1, 0, -1):
    if d[i][0] - 1 == d[i - 1][0]:
        ans *= (d[i - 1][1] ** d[i][1])
        ans = ans % INF
    else:
        print(0)
        sys.exit()

print(ans)
Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin
import bisect
from itertools import groupby
 
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
 
li.sort()
lin = []

for key, value in groupby(li):
    lin.append((key,len(list(value))))

if lin[0][0] != 0 or lin[0][1] > 1:
    print(0)
    exit()

print(lin)
point = 1
for i in range(1,len(lin)):
    if lin[i][1] <1:
        print(0)
        exit()
    point *= lin[i-1][1]**lin[i][1]
    point %= 998244353
    
print(point)

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
[(0, 1), (1, 2), (2, 1)]
2


Fixed submission (verdict: Accepted):
from sys import stdin
import bisect
from itertools import groupby
 
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
 
if li[0] != 0 or 0 in li[1:]:
    print(0)
    exit()

li.sort()
lin = []

for key, value in groupby(li):
    lin.append((key,len(list(value))))
 
point = 1
for i in range(1,len(lin)):
    if lin[i-1][0]+1 != lin[i][0]:
        print(0)
        exit()
    elif lin[i][1] == 0:
        print(0)
        exit()
    point *= (lin[i-1][1]**lin[i][1])
 
print(point%998244353)

Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter
n = int(input())
lst = list(map(int,input().split()))
mod = 998244353
c = dict(Counter(lst))
c = dict(sorted(c.items(), key=lambda x:x[0]))

ans = 1
pre_v = 1
for e,(k,v) in enumerate(c.items()):
    print(e,k,v)
    if e==0 and k!=0:
        ans = 0
        break
    elif e!=k:
        ans = 0
        break
    else:
        ans = ans*pow(pre_v, v, mod)%mod
        pre_v = v
print(ans%mod)

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
0 0 1
1 1 2
2 2 1
2


Fixed submission (verdict: Accepted):

from collections import Counter
n = int(input())
lst = list(map(int,input().split()))
if lst[0] != 0:
    print(0)
    exit()
mod = 998244353
c = dict(Counter(lst))
c = dict(sorted(c.items(), key=lambda x:x[0]))

for e,(k,v) in enumerate(c.items()):
    if e==0:
        if k!=0 or v!=1:
            ans = 0
            break
        else:
            pre_v = v
            ans = v
    elif e!=k or v==0:
        ans = 0
        break
    else:
        ans = ans*pow(pre_v, v, mod)%mod
        pre_v = v
print(ans%mod)
Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def modpow(a, n, mod):
    bi = format(n, 'b')
    res = 1
    for i in range(len(bi)):
        res = (res * res) % mod
        if bi[i] == '1':
            res = (res * a) % mod
    return res

N = int(input())
D = list(map(int, input().split()))
mod = 998244353

L = [0] * (max(D) + 1)
for d in D:
    L[d] += 1

L = [1, 100000, 10000]    
if (L[0] != 1) & (D[0] == 0):
    ans = 0
else:
    ans = 1
    for i in range(len(L)-1):
        ans *= modpow(L[i], L[i+1], mod)
        ans %= mod

print(ans)

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
514671008


Fixed submission (verdict: Accepted):
def modpow(a, n, mod):
    bi = format(n, 'b')
    res = 1
    for i in range(len(bi)):
        res = (res * res) % mod
        if bi[i] == '1':
            res = (res * a) % mod
    return res

N = int(input())
D = list(map(int, input().split()))
mod = 998244353

L = [0] * (max(D) + 1)
for d in D:
    L[d] += 1

if (L[0] != 1) | (D[0] != 0):
    ans = 0
else:
    ans = 1
    for i in range(len(L)-1):
        ans *= modpow(L[i], L[i+1], mod)
        ans %= mod

print(ans)

Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N = input()
    D_list = list(map(int, input().split()))

    if D_list[0] == 0:
        ans = 0
    
    else:
        maxD = max(D_list)
        count_ele_Dlist = [0] * (maxD + 1)
        ans = 1

        for i in D_list:
            count_ele_Dlist[i] = count_ele_Dlist[i] + 1

        for i in range(1, maxD + 1):
            ans = (ans * count_ele_Dlist[i - 1] ** count_ele_Dlist[i]) % 998244353
    
    print(ans)

if __name__ == "__main__":
    main()

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
0


Fixed submission (verdict: Accepted):
def main():
    N = input()
    D_list = list(map(int, input().split()))

    if D_list[0] != 0:
        ans = 0
    
    else:
        maxD = max(D_list)
        count_ele_Dlist = [0] * (maxD + 1)

        for i in D_list:
            count_ele_Dlist[i] = count_ele_Dlist[i] + 1

        if count_ele_Dlist[0] == 1:
            ans = 1
            for i in range(1, maxD + 1):
                ans = (ans * count_ele_Dlist[i - 1] ** count_ele_Dlist[i]) % 998244353
        else:
            ans = 0
        
    print(ans)

if __name__ == "__main__":
    main()
Problem: p02866
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
from collections import Counter

input = sys.stdin.readline

N = int(input())
ans = 1
mod = 998244353
D = sorted(Counter(list(map(int, input().split()))).items())
tmp = D[0][1]
stream = -1
for n, i in D:
    if stream + 1 != n:
        print(0)
        exit()
    if n == 0:
        continue
    ans *= pow(tmp, i)
    ans %= mod
    tmp = i
    stream += 1
print(ans)


Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
0


Fixed submission (verdict: Accepted):
import sys
from collections import Counter

input = sys.stdin.readline

N = int(input())
ans = 1
mod = 998244353
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
    exit()
D = sorted(Counter(D).items())
tmp = D[0][1]
stream = 0
for n, i in D:
    if stream != n:
        print(0)
        exit()
    if n == 0 and i == 1:
        stream += 1
        continue
    elif n==0:
        print(0)
        exit()
    ans *= pow(tmp, i)
    ans %= mod
    tmp = i
    stream += 1
print(ans)

Problem: p02866
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter
N = int(input())
D = list(map(int, input().split()))

c = Counter(D)

mod = 998244353

L = list(set(D[:]))

L.sort(reverse=True)
if (c[0] > 1):
    print(0)
    exit()

if 0 not in D:
    print(0)
    exit()


ans = []
for i in L:
    if (c[i - 1] == 0):
        ans.append(c[i])
        continue
    ans.append(c[i - 1] ** c[i])

if (len(ans) == 0):
    print(0)
    exit()
print(ans)
multi_ans = 1
for i in ans:
    multi_ans *= i

print(multi_ans % mod)


Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
[2, 1, 1]
2


Fixed submission (verdict: Accepted):
from collections import Counter
N = int(input())
D = list(map(int, input().split()))

c = Counter(D)

mod = 998244353

L = list(set(D[:]))

L.sort(reverse=True)
if (D[0] != 0):
    print(0)
    exit()

if (c[0] > 1):
    print(0)
    exit()

if (N == 1):
    print(1)
    exit()

ans = []
for i in L:
    if (i == 0):
        break
    else:
        ans.append(c[i - 1] ** c[i])


if (len(ans) == 0):
    print(0)
    exit()

multi_ans = 1
for i in ans:
    multi_ans *= i

print(multi_ans % mod)
Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

pre_strk = 1
now_strk = 1
ans = 1
n = int(input())
d_list = list(map(int,input().split()))
d_list.sort()
print(d_list)
if d_list[0] != 0:
    print(0)
    sys.exit()

for i in range(1,n):
    if d_list[i] == d_list[i-1]:
        now_strk += 1
    elif d_list[i] != d_list[i-1] and (d_list[i-1] != 1 or d_list[i-1] != 0):
        ans *= pre_strk ** now_strk
        pre_strk = now_strk
        now_strk = 1
        print(ans)
    else:
        pre_strk = now_strk
        now_strk = 1
ans *= pre_strk ** now_strk
print(ans)



Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
[0, 1, 1, 2]
1
1
2


Fixed submission (verdict: Accepted):
import sys

pre_strk = 1
now_strk = 1
ans = 1
n = int(input())
d_list = list(map(int,input().split()))

if d_list[0] != 0:
    print(0)
    sys.exit()

d_list.sort()
if d_list[1] == 0:
    print(0)
    sys.exit()

for i in range(1,n):
    if d_list[i] == d_list[i-1]:
        now_strk += 1

    elif d_list[i] > d_list[i-1] + 1:
        print(0)
        sys.exit()

    elif d_list[i] != d_list[i-1] and d_list[i-1] != 1:
        for j in range(now_strk):
            ans *= pre_strk
        pre_strk = now_strk
        now_strk = 1
        
        ans = ans % 998244353

    else:
        pre_strk = now_strk
        now_strk = 1
for i in range(now_strk):
    ans *= pre_strk
print(ans%998244353)

Problem: p02866
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import os
N=int(input())
a=list(map(int, input().split()))
if not (a[0]==0):
  print(0)
elif 0 in a[1:]:
  print(0)
else:
  m=max(a)
  b=[0]*m
  for i in a[1:]:
    b[i-1]+=1
  if 0 in b:
    print(0)
  else:
    res=1
    print(b)
    for i in range(1,len(b)):
      res*=b[i-1]**b[i]
    print(res%998244353)

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
[2, 1]
2


Fixed submission (verdict: Accepted):
import os
N=int(input())
a=list(map(int, input().split()))
if not (a[0]==0):
  print(0)
else:
  m=max(a)
  b=[0]*m
  flag=True
  for i in a[1:]:
    if i==0:
      print(0)
      flag=False
    b[i-1]+=1
  if flag:
    res=1
    
    for i in range(1,len(b)):
      res*=b[i-1]**b[i]

    print((res)%998244353)
Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter
import math
n = int(input())
d = list(map(int, input().split()))

setD = list(set(d))
setD.sort()
ans = 1


if d[0] > 0:
        print(0)
else:
        c = Counter(d)
        
        
        
        

        
                
        
        for _d in d:
                if _d != 0:
                        
                        print(c[_d - 1])
                        
                        ans *= c[_d - 1]

        

        hoge = 1
        for _d in d:
                if _d != 0:
                        hoge *= _d
        print(hoge)

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
1
1
2
2


Fixed submission (verdict: Accepted):
from collections import Counter
import math
n = int(input())
d = list(map(int, input().split()))

for i in range(1, n):
        if d[i] == 0:
                print(0)
                exit()

ans = 1
setD = list(set(d))




if d[0] > 0:
        print(0)
else:
        c = Counter(d)
        
        
        
        
        
        
        

        for _d in setD:
                if _d != 0:
                        ans *= c[_d - 1] ** c[_d]

        print(ans%998244353)

Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter
import math
n = int(input())
d = list(map(int, input().split()))

setD = list(set(d))
setD.sort()
ans = 1
nodeMulti = 1

if d[0] > 0:
        print(0)
        exit()
else:
        c = Counter(d)
        for s in setD:
                ans *= math.factorial(c[s])
                nodeMulti *= c[s]
        nodeMulti 
        ans *= nodeMulti
        print(ans%998244353)

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
4


Fixed submission (verdict: Accepted):
from collections import Counter
import math
n = int(input())
d = list(map(int, input().split()))

for i in range(1, n):
        if d[i] == 0:
                print(0)
                exit()

ans = 1
setD = list(set(d))




if d[0] > 0:
        print(0)
else:
        c = Counter(d)
        
        
        
        
        
        
        

        for _d in setD:
                if _d != 0:
                        ans *= c[_d - 1] ** c[_d]

        print(ans%998244353)
Problem: p02866
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter
mod = 998244353
n = int(input())
d = list(map(int,input().split()))
if d[0] != 0:
    print(0)
    exit()

C = Counter(d)
C = dict(sorted(C.items()))
print(C)

memo1 = C[1]
memo2 = 1
ans = 1

for i in range(1,n):
    if d[i] == 0:
        print(0)
        exit()

for key in C:
    if key >= 2:
        print(key)
        if memo2 + 1 != key: 
            print(0)
            exit()
        ans = (ans * memo1 ** C[key]) % mod 
        memo1 = C[key]
        memo2 = key
print(ans)
    

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
{0: 1, 1: 2, 2: 1}
2
2


Fixed submission (verdict: Accepted):
from collections import Counter
mod = 998244353
n = int(input())
d = list(map(int,input().split()))
if d[0] != 0:
    print(0)
    exit()

C = Counter(d)
C = dict(sorted(C.items()))

memo1 = C[1]
memo2 = 1
ans = 1

for i in range(1,n):
    if d[i] == 0:
        print(0)
        exit()

for key in C:
    if key >= 2:
        if memo2 + 1 != key: 
            print(0)
            exit()
        ans = (ans * memo1 ** C[key]) % mod 
        memo1 = C[key]
        memo2 = key
print(ans)

Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    import collections
    import sys
    input = sys.stdin.readline
    n = int(input())
    d = list(map(int, input().split()))
    ans = 1
    tmp = -1
    if d[0] != 0:
        print(0)
    else:
        c = collections.Counter(d)
        if 0 in c.keys() and c[0] > 1:
            print(0)
            exit()
        for i in range(1, n):
            if i in c.keys():
                if i == 1:
                    ans *= c[1]
                else:
                    ans = (ans ** c[i]) * c[i]
                ans %= 998244353
            else:
                tmp = i
                break
        for i in range(tmp + 1, n):
            if i in c.keys():
                print(0)
                exit()


if __name__ == "__main__":
    main()


Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:

Fixed submission (verdict: Accepted):
def main():
    import collections
    import sys
    input = sys.stdin.readline
    n = int(input())
    d = list(map(int, input().split()))
    c = collections.Counter(d)
    ans = 1
    tmp = -1
    if d[0] != 0 or c[0] > 1:
        print(0)
        exit()
    for i in range(2, n):
        if i - 1 in c.keys():
            ans *= c[i - 1] ** c[i]
            ans %= 998244353
        else:
            tmp = i
            break
    if tmp >= 0:
        for j in range(tmp, n):
            if j in c.keys():
                print(0)
                exit()
    print(ans)


if __name__ == "__main__":
    main()
Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
d = [int(i) for i in input().split()]
a = [0] * n
for i in d:
    a[i] += 1
if d[0] != 0:
    print(0)
else:
    j = 1
    for i in range(n - 1):
        if a[i] == 0:
            break
        j *= a[i] ** a[i + 1]
        j %= 998244353
    print(a)
    print(j)

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
[1, 2, 1, 0]
2


Fixed submission (verdict: Accepted):
n = int(input())
d = [int(i) for i in input().split()]
a = [0] * n
k = 0
for i in d:
    a[i] += 1
    k=max(k,i)
if d[0] != 0:
    print(0)
elif a[0] != 1:
    print(0)
else:
    j = 1
    for i in range(k):
        j *= a[i] ** a[i + 1]
        j %= 998244353
    print(j)

Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter

def cal(MC,m):
    n = len(MC)
    for i in range(n):
        if MC[i][0] != i:
            
            return 0
    if MC[0][1] != 1:
        
        return 0

    output = 1
    for i in range(n-1):
        output *= pow(MC[i][1],MC[i+1][1],m)
        output %= m
    return output

def main():
    N = int(input())
    D = list(map(int,input().split()))
    M = 998244353
    
    
    
    C = Counter(D)
    MC = C.most_common()
    MC.sort(key = lambda x:x[0])
    print(MC)
    ans = cal(MC,M)
    print(ans)

if __name__ == "__main__":
    main()


Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
[(0, 1), (1, 2), (2, 1)]
2


Fixed submission (verdict: Accepted):
from collections import Counter

def cal(D,M):
    C = Counter(D)
    MC = C.most_common()
    MC.sort(key = lambda x:x[0])
    n = len(MC)
    
    
    
    for i in range(n):
        if MC[i][0] != i:
            
            return 0
    if MC[0][1] != 1 or D[0] != 0:
        
        return 0

    output = 1
    for i in range(n-1):
        output *= pow(MC[i][1],MC[i+1][1],M)
        output %= M
    return output

def main():
    N = int(input())
    D = list(map(int,input().split()))
    M = 998244353

    ans = cal(D,M)
    print(ans)

if __name__ == "__main__":
    main()

Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter

N = int(input())
*D, = map(int, input().split())
mod = 998244353
c = Counter(D)
v = max(D)

if c[0]!=1 or D[0]!=0:
    print(0)
else:
    ans = 1
    for i in range(1, v+1):
        ans *= (c[i-1]**c[i])
        ans %= mod

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:

Fixed submission (verdict: Accepted):
from collections import Counter

N = int(input())
*D, = map(int, input().split())
mod = 998244353
c = Counter(D)
v = max(D)

if c[0]!=1 or D[0]!=0:
    print(0)
else:
    ans = 1
    for i in range(1, v+1):
        ans *= (c[i-1]**c[i])
        ans %= mod
    print(ans)
Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
n=int(input())
d=list(map(int,input().split()))
num_d=[0 for i in range(n)]
if d[0]!=0:
  print(0)
  sys.exit()
for i in d:
  if i==0:
    print(0)
    sys.exit()
  num_d[i]+=1
max_d=0
ans=1
for i in range(1,n):
  if num_d[i]!=0:
    if max_d!=i-1:
      print(0)
      sys.exit()
    max_d=i
    ans*=num_d[i-1]**num_d[i]
    ans%=998244353
print(ans)

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
0


Fixed submission (verdict: Accepted):
import sys
n=int(input())
d=list(map(int,input().split()))
num_d=[0 for i in range(n)]
num_d[0]=1
if d[0]!=0:
  print(0)
  sys.exit()
for i in range(1,len(d)):
  if d[i]==0:
    print(0)
    sys.exit()
  num_d[d[i]]+=1
max_d=0
ans=1
for i in range(1,n):
  if num_d[i]!=0:
    if max_d!=i-1:
      print(0)
      sys.exit()
    max_d=i
    ans*=num_d[i-1]**num_d[i]
    ans%=998244353
print(ans)

Problem: p02866
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def main():
    MOD = 998244353
    N = int(input())
    D = [int(i) for i in input().split()]
    if D[0] != 0:
        return print(0)
    from collections import Counter
    c = Counter(D)
    ans = 1
    for k, v in sorted(c.items()):
        print(k, v)
        if k == 0 or k == 1:
            continue
        elif v == 0:
            return print(0)
        else:
            ans *= c[k-1]**v
            ans = int(ans) % MOD
    print(ans % MOD)


if __name__ == '__main__':
    main()


Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
0 1
1 2
2 1
2


Fixed submission (verdict: Accepted):
def main():
    MOD = 998244353
    N = int(input())
    D = [int(i) for i in input().split()]
    if D[0] != 0:
        return print(0)
    from collections import Counter
    c = Counter(D)
    ans = 1
    for d in D[1:]:
        if d == 0:
            return print(0)
        ans *= c[d-1]
        ans %= MOD
    print(ans % MOD)


if __name__ == '__main__':
    main()
Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin
import bisect
from itertools import groupby
 
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
 
li.sort()
lin = []

for key, value in groupby(li):
    lin.append((key,len(list(value))))

print(lin)

if lin[0][0] != 0 or lin[0][1] > 1:
    print(0)
    exit()

point = 1
for i in range(1,len(lin)):
    if lin[i-1][0]+1 != lin[i][0]:
        print(0)
        exit()
    point *= (lin[i-1][1]**lin[i][1])

print(point%998244353)

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
[(0, 1), (1, 2), (2, 1)]
2


Fixed submission (verdict: Accepted):
from sys import stdin
import bisect
from itertools import groupby
 
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
 
if li[0] != 0 or 0 in li[1:]:
    print(0)
    exit()

li.sort()
lin = []

for key, value in groupby(li):
    lin.append((key,len(list(value))))
 
point = 1
for i in range(1,len(lin)):
    if lin[i-1][0]+1 != lin[i][0]:
        print(0)
        exit()
    elif lin[i][1] == 0:
        print(0)
        exit()
    point *= (lin[i-1][1]**lin[i][1])
 
print(point%998244353)

Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter

n = int(input())
s = input()
if s[0] != 0:
    print(0)
    exit()
d = Counter(map(int, s.split()))
mod = 998244353

if 0 not in d or d[0] > 1:
    print(0)
    exit()
if n == 1:
    print(1)
    exit()

ans = 1
for i in range(1,len(d)):
    if i not in d:
        print(0)
        exit()
    ans = (ans * d[i-1]**d[i]) % mod

print(ans % mod)



Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
0


Fixed submission (verdict: Accepted):
from collections import Counter

n = int(input())
s = input()
if s[0] != '0':
    print(0)
    exit()

d = Counter(map(int, s.split()))
mod = 998244353

if 0 not in d or d[0] > 1:
    print(0)
    exit()
if n == 1:
    print(1)
    exit()

ans = 1
for i in range(1,len(d)):
    if i not in d:
        print(0)
        exit()
    ans = (ans * d[i-1]**d[i]) % mod

print(ans % mod)
Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
l = list(map(int, input().split()))

div_num = 998244353
result = 1
ct_l = []

for i in range(n):
    ct_l.append(0)

for item in l:
    ct_l[item] += 1


prev_v = -1
curr_v = -1
e = n-1

for i, item in enumerate(ct_l):
    if i == 2:
        break
    if i == 0 and item == 1:
        pass
    else:
        e -= item
    if i == 1:
        prev_v = item

for i, item in enumerate(ct_l[2:]):
    print(prev_v, item, e, result)
    e -= item
    if item == 0:
        break
    curr_v = item
    result *= prev_v**curr_v%div_num
    prev_v = curr_v
    

if e < 0:
    print(0)
else:
    print(result)

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
2 1 1 1
1 0 0 2
2


Fixed submission (verdict: Accepted):
n = int(input())
l = list(map(int, input().split()))

div_num = 998244353
result = 1
ct_l = []

for i in range(max(l)+1):
    ct_l.append(0)

for item in l:
    ct_l[item] += 1


prev_v = -1
curr_v = -1
e = n-1

for i, item in enumerate(ct_l):
    if i == 2:
        break
    if i == 0 and item == 1:
        pass
    else:
        e -= item
    if i == 1:
        prev_v = item

for i, item in enumerate(ct_l[2:]):
    
    e -= item
    if item == 0:
        break
    curr_v = item
    result *= prev_v**curr_v
    result %= div_num
    prev_v = curr_v
    

if e < 0 or e > 0 or l[0] > 0:
    print(0)
elif n == l[1]:
    print(1)
else:
    print(result)

Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter
n = int(input())
d = list(map(int, input().split()))

if d[0] != 0:
    print(0)
    exit()

cnt = Counter(d)
print(cnt)

if cnt[0] != 1:
    print(0)
    exit()

ans = 1
for i in d:
    if i != 0:
        ans = (ans * cnt[i-1]) % 998244353
print(ans)


Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
Counter({1: 2, 0: 1, 2: 1})
2


Fixed submission (verdict: Accepted):
from collections import Counter
n = int(input())
d = list(map(int, input().split()))

if d[0] != 0:
    print(0)
    exit()

cnt = Counter(d)

if cnt[0] != 1:
    print(0)
    exit()

ans = 1
for i in d:
    if i != 0:
        ans = (ans * cnt[i-1]) % 998244353
print(ans)
Problem: p02866
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
from collections import Counter

input = sys.stdin.readline

N = int(input())
ans = 1
mod = 998244353
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
    exit()
D = sorted(Counter(D).items())
tmp = D[0][1]
stream = 0
for n, i in D:
    if stream != n:
        print(0)
        exit()
    if n == 0 and i == 1:
        stream += 1
        continue
    else:
        print(0)
        exit()
    ans *= pow(tmp, i)
    ans %= mod
    tmp = i
    stream += 1
print(ans)


Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
0


Fixed submission (verdict: Accepted):
import sys
from collections import Counter

input = sys.stdin.readline

N = int(input())
ans = 1
mod = 998244353
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
    exit()
D = sorted(Counter(D).items())
tmp = D[0][1]
stream = 0
for n, i in D:
    if stream != n:
        print(0)
        exit()
    if n == 0 and i == 1:
        stream += 1
        continue
    elif n==0:
        print(0)
        exit()
    ans *= pow(tmp, i)
    ans %= mod
    tmp = i
    stream += 1
print(ans)

Problem: p02866
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(10**5)]
MOD = 998244353

max_B = -1
for i in range(1, len(A)):
    B[A[i]-1] += 1
    if A[i] > max_B:
        max_B = A[i]

ans = 1
if A[0] != 0:
    ans = 0 

for i in range(1, max_B):    
    if B[i] == 0:
        ans = 0 
        break
    else:
        print(ans)
        ans = (ans * (B[i-1] ** B[i])%MOD)%MOD

print(ans)


Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
1
2


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(10**5)]
MOD = 998244353

max_B = -1
ans = 1

for i in range(1, len(A)):
    if A[i]==0:
        ans = 0
    else:
        B[A[i]-1] += 1
    if A[i] > max_B:
        max_B = A[i]

if A[0] != 0:
    ans = 0 

for i in range(1, max_B):    
    if B[i] == 0:
        ans = 0 
        break
    else:
        ans = (ans * (B[i-1] ** B[i])%MOD)%MOD

print(ans)
Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    n=int(input())
    D=[int(_) for _ in input().split()]
    dc=Counter(D)
    dci=list(dc.items())
    dci.sort()
    mod,ans=998244353,1
    if D[0]!=0 or (D[0]==0 and dci[0][1]>1):
        print(0)
        sys.exit()
    print(dci)
    for i in range(len(dci)):
        if dci[i][0]!=i:
            print(0)
            break
        if i>=2:
            ans*=dci[i-1][1]**dci[i][1]%mod
    else:
        print(ans)

if __name__=='__main__':
    main()

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
[(0, 1), (1, 2), (2, 1)]
2


Fixed submission (verdict: Accepted):
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    n=int(input())
    D=[int(_) for _ in input().split()]
    dc=Counter(D)
    mod,ans=998244353,1
    if D[0]!=0 or dc[0]!=1:
        print(0)
        sys.exit()
    for i,_ in enumerate(list(dc.items())):
        if i>1:
            ans*=dc[i-1]**dc[i]%mod
    print(ans%mod)

if __name__=='__main__':
    main()

Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import collections
N=int(input())
d=list(map(int,input().split()))
dd = collections.Counter(d)
if dd[0]!=1:
    print(0)
    exit()
count=1
for i in range(0,max(d)):
    count = (count*pow(i+1,dd[i],99844353))%99844353
print(count%99844353)


Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
4


Fixed submission (verdict: Accepted):
n=int(input())
d=list(map(int,input().split()))
mod=998244353
from collections import Counter
q=Counter(d)
if q[0]!=1 or d[0]!=0:
	print(0)
	exit()
ans=1
for i in range(1,max(q)+1):
    ans *=pow(q[i-1],q[i],mod)
    ans %=mod
print(ans)

Problem: p02866
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
d_list = list(map(int,input().split()))

dist = [0] * 10**5
max_d = 0
for d in d_list:
    dist[d] += 1
    max_d = max(max_d, d)

MOD = 998244353
if d_list[0] != 1:
    print(0)
    exit()
if dist[0]>1:
    print(0)
    exit()

ans = 1
for i in range(max_d):
    if dist[i] == 0 or dist[i+1] ==0:
        print(0)
        exit()
    ans *= (dist[i]**dist[i+1])%MOD
print(ans)

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
d_list = list(map(int,input().split()))

dist = [0] * 10**5
max_d = 0
for d in d_list:
    dist[d] += 1
    max_d = max(max_d, d)

MOD = 998244353
if d_list[0] != 0:
    print(0)
    exit()
elif dist[0]>1:
    print(0)
    exit()

ans = 1
for i in range(max_d):
    if dist[i] == 0 or dist[i+1] ==0:
        print(0)
        exit()
    ans *= (dist[i]**dist[i+1])
    ans %= MOD

print(ans)
Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
ls = list(map(int, input().split(' ')))
n = 100000
ls = [i%31 for i in range(n)]
ans = 1
if ls[0] != 0:
    ans = 0
m = max(set(ls))
if m > n:
    ans = 0

d = {}
for l in ls:
    d[l] = d.get(l, 0) + 1
if ans != 0:
    for i in range(1, m+1):
        if d[i] == 0:
            ans = 0
        ans = (ans * (d[i-1] ** d[i])) % 998244353
print(ans)


Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
449926144


Fixed submission (verdict: Accepted):
n = int(input())
ls = list(map(int, input().split(' ')))
m = max(set(ls))
d = {}
for l in ls:
    d[l] = d.get(l, 0) + 1
ans = 0 if (ls[0] != 0 or d.get(0) >= 2) else 1
for i in range(1, m+1):
    if i not in d:
        ans = 0
    ans = (ans * (d.get(i-1, 0) ** d.get(i, 0))) % 998244353 
print(ans)

Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
from collections import Counter
inputs = sys.stdin.readlines()

n = int(inputs[0])
A = list(map(int, inputs[1].split()))
MOD = 998244353

B = sorted(Counter(A).items())
C = [b[1] for b in B]
if all([i == k for i, (k, v) in enumerate(B)]) and A[0] == 1:
    ans = 1
    for i in range(1, len(C)-1):
        ans *= pow(C[i], C[i+1], MOD) % MOD
else:
    ans = 0
print(ans) 

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
0


Fixed submission (verdict: Accepted):
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)

Problem: p02866
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
D = list(map(int, input().split()))

MOD = 998244353

occ = [0 for i in range(N+5)]
for d in D:
    occ[d] += 1

if occ[0] != 1:
    print(0)
    quit()

cur = 1
t = 1
for i in range(1, N+5):
    if occ[i] == 0:
        break
    t += occ[i]
    cur *= pow(occ[i - 1], occ[i])
    cur %= MOD

if t == N - 1:
    print(cur % MOD)
else:
    print(0)


Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
D = list(map(int, input().split()))

 
MOD = 998244353
 
occ = [0 for i in range(N+5)]
for d in D:
    occ[d] += 1
 
if occ[0] != 1 or D[0] != 0:
    print(0)
    quit()
 
cur = 1
for i in range(1, N+5):
    cur *= pow(occ[i - 1], occ[i])
    cur %= MOD
print(cur % MOD)
Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
d=list(map(int,input().split()))
c=[0]*n
ans=0
for i in range(0,n):
  c[d[i]]+=1

if d[0]!=0 or c[0]!=1:
  print(0)
  
else:
  for j in range(2,n):
    ans*=c[j]**c[j-1]
  print(ans)  
    
  

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
0


Fixed submission (verdict: Accepted):
n=int(input())
d=list(map(int,input().split()))
x=max(d)
li=[0]*(x+1)
for i in range(n):
    li[d[i]]+=1
if d[0]!=0 or li[0]!=1:
    print(0) 
else:
    ans=1
    for i in range(2,len(li)):
        ans*=pow(li[i-1],li[i],998244353)   
    print(ans%998244353)

Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))

output = 1
if a[0] != 0:
    print(0)
elif max(a) == 1:
    print(1)
else:
    for i in range(2, max(a)+1):
        if a.count(i) == 1:
            continue
        output *= pow(a.count(i-1),a.count(i),998244353)
    print(output)

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().split()))
cnt = [0]*n
for i in a:
    cnt[i] += 1

output = 1
if a[0] != 0 or cnt[0] != 1:
    print(0)
elif max(a) == 1:
    print(1)
else:
    for i in range(2, n):
        output *= cnt[i-1]**cnt[i]
        output %= 998244353
    print(output)

Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
d=[int(x) for x in input().split()]

d.sort()
dd=[0]*10**5
max=0
for i in d:
    dd[i]+=1
    if(max<i):
        max=i

ans=True
now=1
before=0
if(dd[0]!=1):
    ans=False
else:
    before=1

for i in range(1,max+1):
    if(dd[i]==0):
        ans=False
    now=now*(before**dd[i]) % 998244353
    before=dd[i]
    print(dd[i],now)

if(ans):
    print(now)
else:
    print("0")

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
2 1
1 2
2


Fixed submission (verdict: Accepted):
n=int(input())
d=[int(x) for x in input().split()]
ans=True
if(d[0]!=0):
    ans=False
d.sort()
dd=[0]*10**5
max=0
for i in d:
    dd[i]+=1
    if(max<i):
        max=i

now=1
before=0
if(dd[0]!=1):
    ans=False
else:
    before=1

for i in range(1,max+1):
    if(dd[i]==0):
        ans=False
    now=now*(before**dd[i]) % 998244353
    before=dd[i]
    

if(ans):
    print(now)
else:
    print("0")
Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
d = list(map(int, input().split()))
mod = 998244353
distance_dict = {}
if d[0] != 0:
    print(0)
    exit()
for i in range(1,n):
    if d[i] == 0:
        print(0)
        exit()
    distance_dict[d[i]] = 0

for i in range(1,n):
    distance_dict[d[i]] += 1
pre = 1
ans = 1
for i in range(1,n):
    if i in distance_dict:
      ans *= pre ** distance_dict[i]
      pre = distance_dict[i]
      ans %= mod
      if i - 1 not in distance_dict:
          print(0)
          exit()
print(ans)

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
d = list(map(int, input().split()))
mod = 998244353
distance_dict = {}
if d[0] != 0:
    print(0)
    exit()
for i in range(1,n):
    if d[i] == 0:
        print(0)
        exit()
    distance_dict[d[i]] = 0

for i in range(1,n):
    distance_dict[d[i]] += 1
pre = 1
ans = 1
for i in range(1,n):
    if i in distance_dict:
      ans *= pre ** distance_dict[i]
      pre = distance_dict[i]
      ans %= mod
      if i != 1 and i - 1 not in distance_dict:
          print(0)
          exit()
print(ans)

Problem: p02866
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

from collections import Counter
N = int(input())
D = list(map(int, input().split()))


c = Counter(D)


print(c)
ans = 1
if D[0] > 0:
    print(0)
    exit()
elif c[0] != 1:
    print(0)
    exit()
else:
    for i in range(1,max(D)+1):
        ans *= i**c[i]
        ans = ans % 998244353
print(ans)

Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
Counter({1: 2, 0: 1, 2: 1})
2


Fixed submission (verdict: Accepted):

import collections
N = int(input())
D = list(map(int, input().split()))

c = collections.Counter(D)
ans = 1
tmp = 1
if D[0] > 0:
    print(0)
    exit()
elif c[0] != 1:
    print(0)
    exit()
else:
    for i in range(1,max(D)+1):
        ans *= (tmp ** c[i])
        ans = ans % 998244353
        tmp = c[i]
print(ans)

Problem: p02866
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter

MOD = 998244353

N = int(input())
D = [int(i) for i in input().split()]

counter = Counter(D)


ans = 1
count = 0
for i, item in enumerate(sorted(counter.items(), key=lambda x: x[0])):
    
    
    if i != item[0]:
        ans = 0
        break
    if item[0] == 0 and item[1] != 0:
        ans = 0
        break
    else:
        ans *= (count ** item[1]) % MOD
    count = item[1]
print(ans % MOD)


Failing test case input:
4
0 1 1 2

Expected output:
2

Actual output:
0


Fixed submission (verdict: Accepted):
from collections import Counter

MOD = 998244353

N = int(input())
D = [int(i) for i in input().split()]

counter = Counter(D)


if D[0] != 0:
    ans = 0
else:
    ans = 1
    count = 1
    for i, item in enumerate(sorted(counter.items(), key=lambda x: x[0])):
        
        
        if i != item[0]:
            ans = 0
            break
        if item[0] == 0 and item[1] != 1:
            ans = 0
            break

        ans *= (count ** item[1]) % MOD
        count = item[1]
print(ans % MOD)