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)

fn main() {
    let vec: Vec<u32> = read_vec();
    let h = vec[0];
    let w = vec[1];
    let ss: Vec<String> = read_lines(h);
    let ss2 =
        (0..w).map(|n| {
                ss.iter()
                    .map(|s| {
                        s.chars().nth(n as usize).unwrap()
                    }).collect()
            }).collect();
    if compare_sets(&ss) && compare_sets(&ss2) {
        println!("YES");
    } else {
        println!("NO");
    }
}

fn compare_sets(ss: &Vec<String>) -> bool {
    let mut list: Vec<usize> = Vec::new();

    for (i1, s1) in ss.iter().enumerate() {
        if list.contains(&i1) {
            continue;
        }
        for (i2, s2) in ss.iter().enumerate() {
            if i1 == i2 {
                continue;
            } else if list.contains(&i2) {
                continue;
            } else if set_compare_eq(s1, s2) {
                list.push(i1);
                list.push(i2);
                break;
            }
        }
    }
    ss.len() - list.len() == 0 || ss.len() - list.len() == 1
}

fn set_compare_eq(s1: &String, s2: &String) -> bool {
    for c in s1.chars() {
        if !s2.contains(c) {
            return false;
        }
    }
    true
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_lines<T: std::str::FromStr>(n: u32) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}