let h, w, m, ans, a_ss = Scanf.(scanf "%d %d" @@ fun h w -> Array.(h, w, ref 0, make (h * w) (0, 0, 0, 0), init h @@ fun _ -> init w @@ fun _ -> scanf " %d" (+) 0))
let _ = Array.(iteri (fun i a_s -> iteri (fun j a -> let k, d = if i mod 2 = 1 then w - 1 - j, -1 else j, 1 in if a_s.(k) mod 2 = 1 && (j <> w - 1 || i <> h - 1) then let i1, j1 = if j = w - 1 then i + 1, k else i, k + d in ans.(!m) <- i + 1, k + 1, i1 + 1, j1 + 1; incr m; a_ss.(i1).(j1) <- a_ss.(i1).(j1) + 1) a_s) a_ss; Printf.(printf "%d\n" !m; iteri (fun i (a, b, c, d) -> if i < !m then printf "%d %d %d %d\n" a b c d) ans))