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 input_mcr::*;
use std::cmp::*;
use std::collections::HashMap;

use atcoder_maxflow::*;
use field::*;

fn main() {
    input! {
        h: usize,
        w: usize,
        field: [chars; h],
    }
    let field = Field::from_vec_vec(&field);
    let mut g = MaxFlowGraph::<i32>::new(h * w + 2);
    let mut mark = HashMap::new();
    for y in 0..h {
        for x in 0..w {
            if (x + y) % 2 == 0 {
                let p = Pos { x, y };
                if field[p] == '.' {
                    for (d, p2) in field.n4(p) {
                        if field[p2] == '.' {
                            g.add_edge(p.y * w + p.x, p2.y * w + p2.x, 1);
                            let cc = match d {
                                Dir::U => ('^', 'v'),
                                Dir::R => ('>', '<'),
                                Dir::D => ('v', '^'),
                                Dir::L => ('<', '>'),
                            };
                            mark.insert((p, p2), cc);
                        }
                    }
                }
            }
        }
    }
    for y in 0..h {
        for x in 0..w {
            if (x + y) % 2 == 0 {
                g.add_edge(h * w, y * w + x, 1);
            } else {
                g.add_edge(y * w + x, h * w + 1, 1);
            }
        }
    }
    let t = g.flow(h * w, h * w + 1, 10000);
    println!("{}", t);
    let mut res = field.clone();
    let edges = g.edges();
    for edge in &edges {
        if edge.flow != 0 {
            let p = Pos {
                x: edge.from % w,
                y: edge.from / w,
            };
            let p2 = Pos {
                x: edge.to % w,
                y: edge.to / w,
            };
            if let Some((c, c2)) = mark.get(&(p, p2)) {
                res[p] = *c;
                res[p2] = *c2;
            }
        }
    }
    let mut res_s = String::new();
    for y in 0..h {
        for x in 0..w {
            let p = Pos { x, y };
            res_s.push(res[p]);
        }
        res_s.push('\n');
    }
    print!("{}", res_s);
}
pub mod input_mcr {
    // ref: tanakh <https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8>
    #[macro_export(local_inner_macros)]
    macro_rules! input {
        (source = $s:expr, $($r:tt)*) => {
            let mut parser = Parser::from_str($s);
            input_inner!{parser, $($r)*}
        };
        (parser = $parser:ident, $($r:tt)*) => {
            input_inner!{$parser, $($r)*}
        };
        (new_stdin_parser = $parser:ident, $($r:tt)*) => {
            let stdin = std::io::stdin();
            let reader = std::io::BufReader::new(stdin.lock());
            let mut $parser = Parser::new(reader);
            input_inner!{$parser, $($r)*}
        };
        ($($r:tt)*) => {
            input!{new_stdin_parser = parser, $($r)*}
        };
    }

    #[macro_export(local_inner_macros)]
    macro_rules! input_inner {
        ($parser:ident) => {};
        ($parser:ident, ) => {};
        ($parser:ident, $var:ident : $t:tt $($r:tt)*) => {
            let $var = read_value!($parser, $t);
            input_inner!{$parser $($r)*}
        };
    }

    #[macro_export(local_inner_macros)]
    macro_rules! read_value {
        ($parser:ident, ( $($t:tt),* )) => {
            ( $(read_value!($parser, $t)),* )
        };
        ($parser:ident, [ $t:tt ; $len:expr ]) => {
            (0..$len).map(|_| read_value!($parser, $t)).collect::<Vec<_>>()
        };
        ($parser:ident, chars) => {
            read_value!($parser, String).chars().collect::<Vec<char>>()
        };
        ($parser:ident, char_) => {
            read_value!($parser, String).chars().collect::<Vec<char>>()[0]
        };
        ($parser:ident, usize1) => {
            read_value!($parser, usize) - 1
        };
        ($parser:ident, line) => {
            $parser.next_line()
        };
        ($parser:ident, line_) => {
            $parser.next_line().chars().collect::<Vec<char>>()
        };
        ($parser:ident, $t:ty) => {
            $parser.next::<$t>().expect("Parse error")
        };
    }

