fork download
  1. //...START BY DOING WHAT IS NECESSARY, THEN WHAT IS POSSIBLE AND SUDDENLY YOU ARE DOING THE IMPOSSIBLE...
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define FAST_FURIER ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  5. #define pb push_back
  6. #define rep(i,a,N) for(ll i=a;i<N;i++)
  7. typedef long long ll;
  8. #define endl '\n'
  9. #define M 1000000007
  10. bool comp(int x,int y)
  11. {
  12. return x > y;
  13. }
  14.  
  15.  
  16. /*..............................code starts here........................*/
  17. // S is the courage to continue that counts.
  18. ll fac[1000002];
  19. ll power(ll no,ll p)
  20. {
  21. if(p == 1)
  22. return no;
  23. if(p == 0)
  24. return 1;
  25. ll q = power(no,p/2);
  26. q = (q*q)%M;
  27. if(p % 2 != 0)
  28. q = (q*no)%M;
  29. return q;
  30. }
  31. void factorial(){
  32. fac[0] = 1;
  33. rep(i,1,1000001)
  34. fac[i] = (fac[i-1]*i)%M;
  35. }
  36. ll calculate(ll x){
  37. ll no = power(fac[x/2],M-2)%M;
  38. no = (no*no)%M;
  39. return (fac[x]*no)%M;
  40. }
  41. int main() {
  42. FAST_FURIER;
  43. factorial();
  44. int t=1;
  45. cin >> t;
  46. ll m,n,k;
  47. string a,b;
  48. while(t--)
  49. {
  50. cin >> n;
  51. int count = 0;
  52. int input;
  53. int mx = INT_MIN;
  54. rep(i,0,n){
  55. cin >> input;
  56. if(input > mx){
  57. mx = input;
  58. count = 1;
  59. }
  60. else if(input == mx){
  61. count += 1;
  62. }
  63. }
  64. // cout << it->first << " " << it->second << endl;
  65. //cout << mp[mx] << endl;
  66. if(count % 2 == 1)
  67. cout << power(2,n) << endl;
  68. else{
  69. ll no = ((power(2,n-count)*calculate(count)%M+M))%M;
  70. cout << (power(2,n) - no)%M << endl;
  71. }
  72. }
  73. }
  74.  
  75.  
  76.  
  77.  
  78. // Author : Shivam_123 (cf) shihack(chef)
  79.  
  80. // g++ -std=c++17
Time limit exceeded #stdin #stdout 5s 11080KB
stdin
Standard input is empty
stdout
Standard output is empty