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 = 10005, MAXM = 2005;
bool Q[MAXN];
vector<int> E[MAXN];
char s[MAXM][MAXM];
int Num[MAXN][3], Bel[MAXN], Ch[MAXN], cnt, N, tot, root, cur;
void Dfs(int Cur) {
  Num[Cur][0] = Num[Cur][1] = Num[Cur][2] = 0;
  if (Cur <= N) {
    Bel[Cur] = (s[cur][Cur] == '1');
    Num[Cur][Bel[Cur]]++;
    return;
  }
  int f0 = 1, f1 = 1;
  for (vector<int>::iterator i = E[Cur].begin(); i != E[Cur].end(); i++) {
    Dfs(*i);
    Num[Cur][Bel[*i]]++;
    if (Bel[*i]) f0 = 0;
    if (Bel[*i] != 1) f1 = 0;
  }
  if (f0)
    Bel[Cur] = 0;
  else if (!f1)
    Bel[Cur] = 2;
  else
    Bel[Cur] = 1;
}
int Get(int Cur, vector<int> &Lk) {
  if (Num[Cur][2] > 1) return 1;
  if (Q[Cur]) {
    vector<int>::iterator Fr = E[Cur].begin();
    if (Bel[*Fr] != 1 && Num[Cur][1] || Bel[*Fr] != 2 && !Num[Cur][1])
      reverse(E[Cur].begin(), E[Cur].end());
    Fr = E[Cur].begin();
    for (int i = 1; i <= Num[Cur][1]; i++) {
      if (Bel[*Fr] != 1) return 1;
      Lk.push_back(*Fr);
      Fr++;
    }
    bool Flag = 0;
    for (; Fr != E[Cur].end(); Fr++) {
      if (!Flag && Num[Cur][2] && Bel[*Fr] != 2) return 1;
      if (Bel[*Fr] == 2) {
        Flag = 1;
        if (Get(*Fr, Lk)) return 1;
      } else
        Lk.push_back(*Fr);
    }
    return 0;
  }
  if (Num[Cur][1]) {
    int t1 = ++tot;
    for (vector<int>::iterator i = E[Cur].begin(); i != E[Cur].end(); i++)
      if (Bel[*i] == 1) E[t1].push_back(*i);
    if (E[t1].size() == 1) t1 = E[t1][0];
    Lk.push_back(t1);
  }
  for (vector<int>::iterator i = E[Cur].begin(); i != E[Cur].end(); i++)
    if (Bel[*i] == 2 && Get(*i, Lk)) return 1;
  if (Num[Cur][0]) {
    int t2 = ++tot;
    for (vector<int>::iterator i = E[Cur].begin(); i != E[Cur].end(); i++)
      if (!Bel[*i]) E[t2].push_back(*i);
    if (E[t2].size() == 1) t2 = E[t2][0];
    Lk.push_back(t2);
  }
  return 0;
}
int Getr(int Cur, vector<int> &Lk) {
  int tmp = Lk.size();
  if (!Get(Cur, Lk)) {
    reverse(Lk.begin() + tmp, Lk.end());
    return 0;
  }
  return 1;
}
int Getl(int Cur, vector<int> &Lk) { return Get(Cur, Lk); }
int Calc(int Cur) {
  if (Cur <= N) return 0;
  if (Num[Cur][2] > 2) return 1;
  if (Num[Cur][1] + Num[Cur][2] == 1) {
    for (vector<int>::iterator i = E[Cur].begin(); i != E[Cur].end(); i++)
      if (Bel[*i]) return Calc(*i);
  }
  vector<int> Tmp;
  Tmp.clear();
  if (Q[Cur]) {
    bool End = 0, One = 0;
    for (vector<int>::iterator i = E[Cur].begin(); i != E[Cur].end(); i++) {
      if (End && Bel[*i]) return 1;
      if (One && !Bel[*i]) End = 1;
      if (Bel[*i] == 2) {
        if (!One) {
          if (Getr(*i, Tmp)) return 1;
        } else if (Getl(*i, Tmp))
          return 1;
      } else
        Tmp.push_back(*i);
      if (Bel[*i]) One = 1;
    }
    E[Cur] = Tmp;
    return 0;
  } else {
    int t1 = ++tot;
    Q[t1] = 1;
    for (vector<int>::iterator i = E[Cur].begin(); i != E[Cur].end(); i++)
      if (Bel[*i] == 2) {
        if (Getr(*i, E[t1])) return 1;
        break;
      }
    if (Num[Cur][1]) {
      int t2 = ++tot;
      for (vector<int>::iterator i = E[Cur].begin(); i != E[Cur].end(); i++)
        if (Bel[*i] == 1) E[t2].push_back(*i);
      if (E[t2].size() == 1) t2 = E[t2][0];
      E[t1].push_back(t2);
    }
    int Fl = 0;
    for (vector<int>::iterator i = E[Cur].begin(); i != E[Cur].end(); i++)
      if (Bel[*i] == 2) {
        if (!Fl)
          Fl = 1;
        else {
          if (Getl(*i, E[t1])) return 1;
          break;
        }
      }
    if (E[t1].size() == 1) t1 = E[t1][0];
    Tmp.push_back(t1);
    for (vector<int>::iterator i = E[Cur].begin(); i != E[Cur].end(); i++)
      if (!Bel[*i]) Tmp.push_back(*i);
  }
  E[Cur] = Tmp;
  return 0;
}
void Get_Order(int Cur) {
  if (Cur <= N) {
    Ch[++cnt] = Cur;
    return;
  }
  for (vector<int>::iterator i = E[Cur].begin(); i != E[Cur].end(); i++)
    Get_Order(*i);
}
int main() {
  scanf("%d", &N);
  root = tot = N + 1;
  for (int i = 1; i <= N; i++) E[tot].push_back(i);
  for (int i = 1; i <= N; i++) {
    scanf("%s", s[i] + 1);
    cur = i, Dfs(root);
    if (Calc(root)) {
      printf("NO\n");
      return 0;
    }
  }
  Get_Order(root);
  printf("YES\n");
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) printf("%c", s[i][Ch[j]]);
    printf("\n");
  }
}