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 M = 1 << 11;
char str[M][M];
bool has_all(char *col, vector<int> &inds) {
  for (int i = 0; i < (int)inds.size(); ++i)
    if (col[inds[i]] == '0') return false;
  return true;
}
bool add_boundary_constraint(int &n, vector<char *> &a, vector<int> &bound,
                             int symbol) {
  if (!bound.empty()) {
    bool candidate_exists = false;
    for (int j = 0; j < (int)a.size(); ++j)
      if (has_all(a[j], bound)) {
        a[j][n] = '0' + symbol;
        candidate_exists = true;
      } else
        a[j][n] = '0' + 1 - symbol;
    if (!candidate_exists) return false;
    ++n;
  }
  return true;
}
int count(vector<char *> &v, int row) {
  int res = 0;
  for (int j = 0; j < (int)v.size(); ++j)
    if (v[j][row] == '1') ++res;
  return res;
}
bool go(vector<char *> &v, int n, int m) {
  int cnt[M], cnt_a[M], cnt_b[M];
  int max_ind = -1;
  for (int i = 0; i < n; ++i) {
    cnt[i] = count(v, i);
    if (cnt[i] != m && (max_ind == -1 || cnt[max_ind] < cnt[i])) max_ind = i;
  }
  if (max_ind == -1 || cnt[max_ind] <= 1) return true;
  vector<char *> a, b;
  for (int i = 0; i < m; ++i)
    if (v[i][max_ind] == '1')
      a.push_back(v[i]);
    else
      b.push_back(v[i]);
  int a_sz = cnt[max_ind];
  int b_sz = (int)b.size();
  vector<int> common;
  for (int i = 0; i < n; ++i) {
    cnt_a[i] = count(a, i);
    cnt_b[i] = count(b, i);
    if (cnt_a[i] != 0 && cnt_b[i] != 0 && cnt[i] != m) common.push_back(i);
  }
  set<int> first_bound;
  if (!common.empty()) {
    first_bound.insert(0);
    for (int j = 0; j < b_sz; ++j)
      if (b[j][common[0]] == '1')
        for (int k = 1; k < (int)common.size(); ++k)
          if (b[j][common[k]] == '1') first_bound.insert(k);
  }
  vector<int> bound1, bound2;
  for (int k = 0; k < (int)common.size(); ++k)
    if (first_bound.count(k) == 0)
      bound2.push_back(common[k]);
    else
      bound1.push_back(common[k]);
  int old_n = n;
  if (!add_boundary_constraint(n, a, bound1, 0)) return false;
  if (!add_boundary_constraint(n, a, bound2, 0)) return false;
  if (!go(a, n, a_sz)) return false;
  n = old_n;
  if (!add_boundary_constraint(n, b, bound1, 1)) return false;
  if (!add_boundary_constraint(n, b, bound2, 1)) return false;
  char *col;
  if (!bound1.empty()) {
    col = new char[M];
    for (int i = 0; i < old_n; ++i)
      if (cnt[i] == m)
        col[i] = '1';
      else
        col[i] = '0';
    for (int i = old_n; i < n; ++i) col[i] = '1';
    b.push_back(col);
    ++b_sz;
  }
  if (!go(b, n, b_sz)) return false;
  v.clear();
  if (bound1.empty()) {
    for (int j = 0; j < a_sz; ++j) v.push_back(a[j]);
    for (int j = 0; j < b_sz; ++j) v.push_back(b[j]);
    return true;
  }
  bool fake_found = false;
  for (int j = 0; j < b_sz; ++j)
    if (b[j] == col) {
      if (fake_found) throw -1;
      fake_found = true;
      bool has_all_b = j > 0 && has_all(b[j - 1], bound1);
      bool has_all_a = has_all(a[0], bound1);
      if (has_all_a != has_all_b) reverse(a.begin(), a.end());
      for (int k = 0; k < a_sz; ++k) v.push_back(a[k]);
    } else
      v.push_back(b[j]);
  if (!fake_found) throw -1;
  return true;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%s", str[i]);
  vector<char *> v;
  for (int j = 0; j < n; ++j) {
    char *col = new char[M];
    for (int i = 0; i < n; ++i) col[i] = str[i][j];
    v.push_back(col);
  }
  if (!go(v, n, n)) {
    puts("NO");
    return 0;
  }
  puts("YES");
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) putchar(v[j][i]);
    puts("");
  }
  return 0;
}