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

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static bool Solve(int N, string[] S)
        {
            var dict = new Dictionary<string, int>();
            foreach (string s in S)
            {
                if (!dict.ContainsKey(s)) { dict[s] = 0; }
                ++dict[s];
            }
            int count = 0;
            foreach (int value in dict.Values)
            {
                if (value % 2 != 0) { ++count; }
            }
            return (N % 2 != 0) ? (count == 1) : (count == 0);
        }
        static bool Solve(int H, int W, string[] S)
        {
            var S1 = new string[H];
            for (int i = 0; i < H; ++i)
            {
                S1[i] = new string(S[i].OrderBy(c => c).ToArray());
            }
            var S2 = new string[W];
            for (int i = 0; i < W; ++i)
            {
                S2[i] = new string(Enumerable.Range(0, H).Select(j => S[j][i]).OrderBy(c => c).ToArray());
            }
            return Solve(H, S1) && Solve(W, S2);
        }
        static void Main(string[] args)
        {
            int[] V = ReadInts();
            int H = V[0];
            int W = V[1];
            var S = new string[H];
            for (int i = 0; i < H; ++i) { S[i] = Read(); }
            Console.WriteLine(Solve(H, W, S) ? "YES" : "NO");
        }
    }
}