from collections.abc import Iterable from enum import IntEnum, auto 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 class E(IntEnum): S = 0, TAKE = auto() G = auto() def f(k, v, x): s, b = k # (状態, 0を含むか) match s: case E.S: # まだ取ってない yield k, v # 取る nb = b | (x == 0) yield (E.TAKE, nb), v case E.TAKE: # 取った nb = b | (x == 0) yield (E.TAKE, nb), v # とり続ける # ここで終了 if b: yield (E.G, b), v case E.G: # 終了状態 yield k, v case _: assert False N = int(input()) A = list(map(int, input().split())) init = {(E.S, False): 1} dp = accum_dp(A, f, op, 0, init) ans = 0 for (t, b), v in dp.items(): if t in [E.TAKE, E.G] and b: ans += v print(ans)