#include <bits/stdc++.h>
#define int long long

const int inf = 1e17;

using namespace std;

int n, cnt[2005][2005], max1=2, erase1; string a[2005], ans=""; bool trail[2005][2005];

signed main()
{
	//if i dont get an AC in my first submission i will propose to my crush
	//edit: fuck.

	{
		a[0]="}";
	}

	cin>>n>>erase1;
	for(int i=1; i<=n; i++)
	{
		cin>>a[i];
		a[0]+='}', a[i]='}'+a[i];
		cnt[i][0]=-inf, cnt[0][i]=-inf;
	}
	cnt[0][1]=erase1;
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=n; j++)
		{
			cnt[i][j]=max(cnt[i-1][j], cnt[i][j-1])-1;
			//cout<<a[i][j];
			if(a[i][j]=='a')
			{
				cnt[i][j]++;
			}
			if(cnt[i][j]>=0)
			{
				if(i+j>max1)
				{
					max1=i+j;
				}
			}
			//cout<<cnt[i][j]<<"\t";
		}
		//cout<<endl;
	}
	//cout<<max1<<endl;
	if(erase1!=0)
	{
		for(int i=1; i<max1; i++)
		{
			ans+='a';
		}
	}
	else
	{
		ans+=a[1][1];
	}
	if(max1==2*n)
	{
		for(int i=1; i<max1; i++)
		{
			cout<<"a";
		}
		return 0;
	}
	int maxi=min(n, max1-1), mini=max1-maxi;
	for(int i=maxi; i>=mini; i--)
	{
		if(cnt[i][max1-i]==0)
		{
			a[i][max1-i]='a';
		}
	}
	//cout<<"debug\n";
	max1++;
	while(max1<=2*n)
	{
		char minchar='}';
		maxi=min(n, max1-1);
		mini=max1-maxi;
		for(int i=maxi; i>=mini; i--)
		{
			if(a[i-1][max1-i]==ans[ans.length()-1]||a[i][max1-i-1]==ans[ans.length()-1])
			{
				//cout<<"ha";
				minchar=min(minchar, a[i][max1-i]);
			}
		}
		ans+=minchar;
		max1++;
	}
	cout<<ans;
}


#include <bits/stdc++.h>
#define int long long

const int inf = 1e17;

using namespace std;

int n, cnt[2005][2005], max1=2, erase1; string a[2005], ans=""; bool used[2005][2005];

signed main()
{
	//if i dont get an AC in my first submission i will propose to my crush

	//edit: fuck.

	//edit: god damn it so many dumb mistakes

	//edit: lol 4 times im debugging by submitting right now ffs. this time if gonna be an AC :>

	//edit: okey 5 times enough for today

	//edit: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

	//edit: wrong...answer...on...test.. .. 7...3

	//edit: 74 god please save me from this madness...

	//edit: lol now 49 i can make a hentai code from this
	{
		a[0]="}";
		memset(used, 0, sizeof(used));
	}

	cin>>n>>erase1;
	for(int i=1; i<=n; i++)
	{
		cin>>a[i];
		a[0]+='}', a[i]='}'+a[i];
		cnt[i][0]=-inf, cnt[0][i]=-inf;
	}
	cnt[0][1]=erase1;
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=n; j++)
		{
			cnt[i][j]=max(cnt[i-1][j], cnt[i][j-1])-1;
			//cout<<a[i][j];
			if(a[i][j]=='a')
			{
				cnt[i][j]++;
			}
			if(cnt[i][j]>=0)
			{
				if(i+j>max1)
				{
					max1=i+j;
				}
			}
			//cout<<cnt[i][j]<<"\t";
		}
		//cout<<endl;
	}
	//cout<<max1<<endl;
	if(erase1!=0)
	{
		for(int i=1; i<max1; i++)
		{
			ans+='a';
		}
	}
	else
	{
		ans+=a[1][1];
	}
	if(max1==2*n)
	{
		if(erase1==0&&n==1)
		{
			cout<<a[1][1];
		}
		else for(int i=1; i<max1; i++)
		{
			cout<<"a";
		}
		return 0;
	}
	cnt[1][1]=0;
	int maxi=min(n, max1-1), mini=max1-maxi;
	for(int i=maxi; i>=mini; i--)
	{
		if(cnt[i][max1-i]==0)
		{
			a[i][max1-i]='a';
			used[i][max1-i]=true;
		}
	}
	//cout<<"debug\n";
	max1++;
	while(max1<=2*n)
	{
		char minchar='}';
		maxi=min(n, max1-1);
		mini=max1-maxi;
		for(int i=maxi; i>=mini; i--)
		{
			if(used[i-1][max1-i]||used[i][max1-i-1])
			{
				//cout<<"ha";
				minchar=min(minchar, a[i][max1-i]);
			}
		}
		for(int i=maxi; i>=mini; i--)
		{
			if(a[i][max1-i]==minchar&&(used[i-1][max1-i]||used[i][max1-i-1]))
			{
				used[i][max1-i]=true;
			}
		}
		ans+=minchar;
		max1++;
	}
	cout<<ans;
}


#include <bits/stdc++.h>
#define int long long

const int inf = 1e17;

using namespace std;

int n, cnt[2005][2005], max1=2, erase1; string a[2005], ans=""; bool used[2005][2005];

signed main()
{
	//if i dont get an AC in my first submission i will propose to my crush

	//edit: fuck.

	//edit: god damn it so many dumb mistakes

	//edit: lol 4 times im debugging by submitting right now ffs. this time if gonna be an AC :>

	//edit: okey 5 times enough for today

	//edit: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
	{
		a[0]="}";
		memset(used, 0, sizeof(used));
	}

	cin>>n>>erase1;
	for(int i=1; i<=n; i++)
	{
		cin>>a[i];
		a[0]+='}', a[i]='}'+a[i];
		cnt[i][0]=-inf, cnt[0][i]=-inf;
	}
	cnt[0][1]=erase1;
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=n; j++)
		{
			cnt[i][j]=max(cnt[i-1][j], cnt[i][j-1])-1;
			//cout<<a[i][j];
			if(a[i][j]=='a')
			{
				cnt[i][j]++;
			}
			if(cnt[i][j]>=0)
			{
				if(i+j>max1)
				{
					max1=i+j;
				}
			}
			//cout<<cnt[i][j]<<"\t";
		}
		//cout<<endl;
	}
	//cout<<max1<<endl;
	if(erase1!=0)
	{
		for(int i=1; i<max1; i++)
		{
			ans+='a';
		}
	}
	else
	{
		ans+=a[1][1];
	}
	if(max1==2*n)
	{
		for(int i=1; i<max1; i++)
		{
			cout<<"a";
		}
		return 0;
	}
	cnt[1][1]=0;
	int maxi=min(n, max1-1), mini=max1-maxi;
	for(int i=maxi; i>=mini; i--)
	{
		if(cnt[i][max1-i]==0)
		{
			a[i][max1-i]='a';
			used[i][max1-i]=true;
		}
	}
	//cout<<"debug\n";
	max1++;
	while(max1<=2*n)
	{
		char minchar='}';
		maxi=min(n, max1-1);
		mini=max1-maxi;
		for(int i=maxi; i>=mini; i--)
		{
			if(used[i-1][max1-i]||used[i][max1-i-1])
			{
				//cout<<"ha";
				minchar=min(minchar, a[i][max1-i]);
			}
		}
		for(int i=maxi; i>=mini; i--)
		{
			if(a[i][max1-i]==minchar&&(used[i-1][max1-i]||used[i][max1-i-1]))
			{
				used[i][max1-i]=true;
			}
		}
		ans+=minchar;
		max1++;
	}
	cout<<ans;
}


#include <bits/stdc++.h>
#define int long long

const int inf = 1e17;

using namespace std;

int n, cnt[2005][2005], max1=2, erase1; string a[2005], ans=""; bool used[2005][2005];

signed main()
{
	//if i dont get an AC in my first submission i will propose to my crush

	//edit: fuck.

	//edit: god damn it so many dumb mistakes

	//edit: lol 4 times im debugging by submitting right now ffs. this time if gonna be an AC :>

	//edit: okey 5 times enough for today

	//edit: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

	//edit: wrong...answer...on...test.. .. 7...3

        //edit: 74 god please save me from this madness...
	{
		a[0]="}";
		memset(used, 0, sizeof(used));
	}

	cin>>n>>erase1;
	for(int i=1; i<=n; i++)
	{
		cin>>a[i];
		a[0]+='}', a[i]='}'+a[i];
		cnt[i][0]=-inf, cnt[0][i]=-inf;
	}
	cnt[0][1]=erase1;
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=n; j++)
		{
			cnt[i][j]=max(cnt[i-1][j], cnt[i][j-1])-1;
			//cout<<a[i][j];
			if(a[i][j]=='a')
			{
				cnt[i][j]++;
			}
			if(cnt[i][j]>=0)
			{
				if(i+j>max1)
				{
					max1=i+j;
				}
			}
			//cout<<cnt[i][j]<<"\t";
		}
		//cout<<endl;
	}
	//cout<<max1<<endl;
	if(erase1!=0)
	{
		for(int i=1; i<max1; i++)
		{
			ans+='a';
		}
	}
	else
	{
		ans+=a[1][1];
	}
	if(max1==2*n)
	{
		if(erase1==0)
		{
			cout<<a[1][1];
		}
		else for(int i=1; i<max1; i++)
		{
			cout<<"a";
		}
		return 0;
	}
	cnt[1][1]=0;
	int maxi=min(n, max1-1), mini=max1-maxi;
	for(int i=maxi; i>=mini; i--)
	{
		if(cnt[i][max1-i]==0)
		{
			a[i][max1-i]='a';
			used[i][max1-i]=true;
		}
	}
	//cout<<"debug\n";
	max1++;
	while(max1<=2*n)
	{
		char minchar='}';
		maxi=min(n, max1-1);
		mini=max1-maxi;
		for(int i=maxi; i>=mini; i--)
		{
			if(used[i-1][max1-i]||used[i][max1-i-1])
			{
				//cout<<"ha";
				minchar=min(minchar, a[i][max1-i]);
			}
		}
		for(int i=maxi; i>=mini; i--)
		{
			if(a[i][max1-i]==minchar&&(used[i-1][max1-i]||used[i][max1-i-1]))
			{
				used[i][max1-i]=true;
			}
		}
		ans+=minchar;
		max1++;
	}
	cout<<ans;
}


#include <bits/stdc++.h>
#define int long long

const int inf = 1e17;

using namespace std;

int n, cnt[2005][2005], max1=2, erase1; string a[2005], ans=""; bool used[2005][2005];

