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 Rust (1.15.1) (judge verdict: Wrong Answer)

use std::collections::HashMap;
use std::io;
use std::io::{BufRead, Write};

fn count(val: &[u8]) -> [usize; 26] {
    let mut ret = [0usize; 26];
    for &i in val {
        assert!(i >= b'a' && i <= b'z');
        ret[(i - b'a') as usize] += 1;
    }
    ret
}

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut buf = String::new();
    input.read_line(&mut buf).unwrap();
    let (h, w): (usize, usize) = {
        let mut split = buf.split_whitespace();
        (
            split.next().unwrap().parse().unwrap(),
            split.next().unwrap().parse().unwrap(),
        )
    };
    let grid: Vec<_> = (0..h)
        .map(|_| {
            buf.clear();
            input.read_line(&mut buf).unwrap();
            buf.trim_right().as_bytes().to_owned()
        })
        .collect();
    let inverse: Vec<Vec<u8>> = (0..w)
        .map(|y| (0..h).map(|x| grid[x][y]).collect())
        .collect();
    let mut horizontal = HashMap::new();
    for i in &grid {
        let count = horizontal.entry(count(i)).or_insert(0usize);
        *count += 1;
    }
    let mut vertical = HashMap::new();
    for i in &inverse {
        let count = vertical.entry(count(i)).or_insert(0usize);
        *count += 1;
    }
    let horizontal = horizontal.values().filter(|&i| i % 2 == 1).count() <= 1;
    let vertical = vertical.values().filter(|&i| i % 2 == 1).count() <= 1;
    writeln!(
        output,
        "{}",
        if horizontal && vertical { "YES" } else { "NO" }
    ).unwrap();
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v: Vec<u8> = Vec::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }

    #[test]
    fn case1() {
        test(
            "2 3
arc
rac
",
            "YES\n",
        );
    }

    #[test]
    fn case2() {
        test(
            "3 7
atcoder
regular
contest
",
            "NO\n",
        );
    }

    #[test]
    fn case3() {
        test(
            "12 12
bimonigaloaf
faurwlkbleht
dexwimqxzxbb
lxdgyoifcxid
ydxiliocfdgx
nfoabgilamoi
ibxbdqmzxxwe
pqirylfrcrnf
wtehfkllbura
yfrnpflcrirq
wvcclwgiubrk
lkbrwgwuiccv
",
            "YES\n",
        );
    }

    #[test]
    fn case4() {
        test(
            "3 3
abc
bca
cab",
            "YES\n",
        )
    }
}