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)

#[derive(Default)]
pub(crate) struct SimpleQueue<T> {
    payload: Vec<T>,
    pos: usize,
}

impl<T> SimpleQueue<T> {
    pub(crate) fn reserve(&mut self, n: usize) {
        if n > self.payload.len() {
            self.payload.reserve(n - self.payload.len());
        }
    }

    pub(crate) fn size(&self) -> usize {
        self.payload.len() - self.pos
    }

    pub(crate) fn empty(&self) -> bool {
        self.pos == self.payload.len()
    }

    pub(crate) fn push(&mut self, t: T) {
        self.payload.push(t);
    }

    // Do we need mutable version?
    pub(crate) fn front(&self) -> &T {
        &self.payload[self.pos]
    }

    pub(crate) fn clear(&mut self) {
        self.payload.clear();
        self.pos = 0;
    }

    pub(crate) fn pop(&mut self) -> &T {
        self.pos += 1;
        &self.payload[self.pos - 1]
    }
}
use std::cmp::min;
use std::iter;
use std::ops::{Add, AddAssign, Sub, SubAssign};

// Maybe it should be in a separate module
pub trait MfCapacity:
    Copy + Ord + Add<Output = Self> + AddAssign + Sub<Output = Self> + SubAssign
{
    fn zero() -> Self;
    fn max_value() -> Self;
}

impl MfCapacity for i32 {
    fn zero() -> Self {
        0
    }
    fn max_value() -> Self {
        std::i32::MAX
    }
}

impl MfCapacity for i64 {
    fn zero() -> Self {
        0
    }
    fn max_value() -> Self {
        std::i64::MAX
    }
}

impl MfCapacity for u32 {
    fn zero() -> Self {
        0
    }
    fn max_value() -> Self {
        std::u32::MAX
    }
}

impl MfCapacity for u64 {
    fn zero() -> Self {
        0
    }
    fn max_value() -> Self {
        std::u64::MAX
    }
}

impl<Cap> MfGraph<Cap>
where
    Cap: MfCapacity,
{
    pub fn new(n: usize) -> MfGraph<Cap> {
        MfGraph {
            _n: n,
            pos: Vec::new(),
            g: iter::repeat_with(Vec::new).take(n).collect(),
        }
    }

    pub fn add_edge(&mut self, from: usize, to: usize, cap: Cap) -> usize {
        assert!(from < self._n);
        assert!(to < self._n);
        assert!(Cap::zero() <= cap);
        let m = self.pos.len();
        self.pos.push((from, self.g[from].len()));
        let rev = self.g[to].len() + if from == to { 1 } else { 0 };
        self.g[from].push(_Edge { to, rev, cap });
        let rev = self.g[from].len() - 1;
        self.g[to].push(_Edge {
            to: from,
            rev,
            cap: Cap::zero(),
        });
        m
    }
}

pub struct Edge<Cap> {
    pub from: usize,
    pub to: usize,
    pub cap: Cap,
    pub flow: Cap,
}

impl<Cap> MfGraph<Cap>
where
    Cap: MfCapacity,
{
    pub fn get_edge(&self, i: usize) -> Edge<Cap> {
        let m = self.pos.len();
        assert!(i < m);
        let _e = &self.g[self.pos[i].0][self.pos[i].1];
        let _re = &self.g[_e.to][_e.rev];
        Edge {
            from: self.pos[i].0,
            to: _e.to,
            cap: _e.cap + _re.cap,
            flow: _re.cap,
        }
    }
    pub fn edges(&self) -> Vec<Edge<Cap>> {
        let m = self.pos.len();
        (0..m).map(|i| self.get_edge(i)).collect()
    }
    pub fn change_edge(&mut self, i: usize, new_cap: Cap, new_flow: Cap) {
        let m = self.pos.len();
        assert!(i < m);
        assert!(Cap::zero() <= new_flow && new_flow <= new_cap);
        let (to, rev) = {
            let _e = &mut self.g[self.pos[i].0][self.pos[i].1];
            _e.cap = new_cap - new_flow;
            (_e.to, _e.rev)
        };
        let _re = &mut self.g[to][rev];
        _re.cap = new_flow;
    }

    pub fn flow(&mut self, s: usize, t: usize) -> Cap {
        self.flow_with_capacity(s, t, Cap::max_value())
    }
    pub fn flow_with_capacity(&mut self, s: usize, t: usize, flow_limit: Cap) -> Cap {
        let n_ = self._n;
        assert!(s < n_);
        assert!(t < n_);

        let mut calc = FlowCalculator {
            graph: self,
            s,
            t,
            flow_limit,
            level: vec![0; n_],
            iter: vec![0; n_],
            que: SimpleQueue::default(),
        };

        let mut flow = Cap::zero();
        while flow < flow_limit {
            calc.bfs();
            if calc.level[t] == -1 {
                break;
            }
            calc.iter.iter_mut().for_each(|e| *e = 0);
            while flow < flow_limit {
                let f = calc.dfs(t, flow_limit - flow);
                if f == Cap::zero() {
                    break;
                }
                flow += f;
            }
        }
        flow
    }

    pub fn min_cut(&self, s: usize) -> Vec<bool> {
        let mut visited = vec![false; self._n];
        let mut que = SimpleQueue::default();
        que.push(s);
        while !que.empty() {
            let &p = que.front();
            que.pop();
            visited[p] = true;
            for e in &self.g[p] {
                if e.cap != Cap::zero() && !visited[e.to] {
                    visited[e.to] = true;
                    que.push(e.to);
                }
            }
        }
        visited
    }
}

