fn main() { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let n: usize = s.trim().parse().unwrap(); let (mut x, mut y, mut p, mut q) = (0, 0, 1, 0); let mut a = vec![0; n * n]; for i in 1..=n * n { a[(x + y * n as i16) as usize] = i; if x + p >= n as i16 || y + q >= n as i16 || a[(x + p + (y + q) * n as i16) as usize] != 0 { (p, q) = (-q, p); } x += p; y += q; } a.chunks(n).for_each(|r| { println!( "{}", r.iter() .map(|&x| format!("{:03}", x)) .collect::>() .join(" ") ) }); }