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.#
^><



Sample input:
3 3
#..
..#
...


Sample output:
3
#><
vv#
^^.

Submission status: Wrong Answer

Solution code:
import sys
import itertools
import numpy as np
import networkx as nx

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
S = np.frombuffer(read(), 'S1').reshape(N, -1)[:, :M].astype('U1')

A = []
B = []
E = []

for i, j in itertools.product(range(N), range(M)):
    if S[i, j] == '#':
        continue
    elif (i + j) & 1:
        A.append((i, j))
    else:
        B.append((i, j))

for i, j in A:
    for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        i1, j1 = i + dx, j + dy
        if 0 <= i1 < N and 0 <= j1 < M and S[i1, j1] != '#':
            E.append(((i, j), (i1, j1)))

G = nx.Graph()
G.add_nodes_from(A, bipartite=0)
G.add_nodes_from(B, bipartite=1)
G.add_edges_from(E)

M = nx.bipartite.maximum_matching(G, A)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
import numpy as np
import networkx as nx

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H, W = map(int, readline().split())
S = np.frombuffer(read(), 'S1').reshape(H, -1)[:, :W].astype('U1')

A = []
B = []
E = []

for i, j in itertools.product(range(H), range(W)):
    if S[i, j] == '#':
        continue
    elif (i + j) & 1:
        A.append(W*i+j)
    else:
        B.append(W*i+j)

for a in A:
    i,j = divmod(a,W)
    for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        i1, j1 = i + dx, j + dy
        if 0 <= i1 < H and 0 <= j1 < W and S[i1, j1] != '#':
            b = W*i1+j1
            E.append((a,b))

Submission status: Wrong Answer

Solution code:
import sys
import itertools
import numpy as np
import networkx as nx

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
S = np.frombuffer(read(), 'S1').reshape(N, -1)[:, :M].astype('U1')

G = nx.DiGraph()
G.add_nodes_from(['S', 'T'])
for i, j in itertools.product(range(N), range(M)):
    if S[i, j] == '#':
        continue
    if (i + j) % 2 == 0:
        G.add_edge('S', (i, j), capacity=1)
    else:
        G.add_edge((i, j), 'T', capacity=1)
    if (i + j) % 2 == 0:
        for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            i1, j1 = i + dx, j + dy
            if 0 <= i1 < N and 0 <= j1 < M and S[i1, j1] != '#':
                G.add_edge((i, j), (i1, j1), capacity=1)

flow_value, flow = nx.maximum_flow(G, 'S', 'T')

Submission status: Wrong Answer

Solution code:
import sys
import itertools
import numpy as np
import networkx as nx

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
S = np.frombuffer(read(), 'S1').reshape(N, -1)[:, :M].astype('U1')

Submission status: Wrong Answer

Solution code:
import sys
import itertools
import numpy as np
import networkx as nx

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
S = np.frombuffer(read(), 'S1').reshape(N, -1)[:, :M].astype('U1')

G = nx.DiGraph()
G.add_nodes_from(['S', 'T'])
for i, j in itertools.product(range(N), range(M)):
    if S[i, j] == '#':
        continue
    if (i + j) % 2 == 0:
        G.add_edge('S', (i, j), capacity=1)
    else:
        G.add_edge((i, j), 'T', capacity=1)
    if (i + j) % 2 == 0:
        for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            i1, j1 = i + dx, j + dy
            if 0 <= i1 < N and 0 <= j1 < M and S[i1, j1] != '#':
                G.add_edge((i, j), (i1, j1), capacity=1)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = list(map(int, input().split()))
s = [input() for _ in range(n)]
# scipyの例
import scipy.sparse
data = []
rs = []
cs = []
def add(i,j,v=1,directed=False):
    rs.append(i)
    cs.append(j)
    data.append(v)
    if not directed:
        rs.append(j)
        cs.append(i)
        data.append(v)
S = n*m
T = n*m+1
for i in range(n):
    for j in range(m):
        if (i+j)%2==0:
            add(S, i*m+j)
        else:
            add(i*m+j, T)
        if s[i][j]=="#":
            continue
        u = i*m + j
        if i>=1:
            v = u-m
            if s[i-1][j]==".":
                add(u,v)
        if j>=1:
            v = u-1
            if s[i][j-1]==".":
                add(u,v)
        
