Guest User

Untitled

a guest
Oct 19th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. def main():
  2. R = 10**9+7
  3. N = int(input())
  4. a = list(map(int, input().split(" ")))
  5.  
  6. if a[0] != 0:
  7. return 0
  8.  
  9. amax = max(a)
  10. h = [0] * (amax+1)
  11. for i in a:
  12. h[i] += 1
  13. if h[0] != 1:
  14. return 0
  15.  
  16. ans = 1
  17. b = 1
  18. for i in h[1:]:
  19. if i == 0:
  20. return 0
  21. ans *= pow(2, i * (i - 1) // 2, R)
  22. ans %= R
  23. ans *= pow(pow(2, b, R) - 1, i, R)
  24. ans %= R
  25. b = i
  26. return ans
  27.  
  28.  
  29. if __name__ == '__main__':
  30. print(main())
Add Comment
Please, Sign In to add comment