forked from shauryas1ngh/codes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CRDGAME2.cp
108 lines (89 loc) · 1.74 KB
/
CRDGAME2.cp
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include<bits/stdc++.h>
#define pi 3.14159265359
#define ll long long
#define wh(t) int t;cin>>t; while(t--)
#define speed ios::sync_with_stdio(0); cin.tie(0);
#define endl "\n"
#define f(i,a,b) for(int i=a;i<b;i++)
#define m 1000000007
using namespace std;
#include<string.h>
//aditya ranaut- phoenix_aditya
const int mxn=1e5+5;
ll arr[mxn];
ll power(ll x, ll y)
{
if(y==0)
return 1;
ll zeta= power(x,y/2)%m;
zeta=(zeta*zeta)%m;
if(y%2!=0)
zeta=(zeta*x)%m;
return zeta;
}
ll modinv(ll n)
{
return power(n,m-2);
}
ll ncrmod(ll n, ll r)
{
ll c[n+1];
memset(c, 0, sizeof(c));
c[0]=1;
f(i,1,n+1)
{
c[i]=(c[i-1]*i)%m;
}
return (c[n] * modinv(c[r]) % m*modinv(c[n - r])%m)%m;
}
ll ncr(ll n, ll r)
{
if(r==0)
return 1;
int ni = n%m, ri = r%m;
return (ncrmod(n/m, r/m) * ncrmod(ni, ri) % m);
}
void solve()
{
ll n;
cin>>n;
f(i,0,n)
cin>>arr[i];
if(n==1)
{
cout<<2<<endl;
return;
}
ll max=0;
f(i,0,n)
{
if(arr[i]>max)
max=arr[i];
}
ll noofmax=0;
f(i,0,n)
{
if(arr[i]==max)
noofmax++;
}
ll ans=0;
if(noofmax%2!=0)
{
ans=power(2, n)%m;
}
else
{
ans=power(2,n)%m;
ans-=((power(2, n-noofmax)%m)*ncr(noofmax, noofmax/2)%m)%m;
if(ans<0)
ans=(ans+m)%m;
}
cout<<ans%m<<endl;
}
int main()
{
speed;
wh(t)
{solve();}
return 0;
}