# 実装疲れた N = int(input()) As = list(map(int, input().split())) MOD = 998244353 half = pow(2, MOD - 2, MOD) alphas = [0] * 5 dp = [0] * (N + 1) dpsum = 0 prod = 1 for i, A in enumerate(As): prod *= A if not (-2 <= prod <= 2): prod = 0 if prod == -2: dp[i + 1] += pow(2, MOD - 2 - i, MOD) alphas[1] += 1 new_alphas = [0] * 5 for j in range(-2, 3): index = j * A if not (-2 <= index <= 2): index = 0 new_alphas[index] += alphas[j] * half new_alphas[index] %= MOD alphas = new_alphas dp[i + 1] += (dpsum + alphas[-2]) % MOD dp[i + 1] %= MOD dpsum += dp[i + 1] dpsum = dpsum * half % MOD print(dp) print(dp[-1])