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>
using namespace std;
int Read() {
  char c;
  while (c = getchar(), (c != '-') && (c < '0' || c > '9'))
    ;
  bool neg = (c == '-');
  int ret = (neg ? 0 : c - 48);
  while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + c - 48;
  return neg ? -ret : ret;
}
const int MAXN = 505;
vector<int> rs, cs;
int N, cnt[MAXN], a[MAXN][MAXN], ans[MAXN], out[MAXN][MAXN];
char s[MAXN];
bool mk[MAXN];
void init() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%s", s + 1);
    for (int j = 1; j <= N; j++) {
      a[i][j] = s[j] - 48;
      cnt[i] += a[i][j];
    }
    cs.push_back(i);
    if (cnt[i] && cnt[i] < N) rs.push_back(i);
  }
}
bool Split(vector<vector<int> > &cb, vector<vector<int> > &cr, int K) {
  int inc = 0;
  vector<vector<int> > nb, nr;
  for (int i = 0; i <= ((int)(cb).size() - 1); i++) {
    vector<int> b[2];
    for (int j = 0; j <= ((int)(cb[i]).size() - 1); j++)
      b[a[K][cb[i][j]]].push_back(cb[i][j]);
    int flag = 1, sz = nb.size();
    if (!inc && i < ((int)(cb).size() - 1)) {
      if (b[0].size()) nb.push_back(b[0]);
      if (b[1].size()) nb.push_back(b[1]), inc = 1;
      flag ^= 1;
    } else {
      if (b[1].size()) {
        if (inc == 2) {
          reverse(cb.begin(), cb.end() - 1);
          reverse(cr.begin(), cr.end() - 1);
          return 0;
        }
        nb.push_back(b[1]);
      }
      if (b[0].size()) nb.push_back(b[0]), inc = 2;
    }
    nr.resize(nb.size());
    if (b[0].size() && b[1].size()) {
      int v = b[0].size() >= b[1].size();
      for (int j = 0; j <= ((int)(cr[i]).size() - 1); j++) {
        int cc = 0, cd = cr[i][j];
        if (cd != K) {
          for (int k = 0; k <= ((int)(b[v]).size() - 1); k++)
            cc += a[cd][b[v][k]];
          if (cc && cc != cnt[cd])
            mk[cd] = 1;
          else if (cc == cnt[cd])
            nr[sz + (v ^ flag)].push_back(cd);
          else
            nr[sz + (v ^ flag ^ 1)].push_back(cd);
        }
      }
    } else if (b[0].size() || b[1].size())
      nr[nr.size() - 1] = cr[i];
    if (i == ((int)(cb).size() - 1) && !b[0].size())
      nr.push_back(vector<int>()), nb.push_back(vector<int>());
  }
  return cb = nb, cr = nr, 1;
}
bool Cut(vector<vector<int> > &cb, vector<vector<int> > &cr, vector<int> &rs,
         int d) {
  int K = rs[d];
  swap(rs[d], rs.back()), rs.pop_back();
  if (Split(cb, cr, K)) return 1;
  return Split(cb, cr, K);
}
bool Solve(vector<int> &rs, vector<int> &cs, int st) {
  for (int i = 0; i <= ((int)(rs).size() - 1); i++)
    if (mk[rs[i]] || cnt[rs[i]] == cs.size())
      swap(rs[i], rs.back()), rs.pop_back();
  if (!rs.size()) {
    for (int i = 0; i <= ((int)(cs).size() - 1); i++) ans[cs[i]] = st + i;
    return 1;
  };
  int most = 0;
  for (int i = 1; i <= ((int)(rs).size() - 1); i++)
    if (cnt[rs[i]] > cnt[rs[most]]) most = i;
  vector<vector<int> > cb, cr;
  cr.push_back(rs), cb.push_back(cs);
  mk[rs[most]] = 1;
  if (!Cut(cb, cr, rs, most)) return 0;
  for (; rs.size();) {
    int fin = -1;
    for (int i = 0; i <= ((int)(rs).size() - 1); i++)
      if (mk[rs[i]]) {
        fin = i;
        break;
      }
    if (fin < 0) {
      for (int i = 0; i <= ((int)(cb).size() - 1); i++) {
        if (!Solve(cr[i], cb[i], st)) return 0;
        st += cb[i].size();
      }
      return 1;
    } else if (!Cut(cb, cr, rs, fin))
      return 0;
  }
  for (int i = 0; i <= ((int)(cb).size() - 1); i++) {
    if (!Solve(cr[i], cb[i], st)) return 0;
    st += cb[i].size();
  }
  return 1;
}
void work() {
  if (Solve(rs, cs, 1)) {
    puts("YES");
    for (int i = 1; i <= N; i++)
      for (int j = 1; j <= N; j++) out[i][ans[j]] = a[i][j];
    for (int i = 1; i <= N; i++) {
      for (int j = 1; j <= N; j++) printf("%d", out[i][j]);
      puts("");
    }
  } else
    puts("NO");
}
int main() {
  init();
  work();
  return 0;
}