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>
long d[1101][1101] = {0}, sum[1101] = {0}, b[1101][1101] = {0}, num[1101] = {0},
     next[1101] = {0}, rec[1101] = {0}, can[1101] = {0};
char ttt[1101][1101], sss[1101][1101], str[1101][1101] = {0},
                                       hash[1101][1101] = {0}, c[1101] = {0},
                                       used[1101] = {0};
long n, m, s, tot = 1, ans = 0, o = 0;
long work(long now) {
  long i, j, k, p, a, cur = ++o;
  char tmp;
  s = 0;
  for (i = 1; i <= n; i++)
    if (!used[i] && b[i][now]) can[++s] = i;
  next[now] = now;
  if (!hash[now][0]) {
    hash[now][0] = 1;
    sum[now]++;
  }
  if (!s) {
    for (p = now; !hash[p][0]; p = next[p])
      ;
    for (i = 1; i <= m; i++)
      if (hash[p][i]) rec[++ans] = i;
    for (i = next[p]; i != p; i = next[i])
      for (j = 1; j <= m; j++)
        if (hash[i][j]) rec[++ans] = j;
  } else {
    while (1) {
      p = 0;
      for (i = 1; i <= s; i++)
        if (!used[can[i]] && (!p || c[can[i]] || !c[p] && num[can[i]] > num[p]))
          p = can[i];
      if (next[now] != now && !c[p]) break;
      used[p] = 1;
      if (!c[p]) {
        next[++tot] = now;
        next[now] = tot;
        tmp = (b[p][now] <= sum[now] / 2) + '0';
        for (i = 0; i <= m; i++)
          if (hash[now][i] && str[p][i] == tmp) {
            for (a = 1; a <= n; a++)
              if (str[a][i] == '1') {
                b[a][now]--;
                b[a][tot]++;
              }
            hash[now][i] = 0;
            sum[now]--;
            hash[tot][i] = 1;
            sum[tot]++;
          }
        for (i = 1; i <= s; i++)
          c[can[i]] |= (b[can[i]][now] && b[can[i]][tot]);
      } else {
        for (i = next[now]; (b[p][i] || !b[p][next[i]]) && i != now;
             i = next[i])
          ;
        if (!b[p][i] && b[p][next[i]])
          i = next[i];
        else {
          for (i = now; b[p][i] == sum[i]; i = next[i])
            ;
          if (b[p][next[i]] != sum[next[i]]) i = next[i];
        }
        j = i;
        while (b[p][next[j]] && next[j] != i) j = next[j];
        for (k = next[i]; k != j; k = next[k])
          if (b[p][k] != sum[k]) return 0;
        for (k = next[j]; k != i; k = next[k])
          if (b[p][k]) return 0;
        if (b[p][i] != sum[i]) {
          if (b[p][i] <= sum[i] / 2) {
            next[++tot] = next[i];
            next[i] = tot;
          } else {
            for (k = next[i]; next[k] != i; k = next[k])
              ;
            next[++tot] = i;
            next[k] = tot;
          }
          tmp = (b[p][i] <= sum[i] / 2) + '0';
          for (k = 0; k <= m; k++)
            if (hash[i][k] && str[p][k] == tmp) {
              for (a = 1; a <= n; a++)
                if (str[a][k] == '1') {
                  b[a][i]--;
                  b[a][tot]++;
                }
              hash[i][k] = 0;
              sum[i]--;
              hash[tot][k] = 1;
              sum[tot]++;
            }
          for (k = 1; k <= s; k++)
            c[can[k]] |= (b[can[k]][i] && b[can[k]][tot]);
        }
        if (b[p][j] != sum[j]) {
          if (b[p][j] <= sum[j] / 2) {
            for (k = next[j]; next[k] != j; k = next[k])
              ;
            next[++tot] = j;
            next[k] = tot;
          } else {
            next[++tot] = next[j];
            next[j] = tot;
          }
          tmp = (b[p][j] <= sum[j] / 2) + '0';
          for (k = 0; k <= m; k++)
            if (hash[j][k] && str[p][k] == tmp) {
              for (a = 1; a <= n; a++)
                if (str[a][k] == '1') {
                  b[a][j]--;
                  b[a][tot]++;
                }
              hash[j][k] = 0;
              sum[j]--;
              hash[tot][k] = 1;
              sum[tot]++;
            }
          for (k = 1; k <= s; k++)
            c[can[k]] |= (b[can[k]][j] && b[can[k]][tot]);
        }
      }
    }
    for (p = now; !hash[p][0]; p = next[p])
      ;
    d[cur][++d[cur][0]] = p;
    for (i = next[p]; i != p; i = next[i]) d[cur][++d[cur][0]] = i;
    for (i = 1; i <= d[cur][0]; i++)
      if (!work(d[cur][i])) return 0;
  }
  return 1;
}
int main() {
  long i, j;
  scanf("%ld\n", &n);
  m = n;
  for (i = 1; i <= n; i++) {
    str[i][0] = '0';
    gets(str[i] + 1);
    strcpy(ttt[i] + 1, str[i] + 1);
    for (j = 1; j <= m; j++)
      if (str[i][j] == '1') num[i]++;
    b[i][1] = num[i];
  }
  sum[1] = m;
  for (i = 1; i <= m; i++) hash[1][i] = 1;
  if (work(1)) {
    puts("YES");
    for (i = 1; i <= m; i++)
      for (j = 1; j <= n; j++) sss[j][i] = ttt[j][rec[i]];
    for (i = 1; i <= n; i++) puts(sss[i] + 1);
  } else
    puts("NO");
  return 0;
}