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 maxn = 500;
char s[maxn][maxn + 1];
bool used[maxn];
int n;
void resort(int y, int *cur, int *group, int &groupSz, int grpos, int pos,
            int type) {
  if (grpos == -1) return;
  int r = 0;
  for (int i = 0; i < group[grpos]; i++) {
    if ((int)s[y][cur[pos + i]] == type) swap(cur[pos + i], cur[pos + (r++)]);
  }
  if (!r || group[grpos] == r) return;
  int insertGroup = group[grpos] - r;
  group[grpos] = r;
  for (int i = groupSz - 1; i > grpos; i--) group[i + 1] = group[i];
  group[grpos + 1] = insertGroup;
  ++groupSz;
}
int came[maxn];
int maxu;
int groupTmp[maxn][maxn];
int counts[maxn];
bool solve(int depth, int *cur, int cnt) {
  if (!cnt) return 1;
  int mxsum = -1, mxpos = -1;
  for (int y = 0; y < n; y++) {
    if (used[y]) continue;
    int csum = 0;
    for (int i = 0; i < cnt; i++) csum += s[y][cur[i]];
    if (mxsum < csum) mxsum = csum, mxpos = y;
  }
  if (mxsum == -1) return 1;
  int *group = groupTmp[depth];
  int groupSz;
  if (mxsum && mxsum < cnt) {
    groupSz = 2;
    group[0] = group[1] = 0;
    int r = 0;
    for (int i = 0; i < cnt; i++) {
      group[!s[mxpos][cur[i]]]++;
      if (s[mxpos][cur[i]]) swap(cur[i], cur[r++]);
    }
  } else
    groupSz = 1, group[0] = cnt;
  ++maxu;
  while (1) {
    bool ch = 0;
    for (int y = 0; y < n; y++) {
      if (used[y] || came[y] == maxu) continue;
      int alert = 0;
      int pos = 0;
      for (int i = 0; i < groupSz; i++) {
        counts[i] = 0;
        for (int iter = 0; iter < group[i]; iter++) {
          counts[i] += s[y][cur[pos]];
          pos++;
        }
        alert += !!counts[i];
      }
      if (alert <= 1) continue;
      came[y] = maxu;
      ch = 1;
      int sum = group[0];
      int start = 0;
      for (int i = 1; i < groupSz; i++) {
        if (!counts[i - 1] && counts[i]) {
          start = i;
          break;
        }
        sum += group[i];
      }
      if (!start) sum = 0;
      pos = start;
      int ended = 0;
      pair<int, int> tmp[2] = {make_pair(-1, 0), make_pair(-1, 0)};
      for (int iter = 0; iter < groupSz; iter++) {
        if (counts[pos] && ended) return 0;
        if (iter && (!group[pos] || counts[pos] < group[pos])) ended = 1;
        if (counts[pos] && counts[pos] < group[pos])
          tmp[ended] = make_pair(pos, sum);
        sum += group[pos];
        if (++pos >= groupSz) pos -= groupSz, sum = 0;
      }
      if (tmp[0].first != -1 && tmp[0].first > tmp[1].first) {
        resort(y, cur, group, groupSz, tmp[0].first, tmp[0].second, 0);
        resort(y, cur, group, groupSz, tmp[1].first, tmp[1].second, 1);
      } else {
        resort(y, cur, group, groupSz, tmp[1].first, tmp[1].second, 1);
        resort(y, cur, group, groupSz, tmp[0].first, tmp[0].second, 0);
      }
    }
    if (ch) continue;
    break;
  }
  bool ok = (groupSz == 1);
  for (int x = 0, sum = 0, grid = 0; !ok && x < cnt; x++) {
    if (x != sum) continue;
    int xn = !x ? cnt - 1 : x - 1;
    ok = 1;
    for (int y = 0; y < n; y++) {
      if (used[y]) continue;
      if (s[y][cur[x]] && s[y][cur[xn]]) {
        ok = 0;
        break;
      }
    }
    if (ok) {
      rotate(group, group + grid, group + groupSz);
      rotate(cur, cur + sum, cur + cnt);
      break;
    }
    sum += group[grid];
    grid++;
  }
  if (!ok) return 0;
  used[mxpos] = 1;
  int pos = 0;
  for (int i = 0; i < groupSz; i++) {
    if (!solve(depth + 1, cur + pos, group[i])) return 0;
    pos += group[i];
  }
  used[mxpos] = 0;
  for (int y = 0; y < n; y++) {
    if (used[y]) continue;
    int groups = 0;
    for (int x = 0; x < cnt; x++) {
      if (s[y][cur[x]] && (!x || !s[y][cur[x - 1]])) ++groups;
    }
    assert(groups <= 1);
  }
  return 1;
}
int cur[maxn];
int main() {
  while (scanf("%d", &n) >= 1) {
    for (int i = 0; i < n; i++) {
      scanf("%s", s[i]);
      for (int j = 0; j < n; j++) s[i][j] -= '0';
    }
    for (int i = 0; i < n; i++) cur[i] = i;
    maxu = 0;
    memset(came, 0, sizeof(came));
    memset(used, 0, sizeof(used));
    if (solve(0, cur, n)) {
      printf("YES\n");
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) printf("%d", s[i][cur[j]]);
        printf("\n");
      }
    } else
      printf("NO\n");
  }
  return 0;
}