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)

// https://atcoder.jp/contests/practice2/tasks/practice2_d
//
#![allow(unused_imports)]
use std::io::*;
use std::io::Write;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

// Input macros.
// Original by tanakh: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, [ next / $t:tt ]) => {
        {
            let len = read_value!($iter, usize);
            (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, switch) => {
        {
            let ty = read_value!($iter, i32);
            if ty == 1 {
                vec![ty, read_value!($iter, i32), read_value!($iter, i32)]
            } else if ty == 2 {
                vec![ty, read_value!($iter, i32)]
            } else {
                vec![ty, read_value!($iter, i32)]
            }
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! read_line {
    ($t:tt) => {
        {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).unwrap();
            s.trim_right().parse::<$t>().unwrap()
        }
    }
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! join {
    ($t:expr, $glue:expr) => {
        $t.into_iter().map(|w| w.to_string()).collect::<Vec<_>>().join($glue)
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

// ===

const MAX_FLOW: i32 = 100000000;

#[derive(Clone, Copy)]
struct Edge {
    from: usize,
    to: usize,
    cap: i32,
    maxcap: i32,
    label: usize,
}

impl Edge {
    fn goto(&self, from: usize) -> usize {
        self.from + self.to - from
    }

    fn cap(&self, from: usize) -> i32 {
        if self.from == from {
            self.cap
        } else {
            self.maxcap - self.cap
        }
    }
}

struct FlowGraph {
    n: usize,
    graph: Vec<Vec<usize>>,
    edges: Vec<Edge>,
    level: Vec<i32>,
    itr: Vec<usize>
}

impl FlowGraph {
    fn new(n: usize) -> Self {
        let graph = vec![vec![]; n];
        let level = vec![0; n];
        let itr = vec![0; n];
        FlowGraph { n: n, graph: graph, edges: vec![], level: level, itr: itr }
    }

    fn add_edge(&mut self, from: usize, to: usize, cap: i32, label: usize) {
        let e = Edge { from: from, to: to, cap: cap, maxcap: cap, label: label };
        let l = self.edges.len();
        self.graph[from].push(l);
        self.graph[to].push(l);
        self.edges.push(e);
    }

    fn dfs(&mut self, now: usize, to: usize, flow: i32) -> i32 {
        if now == to {
            return flow;
        }
        for i in self.itr[now]..self.graph[now].len() {
            self.itr[now] = i;
            let eidx = self.graph[now][i];

            let e = self.edges[eidx];
            let next = e.goto(now);
            let ecap = e.cap(now);
            if ecap > 0 && self.level[now] < self.level[next] {
                let d = self.dfs(next, to, min(flow, ecap));
                if d >= 1 {
                    let e = &mut self.edges[eidx];
                    if e.from == now {
                        e.cap -= d;
                    } else {
                        e.cap += d;
                    }
                    return d;
                }
            }

        }
        return 0;
    }

    fn bfs(&mut self, from: usize) {
        for i in 0..self.n {
            self.level[i] = -1;
        }
        self.level[from] = 0;
        let mut q: VecDeque<usize> = VecDeque::new();
        q.push_back(from);
        while let Some(idx) = q.pop_front() {
            for &eidx in &self.graph[idx] {
                let e = &self.edges[eidx];
                let to = e.goto(idx);
                if e.cap(idx) >= 1 && self.level[to] == -1 {
                    self.level[to] = self.level[idx] + 1;
                    q.push_back(to);
                }
            }
        }
    }

    fn max_flow(&mut self, from: usize, to: usize) -> i32 {
        let mut flow = 0;
        loop {
            self.bfs(from);
            if self.level[to] < 0 {
                return flow;
            }
            for i in 0..self.n {
                self.itr[i] = 0;
            }
            loop {
                let f = self.dfs(from, to, MAX_FLOW);
                if f <= 0 {
                    break;
                }
                flow += f;
            }
        }
    }
}

fn detect_order(ay: usize, ax: usize, by: usize, bx: usize) -> ((usize,usize),(usize,usize),char,char) {
    // debug!(ay,ax,by,bx);
    assert!((ay == by) ^ (ax == bx));

    if ay == by {
        ((ay,min(ax,bx)), (ay,max(ax,bx)), '>', '<')
    } else {
        ((min(ay,by),ax), (max(ay,by),ax), 'v', '^')
    }
}

fn main() {
    input! {
        n: usize, m: usize,
        mut table: [chars; n]
    };


    let cell_id = |i: usize, j: usize| {
        i*m+j
    };

    let mut flow = FlowGraph::new(n*m+2);
    let source = n*m;
    let sink = source+1;
    for i in 0..n {
        for j in 0..m {
            if table[i][j] == '#' {
                continue;
            }

            if (i+j)&1 == 0 {
                flow.add_edge(source, cell_id(i,j), 1, 0);
            } else {
                flow.add_edge(cell_id(i,j), sink, 1, 0);
            }
        }
    }


    let dx = [1,0,1,2];
    let dy = [0,1,2,1];
    for i in 0..n {
        for j in 0..m {
            if table[i][j] == '#' {
                continue;
            }
            if (i+j)&1 == 0 {
                for d in 0..4 {
                    let ti = i+dy[d];
                    let tj = j+dx[d];
                    if ti == 0 || tj == 0 || ti >= n+1 || tj >= m+1 {
                        continue;
                    }
                    let ti = ti-1;
                    let tj = tj-1;
                    if table[ti][tj] == '#' {
                        continue;
                    }
                    flow.add_edge(cell_id(i,j), cell_id(ti,tj), 1, 1);
                }
            }
        }
    }

    let max_flow = flow.max_flow(source, sink);
    for i in 0..n {
        for j in 0..m {
            if table[i][j] == '#' || (i+j)&1==1 {
                continue;
            }
            for &eid in &flow.graph[cell_id(i,j)] {
                if flow.edges[eid].cap == 0 && flow.edges[eid].label == 1 {
                    let tid = flow.edges[eid].from+flow.edges[eid].to-cell_id(i,j);
                    let ti = tid/m;
                    let tj = tid%m;
                    let (f, t, a, b) = detect_order(i, j, ti, tj);
                    table[f.0][f.1] = a;
                    table[t.0][t.1] = b;
                }
            }
        }
    }

    println!("{}", max_flow);
    for c in table {
        println!("{}", join!(c, ""));
    }
}