    use std::collections::VecDeque;
    use std::io;
    use std::io::BufRead;
    use std::str;

    pub struct Parser<R> {
        pub reader: R,
        buf: VecDeque<u8>,
        parse_buf: Vec<u8>,
    }

    impl Parser<io::Empty> {
        pub fn from_str(s: &str) -> Parser<io::Empty> {
            Parser {
                reader: io::empty(),
                buf: VecDeque::from(s.as_bytes().to_vec()),
                parse_buf: vec![],
            }
        }
    }

    impl<R: BufRead> Parser<R> {
        pub fn new(reader: R) -> Parser<R> {
            Parser {
                reader: reader,
                buf: VecDeque::new(),
                parse_buf: vec![],
            }
        }
        pub fn update_buf(&mut self) {
            loop {
                let (len, complete) = {
                    let buf2 = self.reader.fill_buf().unwrap();
                    self.buf.extend(buf2.iter());
                    let len = buf2.len();
                    (len, buf2.last() < Some(&0x20))
                };
                self.reader.consume(len);
                if complete {
                    break;
                }
            }
        }
        pub fn next<T: str::FromStr>(&mut self) -> Result<T, T::Err> {
            loop {
                while let Some(c) = self.buf.pop_front() {
                    if c > 0x20 {
                        self.buf.push_front(c);
                        break;
                    }
                }
                self.parse_buf.clear();
                while let Some(c) = self.buf.pop_front() {
                    if c <= 0x20 {
                        self.buf.push_front(c);
                        break;
                    } else {
                        self.parse_buf.push(c);
                    }
                }
                if self.parse_buf.is_empty() {
                    self.update_buf();
                } else {
                    return unsafe { str::from_utf8_unchecked(&self.parse_buf) }.parse::<T>();
                }
            }
        }
        pub fn next_line(&mut self) -> String {
            loop {
                while let Some(c) = self.buf.pop_front() {
                    if c >= 0x20 {
                        self.buf.push_front(c);
                        break;
                    }
                }
                self.parse_buf.clear();
                while let Some(c) = self.buf.pop_front() {
                    if c < 0x20 {
                        self.buf.push_front(c);
                        break;
                    } else {
                        self.parse_buf.push(c);
                    }
                }
                if self.parse_buf.is_empty() {
                    self.update_buf();
                } else {
                    return unsafe { str::from_utf8_unchecked(&self.parse_buf) }.to_string();
                }
            }
        }
    }
}
pub mod atcoder_maxflow {
    use std::collections::VecDeque;
    use std::ops::{Add, AddAssign, Sub, SubAssign};

    #[derive(Clone, Copy)]
    struct GraphEdge<Cap> {
        to: usize,
        rev: usize,
        cap: Cap,
    }

    #[derive(Clone, Copy)]
    pub struct FlowEdge<Cap> {
        pub from: usize,
        pub to: usize,
        pub cap: Cap,
        pub flow: Cap,
    }

    pub struct MaxFlowGraph<Cap> {
        n: usize,
        pos: Vec<(usize, usize)>,
        g: Vec<Vec<GraphEdge<Cap>>>,
    }