signed main()
{
	//if i dont get an AC in my first submission i will propose to my crush

	//edit: fuck.

	//edit: god damn it so many dumb mistakes

	{
		a[0]="}";
	}

	cin>>n>>erase1;
	for(int i=1; i<=n; i++)
	{
		cin>>a[i];
		a[0]+='}', a[i]='}'+a[i];
		cnt[i][0]=-inf, cnt[0][i]=-inf;
	}
	cnt[0][1]=erase1;
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=n; j++)
		{
			cnt[i][j]=max(cnt[i-1][j], cnt[i][j-1])-1;
			//cout<<a[i][j];
			if(a[i][j]=='a')
			{
				cnt[i][j]++;
			}
			if(cnt[i][j]>=0)
			{
				if(i+j>max1)
				{
					max1=i+j;
				}
			}
			//cout<<cnt[i][j]<<"\t";
		}
		//cout<<endl;
	}
	//cout<<max1<<endl;
	if(erase1!=0)
	{
		for(int i=1; i<max1; i++)
		{
			ans+='a';
		}
	}
	else
	{
		ans+=a[1][1];
	}
	if(max1==2*n)
	{
		for(int i=1; i<max1; i++)
		{
			cout<<"a";
		}
		return 0;
	}
	int maxi=min(n, max1-1), mini=max1-maxi;
	for(int i=maxi; i>=mini; i--)
	{
		if(cnt[i][max1-i]==0)
		{
			a[i][max1-i]='a';
			used[i][max1-i]=true;
		}
	}
	//cout<<"debug\n";
	max1++;
	while(max1<=2*n)
	{
		char minchar='}';
		maxi=min(n, max1-1);
		mini=max1-maxi;
		for(int i=maxi; i>=mini; i--)
		{
			if(used[i-1][max1-i]||used[i][max1-i-1])
			{
				//cout<<"ha";
				minchar=min(minchar, a[i][max1-i]);
			}
		}
		for(int i=maxi; i>=mini; i--)
		{
			if(a[i][max1-i]==minchar)
			{
				used[i][max1-i]=true;
			}
		}
		ans+=minchar;
		max1++;
	}
	cout<<ans;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);

	int n, k;
	cin>> n >> k;

	char arr[n][n];
	int dp[n][n];

	memset(arr, 0, sizeof(arr));

	int maxLocatedAs = 0;
	set< pair<int,int> > originalSet;

	for(int i = 0; i < n; i++){
		for(int j = 0; j <n; j++){
			cin >> arr[i][j];

			if(i > 0 || j > 0){

				if(j == 0){
					dp[i][j] = dp[i-1][j];
				}
				else if(i == 0){
					dp[i][j] =  dp[i][j-1];
				}
				else{
					dp[i][j] = min(dp[i-1][j], dp[i][j-1]);
				}
				if(arr[i][j] != 'a'){
					dp[i][j] = dp[i][j]+ 1;
				}
			}else{
				if(arr[i][j] == 'a'){
					dp[i][j] = 0;
				}else{
					dp[i][j] = 1;
				}
			}

			if(dp[i][j] == k){
				if(maxLocatedAs < i + j){
					maxLocatedAs = i + j;
				}
			}
		}
	}

	if(k >= 2*n + 1){
		for(int i = 0; i < 2*n +1; i++){
			cout<<"a";
		}
		cout<<endl;
		return 0;
	}

	int cnt = 0;

	for(int i = 0; i <n; i++){
		for(int j = 0; j <n; j++){

			if(dp[i][j] == k && i+j == maxLocatedAs){
				originalSet.insert(make_pair(i,j));

				if(maxLocatedAs == 0){
					cout<<arr[i][j];
					cnt++;
					break;
				}
			}
			//cout << dp[i][j] << " ";
		}
		//cout  << endl;
	}

	if(maxLocatedAs){
		for(int i = 0; i < maxLocatedAs + 1; i++){
			cout<<"a";
			cnt++;
		}
	}

	if(originalSet.size() == 0){
		cout<<arr[0][0];
		cnt++;
		originalSet.insert(make_pair(0,0));
	}

	while(cnt < 2*n - 1){

		char smallestChar = 'z';

		set <pair <int, int> > tempSet;

		for(set <pair <int, int> > :: iterator itr = originalSet.begin(); itr != originalSet.end(); itr++) {

			int i = itr -> first;
        	int j = itr -> second;

        	if(i < n - 1){
        		if(arr[i+1][j] < smallestChar){
        			smallestChar = arr[i+1][j];
        			tempSet.clear();
        			tempSet.insert(make_pair(i+1, j));
        		}else if(arr[i+1][j] == smallestChar){
           			tempSet.insert(make_pair(i+1, j));
        		}
        	}
        	if(j < n - 1){
        		if(arr[i][j+1] < smallestChar){
        			smallestChar = arr[i][j+1];
        			tempSet.clear();
        			tempSet.insert(make_pair(i, j+1));
        		}else if(arr[i][j+1] == smallestChar){
           			tempSet.insert(make_pair(i, j+1));
        		}
        	}

		}

		cout << smallestChar;
		originalSet = tempSet;
		cnt++;
	}

    cout << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);

	int n, k;
	cin>> n >> k;
	char arr[n][n];
	int dp[n][n];

	memset(arr, 0, sizeof(arr));

	int maxLocatedAs = 0;
	set< pair<int,int> > originalSet;

	for(int i = 0; i < n; i++){
		for(int j = 0; j <n; j++){
			cin >> arr[i][j];

			if(i > 0 || j > 0){

				if(j == 0){
					dp[i][j] = dp[i-1][j];
				}
				else if(i == 0){
					dp[i][j] =  dp[i][j-1];
				}
				else{
					dp[i][j] = min(dp[i-1][j], dp[i][j-1]);
				}
				if(arr[i][j] != 'a'){
					dp[i][j] = dp[i][j]+ 1;
				}
			}else{
				if(arr[i][j] == 'a'){
					dp[i][j] = 0;
				}else{
					dp[i][j] = 1;
				}
			}

			if(dp[i][j] == k){
				if(maxLocatedAs < i + j){
					maxLocatedAs = i + j;
				}
			}
		}
	}

	for(int i = 0; i <n; i++){
		for(int j = 0; j <n; j++){

			if(dp[i][j] == k && i+j == maxLocatedAs){
				originalSet.insert(make_pair(i,j));
				//cout << i << "--" << j << endl;
			}

			//cout << dp[i][j] << " ";
		}
		//cout  << endl;
	}

	for(int i = 0; i <= maxLocatedAs; i++){
		cout<<"a";
	}

	int cnt = 0;
	while(cnt < (2*n -2 - maxLocatedAs)){

		char smallestChar = 'z';

		set <pair <int, int> > tempSet;

		for(set <pair <int, int> > :: iterator itr = originalSet.begin(); itr != originalSet.end(); itr++) {

			int i = itr -> first;
        	int j = itr -> second;

        	if(i < n - 1){
        		if(arr[i+1][j] < smallestChar){
        			smallestChar = arr[i+1][j];
        			tempSet.clear();
        			tempSet.insert(make_pair(i+1, j));
        		}else if(arr[i+1][j] == smallestChar){
           			tempSet.insert(make_pair(i+1, j));
        		}
        	}
        	if(j < n - 1){
        		if(arr[i][j+1] < smallestChar){
        			smallestChar = arr[i][j+1];
        			tempSet.clear();
        			tempSet.insert(make_pair(i, j+1));
        		}else if(arr[i][j+1] == smallestChar){
           			tempSet.insert(make_pair(i, j+1));
        		}
        	}

		}

		cout << smallestChar;
		originalSet = tempSet;
		cnt++;
	}

    cout << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);

	int n, k;
	cin>> n >> k;
	char arr[n][n];
	int dp[n][n];

	memset(arr, 0, sizeof(arr));

	int maxLocatedAs = 0;
	set< pair<int,int> > originalSet;

	for(int i = 0; i < n; i++){
		for(int j = 0; j <n; j++){
			cin >> arr[i][j];

			if(i > 0 || j > 0){

				if(j == 0){
					dp[i][j] = dp[i-1][j];
				}
				else if(i == 0){
					dp[i][j] =  dp[i][j-1];
				}
				else{
					dp[i][j] = min(dp[i-1][j], dp[i][j-1]);
				}
				if(arr[i][j] != 'a'){
					dp[i][j] = dp[i][j]+ 1;
				}
			}else{
				if(arr[i][j] == 'a'){
					dp[i][j] = 0;
				}else{
					dp[i][j] = 1;
				}
			}

			if(dp[i][j] == k){
				if(maxLocatedAs < i + j){
					maxLocatedAs = i + j;
				}
			}
		}
	}

	int cnt = 0;

	for(int i = 0; i <n; i++){
		for(int j = 0; j <n; j++){

			if(dp[i][j] == k && i+j == maxLocatedAs){
				originalSet.insert(make_pair(i,j));

				if(maxLocatedAs == 0){
					cout<<arr[i][j];
					cnt++;
					break;
				}
			}
			//cout << dp[i][j] << " ";
		}
		//cout  << endl;
	}

	if(maxLocatedAs){
		for(int i = 0; i < maxLocatedAs + 1; i++){
			cout<<"a";
			cnt++;
		}
	}

	while(cnt < 2*n - 1){

		char smallestChar = 'z';

		set <pair <int, int> > tempSet;

		for(set <pair <int, int> > :: iterator itr = originalSet.begin(); itr != originalSet.end(); itr++) {

			int i = itr -> first;
        	int j = itr -> second;

        	if(i < n - 1){
        		if(arr[i+1][j] < smallestChar){
        			smallestChar = arr[i+1][j];
        			tempSet.clear();
        			tempSet.insert(make_pair(i+1, j));
        		}else if(arr[i+1][j] == smallestChar){
           			tempSet.insert(make_pair(i+1, j));
        		}
        	}
        	if(j < n - 1){
        		if(arr[i][j+1] < smallestChar){
        			smallestChar = arr[i][j+1];
        			tempSet.clear();
        			tempSet.insert(make_pair(i, j+1));
        		}else if(arr[i][j+1] == smallestChar){
           			tempSet.insert(make_pair(i, j+1));
        		}
        	}

		}

		cout << smallestChar;
		originalSet = tempSet;
		cnt++;
	}

    cout << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);

	int n, k;
	cin>> n >> k;
	char arr[n][n];
	int dp[n][n];

	memset(arr, 0, sizeof(arr));

	int maxLocatedAs = 0;
	set< pair<int,int> > originalSet;

	for(int i = 0; i < n; i++){
		for(int j = 0; j <n; j++){
			cin >> arr[i][j];

			if(i > 0 || j > 0){

				if(j == 0){
					dp[i][j] = dp[i-1][j];
				}
				else if(i == 0){
					dp[i][j] =  dp[i][j-1];
				}
				else{
					dp[i][j] = min(dp[i-1][j], dp[i][j-1]);
				}
				if(arr[i][j] != 'a'){
					dp[i][j] = dp[i][j]+ 1;
				}
			}else{
				if(arr[i][j] == 'a'){
					dp[i][j] = 0;
				}else{
					dp[i][j] = 1;
				}
			}

			if(dp[i][j] == k){
				if(maxLocatedAs < i + j){
					maxLocatedAs = i + j;
				}
			}
		}
	}

	int cnt = 0;

	for(int i = 0; i <n; i++){
		for(int j = 0; j <n; j++){

			if(dp[i][j] == k && i+j == maxLocatedAs){
				originalSet.insert(make_pair(i,j));

				if(maxLocatedAs == 0){
					cout<<arr[i][j];
					cnt++;
					break;
				}
			}
			//cout << dp[i][j] << " ";
		}
		//cout  << endl;
	}

	if(maxLocatedAs){
		for(int i = 0; i < maxLocatedAs + 1; i++){
			cout<<"a";
			cnt++;
		}
	}

	if(originalSet.size() == 0){
		originalSet.insert(make_pair(0,0));
	}

	while(cnt < 2*n - 1){

		char smallestChar = 'z';

		set <pair <int, int> > tempSet;

		for(set <pair <int, int> > :: iterator itr = originalSet.begin(); itr != originalSet.end(); itr++) {

			int i = itr -> first;
        	int j = itr -> second;

        	if(i < n - 1){
        		if(arr[i+1][j] < smallestChar){
        			smallestChar = arr[i+1][j];
        			tempSet.clear();
        			tempSet.insert(make_pair(i+1, j));
        		}else if(arr[i+1][j] == smallestChar){
           			tempSet.insert(make_pair(i+1, j));
        		}
        	}
        	if(j < n - 1){
        		if(arr[i][j+1] < smallestChar){
        			smallestChar = arr[i][j+1];
        			tempSet.clear();
        			tempSet.insert(make_pair(i, j+1));
        		}else if(arr[i][j+1] == smallestChar){
           			tempSet.insert(make_pair(i, j+1));
        		}
        	}

		}

		cout << smallestChar;
		originalSet = tempSet;
		cnt++;
	}

    cout << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);

	int n, k;
	cin>> n >> k;

	char arr[n][n];
	int dp[n][n];

	memset(arr, 0, sizeof(arr));

	int maxLocatedAs = 0;
	set< pair<int,int> > originalSet;

	for(int i = 0; i < n; i++){
		for(int j = 0; j <n; j++){
			cin >> arr[i][j];

			if(i > 0 || j > 0){

				if(j == 0){
					dp[i][j] = dp[i-1][j];
				}
				else if(i == 0){
					dp[i][j] =  dp[i][j-1];
				}
				else{
					dp[i][j] = min(dp[i-1][j], dp[i][j-1]);
				}
				if(arr[i][j] != 'a'){
					dp[i][j] = dp[i][j]+ 1;
				}
			}else{
				if(arr[i][j] == 'a'){
					dp[i][j] = 0;
				}else{
					dp[i][j] = 1;
				}
			}

			if(dp[i][j] == k){
				if(maxLocatedAs < i + j){
					maxLocatedAs = i + j;
				}
			}
		}
	}

	if(k >= 2*n - 1 || maxLocatedAs + 1 < k ){
		for(int i = 0; i < 2*n - 1; i++){
			cout<<"a";
		}
		//cout<<endl;
		return 0;
	}

	int cnt = 0;

	for(int i = 0; i <n; i++){
		for(int j = 0; j <n; j++){

			if(dp[i][j] == k && i+j == maxLocatedAs){
				originalSet.insert(make_pair(i,j));

				if(maxLocatedAs == 0){
					cout<<arr[i][j];
					cnt++;
					break;
				}
			}
			//cout << dp[i][j] << " ";
		}
		//cout  << endl;
	}

	if(maxLocatedAs){
		for(int i = 0; i < maxLocatedAs + 1; i++){
			cout<<"a";
			cnt++;
		}
	}

	if(originalSet.size() == 0){
		cout<<arr[0][0];
		cnt++;
		originalSet.insert(make_pair(0,0));
	}

	while(cnt < 2*n - 1){

		char smallestChar = 'z';

		set <pair <int, int> > tempSet;

		for(set <pair <int, int> > :: iterator itr = originalSet.begin(); itr != originalSet.end(); itr++) {

			int i = itr -> first;
        	int j = itr -> second;

        	if(i < n - 1){
        		if(arr[i+1][j] < smallestChar){
        			smallestChar = arr[i+1][j];
        			tempSet.clear();
        			tempSet.insert(make_pair(i+1, j));
        		}else if(arr[i+1][j] == smallestChar){
           			tempSet.insert(make_pair(i+1, j));
        		}
        	}
        	if(j < n - 1){
        		if(arr[i][j+1] < smallestChar){
        			smallestChar = arr[i][j+1];
        			tempSet.clear();
        			tempSet.insert(make_pair(i, j+1));
        		}else if(arr[i][j+1] == smallestChar){
           			tempSet.insert(make_pair(i, j+1));
        		}
        	}

		}

		cout << smallestChar;
		originalSet = tempSet;
		cnt++;
	}

    cout << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);

	int n, k;
	cin>> n >> k;
	char arr[n][n];
	int dp[n][n];

	memset(arr, 0, sizeof(arr));

	int maxLocatedAs = 0;
	set< pair<int,int> > originalSet;

	for(int i = 0; i < n; i++){
		for(int j = 0; j <n; j++){
			cin >> arr[i][j];

			if(i > 0 || j > 0){

				if(j == 0){
					dp[i][j] = dp[i-1][j];
				}
				else if(i == 0){
					dp[i][j] =  dp[i][j-1];
				}
				else{
					dp[i][j] = min(dp[i-1][j], dp[i][j-1]);
				}
				if(arr[i][j] != 'a'){
					dp[i][j] = dp[i][j]+ 1;
				}
			}else{
				if(arr[i][j] == 'a'){
					dp[i][j] = 0;
				}else{
					dp[i][j] = 1;
				}
			}

			if(dp[i][j] == k){
				if(maxLocatedAs < i + j){
					maxLocatedAs = i + j;
				}
			}
		}
	}

	int cnt = 0;

	for(int i = 0; i <n; i++){
		for(int j = 0; j <n; j++){

			if(dp[i][j] == k && i+j == maxLocatedAs){
				originalSet.insert(make_pair(i,j));

				if(maxLocatedAs == 0){
					cout<<arr[i][j];
					cnt++;
					break;
				}
			}
			//cout << dp[i][j] << " ";
		}
		//cout  << endl;
	}

	if(maxLocatedAs){
		for(int i = 0; i < maxLocatedAs + 1; i++){
			cout<<"a";
			cnt++;
		}
	}

	if(originalSet.size() == 0){
		cout<<arr[0][0];
		cnt++;
		originalSet.insert(make_pair(0,0));
	}

	while(cnt < 2*n - 1){

		char smallestChar = 'z';

		set <pair <int, int> > tempSet;

		for(set <pair <int, int> > :: iterator itr = originalSet.begin(); itr != originalSet.end(); itr++) {

			int i = itr -> first;
        	int j = itr -> second;

        	if(i < n - 1){
        		if(arr[i+1][j] < smallestChar){
        			smallestChar = arr[i+1][j];
        			tempSet.clear();
        			tempSet.insert(make_pair(i+1, j));
        		}else if(arr[i+1][j] == smallestChar){
           			tempSet.insert(make_pair(i+1, j));
        		}
        	}
        	if(j < n - 1){
        		if(arr[i][j+1] < smallestChar){
        			smallestChar = arr[i][j+1];
        			tempSet.clear();
        			tempSet.insert(make_pair(i, j+1));
        		}else if(arr[i][j+1] == smallestChar){
           			tempSet.insert(make_pair(i, j+1));
        		}
        	}

		}

		cout << smallestChar;
		originalSet = tempSet;
		cnt++;
	}

    cout << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);

	int n, k;
	cin>> n >> k;

	char arr[n][n];
	int dp[n][n];

	memset(arr, 0, sizeof(arr));

	int maxLocatedAs = 0;
	set< pair<int,int> > originalSet;

	for(int i = 0; i < n; i++){
		for(int j = 0; j <n; j++){
			cin >> arr[i][j];

			if(i > 0 || j > 0){

				if(j == 0){
					dp[i][j] = dp[i-1][j];
				}
				else if(i == 0){
					dp[i][j] =  dp[i][j-1];
				}
				else{
					dp[i][j] = min(dp[i-1][j], dp[i][j-1]);
				}
				if(arr[i][j] != 'a'){
					dp[i][j] = dp[i][j]+ 1;
				}
			}else{
				if(arr[i][j] == 'a'){
					dp[i][j] = 0;
				}else{
					dp[i][j] = 1;
				}
			}

			if(dp[i][j] == k){
				if(maxLocatedAs < i + j){
					maxLocatedAs = i + j;
				}
			}
		}
	}

	if(k >= 2*n - 1 || maxLocatedAs + 1 < k || dp[n-1][n-1] < k){
		for(int i = 0; i < 2*n - 1; i++){
			cout<<"a";
		}
		//cout<<endl;
		return 0;
	}

	int cnt = 0;

	for(int i = 0; i <n; i++){
		for(int j = 0; j <n; j++){

			if(dp[i][j] == k && i+j == maxLocatedAs){
				originalSet.insert(make_pair(i,j));

				if(maxLocatedAs == 0){
					cout<<arr[i][j];
					cnt++;
					break;
				}
			}
			//cout << dp[i][j] << " ";
		}
		//cout  << endl;
	}

	if(maxLocatedAs){
		for(int i = 0; i < maxLocatedAs + 1; i++){
			cout<<"a";
			cnt++;
		}
	}

	if(originalSet.size() == 0){
		cout<<arr[0][0];
		cnt++;
		originalSet.insert(make_pair(0,0));
	}

	while(cnt < 2*n - 1){

		char smallestChar = 'z';

		set <pair <int, int> > tempSet;

		for(set <pair <int, int> > :: iterator itr = originalSet.begin(); itr != originalSet.end(); itr++) {

			int i = itr -> first;
        	int j = itr -> second;

        	if(i < n - 1){
        		if(arr[i+1][j] < smallestChar){
        			smallestChar = arr[i+1][j];
        			tempSet.clear();
        			tempSet.insert(make_pair(i+1, j));
        		}else if(arr[i+1][j] == smallestChar){
           			tempSet.insert(make_pair(i+1, j));
        		}
        	}
        	if(j < n - 1){
        		if(arr[i][j+1] < smallestChar){
        			smallestChar = arr[i][j+1];
        			tempSet.clear();
        			tempSet.insert(make_pair(i, j+1));
        		}else if(arr[i][j+1] == smallestChar){
           			tempSet.insert(make_pair(i, j+1));
        		}
        	}

		}

		cout << smallestChar;
		originalSet = tempSet;
		cnt++;
	}

    cout << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);

	int n, k;
	cin>> n >> k;

	char arr[n][n];
	int dp[n][n];

	memset(arr, 0, sizeof(arr));

	int maxLocatedAs = 0;
	set< pair<int,int> > originalSet;

	for(int i = 0; i < n; i++){
		for(int j = 0; j <n; j++){
			cin >> arr[i][j];

			if(i > 0 || j > 0){

				if(j == 0){
					dp[i][j] = dp[i-1][j];
				}
				else if(i == 0){
					dp[i][j] =  dp[i][j-1];
				}
				else{
					dp[i][j] = min(dp[i-1][j], dp[i][j-1]);
				}
				if(arr[i][j] != 'a'){
					dp[i][j] = dp[i][j]+ 1;
				}
			}else{
				if(arr[i][j] == 'a'){
					dp[i][j] = 0;
				}else{
					dp[i][j] = 1;
				}
			}

			if(dp[i][j] == k){
				if(maxLocatedAs < i + j){
					maxLocatedAs = i + j;
				}
			}
		}
	}

	if(k >= 2*n - 1 || maxLocatedAs + 1 < k || dp[n-1][n-1] < k){
		for(int i = 0; i < 2*n - 1; i++){
			cout<<"a";
		}
		//cout<<endl;
		return 0;
	}

	int cnt = 0;

	for(int i = 0; i <n; i++){
		for(int j = 0; j <n; j++){

			if(dp[i][j] == k && i+j == maxLocatedAs){
				originalSet.insert(make_pair(i,j));

				if(maxLocatedAs == 0 ){
					if(k != 0){
						cout << "a";
					}else{
						cout<<arr[i][j];
					}
					cnt++;
					break;
				}
			}
			//cout << dp[i][j] << " ";
		}
		//cout  << endl;
	}

	if(maxLocatedAs){
		for(int i = 0; i < maxLocatedAs + 1; i++){
			cout<<"a";
			cnt++;
		}
	}

	if(originalSet.size() == 0){
		cout<<arr[0][0];
		cnt++;
		originalSet.insert(make_pair(0,0));
	}

	while(cnt < 2*n - 1){

		char smallestChar = 'z';

		set <pair <int, int> > tempSet;

		for(set <pair <int, int> > :: iterator itr = originalSet.begin(); itr != originalSet.end(); itr++) {

			int i = itr -> first;
        	int j = itr -> second;

        	if(i < n - 1){
        		if(arr[i+1][j] < smallestChar){
        			smallestChar = arr[i+1][j];
        			tempSet.clear();
        			tempSet.insert(make_pair(i+1, j));
        		}else if(arr[i+1][j] == smallestChar){
           			tempSet.insert(make_pair(i+1, j));
        		}
        	}
        	if(j < n - 1){
        		if(arr[i][j+1] < smallestChar){
        			smallestChar = arr[i][j+1];
        			tempSet.clear();
        			tempSet.insert(make_pair(i, j+1));
        		}else if(arr[i][j+1] == smallestChar){
           			tempSet.insert(make_pair(i, j+1));
        		}
        	}

		}

		cout << smallestChar;
		originalSet = tempSet;
		cnt++;
	}

    cout << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);

	int n, k;
	cin>> n >> k;

	char arr[n][n];
	int dp[n][n];

	memset(arr, 0, sizeof(arr));

	int maxLocatedAs = 0;
	set< pair<int,int> > originalSet;

	for(int i = 0; i < n; i++){
		for(int j = 0; j <n; j++){
			cin >> arr[i][j];

			if(i > 0 || j > 0){

				if(j == 0){
					dp[i][j] = dp[i-1][j];
				}
				else if(i == 0){
					dp[i][j] =  dp[i][j-1];
				}
				else{
					dp[i][j] = min(dp[i-1][j], dp[i][j-1]);
				}
				if(arr[i][j] != 'a'){
					dp[i][j] = dp[i][j]+ 1;
				}
			}else{
				if(arr[i][j] == 'a'){
					dp[i][j] = 0;
				}else{
					dp[i][j] = 1;
				}
			}

			if(dp[i][j] == k){
				if(maxLocatedAs < i + j){
					maxLocatedAs = i + j;
				}
			}
		}
	}

	if(k >= 2*n - 1 || maxLocatedAs < k ){
		for(int i = 0; i < 2*n - 1; i++){
			cout<<"a";
		}
		//cout<<endl;
		return 0;
	}

	int cnt = 0;

	for(int i = 0; i <n; i++){
		for(int j = 0; j <n; j++){

			if(dp[i][j] == k && i+j == maxLocatedAs){
				originalSet.insert(make_pair(i,j));

				if(maxLocatedAs == 0){
					cout<<arr[i][j];
					cnt++;
					break;
				}
			}
			//cout << dp[i][j] << " ";
		}
		//cout  << endl;
	}

	if(maxLocatedAs){
		for(int i = 0; i < maxLocatedAs + 1; i++){
			cout<<"a";
			cnt++;
		}
	}

	if(originalSet.size() == 0){
		cout<<arr[0][0];
		cnt++;
		originalSet.insert(make_pair(0,0));
	}

	while(cnt < 2*n - 1){

		char smallestChar = 'z';

		set <pair <int, int> > tempSet;

		for(set <pair <int, int> > :: iterator itr = originalSet.begin(); itr != originalSet.end(); itr++) {

			int i = itr -> first;
        	int j = itr -> second;

        	if(i < n - 1){
        		if(arr[i+1][j] < smallestChar){
        			smallestChar = arr[i+1][j];
        			tempSet.clear();
        			tempSet.insert(make_pair(i+1, j));
        		}else if(arr[i+1][j] == smallestChar){
           			tempSet.insert(make_pair(i+1, j));
        		}
        	}
        	if(j < n - 1){
        		if(arr[i][j+1] < smallestChar){
        			smallestChar = arr[i][j+1];
        			tempSet.clear();
        			tempSet.insert(make_pair(i, j+1));
        		}else if(arr[i][j+1] == smallestChar){
           			tempSet.insert(make_pair(i, j+1));
        		}
        	}

		}

		cout << smallestChar;
		originalSet = tempSet;
		cnt++;
	}

    cout << endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const long long N=2e3+5,
        INF=1e16+7;

