fn main() { let mut hw = String::new(); std::io::stdin().read_line(&mut hw).ok(); let hw: Vec = hw.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let h = hw[0]; let w = hw[1]; if h % 2 == 0 && w % 2 == 0 { println!("{}", h*w); for _ in 0..h { println!("{}", vec!["1"; w].join(" ")); } } else if h % 2 == 0 { println!("{}", h * (w-1)); for _ in 0..h { println!("{} 0", vec!["1"; w-1].join(" ")); } } else if w % 2 == 0 { println!("{}", (h-1)*w); for _ in 0..h-1 { println!("{}", vec!["1"; w].join(" ")); } println!("{}", vec!["0"; w].join(" ")); } else { println!("{}", (h.min(w) - 1) * h.max(w)); let mut ret = vec![vec![1usize; w]; h]; for i in 0..h.min(w) { ret[i][i] = 0; } for i in 0..h.max(w) { let mut idx = 0usize; if h > w { for j in (w..h).step_by(2) { ret[j][idx] = 0; ret[j+1][idx] = 0; idx = (idx + 1) % w; } } else { for j in (h..w).step_by(2) { ret[idx][j] = 0; ret[idx][j+1] = 0; idx = (idx + 1) % h; } } } for i in 0..h { println!("{}", ret[i].iter().map(|v| v.to_string()).collect::>().join(" ")); } } }