// ---------- begin next_permutation ---------- fn next_permutation(a: &mut [T]) -> bool { a.windows(2).rposition(|a| a[0] < a[1]).map_or(false, |x| { let y = a.iter().rposition(|b| a[x] < *b).unwrap(); a.swap(x, y); a[(x + 1)..].reverse(); true }) } // ---------- end next_permutation ---------- // ---------- begin scannner ---------- #[allow(dead_code)] mod scanner { use std::str::FromStr; pub struct Scanner<'a> { it: std::str::SplitWhitespace<'a>, } impl<'a> Scanner<'a> { pub fn new(s: &'a String) -> Scanner<'a> { Scanner { it: s.split_whitespace(), } } pub fn next(&mut self) -> T { self.it.next().unwrap().parse::().ok().unwrap() } pub fn next_bytes(&mut self) -> Vec { self.it.next().unwrap().bytes().collect() } pub fn next_chars(&mut self) -> Vec { self.it.next().unwrap().chars().collect() } pub fn next_vec(&mut self, len: usize) -> Vec { (0..len).map(|_| self.next()).collect() } } } // ---------- end scannner ---------- use std::io::Write; fn main() { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); let mut sc = scanner::Scanner::new(&s); let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); run(&mut sc, &mut out); } fn run(sc: &mut scanner::Scanner, out: &mut std::io::BufWriter) { let n: usize = sc.next(); let mut dp = vec![0; 1000000 + 1]; let mut a = vec![]; for _ in 0..n { let m: usize = sc.next(); let mut p = vec![(0usize, 0usize); m]; for p in p.iter_mut() { p.0 = sc.next(); p.1 = sc.next(); dp[p.0] = dp[p.0].max(p.1); } a.push(p); } let mut cond = vec![]; for i in 0..dp.len() { if dp[i] > 0 { cond.push(i); } } for a in a.iter() { if a.len() == cond.len() && a.iter().all(|p| p.1 == dp[p.0]) { writeln!(out, "-1").ok(); return; } } let mut ban = std::collections::BTreeSet::new(); for a in a.iter() { let mut p = vec![]; for a in a.iter() { if dp[a.0] == a.1 { p.push(a.0); } } ban.insert(p); } for i in 1.. { let mut next = vec![]; for ban in ban.iter() { if ban.len() > i { let mut p = ban.clone(); p.remove(i - 1); next.push(p); } } if next.len() == 0 { break; } ban.extend(next); } for k in 2.. { let mut test = vec![0; cond.len()]; for t in test.iter_mut().rev().take(k) { *t = 1; } while { let mut x = vec![]; for (i, t) in test.iter().enumerate() { if *t > 0 { x.push(cond[i]); } } if !ban.contains(&x) { let mut ans = vec![vec![]; k]; for a in a { for (ans, &x) in ans.iter_mut().zip(&x) { if !a.contains(&(x, dp[x])) { ans.push(a.iter().fold(1, |s, a| s * a.0.pow(a.1 as u32))); break; } } } writeln!(out, "{}", ans.len()).ok(); for ans in ans { write!(out, "{}", ans.len()).ok(); for a in ans { write!(out, " {}", a).ok(); } writeln!(out).ok(); } return; } next_permutation(&mut test) } {} } }