long long n, k;
char a[N][N];
long long dp[N][N];
pair<long long, long long> pr[N][N];

main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>n>>k;
    for (long long i=0; i<=n; ++i){
        for (long long j=0; j<=n; ++j){
            dp[i][j]=INF;
        }
    }
    for (long long i=1; i<=n; ++i){
        for (long long j=1; j<=n; ++j){
            cin>>a[i][j];
        }
    }
    dp[1][1]=0;
    for (long long i=1; i<=n; ++i){
        for (long long j=1; j<=n; ++j){
            dp[i][j]=min(dp[i][j], min(dp[i-1][j], dp[i][j-1]));
            if (a[i][j]!='a') dp[i][j]++;
            if (dp[i][j]<=k) a[i][j]='a';
        }
    }
    vector<int>ans;
    cout<<a[1][1];
    set<pair<int, int> >q;
    q.insert(make_pair(1, 1));
    while(1){
        vector<pair<int, int> >b;
        char X='z'+1;
        for (set<pair<int, int> >::iterator it=q.begin(); it!=q.end(); ++it){
            int x, y;
            x=it->first+1;
            y=it->second;

            if (x<=n) X=min(X, a[x][y]);

            x=it->first;
            y=it->second+1;

            if (y<=n) X=min(X, a[x][y]);
        }
        for (set<pair<int, int> >::iterator it=q.begin(); it!=q.end(); ++it){
            int x, y;
            x=it->first+1;
            y=it->second;

            if (x<=n&&a[x][y]==X) b.push_back(make_pair(x, y));

            x=it->first;
            y=it->second+1;

            if (y<=n&&a[x][y]==X) b.push_back(make_pair(x, y));
        }
        if (b.size()==0) break;
        cout<<X;
        q.clear();
        for (int i=0; i<b.size(); ++i){
            q.insert(b[i]);
        }
    }
}


#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#include <stack>
#include<set>
#include<cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdio>
#include <string.h>
#include<iterator>
#include <map>
using namespace std;
// bool cmp(long long a, long long b){
//     return a > b;
// }
int  arr[3500];
string str[10];
char str_arr[5][5];
int matr[25][25], saved_matr[5][5], ish_matr[5][5];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    long long t, ch, i, curr, p = 1, x, y, weight, j, k = 0, n, m = 1, ch1, ans = 0;
    long long a, b;
    int fl, fl1, fl2, fl3;
    string s;
//    cin >> t;
    long long f, size_f, size_s, weight1, weight2;
    long long sum, k_min, k_max;
//    for (auto test_case = 0; test_case < t; test_case++) {
//    }
    cin >> n;
    long long* ar = new long long[n * n + 5];
    for (i = 0; i < n * n; i++) {
        cin >> ar[i];
        arr[ar[i]]++;
    }
    sort(ar, ar + n);
    if (n == 1){
        cout << "YES\n";
        cout << ar[0];
        return 0;
    }
    for (j = 0; j < n * n; j++) {
        if (matr[j / n][j % n] != 0) {
//            cout << j << " " << j / n << " " << j % n << " " << matr[j / n][j % n] << endl;
            continue;
        }
        k = 1;
        k = k * 2;
        if ((j / n == (n / 2)) && (n % 2 == 1))
            k = k / 2;
        k = k * 2;
        if ((j % n == (n / 2)) && (n % 2 == 1))
            k = k / 2;
        long long minim = 1e12, minind = -1;
        fl = 0;
//        cout << k << endl;
        for (i = 0; i < n * n; i++) {
//            cout << j << " " << i << " " << k << " " << ar[i] << " " << arr[ar[i]] << endl;
            if ((arr[ar[i]] >= k) && (arr[ar[i]] < minim)) {
                fl = 1;
                minim = arr[ar[i]];
                minind = i;
            }
        }
//        for (i = 0; i < n; i++){
//            for (t = 0; t < n; t++)
//                cout << matr[i][t] << " ";
//            cout << endl;
//        }
//        cout << "=================" << endl;
        if (!fl)
            break;
        else{
            matr[j / n][j % n] = ar[minind];
            matr[(n - 1) - j / n][j % n] = ar[minind];
            matr[j / n][n - 1 - j % n] = ar[minind];
            matr[(n - 1) - j / n][n - 1 - j % n] = ar[minind];
            arr[ar[minind]] -= k;
        }
    }
    if (fl){
        cout << "YES" << endl;
        for (i = 0; i < n; i++){
            for (j = 0; j < n; j++)
                cout << matr[i][j] << " ";
            cout << endl;
        }
    }else{
        cout << "NO" << endl;
//        for (i = 0; i < n; i++){
//            for (j = 0; j < n; j++)
//                cout << matr[i][j] << " ";
//            cout << endl;
//        }
    }
    return 0;
}


#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#include <stack>
#include<set>
#include<cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdio>
#include <string.h>
#include<iterator>
#include <map>
using namespace std;
// bool cmp(long long a, long long b){
//     return a > b;
// }
int  arr[3500];
string str[10];
char str_arr[5][5];
int matr[25][25], saved_matr[5][5], ish_matr[5][5];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    long long t, ch, i, curr, p = 1, x, y, weight, j, k = 0, n, m = 1, ch1, ans = 0;
    long long a, b;
    int fl, fl1, fl2, fl3;
    string s;
