fork download
  1. MOD = 1000000007
  2.  
  3. def modular_exponentiation(b: int, ex: int) -> int:
  4. result = 1
  5. while ex > 0:
  6. if ex % 2 == 1:
  7. result = (result * b) % MOD
  8. b = (b * b) % MOD
  9. ex //= 2
  10. return result
  11.  
  12. T = int(input())
  13.  
  14. for t in range(T):
  15. N = int(input())
  16. array = list(map(int, input().split()))
  17.  
  18. odd_count = 0
  19. even_count = 0
  20.  
  21. for i in range(N):
  22. if array[i] % 2 == 0:
  23. even_count += 1
  24. else:
  25. odd_count += 1
  26.  
  27. if odd_count == 0:
  28. result = (modular_exponentiation(2, even_count) - 1 + MOD) % MOD
  29. else:
  30. result = modular_exponentiation(2, even_count)
  31.  
  32. print(result)
  33.  
Success #stdin #stdout 0.04s 9784KB
stdin
2
3
2 1 4
3
1 2 3 
stdout
4
2