fork download
  1. #include <bits/stdc++.h>
  2. typedef long long ll;
  3. using namespace std;
  4. void Code_By_Mohamed_Khaled() {
  5. ios_base::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7. cout.tie(nullptr);
  8. #ifndef ONLINE_JUDGE
  9. freopen("input.txt","r",stdin);
  10. freopen("output.txt","w",stdout);
  11. #endif
  12. }
  13. ll mod = 1e9 + 7;
  14. ll add(ll a, ll b) { return ((b % mod) + (a % mod)) % mod; }
  15. ll mul(ll a, ll b) { return ((b % mod) * (a % mod)) % mod; }
  16. ll fast_power(ll base, ll power) {
  17. ll res=1;
  18. while(power) {
  19. if (power & 1)res=mul(res,base);
  20. base=mul(base,base);
  21. power >>= 1;
  22. }
  23. return res;
  24. }
  25. vector<ll>fact(2e6+5,0),inv_fact(2e6+5);
  26. void precompute() {
  27. fact[0]=fact[1]=1;ll N=2e6;
  28. inv_fact[0]=1;
  29. for (ll i=2;i<=2e6;i++) {
  30. fact[i]=mul(fact[i-1],i);
  31. }
  32. inv_fact[N]=fast_power(fact[N],mod-2);
  33. for (ll i=2e6-1;i>0;i--) {
  34. inv_fact[i]=mul(inv_fact[i+1],i+1);
  35. }
  36. }
  37. ll comb(int n, int r) {
  38. if (r > n || r < 0) return 0;
  39. return mul(mul(fact[n], inv_fact[r]), inv_fact[n - r]);
  40. }
  41. int main() {
  42. Code_By_Mohamed_Khaled();
  43. precompute();
  44. ll t;cin>>t;
  45. while (t--) {
  46. ll n;cin>>n;
  47. vector<ll>v(n);map<ll,ll>mp;
  48. for (auto &it:v)cin>>it,mp[it]++;
  49. ll res=1;
  50. for (auto it:mp) {
  51. res=mul(res,it.second+1);
  52. }
  53. res-=(mp.size()+1);
  54. res+=2*mod;res%=mod;
  55. cout<<res<<"\n";
  56. }
  57. return 0;
  58. }
Success #stdin #stdout 0.16s 34244KB
stdin
1
5
2 2 2 2 2
stdout
4