Problem:
 Score : 400 points    Problem Statement We have an H -by- W matrix.
Let a_{ij} be the element at the i -th row from the top and j -th column from the left.
In this matrix, each a_{ij} is a lowercase English letter.  Snuke is creating another H -by- W matrix, A' , by freely rearranging the elements in A .
Here, he wants to satisfy the following condition:   Every row and column in A' can be read as a palindrome.   Determine whether he can create a matrix satisfying the condition.      Note A palindrome is a string that reads the same forward and backward.
For example, a , aa , abba and abcba are all palindromes, while ab , abab and abcda are not.      Constraints  1 ≤ H, W ≤ 100  a_{ij} is a lowercase English letter.         Input Input is given from Standard Input in the following format:  H  W  a_{11} a_{12} ... a_{1W}  :  a_{H1} a_{H2} ... a_{HW}       Output If Snuke can create a matrix satisfying the condition, print Yes ; otherwise, print No .        Sample Input 1 3 4
aabb
aabb
aacc      Sample Output 1 Yes  For example, the following matrix satisfies the condition.  abba
acca
abba       Sample Input 2 2 2
aa
bb      Sample Output 2 No  It is not possible to create a matrix satisfying the condition, no matter how we rearrange the elements in A .       Sample Input 3 5 1
t
w
e
e
t      Sample Output 3 Yes  For example, the following matrix satisfies the condition.  t
e
w
e
t       Sample Input 4 2 5
abxba
abyba      Sample Output 4 No       Sample Input 5 1 1
z      Sample Output 5 Yes

Solution (Python):
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
 
cnt = {}
for ai in a:
    for c in ai:
        if c in cnt:
            cnt[c] += 1
        else:
            cnt[c] = 1
