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 long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = 3.1415926535897932384626433832795;
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T>
T abs(T x) {
  return x < 0 ? -x : x;
}
void no() {
  puts("NO");
  exit(0);
}
double rr = 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) {
    h.clear();
    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) {
    int npv = getNum(pv);
    int npu = getNum(pu);
    e[npv].push_back(make_pair(npu, u));
    e[npu].push_back(make_pair(npv, v));
  }
  void dfs(int v, vector<int> &st) {
    st.push_back(v);
    us[v] = 1;
    for (int i = 0; i < (int)(e[v].size()); i++)
      if (!us[e[v][i].first]) dfs(e[v][i].first, st);
  }
  vector<int> getOrder() {
    vector<int> st, en;
    if (lft != 0) {
      int v = getNum(lft);
      if (!us[v]) dfs(v, st);
    }
    if (rgt != 0) {
      int v = getNum(rgt);
      if (!us[v]) dfs(v, en);
    }
    for (int i = 0; i < (int)(g.size()); i++) {
      set<int> qwe;
      for (int j = 0; j < (int)(e[i].size()); j++) qwe.insert(e[i][j].first);
      if (!us[i] && qwe.size() == 1) dfs(i, st);
    }
    for (int i = 0; i < (int)(g.size()); i++) {
      if (!us[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)(g.size()); i++) g[i]->solve();
    for (int i = 0; i < (int)(ord.size()); i++)
      for (int j = 0; j < (int)(g[ord[i]]->res.size()); j++)
        res.push_back(g[ord[i]]->res[j]);
  }
};
typedef tree *ptree;
const int nmax = 600;
int n;
char a[nmax][nmax], b[nmax][nmax];
ptree root;
vector<ptree> tc;
bool update(ptree v, int idx) {
  if (v->g.size() == 0) {
    if (a[idx][v->h[0]] == '1') return 1;
    return 0;
  }
  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;
  rr -= clock();
  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));
  rr += clock();
  return 0;
}
bool check() {
  for (int i = 0; i < (int)(n); i++) {
    int cnt = 0;
    for (int j = 0; j < (int)(n - 1); j++)
      if (b[i][j] == '0' && b[i][j + 1] == '1') cnt++;
    if (b[i][0] == '1') cnt++;
    if (cnt > 1) return 0;
  }
  return 1;
}
ptree process(ptree v, int idx) {
  bool f1, f2;
  f1 = f2 = 1;
  for (int i = 0; i < (int)(v->h.size()); i++) {
    if (a[idx][v->h[i]] == '1') f1 = 0;
    if (a[idx][v->h[i]] == '0') f2 = 0;
  }
  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() == 2) {
    v->add(tc[0].second, tc[1].second, tc[0].first, tc[1].first);
    if (tc[0].first == tc[0].second) return tc[0].first;
    if (tc[1].first == tc[1].second) return tc[1].second;
    return 0;
  }
  if (tc.size() == 3) {
    if (tc[1].first == tc[1].second) swap(tc[0], tc[1]);
    if (tc[2].first == tc[2].second) swap(tc[0], tc[2]);
    if (tc[0].first != tc[0].second) no();
    v->add(tc[0].second, tc[1].second, tc[0].first, tc[1].first);
    v->add(tc[0].second, tc[2].second, tc[0].first, tc[2].first);
    return tc[0].first;
  }
  if (tc.size() >= 4) no();
  return 0;
}
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++) {
    for (int j = 0; j < (int)(n); j++) {
      printf("%c", b[i][j]);
    }
    puts("");
  }
  return 0;
}