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.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.Remoting.Contexts;
using System.Security.Cryptography.X509Certificates;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }
        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }
    }

    struct A
    {
        public int Value, Index;

        public A(int v, int i)
        {
            Value = v;
            Index = i;
        }
    }

    class Program
    {
        private int H, W;
        private char[][] S;
        private void Scan()
        {
            var sc = new Scanner();
            H = sc.NextInt();
            W = sc.NextInt();
            S = new char[H][];
            for (int i = 0; i < H; i++)
            {
                S[i] = sc.Next().ToArray();
            }
        }

        class HashMap<K, V> : Dictionary<K, V>
        {
            new public V this[K i]
            {
                get
                {
                    V v;
                    return TryGetValue(i, out v) ? v : base[i] = default(V);
                }
                set { base[i] = value; }
            }
        }

        public void Solve()
        {
            Scan();

            var a = B(S);
            var tate = new char[W][];
            for (int i = 0; i < W; i++)
            {
                tate[i] = new char[H];
                for (int j = 0; j < H; j++)
                {
                    tate[i][j] = S[j][i];
                }
            }

            var b = B(tate);
            Console.WriteLine(a & b ? "YES" : "NO");
        }

        private bool B(char[][] c)
        {
            var cp = new char[c.Length][];
            for (int i = 0; i < c.Length; i++)
            {
                cp[i] = c[i].ToArray();
                Array.Sort(cp[i]);
            }

            var s = new string[c.Length];
            for (int i = 0; i < c.Length; i++)
            {
                s[i] = new string(cp[i]);
            }
            Array.Sort(s);
            //Console.WriteLine(string.Join("\n", s));
            var hm = new HashMap<string, int>();
            foreach (var s1 in s)
            {
                hm[s1]++;
            }

            int b = 0;
            foreach (var i in hm)
            {
                if (i.Value % 2 == 1)
                {
                    b++;
                }
            }

            if (c.Length % 2 == 0)
            {
                return b == 0;
            }
            else
            {
                return b == 1;
            }
        }


        static void Main(string[] args)
        {
            new Program().Solve();
        }
    }
}