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;
vector<vector<int> > prienik;
struct riadok {
  int id;
  int vojakov;
  int zaciatok, koniec;
  riadok* kamarat;
  riadok(string s, int _id) {
    id = _id;
    vojakov = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '1') vojakov++;
    }
    zaciatok = -1;
    koniec = -1;
    kamarat = NULL;
  }
  string vypis(int n) {
    string s;
    for (int i = 0; i < n; i++) {
      if (i >= zaciatok && i < koniec)
        s.push_back('1');
      else
        s.push_back('0');
    }
    return s;
  }
  bool umiestni(riadok* kamos);
  void posun(int delta) {
    zaciatok += delta;
    koniec += delta;
  }
};
int prekryv(riadok* a, riadok* b) { return prienik[a->id][b->id]; }
bool riadok::umiestni(riadok* kamos) {
  if (kamos == NULL) {
    zaciatok = 0;
    koniec = vojakov;
    return true;
  }
  int p = prekryv(this, kamos);
  kamarat = kamos;
  zaciatok = kamos->koniec - p;
  koniec = zaciatok + vojakov;
  if (kamos->kamarat == NULL) {
    kamos->kamarat = this;
    return true;
  }
  int p2 = prekryv(this, kamos->kamarat);
  int realny_prekryv = max(min(koniec, kamos->kamarat->koniec) -
                               max(zaciatok, kamos->kamarat->zaciatok),
                           0);
  if (p2 == realny_prekryv) return true;
  koniec = kamos->zaciatok + p;
  zaciatok = koniec - vojakov;
  realny_prekryv = max(min(koniec, kamos->kamarat->koniec) -
                           max(zaciatok, kamos->kamarat->zaciatok),
                       0);
  if (p2 == realny_prekryv) return true;
  return false;
}
bool ciastocny_prekryv(riadok* a, riadok* b) {
  int p = prekryv(a, b);
  return p > 0 && p < a->vojakov && p < b->vojakov;
}
int spolocnych(string a, string b) {
  int res = 0;
  for (int i = 0; i < a.size(); i++) {
    res += (a[i] == '1' && b[i] == '1');
  }
  return res;
}
bool vyries(vector<riadok*> r) {
  if (r.size() == 0) return true;
  pair<int, int> najdlhsi(-1, -1);
  for (int i = 0; i < r.size(); i++) {
    najdlhsi = max(najdlhsi, pair<int, int>(r[i]->vojakov, i));
  }
  vector<riadok*> hotove;
  swap(r[najdlhsi.second], r.back());
  r.back()->umiestni(NULL);
  hotove.push_back(r.back());
  r.pop_back();
  for (int i = 0; i < hotove.size(); i++) {
    for (int j = 0; j < r.size(); j++) {
      if (ciastocny_prekryv(hotove[i], r[j])) {
        if (!(r[j]->umiestni(hotove[i]))) return false;
        hotove.push_back(r[j]);
        swap(r[j], r.back());
        r.pop_back();
        j--;
      }
    }
  }
  int minsur = 1023456789, maxsur = -1023456789;
  for (int i = 0; i < hotove.size(); i++) {
    minsur = min(minsur, hotove[i]->zaciatok);
  }
  for (int i = 0; i < hotove.size(); i++) {
    hotove[i]->posun(-minsur);
    maxsur = max(maxsur, hotove[i]->koniec);
  }
  vector<pair<pair<int, int>, riadok*> > podla_intervalu;
  for (int i = 0; i < r.size(); i++) {
    int zac = -1, kon = -1;
    for (int j = 0; j < hotove.size(); j++) {
      if (prekryv(r[i], hotove[j]) > 0) {
        if (zac == -1 && kon == -1) {
          zac = hotove[j]->zaciatok;
          kon = hotove[j]->koniec;
        } else {
          zac = max(zac, hotove[j]->zaciatok);
          kon = min(kon, hotove[j]->koniec);
        }
      }
    }
    if (zac != -1) {
      for (int j = 0; j < hotove.size(); j++) {
        if (prekryv(hotove[j], r[i]) == 0) {
          if (hotove[j]->zaciatok <= zac) {
            zac = max(zac, hotove[j]->koniec);
          }
          if (hotove[j]->koniec >= kon) {
            kon = min(kon, hotove[j]->zaciatok);
          }
        }
      }
    }
    podla_intervalu.push_back(make_pair(make_pair(zac, kon), r[i]));
  }
  sort(podla_intervalu.begin(), podla_intervalu.end());
  vector<riadok*> skupina;
  int zac = -2, kon = -2;
  for (int i = 0; i < podla_intervalu.size(); i++) {
    if (podla_intervalu[i].first == make_pair(zac, kon)) {
      skupina.push_back(podla_intervalu[i].second);
    } else {
      if (skupina.size() > 0) {
        if (!vyries(skupina)) return false;
        int pos = zac == -1 ? maxsur : zac;
        for (int j = 0; j < skupina.size(); j++) {
          skupina[j]->posun(pos);
        }
        skupina.clear();
      }
      zac = podla_intervalu[i].first.first;
      kon = podla_intervalu[i].first.second;
      skupina.push_back(podla_intervalu[i].second);
    }
  }
  if (skupina.size() > 0) {
    if (!vyries(skupina)) return false;
    int pos = zac == -1 ? maxsur : zac;
    for (int j = 0; j < skupina.size(); j++) {
      skupina[j]->posun(pos);
    }
  }
  return true;
}
vector<string> normalizuj(vector<string> formacia) {
  int n = formacia.size();
  vector<string> vysledok(n);
  for (int x = 0; x < n; x++) {
    for (int y = 0; y < n; y++) {
      vysledok[x].push_back(formacia[y][x]);
    }
  }
  sort(vysledok.begin(), vysledok.end());
  return vysledok;
}
bool over(vector<string> vstup, vector<string> vystup) {
  return normalizuj(vstup) == normalizuj(vystup);
}
int main() {
  int n;
  cin >> n;
  string pom;
  getline(cin, pom);
  vector<string> vstup(n);
  vector<riadok*> vsetky;
  vector<riadok*> neprazdne;
  for (int y = 0; y < n; y++) {
    getline(cin, vstup[y]);
    vsetky.push_back(new riadok(vstup[y], y));
    if (vsetky.back()->vojakov > 0) {
      neprazdne.push_back(vsetky.back());
    }
  }
  prienik.resize(n, vector<int>(n, 0));
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      prienik[i][j] = prienik[j][i] = spolocnych(vstup[i], vstup[j]);
    }
  }
  if (!vyries(neprazdne)) {
    cout << "NO" << endl;
    return 0;
  }
  vector<string> vysledok(n);
  for (int y = 0; y < n; y++) vysledok[y] = vsetky[y]->vypis(n);
  if (!over(vstup, vysledok)) {
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  for (int y = 0; y < n; y++) {
    cout << vysledok[y] << endl;
  }
  prienik.resize(n, vector<int>(n));
  return 0;
}