# Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) C. Felicity is Coming! 哈希

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxm=1000005;
const ll mod=1e9+7;
vector<int> vec[maxm];
int n,m,t,c;
ll res,tc;
int main()
{
scanf("%d%d",&n,&m);
for (int i=0;i<n;++i) {
scanf("%d",&t);
while (t--) {
scanf("%d",&c);
vec[c].push_back(i);
}
}
sort(vec+1,vec+m+1);
res=1;
for (int i=1;i<=m;++i)
if (vec[i]==vec[i-1]) {
++tc;
res=(res*tc)%mod;
} else
tc=1;
printf("%lld\n",res);
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fst first
#define snd second
typedef long long ll;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
const ll mod1=1e9+7;
const ll mod2=1e9+3;
map<pll,ll> mp;
map<ll,ll> mp2[100005];
ll fac[1000006],pow1[100005],pow2[100005],ha1[1000005],ha2[1000005];
int n,m,a,t,tf;
int main()
{
fac[0]=1LL;
fac[1]=1LL;
for (ll i=2;i<=1000005LL;++i)
fac[i]=(i*fac[i-1])%mod;
pow1[0]=1LL;
pow2[0]=1LL;
for (int i=1;i<=100000;++i) {
pow1[i]=(mod1*pow1[i-1])%mod2;
pow2[i]=(mod2*pow2[i-1])%mod1;
}
scanf("%d%d",&n,&m);
map<ll,ll>::iterator it;
for (int i=0;i<n;++i) {
scanf("%d",&t);
tf+=t;
for (int j=0;j<t;++j) {
scanf("%d",&a);
++mp2[i][a];
}
for (it=mp2[i].begin();it!=mp2[i].end();++it) {
ha1[(*it).fst]=(ha1[(*it).fst]+(*it).snd*pow1[i])%mod2;
ha2[(*it).fst]=(ha2[(*it).fst]+(*it).snd*pow2[i])%mod1;
}
}
for (int i=1;i<=m;++i)
++mp[pll(ha1[i],ha2[i])];
ll res=1LL;
map<pll,ll>::iterator it2;
for (it2=mp.begin();it2!=mp.end();++it2)
res=(res*fac[(*it2).snd])%mod;
printf("%lld\n",res);
return 0;
}

#### 【解题报告】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)

2017-03-02 23:16:50

#### ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)

2017-02-25 14:25:43

#### Codeforces Round #471 div.2 ABC题解

2018-03-24 14:16:58

#### CF-Codeforces Round #483 (Div. 2) A~D

2018-05-16 00:48:25

#### Codeforces Round #465 (Div. 2) C. Fifa and Fafa(圆问题，数论)

2018-02-20 16:16:48

#### Codeforces Round #377 (Div. 2)C. Sanatorium(贪心）

2016-10-26 20:08:59

#### Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence (构造 贪心)

2017-11-20 13:19:26

#### 【CodeForces】CodeForces Round #464 (Div. 2) 题解

2018-02-18 11:05:43

#### Codeforces Round #482 (Div. 2)

2018-05-15 12:51:24

#### Educational Codeforces Round 35 (Rated for Div. 2) A——C

2017-12-29 00:06:09