g = scipy.sparse.csr_matrix((data, (rs, cs)), shape=(n*m+2, n*m+2))
ans = scipy.sparse.csgraph.maximum_flow(g, S, T) # 最大流
# 復元
val = [["."]*m for _ in range(n)]
for i in range(n):
    for j in range(m):
        if s[i][j]=="#":
            val[i][j] = "#"
        u = i*m + j
        if i>=1:
            v = u-m
            if ans.residual[u,v]==-1:
                val[i][j] = "^"
                val[i-1][j] = "v"
            elif ans.residual[v,u]==-1:
                val[i][j] = "^"
                val[i-1][j] = "v"
        if j>=1:
            v = u-1
            if ans.residual[u,v]==-1:
                val[i][j] = "<"
                val[i][j-1] = ">"
            elif ans.residual[v,u]==-1:
                val[i][j] = "<"
                val[i][j-1] = ">"
print(ans.flow_value)
write("\n".join(["".join(val[i]) for i in range(n)]))

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = list(map(int, input().split()))
s = [input() for _ in range(n)]
# scipyの例
import scipy.sparse
data = []
rs = []
cs = []
def add(i,j,v=1,directed=False):
    rs.append(i)
    cs.append(j)
    data.append(v)
    if not directed:
        rs.append(j)
        cs.append(i)
        data.append(v)
S = n*m
T = n*m+1
for i in range(n):
    for j in range(m):
        if (i+j)%2==0:
            add(S, i*m+j)
        else:
            add(i*m+j, T)
        if s[i][j]=="#":
            continue
        u = i*m + j
        if i>=1:
            v = u-m
            if s[i-1][j]==".":
                add(u,v)
        if j>=1:
            v = u-1
            if s[i][j-1]==".":
                add(u,v)
        
g = scipy.sparse.csr_matrix((data, (rs, cs)), shape=(n*m+2, n*m+2))
ans = scipy.sparse.csgraph.maximum_flow(g, S, T) # 最大流
# 復元
val = [["."]*m for _ in range(n)]
for i in range(n):
    for j in range(m):
        if s[i][j]=="#":
            val[i][j] = "#"
        u = i*m + j
        if i>=1:
            v = u-m
            if ans.residual[u,v]:
                val[i][j] = "^"
                val[i-1][j] = "v"
            elif ans.residual[v,u]:
                val[i][j] = "v"
                val[i-1][j] = "^"
        if j>=1:
            v = u-1
            if ans.residual[u,v]:
                val[i][j] = "<"
                val[i][j-1] = ">"
            elif ans.residual[v,u]:
                val[i][j] = ">"
                val[i][j-1] = "<"
print(ans.flow_value)
write("\n".join(["".join(val[i]) for i in range(n)]))

Submission status: Wrong Answer

Solution code:
from collections import deque