    impl<
            Cap: Clone
                + Copy
                + PartialOrd<Cap>
                + From<i8>
                + Add<Output = Cap>
                + Sub<Output = Cap>
                + Sub<Output = Cap>
                + AddAssign<Cap>
                + SubAssign<Cap>,
        > MaxFlowGraph<Cap>
    {
        pub fn new(n: usize) -> MaxFlowGraph<Cap> {
            MaxFlowGraph::<Cap> {
                n,
                pos: vec![],
                g: vec![vec![]; n],
            }
        }

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

        pub fn get_edge(&self, i: usize) -> FlowEdge<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];
            FlowEdge {
                from: self.pos[i].0,
                to: e.to,
                cap: e.cap + re.cap,
                flow: re.cap,
            }
        }

        pub fn edges(&self) -> Vec<FlowEdge<Cap>> {
            let m = self.pos.len();
            let mut result = vec![];
            for i in 0..m {
                result.push(self.get_edge(i));
            }
            result
        }

        pub fn change_edge(&mut self, i: usize, new_cap: Cap, new_flow: Cap) {
            let m = self.pos.len();
            assert!(i < m);
            assert!(Cap::from(0) <= new_flow && new_flow <= new_cap);
            self.g[self.pos[i].0][self.pos[i].1].cap = new_cap - new_flow;
            let e = self.g[self.pos[i].0][self.pos[i].1];
            self.g[e.to][e.rev].cap = new_flow;
        }

        pub fn flow(&mut self, s: usize, t: usize, flow_limit: Cap) -> Cap {
            assert!(s < self.n);
            assert!(t < self.n);

            let mut level = vec![0; self.n];
            let mut iter = vec![0; self.n];
            let mut que = VecDeque::new();

            fn bfs<Cap: PartialOrd + From<i8>>(
                g: &Vec<Vec<GraphEdge<Cap>>>,
                que: &mut VecDeque<usize>,
                level: &mut Vec<i64>,
                iter: &mut Vec<usize>,
                s: usize,
                t: usize,
            ) {
                for x in level.iter_mut() {
                    *x = -1;
                }
                level[s] = 0;
                que.clear();
                que.push_back(s);
                while let Some(v) = que.pop_front() {
                    for e in &g[v] {
                        if e.cap == Cap::from(0) || level[e.to] >= 0 {
                            continue;
                        }
                        level[e.to] = level[v] + 1;
                        if e.to == t {
                            return;
                        }
                        que.push_back(e.to);
                    }
                }
            }

            fn dfs<
                Cap: Clone + Copy + Sub<Output = Cap> + From<i8> + PartialOrd + AddAssign + SubAssign,
            >(
                g: &mut Vec<Vec<GraphEdge<Cap>>>,
                level: &mut Vec<i64>,
                iter: &mut Vec<usize>,
                v: usize,
                up: Cap,
                s: usize,
            ) -> Cap {
                if v == s {
                    return up;
                }
                let mut res = Cap::from(0);
                let level_v = level[v];
                for i in iter[v]..g[v].len() {
                    iter[v] = i;
                    let e = g[v][i];
                    if level_v <= level[e.to] || g[e.to][e.rev].cap == Cap::from(0) {
                        continue;
                    }
                    let new_up = if up - res <= g[e.to][e.rev].cap {
                        up - res
                    } else {
                        g[e.to][e.rev].cap
                    };
                    let d = dfs(g, level, iter, e.to, new_up, s);
                    if d <= Cap::from(0) {
                        continue;
                    }
                    g[v][i].cap += d;
                    g[e.to][e.rev].cap -= d;
                    res += d;
                    if res == up {
                        break;
                    }
                }
                res
            }

            let mut flow = Cap::from(0);
            while flow < flow_limit {
                bfs(&mut self.g, &mut que, &mut level, &mut iter, s, t);
                if level[t] == -1 {
                    break;
                }
                for x in iter.iter_mut() {
                    *x = 0;
                }
                while flow < flow_limit {
                    let f = dfs(&mut self.g, &mut level, &mut iter, t, flow_limit - flow, s);
                    if f == Cap::from(0) {
                        break;
                    }
                    flow += f;
                }
            }
            flow
        }

        pub fn min_cut(&mut self, s: usize) {
            unimplemented!();
        }
    }
}
pub mod field {
    use std::iter::Iterator;
    use std::ops::{Index, IndexMut};

    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
    pub enum Dir {
        U,
        R,
        D,
        L,
    }