//    cin >> t;
    long long f, size_f, size_s, weight1, weight2;
    long long sum, k_min, k_max;
//    for (auto test_case = 0; test_case < t; test_case++) {
//    }
    cin >> n;
    long long* ar = new long long[n * n + 5];
    for (i = 0; i < n * n; i++) {
        cin >> ar[i];
        arr[ar[i]]++;
    }
    sort(ar, ar + n);
    if (n % 2 != 0)
        ch = (n * n) / 2;
    else
        ch = n / 2 * n - n / 2;
    for (j = 0; j <= ch; j++) {
        if (matr[j / n][j % n] != 0) {
//            cout << j << " " << j / n << " " << j % n << " " << matr[j / n][j % n] << endl;
            continue;
        }
        k = 1;
        if (j / n != (n - 1) - j / n)
            k = k * 2;
        if (j % n != (n - 1) - j % n)
            k = k * 2;
        fl = 0;
        for (i = 0; i < n * n; i++)
            if (arr[ar[i]] >= k) {
                arr[ar[i]] -= k;
                matr[j / n][j % n] = ar[i];
                matr[(n - 1) - j / n][j % n] = ar[i];
                matr[j / n][n - 1 - j % n] = ar[i];
                matr[(n - 1) - j / n][n - 1 - j % n] = ar[i];
                fl = 1;
                break;
            }
//        for (i = 0; i < n; i++){
//            for (t = 0; t < n; t++)
//                cout << matr[i][t] << " ";
//            cout << endl;
//        }
//        cout << "=================" << endl;
        if (!fl)
            break;
        }
    if (fl){
        cout << "YES" << endl;
        for (i = 0; i < n; i++){
            for (j = 0; j < n; j++)
                cout << matr[i][j] << " ";
            cout << endl;
        }
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#include <stack>
#include<set>
#include<cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdio>
#include <string.h>
#include<iterator>
#include <map>
using namespace std;
// bool cmp(long long a, long long b){
//     return a > b;
// }
int  arr[3500];
string str[10];
char str_arr[5][5];
int matr[25][25], saved_matr[5][5], ish_matr[5][5];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    long long t, ch, i, curr, p = 1, x, y, weight, j, k = 0, n, m = 1, ch1, ans = 0;
    long long a, b;
    int fl, fl1, fl2, fl3;
    string s;
//    cin >> t;
    long long f, size_f, size_s, weight1, weight2;
    long long sum, k_min, k_max;
//    for (auto test_case = 0; test_case < t; test_case++) {
//    }
    cin >> n;
    long long* ar = new long long[n * n + 5];
    for (i = 0; i < n * n; i++) {
        cin >> ar[i];
        arr[ar[i]]++;
    }
    sort(ar, ar + n);
    if (n % 2 != 0)
        ch = (n * n) / 2 + 1;
    else
        ch = n / 2 * n - n / 2;
    for (j = 0; j < ch; j++) {
        if (matr[j / n][j % n] != 0) {
//            cout << j << " " << j / n << " " << j % n << " " << matr[j / n][j % n] << endl;
            continue;
        }
        k = 1;
        if (j / n != (n - 1) - j / n)
            k = k * 2;
        if (j % n != (n - 1) - j % n)
            k = k * 2;
        fl = 0;
        for (i = 0; i < n * n; i++)
            if (arr[ar[i]] >= k) {
                arr[ar[i]] -= k;
                matr[j / n][j % n] = ar[i];
                matr[(n - 1) - j / n][j % n] = ar[i];
                matr[j / n][n - 1 - j % n] = ar[i];
                matr[(n - 1) - j / n][n - 1 - j % n] = ar[i];
                fl = 1;
                break;
            }
//        for (i = 0; i < n; i++){
//            for (t = 0; t < n; t++)
//                cout << matr[i][t] << " ";
//            cout << endl;
//        }
//        cout << "=================" << endl;
        if (!fl)
            break;
        }
    if (fl){
        cout << "YES" << endl;
        for (i = 0; i < n; i++){
            for (j = 0; j < n; j++)
                cout << matr[i][j] << " ";
            cout << endl;
        }
    }else{
        cout << "NO" << endl;
//        for (i = 0; i < n; i++){
//            for (j = 0; j < n; j++)
//                cout << matr[i][j] << " ";
//            cout << endl;
//        }
//        for (i = 0; i < n * n; i++)
//            cout << arr[ar[i]] << " ";
//        cout << endl;
    }
    return 0;
}


#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#include <stack>
#include<set>
#include<cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdio>
#include <string.h>
#include<iterator>
#include <map>
using namespace std;
// bool cmp(long long a, long long b){
//     return a > b;
// }
int  arr[3500];
string str[10];
char str_arr[5][5];
int matr[25][25], saved_matr[5][5], ish_matr[5][5];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    long long t, ch, i, curr, p = 1, x, y, weight, j, k = 0, n, m = 1, ch1, ans = 0;
    long long a, b;
    int fl, fl1, fl2, fl3;
    string s;
//    cin >> t;
    long long f, size_f, size_s, weight1, weight2;
    long long sum, k_min, k_max;
//    for (auto test_case = 0; test_case < t; test_case++) {
//    }
    cin >> n;
    long long* ar = new long long[n * n + 5];
    for (i = 0; i < n * n; i++) {
        cin >> ar[i];
        arr[ar[i]]++;
    }
    sort(ar, ar + n);
    if (n == 1){
        cout << "YES\n";
        cout << ar[0];
        return 0;
    }
    for (j = 0; j < n * n; j++) {
        if (matr[j / n][j % n] != 0) {
//            cout << j << " " << j / n << " " << j % n << " " << matr[j / n][j % n] << endl;
            continue;
        }
        k = 1;
        k = k * 2;
        if ((j / n == (n / 2)) && (n % 2 == 1))
            k = k / 2;
        k = k * 2;
        if ((j % n == (n / 2)) && (n % 2 == 1))
            k = k / 2;
        long long minim = 1e12, minind = -1;
        fl = 0;
//        cout << k << endl;
        for (i = 0; i < n * n; i++)
            if ((arr[ar[i]] >= k) && (arr[ar[i]] < minim)) {
                fl = 1;
                minim = arr[ar[i]];
                minind = i;
                break;
            }
//        for (i = 0; i < n; i++){
//            for (t = 0; t < n; t++)
//                cout << matr[i][t] << " ";
//            cout << endl;
//        }
//        cout << "=================" << endl;
        if (!fl)
            break;
        else{
            matr[j / n][j % n] = ar[minind];
            matr[(n - 1) - j / n][j % n] = ar[minind];
            matr[j / n][n - 1 - j % n] = ar[minind];
            matr[(n - 1) - j / n][n - 1 - j % n] = ar[minind];
            arr[ar[minind]] -= k;
        }
    }
    if (fl){
        cout << "YES" << endl;
        for (i = 0; i < n; i++){
            for (j = 0; j < n; j++)
                cout << matr[i][j] << " ";
            cout << endl;
        }
    }else{
        cout << "NO" << endl;
//        for (i = 0; i < n; i++){
//            for (j = 0; j < n; j++)
//                cout << matr[i][j] << " ";
//            cout << endl;
        }
    }
    return 0;
}


#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#include <stack>
#include<set>
#include<cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdio>
#include <string.h>
#include<iterator>
#include <map>
using namespace std;
// bool cmp(long long a, long long b){
//     return a > b;
// }
int  arr[3500];
string str[10];
char str_arr[5][5];
int matr[25][25], saved_matr[5][5], ish_matr[5][5];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    long long t, ch, i, curr, p = 1, x, y, weight, j, k = 0, n, m = 1, ch1, ans = 0;
    long long a, b;
    int fl, fl1, fl2, fl3;
    string s;
//    cin >> t;
    long long f, size_f, size_s, weight1, weight2;
    long long sum, k_min, k_max;
//    for (auto test_case = 0; test_case < t; test_case++) {
//    }
    cin >> n;
    long long* ar = new long long[n * n + 5];
    for (i = 0; i < n * n; i++) {
        cin >> ar[i];
        arr[ar[i]]++;
    }
    sort(ar, ar + n);
    for (j = 0; j < n * n; j++) {
        if (matr[j / n][j % n] != 0) {
//            cout << j << " " << j / n << " " << j % n << " " << matr[j / n][j % n] << endl;
            continue;
        }
        k = 1;
        if (j / n != (n - 1) - j / n)
            k = k * 2;
        if (j % n != (n - 1) - j % n)
            k = k * 2;
        fl = 0;
        for (i = 0; i < n * n; i++)
            if (arr[ar[i]] >= k) {
                arr[ar[i]] -= k;
                matr[j / n][j % n] = ar[i];
                matr[(n - 1) - j / n][j % n] = ar[i];
                matr[j / n][n - 1 - j % n] = ar[i];
                matr[(n - 1) - j / n][n - 1 - j % n] = ar[i];
                fl = 1;
                break;
            }
//        for (i = 0; i < n; i++){
//            for (t = 0; t < n; t++)
//                cout << matr[i][t] << " ";
//            cout << endl;
//        }
//        cout << "=================" << endl;
        if (!fl)
            break;
        }
    if (fl){
        cout << "YES" << endl;
        for (i = 0; i < n; i++){
            for (j = 0; j < n; j++)
                cout << matr[i][j] << " ";
            cout << endl;
        }
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#include <stack>
#include<set>
#include<cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdio>
#include <string.h>
#include<iterator>
#include <map>
using namespace std;
// bool cmp(long long a, long long b){
//     return a > b;
// }
int  arr[3500];
string str[10];
char str_arr[5][5];
int matr[25][25], saved_matr[5][5], ish_matr[5][5];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    long long t, ch, i, curr, p = 1, x, y, weight, j, k = 0, n, m = 1, ch1, ans = 0;
    long long a, b;
    int fl, fl1, fl2, fl3;
    string s;
//    cin >> t;
    long long f, size_f, size_s, weight1, weight2;
    long long sum, k_min, k_max;
//    for (auto test_case = 0; test_case < t; test_case++) {
//    }
    cin >> n;
    long long* ar = new long long[n * n + 5];
    for (i = 0; i < n * n; i++) {
        cin >> ar[i];
        arr[ar[i]]++;
    }
    sort(ar, ar + n);
    if (n == 1){
        cout << "YES\n";
        cout << ar[0];
        return 0;
    }
    for (j = 0; j < n * n; j++) {
        if (matr[j / n][j % n] != 0) {
//            cout << j << " " << j / n << " " << j % n << " " << matr[j / n][j % n] << endl;
            continue;
        }
        k = 1;
        k = k * 2;
        if ((j / n == (n / 2)) && (n % 2 == 1))
            k = k / 2;
        k = k * 2;
        if ((j % n == (n / 2)) && (n % 2 == 1))
            k = k / 2;
        fl = 0;
//        cout << k << endl;
        for (i = 0; i < n * n; i++)
            if (arr[ar[i]] >= k) {
                arr[ar[i]] -= k;
                matr[j / n][j % n] = ar[i];
                matr[(n - 1) - j / n][j % n] = ar[i];
                matr[j / n][n - 1 - j % n] = ar[i];
                matr[(n - 1) - j / n][n - 1 - j % n] = ar[i];
                fl = 1;
                break;
            }
//        for (i = 0; i < n; i++){
//            for (t = 0; t < n; t++)
//                cout << matr[i][t] << " ";
//            cout << endl;
//        }
//        cout << "=================" << endl;
        if (!fl)
            break;
        }
    if (fl){
        cout << "YES" << endl;
        for (i = 0; i < n; i++){
            for (j = 0; j < n; j++)
                cout << matr[i][j] << " ";
            cout << endl;
        }
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#include <stack>
#include<set>
#include<cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdio>
#include <string.h>
#include<iterator>
#include <map>
using namespace std;
// bool cmp(long long a, long long b){
//     return a > b;
// }
int  arr[3500];
string str[10];
char str_arr[5][5];
int matr[25][25], saved_matr[5][5], ish_matr[5][5];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    long long t, ch, i, curr, p = 1, x, y, weight, j, k = 0, n, m = 1, ch1, ans = 0;
    long long a, b;
    int fl, fl1, fl2, fl3;
    string s;
//    cin >> t;
    long long f, size_f, size_s, weight1, weight2;
    long long sum, k_min, k_max;
//    for (auto test_case = 0; test_case < t; test_case++) {
//    }
    cin >> n;
    long long* ar = new long long[n * n + 5];
    for (i = 0; i < n * n; i++) {
        cin >> ar[i];
        arr[ar[i]]++;
    }
    sort(ar, ar + n);
    if (n == 1){
        cout << "YES\n";
        cout << ar[0];
        return 0;
    }
    for (j = 0; j < n * n; j++) {
        if (matr[j / n][j % n] != 0) {
//            cout << j << " " << j / n << " " << j % n << " " << matr[j / n][j % n] << endl;
            continue;
        }
        k = 1;
        k = k * 2;
        if ((j / n == (n / 2)) && (n % 2 == 1))
            k = k / 2;
        k = k * 2;
        if ((j % n == (n / 2)) && (n % 2 == 1))
            k = k / 2;
        long long minim = 1e12, minind = -1;
        fl = 0;
//        cout << k << endl;
        for (i = 0; i < n * n; i++)
            if ((arr[ar[i]] >= k) && (arr[ar[i]] < minim)) {
                fl = 1;
                minim = arr[ar[i]];
                minind = i;
                break;
            }
//        for (i = 0; i < n; i++){
//            for (t = 0; t < n; t++)
//                cout << matr[i][t] << " ";
//            cout << endl;
//        }
//        cout << "=================" << endl;
        if (!fl)
            break;
        else{
            matr[j / n][j % n] = ar[minind];
            matr[(n - 1) - j / n][j % n] = ar[minind];
            matr[j / n][n - 1 - j % n] = ar[minind];
            matr[(n - 1) - j / n][n - 1 - j % n] = ar[minind];
            arr[ar[minind]] -= k;
        }
    }
    if (fl){
        cout << "YES" << endl;
        for (i = 0; i < n; i++){
            for (j = 0; j < n; j++)
                cout << matr[i][j] << " ";
            cout << endl;
        }
    }else{
        cout << "NO" << endl;
        for (i = 0; i < n; i++){
            for (j = 0; j < n; j++)
                cout << matr[i][j] << " ";
            cout << endl;
        }
    }
    return 0;
}


#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#include <stack>
#include<set>
#include<cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdio>
#include <string.h>
#include<iterator>
#include <map>
using namespace std;
// bool cmp(long long a, long long b){
//     return a > b;
// }
int  arr[3500];
string str[10];
char str_arr[5][5];
int matr[25][25], saved_matr[5][5], ish_matr[5][5];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    long long t, ch, i, curr, p = 1, x, y, weight, j, k = 0, n, m = 1, ch1, ans = 0;
    long long a, b;
    int fl, fl1, fl2, fl3;
    string s;
//    cin >> t;
    long long f, size_f, size_s, weight1, weight2;
    long long sum, k_min, k_max;
//    for (auto test_case = 0; test_case < t; test_case++) {
//    }
    cin >> n;
    long long* ar = new long long[n * n + 5];
    for (i = 0; i < n * n; i++) {
        cin >> ar[i];
        arr[ar[i]]++;
    }
    sort(ar, ar + n);
    if (n == 1){
        cout << "YES\n";
        cout << ar[0];
        return 0;
    }
    for (j = 0; j < n * n; j++) {
        if (matr[j / n][j % n] != 0) {
//            cout << j << " " << j / n << " " << j % n << " " << matr[j / n][j % n] << endl;
            continue;
        }
        k = 1;
        k = k * 2;
        if ((j / n == (n / 2)) && (n % 2 == 1))
            k = k / 2;
        k = k * 2;
        if ((j % n == (n / 2)) && (n % 2 == 1))
            k = k / 2;
        long long minim = 1e12, minind = -1;
        fl = 0;
//        cout << k << endl;
        for (i = 0; i < n * n; i++)
            if ((arr[ar[i]] >= k) && (arr[ar[i]] < minim)) {
                fl = 1;
                minim = arr[ar[i]];
                minind = i;
                break;
            }
//        for (i = 0; i < n; i++){
//            for (t = 0; t < n; t++)
//                cout << matr[i][t] << " ";
//            cout << endl;
//        }
//        cout << "=================" << endl;
        if (!fl)
            break;
        else{
            matr[j / n][j % n] = ar[minind];
            matr[(n - 1) - j / n][j % n] = ar[minind];
            matr[j / n][n - 1 - j % n] = ar[minind];
            matr[(n - 1) - j / n][n - 1 - j % n] = ar[minind];
            arr[ar[minind]] -= k;
        }
    }
    if (fl){
        cout << "YES" << endl;
        for (i = 0; i < n; i++){
            for (j = 0; j < n; j++)
                cout << matr[i][j] << " ";
            cout << endl;
        }
    }else{
        cout << "NO" << endl;
//        for (i = 0; i < n; i++){
//            for (j = 0; j < n; j++)
//                cout << matr[i][j] << " ";
//            cout << endl;
//        }
    }
    return 0;
}


