#include #include #include using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000001 struct rolling_hash{ long long t_hash; static vector power; static const long long MOD = (1LL<<61)-1; static const long long b = 123456; int sz; rolling_hash(){ sz = 0; t_hash = 0; } rolling_hash(long long c){ sz = 1; t_hash = b*c; } long long mul(__int128 x,__int128 y){ __int128 t = x*y; t = (t>>61) + (t&MOD); if(t>=MOD)t -= MOD; return t; } long long get_pow(int sz){ if(power.size()>sz)return power[sz]; while(power.size()<=sz){ if(power.size()==0)power.push_back(1); else power.push_back(mul(power.back(),b)); } return power.back(); } rolling_hash &operator+=(const rolling_hash &another){ (*this).t_hash = mul((*this).t_hash,get_pow(another.sz)); (*this).t_hash += another.t_hash; if((*this).t_hash>=MOD)(*this).t_hash -= MOD; (*this).sz += another.sz; return (*this); } rolling_hash operator+(const rolling_hash &another)const{ return (rolling_hash(*this)+=another); } rolling_hash &operator-=(const rolling_hash &another){ (*this).t_hash += MOD - mul(another.t_hash,get_pow((*this).sz-another.sz)); if((*this).t_hash>=MOD)(*this).t_hash -= MOD; (*this).sz -= another.sz; return (*this); } rolling_hash operator-(const rolling_hash &another)const{ return (rolling_hash(*this)-=another); } bool operator<(const rolling_hash &another)const{ if((*this).t_hash!=another.t_hash)return (*this).t_hash rolling_hash::power; int main(){ int N; cin>>N; vector> mp(N); map LCA; vector v(N,1); rep(i,N){ int m; cin>>m; rep(j,m){ int p,e; cin>>p>>e; mp[i][p] = e; LCA[p] = max(LCA[p],e); rep(k,e)v[i] *= p; } } map pos; int cur = 0; vector ps(LCA.size()); for(auto a:LCA){ pos[a.first] = cur; ps[cur] = a.first; cur++; } set S; vector> tt(N); rep(i,N){ vector t; for(auto a:mp[i]){ if(a.second == LCA[a.first]){ t.push_back(pos[a.first]); } } sort(t.begin(),t.end()); rolling_hash h; rep(j,t.size())h += rolling_hash(t[j]); tt[i] = t; if(S.count(h))continue; rep(j,1<>k)&1)th += rolling_hash(t[k]); } S.insert(th); } } //cout<<'a'<> t(cur); rep(i,cur)t[i] = {i}; while(true){ if(t.size()==0){ cout<<-1<> nt; rep(i,t.size()){ int last = t[i].back(); for(int j=last+1;j temp = t[i]; temp.push_back(j); rolling_hash h; rep(k,temp.size())h += rolling_hash(temp[k]); if(!S.count(h)){ cout<> ans(temp.size()); rep(i,N){ rep(j,temp.size()){ if(binary_search(tt[i].begin(),tt[i].end(),temp[j]))continue; ans[j].push_back(v[i]); break; } } rep(i,temp.size()){ cout<