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;
const int N = 512;
namespace PQ {
const int P = -1, Q = -2;
enum col { White = 0, Gray, Black };
struct node {
  int v;
  node *son, *bro;
  col c;
  inline node() {}
  inline node(int v, node *son, node *bro, col c)
      : v(v), son(son), bro(bro), c(c) {}
} pool[N << 2], *bin;
int pt;
inline void init() { pt = 0, bin = 0; }
inline node *NEW() {
  if (bin) {
    node *p = bin;
    bin = bin->bro;
    return p;
  } else
    return pool + (pt++);
}
inline void DELETE(node *p) { p->bro = bin, bin = p; }
inline node *newSubtree(node *p, int k) {
  return p->bro ? (new (NEW()) node(k, p, 0, White)) : p;
}
inline node **tail(node *p) {
  if (!p) return NULL;
  for (; p->bro; p = p->bro)
    ;
  return &p->bro;
}
inline void add(node *p, node *q) { *(tail(p)) = q; }
inline void reverse(node *p) {
  node *pre = 0, *nex, *i;
  for (i = p->son; i; i = nex) nex = i->bro, i->bro = pre, pre = i;
  p->son = pre;
}
inline bool check(node *p) {
  int cnt[3] = {0, 0, 0}, lc = 0;
  for (p = p->son; p; p = p->bro) {
    if (p->c < lc) return 0;
    lc = p->c, cnt[p->c]++;
  }
  return cnt[Gray] <= 1;
}
inline void assign(node *p) {
  if (p->v == P) {
    node *h = 0, *s, **hl = &h, **sl = &p->son;
    for (s = *sl; s; s = s->bro)
      if (s->c == Gray)
        *hl = s, hl = &s->bro;
      else
        *sl = s, sl = &s->bro;
    *sl = 0, sl = &p->son;
    for (s = p->son; s; s = s->bro)
      if (s->c == Black)
        *hl = s, hl = &s->bro;
      else
        *sl = s, sl = &s->bro;
    *sl = h;
    *hl = 0;
  } else if (!check(p))
    reverse(p);
}
inline node *splitWhite(node *p) {
  node **q = &p->son;
  for (p = p->son; p; q = &p->bro, p = p->bro)
    if (p->c != White) {
      *q = 0;
      return p;
    }
  return 0;
}
inline int cntGray(node *p) {
  int cnt = 0;
  for (; p && p->c == Gray; p = p->bro) ++cnt;
  return cnt;
}
struct PQTree {
  int n;
  node *rt;
  inline void init(int n) {
    this->n = n;
    int i;
    rt = new (NEW()) node(P, 0, 0, White);
    node **lt = &rt->son;
    for (i = 1; i <= n; i++) {
      *lt = new (NEW()) node(i, 0, 0, White);
      lt = &(*lt)->bro;
    }
  }
  char *lim;
  inline void walk(node *p, int *&out) {
    for (node *s = p->son; s; s = s->bro)
      if (s->v > 0)
        *++out = s->v;
      else
        walk(s, out);
  }
  inline void travel(int *out) { walk(rt, out); }
  inline void predfs(node *p) {
    if (p->v > 0)
      p->c = lim[p->v] == '1' ? Black : White;
    else {
      int s1 = 0, s2 = 1;
      node *s;
      for (s = p->son; s; s = s->bro) {
        predfs(s);
        s1 |= s->c != White;
        s2 &= s->c == Black;
      }
      p->c = (s1 ? s2 ? Black : Gray : White);
    }
  }
  inline bool insdfs(node *p) {
    if (p->v > 0 || p->c != Gray) return 1;
    if (p->v == P) {
      assign(p);
      node *h = splitWhite(p);
      if (!p->son) {
        p->son = h;
        int nGray = cntGray(h);
        if (nGray == 0)
          return 1;
        else if (nGray == 1) {
          p->v = Q;
          node *np = h, *nq = newSubtree(h->bro, P);
          nq->c = Black;
          p->son = np, np->bro = nq;
        } else if (nGray == 2) {
          p->v = Q;
          node *g1 = h, *g2 = g1->bro;
          if (g2->bro) {
            node *nq = newSubtree(g2->bro, P);
            nq->c = Black;
            p->son = g1, g1->bro = nq, nq->bro = g2, g2->bro = 0;
          } else {
            p->son = g1, g1->bro = g2;
          }
        }
      } else {
        node *np = newSubtree(h, P);
        np->c = Gray;
        np->bro = p->son, p->son = np;
        return insdfs(np);
      }
    }
    node *fs = 0, *ls = 0;
    for (node *s = p->son; s; s = s->bro)
      if (s->c != White) {
        if (!fs) fs = s;
        ls = s;
      }
    if (fs == ls) return insdfs(fs);
    for (node *s = fs->bro; s != ls; s = s->bro)
      if (s->c != Black) return 0;
    int ti;
    for (ti = 0; ti <= 1; ti++) {
      if (ti == 1) reverse(p), swap(fs, ls);
      while (fs->c != Black) {
        assign(fs);
        if (!check(fs)) return 0;
        node *h = splitWhite(fs);
        if (fs->v == P) {
          int nGray = cntGray(h);
          if (!nGray) {
            h = newSubtree(h, P);
            h->c = Black;
          } else {
            if (h->bro) {
              h->bro = newSubtree(h->bro, P);
              h->bro->c = Black;
            }
          }
        } else {
          if (fs->son) {
            node *nex = fs->son;
            while (nex->bro) nex = nex->bro;
            nex->bro = fs->bro, fs->bro = fs->son, fs->son = 0;
            fs = nex;
          }
        }
        add(h, fs->bro);
        fs->bro = h;
        fs = fs->bro;
      }
      if (ti == 1) reverse(p), swap(fs, ls);
    }
    for (node *s = p->son, **pre = &p->son; s; s = *pre) {
      if (s->v > 0)
        pre = &s->bro;
      else {
        if (!s->son)
          *pre = s->bro, DELETE(s);
        else if (!s->son->bro)
          *pre = s->son, s->son->bro = s->bro, DELETE(s);
        else
          pre = &s->bro;
      }
    }
    return 1;
  }
  inline bool ins(char *s) {
    lim = s;
    predfs(rt);
    return insdfs(rt);
  }
};
}  // namespace PQ
char s[N][N];
int res[N];
PQ::PQTree T;
int main() {
  int i, j, n;
  scanf("%d", &n);
  T.init(n);
  for (i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  for (i = 1; i <= n; i++)
    if (!T.ins(s[i])) {
      printf("NO");
      return 0;
    }
  T.travel(res);
  printf("YES\n");
  for (i = 1; i <= n; putchar('\n'), i++)
    for (j = 1; j <= n; j++) putchar(s[i][res[j]]);
  return 0;
}