class MaxFlow:
    def __init__(self, n):
        self.n = n
        self.graph = [[] for _ in range(n)]
        self.pos = []

    def add_edge(self, fr, to, cap):
        m = len(self.pos)
        self.pos.append((fr, len(self.graph[fr])))
        self.graph[fr].append([to, len(self.graph[to]), cap])
        self.graph[to].append([fr, len(self.graph[fr]) - 1, 0])
        return m

    def get_edge(self, idx):
        to, rev, cap = self.graph[self.pos[idx][0]][self.pos[idx][1]]
        rev_to, rev_rev, rev_cap = self.graph[to][rev]
        return rev_to, to, cap + rev_cap, rev_cap

    def edges(self):
        m = len(self.pos)
        for i in range(m):
            yield self.get_edge(i)

    def change_edge(self, idx, new_cap, new_flow):
        to, rev, cap = self.graph[self.pos[idx][0]][self.pos[idx][1]]
        self.graph[self.pos[idx][0]][self.pos[idx][1]][2] = new_cap - new_flow
        self.graph[to][rev][2] = new_flow

    def dfs(self, s, v, up):
        if v == s:
            return up
        res = 0
        lv = self.level[v]
        for i in range(self.iter[v], len(self.graph[v])):
            to, rev, cap = self.graph[v][i]
            if lv <= self.level[to] or self.graph[to][rev][2] == 0:
                continue
            d = self.dfs(s, to, min(up - res, self.graph[to][rev][2]))
            if d <= 0:
                continue
            self.graph[v][i][2] += d
            self.graph[to][rev][2] -= d
            res += d
            if res == up:
                break
            self.iter[v] += 1
        return res

    def max_flow(self, s, t):
        return self.max_flow_with_limit(s, t, 2 ** 63 - 1)

    def max_flow_with_limit(self, s, t, limit):
        flow = 0
        while flow < limit:
            self.level = [-1] * self.n
            self.level[s] = 0
            queue = deque()
            queue.append(s)
            while queue:
                v = queue.popleft()
                for to, rev, cap in self.graph[v]:
                    if cap == 0 or self.level[to] >= 0:
                        continue
                    self.level[to] = self.level[v] + 1
                    if to == t:
                        break
                    queue.append(to)
            if self.level[t] == -1:
                break
            self.iter = [0] * self.n
            while flow < limit:
                f = self.dfs(s, t, limit - flow)
                if not f:
                    break
                flow += f
        return flow

    def min_cut(self, s):
        visited = [0] * self.n
        queue = deque()
        queue.append(s)
        while queue:
            p = queue.popleft()
            visited[p] = True
            for to, rev, cap in self.graph[p]:
                if cap and not visited[to]:
                    visited[to] = True
                    queue.append(to)
        return visited


n,m = map(int, input().split())
s = [list(input()) for _ in range(n)]

mf = MaxFlow(n * m + 2)

start = n * m
end = n * m + 1
d = [(1,0), (-1,0), (0,1), (0,-1)]

for i in range(n):
    for j in range(m):
        if s[i][j] == '#':
            continue
        else:
            if (i + j) % 2 == 0:
                mf.add_edge(start, i * m + j, 1)

                for i1, j1 in d:
                    if 0 <= i + i1 < n and 0 <= j + j1 < m:
                        if s[i+i1][j+j1] == '.':
                            mf.add_edge(i * m + j, (i+i1) * m + (j+j1), 1)

            else:
                mf.add_edge(i * m + j, end, 1)

print(mf.max_flow(start, end))

for i in range(len(mf.pos)):
    s1, e1, cap, flow = mf.get_edge(i)
    if flow == 0 or s1 == start or e1 == end:
        continue
    else:
        si = s1 // m
        sj = s1 % m
        ei = e1 // m
        ej = e1 % m
        if s1 - e1 == 1:
            s[si][sj] = '<'
            s[ei][ej] = '>'
        elif e1 - s1 == 1:
            s[si][sj] = '>'
            s[ei][ej] = '<'
        elif s1 - e1 == m:
            s[si][sj] = '^'
            s[ei][ej] = 'v'
        else:
            s[si][sj] = 'v'
            s[ei][ej] = '^'

for i in s:
    for j in i:
        print(j, end = '')
    print()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N,M=map(int,input().split())
MAP=[list(input().strip()) for i in range(N)]

start=N*M+2
goal=N*M+3

EDGE=[set() for i in range(N*M+5)]

for i in range(N):
    for j in range(M):
        if (i+j)%2==0 and MAP[i][j]==".":
            EDGE[start].add(i*M+j)

            for x,y in [(i+1,j),(i-1,j),(i,j+1),(i,j-1)]:
                if 0<=x<N and 0<=y<M and MAP[x][y]==".":
                    EDGE[i*M+j].add(x*M+y)

        if (i+j)%2==1 and MAP[i][j]==".":
            EDGE[i*M+j].add(goal)

count=0 # カット数をカウント

