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;
struct ww {
  vector<int> a;
  int ty, flag, cov;
} a[2010 * 2010];
int i, j, k, n, m, t, an;
int re[2010], s[2010 * 2010], size[2010 * 2010];
char p[2010][2010];
inline void Cov(int x) {
  if (a[x].ty != 2 || a[x].flag) return;
  a[x].cov ^= 1;
  reverse(a[x].a.begin(), a[x].a.end());
}
inline void renew(int x) {
  int i;
  if (!a[x].cov) return;
  a[x].cov = 0;
  for (i = 0; i < a[x].a.size(); i++) {
    int A = a[x].a[i];
    Cov(A);
  }
}
void dfs(int x) {
  renew(x);
  int i;
  size[x] = x <= n;
  for (i = 0; i < a[x].a.size(); i++) {
    int A = a[x].a[i];
    dfs(A);
    s[x] += s[A];
    size[x] += size[A];
  }
}
void dfs_ans(int x) {
  renew(x);
  int i;
  if (x <= n) re[++an] = x;
  for (i = 0; i < a[x].a.size(); i++) {
    int A = a[x].a[i];
    dfs_ans(A);
  }
}
inline void fail() {
  printf("NO\n");
  exit(0);
}
void Dfs(int x, int y) {
  renew(x);
  if (size[x] == s[x]) return;
  int i, j;
  if (a[x].ty == 1) {
    vector<int> quan, kong, zi;
    for (i = 0; i < a[x].a.size(); i++) {
      int A = a[x].a[i];
      if (size[A] == s[A])
        quan.push_back(A);
      else if (!s[A])
        kong.push_back(A);
      else
        zi.push_back(A);
    }
    if (zi.size() > 2) fail();
    if (zi.size() == 2 && y) fail();
    for (i = 0; i < zi.size(); i++) {
      int A = zi[i];
      if (!quan.size() && zi.size() == 1 && !y)
        Dfs(A, 0);
      else {
        if (zi.size() == 1 && y)
          Dfs(A, y);
        else
          Dfs(A, i + 1);
      }
    }
    int a1 = 0, a2 = 0;
    if (quan.size() == 1)
      a1 = quan[0];
    else if (quan.size()) {
      a[a1 = ++t].ty = 1;
      a[a1].a = quan;
    }
    if (kong.size() == 1)
      a2 = kong[0];
    else if (kong.size()) {
      a[a2 = ++t].ty = 1;
      a[a2].a = kong;
    }
    if (zi.size() == 1) {
      if (!a1)
        a1 = zi[0];
      else {
        int A = ++t;
        a[A].ty = 2;
        a[A].flag = !y;
        if (y != 2) a[A].a.push_back(zi[0]);
        a[A].a.push_back(a1);
        if (y == 2) a[A].a.push_back(zi[0]);
        a1 = A;
      }
    }
    if (zi.size() == 2) {
      int A = ++t;
      a[A].ty = 2;
      a[A].flag = 1;
      a[A].a.push_back(zi[0]);
      if (a1) a[A].a.push_back(a1);
      a[A].a.push_back(zi[1]);
      a1 = A;
    }
    if (!y) {
      if (!a2)
        a[x] = a[a1];
      else {
        int A = ++t;
        a[A].ty = 1;
        a[A].a = kong;
        a[A].a.push_back(a1);
        a[x] = a[A];
      }
    } else {
      int A = ++t;
      a[A].ty = 2;
      if (y == 2) a[A].a.push_back(a1);
      if (a2) a[A].a.push_back(a2);
      if (y == 1) a[A].a.push_back(a1);
      a[x] = a[A];
    }
  } else {
    for (i = 0; i < a[x].a.size(); i++) {
      int A = a[x].a[i];
      if (s[A]) break;
    }
    for (j = i; j < a[x].a.size(); j++) {
      int A = a[x].a[j];
      if (!s[A]) break;
    }
    int l = i, r = j - 1;
    for (i = r + 1; i < a[x].a.size(); i++) {
      int A = a[x].a[i];
      if (s[A]) fail();
    }
    for (i = l + 1; i < r; i++) {
      int A = a[x].a[i];
      if (size[A] != s[A]) fail();
    }
    if (y == 1) {
      int A = a[x].a[r];
      if (r + 1 != a[x].a.size() || l < r && size[A] != s[A]) {
        if (!a[x].flag) fail();
        a[x].flag = 0;
        Cov(x);
        Dfs(x, y);
        return;
      }
      a[x].flag = 0;
    }
    if (y == 2) {
      int A = a[x].a[l];
      if (l || l < r && size[A] != s[A]) {
        if (!a[x].flag) fail();
        a[x].flag = 0;
        Cov(x);
        Dfs(x, y);
        return;
      }
      a[x].flag = 0;
    }
    if (l == r)
      Dfs(a[x].a[l], y);
    else {
      Dfs(a[x].a[l], 1);
      Dfs(a[x].a[r], 2);
    }
  }
}
int main() {
  scanf("%d", &n);
  a[t = n + 1].ty = 1;
  for (i = 1; i <= n; i++) a[t].a.push_back(i);
  for (i = 1; i <= n; i++) {
    scanf("%s", p[i] + 1);
    memset(s, 0, sizeof(s));
    for (j = 1; j <= n; j++)
      if (p[i][j] == '1') s[j] = 1;
    dfs(n + 1);
    if (!s[n + 1]) continue;
    Dfs(n + 1, 0);
  }
  dfs_ans(n + 1);
  printf("YES\n");
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) printf("%c", p[i][re[j]]);
    printf("\n");
  }
  return 0;
}