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>
const int N = 2000 + 10;
const int EMPTY = 0, SUB = 1, FULL = 2;
const int BLOCK = 0, LEFT = 1, RIGHT = 2;
int n;
char a[N][N];
struct node_t {
  std::vector<node_t *> next;
  char type;
  int id;
  bool tag, flag;
  node_t(char _c = 'S') : type(_c), tag(false), flag(false) { next.clear(); }
  void release() {
    if (!flag) return;
    std::reverse(next.begin(), next.end());
    for (std::vector<node_t *>::iterator it = next.begin(); it != next.end();
         ++it)
      (*it)->flag ^= 1;
    flag = false;
  }
  void toggle() {
    if (!tag || type == 'P') {
      puts("NO"), exit(EXIT_SUCCESS);
    };
    tag = false;
    flag = true;
    release();
  }
  void print();
} *root = new node_t('P'), pool[N];
void node_t::print() {
  release();
  printf("%p %c:", this, type);
  if (type == 'S') {
    printf("%ld\n", this - pool);
    return;
  }
  for (std::vector<node_t *>::iterator it = next.begin(); it != next.end();
       ++it)
    printf("%p ", *it);
  putchar('\n');
  for (std::vector<node_t *>::iterator it = next.begin(); it != next.end();
       ++it)
    (*it)->print();
}
std::vector<bool> state(N);
void DFS(node_t *u) {
  u->release();
  if (u->type == 'S') {
    u->id = (state[u - pool] ? FULL : EMPTY);
    return;
  }
  u->id = 0;
  int a = 0, b = 0;
  for (std::vector<node_t *>::iterator it = u->next.begin();
       it != u->next.end(); ++it) {
    node_t *v = *it;
    DFS(v);
    a += (v->id == EMPTY);
    b += (v->id == FULL);
  }
  if (a == u->next.size())
    u->id = EMPTY;
  else if (b == u->next.size())
    u->id = FULL;
  else
    u->id = SUB;
}
node_t *Split(node_t *u, int dir) {
  u->release();
  if (u->type == 'S') return u;
  std::vector<node_t *> set[3];
  for (std::vector<node_t *>::iterator it = u->next.begin();
       it != u->next.end(); ++it) {
    node_t *v = *it;
    set[v->id].push_back(v);
  }
  if (set[SUB].size() > 2) {
    puts("NO"), exit(EXIT_SUCCESS);
  };
  if (set[SUB].size() == 2 && dir != BLOCK) {
    puts("NO"), exit(EXIT_SUCCESS);
  };
  if (u->type == 'P') {
    if (set[FULL].empty() && set[SUB].size() == 1 && dir == BLOCK) {
      for (std::vector<node_t *>::iterator it = u->next.begin();
           it != u->next.end(); ++it) {
        node_t *&v = *it;
        if (v->id == SUB) {
          v = Split(v, BLOCK);
          return u;
        }
      }
    }
    node_t *x;
    if (set[FULL].empty()) {
      x = NULL;
    } else if (set[FULL].size() == 1) {
      x = set[FULL][0];
    } else {
      x = new node_t('P');
      x->next = set[FULL];
    }
    std::vector<node_t *> temp;
    if (!set[SUB].empty() && dir != LEFT)
      temp.push_back(Split(set[SUB][0], RIGHT));
    if (x) temp.push_back(x);
    if (set[SUB].size() > (dir == BLOCK ? 1 : 0) && dir != RIGHT)
      temp.push_back(Split(set[SUB].back(), LEFT));
    node_t *z = NULL;
    assert(temp.size() > 0);
    if (temp.size() == 1) {
      z = temp[0];
    } else {
      z = new node_t('Q');
      z->next = temp;
      z->tag = true;
    }
    if (set[EMPTY].empty()) {
      u = z;
    } else {
      if (dir == BLOCK) {
        u->flag = false;
        u->next = set[EMPTY];
        u->next.push_back(z);
      } else {
        node_t *y = NULL;
        if (set[EMPTY].size() == 1) {
          y = set[EMPTY][0];
        } else {
          y = new node_t('P');
          y->next = set[EMPTY];
        }
        u->type = 'Q';
        u->tag = u->flag = false;
        u->next.clear();
        if (dir == LEFT) std::swap(y, z);
        u->next.push_back(y);
        u->next.push_back(z);
      }
    }
    return u;
  } else {
    if (dir == LEFT &&
        !(u->next[0]->id == FULL ||
          (u->next[0]->id != EMPTY && u->next.back()->id != FULL)))
      u->toggle();
    if (dir == RIGHT &&
        !(u->next.back()->id == FULL ||
          (u->next.back()->id != EMPTY && u->next[0]->id != FULL)))
      u->toggle();
    bool flag = false;
    int last = -1;
    for (std::vector<node_t *>::iterator it = u->next.begin();
         it != u->next.end(); ++it) {
      node_t *v = *it;
      if (~last) {
        if (dir == LEFT && v->id > last) {
          puts("NO"), exit(EXIT_SUCCESS);
        };
        if (dir == RIGHT && v->id < last) {
          puts("NO"), exit(EXIT_SUCCESS);
        };
        flag |= (v->id == EMPTY && last != EMPTY);
        if (flag && v->id != EMPTY && last == EMPTY) {
          puts("NO"), exit(EXIT_SUCCESS);
        };
      }
      last = v->id;
    }
    int cnt = 0;
    for (std::vector<node_t *>::iterator it = u->next.begin();
         it != u->next.end(); ++it) {
      node_t *&v = *it;
      cnt += (v->id != EMPTY);
      if (v->id == SUB) {
        if (dir == LEFT) {
          v = Split(v, LEFT);
        } else if (dir == RIGHT) {
          v = Split(v, RIGHT);
        } else {
          if (set[FULL].size() + set[SUB].size() == 1)
            v = Split(v, BLOCK);
          else
            v = Split(v, (cnt > 1) ? LEFT : RIGHT);
        }
      }
    }
    return u;
  }
}
std::vector<int> ans;
void Inorder(node_t *u) {
  u->release();
  if (u->type == 'S') {
    ans.push_back(u - pool);
    return;
  }
  for (std::vector<node_t *>::iterator it = u->next.begin();
       it != u->next.end(); ++it)
    Inorder(*it);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf(" %s", a[i]);
    root->next.push_back(pool + i);
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) state[j] = (a[i][j] == '1');
    DFS(root);
    if (root->id == EMPTY) continue;
    root = Split(root, BLOCK);
  }
  Inorder(root);
  puts("YES");
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) putchar(a[i][ans[j]]);
    putchar('\n');
  }
  return 0;
}