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: Wrong Answer)

#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#define inl inline
#define reg register
#define C 18
#define P 33
#define N 12
#define S 4096
using namespace std;
bool eq[N][N],dp[S];
char s[N][N|1];
int n,m,c,p[N];
inl int rnd() {
	return c=((0u+(1u*c<<27)+(1u*c>>5))>>1);
}
inl void rndp() {
	for(int i=1;i<n;i++)
		swap(p[i],p[rnd()%i]);
}
int main() {
	srand(time(0));
	c=rand();
	scanf("%d%d",&n,&m);
	for(reg int i=0;i<n;i++)
		p[i]=i,scanf("%s",s[i]);
	while(C*clock()<P*10*CLOCKS_PER_SEC) {
		rndp();
		memset(eq,1,sizeof(eq));
		for(int i=0;i<m;i++)
			for(int j=i;j<m;j++)
				for(int k=0;k<n;k++)
					if(s[p[k]][i]!=s[p[n-k-1]][j])
						eq[i][j]=0;
		memset(dp,0,sizeof(dp));
		dp[0]=1;
		for(int s=0;s<(1<<m);s++)
			for(int i=0;i<m;i++)
				for(int j=i;j<m;j++)
					if(!(1<<i&s)&&!(1<<j&s)&&eq[i][j])
						dp[s|(1<<i)|(1<<j)]=1;
		bool chk=0;
		if(m&1) {
			for(int i=0;i<m;i++)
				if(dp[(1<<m)-(1<<i)-1]&&eq[i][i])
					chk=1;
		} else	chk=dp[(1<<m)-1];
		if(chk) {	puts("YES");	return 0;	}
	}	puts("NO");	return 0;
}