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;
using LL = long long;
const int oo = 0x3f3f3f3f;
const int maxn = 500;
const int max0 = 1000000;
struct node {
  bool ty = 0;
  bool empty = 0, full = 0;
  vector<node *> child;
  node() = default;
  node(const bool &_ty) : ty(_ty) {}
};
node nd[max0 + 5];
node *rt;
int cur = 0;
int n, m;
void work(node *x);
template <typename T>
inline void clr(T &x) {
  T all;
  all.clear();
  for (auto e : x)
    if (e - nd < m || !e->child.empty()) all.push_back(e);
  x = all;
}
vector<node *> split(node *x) {
  vector<node *> t;
  if (x->full || x->empty) {
    t.push_back(x);
    return t;
  }
  if (x->ty) {
    int l = oo, r = -1;
    if (x->child[0]->empty || ((x->child)[(int((x->child).size())) - 1])->full)
      reverse((x->child).begin(), (x->child).end());
    for (int i = (0), _end_ = ((int((x->child).size()))); i != _end_; ++i)
      if (!x->child[i]->empty) l = min(l, i), r = max(r, i);
    vector<node *> new_child;
    for (int i = (0), _end_ = ((int((x->child).size()))); i != _end_; ++i) {
      if (!x->child[i]->full && i > l && i < r) printf("NO"), exit(0);
      if (i < l || i > r) t.push_back(x->child[i]);
      if (x->child[i]->full)
        t.push_back(x->child[i]);
      else if (i == r) {
        auto tmp = split(x->child[i]);
        copy((tmp).begin(), (tmp).end(), back_inserter(t));
      } else if (i <= l)
        printf("NO"), exit(0);
    }
    return t;
  } else {
    vector<int> yyt, lyc;
    node *owaski = nd + (cur++), *zzj = nd + (cur++);
    owaski->ty = 0;
    zzj->ty = 0;
    t.push_back(zzj);
    bool flag = 0;
    for (int i = (0), _end_ = ((int((x->child).size()))); i != _end_; ++i)
      if (!x->child[i]->empty) {
        if (!x->child[i]->full) {
          if (flag) printf("NO"), exit(0);
          auto tmp = split(x->child[i]);
          copy((tmp).begin(), (tmp).end(), back_inserter(t));
        } else
          zzj->child.push_back(x->child[i]);
      } else
        owaski->child.push_back(x->child[i]);
    t.push_back(owaski);
    return t;
  }
}
void work(node *x) {
  if (x->empty || x->full) return;
  if (x->ty) {
    int l = oo, r = -1;
    for (int i = (0), _end_ = ((int((x->child).size()))); i != _end_; ++i)
      if (!x->child[i]->empty) l = min(l, i), r = max(r, i);
    if (l == r) {
      work(x->child[l]);
      return;
    }
    vector<node *> new_child;
    for (int i = (0), _end_ = ((int((x->child).size()))); i != _end_; ++i) {
      if (!x->child[i]->full && i > l && i < r) printf("NO"), exit(0);
      if (i < l || i > r) new_child.push_back(x->child[i]);
      if (x->child[i]->full)
        new_child.push_back(x->child[i]);
      else if (i == l) {
        auto tmp = split(x->child[i]);
        copy(tmp.rbegin(), tmp.rend(), back_inserter(new_child));
      } else if (i == r) {
        auto tmp = split(x->child[i]);
        copy((tmp).begin(), (tmp).end(), back_inserter(new_child));
      }
    }
    x->child = new_child;
  } else {
    vector<int> yyt;
    node *zzj = nd + (cur++), *lyc = nd + (cur++);
    zzj->ty = 0, lyc->ty = 1;
    int cnt = 0;
    vector<node *> new_child;
    new_child.push_back(lyc);
    int tot = 0;
    for (int i = (0), _end_ = ((int((x->child).size()))); i != _end_; ++i)
      if (!x->child[i]->empty) ++tot;
    for (int i = (0), _end_ = ((int((x->child).size()))); i != _end_; ++i)
      if (!x->child[i]->empty) {
        if (tot == 1) {
          work(x->child[i]);
          return;
        }
        if (!x->child[i]->full) {
          auto tmp = split(x->child[i]);
          if (!cnt)
            copy(tmp.rbegin(), tmp.rend(), back_inserter(lyc->child)),
                lyc->child.push_back(zzj);
          else
            copy((tmp).begin(), (tmp).end(), back_inserter(lyc->child));
          ++cnt;
          if (cnt > 2) printf("NO"), exit(0);
        } else
          zzj->child.push_back(x->child[i]);
      } else
        new_child.push_back(x->child[i]);
    if (!cnt) lyc->child.push_back(zzj);
    x->child = new_child;
  }
}
void dfs(node *rt, char *s) {
  if (rt - nd < m) {
    rt->full = s[rt - nd] == '1', rt->empty = !rt->full;
    return;
  }
  if (rt->child.empty()) {
    rt->full = 0, rt->empty = 1;
    return;
  }
  rt->full = 1, rt->empty = 1;
  for (int i = (0), _end_ = ((int((rt->child).size()))); i != _end_; ++i) {
    dfs(rt->child[i], s);
    rt->empty &= rt->child[i]->empty;
    rt->full &= rt->child[i]->full;
  }
}
void deal(node *rt) {
  if (rt - nd < m) return;
  for (auto &e : rt->child) {
    deal(e);
    if ((int((e->child).size())) == 1) e = e->child[0];
  }
  clr(rt->child);
}
inline void add(char *s) {
  dfs(rt, s);
  work(rt);
  while ((int((rt->child).size())) == 1 && rt->child[0] - nd >= m)
    rt = rt->child[0];
  deal(rt);
}
int pos[maxn + 5];
int cnt = 0;
void get(node *rt) {
  if (rt - nd < m) {
    pos[cnt++] = rt - nd;
    return;
  }
  for (auto e : rt->child) get(e);
}
int main() {
  static char s[maxn + 5][maxn + 5];
  scanf("%d", &n), m = n;
  rt = nd + m;
  rt->ty = 0;
  cur = m + 1;
  for (int i = (0), _end_ = (m); i != _end_; ++i) rt->child.push_back(nd + i);
  for (int i = (0), _end_ = (n); i != _end_; ++i) {
    scanf("%s", s[i]);
    add(s[i]);
  }
  printf("YES\n");
  get(rt);
  for (int i = (0), _end_ = (n); i != _end_; ++i) {
    for (int j = (0), _end_ = (m); j != _end_; ++j) printf("%c", s[i][pos[j]]);
    printf("\n");
  }
  return 0;
}