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 C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;
template<typename T>
struct MaxFlow{
  public:
    MaxFlow() : _n(0) {}
    MaxFlow(int n) : _n(n), g(n) {}//n頂点
    struct edge {
        int from, to;
        T cap, flow;
    };
    int add_edge(int from, int to, T cap) {
        int m = int(pos.size());
        pos.push_back(make_pair(from, int(g[from].size())));
        g[from].push_back(_edge{to, int(g[to].size()), cap});
        g[to].push_back(_edge{from, int(g[from].size()) - 1, 0});
        return m;
    }
    edge get_edge(int i) {
        //int m = int(pos.size());
        auto _e = g[pos[i].first][pos[i].second];
        auto _re = g[_e.to][_e.rev];
        return edge{pos[i].first, _e.to, _e.cap + _re.cap, _re.cap};
    }
    vector<edge> edges() {
        int m = int(pos.size());
        vector<edge> result;
        for (int i = 0; i < m; i++) {
            result.push_back(get_edge(i));
        }
        return result;
    }
    void change_edge(int i, T new_cap, T new_flow) {
        int m = int(pos.size());
        assert(0 <= i && i < m);
        assert(0 <= new_flow && new_flow <= new_cap);
        auto& _e = g[pos[i].first][pos[i].second];
        auto& _re = g[_e.to][_e.rev];
        _e.cap = new_cap - new_flow;
        _re.cap = new_flow;
    }
    T flow(int s, int t) {
        return flow(s, t, numeric_limits<T>::max());
    }
    T flow(int s, int t, T flow_limit) {
        vector<int> level(_n);
        vector<int> iter(_n);
        queue<int> que;
        auto bfs = [&]() {
            fill(level.begin(), level.end(), -1);
            level[s] = 0;
            queue<int> empty;
            swap(que, empty);
            que.push(s);
            while (!que.empty()) {
                int v = que.front();
                que.pop();
                for (auto e : g[v]) {
                    if (e.cap == 0 || level[e.to] >= 0) {
                        continue;
                    }
                    level[e.to] = level[v] + 1;
                    if (e.to == t) {
                        return;
                    }
                    que.push(e.to);
                }
            }
        };
        auto dfs = [&](auto self, int v, T up) {
            if (v == s) {
                return up;
            }
            T res = 0;
            int level_v = level[v];
            for (int& i = iter[v]; i < int(g[v].size()); i++) {
                _edge& e = g[v][i];
                if (level_v <= level[e.to] || g[e.to][e.rev].cap == 0) {
                    continue;
                }
                T d = self(self, e.to, std::min(up - res, g[e.to][e.rev].cap));
                if (d <= 0) {
                    continue;
                }
                g[v][i].cap += d;
                g[e.to][e.rev].cap -= d;
                res += d;
                if (res == up) {
                    break;
                }
            }
            return res;
        };
        T flow = 0;
        while (flow < flow_limit) {
            bfs();
            if (level[t] == -1) break;
            fill(iter.begin(), iter.end(), 0);
            while (flow < flow_limit) {
                T f = dfs(dfs, t, flow_limit - flow);
                if (!f) break;
                flow += f;
            }
        }
        return flow;
    }
    vector<bool> min_cut(int s) {
        vector<bool> visited(_n);
        queue<int> que;
        que.push(s);
        while (!que.empty()) {
            int p = que.front();
            que.pop();
            visited[p] = true;
            for (auto e : g[p]) {
                if (e.cap && !visited[e.to]) {
                    visited[e.to] = true;
                    que.push(e.to);
                }
            }
        }
        return visited;
    }
  private:
    int _n;
    struct _edge {
        int to, rev;
        T cap;
    };
    vector<pair<int, int>> pos;
    vector<vector<_edge>> g;
};
int main(){
  #define int long long
  int N,M;
  cin>>N>>M;
  int count=N*M;
  vector<string> t(N);
  MaxFlow<int> rock(N*M+10);
  for(int i=0;i<N;i++){
    cin>>t.at(i);
    for(int j=0;j<M-1;j++){
      if(t.at(i).at(j)=='.' && t.at(i).at(j+1)=='.'){
        if(i%2==0 && j%2==1){
          continue;
        }
        if(i%2==1 && j%2==0){
          continue;
        }
        rock.add_edge(i*M+j,i*M+j+1,1);
        //rock.add_edge(i*M+j+1,i*M+j,1);
        count++;
      }
    }
  }
  for(int i=0;i<M;i++){
    for(int j=0;j<N-1;j++){
      if(t.at(j).at(i)=='.' && t.at(j+1).at(i)=='.'){
        if(i%2==0 && j%2==1){
          continue;
        }
        if(i%2==1 && j%2==0){
          continue;
        }
        rock.add_edge(j*M+i,(j+1)*M+i,1);
        //rock.add_edge((j+1)*M+i,j*M+i,1);
        count++;
      }
    }
  }
  int start=N*M+1;
  int goal=N*M+2;
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      if(i%2==0){
        if(j%2==0){
          rock.add_edge(start,i*M+j,1);
        }
        else{
          rock.add_edge(i*M+j,goal,1);
        }
      }
      if(i%2==1){
        if(j%2==1){
          rock.add_edge(start,i*M+j,1);
        }
        else{
          rock.add_edge(i*M+j,goal,1);
        }
      }
    }
  }
  int a=rock.flow(start,goal);
  cout<<a<<endl;
  for(int i=0;i<count;i++){
    //cout<<rock.get_edge(i).from<<" "<<rock.get_edge(i).to<<" "<<rock.get_edge(i).cap<<" "<<rock.get_edge(i).flow<<endl;
    if(rock.get_edge(i).flow==1){
      int v=rock.get_edge(i).from;
      int nv=rock.get_edge(i).to;
      if(v>N*M || nv>N*M){
        continue;
      }
      if(max(nv-v,v-nv)==1 && M!=1){
        if(v<nv){
          t.at(v/M).at(v%M)='>';
          t.at(nv/M).at(nv%M)='<';
        }
        else{
          t.at(v/M).at(v%M)='<';
          t.at(nv/M).at(nv%M)='>';
        }
      }
      else{
        if(v<nv){
          t.at(v/M).at(v%M)='v';
          t.at(nv/M).at(nv%M)='^';
        }
        else{
          t.at(v/M).at(v%M)='^';
          t.at(nv/M).at(nv%M)='v';
        }
      }
    }
  }
  for(int i=0;i<N;i++){
    cout<<t.at(i)<<endl;
  }
}