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 <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
//C:flow_type,D:cost_type,E:edge_class
template<typename C, typename D, class E>
struct MinCostFlow{
    const D INF = numeric_limits<D>::max();
    vector<vector<E>> g;
    int n;
    int s, t;
    vector<int> pv, pe;
    vector<D> h;
    MinCostFlow(vector<vector<E>> _g, int _s, int _t, bool negative):g(_g),n((int)g.size()), s(_s), t(_t),pv(n),pe(n),h(n){
        assert(s != t);
        if(negative){
            vector<D> dist(n, INF);
            dist[s] = 0;
            for(int c = 0; c < n; c++){
                for(int i = 0; i < n; i++){
                    for(auto &e : g[i]){
                        if(e.cap > 0 and dist[i] < INF){
                            dist[e.to] = min(dist[e.to], dist[i] + e.cost);
                        }
                    }
                }
            }
            for(int i = 0; i < n; i++){
                h[i] += dist[i];
            }
        }
    }
    D solve(C f){
        D res = 0;
        while(f > 0){
            vector<D> dist(n, INF);
            using P = pair<D, int>;
            priority_queue<P, vector<P>, greater<P>>pq;
            dist[s] = 0;
            pq.emplace(dist[s], s);
            while(!pq.empty()){
                auto x = pq.top();
                pq.pop();
                int v = x.second;
                if(dist[v] < x.first)continue;
                for(int i = 0; i < (int) g[v].size(); i++){
                    const auto &e = g[v][i];
                    if(e.cap <= 0)continue;
                    D temp = dist[v] + e.cost + h[v] - h[e.to];
                    if(dist[e.to] > temp){
                        dist[e.to] = temp;
                        pv[e.to] = v;
                        pe[e.to] = i;
                        pq.emplace(dist[e.to], e.to);
                    }
                }
            }
            if(dist[t] == INF){
                return D(-1);
            }
            for(int i = 0; i < n; i++){
                h[i] += dist[i];
            }
            if(h[t] > 0)return res;
            C d = f;
            for(int v = t; v != s; v = pv[v]){
                d = min(d, g[pv[v]][pe[v]].cap);
            }
            f -= d;
            res += h[t] * d;
            for(int v = t; v != s; v = pv[v]){
                auto &e = g[pv[v]][pe[v]];
                e.cap -= d;
                g[v][e.rev].cap += d;
            }
        }
        return res;
    }
};
template<class C, class D, class E>
MinCostFlow<C, D, E> get_mcf(const vector<vector<E>>& g, int s, int t, bool negative = false){
    return MinCostFlow<C, D, E>(g, s, t, negative);
}
int main(){
    int n, k;
    cin >> n >> k;
   
    struct E{
        int to, rev, cap;
        ll cost;
    };
    
    vector<vector<E>> g(2 * n + 2);
    auto add_edge = [&](int from, int to, int cap, ll dist) {
        g[from].push_back(E{to, int(g[to].size()), cap, dist});
        g[to].push_back(E{from, int(g[from].size())-1, 0, -dist});
    };
    const int s = 2 * n;
    const int t = 2 * n + 1;
    rep(i,n){
        add_edge(s, i, k, 0);
        add_edge(i + n, t, k, 0);
    }
    rep(i,n)rep(j,n){
        ll x;
        cin >> x;
        add_edge(i, j + n, 1, -x);
    }
    auto mcf = get_mcf<int, ll>(g, s, t, true);
    cout << -mcf.solve(n * k) << "\n";
    vector<string> ans(n, string(n,'.'));
    rep(i,n){
        for(auto &e: mcf.g[i]){
            if(e.cap == 0)ans[i][e.to-n] = 'X';
        }
    }
    rep(i,n){
        cout << ans[i] << "\n";
    }
}