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 nmax = 600;
void no() {
  puts("NO");
  exit(0);
}
struct tree {
  vector<int> h, res, us, ord;
  vector<tree *> g;
  tree *lft, *rgt, *p;
  vector<vector<pair<int, tree *> > > e;
  void init() {
    e.resize(g.size());
    us.resize(g.size());
    lft = rgt = 0;
    for (int i = 0; i < (int)(g.size()); i++) g[i]->init();
  }
  tree(){};
  tree(int n) {
    p = 0;
    for (int i = 0; i < (int)(n); i++) h.push_back(i);
    for (int i = 0; i < (int)(n); i++) g.push_back(new tree(i, this));
  }
  tree(int n, tree *pr) : p(pr) { h.push_back(n); }
  tree(const vector<tree *> &e, tree *p) : g(e), p(p) {
    for (int i = 0; i < (int)(g.size()); i++) {
      g[i]->p = this;
      for (int j = 0; j < (int)(g[i]->h.size()); j++) h.push_back(g[i]->h[j]);
    }
  }
  int getNum(tree *v) {
    for (int i = 0; i < (int)(g.size()); i++)
      if (g[i] == v) return i;
    return -1;
  }
  void paintR(tree *v, tree *pv) {
    while (v != pv) {
      if (v->p->rgt != 0) return;
      v->p->rgt = v;
      v = v->p;
    }
  }
  void paintL(tree *v, tree *pv) {
    while (v != pv) {
      if (v->p->lft != 0) return;
      v->p->lft = v;
      v = v->p;
    }
  }
  void add(tree *pv, tree *pu, tree *v, tree *u) {
    e[getNum(pv)].push_back(make_pair(getNum(pu), u));
    e[getNum(pu)].push_back(make_pair(getNum(pv), v));
  }
  void dfs(int v, vector<int> &st) {
    if (us[v]) return;
    st.push_back(v);
    us[v] = 1;
    for (int i = 0; i < (int)(e[v].size()); i++) dfs(e[v][i].first, st);
  }
  vector<int> getOrder() {
    vector<int> st, en;
    if (getNum(lft) != -1) dfs(getNum(lft), st);
    if (getNum(rgt) != -1) dfs(getNum(rgt), en);
    for (int i = 0; i < (int)(g.size()); i++) {
      bool done = 1;
      for (int j = 0; j < (int)(e[i].size() - 1); j++)
        if (e[i][j].first != e[i][j + 1].first) done = 0;
      if (done) dfs(i, st);
    }
    for (int i = 0; i < (int)(g.size()); i++) dfs(i, st);
    for (int i = (int)(en.size()) - 1; i >= 0; i--) st.push_back(en[i]);
    return st;
  }
  void solve() {
    if (g.size() == 0) {
      res = h;
      return;
    }
    ord = getOrder();
    for (int i = 0; i < (int)(ord.size() - 1); i++) {
      int v = ord[i], u = ord[i + 1];
      for (int j = 0; j < (int)(e[v].size()); j++)
        if (e[v][j].first == u) paintL(e[v][j].second, this);
      for (int j = 0; j < (int)(e[u].size()); j++)
        if (e[u][j].first == v) paintR(e[u][j].second, this);
    }
    for (int i = 0; i < (int)(ord.size()); i++) {
      g[ord[i]]->solve();
      for (int j = 0; j < (int)(g[ord[i]]->res.size()); j++)
        res.push_back(g[ord[i]]->res[j]);
    }
  }
};
typedef tree *ptree;
int n;
char a[nmax][nmax], b[nmax][nmax];
ptree root;
void calcF(ptree v, int idx, bool &f1, bool &f2) {
  f1 = f2 = 1;
  for (int i = 0; i < (int)(v->h.size()); i++) {
    if (a[idx][v->h[i]] == '1')
      f1 = 0;
    else
      f2 = 0;
    if (!f1 && !f2) return;
  }
}
bool update(ptree v, int idx) {
  bool f1, f2;
  calcF(v, idx, f1, f2);
  if (f1) return 0;
  if (f2) return 1;
  vector<ptree> ng;
  bool done = 1;
  for (int i = 0; i < (int)(v->g.size()); i++)
    if (update(v->g[i], idx))
      ng.push_back(v->g[i]);
    else
      done = 0;
  if (done) return 1;
  if (ng.size() <= 1) return 0;
  int m = 0, j = 0;
  for (int i = 0; i < (int)(v->g.size()); i++) {
    while (j < ng.size() && v->g[i] == ng[j]) j++, i++;
    if (i < v->g.size()) v->g[m++] = v->g[i];
  }
  v->g.resize(m);
  v->g.push_back(new tree(ng, v));
  return 0;
}
ptree process(ptree v, int idx) {
  bool f1, f2;
  calcF(v, idx, f1, f2);
  if (f1) return 0;
  if (f2) return v;
  vector<pair<ptree, ptree> > tc;
  for (int i = 0; i < (int)(v->g.size()); i++) {
    ptree buf = process(v->g[i], idx);
    if (buf != 0) tc.push_back(make_pair(buf, v->g[i]));
  }
  if (tc.size() == 1) return tc[0].first;
  if (tc.size() >= 4) no();
  if (tc.size() == 3) {
    for (int i = 0; i < (int)(2); i++)
      if (tc[1 + i].first == tc[1 + i].second) swap(tc[0], tc[1 + i]);
    if (tc[0].first != tc[0].second) no();
  }
  for (int i = 1; i < (int)tc.size(); i++)
    v->add(tc[0].second, tc[i].second, tc[0].first, tc[i].first);
  for (int i = 0; i < (int)(tc.size()); i++)
    if (tc[i].first == tc[i].second) return tc[i].first;
  return 0;
}
bool check() {
  for (int i = 0; i < (int)(n); i++) {
    int cnt = b[i][0] - '0';
    for (int j = 0; j < (int)(n - 1); j++)
      if (b[i][j] == '0' && b[i][j + 1] == '1') cnt++;
    if (cnt > 1) return 0;
  }
  return 1;
}
int main() {
  scanf("%d\n", &n);
  root = new tree(n);
  for (int i = 0; i < (int)(n); i++) {
    gets(a[i]);
    update(root, i);
  }
  root->init();
  for (int i = 0; i < (int)(n); i++) process(root, i);
  root->solve();
  vector<int> res = root->res;
  for (int i = 0; i < (int)(n); i++)
    for (int j = 0; j < (int)(n); j++) b[i][j] = a[i][res[j]];
  if (!check()) no();
  puts("YES");
  for (int i = 0; i < (int)(n); i++) puts(b[i]);
  return 0;
}