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:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo LLONG_MAX
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*
各行列が従業員。
数値N*Nが仕事。
従業員はK個までとれる。
仕事は2個とられる、行列で。

かな？

addedgeは、該当する行列2通りかな

違うかも
行 -> 列ぽい？
んで移動値がコストみたいな

いけるかな

*/
typedef ll FLOW;        // フローを表す型、今回は ll 型
typedef ll COST;        // コストを表す型、今回は ll 型
const ll MAX_V = 3000;      // グラフの最大ノード数
const COST INF = 10000000000000;   // 十分大きい値

// グラフの辺の構造体
struct Edge {
  ll rev, from, to;
  FLOW cap, icap;
  COST cost;
  Edge(ll r, ll f, ll t, FLOW ca, COST co) : rev(r), from(f), to(t), cap(ca), icap(ca), cost(co) {}
};

// グラフ構造体
struct Graph {
  ll V;
  vector<Edge> list[MAX_V];

  Graph(ll n = 0) : V(n) { for (ll i = 0; i < MAX_V; ++i) list[i].clear(); }
  void init(ll n = 0) { V = n; for (ll i = 0; i < MAX_V; ++i) list[i].clear(); }
  void resize(ll n = 0) { V = n; }
  void reset() { for (ll i = 0; i < V; ++i) for (ll j = 0; j < (ll)list[i].size(); ++j) list[i][j].cap = list[i][j].icap; }
  inline vector<Edge>& operator [] (ll i) { return list[i]; }

  Edge &redge(Edge &e) {
    if (e.from != e.to) return list[e.to][e.rev];
    else return list[e.to][e.rev + 1];
  }

  void addedge(ll from, ll to, FLOW cap, COST cost) {
    list[from].push_back(Edge((ll)list[to].size(), from, to, cap, cost));
    list[to].push_back(Edge((ll)list[from].size() - 1, to, from, 0, -cost));
  }
};

// 最小費用流を求める関数
COST MinCostFlow(Graph &G, ll s, ll t, FLOW inif) {
  COST dist[MAX_V];
  ll prevv[MAX_V];
  ll preve[MAX_V];

  COST res = 0;
  FLOW f = inif;
  while (f > 0) {
    fill(dist, dist + G.V, INF);
    dist[s] = 0;
    while (true) {
      bool update = false;
      for (ll v = 0; v < G.V; ++v) {
        if (dist[v] == INF) continue;
        for (ll i = 0; i < (ll)G[v].size(); ++i) {
          Edge &e = G[v][i];
          if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
            dist[e.to] = dist[v] + e.cost;
            prevv[e.to] = v;
            preve[e.to] = i;
            update = true;
          }
        }
      }
      if (!update) break;
    }

    if (dist[t] == INF) return 0;

    FLOW d = f;
    for (ll v = t; v != s; v = prevv[v]) {
      d = min(d, G[prevv[v]][preve[v]].cap);
    }
    f -= d;
    res += dist[t] * d;
    for (ll v = t; v != s; v = prevv[v]) {
      Edge &e = G[prevv[v]][preve[v]];
      Edge &re = G.redge(e);
      e.cap -= d;
      re.cap += d;
    }
  }
  return res;
}


int main() {
  ll N, K;
  cin >> N >> K;

  // グラフの定義 (ノード数を引数に)
  Graph G(N * 2 + 2);       // +2 は S, T の分

  // スーパーノード S, T の index
  ll from = N * 2;
  ll to   = N * 2 + 1;

  // グラフに枝を張っていく
  for (ll i = 0; i < N; ++i) {
    G.addedge( from,  i, K, 0);
    G.addedge(N + i, to, K, 0);
    G.addedge(    i, to, K, 0); //任意にとる線かな
    for (ll j = 0; j < N; ++j) {
      ll gain;
      cin >> gain;

      // 従業員 i から、仕事 j (index は j+NUM_WORKER) へと、容量 1, コスト -gain の枝を張る
      G.addedge(i, N + j, 1, -gain);
    }
  }

  // 最小費用流を求める なんでN*K??
  COST res = MinCostFlow(G, from, to, N*K);

  // 出力
  cout << -res << endl;

  vector<vector<char>> C(N, vector<char>(N, '.'));
  // 誰がどの仕事に割当てられたかを出力する
  for (ll i = 0; i < N; ++i) {
    for (auto e : G[i]) {
      // 元々の容量 (e.icap) が 1 で、フローが流れて容量 (e.cap) が 0 になった部分が割り当てられたところ
      if (e.icap == 1 && e.cap == 0) {
        C[i][e.to - N] = 'X';
      }
    }
  }
  rep(i, N){
    rep(j, N){
      cout << C[i][j];
    }
    cout << endl;
  }
  return 0;
}