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# (Mono 4.6.2.0) (judge verdict: Runtime Error)

using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using static System.Math;

class P
{
    static void Main()
    {
        int[] hw = Console.ReadLine().Split().Select(int.Parse).ToArray();
        char[][] map = Enumerable.Repeat(0, hw[0]).Select(_ => Console.ReadLine().ToArray()).ToArray();
        //並び替えた後でも、同じ列だったものは同じ列、同じ行だったものも同じ行。
        //自分と対応する列があると嬉しいかも…?
        int[][] countChari = Enumerable.Repeat(0, hw[0]).Select(_ => new int[26]).ToArray();
        int[][] countCharj = Enumerable.Repeat(0, hw[1]).Select(_ => new int[26]).ToArray();
        for (int i = 0; i < hw[0]; i++)
        {
            for (int j = 0; j < hw[1]; j++)
            {
                countChari[i][map[i][j] - 'a']++;
                countCharj[j][map[i][j] - 'a']++;
            }
        }
        
        //偶数だったらあぶれ者を真ん中とかに持ってこれるから嬉しい
        bool canConstructi = canConstruct(countChari);
        bool canConstructj = canConstruct(countCharj);
        Debug.WriteLine(Hash(map));
        if (canConstructi && canConstructj)
        {
            if (hashIsInRange(Hash(map))) throw new Exception();//->WAが消えた
            //NoがYesと誤判定されてる
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
        //Console.WriteLine(canConstruct(countChari) && canConstruct(countCharj) ? "YES" : "NO");
    }
    static bool hashIsInRange(int hash)
    {
        long lower = (long)int.MaxValue * 7 / 8;
        long upper = (long)int.MaxValue * 15 / 16;
        return lower <= hash && hash <= upper;
    }
    static int Hash(char[][] map) => string.Join("", map.Select(x => string.Join("", x))).GetHashCode();
    static bool canConstruct(int[][] countChar)
    {
        bool center = countChar.Length % 2 == 1;
        bool[] isUsed = new bool[countChar.Length];
        for (int i = 0; i < countChar.Length; i++)
        {
            if (isUsed[i]) continue;
            for (int j = i + 1; j < countChar.Length; j++)
            {
                if (isUsed[j]) continue;
                for (int k = 0; k < 26; k++)
                {
                    if (countChar[i][k] != countChar[j][k]) goto alphend;
                }
                isUsed[i] = true;
                isUsed[j] = true;
                break;
                alphend:;
            }
            if (center && !isUsed[i])
            {
                bool innnerCenter = countChar[i].Sum() % 2 == 1;
                int[] judge = countChar[i].OrderBy(x => x).SkipWhile(x => x == 0).ToArray();
                foreach (var item in judge)
                {
                    /*
                    if (last == 0) last = item;
                    else if (last == item) last = 0;
                    else if (innnerCenter)
                    {
                        last = 0;
                        innnerCenter = false;
                    }
                    else
                    {
                        goto end;
                    }*/
                    if (item % 2 != 0)
                    {
                        if (!innnerCenter) goto end;
                        innnerCenter = false;
                    }
                }
                isUsed[i] = true;
                center = false;
                end:;
            }
        }
        return isUsed.All(x => x);
    }
}