P23157 [AtCoder] Palindromic Matrix
普及+
题目描述

Problem Description

There is a matrix $ A $ with $ H $ rows and $ W $ columns. The element in the $ i $-th row and $ j $-th column is denoted as $ a_{ij} $. Each $ a_{ij} $ is a lowercase English letter.

Snuke is trying to rearrange the elements of $ A $ to form a matrix $ A' $ with $ H $ rows and $ W $ columns, such that the following condition is satisfied:

  • Every row and every column of $ A' $ is a palindrome.

Determine if there exists such a matrix $ A' $.

Input Format

The input is given from the standard input in the following format:

$ H $ $ W $ $ a_{11} $$ a_{12} $$ ... $$ a_{1W} $ $ : $ $ a_{H1} $$ a_{H2} $$ ... $$ a_{HW} $

Output Format

If there exists a matrix $ A' $ that satisfies the condition, output Yes. Otherwise, output No.

Sample Input and Output

Sample Input #1

3 4
aabb
aabb
aacc

Sample Output #1

Yes

Sample Input #2

2 2
aa
bb

Sample Output #2

No

Sample Input #3

5 1
t
w
e
e
t

Sample Output #3

Yes

Sample Input #4

2 5
abxba
abyba

Sample Output #4

No

Sample Input #5

1 1
z

Sample Output #5

Yes

Notes/Hints

Annotation

A palindrome is a string that reads the same backward as forward. For example, a, aa, abba, abcba are palindromes, but ab, abab, abcda are not.

Constraints

  • $1\ \leq\ H,\ W\ \leq\ 100$
  • $ a_{ij} $ is a lowercase English letter.

Sample Explanation 1

For example, the following $ A' $ satisfies the condition:

abba
acca
abba

Sample Explanation 2

No matter how the elements of $ A $ are rearranged, it is impossible to create a matrix $ A' $ that satisfies the condition.

Sample Explanation 3

For example, the following $ A' $ satisfies the condition:

t
e
w
e
t
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 4 aabb aabb aacc
样例输出
Yes