Problem: 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). A nonnegative integer A_{i,j} is written for each square (i,j).

You choose some of the squares so that each row and column contains at most K chosen squares. Under this constraint, calculate the maximum value of the sum of the integers written on the chosen squares. Additionally, calculate a way to choose squares that acheives the maximum.

Constraints

* 1 \leq N \leq 50
* 1 \leq K \leq N
* 0 \leq A_{i,j} \leq 10^9
* All values in Input are integer.

Input

Input is given from Standard Input in the following format:


N K
A_{1,1} A_{1,2} \cdots A_{1,N}
A_{2,1} A_{2,2} \cdots A_{2,N}
\vdots
A_{N,1} A_{N,2} \cdots A_{N,N}


Output

On the first line, print the maximum value of the sum of the integers written on the chosen squares.

On the next N lines, print a way that achieves the maximum.

Precisely, output the strings t_1,t_2,\cdots,t_N, that satisfies t_{i,j}=`X` if you choose (i,j) and t_{i,j}=`.` otherwise.

You may print any way to choose squares that maximizes the sum.

Examples

Input

3 1
5 3 2
1 4 8
7 6 9


Output

19
X..
..X
.X.


Input

3 2
10 10 1
10 10 1
1 1 10


Output

50
XX.
XX.
..X

Solution (in CPP):

Solution:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

struct MinCostFlow {
  struct edge {
    int to, cap;
    int64_t cost;
    int rev;
  };
  using P = pair<int64_t, int>;
  int V;
  vector<vector<edge>> G;
  vector<int64_t> h, dist;
  vector<int> prevv, preve;
  const int64_t INF;
  MinCostFlow(int n):V(n), G(n), h(n), dist(n), prevv(n), preve(n), INF(INT64_MAX/100000) {}

  inline int add(int from, int to, int cap, int64_t cost) {
    G[from].emplace_back((edge){to, cap, cost, (int)G[to].size()});
    G[to].emplace_back((edge){from, 0, -cost, (int)G[from].size()-1});
    return G[from].size()-1;
  }
  //最小費用流//無理な時は-1
  int64_t min_cost_flow(const int s, const int t, int f) {
    int64_t res = 0;
    while(f > 0) {
      priority_queue<P, vector<P>, greater<P>> que;
      fill(dist.begin(), dist.end(), INF);
      dist[s] = 0;
      que.emplace(0, s);
      while(!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if(dist[v] < p.first) continue;
        for(int i = 0; i < G[v].size(); i++) {
          edge &e = G[v][i];
          if(e.cap > 0 and dist[e.to] > dist[v]+e.cost+h[v]-h[e.to]) {
            dist[e.to] = dist[v]+e.cost+h[v]-h[e.to];
            prevv[e.to] = v;
            preve[e.to] = i;
            que.emplace(dist[e.to], e.to);
          }
        }
      }
      if(dist[t] == INF) return -1;
      for(int v = 0; v < V; v++) h[v] += dist[v];

      int d = f;
      for(int v = t; v != s; v = prevv[v]) d = min(d, G[prevv[v]][preve[v]].cap);
      f -= d;
      res += d*h[t];
      for(int v = t; v != s; v = prevv[v]) {
        edge &e = G[prevv[v]][preve[v]];
        e.cap -= d;
        G[v][e.rev].cap += d;
      }
    }
    return res;
  }
};

#define N 1000000000LL

//head

ll ans, f;
int n, k;
string str[50];
int rev[50][50];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  MinCostFlow mcf(n*2+2);
  const int s = n*2, t = s+1;
  rep(i, n) rep(j, n) {
    int a;
    cin >> a;
    rev[i][j] = mcf.add(i, j+n, 1, N-a);
  }
  rep(i, n) {
    mcf.add(s, i, k, 0);
    mcf.add(i+n, t, k, 0);
  }
  rep(i, k*n) {
    if(chmax(ans, N*(i+1) - (f += mcf.min_cost_flow(s, t, 1)))) {
      rep(i, n) str[i].clear();
      rep(i, n) rep(j, n) {
        if(mcf.G[i][rev[i][j]].cap) str[i] += '.';
        else str[i] += 'X';
      }
    }
  }
  cout << ans << '\n';
  rep(i, n) cout << str[i] << '\n';
}