from collections.abc import Iterable def accum_dp(xs: Iterable, f, op, e, init: dict, *, is_reset=True): dp = init.copy() for x in xs: pp = {} if is_reset else dp.copy() dp, pp = pp, dp for fm_key, fm_val in pp.items(): for to_key, to_val in f(fm_key, fm_val, x): dp[to_key] = op(dp.get(to_key, e), to_val) return dp def op(a, b): return a + b ans = 0 def f(k, v, x): global ans t, b = k # (取った, 0を含むか) if t == 0: yield k, v # 取る nb = b | (x == 0) yield (1, nb), v elif t == 1: nb = b | (x == 0) yield (1, nb), v if b: ans += v else: assert False N = int(input()) A = list(map(int, input().split())) init = {(0, False): 1} dp = accum_dp(A, f, op, 0, init) for (t, b), v in dp.items(): if t == 1 and b: ans += v print(ans)