#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);
}
struct tree {
  vector<int> h, cur, res, us, ord;
  vector<tree *> g;
  tree *lft, *rgt;
  vector<vector<pair<int, tree *> > > e;
  tree *p;
  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]);
    }
    sort(h.begin(), h.end());
  }
  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) {
      v->p->rgt = v;
      v = v->p;
    }
  }
  void paintL(tree *v, tree *pv) {
    while (v != pv) {
      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);
      reverse(en.begin(), en.end());
    }
    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 = 0; i < (int)(en.size()); 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];
      int u = ord[i + 1];
      for (int j = 0; j < (int)(e[v].size()); j++)
        if (e[v][j].first == u) {
          if (e[v][j].second->h[0] == 4) cerr << "";
          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]);
    cerr << "";
    cerr << "";
  }
};
typedef tree *ptree;
void cross(const vector<int> &a, const vector<int> &b, vector<int> &c) {
  int pa = 0, push_back = 0;
  while (pa < a.size() && push_back < b.size()) {
    if (a[pa] == b[push_back]) {
      c.push_back(a[pa]);
      pa++;
      push_back++;
      continue;
    }
    if (a[pa] < b[push_back])
      pa++;
    else
      push_back++;
  }
}
bool update(ptree v, const vector<int> &a) {
  vector<int> buf;
  cross(v->h, a, buf);
  if (buf.size() == v->h.size()) return 1;
  if (buf.size() <= 1) return 0;
  vector<ptree> ng;
  for (int i = 0; i < (int)(v->g.size()); i++) {
    if (update(v->g[i], a)) {
      ng.push_back(v->g[i]);
      swap(v->g[i], v->g[v->g.size() - 1]);
      v->g.pop_back();
      i--;
    }
  }
  if (ng.size() == 1 || v->g.size() == 0) {
    for (int i = 0; i < (int)(ng.size()); i++) v->g.push_back(ng[i]);
    ng.clear();
  }
  if (ng.size() > 1) v->g.push_back(new tree(ng, v));
  return 0;
}
void print(ptree v) {
  for (int i = 0; i < (int)(v->h.size()); i++) cout << v->h[i] << " ";
  cout << endl;
  for (int i = 0; i < (int)(v->g.size()); i++) print(v->g[i]);
}
const int nmax = 600;
int n;
char a[nmax][nmax], b[nmax][nmax];
ptree root;
vector<ptree> tc;
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 lca(ptree a, ptree b) {
  while (a != b) {
    if (a->h.size() < b->h.size())
      a = a->p;
    else
      b = b->p;
  }
  return a;
}
ptree under(ptree a, ptree b) {
  while (a->p != b) a = a->p;
  return a;
}
ptree process(ptree v, const vector<int> &a) {
  vector<int> buf;
  cross(v->h, a, buf);
  if (buf.size() == 0) return 0;
  if (buf.size() == v->h.size()) {
    tc.push_back(v);
    return v;
  }
  buf.clear();
  vector<ptree> tc;
  for (int i = 0; i < (int)(v->g.size()); i++) {
    ptree buf = process(v->g[i], a);
    if (buf != 0) {
      tc.push_back(buf);
    }
  }
  if (tc.size() == 4) no();
  if (tc.size() == 1) return tc[0];
  if (tc.size() == 2) {
    ptree v = tc[0], u = tc[1];
    ptree w = lca(v, u);
    ptree pv = under(v, w), pu = under(u, w);
    w->add(pv, pu, v, u);
    if (v == pv) return v;
    if (u == pu) return u;
    return v;
  }
  if (tc.size() == 3) {
    ptree v = tc[0], u = tc[1], m = tc[2];
    ptree w = lca(lca(v, u), m);
    ptree pv = under(v, w), pu = under(u, w), pm = under(m, w);
    if (u == pu) {
      swap(v, u);
      swap(pv, pu);
    }
    if (m == pm) {
      swap(v, m);
      swap(pv, pm);
    }
    if (v != pv) no();
    w->add(pv, pu, v, u);
    w->add(pv, pm, v, m);
    return v;
  }
  return 0;
}
int main() {
  cin >> n;
  for (int i = 0; i < (int)(n); i++)
    for (int j = 0; j < (int)(n); j++) scanf(" %c", &a[i][j]);
  root = new tree(n);
  for (int i = 0; i < (int)(n); i++) {
    vector<int> now;
    for (int j = 0; j < (int)(n); j++)
      if (a[i][j] == '1') now.push_back(j);
    update(root, now);
  }
  root->init();
  for (int i = 0; i < (int)(n); i++) {
    vector<int> now;
    for (int j = 0; j < (int)(n); j++)
      if (a[i][j] == '1') now.push_back(j);
    process(root, now);
    cerr << "";
  }
  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;
}

### Prompt

Your task is to create a cpp solution to the following 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

