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 <bits/stdc++.h>

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 20;

int N, M;
bool Vis[MAX_N];
char Mp[MAX_N][MAX_N];
char Now[MAX_N][MAX_N];
string S[MAX_N];
void chooseH() {
	map<string, set<int>> mp;
	vector<bool> vis(N, false);
	for(int i=0; i<N; i++) {
		S[i] = Now[i];
		//printf("%d : %s\n", i, S[i].c_str());
		mp[S[i]].insert(i);
		string rs = S[i]; reverse(ALL(rs));
		mp[rs];
	}
	bool used = false;
	if(N % 2 == 0) used = true;
	for(int i=0; i<N; i++) if(!vis[i]) {
		vis[i] = true;
		string s = S[i];
		mp[S[i]].erase(i);
		string rs = s;
		reverse(ALL(rs));
		if(SZ(mp[rs]) == 0) {
			if(rs == s) {
				if(used) return;
				used = true;
			}else{
				return;
			}
		}else{
			auto it = mp[rs].begin();
			vis[*it] = true;
			mp[rs].erase(it);
		}
	}
	puts("YES");
	exit(0);
}
void chooseW(int who, int ix, int cnt) {
	if(who == M) return chooseH();
	if(Vis[who]) return chooseW(who+1, ix, cnt);
	Vis[who] = true;
	for(int k=0; k<N; k++) Now[k][ix] = Mp[k][who];
	if(cnt+1 == M) {
		chooseH();
		Vis[who] = false;
		return;
	}
	for(int i=who+1; i<M; i++) if(not Vis[i]) {
		Vis[i] = true;
		for(int k=0; k<N; k++) Now[k][M-1-ix] = Mp[k][i];
		chooseW(who+1, ix+1, cnt+2);
		Vis[i] = false;
	}
	Vis[who] = false;
}
int main() {
	cin >> N >> M;
	for(int i=0; i<N; i++) scanf("%s", Mp[i]);
	for(int k=0; k<N; k++) Now[k][M] = 0;
	chooseW(0, 0, 0);
	puts("NO");
	return 0;
}