while True:

    USED=[0]*(N*M+5)
    ROUTE=[-1]*(N*M+5)
    Q=[start]
    
    while Q: # 探索
        NOW=Q.pop()
        if NOW==goal:
            break
        
        for to in EDGE[NOW]:
            if USED[to]==0:
                ROUTE[to]=NOW # EDGEの更新用に後ろから辿る方法を覚えておく
                USED[to]=1
                Q.append(to)
    else:
        break

    count+=1
    i=goal
    while i!=start: # goalからたどり,Routeを使ってEDGEの更新
        j=ROUTE[i]
        EDGE[j].remove(i) # 使ったルートをいけなく更新
        EDGE[i].add(j) # 逆向きに進めるようにする.これらを重みつきにすれ普通のフロー
        i=j
        
print(count)

for i in range(N):
    for j in range(M):
        if (i+j)%2==1:
            for to in EDGE[i*M+j]:
                if j>1 and to == i*M+j-1:
                    MAP[i][j]="<"
                    MAP[i][j-1]=">"
                elif j>1 and to == i*M+j+1:
                    MAP[i][j]=">"
                    MAP[i][j+1]="<"
                elif to == i*M+j-M:
                    MAP[i][j]="^"
                    MAP[i-1][j]="v"
                elif to == i*M+j+M:
                    MAP[i][j]="v"
                    MAP[i+1][j]="^"

for m in MAP:
    print("".join(m))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N,M=map(int,input().split())
MAP=[list(input().strip()) for i in range(N)]

start=N*M+2
goal=N*M+3

EDGE=[set() for i in range(N*M+5)]

for i in range(N):
    for j in range(M):
        if (i+j)%2==0 and MAP[i][j]==".":
            EDGE[start].add(i*M+j)

            for x,y in [(i+1,j),(i-1,j),(i,j+1),(i,j-1)]:
                if 0<=x<N and 0<=y<M and MAP[x][y]==".":
                    EDGE[i*M+j].add(x*M+y)

        if (i+j)%2==1 and MAP[i][j]==".":
            EDGE[i*M+j].add(goal)

count=0 # カット数をカウント

while True:

    USED=[0]*(N*M+5)
    ROUTE=[-1]*(N*M+5)
    Q=[start]
    
    while Q: # 探索
        NOW=Q.pop()
        if NOW==goal:
            break
        
        for to in EDGE[NOW]:
            if USED[to]==0:
                ROUTE[to]=NOW # EDGEの更新用に後ろから辿る方法を覚えておく
                USED[to]=1
                Q.append(to)
    else:
        break

    count+=1
    i=goal
    while i!=start: # goalからたどり,Routeを使ってEDGEの更新
        j=ROUTE[i]
        EDGE[j].remove(i) # 使ったルートをいけなく更新
        EDGE[i].add(j) # 逆向きに進めるようにする.これらを重みつきにすれ普通のフロー
        i=j
        
print(count)

for i in range(N):
    for j in range(M):
        if (i+j)%2==1:
            for to in EDGE[i*M+j]:
                if to == i*M+j -1:
                    MAP[i][j]="<"
                    MAP[i][j-1]=">"
                elif to == i*M+j+1:
                    MAP[i][j]=">"
                    MAP[i][j+1]="<"
                elif to == i*M+j-M:
                    MAP[i][j]="^"
                    MAP[i-1][j]="v"
                elif to == i*M+j+M:
                    MAP[i][j]="v"
                    MAP[i+1][j]="^"

for m in MAP:
    print("".join(m))

Submission status: Wrong Answer

