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 JAVA):

Solution:
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author George Marcus
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskE solver = new TaskE();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskE {
    char[][] A;
    int[] ans;
    ArrayList<Integer>[] B;
    int[] inGroup;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int N = in.nextInt();
        A = new char[N][];
        for (int i = 0; i < N; i++) {
            A[i] = in.nextString().toCharArray();
        }

        ans = new int[N + 1];
        B = new ArrayList[N];
        for (int i = 0; i < N; i++) {
            B[i] = new ArrayList<Integer>();
            for (int j = 0; j < N; j++) {
                if (A[i][j] == '1') {
                    B[i].add(j);
                }
            }
        }

        ArrayList<Integer> rows = new ArrayList<Integer>();
        ArrayList<Integer> cols = new ArrayList<Integer>();
        for (int i = 0; i < N; i++) {
            if (!B[i].isEmpty()) {
                rows.add(i);
            }
            cols.add(i);
        }

        inGroup = new int[N];
        if (go(rows, cols)) {
            if (ans[0] != N) {
                throw new RuntimeException();
            }

            out.println("YES");
            for (int i = 0; i < N; i++) {
                for (int j = 1; j <= N; j++) {
                    out.print(A[i][ans[j]]);
                }
                out.println();
            }
        }
        else {
            out.println("NO");
        }
    }

    private boolean go(ArrayList<Integer> rows, ArrayList<Integer> cols) {
        if (rows.isEmpty()) {
            for (int col : cols) {
                ans[++ans[0]] = col;
            }
            return true;
        }

        int pmax = 0;
        for (int i = 1; i < rows.size(); i++) {
            if (B[rows.get(i)].size() > B[rows.get(pmax)].size()) {
                pmax = i;
            }
        }
        int maxRow = rows.get(pmax);
        rows.remove(pmax);

        ArrayList<ArrayList<Integer>> groups = new ArrayList<ArrayList<Integer>>();
        ArrayList<Integer> ones = new ArrayList<Integer>();
        ArrayList<Integer> zeros = new ArrayList<Integer>();
        split(maxRow, cols, ones, zeros);
        groups.add(ones);
        groups.add(zeros);

        if (rows.isEmpty()) {
            for (ArrayList<Integer> gcols : groups) {
                for (int gcol : gcols) {
                    ans[++ans[0]] = gcol;
                }
            }
            return true;
        }
        if (ones.isEmpty() || zeros.isEmpty()) {
            return go(rows, cols);
        }

        int p = -1;
        int special = groups.get(groups.size() - 1).size();
        while ((p = find(groups, rows)) != -1) {
            rows.remove((Integer) p);

            int state = 0;
            boolean maybe = false;
            ArrayList<ArrayList<Integer>> ngroups = new ArrayList<ArrayList<Integer>>();
            for (int i = 0; i < groups.size(); i++) {
                ArrayList<Integer> group = groups.get(i);
                ones = new ArrayList<Integer>();
                zeros = new ArrayList<Integer>();
                split(p, group, ones, zeros);

                if (state == 0) {
                    if (!zeros.isEmpty()) ngroups.add(zeros);
                    if (!ones.isEmpty()) {
                        ngroups.add(ones);
                        state = 1;
                    }
                }
                else if (state == 1) {
                    if (!ones.isEmpty()) ngroups.add(ones);
                    if (!zeros.isEmpty()) {
                        ngroups.add(zeros);
                        state = 2;
                    }
                }
                else { // 2
                    if (!zeros.isEmpty()) ngroups.add(zeros);
                    if (!ones.isEmpty()) {
                        if (i + 1 < groups.size() || special == 0) {
                            return false;
                        }
                        else {
                            maybe = true;
                        }
                    }
                }
                if (i == groups.size() - 1) {
                    special -= ones.size();
                }
            }

            if (maybe) {
                ngroups = new ArrayList<ArrayList<Integer>>();
                state = 0;
                for (int i = 0; i < groups.size(); i++) {
                    ArrayList<Integer> group = groups.get(i);
                    ones = new ArrayList<Integer>();
                    zeros = new ArrayList<Integer>();
                    split(p, group, ones, zeros);

                    if (i == groups.size() - 1) {
                        if (!ones.isEmpty()) ngroups.add(0, ones);
                        if (!zeros.isEmpty()) ngroups.add(zeros);
                        break;
                    }
                    if (!ones.isEmpty()) {
                        if (state == 1) return false;
                        ngroups.add(ones);
                    }
                    if (!zeros.isEmpty()) {
                        if (state == 0) state = 1;
                        ngroups.add(zeros);
                    }
                }
            }

            groups = ngroups;
        }

        ArrayList<Integer>[] groupRows = new ArrayList[groups.size()];
        for (int i = 0; i < groups.size(); i++) {
            groupRows[i] = new ArrayList<Integer>();
        }
        for (int r : rows) {
            int f = B[r].get(0);
            int g = inGroup[f];
            groupRows[g].add(r);
        }
        for (int i = 0; i < groups.size(); i++) {
            if (!go(groupRows[i], groups.get(i))) {
                return false;
            }
        }
        return true;
    }

    private int find(ArrayList<ArrayList<Integer>> groups, ArrayList<Integer> rows) {
        for (int i = 0; i < groups.size(); i++) {
            for (int col : groups.get(i)) {
                inGroup[col] = i;
            }
        }
        for (int r : rows) {
            for (int j = 1; j < B[r].size(); j++) {
                if (inGroup[ B[r].get(j - 1) ] != inGroup[ B[r].get(j) ]) {
                    return r;
                }
            }
        }
        return -1;
    }

    private void split(int row, ArrayList<Integer> cols, ArrayList<Integer> ones, ArrayList<Integer> zeros) {
        for (int col : cols) {
            if (A[row][col] == '1') {
                ones.add(col);
            }
            else {
                zeros.add(col);
            }
        }
    }
}

class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int nextInt() {
        return Integer.parseInt(nextString());
    }

    public String nextString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));

        return res.toString();
    }

    private boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

}