#include<iostream>
using namespace std;
#include<stdio.h>
#define pii pair<int,int>
#include<queue>
#include<vector>
#include<stack>
#include<algorithm>
#include<string.h>
#define pb(x) push_back(x)
const int maxn = 1e3+10;
int n;
int have[maxn];
vector <int> g1,g2,g4;
int matrix[30][30];
int main(){
	scanf("%d",&n);
	memset(have,0,sizeof(have));
	for(int i = 1; i <= n*n; i++){
		int x;scanf("%d",&x);
		have[x]++;
	}
	for(int i = 1; i <= maxn; i++){
		if(have[i]&&have[i]%4==0) g4.pb(i);
		else if(have[i]&&have[i]%2==0) g2.pb(i);
		else if(have[i]) g1.pb(i);
	}
	if(n%2==0){
		if(g2.size()||g1.size()){
			puts("NO");
			return 0;
		}
		else{
			puts("YES");
			int l = 1,r = n,up = 1,down = n;
			while(up<=down){
				int pos = g4.size()-1;
				l = 1;r = n;
				while(l<=r){
					matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g4[pos];
					have[g4[pos]]-=4;
					if(have[g4[pos]]==0)
						g4.erase(g4.begin()+pos--);
					l++;r--;
				}
				up++;down--;
			}
		}
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++)
				printf("%d ",matrix[i][j]);
			printf("\n");
		}
	}
	else{
		int all = 0;
		for(int i = 1; i <= maxn; i++)
			all+=have[i]/4;
		if(g1.size()!=1||all<(n*n/4)){
			puts("NO");
			return 0;
		}
		else{
			puts("YES");
			int l = 1,r = n,up = 1,down = n,pos;
			while(up<down){
				if(g4.size()) pos = g4.size()-1;
				else pos = g1.size()-1;
				l = 1,r = n;
				while(l<r){
					if(g4.size()){
						matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g4[pos];
						have[g4[pos]]-=4;
						if(have[g4[pos]]==0) g4.erase(g4.begin()+pos--);
						l++;r--;
					}
					else{
						while(have[g1[pos]]==1) pos--;
						matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g1[pos];
						have[g1[pos]]-=4;
						l++;r--;
					}
				}
				up++;down--;
			}
			l = 1,r = n,up = 1,down = n;
			int p = n/2+1;
			pos = g2.size()-1;
			while(l<r&&g2.size()){
				matrix[p][l] = matrix[p][r] = g2[pos];
				have[g2[pos]]-=2;
				if(have[g2[pos]]==0) g2.erase(g2.begin()+pos--);
				l++;r--;
			}
			while(up<down&&g2.size()){
				matrix[up][p] = matrix[down][p] = g2[pos];
				have[g2[pos]]-=2;
				if(have[g2[pos]]==0) g2.erase(g2.begin()+pos--);
				up++;down--;
			}
			pos = g4.size()-1;
			while(l<r&&g4.size()){
				matrix[p][l] = matrix[p][r] = g4[pos];
				have[g4[pos]]-=2;
				if(have[g4[pos]]==0) g4.erase(g4.begin()+pos--);
				l++;r--;
			}
			while(up<down&&g4.size()){
				matrix[up][p] = matrix[down][p] = g4[pos];
				have[g4[pos]]-=2;
				if(have[g4[pos]]==0) g4.erase(g4.begin()+pos--);
				up++;down--;
			}
			pos = g1.size()-1;
			while(l<r&&g1.size()){
				matrix[p][l] = matrix[p][r] = g1[pos];
				have[g1[pos]]-=2;
				l++;r--;
			}
			while(up<down&&g1.size()){
				matrix[up][p] = matrix[down][p] = g1[pos];
				have[g1[pos]]-=2;
				up++;down--;
			}
			matrix[p][p]=g1[g1.size()-1];
			for(int i = 1; i <= n; i++){
				for(int j = 1; j <= n; j++)
					printf("%d ",matrix[i][j]);
				printf("\n");
			}
		}
	}
	return 0;
}


#include<iostream>
using namespace std;
#include<stdio.h>
#define pii pair<int,int>
#include<queue>
#include<vector>
#include<stack>
#include<algorithm>
#include<string.h>
#define pb(x) push_back(x)
const int maxn = 1e3+10;
int n;
int have[maxn+1];
vector <int> g1,g2,g4;
int matrix[30][30];
int main(){
	scanf("%d",&n);
	memset(have,0,sizeof(have));
	for(int i = 1; i <= n*n; i++){
		int x;scanf("%d",&x);
		have[x]++;
	}
	for(int i = 1; i <= maxn; i++){
		if(have[i]&&have[i]%4==0) g4.pb(i);
		else if(have[i]&&have[i]%2==0) g2.pb(i);
		else if(have[i]) g1.pb(i);
	}
	if(n%2==0){
		if(g2.size()||g1.size()){
			puts("NO");
			return 0;
		}
		else{
			puts("YES");
			int l = 1,r = n,up = 1,down = n;
			while(up<=down){
				int pos = g4.size()-1;
				l = 1;r = n;
				while(l<=r){
					matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g4[pos];
					have[g4[pos]]-=4;
					if(have[g4[pos]]==0)
						g4.erase(g4.begin()+pos--);
					l++;r--;
				}
				up++;down--;
			}
		}
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++)
				printf("%d ",matrix[i][j]);
			printf("\n");
		}
	}
	else{
		int all = 0;
		for(int i = 1; i <= maxn; i++)
			all+=have[i]/4;
		printf("%d %d %d\n",g1.size(),all,n*n/4);
		if(g1.size()!=1||all<(n/2)*(n/2)){
			puts("NO");
			return 0;
		}
		else{
			puts("YES");
			int l = 1,r = n,up = 1,down = n,pos;
			while(up<down){
				pos = g4.size()-1;
				l = 1,r = n;
				while(l<r){
					if(g4.size()){
						matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g4[pos];
						have[g4[pos]]-=4;
						if(have[g4[pos]]==0) g4.erase(g4.begin()+pos--);
						l++;r--;
					}
					else if(have[g1[g1.size()-1]]>4){
						pos = g1.size()-1;
						matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g1[pos];
						have[g1[pos]]-=4;
						l++;r--;
					}
					else{
						pos = g2.size()-1;
						while(have[g2[pos]]<4) pos--;
						matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g2[pos];
						have[g2[pos]]-=4;
						l++;r--;
					}
				}
				up++;down--;
			}
			l = 1,r = n,up = 1,down = n;
			int p = n/2+1;
			pos = g2.size()-1;
			while(l<r&&g2.size()){
				matrix[p][l] = matrix[p][r] = g2[pos];
				have[g2[pos]]-=2;
				if(have[g2[pos]]==0) g2.erase(g2.begin()+pos--);
				l++;r--;
			}
			while(up<down&&g2.size()){
				matrix[up][p] = matrix[down][p] = g2[pos];
				have[g2[pos]]-=2;
				if(have[g2[pos]]==0) g2.erase(g2.begin()+pos--);
				up++;down--;
			}
			pos = g4.size()-1;
			while(l<r&&g4.size()){
				matrix[p][l] = matrix[p][r] = g4[pos];
				have[g4[pos]]-=2;
				if(have[g4[pos]]==0) g4.erase(g4.begin()+pos--);
				l++;r--;
			}
			while(up<down&&g4.size()){
				matrix[up][p] = matrix[down][p] = g4[pos];
				have[g4[pos]]-=2;
				if(have[g4[pos]]==0) g4.erase(g4.begin()+pos--);
				up++;down--;
			}
			pos = g1.size()-1;
			while(l<r&&g1.size()){
				matrix[p][l] = matrix[p][r] = g1[pos];
				have[g1[pos]]-=2;
				l++;r--;
			}
			while(up<down&&g1.size()){
				matrix[up][p] = matrix[down][p] = g1[pos];
				have[g1[pos]]-=2;
				up++;down--;
			}
			matrix[p][p]=g1[g1.size()-1];
			for(int i = 1; i <= n; i++){
				for(int j = 1; j <= n; j++)
					printf("%d ",matrix[i][j]);
				printf("\n");
			}
		}
	}
	return 0;
}


#include<iostream>
using namespace std;
#include<stdio.h>
#define pii pair<int,int>
#include<queue>
#include<vector>
#include<stack>
#include<algorithm>
#include<string.h>
#define pb(x) push_back(x)
const int maxn = 1e3+10;
int n;
int have[maxn+1];
vector <int> g1,g2,g4;
int matrix[30][30];
int main(){
	scanf("%d",&n);
	memset(have,0,sizeof(have));
	for(int i = 1; i <= n*n; i++){
		int x;scanf("%d",&x);
		have[x]++;
	}
	for(int i = 1; i <= maxn; i++){
		if(have[i]&&have[i]%4==0) g4.pb(i);
		else if(have[i]&&have[i]%2==0) g2.pb(i);
		else if(have[i]) g1.pb(i);
	}
	if(n%2==0){
		if(g2.size()||g1.size()){
			puts("NO");
			return 0;
		}
		else{
			int l = 1,r = n,up = 1,down = n;
			while(up<=down){
				int pos = g4.size()-1;
				l = 1;r = n;
				while(l<=r){
					matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g4[pos];
					have[g4[pos]]-=4;
					if(have[g4[pos]]==0)
						g4.erase(g4.begin()+pos--);
					l++;r--;
				}
				up++;down--;
			}
		}
	}
	else{
		int all = 0;
		for(int i = 1; i <= maxn; i++)
			all+=have[i]/4;
		for(int i = 0; i < g4.size(); i++)
			g2.pb(g4[i]);
		g4.erase(g4.begin(),g4.end());
		if(g1.size()!=1||all<(n/2)*(n/2)){
			puts("NO");
			return 0;
		}
		else{
			int l = 1,r = n,up = 1,down = n,pos;
			while(up<down){
				l = 1,r = n;
				while(l<r){
					if(have[g1[g1.size()-1]]>4){
						pos = g1.size()-1;
						matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g1[pos];
						have[g1[pos]]-=4;
						l++;r--;
					}
					else{
						pos = g2.size()-1;
						while(have[g2[pos]]<4) pos--;
						matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g2[pos];
						have[g2[pos]]-=4;
						if(have[g2[pos]]==0) g2.erase(g2.begin()+pos);
						l++;r--;
					}
				}
				up++;down--;
			}
			l = 1,r = n,up = 1,down = n;
			int p = n/2+1;
			pos = g2.size()-1;
			while(l<r&&g2.size()){
				matrix[p][l] = matrix[p][r] = g2[pos];
				have[g2[pos]]-=2;
				if(have[g2[pos]]==0) g2.erase(g2.begin()+pos--);
				l++;r--;
			}
			while(up<down&&g2.size()){
				matrix[up][p] = matrix[down][p] = g2[pos];
				have[g2[pos]]-=2;
				if(have[g2[pos]]==0) g2.erase(g2.begin()+pos--);
				up++;down--;
			}
			pos = g1.size()-1;
			while(l<r&&g1.size()){
				matrix[p][l] = matrix[p][r] = g1[pos];
				have[g1[pos]]-=2;
				l++;r--;
			}
			while(up<down&&g1.size()){
				matrix[up][p] = matrix[down][p] = g1[pos];
				have[g1[pos]]-=2;
				up++;down--;
			}
			matrix[p][p]=g1[g1.size()-1];
		}
	}
	puts("YES");
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++)
			printf("%d ",matrix[i][j]);
		printf("\n");
	}
	return 0;
}


