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 = 2e3 + 3, M = N * 4;
int n, m, sum, rt, s[M], sze[M], sal[N];
bool res = true;
char str[N][N];
struct PQTree {
  vector<int> sub;
  bool rev, flag;
  int PQ;
  inline void Clear() {
    sub.clear();
    rev = flag = false;
    PQ = 0;
  }
} a[M];
inline void Rev(const int &x) {
  if (a[x].PQ != 2 || a[x].flag) return;
  a[x].rev = !a[x].rev;
  reverse(a[x].sub.begin(), a[x].sub.end());
}
inline void pushdown(const int &x) {
  if (!a[x].rev) return;
  a[x].rev = false;
  for (int i = 0; i < a[x].sub.size(); ++i) Rev(a[x].sub[i]);
}
inline void Cont(const int &x) {
  pushdown(x);
  sze[x] = x <= n;
  for (int i = 0; i < a[x].sub.size(); ++i) {
    Cont(a[x].sub[i]);
    s[x] += s[a[x].sub[i]];
    sze[x] += sze[a[x].sub[i]];
  }
}
inline void Solve(const int &x) {
  pushdown(x);
  if (x <= n) sal[++m] = x;
  for (int i = 0; i < a[x].sub.size(); ++i) Solve(a[x].sub[i]);
}
inline bool Dfs(const int &x, const int &y) {
  pushdown(x);
  if (sze[x] == s[x]) return true;
  if (a[x].PQ == 1) {
    vector<int> A, B, C;
    A.clear();
    B.clear();
    C.clear();
    for (int i = 0; i < a[x].sub.size(); ++i) {
      if (s[a[x].sub[i]] == sze[a[x].sub[i]])
        A.push_back(a[x].sub[i]);
      else if (s[a[x].sub[i]] > 0)
        B.push_back(a[x].sub[i]);
      else
        C.push_back(a[x].sub[i]);
    }
    if (B.size() > 2)
      return false;
    else if (B.size() == 2 && y)
      return false;
    if (B.size() == 2) {
      if (!Dfs(B[0], 1)) return false;
      if (!Dfs(B[1], 2)) return false;
    } else if (B.size() == 1) {
      if (y) {
        if (!Dfs(B[0], y)) return false;
      } else {
        if (!A.size()) {
          if (!Dfs(B[0], y)) return false;
        } else {
          if (!Dfs(B[0], 1)) return false;
        }
      }
    }
    int X = 0, Y = 0;
    if (A.size() == 1)
      X = A[0];
    else if (A.size() > 1) {
      a[X = ++sum].PQ = 1;
      a[X].sub = A;
    }
    if (C.size() == 1)
      Y = C[0];
    else if (C.size() > 1) {
      a[Y = ++sum].PQ = 1;
      a[Y].sub = C;
    }
    if (B.size() == 1) {
      if (!X)
        X = B[0];
      else {
        int tmp = ++sum;
        a[tmp].PQ = 2;
        if (y == 0)
          a[tmp].flag = true;
        else
          a[tmp].flag = false;
        if (y != 2) a[tmp].sub.push_back(B[0]);
        a[tmp].sub.push_back(X);
        if (y == 2) a[tmp].sub.push_back(B[0]);
        X = tmp;
      }
    } else if (B.size() == 2) {
      int tmp = ++sum;
      a[tmp].PQ = 2;
      a[tmp].flag = true;
      a[tmp].sub.push_back(B[0]);
      if (X) a[tmp].sub.push_back(X);
      a[tmp].sub.push_back(B[1]);
      X = tmp;
    }
    if (!y) {
      if (!Y)
        a[x] = a[X];
      else {
        int tmp = ++sum;
        a[tmp].PQ = 1;
        a[tmp].sub = C;
        a[tmp].sub.push_back(X);
        a[x] = a[tmp];
        a[sum--].Clear();
      }
    } else {
      int tmp = ++sum;
      a[tmp].PQ = 2;
      a[tmp].flag = false;
      if (y == 2) a[tmp].sub.push_back(X);
      if (Y) a[tmp].sub.push_back(Y);
      if (y == 1) a[tmp].sub.push_back(X);
      a[x] = a[tmp];
      a[sum--].Clear();
    }
  } else {
    int l, r;
    for (l = 0; l < a[x].sub.size(); ++l)
      if (s[a[x].sub[l]]) break;
    for (r = l; r < a[x].sub.size(); ++r)
      if (!s[a[x].sub[r]]) break;
    --r;
    for (int i = r + 1; i < a[x].sub.size(); ++i)
      if (s[a[x].sub[i]]) return false;
    for (int i = l + 1; i < r; ++i)
      if (sze[a[x].sub[i]] != s[a[x].sub[i]]) return false;
    if (y == 1) {
      if (r + 1 < a[x].sub.size() ||
          l < r && sze[a[x].sub[r]] != s[a[x].sub[r]]) {
        if (!a[x].flag) return false;
        a[x].flag = false;
        Rev(x);
        if (!Dfs(x, y)) return false;
        return true;
      }
      a[x].flag = false;
    }
    if (y == 2) {
      if (l > 0 || l < r && sze[a[x].sub[l]] != s[a[x].sub[l]]) {
        if (!a[x].flag) return false;
        a[x].flag = false;
        Rev(x);
        if (!Dfs(x, y)) return false;
        return true;
      }
      a[x].flag = false;
    }
    if (l == r) {
      if (!Dfs(a[x].sub[l], y)) return false;
    } else {
      if (!Dfs(a[x].sub[l], 1)) return false;
      if (!Dfs(a[x].sub[r], 2)) return false;
    }
  }
  return true;
}
int main() {
  scanf("%d", &n);
  a[rt = sum = n + 1].PQ = 1;
  for (int i = 1; i <= n; ++i) a[rt].sub.push_back(i);
  for (int i = 1; i <= n; ++i) {
    memset(s, 0, sizeof(s));
    scanf("%s", str[i] + 1);
    for (int j = 1; j <= n; ++j)
      if (str[i][j] == '1') s[j] = 1;
    Cont(rt);
    if (!s[rt]) continue;
    if (!Dfs(rt, 0)) {
      res = false;
      break;
    }
  }
  if (!res)
    puts("NO");
  else {
    puts("YES");
    Solve(rt);
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) printf("%c", str[i][sal[j]]);
      printf("\n");
    }
  }
  return 0;
}