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):
from collections import Counter

H, W = map(int, input().split())

num = [0]*5

for h in range(-(-H//2)):
    for w in range(-(-W//2)):
        tmp = 1
        if h < H//2:
            tmp *= 2
        if w < W//2:
            tmp *= 2
        num[tmp] += 1

s = ""
for _ in range(H):
    s += input()

c = list(Counter(s).values())
c.sort(reverse = True)

four = 0
for i in range(len(c)):
    if four == num[4]:
        break
    while c[i] >= 4:
        c[i] -= 4
        four += 1
        if four == num[4]:
            break

two = 0
for i in range(len(c)):
    if two == num[2]:
        break
    while c[i] >= 2:
        c[i] -= 2
        two += 1
        if two == num[2]:
            break

print("Yes" if sum(c) == num[1] and four == num[4] and two == num[2] else "No")

Solution (Python):
h,w = map(int,input().split())
from collections import Counter
s = [[] for i in range(h)]
for i in range(h):
    s[i] = input()

ss = []
for i in range(h):
    for j in range(w):
        ss.append(s[i][j])
            
b = Counter(ss)
odd = 0
    
if h % 2 == 0 and w % 2 == 0:
    fl = 1
    for i in b:
        if b[i] % 4 != 0:
            fl = 0
            
    if fl == 1:
        print("Yes")
    else:
        print("No")
        
elif h % 2 == 1 and w % 2 == 0:
    flsum = 0
    for i in b:
        flsum += b[i] % 4
        if b[i] % 2 == 1:
            odd += 1
        
    if odd != 0:
        print("No")
    elif flsum >= 0 and flsum <= w:
        print("Yes")
    else:
        print("No")
        
elif h % 2 == 0 and w % 2 == 1:
    flsum = 0
    for i in b:
        flsum += b[i] % 4
        if b[i] % 2 == 1:
            odd += 1
        
    if odd != 0:
        print("No")
    elif flsum >= 0 and flsum <= h:
        print("Yes")
    else:
        print("No")
        
else:
    flsum = 0
    for i in b:
        flsum += b[i] % 4
        if b[i] % 2 == 1:
            odd += 1
        
    if odd != 1:
        print("No")
    elif flsum >= 0 and flsum <= h+w-1:
        print("Yes")
    else:
        print("No")

Solution (Python):
h, w = map(int, input().split())

f = (h-h%2)*(w-w%2)//4
t = 0
one = 0
if h%2==1:
    t += w//2
if w%2==1:
    t += h//2
if h%2==1 and w%2==1:
    one = 1

dic = {}
for i in range(h):
    a = list(input())
    for j in a:
        if j in dic:
            dic[j] += 1
        else:
            dic[j] = 1

result = True
for i, j in dic.items():
    if j%2==1:
        if one == 1:
            j -= 1
            one -= 1
        else:
            result = False
    if j==0:
        continue
    while f > 0 and j>=4:
        j -= 4
        f -= 1
        if j==0:
            break
    if j==0:
        continue
    while t > 0 and j>=2:
        j -= 2
        t -= 1
        if j==0:
            break
    if j==0:
        continue
    else:
        result = False

    if result == False:
        break

if result:
    print("Yes")
else:
    print("No")

Solution (Python):
h, w = map(int, input().split())

f = (h-h%2)*(w-w%2)//4
t = 0
one = 0
if h%2==1:
    t += w//2
if w%2==1:
    t += h//2
if h%2==1 and w%2==1:
    one = 1

dic = {}
for i in range(h):
    a = list(input())
    for j in a:
        if j in dic:
            dic[j] += 1
        else:
            dic[j] = 1

result = True
for i, j in dic.items():
    if j%2==1:
        if one == 1:
            j -= 1
            one -= 1
        else:
            result = False
    if j==0:
        continue
    while f > 0 and j>=4:
        j -= 4
        f -= 1
        if j==0:
            break
    if j==0:
        continue
    while t > 0 and j>=2:
        j -= 2
        t -= 1
        if j==0:
            break
    if j==0:
        continue
    else:
        result = False

    if result == False:
        break

if result:
    print("Yes")
else:
    print("No")

Solution (Python):
from collections import Counter

H, W = map(int, input().split())
a = ''
for i in range(H):
    a += input()

c = Counter(a)
n = c.values()
T = [0,
     sum(ni // 4 for ni in n),
     sum((ni % 4) // 2 for ni in n),
     sum(ni % 2 for ni in n)]
E = [(H // 2) * (W // 2),
     (H // 2) * (W % 2) + (H % 2) * (W // 2),
     (H % 2) * (W % 2)]

ans = True
for i in range(3):
    T[i + 1] += T[i] * 2
    T[i + 1] -= E[i]
    if T[i + 1] < 0:
        ans = False
        break
print('Yes' if ans else 'No')

Solution (Python):
import bisect

h, w = map(int, input().split())
figure_dic = {}
def add_dic(figure):
    if not figure in figure_dic:
        figure_dic[figure] = 0
    figure_dic[figure] += 1
for i in range(h):
    line = list(input())
    for j in line:
        add_dic(j)
figures = []
for key, items in figure_dic.items():
    figures.append(items)
figures.sort()
same_boxes = []
if h % 2 == 0:
    if w % 2 == 0:
        same_boxes += [4 for i in range(h*w//4)]
    else:
        same_boxes += [4 for i in range((w//2)*(h//2))]
        same_boxes += [2 for i in range(h//2)]
else:
    if w % 2 == 0:
        same_boxes += [4 for i in range((h//2)*(w//2))]
        same_boxes += [2 for i in range(w//2)]
    else:
        same_boxes += [4 for i in range((h//2)*(w//2))]
        same_boxes += [2 for i in range(h//2 + w//2)]
        same_boxes += [1]
same_boxes.sort(reverse=True)
l = len(figures)
flag = 0
for box in same_boxes:
    left = bisect.bisect_left(figures, box)
    if left == l:
        flag = 1
        break
    figures[left] -= box
    figures.sort()
if flag:
    print("No")
else:
    print("Yes")

Solution (Python):
import collections
H,W=map(int,input().split())
table=[list(input()) for _ in range(H)]
ch=[]
for i in range(H):
    for j in range(W):
        ch.append(table[i][j])
c=collections.Counter(ch)
values=list(c.values())	
key=list(c.keys())	
count4=0
count2=0
count1=0
for i in values:
    if i%4==0:
        count4=count4+1
    elif i%2==0:
        count2=count2+1
    else:
        count1=count1+1
if (H%2==0)and(W%2==0):
    if count2+count1==0:
        print("Yes")
    else:
        print("No")
elif (H%2==1)and(W%2==1):
    if (count2<=((H+W-2)//2))and(count1==1):
        print("Yes")
    else:
        print("No")
else:
    if H%2==0:
        nu=H//2
    else:
        nu=W//2
    if (count2<=nu)and(count1==0):
        print("Yes")
    else:
        print("No")

Solution (Python):
import sys
import math  
import bisect  
import queue  
from collections import Counter


def input():
    return sys.stdin.readline().rstrip()


def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        for c in input():
            A.append(c)

    A.sort()
    B = Counter(A).most_common()
    
    
    success = False
    if H % 2 == 0 and W % 2 == 0:
        if all([val[1] % 4 == 0 for val in B]):
            success = True
    elif H % 2 == 1 and W % 2 == 0:
        if all([val[1] % 2 == 0 for val in B]):
            four = 0
            two = 0
            for el in B:
                x = el[1]
                if x % 4 == 0:
                    four += 1
                elif x % 2 == 0:
                    two += 1
            if two <= W // 2 and (W // 2 - two) % 2 == 0:
                success = True
    elif H % 2 == 0 and W % 2 == 1:
        if all([val[1] % 2 == 0 for val in B]):
            four = 0
            two = 0
            for el in B:
                x = el[1]
                if x % 4 == 0:
                    four += 1
                elif x % 2 == 0:
                    two += 1
            if two <= H // 2 and (H // 2 - two) % 2 == 0:
                success = True
    else:
        odd = 0
        two = 0
        four = 0
        for el in B:
            x = el[1]
            if x % 2 == 1:
                odd += 1
                x -= 1
            if x % 4 == 0:
                four += 1
            elif x % 2 == 0:
                two += 1
        if odd == 1:
            if two <= H // 2 + W // 2 and (H // 2 + W // 2 - two) % 2 == 0:
                success = True
    if success:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Solution (Python):

import collections

H, W = map(int, input().split())
a_frq_dict = collections.defaultdict(int)
for _ in range(H):
    for a in input():
        a_frq_dict[a] += 1


n = H%2 + W%2
frq1, frq2, frq4 = 0,0,0

if n == 2:
    frq1 = 1
    frq2 = (H-1)//2 + (W-1)//2
    frq4 = ((H*W) - (frq2*2 + frq1)) // 4

elif n == 1:
    if H%2:
        frq2 = W//2
    else:
        frq2 = H//2

    frq4 = ((H*W) - frq2*2) // 4

else:
    frq4 = (H * W) // 4





for frq in a_frq_dict.values():
    n = min(frq4, frq//4)
    frq4 -= n
    frq -= n*4

    n = min(frq2, frq//2)
    frq2 -= n
    frq -= n*2

    n = min(frq1, frq)
    frq1 -= n
    frq -= n

    

    if frq:
        print('No')
        exit()




if all(map(lambda x: x == 0, [frq1, frq2, frq4])):
    print('Yes')
else:
    print('No')

Solution (Python):

from collections import Counter, deque  
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()


def resolve():
    def main():
        gg = Counter([])
        H, W = map(int, input().split())
        grid = [[_ for _ in input()] for _ in range(H)]
        for g in grid:
            gg.update(Counter(g))

        if H % 2 == 0 and W % 2 == 0:
            for i in gg.values():
                if i % 4 != 0:
                    return 'No'
            return 'Yes'

        elif H % 2 == 0 and W % 2 == 1:
            cnt = 0
            for i in gg.values():
                if i % 4 == 2:
                    cnt += 2
                elif i % 4 == 1 or i % 4 == 3:
                    return 'No'

            if cnt <= H:
                return 'Yes'
            else:
                return 'No'

        elif H % 2 == 1 and W % 2 == 0:
            cnt = 0
            for i in gg.values():
                if i % 4 == 2:
                    cnt += 2
                elif i % 4 == 1 or i % 4 == 3:
                    return 'No'

            if cnt <= W:
                return 'Yes'
            else:
                return 'No'

        else:
            cnt1 = 0
            cnt2 = 0
            for i in gg.values():
                if i % 4 == 1:
                    cnt1 += 1
                elif i % 4 == 2:
                    cnt2 += 2
                elif i % 4 == 3:
                    cnt2 += 2
                    cnt1 += 1
            if cnt1 == 1 and cnt2 <= (H + W - 2):
                return 'Yes'
            else:
                return 'No'

    print(main())


resolve()

Solution (Python):
def examA():
    N, M, A, B = LI()
    C = [I()for _ in range(M)]
    ans = 0
    for i,c in enumerate(C):
        if N<=A:
            N += B
        N -= c
        if N<0:
            ans = i+1
            break
    if ans==0:
        ans = "complete"
    print(ans)
    return

def examB():
    N = LI()
    P = LI()
    return

def examC():
    S = LSI()
    N = I()
    NG = [SI()for _ in range(N)]
    ans = []
    
    for s in S:
        flag = True
        for ng in NG:
            if not flag:
                break
            if len(s)!=len(ng):
                continue
            f = True
            for i,t in enumerate(ng):
                if s[i]!=t and t!="*":
                    f = False
                    break
            if f:
                flag = False
                break
        if not flag:
            ans.append("*"*len(s))
        else:
            ans.append(s)
    print(" ".join(map(str,ans)))
    return

def examD():
    H, W = LI()
    S = [SI()for _ in range(H)]
    D = defaultdict(int)
    for s in S:
        for d in s:
            D[d] += 1
    odd = 1
    two = (H//2)*(W%2) + (W//2)*(H%2)
    for d in D.values():
        if d%2==1:
            odd -= 1
        elif d%4==2:
            two -= 1
    if odd<0 or two<0:
        print("No")
        return
    print("Yes")
    return

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

def examF():
    N, K = LI()
    S = SI()
    D = [defaultdict(int) for _ in range(N+1)]
    for i in range(N):
        D[i+1] = deepcopy(D[i])
        D[i+1][S[i]] += 1
    ans = "No"
    L = [defaultdict(int) for _ in range(N-K+1)]
    for i in range(N-K+1):
        cur = deepcopy(D[i+K])
        for s,j in D[i].items():
            cur[s] -= j
        L[i] = cur



    print(ans)
    return

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,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,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examD()

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

Solution (Python):
import collections

H, W  = map(int, input().split())
A = []
for _ in range(H):
    for c in input():
        A.append(c)
A.sort()
B = collections.Counter(A).most_common()


success = False
if H % 2 == 0 and W % 2 == 0:
    if all([val[1] % 4 == 0 for val in B]):
        success = True
elif H % 2 == 1 and W % 2 == 0:
    if all([val[1] % 2 == 0 for val in B]):
        four = 0
        two = 0
        for el in B:
            x = el[1]
            if x % 4 == 0:
                four += 1
            elif x % 2 == 0:
                two += 1
        if two <= W // 2 and (W // 2 - two) % 2 == 0:
            success = True
elif H % 2 == 0 and W % 2 == 1:
    if all([val[1] % 2 == 0 for val in B]):
        four = 0
        two = 0
        for el in B:
            x = el[1]
            if x % 4 == 0:
                four += 1
            elif x % 2 == 0:
                two += 1
        if two <= H // 2 and (H // 2 - two) % 2 == 0:
            success = True
else:
    odd = 0
    two = 0
    four = 0
    for el in B:
        x = el[1]
        if x % 2 == 1:
            odd += 1
            x -= 1
        if x % 4 == 0:
            four += 1
        elif x % 2 == 0:
            two += 1
    if odd == 1:
        if two <= H // 2 + W // 2 and (H // 2 + W // 2- two) % 2 == 0:
            success = True
if success:
    print('Yes')
else:
    print('No')

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False



def main():
    H, W = MI()
    alpha = [0] * len(l_alp)

    for i in range(H):
        s = S()
        for j in range(W):
            alpha[ord(s[j])-97] += 1

    for i in range((H+1)//2):
        for j in range((W+1)//2):
            V = 4
            if H % 2 != 0 and i == (H+1)//2-1:
                V //= 2
            if W % 2 != 0 and j == (W+1)//2-1:
                V //= 2
            f = False

            if V == 2:
                for k in range(len(alpha)):
                    if alpha[k] % 2 == 0 and alpha[k] % 4 == 2:
                        f = True
                        alpha[k] -= V
                        break

            if not f:
                for k in range(len(alpha)):
                    if alpha[k] >= V:
                        f = True
                        alpha[k] -= V
                        break
            
            if not f:
                print('No')
                return
    
    print('Yes')

if __name__ == '__main__':
    main()

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
a = [input() for _ in range(H)]
cnt = defaultdict(int)
for l in a:
	for s in l:
		cnt[s] += 1

l = sorted(list(cnt.values()), reverse=True)
if H%2==0 and W%2==0:
	for v in cnt.values():
		if v%4 != 0:
			print("No")
			break
	else:
		print("Yes")
elif H%2==0 and W%2==1:
	tmp = (W-1)*H//4
	if tmp:
		for i in range(len(l)):
			if l[i] >= 4:
				take = l[i]//4
				if tmp - take > 0:
					l[i] -= 4*take
					tmp -= take
				else:  
					l[i] -= 4*tmp
					tmp = 0
					break	
		else:
			print("No")
			exit()
	for v in l:
		if v%2 != 0:
			print("No")
			break
	else:
		print("Yes")
elif H%2==1 and W%2==0:
	tmp = (H-1)*W//4
	if tmp:
		for i in range(len(l)):
			if l[i] >= 4:
				take = l[i]//4
				if tmp - take > 0:
					l[i] -= 4*take
					tmp -= take
				else:  
					l[i] -= 4*tmp
					tmp = 0
					break	
		else:
			print("No")
			exit()
	for v in l:
		if v%2 != 0:
			print("No")
			break
	else:
		print("Yes")
else:
	tmp = (H-1)*(W-1)//4
	if tmp:
		for i in range(len(l)):
			if l[i] >= 4:
				take = l[i]//4
				if tmp - take > 0:
					l[i] -= 4*take
					tmp -= take
				else:  
					l[i] -= 4*tmp
					tmp = 0
					break	
		else:
			print("No")
			exit()
	odd = 0
	for v in l:
		if v%2 == 1:
			odd += 1
	print("Yes" if odd == 1 else "No")

Solution (Python):
h,w = map(int,input().split())
lis = [0 for i in range(26)]
s = [str(input()) for i in range(h)]
for i in range(h):
  for j in range(w):
    lis[ord(s[i][j])-ord("a")] += 1
lis.sort()
cnt1 = 0
cnt4 = 0
for num in lis:
  if num % 2 == 1:
    cnt1 += 1
  cnt4 += num//4
if h % 2 == 0:
  if w % 2 == 0:
    if cnt4 == (h//2)*(w//2):
      print("Yes")
    else:
      print("No")
  else:
    if cnt1 == 0 and cnt4 >= (h//2)*(w//2):
      print("Yes")
    else:
      print("No")
else:
  if w % 2 == 0:
    if cnt1 == 0 and cnt4 >= (h//2)*(w//2):
      print("Yes")
    else:
      print("No")
  else:
    if cnt1 == 1 and cnt4 >= (h//2)*(w//2):
      print("Yes")
    else:
      print("No")

Solution (Python):
H, W = map(int, input().split(" "))
four, two, one = 0, 0, 0

four += ((H // 2)) * (W // 2)
if W % 2 == 1:
    two += (H // 2)
if H % 2 == 1:
    two += (W // 2)

one += (H * W) % 2

counter = {}
for _ in range(H):
    A = input()
    for a in A:
        if a in counter:
            counter[a] += 1
        else:
            counter[a] = 1

flag = True
for c in counter:
    if counter[c] >= 4 and four > 0:
        mk_four = min(four, counter[c] // 4)
        four -= mk_four
        counter[c] -= mk_four * 4
    if counter[c] >= 2 and two > 0:
        mk_two = min(two, counter[c] // 2)
        two -= mk_two
        counter[c] -= mk_two * 2
    if counter[c] >= 1 and one > 0:
        mk_one = min(one, counter[c])
        one -= mk_one
        counter[c] -= mk_one

    if counter[c] != 0:
        flag = False


if flag and (four == two == one == 0):
    print('Yes')
else:
    print('No')

Solution (Python):
from collections import Counter

H, W = map(int, input().split())
mat = [input() for _ in range(H)]
cnts = Counter(c for r in mat for c in r)
odd = 0
if H % 2:
    odd += 1
if W % 2:
    odd += 1


def solve():
    v1 = list(cnts.values())
    rest = sum(v1)
    assert rest == H * W
    v2, v3 = [], []
    for v in v1:
        rest -= v - v % 4
        if v % 4:
            v2.append(v % 4)
    if odd == 0:
        return rest == 0 and not v2
    if H % 2 and W % 2 == 0 and rest > W:
        return False
    if H % 2 == 0 and W % 2 and rest > H:
        return False
    if H % 2 and W % 2 and rest > H + W - 1:
        return False
    for v in v2:
        rest -= v - v % 2
        if v % 2:
            v3.append(v % 2)
    if odd == 1:
        return rest == 0 and not v3
    return rest == 1 and len(v3) == 1


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

Solution (Python):
h,w = map(int, input().split())
a = [input() for i in range(h)]
cnt = [0] * 26
for i in a:
  for j in i:
    cnt[ord(j)-ord("a")] += 1
two,no = 0,0
for i in cnt:
  if i % 2:
    no += 1
  elif i % 4:
    two += 1
if (h % 2) and (w % 2):
  if no <= 1 and two <= h//2 + w//2:
    print("Yes")
  else:
    print("No")
elif (h % 2):
  if no == 0 and two <= w//2:
    print("Yes")
  else:
    print("No")
elif (w % 2):
  if no == 0 and two <= h//2:
    print("Yes")
  else:
    print("No")
else:
  if no == 0 and two == 0:
    print("Yes")
  else:
    print("No")

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

chars=dict()
for line in lines:
    for c in line:
        if c not in chars:
            chars[c]=0
        chars[c]+=1

def judge(H,W,chars):
    
    if H%2+W%2==2:
        ones=1
        twos=H//2 + W//2
    
    elif H%2+W%2==0:
        ones=0
        twos=0
    elif H%2==1:
        ones=0
        twos=W//2
    else:
        ones=0
        twos=H//2
    for c in chars:
        chars[c]%=4
        if chars[c]==0:
            continue
        if chars[c]==2:
            twos-=1
        elif chars[c]==3:
            twos-=1
            ones-=1
        else:
            ones-=1
    if ones<0 or twos<0:
        return False
    return True

if judge(H,W,chars):
    print("Yes")
else:
    print("No")

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

chars=dict()
for line in lines:
    for c in line:
        if c not in chars:
            chars[c]=0
        chars[c]+=1

def judge(H,W,chars):
    
    if H%2+W%2==2:
        ones=1
        twos=H//2 + W//2
    
    elif H%2+W%2==0:
        ones=0
        twos=0
    elif H%2==1:
        ones=0
        twos=W//2
    else:
        ones=0
        twos=H//2
    for c in chars:
        if ones<0 or twos<0:
            return False
        chars[c]%=4
        if chars[c]==0:
            continue
        if chars[c]==2:
            twos-=1
        elif chars[c]==3:
            twos-=1
            ones-=1
        else:
            ones-=1
    if ones<0 or twos<0:
        return False
    return True

if judge(H,W,chars):
    print("Yes")
else:
    print("No")

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

chars=dict()
for line in lines:
    for c in line:
        if c not in chars:
            chars[c]=0
        chars[c]+=1

def judge(H,W,chars):
    
    if H%2+W%2==2:
        ones=1
        twos=H//2 + W//2
    
    elif H%2+W%2==0:
        ones=0
        twos=0
    elif H%2==1:
        ones=0
        twos=W//2
    else:
        ones=0
        twos=H//2
    for c in chars:
        if ones<0 or twos<0:
            return False
        chars[c]%=4
        if chars[c]==0:
            continue
        if chars[c]==2:
            twos-=1
        elif chars[c]==3:
            twos-=1
            ones-=1
        else:
            ones-=1
    return True

if judge(H,W,chars):
    print("Yes")
else:
    print("No")

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

chars=dict()
for line in lines:
    for c in line:
        if c not in chars:
            chars[c]=0
        chars[c]+=1

def judge(H,W,chars):
    
    if H%2+W%2==2:
        ones=1
        twos=(H+W-2)//2
    
    elif H%2+W%2==0:
        ones=0
        twos=0
    elif H%2==1:
        ones=0
        twos=W//2
    else:
        ones=0
        twos=H//2
    for c in chars:
        if ones<0 or twos<0:
            return False
        chars[c]%=4
        if chars[c]==0:
            continue
        if chars[c]==2:
            twos-=1
        elif chars[c]==3:
            twos-=1
            ones-=1
        else:
            ones-=1
    return True

if judge(H,W,chars):
    print("Yes")
else:
    print("No")

Solution (Python):
def main():
    H, W = (int(i) for i in input().split())
    A = [input() for i in range(H)]
    from collections import Counter
    c = Counter(A[0])
    for a in A[1:]:
        c += Counter(a)
    if H % 2 == 0 and W % 2 == 0:
        if all(v % 4 == 0 for v in c.values()):
            return print("Yes")
        else:
            return print("No")
    elif H % 2 == 1 and W % 2 == 1:
        c_odd = sum(1 if v % 2 == 1 else 0 for k, v in c.items())
        if c_odd == 1 and \
            sum(1 if v % 4 == 2 else 0 for v in c.values()) <= \
                (W//2 + H//2):
            return print("Yes")
        else:
            return print("No")
    else:
        if all(v % 2 == 0 for v in c.values()) and \
            sum(1 if v % 4 == 2 else 0 for v in c.values()) <= \
                (W//2 if W % 2 == 0 else H//2):
            return print("Yes")
        else:
            return print("No")


if __name__ == '__main__':
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter

h, w = map(int, readline().split())
a = []
for i in range(h):
    a += list(readline().rstrip().decode())
counter = Counter(a).values()
check = [1, h // 2 + w // 2, (h // 2) * (w // 2)]
if h % 2 == 0:
    check[0] = 0
    check[1] -= w // 2
if w % 2 == 0:
    check[0] = 0
    check[1] -= h // 2
for v in counter:
    if check[2] < v // 4:
        v -= 4 * check[2]
        check[2] = 0
    else:
        check[2] -= v // 4
        v %= 4
    if check[1] < v // 2:
        v -= 2 * check[1]
        check[1] = 0
    else:
        check[1] -= v // 2
        v %= 2
    check[0] -= v
print('Yes' if all(check[i] == 0 for i in range(3)) else 'No')

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    from collections import defaultdict
    H, W = map(int, input().split())
    counter = defaultdict(int)
    for _ in range(H):
        for s in input().rstrip():
            counter[s] += 1
    if H % 2 == 0 and W % 2 == 0:
        for cnt in counter.values():
            if cnt % 4 != 0:
                print("No")
                sys.exit()
        print("Yes")
        sys.exit()
    
    if H % 2 == 1 and W % 2 == 1:
        one_cnt = 0
        two_cnt = 0
        for cnt in counter.values():
            if cnt % 4 != 0:
                if cnt % 2 == 0:
                    two_cnt += 1
                else:
                    one_cnt += 1
        if two_cnt <= H // 2 + W // 2 and one_cnt <= 1:
            print("Yes")
        else:
            print("No")
        sys.exit()
    
    if H % 2 == 1 and W % 2 == 0:
        two_cnt = 0
        for cnt in counter.values():
            if cnt % 4 != 0:
                if cnt % 2 == 0:
                    two_cnt += 1
                else:
                    print("No")
                    sys.exit()
        if two_cnt <= W // 2:
            print("Yes")
        else:
            print("No")
        sys.exit() 

    if H % 2 == 0 and W % 2 == 1:
        two_cnt = 0
        for cnt in counter.values():
            if cnt % 4 != 0:
                if cnt % 2 == 0:
                    two_cnt += 1
                else:
                    print("No")
                    sys.exit()
        if two_cnt <= H // 2:
            print("Yes")
        else:
            print("No")
        sys.exit() 

if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict

H,W = map(int, input().split())
cnt = defaultdict(int)
for _ in range(H):
    for a in list(input()):
        cnt[a] += 1
cnt = [c for c in cnt.values()]



for i in range((H + 2 - 1) // 2):
    for j in range((W + 2 - 1) // 2):
        need = [(i, j), (H - 1 - i, j), (i, W - 1 - j), (H - 1 - i, W - 1 - j)]
        need = set(need)

        cnt.sort()

        flag = False
        for k in range(len(cnt)):
            if len(need) <= cnt[k]:
                flag = True
                cnt[k] -= len(need)
                if cnt[k] == 0:
                    cnt.pop(k)
                break
                    
        if not flag:
            print("No")
            exit()

print("Yes")

Solution (Python):
from collections import Counter
H, W = map(int,input().split())
a = ""
for k in range(H):
    a += input()
C = Counter(a)
s = 0
for e in C:
    s += C[e]//4
if s < (H//2)*(W//2):
    print("No")
    exit(0)

a = s-(H//2)*(W//2)
t = 0
u = 0
for e in C:
    t += C[e]%4
    u += C[e]%2

if 2*t + 4*a < (H%2)*(H//2) + (W%2)*(W//2):
    print("No")
    exit(0)
if u != (H%2)*(W%2):
    print("No")
else:
    print("Yes")

Solution (Python):
H,W = map(int,input().split())
C = {}
for _ in range(H):
    A = input().strip()
    for i in range(W):
        if A[i] not in C:
            C[A[i]] = 0
        C[A[i]] += 1
cnt4 = 0
cnt1 = 0
for a in C:
    if C[a]>=4:
        cnt4 += C[a]//4
        C[a] = C[a]%4
    if C[a]%2==1:
        cnt1 += 1
if cnt4<(W//2)*(H//2):
    flag = 0
else:
    if H%2==1 and W%2==1:
        if cnt1==1:
            flag = 1
        else:
            flag = 0
    else:
        if cnt1==0:
            flag = 1
        else:
            flag = 0
if flag==1:
    print("Yes")
else:
    print("No")