#include<iostream>
using namespace std;
#include<stdio.h>
#define pii pair<int,int>
#include<queue>
#include<vector>
#include<stack>
#include<algorithm>
#include<string.h>
#define pb(x) push_back(x)
const int maxn = 1e3+10;
int n;
int have[maxn+1];
vector <int> g1,g2,g4;
int matrix[30][30];
int main(){
	scanf("%d",&n);
	memset(have,0,sizeof(have));
	for(int i = 1; i <= n*n; i++){
		int x;scanf("%d",&x);
		have[x]++;
	}
	for(int i = 1; i <= maxn; i++){
		if(have[i]&&have[i]%4==0) g4.pb(i);
		else if(have[i]&&have[i]%2==0) g2.pb(i);
		else if(have[i]) g1.pb(i);
	}
	if(n%2==0){
		if(g2.size()||g1.size()){
			puts("NO");
			return 0;
		}
		else{
			puts("YES");
			int l = 1,r = n,up = 1,down = n;
			while(up<=down){
				int pos = g4.size()-1;
				l = 1;r = n;
				while(l<=r){
					matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g4[pos];
					have[g4[pos]]-=4;
					if(have[g4[pos]]==0)
						g4.erase(g4.begin()+pos--);
					l++;r--;
				}
				up++;down--;
			}
		}
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++)
				printf("%d ",matrix[i][j]);
			printf("\n");
		}
	}
	else{
		int all = 0;
		for(int i = 1; i <= maxn; i++)
			all+=have[i]/4;
		for(int i = 0; i < g4.size(); i++)
			g2.pb(g4[i]);
		g4.erase(g4.begin(),g4.end());
		if(g1.size()!=1||all<(n/2)*(n/2)){
			puts("NO");
			return 0;
		}
		else{
			puts("YES");
			int l = 1,r = n,up = 1,down = n,pos;
			while(up<down){
				l = 1,r = n;
				while(l<r){
					if(have[g1[g1.size()-1]]>4){
						pos = g1.size()-1;
						matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g1[pos];
						have[g1[pos]]-=4;
						l++;r--;
					}
					else{
						pos = g2.size()-1;
						while(have[g2[pos]]<4) pos--;
						matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g2[pos];
						have[g2[pos]]-=4;
						if(have[g2[pos]]==0) g2.erase(g2.begin()+pos);
						l++;r--;
					}
				}
				up++;down--;
			}
			l = 1,r = n,up = 1,down = n;
			int p = n/2+1;
			pos = g2.size()-1;
			while(l<r&&g2.size()){
				matrix[p][l] = matrix[p][r] = g2[pos];
				have[g2[pos]]-=2;
				if(have[g2[pos]]==0) g2.erase(g2.begin()+pos--);
				l++;r--;
			}
			while(up<down&&g2.size()){
				matrix[up][p] = matrix[down][p] = g2[pos];
				have[g2[pos]]-=2;
				if(have[g2[pos]]==0) g2.erase(g2.begin()+pos--);
				up++;down--;
			}
			pos = g1.size()-1;
			while(l<r&&g1.size()){
				matrix[p][l] = matrix[p][r] = g1[pos];
				have[g1[pos]]-=2;
				l++;r--;
			}
			while(up<down&&g1.size()){
				matrix[up][p] = matrix[down][p] = g1[pos];
				have[g1[pos]]-=2;
				up++;down--;
			}
			matrix[p][p]=g1[g1.size()-1];
			for(int i = 1; i <= n; i++){
				for(int j = 1; j <= n; j++)
					printf("%d ",matrix[i][j]);
				printf("\n");
			}
		}
	}
	return 0;
}


#include<iostream>
using namespace std;
#include<stdio.h>
#define pii pair<int,int>
#include<queue>
#include<vector>
#include<stack>
#include<algorithm>
#include<string.h>
#define pb(x) push_back(x)
const int maxn = 1e3+10;
int n;
int have[maxn+1];
vector <int> g1,g2,g4;
int matrix[30][30];
int main(){
	scanf("%d",&n);
	memset(have,0,sizeof(have));
	for(int i = 1; i <= n*n; i++){
		int x;scanf("%d",&x);
		have[x]++;
	}
	for(int i = 1; i <= maxn; i++){
		if(have[i]&&have[i]%4==0) g4.pb(i);
		else if(have[i]&&have[i]%2==0) g2.pb(i);
		else if(have[i]) g1.pb(i);
	}
	if(n%2==0){
		if(g2.size()||g1.size()){
			puts("NO");
			return 0;
		}
		else{
			puts("YES");
			int l = 1,r = n,up = 1,down = n;
			while(up<=down){
				int pos = g4.size()-1;
				l = 1;r = n;
				while(l<=r){
					matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g4[pos];
					have[g4[pos]]-=4;
					if(have[g4[pos]]==0)
						g4.erase(g4.begin()+pos--);
					l++;r--;
				}
				up++;down--;
			}
		}
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++)
				printf("%d ",matrix[i][j]);
			printf("\n");
		}
	}
	else{
		int all = 0;
		for(int i = 1; i <= maxn; i++)
			all+=have[i]/4;
		if(g1.size()!=1||all<(n*n/4)){
			puts("NO");
			return 0;
		}
		else{
			puts("YES");
			int l = 1,r = n,up = 1,down = n,pos;
			while(up<down){
				if(g4.size()) pos = g4.size()-1;
				else pos = g1.size()-1;
				l = 1,r = n;
				while(l<r){
					if(g4.size()){
						matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g4[pos];
						have[g4[pos]]-=4;
						if(have[g4[pos]]==0) g4.erase(g4.begin()+pos--);
						l++;r--;
					}
					else{
						while(have[g1[pos]]==1) pos--;
						matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g1[pos];
						have[g1[pos]]-=4;
						l++;r--;
					}
				}
				up++;down--;
			}
			l = 1,r = n,up = 1,down = n;
			int p = n/2+1;
			pos = g2.size()-1;
			while(l<r&&g2.size()){
				matrix[p][l] = matrix[p][r] = g2[pos];
				have[g2[pos]]-=2;
				if(have[g2[pos]]==0) g2.erase(g2.begin()+pos--);
				l++;r--;
			}
			while(up<down&&g2.size()){
				matrix[up][p] = matrix[down][p] = g2[pos];
				have[g2[pos]]-=2;
				if(have[g2[pos]]==0) g2.erase(g2.begin()+pos--);
				up++;down--;
			}
			pos = g4.size()-1;
			while(l<r&&g4.size()){
				matrix[p][l] = matrix[p][r] = g4[pos];
				have[g4[pos]]-=2;
				if(have[g4[pos]]==0) g4.erase(g4.begin()+pos--);
				l++;r--;
			}
			while(up<down&&g4.size()){
				matrix[up][p] = matrix[down][p] = g4[pos];
				have[g4[pos]]-=2;
				if(have[g4[pos]]==0) g4.erase(g4.begin()+pos--);
				up++;down--;
			}
			pos = g1.size()-1;
			while(l<r&&g1.size()){
				matrix[p][l] = matrix[p][r] = g1[pos];
				have[g1[pos]]-=2;
				l++;r--;
			}
			while(up<down&&g1.size()){
				matrix[up][p] = matrix[down][p] = g1[pos];
				have[g1[pos]]-=2;
				up++;down--;
			}
			matrix[p][p]=g1[g1.size()-1];
			for(int i = 1; i <= n; i++){
				for(int j = 1; j <= n; j++)
					printf("%d ",matrix[i][j]);
				printf("\n");
			}
		}
	}
	return 0;
}


#include<iostream>
using namespace std;
#include<stdio.h>
#define pii pair<int,int>
#include<queue>
#include<vector>
#include<stack>
#include<algorithm>
#include<string.h>
#define pb(x) push_back(x)
const int maxn = 1e3+10;
int n;
int have[maxn+1];
vector <int> g1,g2,g4;
int matrix[30][30];
int main(){
	scanf("%d",&n);
	memset(have,0,sizeof(have));
	for(int i = 1; i <= n*n; i++){
		int x;scanf("%d",&x);
		have[x]++;
	}
	for(int i = 1; i <= maxn; i++){
		if(have[i]&&have[i]%4==0) g4.pb(i);
		else if(have[i]&&have[i]%2==0) g2.pb(i);
		else if(have[i]) g1.pb(i);
	}
	if(n%2==0){
		if(g2.size()||g1.size()){
			puts("NO");
			return 0;
		}
		else{
			puts("YES");
			int l = 1,r = n,up = 1,down = n;
			while(up<=down){
				int pos = g4.size()-1;
				l = 1;r = n;
				while(l<=r){
					matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g4[pos];
					have[g4[pos]]-=4;
					if(have[g4[pos]]==0)
						g4.erase(g4.begin()+pos--);
					l++;r--;
				}
				up++;down--;
			}
		}
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++)
				printf("%d ",matrix[i][j]);
			printf("\n");
		}
	}
	else{
		int all = 0;
		for(int i = 1; i <= maxn; i++)
			all+=have[i]/4;
		for(int i = 0; i < g4.size(); i++)
			g2.pb(g4[i]);
		g4.erase(g4.begin(),g4.end());
		if(g1.size()!=1||all<(n/2)*(n/2)){
			puts("NO");
			return 0;
		}
		else{
			puts("YES");
			int l = 1,r = n,up = 1,down = n,pos;
			while(up<down){
				l = 1,r = n;
				while(l<r){
					if(have[g1[g1.size()-1]]>4){
						pos = g1.size()-1;
						matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g1[pos];
						have[g1[pos]]-=4;
						l++;r--;
					}
					else{
						pos = g2.size()-1;
						while(have[g2[pos]]<4) pos--;
						matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g2[pos];
						have[g2[pos]]-=4;
						l++;r--;
					}
				}
				up++;down--;
			}
			l = 1,r = n,up = 1,down = n;
			int p = n/2+1;
			pos = g2.size()-1;
			while(l<r&&g2.size()){
				matrix[p][l] = matrix[p][r] = g2[pos];
				have[g2[pos]]-=2;
				if(have[g2[pos]]==0) g2.erase(g2.begin()+pos--);
				l++;r--;
			}
			while(up<down&&g2.size()){
				matrix[up][p] = matrix[down][p] = g2[pos];
				have[g2[pos]]-=2;
				if(have[g2[pos]]==0) g2.erase(g2.begin()+pos--);
				up++;down--;
			}
			pos = g1.size()-1;
			while(l<r&&g1.size()){
				matrix[p][l] = matrix[p][r] = g1[pos];
				have[g1[pos]]-=2;
				l++;r--;
			}
			while(up<down&&g1.size()){
				matrix[up][p] = matrix[down][p] = g1[pos];
				have[g1[pos]]-=2;
				up++;down--;
			}
			matrix[p][p]=g1[g1.size()-1];
			for(int i = 1; i <= n; i++){
				for(int j = 1; j <= n; j++)
					printf("%d ",matrix[i][j]);
				printf("\n");
			}
		}
	}
	return 0;
}


#include<iostream>
using namespace std;
#include<stdio.h>
#define pii pair<int,int>
#include<queue>
#include<vector>
#include<stack>
#include<algorithm>
#include<string.h>
#define pb(x) push_back(x)
const int maxn = 1e3+10;
int n;
int have[maxn+1];
vector <int> g1,g2,g4;
int matrix[30][30];
int main(){
	scanf("%d",&n);
	memset(have,0,sizeof(have));
	for(int i = 1; i <= n*n; i++){
		int x;scanf("%d",&x);
		have[x]++;
	}
	for(int i = 1; i <= maxn; i++){
		if(have[i]&&have[i]%4==0) g4.pb(i);
		else if(have[i]&&have[i]%2==0) g2.pb(i);
		else if(have[i]) g1.pb(i);
	}
	if(n%2==0){
		if(g2.size()||g1.size()){
			puts("NO");
			return 0;
		}
		else{
			int l = 1,r = n,up = 1,down = n;
			while(up<=down){
				int pos = g4.size()-1;
				l = 1;r = n;
				while(l<=r){
					matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g4[pos];
					have[g4[pos]]-=4;
					if(have[g4[pos]]==0)
						g4.erase(g4.begin()+pos--);
					l++;r--;
				}
				up++;down--;
			}
		}
	}
	else{
		int all = 0;
		for(int i = 1; i <= maxn; i++)
			all+=have[i]/4;
		if(g1.size()!=1||all<(n/2)*(n/2)){
			puts("NO");
			return 0;
		}
		else{
			int l = 1,r = n,up = 1,down = n,pos;
			int i = 1;
			while(up<down){
				l = 1,r = n;
				while(l<r){
					while(have[i]<4) i++;
					matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = i;
					have[i]-=4;
					l++;r--;
				}
				up++;down--;
			}
			i=1,l = 1,r = n,up = 1,down = n;
			int p = n/2+1;
			while(l<r){
				while(have[i]<2) i++;
				matrix[p][l] = matrix[p][r] = i;
				have[i]-=2;
				l++;r--;
			}
			while(up<down){
				while(have[i]<2) i++;
				matrix[up][p] = matrix[down][p] = i;
				have[i]-=2;
				up++;down--;
			}
			for(int i = 1; i <= maxn; i++)
				if(have[i]){
					matrix[p][p]=i;
					break;
				}
		}
	}
	puts("YES");
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++)
			printf("%d ",matrix[i][j]);
		printf("\n");
	}
	return 0;
}