    pub const DIRS: [Dir; 4] = [Dir::U, Dir::R, Dir::D, Dir::L];

    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, Hash)]
    pub struct Pos {
        pub x: usize,
        pub y: usize,
    }

    #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Default, Hash)]
    pub struct Field<T> {
        h: usize,
        w: usize,
        field: Vec<T>,
    }

    pub struct N4 {
        i: usize,
        x: usize,
        y: usize,
        h: usize,
        w: usize,
    }

    impl Iterator for N4 {
        type Item = (Dir, Pos);
        fn next(&mut self) -> Option<(Dir, Pos)> {
            let dx = [0, 1, 0, -1];
            let dy = [-1, 0, 1, 0];
            while self.i < 4 {
                let nx = self.x as i64 + dx[self.i];
                let ny = self.y as i64 + dy[self.i];
                if 0 <= nx && nx < self.w as i64 && 0 <= ny && ny < self.h as i64 {
                    self.i += 1;
                    return Some((
                        DIRS[self.i - 1],
                        Pos {
                            x: nx as usize,
                            y: ny as usize,
                        },
                    ));
                }
                self.i += 1;
            }
            None
        }
    }

    pub struct Nexts<'a, T> {
        field: &'a Field<T>,
        pos: Pos,
        dir: Dir,
    }

    impl<'a, T: Clone + Copy + Default> Iterator for Nexts<'a, T> {
        type Item = Pos;
        fn next(&mut self) -> Option<Pos> {
            let pos2 = self.field.next(self.pos, self.dir);
            if let Some(pos2) = pos2 {
                self.pos = pos2;
                Some(pos2)
            } else {
                None
            }
        }
    }

    impl<T: Clone + Copy + Default> Field<T> {
        pub fn new(h: usize, w: usize, default: T) -> Field<T> {
            Field::<T> {
                h,
                w,
                field: vec![default; h * w],
            }
        }
        pub fn from_vec_vec(xss: &Vec<Vec<T>>) -> Field<T> {
            let h = xss.len();
            let w = xss[0].len();
            let mut field = vec![];
            for y in 0..h {
                for x in 0..w {
                    field.push(xss[y][x]);
                }
            }
            Field::<T> { h, w, field }
        }
        pub fn n4(&self, pos: Pos) -> N4 {
            N4 {
                i: 0,
                x: pos.x,
                y: pos.y,
                h: self.h,
                w: self.w,
            }
        }
        pub fn next(&self, pos: Pos, dir: Dir) -> Option<Pos> {
            match dir {
                Dir::U => {
                    if pos.y > 0 {
                        return Some(Pos {
                            x: pos.x,
                            y: pos.y - 1,
                        });
                    }
                }
                Dir::R => {
                    if pos.x + 1 < self.w {
                        return Some(Pos {
                            x: pos.x + 1,
                            y: pos.y,
                        });
                    }
                }
                Dir::D => {
                    if pos.y + 1 < self.h {
                        return Some(Pos {
                            x: pos.x,
                            y: pos.y + 1,
                        });
                    }
                }
                Dir::L => {
                    if pos.x > 0 {
                        return Some(Pos {
                            x: pos.x - 1,
                            y: pos.y,
                        });
                    }
                }
            }
            None
        }
        pub fn nexts<'a>(&'a self, pos: Pos, dir: Dir) -> Nexts<'a, T> {
            Nexts {
                field: self,
                pos,
                dir,
            }
        }
    }

    impl<T: Clone + Copy + Default> Index<Pos> for Field<T> {
        type Output = T;
        fn index(&self, pos: Pos) -> &T {
            &self.field[pos.y * self.w + pos.x]
        }
    }

    impl<T: Clone + Copy + Default> IndexMut<Pos> for Field<T> {
        fn index_mut(&mut self, pos: Pos) -> &mut T {
            &mut self.field[pos.y * self.w + pos.x]
        }
    }
}