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;
bool a[510][510];
int seq[510], seq0[510], seq1[510], _R[510];
int llen[510], L[510], R[510], S[510], T[510];
char s[510];
bool b[510], c[510];
int n;
inline void fail() {
  printf("NO\n");
  exit(0);
}
void update() {
  int i, j;
  for (i = 1; i <= n; i++) {
    L[i] = n + 1;
    R[i] = 0;
    for (j = 1; j <= n; j++)
      if (a[i][seq[j]]) {
        L[i] = min(L[i], j);
        R[i] = max(R[i], j);
      }
  }
}
int getsum(int i, int l, int r) {
  int j, s;
  s = 0;
  for (j = l; j <= r; j++)
    if (a[i][seq[j]]) s++;
  return s;
}
void split(int l, int x) {
  int i;
  for (i = l; i <= x - 1; i++) _R[i] = x - 1;
}
int rearrange(int l, int r, int x, bool flag) {
  int i, j, k;
  j = 0;
  k = 0;
  for (i = l; i <= r; i++)
    if (a[x][seq[i]] == flag) {
      j++;
      seq0[j] = seq[i];
    } else {
      k++;
      seq1[k] = seq[i];
    }
  for (i = 1; i <= j; i++) seq[i + l - 1] = seq0[i];
  for (i = 1; i <= k; i++) seq[i + l + j - 1] = seq1[i];
  return j + l;
}
void work(int l, int r) {
  int i, j, s, len, x, y, segnum, l0, r0, tot;
  bool flag;
  len = -1;
  memset(b, false, sizeof(b));
  for (i = 1; i <= n; i++) {
    s = getsum(i, l, r);
    if ((s == 0) || (s == r - l + 1))
      b[i] = true;
    else if (s > len) {
      len = s;
      x = i;
    }
  }
  if (len < 0) return;
  b[x] = true;
  llen[1] = 0;
  rearrange(l, r, x, true);
  for (i = 1; i <= n; i++)
    if (!b[i] && getsum(i, len + l, r)) {
      s = getsum(i, l, len + l - 1);
      if (s > llen[1]) {
        llen[1] = s;
        y = i;
      }
    }
  tot = 1;
  llen[1] = len - llen[1];
  if (llen[1] < len) rearrange(l, l + len - 1, y, false);
  while (llen[tot]) {
    memset(c, false, sizeof(c));
    for (i = 1; i <= n; i++)
      if (!b[i] && getsum(i, l, l + llen[tot] - 1)) {
        for (j = len + l; j <= r; j++)
          if (a[i][seq[j]]) c[j] = true;
      }
    tot++;
    llen[tot] = 0;
    for (i = r; i >= l; i--)
      if (c[i]) {
        llen[tot]++;
        seq0[llen[tot]] = seq[i];
      } else
        seq[i + llen[tot]] = seq[i];
    for (i = 1; i <= llen[tot]; i++) seq[i + l - 1] = seq0[i];
    len += llen[tot];
  }
  split(l, l + len);
  for (i = tot - 1; i >= 1; i--) llen[i] += llen[i + 1];
  for (i = 1; i <= tot - 1; i++) split(l, l + llen[i]);
  update();
  do {
    flag = false;
    for (i = 1; i <= n; i++)
      if (!b[i] && (R[i] > _R[L[i]])) {
        flag = true;
        b[i] = true;
        segnum = 0;
        l0 = n + 1;
        r0 = 0;
        for (j = l; j <= r; j++)
          if ((j == l) || (_R[j] != _R[j - 1])) {
            segnum++;
            T[segnum] = _R[j] - j + 1;
            S[segnum] = getsum(i, j, _R[j]);
            if (S[segnum]) {
              l0 = min(l0, j);
              r0 = max(r0, _R[j]);
            }
          }
        x = l;
        for (j = 1; j <= segnum; j++) {
          if ((x >= l0) && (_R[x] <= r0)) {
            if (x == l0) {
              y = rearrange(x, _R[x], i, false);
              split(x, y);
            } else if (_R[x] == r0) {
              y = rearrange(x, _R[x], i, true);
              split(x, y);
            } else if (S[j] != T[j])
              fail();
          }
          x += T[j];
        }
        break;
      }
    update();
  } while (flag);
  for (i = l; i <= r; i++)
    if ((i == l) || (_R[i] != _R[i - 1])) work(i, _R[i]);
}
int main() {
  int i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    for (j = 1; j <= n; j++) a[i][j] = (s[j] == '1');
  }
  memset(b, false, sizeof(b));
  for (i = 1; i <= n; i++) {
    seq[i] = i;
    _R[i] = n;
  }
  work(1, n);
  printf("YES\n");
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) printf("%d", int(a[i][seq[j]]));
    printf("\n");
  }
  return 0;
}