use std::mem::swap; use proconio::input; fn main() { input! { mut h: usize, mut w: usize, } let mut trans = false; if h > w { swap(&mut h, &mut w); trans = true; } let mut color = 3; let mut dominos = vec![]; if h == 1 { color = w / 2 + 1; for j in (0..w).step_by(2) { dominos.push([0, j, (j + 1) / 2, 0, j + 1, (j + 2) / 2]); } } else if h == 3 { color = 2 + (w + 3) / 4; for j in 0..w { dominos.push([0, j, 0, 1, j, 1]); } let mut c = vec![0; w]; for j in 0..w { if j % 4 == 0 || j % 4 == 3 { c[j] = 1; } else { c[j] = j / 4 + 2; } } for j in (0..w).step_by(2) { dominos.push([2, j, c[j], 2, j + 1, c[j + 1]]); } } else if h == 5 && w > 8 { color = 4; for j in 0..w { dominos.push([0, j, 0, 1, j, 1]); dominos.push([3, j, 2, 4, j, 3]); } for j in (0..w).step_by(2) { dominos.push([2, j, 1, 2, j + 1, 2]); } } else if h <= 4 { color = h / 2 + 1; let mut c = vec![vec![0; w]; h]; for i in 0..h { for j in 0..w { c[i][j] = (i + 1) / 2; } } for i in (0..h).step_by(2) { for j in 0..w { dominos.push([i, j, c[i][j], i + 1, j, c[i + 1][j]]); } } } else if h >= 4 && w >= 6 { for i in 0..h { dominos.push([i, 0, 2, i, 1, 0]); } for i in 2..h - 2 { dominos.push([i, 2, 0, i, 3, 1]); } for i in 2..h { dominos.push([i, w - 2, 0, i, w - 1, 1]); } for j in 2..w { dominos.push([0, j, 0, 1, j, 1]); } for j in 2..w - 2 { dominos.push([h - 2, j, 1, h - 1, j, 0]); } if h % 2 == 0 { for i in (2..h - 2).step_by(2) { for j in 4..w - 2 { dominos.push([i, j, 0, i + 1, j, 1]); } } } else if h >= 6 { for j in 4..w - 2 { dominos.push([2, j, 1, 3, j, 0]); } for j in (4..w - 2).step_by(2) { for i in 4..h - 2 { dominos.push([i, j, 0, i, j + 1, 1]); } } } else if h == 5 && w == 8 { dominos.push([2, 4, 1, 2, 5, 0]); } } output(&dominos, color, trans); } fn output(dominos: &[[usize; 6]], color: usize, trans: bool) { println!("{}", color); for &[x, y, c, x2, y2, c2] in dominos { if !trans { println!( "{} {} {} {} {} {}", x + 1, y + 1, c + 1, x2 + 1, y2 + 1, c2 + 1 ); } else { println!( "{} {} {} {} {} {}", y + 1, x + 1, c + 1, y2 + 1, x2 + 1, c2 + 1 ); } } }