fn g() -> Vec { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.split_whitespace().flat_map(str::parse).collect() } fn main() { let v = g(); let mut d = vec![0; v[2] + 1]; d[0] = v[1]; for _ in 0..v[0] { let t = g(); for i in (0..v[2]).rev() { if d[i] < 1 { continue; } let p = if t[0] < 2 { d[i] + t[1] } else { d[i] * 2 }; if p > 10usize.pow(18) { println!("-1"); return; } d[i + 1] = d[i + 1].max(p); } } println!("{}", d[v[2]]) }