Problem: Let's consider an n × n square matrix, consisting of digits one and zero.

We'll consider a matrix good, if it meets the following condition: in each row of the matrix all ones go in one group. That is, each row of the matrix looks like that 00...0011...1100...00 (or simply consists of zeroes if it has no ones).

You are given matrix a of size n × n, consisting of zeroes and ones. Your task is to determine whether you can get a good matrix b from it by rearranging the columns or not.

Input

The first line contains integer n (1 ≤ n ≤ 500) — the size of matrix a.

Each of n following lines contains n characters "0" and "1" — matrix a. Note that the characters are written without separators.

Output

Print "YES" in the first line, if you can rearrange the matrix columns so as to get a good matrix b. In the next n lines print the good matrix b. If there are multiple answers, you are allowed to print any of them.

If it is impossible to get a good matrix, print "NO".

Examples

Input

6
100010
110110
011001
010010
000100
011001


Output

YES
011000
111100
000111
001100
100000
000111


Input

3
110
101
011


Output

NO

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:76777216")
using namespace std;
const int INF = 1000000000;
const int MAX = 1507;
const int MAX2 = 7000;
const int BASE = 1000000000;
int n, m;
char A[MAX][MAX];
int PCol[MAX];
int PRow[MAX];
int Row[MAX];
void sort_left(int row, int l, int r) {
  vector<int> a, b;
  for (int i = (l); i < (r + 1); ++i)
    if (A[row][PCol[i]] == '1')
      a.push_back(PCol[i]);
    else
      b.push_back(PCol[i]);
  for (int i = (0); i < ((int)a.size()); ++i) PCol[l + i] = a[i];
  for (int i = (0); i < ((int)b.size()); ++i)
    PCol[l + (int)a.size() + i] = b[i];
}
void sort_right(int row, int l, int r) {
  vector<int> a, b;
  for (int i = (l); i < (r + 1); ++i)
    if (A[row][PCol[i]] == '1')
      b.push_back(PCol[i]);
    else
      a.push_back(PCol[i]);
  for (int i = (0); i < ((int)a.size()); ++i) PCol[l + i] = a[i];
  for (int i = (0); i < ((int)b.size()); ++i)
    PCol[l + (int)a.size() + i] = b[i];
}
void shift_left(int l, int r, int m) {
  vector<int> a;
  for (int i = (m); i < (r + 1); ++i) a.push_back(PCol[i]);
  for (int i = (l); i < (m); ++i) a.push_back(PCol[i]);
  for (int i = (l); i < (r + 1); ++i) PCol[i] = a[i - l];
}
bool same(vector<int> E, int a, int b) {
  for (int i = (0); i < ((int)E.size()); ++i)
    if (A[E[i]][PCol[a]] != A[E[i]][PCol[b]]) return 0;
  return 1;
}
void F(int row, int l, int r) {
  if (row >= n) return;
  int val = 0, pos = 0;
  for (int i = (row); i < (n); ++i) {
    int cnt = 0;
    for (int j = (l); j < (r + 1); ++j)
      if (A[i][PCol[j]] == '1') ++cnt;
    if (cnt > val) {
      val = cnt;
      pos = i;
    }
  }
  if (val == 0) return;
  for (int i = (0); i < (n); ++i) swap(A[row][i], A[pos][i]);
  swap(PRow[row], PRow[pos]);
  if (val == r - l + 1) {
    F(row + 1, l, r);
    return;
  }
  sort_left(row, l, r);
  vector<int> E;
  int C[MAX];
  int U[MAX];
  for (int i = (0); i < (n); ++i) U[i] = 0;
  vector<pair<int, int> > Q;
  E.push_back(row);
  for (int it = (row + 1); it < (n); ++it) {
    Q.clear();
    int j = l;
    while (j <= r) {
      int k = 1;
      while (j + k <= r && same(E, j, j + k)) ++k;
      Q.push_back(make_pair(j, j + k - 1));
      j += k;
    }
    int pos = 0, cnt = 0, i = -1;
    for (int ii = (row + 1); ii < (n); ++ii) {
      if (U[ii] == 1) continue;
      for (int j = (0); j < ((int)Q.size()); ++j) C[j] = 0;
      pos = 0;
      for (int j = (l); j < (r + 1); ++j) {
        if (A[ii][PCol[j]] == '0') continue;
        while (Q[pos].second < j) ++pos;
        ++C[pos];
      }
      cnt = 0;
      for (int j = (0); j < ((int)Q.size()); ++j)
        if (C[j] != 0) ++cnt;
      if (cnt > 1) {
        i = ii;
        break;
      }
    }
    if (i == -1) break;
    U[i] = 1;
    E.push_back(i);
    bool full = 1;
    for (int j = (1); j < ((int)Q.size() - 1); ++j)
      if (C[j] != Q[j].second - Q[j].first + 1) full = 0;
    if (!full && C[0] > 0 && C[(int)Q.size() - 1] > 0) {
      for (int j = (0); j < ((int)Q.size() - 1); ++j)
        sort_left(i, Q[j].first, Q[j].second);
      sort_left(i, Q.back().first, Q.back().second);
      shift_left(l, Q.back().first + C[(int)Q.size() - 1] - 1, Q.back().first);
      sort_right(i, Q[0].first, Q[0].first + C[(int)Q.size() - 1] - 1);
    } else {
      for (int j = (0); j < ((int)Q.size()); ++j)
        if (C[j] > 0) {
          sort_right(i, Q[j].first, Q[j].second);
          break;
        }
      for (int j = ((int)Q.size()) - 1; j >= (0); --j)
        if (C[j] > 0) {
          sort_left(i, Q[j].first, Q[j].second);
          break;
        }
    }
  }
  for (int i = (0); i < ((int)Q.size()); ++i)
    F(row + 1, Q[i].first, Q[i].second);
}
int main() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) {
    scanf("%s", A[i]);
  }
  for (int i = (0); i < (n); ++i) {
    PRow[i] = i;
    PCol[i] = i;
  }
  F(0, 0, n - 1);
  bool ok = 1;
  for (int i = (0); i < (n); ++i) {
    int cnt = 0;
    for (int j = (0); j < (n); ++j) {
      if (A[i][PCol[j]] == '1' && cnt == 0) ++cnt;
      if (A[i][PCol[j]] == '0' && cnt == 1) ++cnt;
      if (A[i][PCol[j]] == '1' && cnt > 1) ok = 0;
    }
  }
  if (!ok) {
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  for (int i = (0); i < (n); ++i) Row[PRow[i]] = i;
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (n); ++j) cout << A[Row[i]][PCol[j]];
    cout << endl;
  }
  return 0;
}