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 <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
typedef long long int ll;

int h, w;
string s0[12];
bool e;

void solve(vector<int> v){
  if(e==1) return;
  if(v.size()==(h+1)/2){
    bool b[12]={};
    for(int j=0; j<v.size(); j++){
      b[v[j]]=1;
    }
    for(int i=0; i<h; i++){
      if(b[i]==0){
        v.push_back(i);
      }
    }
    for(int i=0; i<h/2; i++){
      if(v[i]>v[h-1-i]) return;
    }
    string str[12];
    for(int i=0; i<w; i++){
      for(int j=0; j<h; j++){
        str[i]+=s0[v[j]][i];
      }
    }
    int t=0;
    bool used[12]={};
    string rstr[12];
    for(int i=0; i<w; i++){
      for(int j=0; j<h; j++){
        rstr[i]+=str[i][h-1-j];
      }
    }
    for(int i=0; i<w; i++){
      if(used[i]==1) continue;
      bool e1=0;
      for(int j=0; j<w; j++){
        if(i==j || used[j]==1) continue;
        if(str[i]==rstr[j]){
          used[i]=1;
          used[j]=1;
          e1=1;
          break;
        }
      }
      if(e1==0){
        if(str[i]!=rstr[i]){
          return;
        }
      }
    }
    for(int i=0; i<w; i++){
      if(used[i]==0) t++;
    }
    if((t==0 && w%2==0) || (t==1 && w%2==1)) e=1;
    return;
  }
  bool used[12]={};
  for(int j=0; j<v.size(); j++){
    used[v[j]]=1;
  }
  for(int i=0; i<h; i++){
    if(used[i]==0){
      v.push_back(i);
      solve(v);
      v.pop_back();
    }
  }
  return;
}

int main()
{
	e=0;
  scanf("%d %d", &h, &w);
  for(int i=0; i<h; i++){
    cin>>s0[i];
  }
  vector<int> v;
  solve(v);
  if(e==1){
    printf("YES\n");
  }else{
	printf("NO\n");
  }
	return 0;
}