Solution code:
code = r"""
# distutils: language=c++
# distutils: include_dirs=[/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include,/opt/atcoder-stl]
# cython: boundscheck=False
# cython: wraparound=False
from libcpp cimport bool
from libcpp.string cimport string
from libcpp.vector cimport vector

cdef extern from "<atcoder/dsu>" namespace "atcoder":
    cpdef cppclass dsu:
        dsu(int n)
        int merge(int a, int b)
        bool same(int a, int b)
        int leader(int a)
        int size(int a)
        vector[vector[int]] groups()
cdef class dsu_:
    cdef dsu *ptr
    def __cinit__(self, int n): self.ptr = new dsu(n)
    def __dealloc__(self): del self.ptr
    cpdef int merge(self,a,b): return self.ptr.merge(a,b)
    cpdef bool same(self,a,b): return self.ptr.same(a,b)
    cpdef int leader(self,a): return self.ptr.leader(a)
    cpdef int size(self,a): return self.ptr.size(a)
    cpdef vector[vector[int]] groups(self): return self.ptr.groups()

cdef extern from "<atcoder/fenwicktree>" namespace "atcoder":
    cdef cppclass fenwick_tree[T]:
        fenwick_tree()
        fenwick_tree(int n)
        void add(int p, T x)
        T sum(int l, int r)
cdef class fenwick_tree_:
    cdef fenwick_tree[int] *ptr
    def __cinit__(self, int n): self.ptr = new fenwick_tree[int](n)  
    def __dealloc__(self): del self.ptr
    cpdef void add(self, int p, long x): self.ptr.add(p, x)
    cpdef long sum(self, int l, int r): return self.ptr.sum(l, r)

cdef extern from "<atcoder/string>" namespace "atcoder":
    vector[int] suffix_array(vector[int] s, int upper)
    vector[int] suffix_array(vector[long] s)
    vector[int] suffix_array(string s)
    vector[int] lcp_array(vector[long] s, vector[int] sa)
    vector[int] lcp_array(string s, vector[int] sa)
    vector[int] z_algorithm(vector[long] s)
    vector[int] z_algorithm(string s)
cpdef vector[int] suffix_array_u(vector[int] s, int upper): return suffix_array(s, upper)
cpdef vector[int] suffix_array_l(vector[long] s): return suffix_array(s)
cpdef vector[int] suffix_array_s(string s): return suffix_array(s)
cpdef vector[int] lcp_array_l(vector[long] s, vector[int] sa): return lcp_array(s, sa)
cpdef vector[int] lcp_array_s(string s, vector[int] sa): return lcp_array(s, sa)
cpdef vector[int] z_algorithm_l(vector[long] s): return z_algorithm(s)
cpdef vector[int] z_algorithm_s(string s): return z_algorithm(s)

cdef extern from "<atcoder/maxflow>" namespace "atcoder":
    cdef cppclass mf_graph[Cap]:
        mf_graph(int n)
        int add_edge(int frm, int to, Cap cap)
        Cap flow(int s, int t)
        Cap flow(int s, int t, Cap flow_limit)
        vector[bool] min_cut(int s)
        cppclass edge:
            int frm "from", to
            Cap cap, flow
            edge(edge &e)
        edge get_edge(int i)
        vector[edge] edges()
        void change_edge(int i, Cap new_cap, Cap new_flow)
cdef class mf_graph_:
    cdef mf_graph[int] *ptr
    def __cinit__(self, int n): self.ptr = new mf_graph[int](n)  
    def __dealloc__(self): del self.ptr
    cpdef int add_edge(self, int frm, int to, int cap): return self.ptr.add_edge(frm, to, cap)
    cpdef int flow(self, int s, int t): return self.ptr.flow(s, t)
    cpdef int flow_limit(self, int s, int t, int flow_limit): return self.ptr.flow(s, t, flow_limit)
    cpdef vector[bool] min_cut(self, int s): return self.ptr.min_cut(s)
    cpdef vector[int] get_edge(self, int i):
        cdef mf_graph[int].edge *e = new mf_graph[int].edge(self.ptr.get_edge(i))
        cdef vector[int] *ret_e = new vector[int]()        
        ret_e.push_back(e.frm)
        ret_e.push_back(e.to)
        ret_e.push_back(e.cap)
        ret_e.push_back(e.flow)
        return ret_e[0]
    cpdef vector[vector[int]] edges(self):
        cdef vector[mf_graph[int].edge] es = self.ptr.edges()
        cdef vector[vector[int]] *ret_es = new vector[vector[int]](es.size())
        for i in range(es.size()):
            ret_es.at(i).push_back(es.at(i).frm)
            ret_es.at(i).push_back(es.at(i).to)
            ret_es.at(i).push_back(es.at(i).cap)
            ret_es.at(i).push_back(es.at(i).flow)
        return ret_es[0]
    cpdef void change_edge(self, int i, int new_cap, int new_flow): self.ptr.change_edge(i, new_cap, new_flow)
"""

