n = int(input())
B = list(map(int,input().split()))
mod = 998244353

two = [0]
for i in range(1,n+1):
    count = 0
    num = i
    while num%2 == 0:
        num //= 2
        count += 1
    two.append(two[-1]+count)


def nCr(n,r):
    if two[n] > two[r]+two[n-r]:
        return 1
    return 0

ans = 1
dp = [0]*2
dp[0] = 1
for i,b in enumerate(B):
    ndp = [0]*2
    even = nCr(n-1,i)
    if b != 1:
        ndp[0] += dp[0]
        ndp[1] += dp[1]

    if b != 0:
        if even:
            ndp[0] += dp[0]
            ndp[1] += dp[1]
        else:
            ndp[1] += dp[0]
            ndp[0] += dp[1]
    dp = ndp
    dp[0] %= mod
    dp[1] %= mod
print(dp[1])