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 Ruby (2.7.1) (judge verdict: Wrong Answer)

class MF_Graph
    def initialize(n = 0)
        @n = n
        @pos = []
        @g = Array.new(n) {[]}
    end

    def add_edge(from, to, cap)
        m = @pos.size
        @pos << [from, @g[from].size]
        @g[from] << [to, @g[to].size, cap]
        @g[to] << [from, @g[from].size - 1, 0]
        return m
    end

    def flow(s, t, flow_limit = 1 << 64)
        level = Array.new(@n)
        iter = Array.new(@n)
        que = []

        bfs =->() {
            level.fill(-1)
            level[s] = 0
            que.clear
            que << s

            while v = que.shift
                @g[v].each do |e|
                    next if e[2] == 0 || level[e[0]] >= 0
                    level[e[0]] = level[v] + 1
                    return if e[0] == t
                    que << e[0]
                end
            end
        }

        dfs =-> (v, up) {
            return up if v == s
            res = 0
            level_v = level[v]

            iter[v].upto(@g[v].size - 1) do |i|
                e = @g[v][i]
                next if level_v <= level[e[0]] || @g[e[0]][e[1]][2] == 0
                d = dfs.(e[0], [ up - res, @g[e[0]][e[1]][2] ].min)
                next if d <= 0
                @g[v][i][2] += d
                @g[e[0]][e[1]][2] -= d
                res += d
                break if res == up
            end

            return res
        }
  
        flow = 0
        while flow < flow_limit
            bfs.()
            break if level[t] == -1
            iter.fill(0)

            while flow < flow_limit
                f = dfs.(t, flow_limit - flow)
                break if f == 0
                flow += f
            end
        end

        return flow
    end

    def calc(s, ans, m)
        @g[s].each do |e|
            next if e[2] > 0
            i, j = e[0].divmod(m)
            @g[e[0]].each do |f|
                next if f[2] > 0
                    x, y = f[0].divmod(m)

                    if i == x
                        j, y = y, j if y < j
                        ans[i][j], ans[i][y] = ?>, ?<
                    else
                        i, x = x, i if x < i
                        ans[i][j], ans[x][j] = ?V, ?^
                    end
                break
            end
        end
    end
end

n, m = gets.split.map(&:to_i)
l = n * m
mf = MF_Graph.new(l+2)

s = n.times.map {gets.chars} << Array.new(m+1, ?#)
s.each {|e| p e}
move = [[1,0], [0,1]]

n.times do |i|
    m.times do |j|
        next if s[i][j] != ?.
        f = !(i.odd? ^ j.odd?)
        f ? mf.add_edge(l, i * m + j, 1) : mf.add_edge(i * m + j, l + 1, 1)

        move.each do |x, y|
            x = i + x
            y = j + y
            next if s[x][y] != ?.
            f ? mf.add_edge(i * m + j, x * m + y, 1) : mf.add_edge(x * m + y, i * m + j, 1)
        end
    end
end

mf.flow(l, l+1)
mf.calc(l, s, m)
puts s[0..-2].map{|e| e.join.chomp}