import os
try:
    from atcoder import *
except:
    open('atcoder.pyx', 'w').write(code)
    os.system('cythonize -i -3 -b atcoder.pyx')

H,W=map(int,input().split())
S=[input() for i in range(H)]
mf=mf_graph_(H*W+2)
s,t=H*W,H*W+1
for i in range(H):
    for j in range(W):
        if S[i][j]=='#': continue
        v=i*W+j
        if (i+j)%2:
            mf.add_edge(s,v,1)
        else:
            mf.add_edge(v,t,1);continue
        if j<W-1 and S[i][j+1]=='.':
            mf.add_edge(v,v+1,1)
        if 0<j and S[i][j-1]=='.':
            mf.add_edge(v,v-1,1)
        if i<H-1 and S[i+1][j]=='.':
            mf.add_edge(v,v+W,1)
        if 0<i and S[i-1][j]=='.':
            mf.add_edge(v,v-W,1)
print(mf.flow(s,t))
r=[[c for c in S[i]] for i in range(H)]
for frm,to,_,flow in mf.edges():
    if flow==1 and frm!=s and to!=t:
        i,j=frm//W,frm%W
        k,l=to//W,to%W
        if frm-to==1:
            r[i][j],r[k][l]='<','>'
        elif to-frm==1:
            r[i][j],r[k][l]='>','<'
        elif frm-to==W:
            r[i][j],r[k][l]='^','v'
        else:
            r[i][j],r[k][l]='v','^'
print(*[''.join(l) for l in r],sep='\n')

Submission status: Wrong Answer

Solution code:
code = r"""
# distutils: language=c++
# distutils: include_dirs=[/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include,/opt/atcoder-stl]
# cython: boundscheck=False
# cython: wraparound=False
from libcpp cimport bool
from libcpp.string cimport string
from libcpp.vector cimport vector

cdef extern from "<atcoder/dsu>" namespace "atcoder":
    cpdef cppclass dsu:
        dsu(int n)
        int merge(int a, int b)
        bool same(int a, int b)
        int leader(int a)
        int size(int a)
        vector[vector[int]] groups()
cdef class dsu_:
    cdef dsu *ptr
    def __cinit__(self, int n): self.ptr = new dsu(n)
    def __dealloc__(self): del self.ptr
    cpdef int merge(self,a,b): return self.ptr.merge(a,b)
    cpdef bool same(self,a,b): return self.ptr.same(a,b)
    cpdef int leader(self,a): return self.ptr.leader(a)
    cpdef int size(self,a): return self.ptr.size(a)
    cpdef vector[vector[int]] groups(self): return self.ptr.groups()

cdef extern from "<atcoder/fenwicktree>" namespace "atcoder":
    cdef cppclass fenwick_tree[T]:
        fenwick_tree()
        fenwick_tree(int n)
        void add(int p, T x)
        T sum(int l, int r)
cdef class fenwick_tree_:
    cdef fenwick_tree[int] *ptr
    def __cinit__(self, int n): self.ptr = new fenwick_tree[int](n)  
    def __dealloc__(self): del self.ptr
    cpdef void add(self, int p, long x): self.ptr.add(p, x)
    cpdef long sum(self, int l, int r): return self.ptr.sum(l, r)

cdef extern from "<atcoder/string>" namespace "atcoder":
    vector[int] suffix_array(vector[int] s, int upper)
    vector[int] suffix_array(vector[long] s)
    vector[int] suffix_array(string s)
    vector[int] lcp_array(vector[long] s, vector[int] sa)
    vector[int] lcp_array(string s, vector[int] sa)
    vector[int] z_algorithm(vector[long] s)
    vector[int] z_algorithm(string s)
cpdef vector[int] suffix_array_u(vector[int] s, int upper): return suffix_array(s, upper)
cpdef vector[int] suffix_array_l(vector[long] s): return suffix_array(s)
cpdef vector[int] suffix_array_s(string s): return suffix_array(s)
cpdef vector[int] lcp_array_l(vector[long] s, vector[int] sa): return lcp_array(s, sa)
cpdef vector[int] lcp_array_s(string s, vector[int] sa): return lcp_array(s, sa)
cpdef vector[int] z_algorithm_l(vector[long] s): return z_algorithm(s)
cpdef vector[int] z_algorithm_s(string s): return z_algorithm(s)

cdef extern from "<atcoder/maxflow>" namespace "atcoder":
    cdef cppclass mf_graph[Cap]:
        mf_graph(int n)
        int add_edge(int frm, int to, Cap cap)
        Cap flow(int s, int t)
        Cap flow(int s, int t, Cap flow_limit)
        vector[bool] min_cut(int s)
        cppclass edge:
            int frm "from", to
            Cap cap, flow
            edge(edge &e)
        edge get_edge(int i)
        vector[edge] edges()
        void change_edge(int i, Cap new_cap, Cap new_flow)
cdef class mf_graph_:
    cdef mf_graph[int] *ptr
    def __cinit__(self, int n): self.ptr = new mf_graph[int](n)  
    def __dealloc__(self): del self.ptr
    cpdef int add_edge(self, int frm, int to, int cap): return self.ptr.add_edge(frm, to, cap)
    cpdef int flow(self, int s, int t): return self.ptr.flow(s, t)
    cpdef int flow_limit(self, int s, int t, int flow_limit): return self.ptr.flow(s, t, flow_limit)
    cpdef vector[bool] min_cut(self, int s): return self.ptr.min_cut(s)
    cpdef vector[int] get_edge(self, int i):
        cdef mf_graph[int].edge *e = new mf_graph[int].edge(self.ptr.get_edge(i))
        cdef vector[int] *ret_e = new vector[int]()        
        ret_e.push_back(e.frm)
        ret_e.push_back(e.to)
        ret_e.push_back(e.cap)
        ret_e.push_back(e.flow)
        return ret_e[0]
    cpdef vector[vector[int]] edges(self):
        cdef vector[mf_graph[int].edge] es = self.ptr.edges()
        cdef vector[vector[int]] *ret_es = new vector[vector[int]](es.size())
        for i in range(es.size()):
            ret_es.at(i).push_back(es.at(i).frm)
            ret_es.at(i).push_back(es.at(i).to)
            ret_es.at(i).push_back(es.at(i).cap)
            ret_es.at(i).push_back(es.at(i).flow)
        return ret_es[0]
    cpdef void change_edge(self, int i, int new_cap, int new_flow): self.ptr.change_edge(i, new_cap, new_flow)
"""

