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 Rust (1.42.0) (judge verdict: Accepted)

use proconio::{
    fastout,
    input,
    marker::Chars
};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        mut s: [Chars; n]
    }

    let start = n * m;
    let term = start + 1;
    let edge = |i, j| i * m + j;
    let pos = |e| (e / m, e % m);
    let mut g = Dinic::new(n * m + 2);
    for i in 0..n {
        for j in 0..m {
            if s[i][j] != '#' {
                if (i + j) % 2 == 0 {
                    g.add_edge(start, edge(i, j), 1);
                    if i     > 0 && s[i - 1][j] != '#' { g.add_edge(edge(i, j), edge(i - 1, j), 1) }
                    if i + 1 < n && s[i + 1][j] != '#' { g.add_edge(edge(i, j), edge(i + 1, j), 1) }
                    if j     > 0 && s[i][j - 1] != '#' { g.add_edge(edge(i, j), edge(i, j - 1), 1) }
                    if j + 1 < m && s[i][j + 1] != '#' { g.add_edge(edge(i, j), edge(i, j + 1), 1) }
                } else {
                    g.add_edge(edge(i, j), term, 1);
                }
            }
        }
    }

    println!("{}", g.calc(start, term));

    for &e in &g.edges[start] {
        if e.cap == 0 {
            let (i, j) = pos(e.to);
            for &ne in &g.edges[e.to] {
                if ne.cap == 0 {
                    let (ni, nj) = pos(ne.to);
                    if i == ni {
                        s[i][j.min(nj)] = '>';
                        s[i][j.max(nj)] = '<';
                    } else {
                        s[i.min(ni)][j] = 'v';
                        s[i.max(ni)][j] = '^';
                    }
                }
            }
        }
    }

    println!("{}",
        s.iter()
         .map(|s| s.iter().collect())
         .collect::<Vec<String>>()
         .join("\n")
    );
}

#[derive(Copy, Clone)]
struct Edge {
    to: usize,
    rev: usize,
    cap: u64,
}

struct Dinic {
    edges: Vec<Vec<Edge>>,
    d: Vec<u64>,
    it: Vec<usize>,
}

impl Dinic {
    fn new(n: usize) -> Self {
        Self {
            edges: vec![vec![]; n],
            d: vec![0; n],
            it: vec![0; n],
        }
    }

    fn add_edge(&mut self, s: usize, t: usize, cap: u64) {
        let rev = self.edges[t].len();
        self.edges[s].push(Edge { to: t, rev, cap });
        let rev = self.edges[s].len() - 1;
        self.edges[t].push(Edge { to: s, rev, cap: 0 });
    }

    fn calc(&mut self, s: usize, t: usize) -> u64 {
        let mut flow = 0;
        while self.calc_distance(s, t) {
            self.it = vec![0; self.len()];
            while let Some(f) = self.move_flow(s, t, std::u64::MAX) {
                flow += f;
            }
        }
        flow
    }

    fn calc_distance(&mut self, s: usize, t: usize) -> bool {
        self.d = vec![0; self.len()];
        self.d[s] = 1;
        let mut q = std::collections::VecDeque::new();
        q.push_back(s);
        while let Some(from) = q.pop_front() {
            for &e in &self.edges[from] {
                if e.cap > 0 && self.d[e.to] == 0 {
                    self.d[e.to] = self.d[from] + 1;
                    q.push_back(e.to);
                }
            }
        }
        self.d[t] != 0
    }

    fn move_flow(&mut self, s: usize, t: usize, flow: u64) -> Option<u64> {
        if s == t {
            Some(flow)
        } else {
            let n = self.edges[s].len();
            for i in self.it[s]..n {
                let e = self.edges[s][i];
                if e.cap > 0 && self.d[s] < self.d[e.to] {
                    if let Some(flow) = self.move_flow(e.to, t, e.cap.min(flow)) {
                        self.edges[s][i].cap -= flow;
                        self.edges[e.to][e.rev].cap += flow;
                        return Some(flow)
                    }
                }
                self.it[s] += 1;
            }
            None
        }
    }

    fn len(&self) -> usize {
        self.edges.len()
    }
}