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: Wrong Answer)

#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn get_index(
    x: usize,
    y: usize,
    even_dict: &HashMap<(usize, usize), usize>,
    odd_dict: &HashMap<(usize, usize), usize>,
) -> usize {
    if (x + y) % 2 == 0 {
        even_dict[&(x, y)]
    } else {
        odd_dict[&(x, y)] + even_dict.len()
    }
}

fn from_index(
    cur: usize,
    even_rev: &Vec<(usize, usize)>,
    odd_rev: &Vec<(usize, usize)>,
) -> (usize, usize) {
    if cur < even_rev.len() {
        even_rev[cur]
    } else {
        odd_rev[cur - even_rev.len()]
    }
}

fn main() {
    let v = read_vec::<usize>();
    let (h, w) = (v[0], v[1]);
    let mut grid = vec![vec![]; h];
    for i in 0..h {
        grid[i] = read::<String>().chars().collect::<Vec<_>>();
    }

    let mut even_dict = HashMap::new();
    let mut odd_dict = HashMap::new();

    for y in 0..h {
        for x in 0..w {
            if (x + y) % 2 == 0 {
                let cur = even_dict.len();
                even_dict.insert((x, y), cur);
            } else {
                let cur = odd_dict.len();
                odd_dict.insert((x, y), cur);
            }
        }
    }

    let mut even_rev = vec![(0, 0); even_dict.len()];
    let mut odd_rev = vec![(0, 0); odd_dict.len()];

    for (&k, &v) in &even_dict {
        even_rev[v] = k;
    }
    for (&k, &v) in &odd_dict {
        odd_rev[v] = k;
    }

    let mut solver = Solver::new(even_dict.len() + odd_dict.len() + 2);
    for y in 0..h {
        for x in 0..w {
            if grid[y][x] == '#' {
                continue;
            }
            let cur = get_index(x, y, &even_dict, &odd_dict);
            for (adj_x, adj_y) in get_adjacents(x, y, w, h) {
                if grid[adj_y][adj_x] == '#' {
                    continue;
                }
                let adj = get_index(adj_x, adj_y, &even_dict, &odd_dict);
                solver.add_edge(cur, adj, 1);
            }
        }
    }
    let s = even_dict.len() + odd_dict.len();
    let t = even_dict.len() + odd_dict.len() + 1;
    for i in 0..even_dict.len() {
        solver.add_edge(s, i, 1);
    }
    for i in even_dict.len()..even_dict.len() + odd_dict.len() {
        solver.add_edge(i, t, 1);
    }
    let num = solver.max_flow(s, t);
    println!("{}", num);

    for (from, edges) in solver.edges.iter().enumerate() {
        for &e in edges {
            if e.cap == 0 {
                if e.to >= even_dict.len() + odd_dict.len()
                    || from >= even_dict.len() + odd_dict.len()
                {
                    continue;
                }

                let (to_x, to_y) = from_index(e.to, &even_rev, &odd_rev);
                let (from_x, from_y) = from_index(from, &even_rev, &odd_rev);

                if to_x == from_x {
                    grid[min(from_y, to_y)][to_x] = 'v';
                    grid[max(from_y, to_y)][to_x] = '^';
                } else {
                    grid[to_y][min(to_x, from_x)] = '>';
                    grid[to_y][max(to_x, from_x)] = '<';
                }
            }
        }
    }
    for line in grid {
        for cell in line {
            print!("{}", cell);
        }
        println!("");
    }
}

fn get_adjacents(x: usize, y: usize, w: usize, h: usize) -> Vec<(usize, usize)> {
    let mut adjacents = vec![];
    if x > 0 {
        adjacents.push((x - 1, y));
    }
    if y > 0 {
        adjacents.push((x, y - 1));
    }
    adjacents.push((x, y));
    if y < h - 1 {
        adjacents.push((x, y + 1));
    }
    if x < w - 1 {
        adjacents.push((x + 1, y));
    }
    adjacents
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

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

#[derive(Clone)]
struct Solver {
    edges: Vec<Vec<Edge>>,
    used: Vec<bool>,
}

impl Solver {
    fn new(v: usize) -> Solver {
        Solver {
            edges: vec![Vec::new(); v],
            used: vec![false; v],
        }
    }

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

    fn dfs(&mut self, v: usize, t: usize, f: i64) -> i64 {
        if v == t {
            return f;
        }
        self.used[v] = true;
        for i in 0..self.edges[v].len() {
            let edge = self.edges[v][i];
            if !self.used[edge.to] && edge.cap > 0 {
                let d = self.dfs(edge.to, t, std::cmp::min(f, edge.cap));
                if d > 0 {
                    self.edges[v][i].cap -= d;
                    self.edges[edge.to][edge.rev].cap += d;
                    return d;
                }
            }
        }
        0
    }

    fn max_flow(&mut self, s: usize, t: usize) -> i64 {
        let mut flow = 0;
        loop {
            self.used = vec![false; self.edges.len()];
            let f = self.dfs(s, t, std::i64::MAX);
            if f == 0 {
                return flow;
            }
            flow += f;
        }
    }
}