n = int(input()) a = list(map(int, input().split())) LIMIT = 10 ** 9 MOD = 10 ** 9 + 7 dist = [] tmp = [] for i in range(n + 1): if i == n or a[i] == 0: dist.append(tmp) tmp = [] else: tmp.append(a[i]) def solve(a, n): # 区間[l, r)を考えつつつ、lとrを尺取りする r = 0 ru_val = 1 ptn_val = 1 ans = 1 for l in range(n): if l > 0: ru_val //= a[l - 1] ptn_val *= pow(pow(a[l - 1], (r - (l - 1)), MOD), MOD - 2, MOD) ptn_val %= MOD while r < n and ru_val * a[r] < LIMIT: ru_val *= a[r] ptn_val *= ru_val ptn_val %= MOD r += 1 ans *= ptn_val ans %= MOD return ans ans = 0 for li in dist: if not li: continue ans += solve(li, len(li)) ans %= MOD print(ans)