#include using namespace std; void dfs(vector &ans, bool &ok, int &cnt, vector &hash, vector &ng, vector &curr, unsigned long long ch, int sz, int p){ if (p == -1){ if (curr.size() == sz){ auto itr = lower_bound(ng.begin(), ng.end(), ch); if (itr == ng.end()){ ans = curr; ok = true; } else if (*itr != ch){ ans = curr; ok = true; } } } else { if (curr.size() < sz){ curr.push_back(p); dfs(ans, ok, cnt, hash, ng, curr, ch ^ hash[p], sz, p - 1); curr.pop_back(); } if (ok){ return; } dfs(ans, ok, cnt, hash, ng, curr, ch, sz, p - 1); } } int main(){ mt19937 mt(chrono::steady_clock::now().time_since_epoch().count()); int N; cin >> N; vector m(N); vector> p(N), e(N); for (int i = 0; i < N; i++){ cin >> m[i]; p[i] = vector(m[i]); e[i] = vector(m[i]); for (int j = 0; j < m[i]; j++){ cin >> p[i][j] >> e[i][j]; } } vector P; for (int i = 0; i < N; i++){ for (int j = 0; j < m[i]; j++){ P.push_back(p[i][j]); } } sort(P.begin(), P.end()); P.erase(unique(P.begin(), P.end()), P.end()); int cnt = P.size(); for (int i = 0; i < N; i++){ for (int j = 0; j < m[i]; j++){ p[i][j] = lower_bound(P.begin(), P.end(), p[i][j]) - P.begin(); } } vector mx(cnt, -1); for (int i = 0; i < N; i++){ for (int j = 0; j < m[i]; j++){ mx[p[i][j]] = max(mx[p[i][j]], e[i][j]); } } vector> s(N); for (int i = 0; i < N; i++){ for (int j = 0; j < m[i]; j++){ if (mx[p[i][j]] == e[i][j]){ s[i].push_back(p[i][j]); } } } bool ok = true; for (int i = 0; i < N; i++){ if (s[i].size() == cnt){ ok = false; } } if (!ok){ cout << -1 << endl; } else { vector hash(cnt, 0); for (int i = 0; i < cnt; i++){ for (int j = 0; j < 64; j++){ hash[i] *= 2; hash[i] += mt() % 2; } } vector ng; for (int i = 0; i < N; i++){ int cnt2 = s[i].size(); for (int j = 0; j < (1 << cnt2); j++){ int sz = __builtin_popcount(j); unsigned long long S = 0; for (int k = 0; k < cnt2; k++){ if ((j >> k & 1) == 1){ S ^= hash[s[i][k]]; } } ng.push_back(S); } } sort(ng.begin(), ng.end()); ng.erase(unique(ng.begin(), ng.end()), ng.end()); return 0; vector ans; for (int i = 1; i <= 10; i++){ vector curr; unsigned long long chh = 0; bool ok2 = false; dfs(ans, ok2, cnt, hash, ng, curr, chh, i, cnt - 1); if (ok2){ break; } } vector A(N, 1); for (int i = 0; i < N; i++){ for (int j = 0; j < m[i]; j++){ for (int k = 0; k < e[i][j]; k++){ A[i] *= P[p[i][j]]; } } } int k = ans.size(); vector> S(k); for (int i = 0; i < N; i++){ for (int j = 0; j < k; j++){ bool ok2 = true; int cnt2 = s[i].size(); for (int l = 0; l < cnt2; l++){ if (s[i][l] == ans[j]){ ok2 = false; } } if (ok2){ S[j].push_back(A[i]); break; } } } cout << k << endl; for (int i = 0; i < k; i++){ int n = S[i].size(); cout << n; for (int j = 0; j < n; j++){ cout << ' ' << S[i][j]; } cout << endl; } } }