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;

namespace arc095_c
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            string[] tate = new string[x[1]];
            string[] yoko = new string[x[0]];
            for (int i = 0; i < x[0]; i++)
            {
                string s = Console.ReadLine();
                for (int j = 0; j < x[1]; j++)
                {
                    tate[j] += s[j];
                }
                yoko[i] = s;
            }
            for (int i = 0; i < tate.Count(); i++)
            {
                var c = tate[i].ToArray(); Array.Sort(c); tate[i] = "";
                foreach (var item in c) tate[i] += item;
            }
            for (int i = 0; i < yoko.Count(); i++)
            {
                var c = yoko[i].ToArray(); Array.Sort(c); yoko[i] = "";
                foreach (var item in c) yoko[i] += item;
            }
            Dictionary<string, int> tdic = new Dictionary<string, int>();
            for (int i = 0; i < x[1]; i++)
            {
                if (!tdic.ContainsKey(tate[i])) tdic.Add(tate[i], 0);
                tdic[tate[i]]++;
            }
            Dictionary<string, int> ydic = new Dictionary<string, int>();
            for (int i = 0; i < x[0]; i++)
            {
                if (!ydic.ContainsKey(yoko[i])) ydic.Add(yoko[i], 0);
                ydic[yoko[i]]++;
            }
            bool ret = true;
            int count = 0;
            foreach (var item in tdic)
            {
                count += item.Value % 2;
            }
            if (count - (x[1] % 2) > 0) ret = false;
            count = 0;
            foreach (var item in ydic)
            {
                count += item.Value % 2;
            }
            if (count - (x[0] % 2) > 1) ret = false;
            Console.WriteLine(ret ? "YES" : "NO");
        }
    }
}