Buggy python submission (verdict: Runtime Error):
n = int(input())
d = list(map(int, input().split()))
b = 1
ans = 1
max = 0
dd=[0]*10**5
for i in d:
    dd[i]+=1
max = max(d)
if d[0] == 0 and d.count(0) == 1:
    for i in range(1, max+1):
        if dd[i] == 0:
            print(0)
            exit()
        if dd[i] == 1:
            ans *= b
        else:
            if b != 1:
                ans *= pow(b, dd[i], 998244353)
        b = dd[i]
    print(ans % 998244353)
else:
    print(0)

Fixed submission:
n = int(input())
d = list(map(int, input().split()))
b = 1
ans = 1
dd=[0]*10**5
for i in d:
    dd[i]+=1
max = max(d)
if d[0] == 0 and d.count(0) == 1:
    for i in range(1, max+1):
        if dd[i] == 0:
            print(0)
            exit()
        if dd[i] == 1:
            ans *= b
        else:
            if b != 1:
                ans *= pow(b, dd[i], 998244353)
        b = dd[i]
    print(ans % 998244353)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x

N = int(input())
D = list(map(int,input().split()))
ans = 1
a = 0
if D[0] != 0 or D.count(0) > 1:
  print(0)
  exit()

prev = 1
for i in range (max(D)):
  if D.count(i+1) == 0:
    if a < N-1:
      print(0)
      exit()
    else:
      print(ans)
      exit()
  else:
    count = D.count(i+1)
    a += count
    ans = ( ans * pow_k(prev,count) ) %998244353 
    prev = count
print(ans)

Fixed submission:
n = int(input())
d = list(map(int, input().split()))
b = 1
ans = 1
dd=[0]*10**5
for i in d:
    dd[i]+=1
max = max(d)
if d[0] == 0 and d.count(0) == 1:
    for i in range(1, max+1):
        if dd[i] == 0:
            print(0)
            exit()
        if dd[i] == 1:
            ans *= b
        else:
            if b != 1:
                ans *= pow(b, dd[i], 998244353)
        b = dd[i]
    print(ans % 998244353)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x

N = int(input())
D = list(map(int,input().split()))
ans = 1
a = 0
if D[0] != 0 or D.count(0) > 1:
  print(0)
  exit()

prev = 1
for i in range (N-2):
  if D.count(i+1) == 0:
    if a < N-1:
      print(0)
      exit()
    else:
      print(ans)
      exit()
  else:
    count = D.count(i+1)
    a += count
    ans = ( ans * pow_k(prev,count) ) %998244353 
    prev = count
print(ans)

Fixed submission:
n = int(input())
d = list(map(int, input().split()))
b = 1
ans = 1
dd=[0]*10**5
for i in d:
    dd[i]+=1
max = max(d)
if d[0] == 0 and d.count(0) == 1:
    for i in range(1, max+1):
        if dd[i] == 0:
            print(0)
            exit()
        if dd[i] == 1:
            ans *= b
        else:
            if b != 1:
                ans *= pow(b, dd[i], 998244353)
        b = dd[i]
    print(ans % 998244353)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x

N = int(input())
D = list(map(int,input().split()))
ans = 1
if D[0] != 0 or D.count(0) > 1:
  print(0)
  exit()

prev = 1
for i in range (N-2):
  count = D.count(i+1)
  ans = ( ans * pow_k(prev,count) ) %998244353 
  prev = count
print(ans)
  

Fixed submission:
n = int(input())
d = list(map(int, input().split()))
b = 1
ans = 1
dd=[0]*10**5
for i in d:
    dd[i]+=1
max = max(d)
if d[0] == 0 and d.count(0) == 1:
    for i in range(1, max+1):
        if dd[i] == 0:
            print(0)
            exit()
        if dd[i] == 1:
            ans *= b
        else:
            if b != 1:
                ans *= pow(b, dd[i], 998244353)
        b = dd[i]
    print(ans % 998244353)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
D = list(map(int,input().split()))
ans = 1
if D[0] != 0 or D.count(0) > 1:
  print(0)
  exit()

prev = 1
for i in range (N-2):
  count = D.count(i+1)
  ans = ( ans * (prev**count)  ) %998244353 
  prev = count
print(ans)
  

Fixed submission:
n = int(input())
d = list(map(int, input().split()))
b = 1
ans = 1
dd=[0]*10**5
for i in d:
    dd[i]+=1
max = max(d)
if d[0] == 0 and d.count(0) == 1:
    for i in range(1, max+1):
        if dd[i] == 0:
            print(0)
            exit()
        if dd[i] == 1:
            ans *= b
        else:
            if b != 1:
                ans *= pow(b, dd[i], 998244353)
        b = dd[i]
    print(ans % 998244353)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
D = list(map(int,input().split()))
ans = 1
if D[0] != 0:
  print(0)
  exit()

prev = 0
for i in range (N):
  if i == 0:
    prev = 1
    if D[0] != 0 or D.count(i) > 1:
      print(0)
      exit()
  else:
    count = D.count(i)
    ans = ( ans * ((prev**count) %998244353 ) ) %998244353
    prev = count
print(ans)

Fixed submission:
n = int(input())
d = list(map(int, input().split()))
b = 1
ans = 1
dd=[0]*10**5
for i in d:
    dd[i]+=1
max = max(d)
if d[0] == 0 and d.count(0) == 1:
    for i in range(1, max+1):
        if dd[i] == 0:
            print(0)
            exit()
        if dd[i] == 1:
            ans *= b
        else:
            if b != 1:
                ans *= pow(b, dd[i], 998244353)
        b = dd[i]
    print(ans % 998244353)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
D = list(map(int,input().split()))
ans = 1
if D[0] != 0:
  print(0)
  exit()

prev = 0
for i in range (N):
  if i == 0:
    prev = 1
    if D[0] != 0 or D.count(i) > 1:
      print(0)
      exit()
  else:
    count = D.count(i)
    ans = (ans * (prev**count) ) %998244353
    prev = count
print(ans)

Fixed submission:
n = int(input())
d = list(map(int, input().split()))
b = 1
ans = 1
dd=[0]*10**5
for i in d:
    dd[i]+=1
max = max(d)
if d[0] == 0 and d.count(0) == 1:
    for i in range(1, max+1):
        if dd[i] == 0:
            print(0)
            exit()
        if dd[i] == 1:
            ans *= b
        else:
            if b != 1:
                ans *= pow(b, dd[i], 998244353)
        b = dd[i]
    print(ans % 998244353)
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
D = list(map(int,input().split()))
ans = 1
if D[0] != 0:
  print(0)
  exit()

prev = 0
for i in range (N):
  if i == 0:
    prev = 1
    if D[0] != 0 or D.count(i) > 1:
      print(0)
      exit()
  else:
    count = D.count(i)
    ans = ans * (prev**count)
    prev = count
print(ans%998244353)

Fixed submission:
n = int(input())
d = list(map(int, input().split()))
b = 1
ans = 1
dd=[0]*10**5
for i in d:
    dd[i]+=1
max = max(d)
if d[0] == 0 and d.count(0) == 1:
    for i in range(1, max+1):
        if dd[i] == 0:
            print(0)
            exit()
        if dd[i] == 1:
            ans *= b
        else:
            if b != 1:
                ans *= pow(b, dd[i], 998244353)
        b = dd[i]
    print(ans % 998244353)
else:
    print(0)