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 long double pi = acos(-1.);
bool matr[505][505];
int sz[505];
int common[505][505];
pair<int, int> incomp[505], cf[505];
int cnum[505], leader[505];
bool cov[505], done[505];
int in[505][505];
pair<int, int> intersect(const pair<int, int> &a, const pair<int, int> &b) {
  return make_pair(max(a.first, b.first), min(a.second, b.second));
}
int len(const pair<int, int> &a) { return max(0, a.second - a.first + 1); }
int n;
bool dfs(int v, int curcomp, pair<int, int> force) {
  cnum[v] = curcomp;
  incomp[v] = force;
  bool ok = 1;
  int L = incomp[v].first, R = incomp[v].second;
  for (int i = 0; i < n && ok; i++)
    if (cnum[i] == curcomp &&
        len(intersect(incomp[v], incomp[i])) != common[v][i])
      ok = 0;
  if (!ok) {
    cnum[v] = -1;
    return 0;
  }
  for (int i = 0; i < n; i++)
    if ((common[v][i] != sz[v] && common[v][i] != sz[i] && common[v][i] != 0) ||
        (common[v][i] == sz[v] && sz[i] == sz[v])) {
      assert(cnum[i] == -1 || cnum[i] == cnum[v]);
      if (cnum[i] == cnum[v]) continue;
      pair<int, int> left =
          make_pair(L + common[v][i] - sz[i], L + common[v][i] - 1);
      assert(len(left) == sz[i]);
      pair<int, int> right =
          make_pair(R - common[v][i] + 1, R - common[v][i] + sz[i]);
      assert(len(right) == sz[i]);
      assert(len(intersect(force, left)) == common[v][i]);
      assert(len(intersect(force, right)) == common[v][i]);
      if (!dfs(i, curcomp, left) && !dfs(i, curcomp, right)) {
        cnum[v] = -1;
        return 0;
      }
    }
  return 1;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) sz[i] = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      char u;
      cin >> u;
      matr[i][j] = u == '1';
      sz[i] += matr[i][j];
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      common[i][j] = 0;
      for (int k = 0; k < n; k++)
        if (matr[i][k] && matr[j][k]) common[i][j]++;
    }
  for (int i = 0; i < n; i++) cnum[i] = -1;
  int cnt = 0;
  for (int i = 0; i < n; i++)
    if (cnum[i] == -1) {
      leader[cnt] = i;
      if (!dfs(i, cnt, make_pair(0, sz[i] - 1))) {
        cout << "NO" << endl;
        return 0;
      }
      cnt++;
    }
  for (int i = 0; i < cnt; i++)
    for (int j = 0; j < cnt; j++) in[i][j] = 0;
  for (int i = 0; i < cnt; i++) {
    int minx = (int)1e9;
    for (int j = 0; j < n; j++)
      if (cnum[j] == i) minx = min(minx, incomp[j].first);
    for (int j = 0; j < n; j++)
      if (cnum[j] == i) incomp[j].first -= minx, incomp[j].second -= minx;
    done[i] = 0;
    for (int j = 0; j < n; j++)
      if (cnum[j] == i) {
        for (int k = 0; k < n; k++)
          if (common[j][k] == sz[j]) in[i][cnum[k]] = 1;
      }
  }
  for (int it = 0; it < cnt; it++)
    for (int i = 0; i < cnt; i++) {
      if (done[i]) continue;
      int ups = 0;
      for (int j = 0; j < cnt && !ups; j++)
        if (i != j && in[i][j] == 1 && !done[j]) ups = 1;
      if (ups) continue;
      bool gok = 0;
      for (int pos = 0; pos < n; pos++) {
        bool ok = 1;
        for (int j = 0; j < n && ok; j++)
          if (cnum[j] == i) {
            if (incomp[j].second + pos >= n) {
              ok = 0;
              break;
            }
            for (int k = 0; k < n && ok; k++)
              if (done[cnum[k]] &&
                  common[k][j] !=
                      len(intersect(make_pair(incomp[j].first + pos,
                                              incomp[j].second + pos),
                                    incomp[k])))
                ok = 0;
          }
        if (ok) {
          for (int j = 0; j < n; j++)
            if (cnum[j] == i) incomp[j].first += pos, incomp[j].second += pos;
          gok = 1;
          break;
        }
      }
      if (!gok) {
        cout << "NO\n";
        return 0;
      }
      done[i] = 1;
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      assert(len(intersect(incomp[i], incomp[j])) == common[i][j]);
  cout << "YES\n";
  for (int i = 0; i < n; i++, cout << "\n")
    for (int j = 0; j < n; j++)
      cout << bool(j >= incomp[i].first && j <= incomp[i].second);
  return 0;
}