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 C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int H,W,match_r[12],match_c[12];
string grid[12];
bool ok;
bool check(){
	memset(match_c,-1,sizeof match_c);
	for(int i=0;i<W;i++){
		if(match_c[i]!=-1) continue;
		for(int j=i+1;j<W;j++){
			if(match_c[j]!=-1) continue;
			bool succ=true;
			for(int k=0;k<H && succ;k++)
				if(grid[match_r[k]][i]!=grid[k][j])
					succ=false;
			if(succ){
				match_c[i]=j,match_c[j]=i;
				break;
			}
		}
	}
	int unmatch=0,mid;
	for(int i=0;i<W;i++)
		if(match_c[i]==-1){
			unmatch++;
			mid=i;
		}
	if(unmatch>=2 || (unmatch && W%2==0)) return false;
	if(!unmatch) return true;
	for(int i=0;i<H;i++)
		if(grid[match_r[i]][mid]!=grid[i][mid])
			return false;
	return true;
}
void dfs(int idx,bool is_skip){
	if(idx>=H){
		if(check()) ok=true;
	}else{
		if(match_r[idx]!=-1){
			dfs(idx+1,is_skip);
		}else{
			for(int i=idx+1;i<H;i++){
				if(match_r[i]==-1){
					match_r[idx]=i;
					match_r[i]=idx;
					dfs(idx+1,is_skip);
					match_r[idx]=match_r[i]=-1;
				}
			}
			if(!is_skip && H&1){
				match_r[idx]=idx;
				dfs(idx+1,true);
				match_r[idx]=-1;
			}
		}
	}
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>H>>W;
	for(int i=0;i<H;i++)
		cin>>grid[i];
	memset(match_r,-1,sizeof match_r);
	dfs(0,false);
	cout<<(ok?"YES":"NO")<<'\n';
	return 0;
}