use std::{ convert::TryFrom, io::{stdin, BufRead}, }; fn main() { let stdin = stdin(); let mut stdin = stdin.lock().lines().map(Result::unwrap); let [n, _m, lim] = <[_; 3]>::try_from( stdin .next() .unwrap() .split_whitespace() .map(|x| x.parse::().unwrap()) .collect::>() .as_slice(), ) .unwrap(); let lim = lim + 1; let mut dp = vec![false; lim]; dp[0] = true; for _ in 0..n { let mut swp = vec![false; lim]; let w = stdin .next() .unwrap() .split_whitespace() .map(|x| x.parse::().unwrap()) .collect::>(); for i in (0..lim).rev() { for &w in &w { if i + w < lim { swp[i + w] |= dp[i]; } } } dp = swp; } let ans = dp .iter() .rposition(|&x| x) .map_or(-1, |p| (lim - 1 - p) as isize); println!("{}", ans); }