import sys #input = sys.stdin.readline input = sys.stdin.buffer.readline def cmb(n,k): if (k<0) or (n 0: amari = n%p nn.append(amari) n //= p kk = [] while k > 0: amari = k%p kk.append(amari) k //= p #足りない長さを補う kk += [0]*(len(nn) - len(kk)) ret = 1 for i in range(len(nn)): temp = cmb(nn[i],kk[i])%p ret = ret*temp%p return ret def main(): n = int(input()); MOD = 998244353 B = list(map(int,input().split())) #dp[i][j]:i番目まで見て和が0(偶数)/1(奇数) dp = [1,0] for i in range(n): p = [0,0] p,dp = dp,p pari = lucas(n-1,i,2) if B[i] == 0: dp[0] = p[0] dp[1] = p[1] elif B[i] == 1: if pari == 0: dp[0] = p[0] dp[1] = p[1] else: dp[0] = p[1] dp[1] = p[0] else: if pari == 0: dp[0] = 2*p[0] dp[1] = 2*p[1] else: dp[0] = p[0] + p[1] dp[1] = p[0] + p[1] dp[0] %= MOD dp[1] %= MOD ans = dp[1] print(ans%MOD) if __name__ == '__main__': main()