struct FlowCalculator<'a, Cap> {
    graph: &'a mut MfGraph<Cap>,
    s: usize,
    t: usize,
    flow_limit: Cap,
    level: Vec<i32>,
    iter: Vec<usize>,
    que: SimpleQueue<usize>,
}

impl<Cap> FlowCalculator<'_, Cap>
where
    Cap: MfCapacity,
{
    fn bfs(&mut self) {
        self.level.iter_mut().for_each(|e| *e = -1);
        self.level[self.s] = 0;
        self.que.clear();
        self.que.push(self.s);
        while !self.que.empty() {
            let v = *self.que.front();
            self.que.pop();
            for e in &self.graph.g[v] {
                if e.cap == Cap::zero() || self.level[e.to] >= 0 {
                    continue;
                }
                self.level[e.to] = self.level[v] + 1;
                if e.to == self.t {
                    return;
                }
                self.que.push(e.to);
            }
        }
    }
    fn dfs(&mut self, v: usize, up: Cap) -> Cap {
        if v == self.s {
            return up;
        }
        let mut res = Cap::zero();
        let level_v = self.level[v];
        for i in self.iter[v]..self.graph.g[v].len() {
            self.iter[v] = i;
            let &_Edge {
                to: e_to,
                rev: e_rev,
                ..
            } = &self.graph.g[v][i];
            if level_v <= self.level[e_to] || self.graph.g[e_to][e_rev].cap == Cap::zero() {
                continue;
            }
            let d = self.dfs(e_to, min(up - res, self.graph.g[e_to][e_rev].cap));
            if d <= Cap::zero() {
                continue;
            }
            self.graph.g[v][i].cap += d;
            self.graph.g[e_to][e_rev].cap -= d;
            res += d;
            if res == up {
                break;
            }
        }
        self.iter[v] = self.graph.g[v].len();
        res
    }
}

#[derive(Default)]
pub struct MfGraph<Cap> {
    _n: usize,
    pos: Vec<(usize, usize)>,
    g: Vec<Vec<_Edge<Cap>>>,
}

struct _Edge<Cap> {
    to: usize,
    rev: usize,
    cap: Cap,
}


use std::io::Read;
// use std::iter;

fn main() {
    const N: usize = 128;

    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    let n: usize = input.next().unwrap().parse().unwrap();
    let m: usize = input.next().unwrap().parse().unwrap();
    let mut s = vec![vec![false; N]; N];
    for i in 1..=n {
        for (j, c) in (1..=m).zip(input.next().unwrap().chars()) {
            s[i][j] = c == '.';
        }
    }

    let dy = [1, 0, -1, 0];
    let dx = [0, 1, 0, -1];
    let c = "v>^<".chars().collect::<Vec<_>>();
    let mut graph = MfGraph::<i32>::new(128 * 128);

    for i in 1..=n {
        for j in 1..=m {
            if (i + j) % 2 == 0 {
                graph.add_edge(0, i * N + j, 1);
                for (dy, dx) in dy.iter().zip(dx.iter()) {
                    let k = (i as i32 + dy) as usize;
                    let l = (j as i32 + dx) as usize;
                    if s[i][j] && s[k][l] {
                        graph.add_edge(i * N + j, k * N + l, 1);
                    }
                }
            } else {
                graph.add_edge(i * N + j, 1, 1);
            }
        }
    }
    println!("{}", graph.flow(0, 1));
    let mut res: Vec<Vec<_>> = (1..=n)
        .map(|i| (1..=m).map(|j| if s[i][j] { '.' } else { '#' }).collect())
        .collect();
    for e in graph.edges() {
        let i = e.from / N;
        let j = e.from % N;
        let k = e.to / N;
        let l = e.to % N;
        if e.flow == 1 {
            for h in 0..4 {
                if i as i32 + dy[h] == k as i32 && j as i32 + dx[h] == l as i32 {
                    res[i - 1][j - 1] = c[h];
                    res[k - 1][l - 1] = c[h ^ 2];
                }
            }
        }
    }
    for s in res {
        println!("{}", s.iter().collect::<String>());
    }
}