Problem:
Score : 100 points

Problem Statement

You are given a grid of N rows and M columns. The square at the i-th row and j-th column will be denoted as (i,j).
Some of the squares contain an object. All the remaining squares are empty.
The state of the grid is represented by strings S_1,S_2,\cdots,S_N. The square (i,j) contains an object if S_{i,j}= # and is empty if S_{i,j}= ..

Consider placing 1 \times 2 tiles on the grid. Tiles can be placed vertically or horizontally to cover two adjacent empty squares.
Tiles must not stick out of the grid, and no two different tiles may intersect. Tiles cannot occupy the square with an object.

Calculate the maximum number of tiles that can be placed and any configulation that acheives the maximum.

Constraints

1 \leq N \leq 100

1 \leq M \leq 100

S_i is a string with length M consists of # and ..

Input

Input is given from Standard Input in the following format:

N M
S_1
S_2
\vdots
S_N

Output

On the first line, print the maximum number of tiles that can be placed.

On the next N lines, print a configulation that achieves the maximum.
Precisely, output the strings t_1,t_2,\cdots,t_N constructed by the following way.

t_i is initialized to S_i.

For each (i,j), if there is a tile that occupies (i,j) and (i+1,j), change t_{i,j}:=v, t_{i+1,j}:=^.

For each (i,j), if there is a tile that occupies (i,j) and (i,j+1), change t_{i,j}:=>, t_{i,j+1}:=<.

See samples for further information.

You may print any configulation that maximizes the number of tiles.

Sample Input 1

3 3
#..
..#
...

Sample Output 1

3
#><
vv#
^^.

The following output is also treated as a correct answer.

3
#><
v.#
^><

Solution in OCaml (4.10.0) (judge verdict: Wrong Answer)

module type CapType = sig
    type t
    val zero : t
    val cap_max : t
    val add : t -> t -> t
    val sub : t -> t -> t
end ;;

module CapInt : CapType with type t = int = struct
    type t = int
    let zero = 0
    let cap_max = max_int
    let add = (+)
    let sub = (-)
end

module type S = sig
    type t
    type cap

    val create : int -> int -> t
    val add_edge : t -> int -> int -> cap -> t
    val edges    : t -> (int * int * cap * cap) array
    val get_edge : t -> int -> int * int * cap * cap
    val flow     : t -> int -> int -> cap
end;;

module Mf_graph = struct
    module Make(Cap: CapType) : S with type cap = Cap.t = struct
        type cap = Cap.t

        type edge = { to_: int; rev: int; mutable cap : cap }
        type t = int * int * int list array * edge array

        let create n m =
            n, 0, Array.make n [], Array.init (m * 2) (fun _ -> { to_ = 0; rev = 0; cap = Cap.zero } )

        let get_edge (n, idx, g, pos) i =
            let _e = pos.(i * 2) in
            let _re = pos.(_e.rev) in
            _re.to_, _e.to_, Cap.add _e.cap _re.cap, _re.cap

        let edges ((n, idx, g, pos) as mf) =
            Array.init (idx / 2) (fun i -> get_edge mf i)

        let add_edge (n, idx, g, pos) from to_ cap =
            pos.(idx)     <- { to_ = to_;  rev = idx + 1; cap = cap  };
            pos.(idx + 1) <- { to_ = from; rev = idx;     cap = Cap.zero };
            g.(from) <- idx :: g.(from);
            g.(to_)  <- (idx + 1) :: g.(to_);
            n, idx + 2, g, pos

        let flow mf s t =
            let flow (n, idx, g, pos) s t flow_limit =
                let rec bfs () =
                    let level = Array.make n (-1) in
                    level.(s) <- 0;

                    let rec loop fq bq =
                        match fq with
                        | [] -> if bq = [] then level else loop (List.rev bq) []
                        | v :: vs -> (
                            let rec loop2 bq = function
                                | [] -> loop vs bq
                                | e :: es ->
                                        let e = pos.(e) in
                                        if e.cap = Cap.zero || level.(e.to_) >= 0 then loop2 bq es else (
                                            level.(e.to_) <- level.(v) + 1;
                                            if e.to_ = t then level else loop2 (e.to_ :: bq) es
                                        )
                            in
                            loop2 bq g.(v)
                        )
                    in
                    loop [ s ] []
                in
                let rec dfs level iter v up =
                    if v = s then up else
                        let level_v = level.(v) in
                        let rec loop res iis =
                            iter.(v) <- iis;
                            match iis with
                            | [] -> res
                            | i :: is ->
                                let e = pos.(i) in
                                if level_v <= level.(e.to_) || pos.(e.rev).cap = Cap.zero then loop res is else
                                    let d = dfs level iter e.to_ (min (Cap.sub up res) pos.(e.rev).cap) in
                                    if d <= Cap.zero then loop res is else (
                                        pos.(i).cap     <- Cap.add pos.(i).cap d;
                                        pos.(e.rev).cap <- Cap.sub pos.(e.rev).cap d;
                                        let res = Cap.add res d in
                                        if res = up then res else loop res is
                                    )
                        in
                        loop Cap.zero iter.(v)
                in
                let rec flow_loop flow =
                    if flow >= flow_limit then flow else
                        let level = bfs () in
                        if level.(t) = -1 then flow else
                            let iter = Array.copy g in
                            let rec loop flow =
                                if flow < flow_limit then (
                                    let f = dfs level iter t (Cap.sub flow_limit flow) in
                                    if f = Cap.zero then flow else
                                        loop (Cap.add flow f)
                                ) else flow
                            in
                            loop flow
                in
                flow_loop Cap.zero

            in
            flow mf s t Cap.cap_max
    end
