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 = 505;
const int M = N * N;
int type[M];
vector<int> go[M];
int tsz, root;
int color[M];
void init(int n) {
  if (n == 1) {
    root = tsz = 1;
  } else {
    root = tsz = n + 1;
    type[root] = 1;
    for (int i = 1; i <= n; i++) go[root].push_back(i);
  }
}
char *s;
void Paint(int u) {
  if (type[u] == 0) {
    color[u] = s[u] == '1' ? 2 : 1;
  } else {
    color[u] = 0;
    for (int v : go[u]) {
      Paint(v);
      color[u] |= color[v];
    }
  }
}
int Merge(vector<int> nodes) {
  if (nodes.empty()) return 0;
  if (nodes.size() == 1) return nodes[0];
  int node = ++tsz;
  type[node] = 1;
  go[node] = nodes;
  return node;
}
bool ok = true;
int Solve(int u, int t) {
  if (!ok) return 0;
  if (color[u] != 3) return u;
  vector<int> ch[3];
  for (int v : go[u]) ch[color[v] - 1].push_back(v);
  if (ch[2].size() > 2 || (t > 0 && ch[2].size() > 1)) {
    ok = false;
    return 0;
  }
  if (type[u] == 1) {
    if (t == 0) {
      go[u] = ch[0];
      if (ch[2].size() == 2 || (ch[2].size() > 0 && ch[1].size() > 0)) {
        int Q = Solve(ch[2][0], 1);
        if (!ok) return 0;
        int b = Merge(ch[1]);
        if (b) go[Q].push_back(b);
        if (ch[2].size() > 1) {
          int q = Solve(ch[2][1], 2);
          if (!ok) return 0;
          for (int v : go[q]) go[Q].push_back(v);
        }
        go[u].push_back(Q);
      } else if (ch[2].size() == 1) {
        int Q = Solve(ch[2][0], 0);
        if (!ok) return 0;
        go[u].push_back(Q);
      } else {
        int b = Merge(ch[1]);
        if (b) go[u].push_back(b);
      }
    } else {
      type[u] = 2;
      go[u].clear();
      int w = Merge(ch[0]);
      if (w) go[u].push_back(w);
      if (ch[2].size()) {
        int g = Solve(ch[2][0], 1);
        if (!ok) return 0;
        for (int v : go[g]) go[u].push_back(v);
      }
      int b = Merge(ch[1]);
      if (b) go[u].push_back(b);
      if (t == 2) reverse(go[u].begin(), go[u].end());
    }
    return u;
  } else {
    string pattern = t == 0 ? "wgbgw" : "wgb";
    int ptr = 0;
    if (color[go[u][0]] == 2 || color[go[u].back()] == 1)
      reverse(go[u].begin(), go[u].end());
    vector<int> ngo;
    bool strict =
        t != 0 || ch[2].size() > 1 || (ch[2].size() > 0 && ch[1].size() > 0);
    for (int v : go[u]) {
      char col = color[v] == 1 ? 'w' : color[v] == 2 ? 'b' : 'g';
      while (ptr < pattern.size() && pattern[ptr] != col) ptr++;
      if (ptr == pattern.size()) {
        ok = false;
        return 0;
      }
      if (color[v] != 3) {
        ngo.push_back(v);
      } else {
        int Q;
        if (!strict)
          Q = Solve(v, 0);
        else if (ptr == 1)
          Q = Solve(v, 1);
        else
          Q = Solve(v, 2);
        if (!ok) return 0;
        if (type[Q] == 1)
          ngo.push_back(Q);
        else
          for (int h : go[Q]) ngo.push_back(h);
        ptr++;
      }
    }
    go[u] = ngo;
    if (t == 2) reverse(go[u].begin(), go[u].end());
    return u;
  }
}
void AddSet(char *t) {
  if (!ok) return;
  s = t;
  Paint(root);
  root = Solve(root, 0);
}
void Print(int u) {
  if (type[u] == 0) {
    printf("%i ", u);
  } else {
    if (type[u] == 1) {
      printf("P{ ");
    } else
      printf("Q[ ");
    for (int v : go[u]) Print(v);
    if (type[u] == 1) {
      printf("} ");
    } else
      printf("] ");
  }
}
vector<int> ord;
void DFS(int u) {
  if (type[u] == 0) {
    ord.push_back(u);
  } else {
    for (int v : go[u]) DFS(v);
  }
}
char mat[N][N];
int main() {
  int n;
  scanf("%i", &n);
  init(n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", mat[i] + 1);
    AddSet(mat[i]);
  }
  if (ok) {
    DFS(root);
    printf("YES\n");
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) printf("%c", mat[i][ord[j - 1]]);
      printf("\n");
    }
  } else
    printf("NO\n");
  return 0;
}