import os
try:
    from atcoder import *
except:
    open('atcoder.pyx', 'w').write(code)
    os.system('cythonize -i -3 -b atcoder.pyx')

H,W=map(int,input().split())
S=[input() for i in range(H)]
mf=mf_graph_(H*W+2)
s,t=H*W,H*W+1
for i in range(H):
    for j in range(W):
        if S[i][j]=='#': continue
        v=i*W+j
        if (i+j)%2:
            mf.add_edge(s,v,1)
        else:
            mf.add_edge(v,t,1)
for i in range(H):
    for j in range(W):
        if S[i][j]=='#' or (i+j)%2==0: continue
        v=i*W+j
        if j<W-1 and S[i][j+1]=='.':
            mf.add_edge(v,v+1,1)
        if 0<j and S[i][j-1]=='.':
            mf.add_edge(v,v-1,1)
        if i<H-1 and S[i+1][j]=='.':
            mf.add_edge(v,v+W,1)
        if 0<i and S[i-1][j]=='.':
            mf.add_edge(v,v-W,1)
print(mf.flow(s,t))
r=[[c for c in S[i]] for i in range(H)]
for frm,to,_,flow in mf.edges():
    if flow==1 and frm<H*W and to<H*W:
        i,j=frm//W,frm%W
        k,l=to//W,to%W
        if frm-to==1:
            r[i][j],r[k][l]='<','>'
        elif to-frm==1:
            r[i][j],r[k][l]='>','<'
        elif frm-to==W:
            r[i][j],r[k][l]='^','v'
        else:
            r[i][j],r[k][l]='v','^'
print(*[''.join(l) for l in r],sep='\n')