c1 = 0
c2 = 0
c4 = 0
for k, v in cnt.items():
    c4 += (v // 4) * 4
    c2 += ((v % 4) // 2) * 2
    c1 += v % 2
 
ans = "No"
if h % 2 == 0:
    if w % 2 == 0:
        if c4 == h * w:
            ans = "Yes"
    else:
        if c2 <= h and c1 == 0:
            ans = "Yes"
else:
    if w % 2 == 0:
        if c2 <= w and c1 == 0:
            ans = "Yes"
    else:
        if c2 <= h + w - 1 and c1 == 1:
            ans = "Yes"
print(ans)

Solution (Python):
from collections import defaultdict

h, w = map(int, input().split())
dd = defaultdict(int)
for _ in range(h):
    string = input()
    for s in string:
        dd[s] += 1
        
one = 0
two = 0
for _, value in dd.items():
    if value % 2 == 1:
        one += 1
        value -= 1
    if value % 4 == 2:
        two += 1
        
if h % 2 == 0 and w % 2 == 0:
    if one == two == 0:
        print("Yes")
    else:
        print("No")
elif h % 2 == 1 and w % 2 == 1:
    if one > 1:
        print("No")
    elif two > h // 2 + w // 2:
        print("No")
    else:
        print("Yes")
else:
    if h % 2 == 0:
        tmp = h // 2
    else:
        tmp = w // 2
    if one > 0:
        print("No")
    elif two > tmp:
        print("No")
    else:
        print("Yes")

Solution (Python):
from collections import Counter
H, W = map(int, input().split())
s = ''
for i in range(H):
  s += str(input())
  
c = Counter(s)
m = c.most_common()
cnt = 0
l = []
for n in m:
  cnt += n[1] // 4
  l.append(n[1]%4)
if cnt < (H//2)*(W//2):
  print('No')
else:
  cnt = 0
  for i in l:
    if i % 2 == 1:
      cnt += 1
  if cnt <= 1:
    print('Yes')
  else:
    print('No')

Solution (Python):





import math
import fractions
import sys
import bisect
import heapq  
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr



def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod



def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

inf = 10 ** 18
mod = 10 ** 9 + 7

h,w = lr()
a = [x for i in range(h) for x in sr()]
a_set = Counter(a)
n4 = 0
n2 = 0
n1 = 0
for _,v in a_set.items():
    if v%4 == 0:
        n4+=1
    elif v%2 == 0:
        n2+=1
    else:
        n1+=1
if h%2==0 and w%2==0:
    if n1 != 0:
        print('No')
        sys.exit()
    if n2 != 0:
        print('No')
        sys.exit()
elif h%2==0:
    if n1 != 0:
        print('No')
        sys.exit()
    if n2 > h//2:
        print('No')
        sys.exit()
elif w%2==0:
    if n1 != 0:
        print('No')
        sys.exit()
    if n2 > w//2:
        print('No')
        sys.exit()
else:
    if n1 != 1:
        print('No')
        sys.exit()
    if n2 > (w-1)//2+(h-1)//2:
        print('No')
        sys.exit()
print('Yes')

Solution (Python):
from collections import Counter

def solve():
    H, W = map(int, input().split())
    cnt = Counter()
    for _ in range(H):
        cnt.update(input())
    
    x = []
    for v in cnt.values():
        n = v%4
        if n:
            x.append(n)
    
    yes = "Yes"
    no = "No"

    c = (H&1)+(W&1)

    if c == 0:
        if x:
            return no
        return yes
    
    elif c == 1:
        if H&1:
            a = W
        else:
            a = H
        if sum(x) > a:
            return no
        for y in x:
            if y&1:
                return no
        return yes

    else:
        if sum(x) > H+W-1:
            return no
        o = 0
        for y in x:
            if y&1:
                o += 1
        
        if o == 1:
            return yes
        
        return no

print(solve())

Solution (Python):
from collections import Counter

H, W = map(int, input().split())
lis = []
for i in range(H):
    a = list(input())
    lis += a

lis = list(Counter(lis).values())
length = len(lis)

check_4 = 0
check_2 = 0
check_kisu = 0
for i in lis:
    if i % 4 == 0:
        check_4 += 1
    elif i % 2 == 0:
        check_2 += 1
    else:
        if check_kisu:
            print('No')
            exit()
        else:
            check_kisu = i % 4

if (H % 2 == 0) & (W % 2 == 0):
    if (check_kisu != 0) | (check_2 != 0):
        print('No')
        exit()

elif (H % 2 == 1) & (W % 2 == 1):
    if (H + W - 1 < check_kisu + 2 * check_2) | ((H + W - 1 - check_kisu - 2 * check_2) % 4 != 0):
        print('No')
        exit()

elif H % 2 == 1:
    if (W < 2 * check_2) | ((W - 2 * check_2) % 4 != 0):
        print('No')
        exit()


elif W % 2 == 1:
    if (H < 2 * check_2) | ((H - 2 * check_2) % 4 != 0):
        print('No')
        exit()

print('Yes')

Solution (Python):

import sys

sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read


sys.setrecursionlimit(10**7)









INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7
def intread():
    return int(sysread())
def mapline(t = int):
    return map(t, sysread().split())
def mapread(t = int):
    return map(t, read().split())


def run():
    H, W = mapline()
    dic = [0] * 27
    for i in range(H):
        S = input()
        for s in S:
            dic[ord(s) - 96] += 1
    permited2 = 0
    permited1 = 0
    if H % 2 and W % 2:
        permited2 += H // 2 + W // 2
        permited1 += 1
    else:
        if H % 2:
            permited2 += W // 2
        elif W % 2:
            permited2 += H // 2
    permited4 = (H * W - permited2 * 2 - permited1) // 4
    for val in dic:
        done = True
        while val and done:
            done = False
            if val >= 4 and permited4:
                val -= 4
                permited4 -= 1
                done= True
            elif val >= 2 and permited2:
                val -= 2
                permited2 -= 1
                done = True
            elif val == 1 and permited1:
                val -= 1
                permited1 -= 1
                done = True
            if not done:
                print('No')
                return
    print('Yes')


if __name__ == "__main__":
    run()

Solution (Python):
import heapq

h,w=map(int,input().split())

a=[input() for _ in range(h)]

alphabet={}

for i in range(h):
    for j in range(w):
        if a[i][j] in alphabet:
            alphabet[a[i][j]]+=1
        else:
            alphabet[a[i][j]]=1

same=[-x for x in alphabet.values()]
heapq.heapify(same)

cnt={}

for i in range(h):
    for j in range(w):
        hh=min(i,h-i-1)
        ww=min(j,w-j-1)

        if (hh,ww) in cnt:
            cnt[(hh,ww)]+=1
        else:
            cnt[(hh,ww)]=1

cntv=sorted(cnt.values())

while cntv:
    c=heapq.heappop(same)
    c=-c
    ccnt=cntv.pop()

    if ccnt>c:
        print('No')
        exit(0)
    elif ccnt<c:
        heapq.heappush(same,ccnt-c)

print('Yes')

Solution (Python):

from collections import Counter, defaultdict
def resolve():
    H, W = map(int, input().split())
    S = Counter()
    for _ in range(H):
        S.update(list(input()))

    dd = defaultdict(int)
    for k, v in S.items():
        q, r = divmod(v, 4)
        dd[4] += q
        qq, rr = divmod(r, 2)
        dd[2] += qq
        dd[1] += rr

    ans = "Yes"

    if H % 2 == 0 and W % 2 == 0:
        if dd[2] != 0 or dd[1] != 0:
            ans = "No"
    elif H % 2 == 0:
        if dd[1] != 0 or dd[2] > H // 2:
            ans = "No"
    elif W % 2 == 0:
        if dd[1] != 0 or dd[2] > W // 2:
            ans = "No"
    else:
        if dd[1] != 1:
            ans = "No"
        else:
            if dd[2] > H // 2 + W // 2:
                ans = "No"

    print(ans)


if __name__ == "__main__":
    resolve()

Solution (Python):
from collections import defaultdict
H,W = map(int,input().split())
d = defaultdict(int)
for _ in range(H):
    for c in list(input()):
        d[c] += 1
for i in range((H-1)//2+1):
    for j in range((W-1)//2+1):
        s = set([(x,y) for x,y in [(i,j),(i,W-1-j),(H-1-i,j),(H-1-i,W-1-j)] if 0<=x<H and 0<=y<W])
        f = True
        for k,_ in sorted(d.items(),key=lambda x:x[1]):
            if d[k] >= len(s):
                d[k] -= len(s)
                f = False
                break
        if f:
            print("No")
            exit(0)
print("Yes")

Solution (Python):
h,w = map(int,input().split())
count = [0]*26
l = [input() for i in range(h)]
for i in l:
    for j in i:
        count[ord(j)-ord("a")] += 1

if h%2:
    if w%2:
        c = 0
        c2 = 0
        for i in count:
            if i%4:
                if i%2:
                    c2 += 1
                else:
                    c += 1
        if c <= w//2+h//2 and c2 == 1:
            print("Yes")
        else:
            print("No")
    
    else:
        c = 0
        for i in count:
            if i%4:
                if i%2:
                    print("No")
                    exit()
                else:
                    c += 1
        if c <= w//2:
            print("Yes")
        else:
            print("No")
else:
    if w%2:
        c = 0
        for i in count:
            if i%4:
                if i%2:
                    print("No")
                    exit()
                else:
                    c += 1
        if c <= h//2:
            print("Yes")
        else:
            print("No")
            
    else:
        for i in count:
            if i%4:
                print("No")
                exit()
        print("Yes")

Solution (Python):
H,W=list(map(int,input().split()))
l=[]
for i in range(H):
   l.append(list(input()))
from collections import Counter
l=sum(l,[])
l=Counter(l)
one=(H%2)*(W%2)
two=(H%2)*(W//2)+(W%2)*(H//2)
four=(H//2)*(W//2)
for i in l.values():
   j=i//4
   i=i%4
   four-=j
   if i==1:
      one-=1
   elif i==2:
      two-=1
   elif i==3:
      one-=1;two-=1
if set([0]) == set([one,two,four]):
   print("Yes")
else:
   if four<0:
      two+=four*2
   four=0
   if set([0]) == set([one,two,four]):
      print("Yes")
   else:
      print("No")

Solution (Python):
from collections import Counter
H, W = map(int,input().split())
d = Counter()
for _ in range(H):
  d.update(list(input()))


def main():
  num1 = (H*W) % 2 
  num2 = (W % 2)*H//2 + (H % 2)*W//2
  num4 = ((H*W) - num1 - num2*2)//4
  

  check1 = sum([val % 2 for key,val in d.items()])
  
  if check1 != num1:
    return False
  
  check4 = 0
  for key,val in d.items():
    if val >= 4:
      deduct = min(num4-check4,val//4)
      d[key] = val - deduct*4
      check4 += deduct
      
      if check4 == num4:
        break
    
  
  if check4 != num4:
    return False
  
  check2 = sum([val//2 for key,val in d.items()])
  
  if check2 != num2:
    return False
      
  return True
      
  
ans = main()
if ans:
  print("Yes")
else:
  print("No")

Solution (Python):
H, W = map(int,input().split())
S = []
for _ in range(H):
  S.append(input())



def main():
  num1 = (H*W) % 2 
  num2 = (W % 2)*H//2 + (H % 2)*W//2
  num4 = ((H*W) - num1 - num2*2)//4
  
  d = {}
  for i in range(H):
    for j in range(W):
      ch = S[i][j]
      if ch in d:
        d[ch] += 1
      else:
        d[ch] = 1

  check1 = sum([val % 2 for key,val in d.items()])
  
  if check1 != num1:
    return False
  
  check4 = 0
  for key,val in d.items():
    if val >= 4:
      deduct = min(num4-check4,val//4)
      d[key] = val - deduct*4
      check4 += deduct
      
      if check4 == num4:
        break
    
  
  if check4 != num4:
    return False
  
  check2 = sum([val//2 for key,val in d.items()])
  
  if check2 != num2:
    return False
      
  return True
      
  
ans = main()
if ans:
  print("Yes")
else:
  print("No")

Solution (Python):
from collections import Counter

H, W = map(int, input().split())
S = Counter()
for _ in range(H):
    S.update(list(input()))

val1, val2 = 0, 0
for v in S.values():
    if v % 2:
        val1 += 1
    elif v % 4:
        val2 += 1

val1_lim = 1 if (H % 2 and W % 2) else 0
val2_lim = 0
if H % 2:
    val2_lim += W // 2
if W % 2:
    val2_lim += H // 2

print('Yes' if val1 <= val1_lim and val2 <= val2_lim else 'No')

Solution (Python):
from collections import defaultdict
h, w = map(int, input().split())

a = [list(input()) for _ in range(h)]
d = defaultdict(int)
for i in range(h):
    for j in range(w):
        d[ord(a[i][j]) - ord('a')] += 1

odd = 0
two = 0
four = 0
for i in range(26):
    four += d[i] // 4
    d[i] %= 4
    if d[i] % 2 == 0:
        two += d[i] // 2
    else:
        odd += 1

if h % 2 == 1 and w % 2 == 1:
    if odd == 1 and two <= h // 2 + w // 2:
        print('Yes')
    else:
        print('No')
elif h % 2 == 1:
    if odd == 0 and two <= w // 2:
        print('Yes')
    else:
        print('No')
elif w % 2 == 1:
    if odd == 0 and two <= h // 2:
        print('Yes')
    else:
        print('No')
else:
    if odd == 0 and two == 0:
        print('Yes')
    else:
        print('No')

Solution (Python):
from collections import Counter
h,w=map(int,input().split())

a=[]
flag=True
for i in range(h):
  a+=list(input())
ca=Counter(a)
if h%2==0 and w%2==0:
  for i in ca:
    if ca[i]%4!=0:
      flag=False
      print('No')
      break
  if flag:
    print('Yes')

elif h%2!=0 and w%2!=0:
  yon=(h-1)*(w-1)
  ni=h*w-yon-1
  iti=1
  for i in ca:
    while ca[i]>0:
      if ca[i]%4==0 and yon>0:
        ca[i]-=4
        yon-=4
      elif ca[i]%2==0 and ni>0:
        ni-=2
        ca[i]-=2
      elif iti>0:
        iti-=1
        ca[i]-=1
      else:
        break
  if yon==0 and ni==0 and iti==0:
    print('Yes')
  else:
    print('No')
else:
  if h%2==0:
    yon=(h)*(w-1)
  else:
    yon=(h-1)*(w)
  ni=h*w-yon
  for i in ca:
    while ca[i]>0:
      if ca[i]%4==0 and yon>0:
        ca[i]-=4
        yon-=4
      elif ca[i]%2==0 and ni>0:
        ni-=2
        ca[i]-=2
      else:
        break
  if yon==0 and ni==0:
    print('Yes')
  else:
    print('No')

Solution (Python):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())  


H,W = MI()
a = [LS2() for _ in range(H)]

from collections import defaultdict

d = defaultdict(int)
for i in range(H):
    for j in range(W):
        d[a[i][j]] += 1

if H % 2 == 0 and W % 2 == 0:
    for key in d.keys():
        if d[key] % 4 != 0:
            print('No')
            exit()
    print('Yes')

if H % 2 == 0 and W % 2 != 0:
    H,W = W,H

if H % 2 != 0 and W % 2 == 0:
    a = 0  
    for key in d.keys():
        if d[key] % 2 != 0:
            print('No')
            exit()
        elif d[key] % 4 != 0:
            a += 1
    if a <= W//2:
        print('Yes')
        exit()
    else:
        print('No')
        exit()

if H % 2 != 0 and W % 2 != 0:
    a,b = 0,0  
    for key in d.keys():
        if d[key] % 4 == 1:
            a += 1
        elif d[key] % 4 == 3:
            a += 1
            b += 1
        elif d[key] % 4 == 2:
            b += 1
    if a <= 1 and b <= H//2 + W//2:
        print('Yes')
        exit()
    else:
        print('No')
        exit()

Solution (Python):
H,W = map(int,input().split())
A = [input().strip() for _ in range(H)]
C = {chr(i):0 for i in range(97,123)}
for i in range(H):
    for j in range(W):
        C[A[i][j]] += 1
if H%2==0 and W%2==0:
    flag = 0
    for a in C:
        if C[a]%4!=0:
            flag = 1
            break
    if flag==0:
        print("Yes")
    else:
        print("No")
elif H%2==0 and W%2==1:
    cnt = 0
    flag = 0
    for a in C:
        if C[a]%4==2:
            cnt += 1
        elif C[a]%4!=0:
            flag = 1
            break
    if flag==1:
        print("No")
    else:
        if cnt<=H//2:
            print("Yes")
        else:
            print("No")
elif H%2==1 and W%2==0:
    flag = 0
    cnt = 0
    for a in C:
        if C[a]%4==2:
            cnt += 1
        elif C[a]%4!=0:
            flag = 1
            break
    if flag==1:
        print("No")
    else:
        if cnt<=W//2:
            print("Yes")
        else:
            print("No")
else:
    cnt1 = 0
    cnt2 = 0
    for a in C:
        if C[a]%4==2:
            cnt2 += 1
        elif C[a]%2==1:
            cnt1 += 1
    if cnt1!=1:
        print("No")
    else:
        if cnt2<=(H-1)//2+(W-1)//2:
            print("Yes")
        else:
            print("No")

Solution (Python):
import sys
from collections import Counter
 
H, W = map(int, sys.stdin.readline().split())
 
string = ""
for _ in range(H):
    string += sys.stdin.readline().strip()
 
counter = Counter(string)
e_one = 0
e_two = 0
e_four = 0
for key, count in counter.items():
    tmp = count // 4
    e_four += tmp
    count -= 4 * tmp
    tmp = count // 2
    e_two += tmp
    count -= 2 * tmp
    e_one += count
 
one = 0
two = 0
four = 0
if H % 2 == 0 and W % 2 == 0:
    four = H * W // 4

elif H % 2 == 1 and W % 2 == 1:
    one = 1
    two = H // 2 + W // 2
    four = (H * W - (one + two * 2)) // 4
else:
    
    if W % 2 == 1:
        H, W = W, H
 
    two = W // 2
    four = (H * W - two * 2) // 4
 
if four > e_four:
    print("No")
else:
    e_four -= four
    e_two += e_four * 2
    if two > e_two:
        print("No")
    else:
        e_two -= two
        e_one += e_two * 2
        if e_one == one:
            print("Yes")
        else:
            print("No")

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

h,w = inpl()
cnt = defaultdict(int)
for _ in range(h):
    for x in input():
        cnt[x] += 1
one = two = 0
for va in cnt.values():
    now = va%4
    if now == 1 or now == 3:
        one += 1
    if now == 2 or now == 3:
        two += 1
res = False
if h%2 == 0 and w%2 == 0:
    if not one and not two:
        res = True
elif h%2 and w%2:
    if one == 1 and two <= (w-1)//2 + (h-1)//2:
        res = True
else:
    now = h if w%2 else w
    if not one and two <= now//2:
        res = True
print('Yes' if res else 'No')

Solution (Python):
from collections import Counter
h, w, *s = open(0).read().split()
h = int(h)
w = int(w)

s = Counter(''.join(s))

odd = 0
two = 0
four = 0
for k, v in s.items():
    four += v // 4
    v %= 4
    if v % 2 == 0:
        two += v // 2
    else:
        odd += 1
if h % 2 == 1 and w % 2 == 1:
    if odd == 1 and two <= h // 2 + w // 2:
        print('Yes')
    else:
        print('No')
elif h % 2 == 1:
    if odd == 0 and two <= w // 2:
        print('Yes')
    else:
        print('No')
elif w % 2 == 1:
    if odd == 0 and two <= h // 2:
        print('Yes')
    else:
        print('No')
else:
    if odd == 0 and two == 0:
        print('Yes')
    else:
        print('No')

Solution (Python):
from collections import Counter
H, W = map(int, input().split())
a = ''
for _ in range(H):
    a += input()
cnt_counter = list(Counter(a).values())
yes_flag = False
if H % 2 == 0 and W % 2 == 0:
    if all([i % 4 == 0 for i in cnt_counter]):
        yes_flag = True
elif H % 2 == 1 and W % 2 == 1:
    two_cnt = (H // 2) + (W // 2)
    four_cnt = (H // 2) * (W // 2)
    for i in range(len(cnt_counter)):
        if cnt_counter[i] % 2 == 1:
            cnt_counter[i] -= 1
            break
    else:
        print('No')
        exit()
    for i in range(len(cnt_counter)):
        if cnt_counter[i] <= 0:
            continue
        if cnt_counter[i] % 2 == 0 and cnt_counter[i] % 4 != 0:
            two_cnt -= 1
            cnt_counter[i] -= 2
        if two_cnt == 0:
            break
    for i in range(len(cnt_counter)):
        if cnt_counter[i] <= 0:
            continue
        if cnt_counter[i] % 4 != 0:
            break
        while two_cnt > 1 and cnt_counter[i]:
            two_cnt -= 2
            cnt_counter[i] -= 4
        while four_cnt > 0 and cnt_counter[i]:
            four_cnt -= 1
            cnt_counter[i] -= 4
    if two_cnt == four_cnt == 0:
        yes_flag = True
else:
    if H % 2 == 0:
        two_cnt = H // 2
    else:
        two_cnt = W // 2
    four_cnt = (H // 2) * (W // 2)
    for i in range(len(cnt_counter)):
        if cnt_counter[i] % 2 == 0 and cnt_counter[i] % 4 != 0:
            two_cnt -= 1
            cnt_counter[i] -= 2
        if two_cnt == 0:
            break
    for i in range(len(cnt_counter)):
        if cnt_counter[i] <= 0:
            continue
        if cnt_counter[i] % 4 != 0:
            break
        while two_cnt > 1 and cnt_counter[i]:
            two_cnt -= 2
            cnt_counter[i] -= 4
        while four_cnt > 0 and cnt_counter[i]:
            four_cnt -= 1
            cnt_counter[i] -= 4
    if two_cnt == four_cnt == 0:
        yes_flag = True
if yes_flag:
    print('Yes')
else:
    print('No')

Solution (Python):
H,W = map(int,input().split())

A = [list(input()) for _ in range(H)]

memo = {}
for a in A:
    for ai in a:
        if ai in memo:
            memo[ai] += 1
        else:
            memo[ai] = 1
            
mod0 = []
mod1_3 = []
mod2 = []
for key, value in memo.items():
    if value % 4 == 0:
        mod0.append(key)
    elif value % 4 == 2:
        mod2.append(key)
    else:
        mod1_3.append(key)

if W % 2 == 0 and H % 2 == 0:
    if len(mod1_3) > 0 or len(mod2) > 0:
        print("No")
    else:
        print("Yes")

elif W % 2 == 0 or H % 2 == 0:
    if H % 2 == 0:
        W, H = H, W
 
    if W // 2 < len(mod2):
        print("No")
    elif len(mod1_3) > 0:
        print("No")
    else:
        print("Yes")

else:
    if len(mod1_3) == 1 and len(mod2) <= H // 2 + W // 2:
        print("Yes")
    else:
        print("No")

Solution (Python):
H, W = map(int, input().split())
A = ""
inf = 1e5
cnt = {}
ans = "Yes"
for i in range(H):
    a = input()
    A += a

for a in A:
    if a not in cnt.keys():
        cnt[a] = 1
    else:
        cnt[a] += 1
jud = [inf, 0, 0, 0]
if H % 2 == 1 and W % 2 == 1:
    jud[2] = H//2+W//2
    jud[1] = 1
elif H % 2 == 1:
    jud[2] = W//2
elif W % 2 == 1:
    jud[2] = H//2
for i in cnt.values():
    b = i % 4
    jud[b] -= 1
    if jud[b] < 0:
        ans = "No"
print(ans)

Solution (Python):
def main():
    examB()

def examA():
    S = SI()
    S = ">" + S + "<"
    N = len(S)
    A = [0]*N
    i = 0
    while(i<N-1):
        r = i + 1
        if S[i]==">" and S[i+1]=="<":
            A[i] = 0
            l = i-1
            cur = 0
            while(1<=l):
                cur += 1
                A[l] = max(A[l], cur)
                l -= 1
                if S[l+1]=="<":
                    
                    break
            r = i+1
            cur = 0
            while(r<N-1):
                cur += 1
                A[r] = max(A[r], cur)
                r += 1
                if r==N-1:
                    break
                if S[r]==">":
                    break
        
        i = r
    
    A[0] = 0; A[-1] = 0
    ans = sum(A)
    print(ans)
    return

def examB():
    H, W = LI()
    A = [SI()for _ in range(H)]
    C = defaultdict(int)
    for a in A:
        for s in a:
            C[s] += 1
    B = sorted(C.items())
    
    flag_odd = not (H%2==1 and W%2==1)
    upper_2 = (H%2==1) * (W//2) + (W%2==1) * (H//2)
    for s,c in B:
        if c%2==1:
            if flag_odd:
                print("No")
                return
            flag_odd = True
        elif c%4==2:
            upper_2 -= 1
            if upper_2<0:
                print("No")
                return
    print("Yes")
    return

def examC():
    N, K = LI()
    P = LI()
    C = LI()

    if max(C)<0:
        print(max(C))
        return

    loop = [[0,0]for _ in range(N)]

    for i in range(N):
        checked = set()
        now = i
        score = 0
        while(now not in checked):
            checked.add(now)
            now = P[now]-1
            score += C[now]
        n = len(checked)
        for j in checked:
            loop[j] = [n,score]
    
    ans = 0
    for i in range(N):
        n,s = loop[i]
        score = 0
        if s>0:
            score += (K//n - 1) * s
        ans = max(ans,score)
        now = i
        for j in range(n + K%n):
            now = P[now] - 1
            score += C[now]
            ans = max(ans,score)

    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

def test():
    i = I()
    li = LI()
    lsi = LSI()
    si = LS()
    print(i)
    print(li)
    print(lsi)
    print(si)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,alphabet_convert,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 1<<31
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    main()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Solution (Python):
from collections import Counter
import numpy as np

h, w = map(int, input().split())
arr = [list(map(str, input().rstrip())) for _ in range(h)]

arr = sum(arr, [])

arr = Counter(arr)
arr = np.array(list(arr.values()))


def solve(arr):
    
    if h % 2 == 0 and w % 2 == 0:
        return np.all(arr % 4 == 0)

    
    elif h % 2 == 1 and w % 2 == 1:
        even = (h + w) // 2 - 1
        if (arr % 2 == 1).sum() != 1:
            return False
        odd = arr[np.where(arr % 2 == 1)].sum()
        if odd % 4 == 3:
            even -= 1
        arr = arr[np.where(arr != odd)]
        ans = (arr % 4 == 2).sum() <= even
        ans &= np.all(arr[np.where(arr % 4 != 2)] % 4 == 0)
        return ans

    
    else:
        even = h // 2 if h % 2 == 0 else w // 2
        ans = (arr % 4 == 2).sum() <= even
        ans &= np.all(arr[np.where(arr % 4 != 2)] % 4 == 0)
        return ans


print("Yes" if solve(arr) else "No")

Solution (Python):
h,w = map(int, input().split())
al = [list(input()) for _ in range(h)]
cnts = {}
for row in al:
    for a in row:
        cnts.setdefault(a,0)
        cnts[a] += 1
        cnts[a]%= 4

c4 = [0]*5
for i,v in cnts.items():
    c4[v] += 1
c4[4] = c4[0]


if w%2 == 0 and h%2 == 0:
    if c4[1] == 0 and c4[2] == 0 and c4[3] == 0:
        print('Yes')
    else:
        print('No')

elif w%2 == 1 and h%2 == 1:
    if c4[1] + c4[3] == 1 and c4[3] + c4[2] <= (h-1)//2 + (w-1)//2:
        print('Yes')
    else:
        print('No')

elif w%2 == 1 and h%2 == 0:
    if c4[1] + c4[3] == 0 and c4[2] <= h//2:
        print('Yes')
    else:
        print('No')

elif w%2 == 0 and h%2 == 1:
    if c4[1] + c4[3] == 0 and c4[2] <= w//2:
        print('Yes')
    else:
        print('No')