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
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <unordered_map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;

const double EPS = 1e-9;

struct edge
{
	int to, cap, cost, rev;
	edge(int to, int cap, int cost, int rev) :to(to), cap(cap), cost(cost), rev(rev) {}
	edge() :to(-1), cap(-1), cost(-1), rev(-1) {}
};

vector<vector<edge>> G;
vector<int> h, dist, prevv, preve;

int min_cost_flow(int s, int t, int f)
{
	int res = 0;
	fill(all(h), 0);
	while (f > 0)
	{
		priority_queue<pii, vector<pii>, greater<pii>> q;
		fill(all(dist), INF);
		dist[s] = 0;
		q.push(pii(0, s));
		while (!q.empty())
		{
			pii p = q.top(); q.pop();
			int v = p.second;
			if (dist[v] < p.first)continue;
			rep(i, 0, SZ(G[v]))
			{
				edge& e = G[v][i];
				if (e.cap > 0 && 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;
					q.push(pii(dist[e.to], e.to));
				}
			}
		}
		if (dist[t] == INF)
		{
			return -1;
		}
		rep(v, 0, SZ(h))h[v] += dist[v];

		int d = f;
		for (int v = t; v != s; v = prevv[v])
		{
			chmin(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;
}

void add_edge(int from, int to, int cap, int cost)
{
	G[from].push_back(edge(to, cap, cost, SZ(G[to])));
	G[to].push_back(edge(from, 0, -cost, SZ(G[from]) - 1));
}

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, K;
	cin >> N >> K;

	G = vector<vector<edge>>(2 * N + 2);
	h = vector<int>(2 * N + 2, 0);
	dist = vector<int>(2 * N + 2, 0); 
	prevv = vector<int>(2 * N + 2, 0);
	preve = vector<int>(2 * N + 2, 0);

	int NAX = (int)1e10;

	int A;
	rep(i, 0, N)rep(j, 0, N)
	{
		cin >> A;
		add_edge(i, N + j, 1, NAX - A);
	}

	rep(i, 0, N)
	{
		add_edge(2 * N, i, K, 0);
		add_edge(N + i, 2 * N + 1, K, 0);
	}

	add_edge(2 * N, 2 * N + 1, INF, NAX);

	int res = N * K*NAX - min_cost_flow(2 * N, 2 * N + 1, N*K);
	cout << res << endl;
	rep(i, 0, N)
	{
		rep(j, 0, N)
		{
			bool f = false;
			for (auto e : G[i])
			{
				if (e.to == N + j && e.cap == 0)
				{
					f = true;
				}
			}
			if (f)
			{
				cout << 'X';
			}
			else
			{
				cout << '.';
			}
		}
		cout << endl;
	}

	return 0;
}