Problem:
Score : 700 points

Problem Statement

There is an H \times W grid (H vertical, W horizontal), where each square contains a lowercase English letter.
Specifically, the letter in the square at the i-th row and j-th column is equal to the j-th character in the string S_i.

Snuke can apply the following operation to this grid any number of times:

Choose two different rows and swap them. Or, choose two different columns and swap them.

Snuke wants this grid to be symmetric.
That is, for any 1 \leq i \leq H and 1 \leq j \leq W, the letter in the square at the i-th row and j-th column and the letter in the square at the (H + 1 - i)-th row and (W + 1 - j)-th column should be equal.

Determine if Snuke can achieve this objective.

Constraints

1 \leq H \leq 12

1 \leq W \leq 12

|S_i| = W

S_i consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

H W
S_1
S_2
:
S_H

Output

If Snuke can make the grid symmetric, print YES; if he cannot, print NO.

Sample Input 1

2 3
arc
rac

Sample Output 1

YES

If the second and third columns from the left are swapped, the grid becomes symmetric, as shown in the image below:

Sample Input 2

3 7
atcoder
regular
contest

Sample Output 2

NO

Sample Input 3

12 12
bimonigaloaf
faurwlkbleht
dexwimqxzxbb
lxdgyoifcxid
ydxiliocfdgx
nfoabgilamoi
ibxbdqmzxxwe
pqirylfrcrnf
wtehfkllbura
yfrnpflcrirq
wvcclwgiubrk
lkbrwgwuiccv

Sample Output 3

YES

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
	new Main().run();
    }
    
    void run(){
	Scanner sc=new Scanner();
	int H=sc.nextInt();
	int W=sc.nextInt();
	char[][] map=new char[H][W];
	for(int i=0;i<H;++i){
	    map[i]=sc.next().toCharArray();
	}
	int[] bind=new int[W];
	Arrays.fill(bind,-1);
	System.out.println(func(map,bind,0,W)?"YES":"NO");
    }

    boolean func(char[][] map,int[] bind,int pos,int res){
	if(res==0){
	    return calc(map,bind);
	}else if(res==1){
	    boolean ret=true;
	    for(int j=0;j<bind.length;++j){
		if(bind[j]!=-1)continue;
		bind[j]=j;
		ret&=calc(map,bind);
		bind[j]=-1;
		return ret;
	    }
	}
	while(pos<bind.length&&bind[pos]!=-1)
	    ++pos;
	boolean ret=false;
	for(int i=pos+1;i<bind.length;++i){
	    if(bind[i]!=-1)continue;
	    bind[i]=pos;
	    bind[pos]=i;
	    ret|=func(map,bind,pos+1,res-2);
	    bind[i]=-1;
	    bind[pos]=-1;
	}
	return ret;
    }

    boolean calc(char[][] map,int[] bind){
	int H=map.length;
	int W=map[0].length;
	boolean[] used=new boolean[H];
	for(int i=0;i<H;++i){
	    if(used[i])continue;
	    for(int j=i+1;j<H;++j){
		boolean flag=true;
		for(int k=0;k<W;++k){
		    flag&=map[i][k]==map[j][bind[k]];
		}
		if(flag){
		    used[i]=true;
		    used[j]=true;
		    break;
		}
	    }
	}
	int cnt=0;
	for(int i=0;i<H;++i){
	    if(used[i])++cnt;
	}
	return cnt==H;
    }

    void tr(Object...o){
	System.out.println(Arrays.deepToString(o));
    }
    
}


class Scanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt(){
	return (int)nextLong();
    }
}