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: Runtime Error)

#![allow(unused)]
// ///////
// Dinic //
// ///////

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

struct Dinic {
    n: usize,
    edges: Vec<Vec<Edge>>,
    dis: Vec<u64>,
    iter: Vec<usize>,
}

impl Dinic {
    fn new(n: usize) -> Self {
        Self {
            n,
            edges: vec![vec![]; n],
            dis: vec![0; n],
            iter: vec![0; n],
        }
    }
    fn add_edge(&mut self, s: usize, t: usize, cap: u64) {
        let edge_id = self.edges[t].len();
        self.edges[s].push(Edge {
            to: t,
            cap,
            rev: edge_id,
        });
        let edge_id = self.edges[s].len() - 1;
        self.edges[t].push(Edge {
            to: s,
            cap: 0,
            rev: edge_id,
        });
    }
    fn dfs(&mut self, v: usize, t: usize, flow: u64) -> u64 {
        if v == t {
            return flow;
        }
        for i in self.iter[v]..self.edges[v].len() {
            let e = self.edges[v][i];
            if e.cap > 0 && self.dis[v] < self.dis[t] {
                let f = self.dfs(e.to, t, std::cmp::min(e.cap, flow));
                if f > 0 {
                    self.edges[v][i].cap -= f;
                    self.edges[e.to][e.rev].cap += f;
                    return f;
                }
            }
            self.iter[v] += 1;
        }
        0
    }
    fn bfs(&mut self, s: usize) {
        self.dis = vec![0; self.n];
        self.dis[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.dis[e.to] == 0 {
                    self.dis[e.to] = self.dis[from] + 1;
                    q.push_back(e.to);
                }
            }
        }
    }
    fn calc(&mut self, s: usize, t: usize) -> u64 {
        let mut flow = 0;
        loop {
            self.bfs(s);
            if self.dis[t] == 0 {
                return flow;
            }
            self.iter = vec![0; self.n];
            let mut f = 0;
            loop {
                let res = self.dfs(s, t, std::u64::MAX);
                if res == 0 {
                    break;
                }
                f += res;
            }
            flow += f;
        }
    }
}

fn main() {
    use proconio::input;
    use proconio::marker::Chars;
    input! {
    n:usize,m:usize,
    mut table: [Chars; n]
    }
    let mut dinic = Dinic::new(n * m + 2);
    for i in 0..n {
        for j in 0..m {
            if table[i][j] == '#' {
                continue;
            }
            if (i + j) % 2 == 1 {
                dinic.add_edge(i * m + j + 1, n * m + 1, 1);
                continue;
            }
            dinic.add_edge(0, i * m + j + 1, 1);
            let dir = [(0, 1), (1, 0), (0, -1), (-1, 0)];
            for &(dx, dy) in dir.iter() {
                let nx = i.wrapping_add(dx as usize);
                let ny = j.wrapping_add(dy as usize);
                if nx < n && ny < m && table[nx][ny] != '#' {
                    dinic.add_edge(i * m + j + 1, nx * m + ny + 1, 1);
                }
            }
        }
    }
    let ans = dinic.calc(0, n * m + 1);

    for &e in &dinic.edges[0] {
        if e.cap == 1 {
            continue;
        }
        for &e1 in &dinic.edges[e.to] {
            if e1.cap == 0 {
                let (px, py) = ((e.to - 1) / m, (e.to - 1) % m);
                let (nx, ny) = ((e1.to - 1) / m, (e1.to - 1) % m);

                if px == nx {
                    table[px][std::cmp::min(py, ny)] = '>';
                    table[px][std::cmp::max(py, ny)] = '<';
                } else {
                    table[std::cmp::min(px, nx)][py] = 'v';
                    table[std::cmp::max(px, nx)][py] = '^';
                }
            }
        }
    }

    println!("{}", ans);

    for i in 0..n {
        for j in 0..m {
            print!("{}", table[i][j]);
        }
        println!();
    }
}