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)

#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>

using namespace std;

long long N,a,b;
long long A;
long long B;
long long yoko[20][26] = {};
long long tate[20][26] = {};
bool yokof[20] = {};
bool tatef[20] = {};
bool no = false;
long long result=0;
string S[20];
vector <long long>vl;
vector <long> v;
//typedef pair<long long, long long> pl;
bool gusut(int aa);
bool gusut(int aa) {
	int bb = 0;
	for (int i = 0; i < 26; i++) {
		bb += tate[aa][i] % 2;
	}
	if (bb <= 1) {
		return true;
	}
	else {
		return false;
	}

}
bool gusuy(int aa);
bool gusuy(int aa) {
	int bb = 0;
	for (int i = 0; i < 26; i++) {
		bb += yoko[aa][i] % 2;
	}
	if (bb <= 1) {
		return true;
	}
	else {
		return false;
	}

}


int main() {

	cin >>A>>B;
	a = 0;
	for (int i = 0; i < A; i++) {
		cin >> S[i];
		for (int j = 0; j < B; j++) {
			yoko[i][S[i][j] - 'a']++;
			tate[j][S[i][j] - 'a']++;
		}

	}

	if (A == 1 && B!=1) {
		if (gusuy(0) == false) {
			no = true;
		}

	}
	else if (B == 1 && A!=1) {
		if (gusut(0) == false) {
			no = true;
		}
	}
	else {
		for (int i = 0; i < A; i++) {
			b = 0;
			if (yokof[i] == false) {

				for (int j = i + 1; j < A; j++) {
					if (yokof[j] == false) {
						for (int k = 0; k < 26; k++) {
							if (yoko[i][k] != yoko[j][k]) {
								break;
							}
							else if (k == 25) {
								yokof[i] = true;
								yokof[j] = true;
								b = 1;
							}

						}
					}

					if (b == 1) {
						break;
					}
					else if (j == A - 1) {
						if (A % 2 == 1 && a == 0) {
							if (gusuy(i) == true) {
								a++;
							}
							else {
								no = true;
							}
						}
						else {
							no = true;
						}
					}

				}
			}
			if (no == true) {
				break;
			}
		}

		a = 0;

		if (no == false) {
			for (int i = 0; i < B; i++) {
				b = 0;
				if (tatef[i] == false) {

					for (int j = i + 1; j < B; j++) {
						if (tatef[j] == false) {
							for (int k = 0; k < 26; k++) {
								if (tate[i][k] != tate[j][k]) {
									break;
								}
								else if (k == 25) {
									tatef[i] = true;
									tatef[j] = true;
									b = 1;
								}

							}
						}

						if (b == 1) {
							break;
						}
						else if (j == B - 1) {
							if (A % 2 == 1 && a == 0) {
								if (gusut(i) == true) {
									a++;
								}
								else {
									no = true;
								}
							}
							else {
								no = true;
							}
						}

					}
				}
				if (no == true) {
					break;
				}
			}
		}
	}

	if (no == true){
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}
	

return 0;
}