### Response

```cpp
#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);
}
struct tree {
  vector<int> h, cur, res, us, ord;
  vector<tree *> g;
  tree *lft, *rgt;
  vector<vector<pair<int, tree *> > > e;
  tree *p;
  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]);
    }
    sort(h.begin(), h.end());
  }
  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) {
      v->p->rgt = v;
      v = v->p;
    }
  }
  void paintL(tree *v, tree *pv) {
    while (v != pv) {
      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);
      reverse(en.begin(), en.end());
    }
    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 = 0; i < (int)(en.size()); 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];
      int u = ord[i + 1];
      for (int j = 0; j < (int)(e[v].size()); j++)
        if (e[v][j].first == u) {
          if (e[v][j].second->h[0] == 4) cerr << "";
          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]);
    cerr << "";
    cerr << "";
  }
};
typedef tree *ptree;
void cross(const vector<int> &a, const vector<int> &b, vector<int> &c) {
  int pa = 0, push_back = 0;
  while (pa < a.size() && push_back < b.size()) {
    if (a[pa] == b[push_back]) {
      c.push_back(a[pa]);
      pa++;
      push_back++;
      continue;
    }
    if (a[pa] < b[push_back])
      pa++;
    else
      push_back++;
  }
}
bool update(ptree v, const vector<int> &a) {
  vector<int> buf;
  cross(v->h, a, buf);
  if (buf.size() == v->h.size()) return 1;
  if (buf.size() <= 1) return 0;
  vector<ptree> ng;
  for (int i = 0; i < (int)(v->g.size()); i++) {
    if (update(v->g[i], a)) {
      ng.push_back(v->g[i]);
      swap(v->g[i], v->g[v->g.size() - 1]);
      v->g.pop_back();
      i--;
    }
  }
  if (ng.size() == 1 || v->g.size() == 0) {
    for (int i = 0; i < (int)(ng.size()); i++) v->g.push_back(ng[i]);
    ng.clear();
  }
  if (ng.size() > 1) v->g.push_back(new tree(ng, v));
  return 0;
}
void print(ptree v) {
  for (int i = 0; i < (int)(v->h.size()); i++) cout << v->h[i] << " ";
  cout << endl;
  for (int i = 0; i < (int)(v->g.size()); i++) print(v->g[i]);
}
const int nmax = 600;
int n;
char a[nmax][nmax], b[nmax][nmax];
ptree root;
vector<ptree> tc;
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 lca(ptree a, ptree b) {
  while (a != b) {
    if (a->h.size() < b->h.size())
      a = a->p;
    else
      b = b->p;
  }
  return a;
}
ptree under(ptree a, ptree b) {
  while (a->p != b) a = a->p;
  return a;
}
ptree process(ptree v, const vector<int> &a) {
  vector<int> buf;
  cross(v->h, a, buf);
  if (buf.size() == 0) return 0;
  if (buf.size() == v->h.size()) {
    tc.push_back(v);
    return v;
  }
  buf.clear();
  vector<ptree> tc;
  for (int i = 0; i < (int)(v->g.size()); i++) {
    ptree buf = process(v->g[i], a);
    if (buf != 0) {
      tc.push_back(buf);
    }
  }
  if (tc.size() == 4) no();
  if (tc.size() == 1) return tc[0];
  if (tc.size() == 2) {
    ptree v = tc[0], u = tc[1];
    ptree w = lca(v, u);
    ptree pv = under(v, w), pu = under(u, w);
    w->add(pv, pu, v, u);
    if (v == pv) return v;
    if (u == pu) return u;
    return v;
  }
  if (tc.size() == 3) {
    ptree v = tc[0], u = tc[1], m = tc[2];
    ptree w = lca(lca(v, u), m);
    ptree pv = under(v, w), pu = under(u, w), pm = under(m, w);
    if (u == pu) {
      swap(v, u);
      swap(pv, pu);
    }
    if (m == pm) {
      swap(v, m);
      swap(pv, pm);
    }
    if (v != pv) no();
    w->add(pv, pu, v, u);
    w->add(pv, pm, v, m);
    return v;
  }
  return 0;
}
int main() {
  cin >> n;
  for (int i = 0; i < (int)(n); i++)
    for (int j = 0; j < (int)(n); j++) scanf(" %c", &a[i][j]);
  root = new tree(n);
  for (int i = 0; i < (int)(n); i++) {
    vector<int> now;
    for (int j = 0; j < (int)(n); j++)
      if (a[i][j] == '1') now.push_back(j);
    update(root, now);
  }
  root->init();
  for (int i = 0; i < (int)(n); i++) {
    vector<int> now;
    for (int j = 0; j < (int)(n); j++)
      if (a[i][j] == '1') now.push_back(j);
    process(root, now);
    cerr << "";
  }
  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;
}

```