#include<iostream>
using namespace std;
#include<stdio.h>
#define pii pair<int,int>
#include<queue>
#include<vector>
#include<stack>
#include<algorithm>
#include<string.h>
#define pb(x) push_back(x)
const int maxn = 1e3+10;
int n;
int have[maxn+1];
vector <int> g1,g2,g4;
int matrix[30][30];
int main(){
	scanf("%d",&n);
	memset(have,0,sizeof(have));
	for(int i = 1; i <= n*n; i++){
		int x;scanf("%d",&x);
		have[x]++;
	}
	for(int i = 1; i <= maxn; i++){
		if(have[i]&&have[i]%4==0) g4.pb(i);
		else if(have[i]&&have[i]%2==0) g2.pb(i);
		else if(have[i]) g1.pb(i);
	}
	if(n%2==0){
		if(g2.size()||g1.size()){
			puts("NO");
			return 0;
		}
		else{
			puts("YES");
			int l = 1,r = n,up = 1,down = n;
			while(up<=down){
				int pos = g4.size()-1;
				l = 1;r = n;
				while(l<=r){
					matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g4[pos];
					have[g4[pos]]-=4;
					if(have[g4[pos]]==0)
						g4.erase(g4.begin()+pos--);
					l++;r--;
				}
				up++;down--;
			}
		}
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++)
				printf("%d ",matrix[i][j]);
			printf("\n");
		}
	}
	else{
		int all = 0;
		for(int i = 1; i <= maxn; i++)
			all+=have[i]/4;
		if(g1.size()!=1||all<(n/2)*(n/2)){
			puts("NO");
			return 0;
		}
		else{
			puts("YES");
			int l = 1,r = n,up = 1,down = n,pos;
			while(up<down){
				pos = g4.size()-1;
				l = 1,r = n;
				while(l<r){
					if(g4.size()){
						matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g4[pos];
						have[g4[pos]]-=4;
						if(have[g4[pos]]==0) g4.erase(g4.begin()+pos--);
						l++;r--;
					}
					else if(have[g1[g1.size()-1]]>4){
						pos = g1.size()-1;
						matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g1[pos];
						have[g1[pos]]-=4;
						l++;r--;
					}
					else{
						pos = g2.size()-1;
						while(have[g2[pos]]<4) pos--;
						matrix[up][l] = matrix[down][l] = matrix[up][r] = matrix[down][r] = g2[pos];
						have[g2[pos]]-=4;
						l++;r--;
					}
				}
				up++;down--;
			}
			l = 1,r = n,up = 1,down = n;
			int p = n/2+1;
			pos = g2.size()-1;
			while(l<r&&g2.size()){
				matrix[p][l] = matrix[p][r] = g2[pos];
				have[g2[pos]]-=2;
				if(have[g2[pos]]==0) g2.erase(g2.begin()+pos--);
				l++;r--;
			}
			while(up<down&&g2.size()){
				matrix[up][p] = matrix[down][p] = g2[pos];
				have[g2[pos]]-=2;
				if(have[g2[pos]]==0) g2.erase(g2.begin()+pos--);
				up++;down--;
			}
			pos = g4.size()-1;
			while(l<r&&g4.size()){
				matrix[p][l] = matrix[p][r] = g4[pos];
				have[g4[pos]]-=2;
				if(have[g4[pos]]==0) g4.erase(g4.begin()+pos--);
				l++;r--;
			}
			while(up<down&&g4.size()){
				matrix[up][p] = matrix[down][p] = g4[pos];
				have[g4[pos]]-=2;
				if(have[g4[pos]]==0) g4.erase(g4.begin()+pos--);
				up++;down--;
			}
			pos = g1.size()-1;
			while(l<r&&g1.size()){
				matrix[p][l] = matrix[p][r] = g1[pos];
				have[g1[pos]]-=2;
				l++;r--;
			}
			while(up<down&&g1.size()){
				matrix[up][p] = matrix[down][p] = g1[pos];
				have[g1[pos]]-=2;
				up++;down--;
			}
			matrix[p][p]=g1[g1.size()-1];
			for(int i = 1; i <= n; i++){
				for(int j = 1; j <= n; j++)
					printf("%d ",matrix[i][j]);
				printf("\n");
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define d double
#define pii pair<int,int>
#define pb push_back
#define cases int t;cin>>t;while(t--)
#define N 1003
//int mod=1e9+7;
//int mod=998244353;
int freq[N];
map<int,int> m;

void print(int ans[21][21],int n)
{
    cout<<"YES\n";
    int i,j;
    for(i=1;i<=n;++i)
    {
        for(j=1;j<=n;++j)
            cout<<ans[i][j]<<" ";
        cout<<"\n";
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    m.clear();
    fill(freq,freq+N,0);
    int n;
    cin>>n;
    int a[n*n+4];
    int i,j,k,l,x;
    for(i=1;i<=n*n;++i)
    {
        cin>>a[i];
        m[a[i]]++;
    }

    int ans[21][21];
    auto it=m.begin();
    i=1;j=1;
    k=n-i+1;l=n-j+1;         //[i][j] = [i][l] = [k][j] = [k][l]
    int t1;

    while(i<=n/2)
    {
        j=1;
        while(j<=n/2)
        {
            if(it==m.end())
            {
                cout<<"NO";
                return 0;
            }
            k=n-i+1;l=n-j+1;
            if(m[it->first]<4)
            {
                ++it;
                continue;
            }
            t1=it->first;
            ans[i][j]=ans[i][l]=ans[k][j]=ans[k][l]=t1;
            m[t1]-=4;
            if(m[t1]==0)
                ++it;
            ++j;
        }
        ++i;
    }
    if(n%2==0)
    {
        print(ans,n);
        return 0;
    }

    i=1;j=n/2+1;
    it=m.begin();
    while(i<=n/2)
    {
        k=n-i+1;
        if(it==m.end())
        {
            cout<<"NO";
            return 0;
        }
        if(m[it->first]<2)
        {
            ++it;
            continue;
        }
        t1=it->first;
        ans[i][j]=ans[k][j]=t1;
        m[t1]-=2;
        if(m[t1]==0)
            ++it;
        ++i;
    }

    j=1;i=n/2+1;
    it=m.begin();
    while(j<=n/2)
    {
        k=n-j+1;
        if(it==m.end())
        {
            cout<<"NO";
            return 0;
        }
        if(m[it->first]<2)
        {
            ++it;
            continue;
        }
        t1=it->first;
        ans[i][j]=ans[i][k]=t1;
        m[t1]-=2;
        if(m[t1]==0)
            ++it;
        ++j;
    }

    for(auto itreal:m)
        if(itreal.second==1)
            ans[n/2+1][n/2+1]=itreal.first;
    print(ans,n);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define d double
#define pii pair<int,int>
#define pb push_back
#define cases int t;cin>>t;while(t--)
#define N 1003
//int mod=1e9+7;
//int mod=998244353;
map<int,int> m;
int freq[N];

void handle(int n)
{
    int i,j,cnt1=0,cnt2=0,cnt3=0,cnt4;
    if(n%2==0)
    {
        for(i=1;i<N;++i)
        {
            if(freq[i]%4>0)
            {
                cout<<"NO";
                exit(0);
            }
        }
    }
    else
    {
        for(i=1;i<N;++i)
        {
            if(freq[i]%4==2)
                ++cnt2;
            else if(freq[i]%4>0)
            {
                if(freq[i]%4==1)
                    ++cnt1;
                else
                    ++cnt3;
            }
        }
        if(cnt1+cnt3!=1)
        {
            cout<<"NO";
            exit(0);
        }
        if(cnt2+cnt3>=n)
        {
            cout<<"NO";
            exit(0);
        }
    }
}

void print(int ans[21][21],int n)
{
    cout<<"YES\n";
    int i,j;
    for(i=1;i<=n;++i)
    {
        for(j=1;j<=n;++j)
            cout<<ans[i][j]<<" ";
        cout<<"\n";
    }
}

signed main()
{
//    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    m.clear();
    fill(freq,freq+N,0);
    int n,a,i,j;
    cin>>n;
    for(i=1;i<=n*n;++i)
    {
        cin>>a;
        freq[a]++;
        m[a]++;
    }
    handle(n);

    int ans[21][21];
    i=1;j=1;
    int k=n-i+1,l=n-j+1;         //[i][j] = [i][l] = [k][j] = [k][l]
    int t1;

    auto it=m.begin();
    while(i<=n/2)
    {
        j=1;
        while(j<=n/2)
        {
            k=n-i+1;l=n-j+1;
            if(m[it->first]<4)
            {
                ++it;
                continue;
            }
            t1=it->first;
            ans[i][j]=ans[i][l]=ans[k][j]=ans[k][l]=t1;
            m[t1]-=4;
            if(m[t1]==0)
            {
                ++it;
            }
            ++j;
        }
        ++i;
    }
    if(n%2==0)
    {
        print(ans,n);
        return 0;
    }

    i=1;j=n/2+1;
    it=m.begin();
    while(i<=n/2)
    {
        k=n-i+1;
        if(m[it->first]<2)
        {
            ++it;
            continue;
        }
        t1=it->first;
        ans[i][j]=ans[k][j]=t1;
        m[t1]-=2;
        if(m[t1]==0)
        {
            ++it;
        }
        ++i;
    }

    j=1;i=n/2+1;
    it=m.begin();
    while(j<=n/2)
    {
        k=n-j+1;
        if(m[it->first]<2)
        {
            if(it->second==1)
            {
                ans[n/2+1][n/2+1]=it->first;
                m[it->first]=0;
            }
            ++it;
            continue;
        }
        t1=it->first;
        ans[i][j]=ans[i][k]=t1;
        m[it->first]-=2;
        if(m[it->first]==0)
        {
            ++it;
        }
        ++j;
    }

    for(auto itreal:m)
        if(it->second==1)
            ans[n/2+1][n/2+1]=it->first;
    print(ans,n);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define d double
#define pii pair<int,int>
#define pb push_back
#define cases int t;cin>>t;while(t--)
#define N 1003
//int mod=1e9+7;
//int mod=998244353;
map<int,int> m;
int freq[N];

void handle(int n)
{
    int i,j,cnt1=0,cnt2=0,cnt3=0,cnt4;
    if(n%2==0)
    {
        for(i=1;i<N;++i)
        {
            if(freq[i]%4>0)
            {
                cout<<"NO";
                exit(0);
            }
        }
    }
    else
    {
        for(i=1;i<N;++i)
        {
            if(freq[i]%4==2)
                ++cnt2;
            else if(freq[i]%4>0)
            {
                if(freq[i]%4==1)
                    ++cnt1;
                else
                    ++cnt3;
            }
        }
        if(cnt1+cnt3!=1)
        {
            cout<<"NO";
            exit(0);
        }
        if(cnt2+cnt3>=n)
        {
            cout<<"NO";
            exit(0);
        }
    }
}

void print(int ans[21][21],int n)
{
    cout<<"YES\n";
    int i,j;
    for(i=1;i<=n;++i)
    {
        for(j=1;j<=n;++j)
            cout<<ans[i][j]<<" ";
        cout<<"\n";
    }
}

signed main()
{
//    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    m.clear();
    fill(freq,freq+N,0);
    int n,a,i,j;
    cin>>n;
    for(i=1;i<=n*n;++i)
    {
        cin>>a;
        freq[a]++;
        m[a]++;
    }
    handle(n);

    int ans[21][21];
    i=1;j=1;
    int k=n-i+1,l=n-j+1;         //[i][j] = [i][l] = [k][j] = [k][l]
    int t1;

    auto it=m.begin();
    while(i<=n/2)
    {
        j=1;
        while(j<=n/2)
        {
            k=n-i+1;l=n-j+1;
            if(m[it->first]<4)
            {
                ++it;
                continue;
            }
            t1=it->first;
            ans[i][j]=ans[i][l]=ans[k][j]=ans[k][l]=t1;
            m[t1]-=4;
            if(m[t1]==0)
            {
                ++it;
            }
            ++j;
        }
        ++i;
    }
    if(n%2==0)
    {
        print(ans,n);
        return 0;
    }

    i=1;j=n/2+1;
    it=m.begin();
    while(i<=n/2)
    {
        k=n-i+1;
        if(m[it->first]<2)
        {
            ++it;
            continue;
        }
        t1=it->first;
        ans[i][j]=ans[k][j]=t1;
        m[t1]-=2;
        if(m[t1]==0)
        {
            ++it;
        }
        ++i;
    }

    j=1;i=n/2+1;
    it=m.begin();
    while(j<=n/2)
    {
        k=n-j+1;
        if(m[it->first]<2)
        {
            if(it->second==1)
            {
                ans[n/2+1][n/2+1]=it->first;
                m[it->first]=0;
            }
            ++it;
            continue;
        }
        t1=it->first;
        ans[i][j]=ans[i][k]=t1;
        m[it->first]-=2;
        if(m[it->first]==0)
        {
            ++it;
        }
        ++j;
    }

    print(ans,n);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define d double
#define pii pair<int,int>
#define pb push_back
#define cases int t;cin>>t;while(t--)
#define N 1003
//int mod=1e9+7;
//int mod=998244353;
map<int,int> m;
bool seen[N];
int freq[N];

void handle(int n)
{
    int i,j,cnt1=0,cnt2=0,cnt3=0,cnt4;
    if(n%2==0)
    {
        for(i=1;i<N;++i)
        {
            if(freq[i]%4>0)
            {
                cout<<"NO";
                exit(0);
            }
        }
    }
    else
    {
        for(i=1;i<N;++i)
        {
            if(freq[i]%4==2)
                ++cnt2;
            else if(freq[i]%4>0)
            {
                if(freq[i]%4==1)
                    ++cnt1;
                else
                    ++cnt3;
            }
        }
        if(cnt1+cnt3!=1)
        {
            cout<<"NO";
            exit(0);
        }
        if(cnt2+cnt3>=n)
        {
            cout<<"NO";
            exit(0);
        }
    }
}

void print(int ans[21][21],int n)
{
    cout<<"YES\n";
    int i,j;
    for(i=1;i<=n;++i)
    {
        for(j=1;j<=n;++j)
            cout<<ans[i][j]<<" ";
        cout<<"\n";
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    m.clear();
    fill(seen,seen+N,0);
    fill(freq,freq+N,0);
    int n;
    cin>>n;
    int a;
    int i,j,k,l,x;
    for(i=1;i<=n*n;++i)
    {
        cin>>a;
        freq[a]++;
        seen[a]=1;
        m[a]++;
    }
    handle(n);

    int ans[21][21];
    auto it=m.begin();
    i=1;j=1;
    k=n-i+1;l=n-j+1;         //[i][j] = [i][l] = [k][j] = [k][l]
    int t1;

    int z=m.size();
    int y=1;
    while(i<=n/2)
    {
        j=1;
        it=m.begin();y=1;z=m.size();
        while(j<=n/2)
        {
            k=n-i+1;l=n-j+1;
            if(m[it->first]<4)
            {
                ++it;
                continue;
            }
            t1=it->first;
            ans[i][j]=ans[i][l]=ans[k][j]=ans[k][l]=t1;
            m[it->first]-=4;
            if(m[it->first]==0)
            {
                m.erase(it->first);
            }
            ++j;
        }
        ++i;
    }
    if(n%2==0)
    {
        print(ans,n);
        return 0;
    }

    y=1;
    z=m.size();
    i=1;j=n/2+1;
    it=m.begin();
    while(i<=n/2)
    {
        k=n-i+1;
        if(m[it->first]<2)
        {
            ++it;
            continue;
        }
        t1=it->first;
        ans[i][j]=ans[k][j]=t1;
        m[it->first]-=2;
        if(m[it->first]==0)
        {
            m.erase(it->first);
        }
        ++i;
    }

    j=1;i=n/2+1;
    it=m.begin();
    y=1;
    z=m.size();
    while(j<=n/2)
    {
        k=n-j+1;
        if(m[it->first]<2)
        {
            ++it;
            continue;
        }
        t1=it->first;
        ans[i][j]=ans[i][k]=t1;
        m[it->first]-=2;
        if(m[it->first]==0)
        {
            m.erase(it->first);
        }
        ++j;
    }
    it=m.begin();
    ans[n/2+1][n/2+1]=it->first;
    print(ans,n);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define d double
#define pii pair<int,int>
#define pb push_back
#define cases int t;cin>>t;while(t--)
#define N 1003
//int mod=1e9+7;
//int mod=998244353;
int freq[N];
map<int,int> m;
bool seen[N];

void print(int ans[21][21],int n)
{
    cout<<"YES\n";
    int i,j;
    for(i=1;i<=n;++i)
    {
        for(j=1;j<=n;++j)
            cout<<ans[i][j]<<" ";
        cout<<"\n";
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    m.clear();
    fill(seen,seen+N,0);
    fill(freq,freq+N,0);
    int n;
    cin>>n;
    int a[n*n+4];
    int i,j,k,l,x;
    for(i=1;i<=n*n;++i)
    {
        cin>>a[i];
        seen[a[i]]=1;
        m[a[i]]++;
    }

    int ans[21][21];
    auto it=m.begin();
    i=1;j=1;
    k=n-i+1;l=n-j+1;         //[i][j] = [i][l] = [k][j] = [k][l]
    int t1,t2,t3,t4;

    auto it2=m.end();
    while(i<=n/2)
    {
        j=1;
        while(j<=n/2)
        {
            if(it==m.end() || it->first>1000 || seen[it->first]==0)
            {
                cout<<"NO";
                return 0;
            }
            k=n-i+1;l=n-j+1;
            if(m[it->first]<4)
            {
                ++it;
                if(it==m.end() || it->first>1000 || seen[it->first]==0)
                {
                    cout<<"NO";
                    return 0;
                }
                continue;
            }
            t1=it->first;
            ans[i][j]=ans[i][l]=ans[k][j]=ans[k][l]=t1;
            m[it->first]-=4;
            if(m[it->first]==0)
            {
                m.erase(it->first);
            }
            ++j;
        }
        ++i;
    }
    if(n%2==0)
    {
        print(ans,n);
        return 0;
    }

    i=1;j=n/2+1;
    it=m.begin();
    while(i<=n/2)
    {
        k=n-i+1;
        if(it==m.end() || it->first>1000 || seen[it->first]==0)
        {
            cout<<"NO";
            return 0;
        }
        if(m[it->first]<2)
        {
            ++it;
            if(it==m.end() || it->first>1000 || seen[it->first]==0)
            {
                cout<<"NO";
                return 0;
            }
            continue;
        }
        t1=it->first;
        ans[i][j]=ans[k][j]=t1; cout<<i<<" "<<j<<" "<<k<<"\n";
        m[it->first]-=2;
        if(m[it->first]==0)
        {
            m.erase(it->first);
        }
        ++i;
    }

    j=1;i=n/2+1;
    it=m.begin();
    while(j<=n/2)
    {
        k=n-j+1;
        if(it==m.end() || it->first>1000 || seen[it->first]==0)
        {
            cout<<"NO";
            return 0;
        }
        if(m[it->first]<2)
        {
            ++it;
            if(it==m.end() || it->first>1000 || seen[it->first]==0)
            {
                cout<<"NO";
                return 0;
            }
            continue;
        }
        t1=it->first;
        ans[i][j]=ans[i][k]=t1; cout<<i<<" "<<j<<" "<<k<<"\n";
        m[it->first]-=2;
        if(m[it->first]==0)
        {
            m.erase(it->first);
        }
        ++j;
    }
    it=m.begin();
    ans[n/2+1][n/2+1]=it->first;
    print(ans,n);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define d double
#define pii pair<int,int>
#define pb push_back
#define cases int t;cin>>t;while(t--)
#define N 1003
//int mod=1e9+7;
//int mod=998244353;
map<int,int> m;
bool seen[N];
int freq[N];

void handle(int n)
{
    int i,j,cnt1=0,cnt2=0,cnt4;
    if(n%2==0)
    {
        for(i=1;i<N;++i)
        {
            if(freq[i]%4>0)
            {
                cout<<"NO";
                exit(0);
            }
        }
    }
    else
    {
        for(i=1;i<N;++i)
        {
            if(freq[i]%4==2)
                ++cnt2;
            else if(freq[i]%4>0)
                ++cnt1;
        }
        if(cnt1!=1)
        {
            cout<<"NO";
            exit(0);
        }
        if(cnt2>=n)
        {
            cout<<"NO";
            exit(0);
        }
    }
}

void print(int ans[21][21],int n)
{
    cout<<"YES\n";
    int i,j;
    for(i=1;i<=n;++i)
    {
        for(j=1;j<=n;++j)
            cout<<ans[i][j]<<" ";
        cout<<"\n";
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    m.clear();
    fill(seen,seen+N,0);
    fill(freq,freq+N,0);
    int n;
    cin>>n;
    int a;
    int i,j,k,l,x;
    for(i=1;i<=n*n;++i)
    {
        cin>>a;
        freq[a]++;
        seen[a]=1;
        m[a]++;
    }
    handle(n);

    int ans[21][21];
    auto it=m.begin();
    i=1;j=1;
    k=n-i+1;l=n-j+1;         //[i][j] = [i][l] = [k][j] = [k][l]
    int t1;

    int z=m.size();
    int y=1;
    while(i<=n/2)
    {
        j=1;
        it=m.begin();y=1;z=m.size();
        while(j<=n/2)
        {
            k=n-i+1;l=n-j+1;
            if(m[it->first]<4)
            {
                ++it;
                continue;
            }
            t1=it->first;
            ans[i][j]=ans[i][l]=ans[k][j]=ans[k][l]=t1;
            m[it->first]-=4;
            if(m[it->first]==0)
            {
                m.erase(it->first);
            }
            ++j;
        }
        ++i;
    }
    if(n%2==0)
    {
        print(ans,n);
        return 0;
    }

    y=1;
    z=m.size();
    i=1;j=n/2+1;
    it=m.begin();
    while(i<=n/2)
    {
        k=n-i+1;
        if(m[it->first]<2)
        {
            ++it;
            continue;
        }
        t1=it->first;
        ans[i][j]=ans[k][j]=t1;
        m[it->first]-=2;
        if(m[it->first]==0)
        {
            m.erase(it->first);
        }
        ++i;
    }

    j=1;i=n/2+1;
    it=m.begin();
    y=1;
    z=m.size();
    while(j<=n/2)
    {
        k=n-j+1;
        if(m[it->first]<2)
        {
            ++it;
            continue;
        }
        t1=it->first;
        ans[i][j]=ans[i][k]=t1;
        m[it->first]-=2;
        if(m[it->first]==0)
        {
            m.erase(it->first);
        }
        ++j;
    }
    it=m.begin();
    ans[n/2+1][n/2+1]=it->first;
    print(ans,n);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define d double
#define pii pair<int,int>
#define pb push_back
#define cases int t;cin>>t;while(t--)
#define N 1003
//int mod=1e9+7;
//int mod=998244353;
map<int,int> m;
bool seen[N];

void print(int ans[21][21],int n)
{
    cout<<"YES\n";
    int i,j;
    for(i=1;i<=n;++i)
    {
        for(j=1;j<=n;++j)
            cout<<ans[i][j]<<" ";
        cout<<"\n";
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    m.clear();
    fill(seen,seen+N,0);
    int n;
    cin>>n;
    int a;
    int i,j,k,l,x;
    for(i=1;i<=n*n;++i)
    {
        cin>>a;
        seen[a]=1;
        m[a]++;
    }

    int ans[21][21];
    auto it=m.begin();
    i=1;j=1;
    k=n-i+1;l=n-j+1;         //[i][j] = [i][l] = [k][j] = [k][l]
    int t1;

    int z=m.size();
    int y=1;
    while(i<=n/2)
    {
        j=1;
        while(j<=n/2)
        {
            k=n-i+1;l=n-j+1;
            if(m[it->first]<4)
            {
                ++it;
                ++y;
                if(y>z || it->first>1000 || !seen[it->first])
                {
                    cout<<"NO";
                    return 0;
                }
                continue;
            }
            t1=it->first;
            ans[i][j]=ans[i][l]=ans[k][j]=ans[k][l]=t1;
            m[it->first]-=4;
            if(m[it->first]==0)
            {
                seen[it->first]=0;
                m.erase(it->first);
                --y;
                --z;
            }
            ++j;
        }
        ++i;
    }
    if(n%2==0)
    {
        print(ans,n);
        return 0;
    }

    y=1;
    z=m.size();
    i=1;j=n/2+1;
    it=m.begin();
    while(i<=n/2)
    {
        k=n-i+1;
        if(m[it->first]<2)
        {
            ++it;
            ++y;
            if(y>z || it->first>1000 || !seen[it->first])
            {
                cout<<"NO";
                return 0;
            }
            continue;
        }
        t1=it->first;
        ans[i][j]=ans[k][j]=t1;
        m[it->first]-=2;
        if(m[it->first]==0)
        {
            seen[it->first]=0;
            m.erase(it->first);
            --y;
            --z;
        }
        ++i;
    }

    j=1;i=n/2+1;
    it=m.begin();
    y=1;
    z=m.size();
    while(j<=n/2)
    {
        k=n-j+1;
        if(m[it->first]<2)
        {
            ++it;
            ++y;
            if(y>z || it->first>1000 || !seen[it->first])
            {
                cout<<"NO";
                return 0;
            }
            continue;
        }
        t1=it->first;
        ans[i][j]=ans[i][k]=t1;
        m[it->first]-=2;
        if(m[it->first]==0)
        {
            seen[it->first]=0;
            m.erase(it->first);
            --y;
            --z;
        }
        ++j;
    }
    it=m.begin();
    ans[n/2+1][n/2+1]=it->first;
    print(ans,n);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define d double
#define pii pair<int,int>
#define pb push_back
#define cases int t;cin>>t;while(t--)
#define N 1003
//int mod=1e9+7;
//int mod=998244353;
int freq[N];
map<int,int> m;
bool seen[N];

void print(int ans[21][21],int n)
{
    cout<<"YES\n";
    int i,j;
    for(i=1;i<=n;++i)
    {
        for(j=1;j<=n;++j)
            cout<<ans[i][j]<<" ";
        cout<<"\n";
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    m.clear();
    fill(seen,seen+N,0);
    fill(freq,freq+N,0);
    int n;
    cin>>n;
    int a[n*n+4];
    int i,j,k,l,x;
    for(i=1;i<=n*n;++i)
    {
        cin>>a[i];
        seen[a[i]]=1;
        m[a[i]]++;
    }

    int ans[21][21];
    auto it=m.begin();
    i=1;j=1;
    k=n-i+1;l=n-j+1;         //[i][j] = [i][l] = [k][j] = [k][l]
    int t1,t2,t3,t4;

    auto it2=m.end();
    while(i<=n/2)
    {
        j=1;
        while(j<=n/2)
        {
            if(it==m.end() || it->first>1000 || seen[it->first]==0)
            {
                cout<<"NO";
                return 0;
            }
            k=n-i+1;l=n-j+1;
            if(m[it->first]<4)
            {
                ++it;
                if(it==m.end() || it->first>1000 || seen[it->first]==0)
                {
                    cout<<"NO";
                    return 0;
                }
                continue;
            }
            t1=it->first;
            ans[i][j]=ans[i][l]=ans[k][j]=ans[k][l]=t1;
            m[it->first]-=4;
            if(m[it->first]==0)
            {
                m.erase(it->first);
            }
            ++j;
        }
        ++i;
    }
    if(n%2==0)
    {
        print(ans,n);
        return 0;
    }

    i=1;j=n/2+1;
    it=m.begin();
    while(i<=n/2)
    {
        k=n-i+1;
        if(it==m.end() || it->first>1000 || seen[it->first]==0)
        {
            cout<<"NO";
            return 0;
        }
        if(m[it->first]<2)
        {
            ++it;
            if(it==m.end() || it->first>1000 || seen[it->first]==0)
            {
                cout<<"NO";
                return 0;
            }
            continue;
        }
        t1=it->first;
        ans[i][j]=ans[k][j]=t1;
        m[it->first]-=2;
        if(m[it->first]==0)
        {
            m.erase(it->first);
        }
        ++i;
    }

    j=1;i=n/2+1;
    it=m.begin();
    while(j<=n/2)
    {
        k=n-j+1;
        if(it==m.end() || it->first>1000 || seen[it->first]==0)
        {
            cout<<"NO";
            return 0;
        }
        if(m[it->first]<2)
        {
            ++it;
            if(it==m.end() || it->first>1000 || seen[it->first]==0)
            {
                cout<<"NO";
                return 0;
            }
            continue;
        }
        t1=it->first;
        ans[i][j]=ans[i][k]=t1;
        m[it->first]-=2;
        if(m[it->first]==0)
        {
            m.erase(it->first);
        }
        ++j;
    }
    it=m.begin();
    ans[n/2+1][n/2+1]=it->first;
    print(ans,n);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PI acos(-1)

typedef long long lli;
const lli MaX = 100005 , infi =1110111110111 , mod = 1000000007 ;
typedef pair<int,int> pii;
const int MX = 200005;

lli n ,a[2200] , occ[5000] , mat[1000][1000],x,err;
vector<int> v,vv;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=1;i<=n*n;i++)
    {
        cin>>a[i];
        occ[a[i]]++;
    }
    for(int i=1;i<=1000;i++)
    {
        if(occ[i]%4>1)vv.push_back(i),occ[i]-=2;
        err+=occ[i]%4==1;
        if(occ[i]%4==1)x=i;
        for(int j=0;j<occ[i]/4;j++)v.push_back(i);

    }
    for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)mat[i][j]=x;
    if( (n%2==0&&err) || (n%2&&err!=1) || (n%2&&vv.size()>n/2) ||(n%2==0&&vv.size()) )return cout<<"NO",0;
    int ii  = 0;
    for(int i=0;i<n/2;i++)
    {
        for(int j=0;j<n/2;j++)
        {
            mat[i][j] = mat[i][n-j-1] = mat[n-i-1][j] = mat[n-i-1][n-j-1] =v[ii];
            ii++;
        }
    }
    for(ii;ii<v.size();ii++)
    {
        vv.push_back(v[ii]);
        vv.push_back(v[ii]);
    }
    int ix = 0;
    if(n%2)
    {
        for(int i=0;i<n/2;i++)
        {
           mat[i][n/2] = mat[n-i-1][n/2] = vv[ix++] ;
        }
        for(int i=0;i<n/2;i++)
        {
            mat[n/2][i] = mat[n/2][n-i-1] = vv[ix++] ;
        }
    }
    cout<<"YES\n";
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cout<<mat[i][j]<<" ";
        }
        cout<<"\n";
    }
    return 0;
}