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 N = 2e3 + 5, M = 2e6 + 5, INF = 1e9, mod = 1e9 + 7;
const long long linf = 1e18;
const double eps = 1e-8, pi = acos(-1);
inline int gmin(int &a, int b) {
  if (a > b) a = b;
}
inline long long gmin(long long &a, long long b) {
  if (a > b) a = b;
}
inline int gmax(int &a, int b) {
  if (a < b) a = b;
}
inline long long gmax(long long &a, long long b) {
  if (a < b) a = b;
}
inline void read(long long &x) {
  long long f = 1, t = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    t = t * 10 + ch - '0';
    ch = getchar();
  }
  x = t * f;
}
inline long long read(long long &x, long long &y) {
  read(x);
  read(y);
}
inline void read(int &x) {
  int f = 1, t = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    t = t * 10 + ch - '0';
    ch = getchar();
  }
  x = t * f;
}
inline int read(int &x, int &y) {
  read(x);
  read(y);
}
inline void read(int &a, int &b, int &c) {
  read(a);
  read(b);
  read(c);
}
inline void read(long long &a, long long &b, long long &c) {
  read(a);
  read(b);
  read(c);
}
inline int read() {
  int x;
  read(x);
  return x;
}
inline long long qpow(long long a, long long b, long long p) {
  long long ret = 1;
  for (; b; b >>= 1, a = a * a % p)
    if (b & 1) ret = ret * a % p;
  return ret;
}
inline long long qpow(long long a, long long b) {
  long long ret = 1;
  for (; b; b >>= 1, a = a * a % mod)
    if (b & 1) ret = ret * a % mod;
  return ret;
}
inline long long qmul(long long a, long long b, long long p) {
  long long ret = 0;
  for (; b; b >>= 1, a = (a << 1) % p)
    if (b & 1) {
      ret = ret + a;
      if (ret >= p)
        ret -= p;
      else if (ret < 0)
        ret += p;
    };
  return ret;
}
inline long long qmul(long long a, long long b) {
  long long ret = 0;
  for (; b; b >>= 1, a = (a << 1) % mod)
    if (b & 1) {
      ret = ret + a;
      if (ret >= mod)
        ret -= mod;
      else if (ret < 0)
        ret += mod;
    };
  return ret;
}
inline void judge() {
  freopen("data.in", "r", stdin);
  freopen("data.out", "w", stdout);
}
inline void gen() { freopen("data.in", "w", stdout); }
int root, ndtot, n, cnt;
bool ok = 1;
vector<int> son[N];
int a[N][N], req[N], num[N][4], bel[N], q[N], rk[N];
char s[N];
void dfs(int x) {
  for (int i = (0); i <= (2); i++) num[x][i] = 0;
  if (x <= n) {
    bel[x] = req[x];
    num[x][bel[x]]++;
    return;
  }
  int emp = 1, ful = 1;
  for (int i = (0); i < (son[x].size()); i++) {
    dfs(son[x][i]);
    if (bel[son[x][i]]) emp = 0;
    if (bel[son[x][i]] != 1) ful = 0;
    num[x][bel[son[x][i]]]++;
  }
  if (emp)
    bel[x] = 0;
  else if (ful)
    bel[x] = 1;
  else
    bel[x] = 2;
}
int get(int x, vector<int> &L) {
  if (num[x][2] > 1) return 0;
  if (q[x]) {
    if (num[x][1] && bel[son[x][0]] != 1 || !num[x][1] && bel[son[x][0]] != 2)
      reverse(son[x].begin(), son[x].end());
    for (int i = (0); i < (num[x][1]); i++) {
      if (bel[son[x][i]] != 1) return 0;
      L.push_back(son[x][i]);
    }
    int k = num[x][1];
    if (num[x][2] && bel[son[x][k]] != 2) return 0;
    if (num[x][2]) {
      if (!get(son[x][k], L)) return 0;
      k++;
    }
    for (int i = (k); i < (son[x].size()); i++) L.push_back(son[x][i]);
  } else {
    if (num[x][1]) {
      int t1 = ++ndtot;
      for (int i = (0); i < (son[x].size()); i++)
        if (bel[son[x][i]] == 1) son[t1].push_back(son[x][i]);
      if (son[t1].size() == 1) t1 = son[t1][0];
      L.push_back(t1);
    }
    for (int i = (0); i < (son[x].size()); i++)
      if (bel[son[x][i]] == 2)
        if (!get(son[x][i], L)) return 0;
    if (num[x][0]) {
      int t2 = ++ndtot;
      for (int i = (0); i < (son[x].size()); i++)
        if (!bel[son[x][i]]) son[t2].push_back(son[x][i]);
      if (son[t2].size() == 1) t2 = son[t2][0];
      L.push_back(t2);
    }
  }
  return 1;
}
int getr(int x, vector<int> &L) {
  int sz = L.size();
  if (get(x, L)) {
    reverse(L.begin() + sz, L.end());
    return 1;
  }
  return 0;
}
int getl(int x, vector<int> &L) { return get(x, L); }
int calc(int x) {
  if (x <= n) return 1;
  if (num[x][1] + num[x][2] == 1)
    for (int i = (0); i < (son[x].size()); i++)
      if (bel[son[x][i]]) return calc(son[x][i]);
  if (num[x][2] > 2) return 0;
  vector<int> tmp;
  tmp.clear();
  if (q[x]) {
    int st = 0, ed = 0;
    for (int i = (0); i < (son[x].size()); i++) {
      if (ed && bel[son[x][i]]) return 0;
      if (st && !bel[son[x][i]]) ed = 1;
      if (bel[son[x][i]] == 2) {
        if (!st) {
          if (!getr(son[x][i], tmp)) return 0;
        } else if (!getl(son[x][i], tmp))
          return 0;
      } else
        tmp.push_back(son[x][i]);
      if (bel[son[x][i]]) st = 1;
    }
  } else {
    int t1 = ++ndtot;
    q[t1] = 1;
    for (int i = (0); i < (son[x].size()); i++)
      if (bel[son[x][i]] == 2) {
        if (!getr(son[x][i], son[t1])) return 0;
        break;
      }
    if (num[x][1]) {
      int t2 = ++ndtot;
      for (int i = (0); i < (son[x].size()); i++)
        if (bel[son[x][i]] == 1) son[t2].push_back(son[x][i]);
      if (son[t2].size() == 1) t2 = son[t2][0];
      son[t1].push_back(t2);
    }
    int ars = 0;
    for (int i = (0); i < (son[x].size()); i++)
      if (bel[son[x][i]] == 2) {
        if (!ars)
          ars = 1;
        else if (!getl(son[x][i], son[t1]))
          return 0;
      }
    if (son[t1].size() == 1) t1 = son[t1][0];
    tmp.push_back(t1);
    for (int i = (0); i < (son[x].size()); i++)
      if (!bel[son[x][i]]) tmp.push_back(son[x][i]);
  }
  son[x] = tmp;
  return 1;
}
int tt = 0;
void getans(int x) {
  if (x <= n) {
    rk[++tt] = x;
    return;
  }
  for (int i = (0); i < (son[x].size()); i++) getans(son[x][i]);
}
int main() {
  read(n);
  root = ndtot = n + 1;
  for (int i = (1); i <= (n); i++) son[root].push_back(i);
  for (int i = (1); i <= (n); i++) {
    scanf("%s", s + 1);
    for (int j = (1); j <= (n); j++) {
      req[j] = s[j] - '0';
      a[i][j] = req[j];
    }
    dfs(root);
    if (!calc(root)) {
      ok = 0;
      puts("NO");
      return 0;
    }
  }
  getans(root);
  puts("YES");
  for (int i = (1); i <= (n); i++) {
    for (int j = (1); j <= (n); j++) printf("%d", a[i][rk[j]]);
    puts("");
  }
}