Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- mod = int(1e9 + 7)
- def modulo(x):
- if x >= 0 and mod > 0:
- return x % mod
- elif x < 0 and mod < 0:
- return abs(x) % abs(mod)
- elif x < 0 and mod > 0:
- return x - (x // mod * mod)
- elif x >= 0 and mod < 0:
- return x - (math.ceil(x / mod) * mod)
- else:
- return -1
- n = int(input())
- a = input().split(' ')
- pref = []
- suf = []
- for i in range(0, len(a)):
- a[i] = int(a[i])
- pref.append(a[i])
- suf.append(a[i])
- for i in range(1, n):
- pref[i] = pref[i] * pref[i - 1]
- for i in range(n - 2, -1, -1):
- suf[i] = suf[i] * suf[i + 1]
- ans = suf[0]
- for i in range(1, n):
- ans = max(ans, suf[i] + pref[i - 1])
- print(modulo(ans))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement