Advertisement
ProgMe

Untitled

Jan 13th, 2021
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. import math
  2.  
  3. mod = int(1e9 + 7)
  4.  
  5.  
  6. def modulo(x):
  7. if x >= 0 and mod > 0:
  8. return x % mod
  9. elif x < 0 and mod < 0:
  10. return abs(x) % abs(mod)
  11. elif x < 0 and mod > 0:
  12. return x - (x // mod * mod)
  13. elif x >= 0 and mod < 0:
  14. return x - (math.ceil(x / mod) * mod)
  15. else:
  16. return -1
  17.  
  18.  
  19. n = int(input())
  20. a = input().split(' ')
  21.  
  22. pref = []
  23. suf = []
  24.  
  25. for i in range(0, len(a)):
  26. a[i] = int(a[i])
  27. pref.append(a[i])
  28. suf.append(a[i])
  29.  
  30. for i in range(1, n):
  31. pref[i] = pref[i] * pref[i - 1]
  32. for i in range(n - 2, -1, -1):
  33. suf[i] = suf[i] * suf[i + 1]
  34.  
  35. ans = suf[0]
  36.  
  37. for i in range(1, n):
  38. ans = max(ans, suf[i] + pref[i - 1])
  39. print(modulo(ans))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement