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 MOD = 998244353;
int n, m;
char mat[1505][1505];
vector<int> ans;
struct pqt {
  int sta[5005], ssiz;
  void rec_id(int x) { sta[ssiz++] = x; }
  int get_id() { return sta[--ssiz]; }
  int tp[5005], cnt;
  vector<int> T[5005];
  void init() {
    cnt = n + 1;
    for (int i = 0; i < (int)(n); i++) tp[i] = -1;
    tp[n] = 0;
    for (int i = 0; i < (int)(n); i++) T[n].push_back(i);
    for (int i = 0; i < (int)(2 * n + 100); i++) rec_id(cnt + i);
  }
  bool hv[5005];
  int hvt[5005], siz[5005];
  void dfs0(int v) {
    if (tp[v] == -1) {
      hvt[v] = hv[v] ? 2 : 1;
      siz[v] = hv[v];
    } else {
      hvt[v] = siz[v] = 0;
      for (int i = 0; i < (int)(T[v].size()); i++) {
        int u = T[v][i];
        dfs0(u);
        hvt[v] |= hvt[u];
        siz[v] += siz[u];
      }
    }
  }
  int findl(int v) {
    for (int i = 0; i < (int)(T[v].size()); i++) {
      int u = T[v][i];
      if (siz[u] == siz[v]) return findl(u);
    }
    return v;
  }
  vector<int> X, Y, Z, V, U[2];
  bool calc(int v, vector<int>& ret) {
    if (tp[v] == 1) {
      if (hvt[T[v][0]] == 2 || (hvt[T[v][0]] == 3 && hvt[T[v].back()] == 1))
        reverse(T[v].begin(), T[v].end());
      int ctp = 1;
      for (int i = 0; i < (int)(T[v].size()); i++) {
        int u = T[v][i];
        if (ctp == 2 && hvt[u] != 2) return false;
        if (hvt[u] == 3) {
          if (!calc(u, ret)) return false;
        } else
          ret.push_back(u);
        if (hvt[u] != 1) ctp = 2;
      }
    } else {
      V.clear();
      for (int i = 0; i < (int)(T[v].size()); i++)
        if (hvt[T[v][i]] == 1) V.push_back(T[v][i]);
      if (V.size() == 1)
        ret.push_back(V[0]);
      else if (V.size() > 1) {
        int nr = get_id();
        tp[nr] = 0;
        T[nr] = V;
        ret.push_back(nr);
      }
      V.clear();
      for (int i = 0; i < (int)(T[v].size()); i++)
        if (hvt[T[v][i]] == 3) V.push_back(T[v][i]);
      if (V.size() == 1) {
        if (!calc(V[0], ret)) return false;
      } else if (V.size() > 1)
        return false;
      V.clear();
      for (int i = 0; i < (int)(T[v].size()); i++)
        if (hvt[T[v][i]] == 2) V.push_back(T[v][i]);
      if (V.size() == 1)
        ret.push_back(V[0]);
      else if (V.size() > 1) {
        int nr = get_id();
        tp[nr] = 0;
        T[nr] = V;
        ret.push_back(nr);
      }
    }
    rec_id(v);
    return true;
  }
  bool addrg() {
    dfs0(n);
    int rt = findl(n);
    if (hvt[rt] != 3) return true;
    X.clear();
    Y.clear();
    Z.clear();
    U[0].clear();
    U[1].clear();
    for (int i = 0; i < (int)(T[rt].size()); i++)
      if (hvt[T[rt][i]] == 3)
        X.push_back(T[rt][i]);
      else if (hvt[T[rt][i]] == 2)
        Y.push_back(T[rt][i]);
      else
        Z.push_back(T[rt][i]);
    if (X.size() > 2) return false;
    for (int i = 0; i < (int)(X.size()); i++)
      if (!calc(X[i], U[i])) return false;
    V.clear();
    if (tp[rt] == 1) {
      int mn = T[rt].size(), mx = -1;
      for (int i = 0; i < (int)(T[rt].size()); i++)
        if (hvt[T[rt][i]] != 1) {
          mn = min(mn, i);
          mx = max(mx, i);
        }
      if (mx - mn + 1 != (int)(X.size() + Y.size())) return false;
      for (int i = 0; i < (int)(X.size()); i++)
        if (X[i] != T[rt][mn] && X[i] != T[rt][mx]) return false;
      for (int i = 0; i < (int)(X.size()); i++)
        if (X[i] == T[rt][mx]) reverse(U[i].begin(), U[i].end());
      int px = 0;
      for (int i = 0; i < (int)(T[rt].size()); i++)
        if (hvt[T[rt][i]] == 3) {
          for (int j = 0; j < (int)(U[px].size()); j++) V.push_back(U[px][j]);
          px++;
        } else
          V.push_back(T[rt][i]);
      T[rt] = V;
    } else {
      int ct;
      if (X.size() == 2) reverse(U[1].begin(), U[1].end());
      if (X.size() >= 1) {
        for (int i = 0; i < (int)(U[0].size()); i++) V.push_back(U[0][i]);
        if (Y.size() == 1)
          V.push_back(Y[0]);
        else if (Y.size() >= 2) {
          int nr = get_id();
          tp[nr] = 0;
          T[nr] = Y;
          V.push_back(nr);
        }
        if (X.size() == 2)
          for (int i = 0; i < (int)(U[1].size()); i++) V.push_back(U[1][i]);
        ct = 1;
      } else {
        V = Y;
        ct = 0;
      }
      if (Z.empty()) {
        tp[rt] = ct;
        T[rt] = V;
      } else {
        int nr = get_id();
        tp[nr] = ct;
        T[nr] = V;
        T[rt] = Z;
        T[rt].push_back(nr);
      }
    }
    return true;
  }
  void output(int v) {
    if (tp[v] == -1)
      ans.push_back(v);
    else
      for (int i = 0; i < (int)(T[v].size()); i++) output(T[v][i]);
  }
} tre;
char buf[1505][1505], otp[1505][1505];
int main() {
  scanf("%d", &n);
  m = n;
  tre.init();
  for (int i = 0; i < (int)(m); i++) {
    scanf("%s", buf[i]);
    for (int j = 0; j < (int)(n); j++) tre.hv[j] = buf[i][j] == '1';
    if (!tre.addrg()) {
      printf("NO\n");
      return 0;
    }
  }
  tre.output(n);
  for (int i = 0; i < (int)(m); i++)
    for (int j = 0; j < (int)(n); j++) otp[i][j] = buf[i][ans[j]];
  printf("YES\n");
  for (int i = 0; i < (int)(m); i++) printf("%s\n", otp[i]);
  return 0;
}