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 = 2005;
char s[N][N];
int n, tot, order[N], root;
int Num[N << 1][3], type[N << 1];
vector<int> E[N << 1];
bool Q[N << 1], v[N];
void Init() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
}
void Dfs(int x) {
  Num[x][0] = Num[x][1] = Num[x][2] = 0;
  if (x <= n) {
    if (v[x])
      type[x] = 1;
    else
      type[x] = 0;
    Num[x][type[x]]++;
    return;
  }
  bool f0 = 0, f1 = 0;
  for (vector<int>::iterator it = E[x].begin(); it != E[x].end(); it++) {
    Dfs(*it);
    if (type[*it]) f1 = 1;
    if (!type[*it] || type[*it] == 2) f0 = 1;
    Num[x][type[*it]]++;
  }
  if (f0 && !f1)
    type[x] = 0;
  else if (f1 && !f0)
    type[x] = 1;
  else
    type[x] = 2;
}
bool Get(int x, vector<int> &Ed) {
  if (Num[x][2] > 1) return 1;
  if (Q[x]) {
    vector<int>::iterator it = E[x].begin();
    if (Num[x][1] && type[*it] != 1 ||
        !Num[x][1] && Num[x][2] && type[*it] != 2)
      reverse(E[x].begin(), E[x].end());
    it = E[x].begin();
    for (int i = 1; i <= Num[x][1]; i++) {
      if (type[*it] != 1) return 1;
      Ed.push_back(*it);
      it++;
    }
    bool Fir = 1;
    for (; it != E[x].end(); it++) {
      if (Fir && Num[x][2] && type[*it] != 2) return 1;
      if (type[*it] == 2) {
        Fir = 0;
        if (Get(*it, Ed)) return 1;
      } else
        Ed.push_back(*it);
    }
    return 0;
  } else {
    if (Num[x][1]) {
      int t1 = ++tot;
      for (vector<int>::iterator it = E[x].begin(); it != E[x].end(); it++)
        if (type[*it] == 1) E[t1].push_back(*it);
      if (E[t1].size() == 1) t1 = E[t1][0];
      Ed.push_back(t1);
    }
    for (vector<int>::iterator it = E[x].begin(); it != E[x].end(); it++)
      if (type[*it] == 2 && Get(*it, Ed)) return 1;
    if (Num[x][0]) {
      int t2 = ++tot;
      for (vector<int>::iterator it = E[x].begin(); it != E[x].end(); it++)
        if (!type[*it]) E[t2].push_back(*it);
      if (E[t2].size() == 1) t2 = E[t2][0];
      Ed.push_back(t2);
    }
    return 0;
  }
}
bool Getr(int x, vector<int> &Ed) {
  int temp = Ed.size();
  if (Get(x, Ed)) return 1;
  reverse(Ed.begin() + temp, Ed.end());
  return 0;
}
bool Getl(int x, vector<int> &Ed) { return Get(x, Ed); }
bool Judge(int x) {
  if (x <= n) return 0;
  if (Num[x][2] > 2) return 1;
  if (!Num[x][1] && !Num[x][2]) return 0;
  if (Num[x][1] + Num[x][2] == 1) {
    for (vector<int>::iterator it = E[x].begin(); it != E[x].end(); it++)
      if (type[*it]) return Judge(*it);
  }
  vector<int> temp;
  temp.clear();
  if (Q[x]) {
    bool Fir = 1, End = 0;
    for (vector<int>::iterator it = E[x].begin(); it != E[x].end(); it++) {
      if (type[*it] && End) return 1;
      if (!Fir && !type[*it]) End = 1;
      if (type[*it] == 2) {
        if (Fir) {
          if (Getr(*it, temp)) return 1;
        } else if (Getl(*it, temp))
          return 1;
      } else
        temp.push_back(*it);
      if (type[*it]) Fir = 0;
    }
    E[x] = temp;
    return 0;
  } else {
    int t1 = ++tot;
    Q[t1] = 1;
    for (vector<int>::iterator it = E[x].begin(); it != E[x].end(); it++)
      if (type[*it] == 2) {
        if (Getr(*it, E[t1])) return 1;
        break;
      }
    if (Num[x][1]) {
      int t2 = ++tot;
      for (vector<int>::iterator it = E[x].begin(); it != E[x].end(); it++)
        if (type[*it] == 1) E[t2].push_back(*it);
      if (E[t2].size() == 1) t2 = E[t2][0];
      E[t1].push_back(t2);
    }
    bool Fir = 1;
    for (vector<int>::iterator it = E[x].begin(); it != E[x].end(); it++)
      if (type[*it] == 2) {
        if (Fir)
          Fir = 0;
        else {
          if (Getl(*it, E[t1])) return 1;
          break;
        }
      }
    if (E[t1].size() == 1) t1 = E[t1][0];
    temp.push_back(t1);
    for (vector<int>::iterator it = E[x].begin(); it != E[x].end(); it++)
      if (!type[*it]) temp.push_back(*it);
    E[x] = temp;
    return 0;
  }
}
void Get_ans(int x) {
  if (x <= n) {
    order[++tot] = x;
    return;
  }
  for (vector<int>::iterator it = E[x].begin(); it != E[x].end(); it++)
    Get_ans(*it);
}
void Dfs_draw(int x) {
  printf("\n%d:", x);
  for (vector<int>::iterator it = E[x].begin(); it != E[x].end(); it++)
    printf("%d ", *it);
  for (vector<int>::iterator it = E[x].begin(); it != E[x].end(); it++)
    Dfs_draw(*it);
}
void Work() {
  root = tot = n + 1;
  for (int i = 1; i <= n; i++) E[root].push_back(i);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) v[j] = 0;
    for (int j = 1; j <= n; j++)
      if (s[i][j] == '1') v[j] = 1;
    Dfs(root);
    if (Judge(root)) {
      puts("NO");
      return;
    }
  }
  tot = 0;
  Get_ans(root);
  puts("YES");
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) printf("%c", s[i][order[j]]);
    printf("\n");
  }
}
int main() {
  Init();
  Work();
  return 0;
}