-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathCRDGAME2
67 lines (45 loc) · 1.1 KB
/
CRDGAME2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<bits/stdc++.h>
using namespace std;
#define int long long int
unsigned long long power(unsigned long long x, int y, int p = 1000000007){
unsigned long long res = 1;
x=x%p;
while (y > 0) {
if(y&1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;}
unsigned long long modinverse(unsigned long long n, int p = 1000000007) {
return power(n, p - 2, p);
}
unsigned long long nCrModPFermat(unsigned long long n, int r, int p = 1000000007)
{
if (r == 0) return 1;
unsigned long long fac[n + 1];
fac[0] = 1;
for (int i = 1; i <= n; i++) fac[i] = (fac[i-1] * i) % p;
return (fac[n] * modinverse(fac[r], p) % p * modinverse(fac[n-r], p) % p) % p;
}
void solve() {
map<int, int> mp;
int n; cin >> n;
int a[n];
int maxi = -1;
for(int i = 0; i < n; ++i) {
cin >> a[i];
mp[a[i]] = mp[a[i]] + 1;
maxi = max(a[i], maxi);
}
int f = mp[maxi];
int left = power(2, n - f);
int right = power(2, f);
if(f % 2 == 0) right = right - nCrModPFermat(f, f/2);
right = right % 1000000007; cout << left * right % 1000000007 << "\n";
}
signed main() {
int t; cin >> t;
while(t--) { solve(); }
return 0;
}