end;;

Scanf.scanf "%d %d" (fun n m ->
    let ss = Array.init n (fun _ -> Scanf.scanf " %s" (fun s -> s)) in

    let module MF = Mf_graph.Make (CapInt) in
    let mf = MF.create (n * m + 2) (n * m * 3) in
    let s = n * m in
    let t = n * m + 1 in
    let rec loop_y y mf =
        let rec loop_x x mf =
            if x = m then loop_y (y + 1) mf else
                let pivot = y * m + x in
                let mf = if ss.(y).[x] = '#' then mf else (
                    let mf = if (x + y) mod 2 = 0 then MF.add_edge mf s pivot 1
                                                  else MF.add_edge mf pivot t 1
                    in
                    if (x + y) mod 2 <> 0 then mf else (
                        let mf = if y > 0     && ss.(y - 1).[x] = '.' then MF.add_edge mf pivot ((y - 1) * m + x) 1 else mf in
                        let mf = if y < n - 1 && ss.(y + 1).[x] = '.' then MF.add_edge mf pivot ((y + 1) * m + x) 1 else mf in
                        let mf = if x > 0     && ss.(y).[x - 1] = '.' then MF.add_edge mf pivot (y * m + x - 1)   1 else mf in
                        let mf = if x < m - 1 && ss.(y).[x + 1] = '.' then MF.add_edge mf pivot (y * m + x + 1)   1 else mf in
                        mf
                    )
                )
                in
                loop_x (x + 1) mf
        in
        if y = n then mf else loop_x 0 mf
    in
    let mf = loop_y 0 mf in
    let f = MF.flow mf s t in
    let ar = MF.edges mf in
    let map = Array.make_matrix n m ' ' in
    for y = 0 to n - 1 do
        for x = 0 to m - 1 do
            map.(y).(x) <- ss.(y).[x]
        done
    done;
    Array.iter (fun (from, to_, c1, c2) -> if c2 > 0 && from <> s && to_ <> t then (
        let prt p1 c1 p2 c2 =
            let prt2 p c =
                let y = p / m in
                let x = p mod m in
                map.(y).(x) <- c
            in
            prt2 p1 c1; prt2 p2 c2
        in
        if from + 1 = to_  then prt from '>' to_ '<' else
        if to_  + 1 = from then prt from '<' to_ '>' else
        if from + m = to_  then prt from 'v' to_ '^' else
        if to_  + m = from then prt from '^' to_ 'v'
    )) ar;
    Printf.printf "%d\n" f;
    for y = 0 to n - 1 do
        for x = 0 to m - 1 do
            print_char map.(y).(x)
        done;
        print_newline ()
    done
)