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())
d=[0]*26
for i in range(h):
    b=list(input())
    for j in range(w):
        d[ord(b[j])-ord("a")]+=1
s=0
t=0
r=0
for i in range(26):
    if d[i]%4==0:
        s+=d[i]//4
    elif d[i]%2==0:
        s+=d[i]//4
        t+=(d[i]%4)//2
    else:
        s+=d[i]//4
        t+=(d[i]%4)//2
        r+=1
if h%2==0 and w%2==0:
    if t==0 and r==0:
        print("Yes")
    else:
        print("No")
elif h%2==1 and w%2==1:
    if r==1 and(w+h-2-2*t)>=0 and (w+h-2-2*t)%4==0:
        print("Yes")
    else:
        print("No")
else:
    q=(w if h%2==1 else h)
    if q-2*t>=0  and (q-2*t)%4==0:
        print("Yes")
    else:
        print("No")

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

Solution (Python):
H, W = map(int, input().split())
c = [0] * 26
for _ in range(H):
	for i in input():
		c[ord(i) - ord('a')] += 1
a = 0
b = 0
for i in c:
	a += i % 4 // 2
	b += i % 2
if (H % 2) * (W % 2) < b:
	print("No")
elif (H % 2) * (W // 2) + (H // 2) * (W % 2) < a:
	print("No")
else:
	print("Yes")

Solution (Python):
H, W = map(int, input().split())
c = [0] * 26
for _ in range(H):
	for i in input():
		c[ord(i) - ord('a')] += 1
a = 0
b = 0
for i in c:
	a += i % 4 // 2
	b += i % 2
if (H % 2) * (W % 2) < b:
	print("No")
elif (H % 2) * (W // 2) + (H // 2) * (W % 2) < a:
	print("No")
else:
	print("Yes")

Solution (Python):


import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H,W=MAP()
S=''
for i in range(H):
    S+=input()


C=Counter(S)
cnt=Counter()
for v in C.values():
    cnt[v%4]+=1

cnt[1]+=cnt[3]
cnt[2]+=cnt[3]
cnt[3]=0


if H%2==0 and W%2==0:
    
    if cnt[1]==0 and cnt[2]==0:
        Yes()
    else:
        No()


elif H%2==0:
    
    if cnt[2]<=H//2 and cnt[1]==0:
        Yes()
    else:
        No()


elif W%2==0:
    
    if cnt[2]<=W//2 and cnt[1]==0:
        Yes()
    else:
        No()


else:
    
    if cnt[1]==1 and cnt[2]<=(H+W)//2-1:
        Yes()
    else:
        No()

Solution (Python):


import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H,W=MAP()
S=''
for i in range(H):
    S+=input()

C=Counter(S)
cnt1=cnt2=0

if H%2==0 and W%2==0:
    for k, v in C.items():
        if v%4!=0:
            No()
            exit()
    
    Yes()

elif H%2==0:
    for k, v in C.items():
        if v%4!=0:
            if v%2==0:
                cnt2+=1
            else:
                No()
                exit()
    
    if cnt2<=H//2:
        Yes()
    else:
        No()

elif W%2==0:
    for k, v in C.items():
        if v%4!=0:
            if v%2==0:
                cnt2+=1
            else:
                No()
                exit()
    
    if cnt2<=W//2:
        Yes()
    else:
        No()

else:
    for k, v in C.items():
        if v%4!=0:
            if v%2==0:
                cnt2+=1
            elif v%3==0:
                cnt1+=1
                cnt2+=1
            else:
                cnt1+=1
    
    if cnt1==1 and cnt2<=(H+W)//2-1:
        Yes()
    else:
        No()

Solution (Python):


import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H,W=MAP()
S=''
for i in range(H):
    S+=input()

C=Counter(S)
if H%2==0 and W%2==0:
    for k, v in C.items():
        if v%4!=0:
            No()
            exit()
    Yes()
elif H%2==0:
    mod2=0
    for k, v in C.items():
        if v%4!=0:
            if v%2==0:
                mod2+=1
            else:
                No()
                exit()
    if mod2<=H//2:
        Yes()
    else:
        No()
elif W%2==0:
    mod2=0
    for k, v in C.items():
        if v%4!=0:
            if v%2==0:
                mod2+=1
            else:
                No()
                exit()
    if mod2<=W//2:
        Yes()
    else:
        No()
else:
    mod2=mod1=0
    for k, v in C.items():
        if v%4!=0:
            if v%2==0:
                mod2+=1
            elif v%3==0:
                mod2+=1
                mod1+=1
            else:
                mod1+=1
    if mod1==1 and mod2<=(H+W)//2-1:
        Yes()
    else:
        No()

Solution (Python):
from collections import Counter

if __name__ == '__main__':
    h, w = map(int, input().split())
    counts = Counter(''.join(input() for _ in range(h))).values()
    c1, c2 = 0, 0
    for x in counts:
        if x % 2:
            c1 += 1
            x -= 1
        if x % 4:
            c2 += 1
    if c1 == 1 and (h * w) & 1 == 0 or c1 > 1:
        print('No')
        quit(0)
    lim2 = 0
    if h & 1:
        lim2 += w // 2
    if w & 1:
        lim2 += h // 2
    if lim2 >= c2:
        print('Yes')
    else:
        print('No')

Solution (Python):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [H, W] = [int(input_raw[0]), int(input_raw[1])]
    dic = {}
    for i in range(H):
        input_raw = read_func().strip()
        for j in range(W):
            if input_raw[j] not in dic:
                dic[input_raw[j]] = 1
            else:
                dic[input_raw[j]] += 1

    max_count = 0
    odd_count = 0
    even_count = 0

    if H % 2 == 0 and W % 2 == 0:
        for s in dic:
            if dic[s] % 4 != 0:
                print "No"
                return
        print "Yes"
    else:
        four_count = (H / 2) * (W / 2)
        count = 0
        odd_count = 0
        for s in dic:
            count += dic[s]/4
            dic[s] %= 4
            if dic[s] %2 == 1:
                odd_count += 1
        if count < four_count:
            print "No"
            return
        if H % 2 == 1 and W % 2 == 1:
            if odd_count == 1:
                print "Yes"
            else:
                print "No"
            return
        else:
            if odd_count == 0:
                print "Yes"
            else:
                print "No"



if __name__ == '__main__':
    main()

Solution (Python):
H,W = list(map(int,input().split()))
def atoi(a):
    alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',
                'p','q','r','s','t','u','v','w','x','y','z']
    return alphabet.index(a)
a_list = [0 for i in range(26)]

for i in range(H):
    S=input()
    for a in range(len(S)):
        a_list[atoi(S[a])]+=1

if H%2==0 and W%2==0:
    flg=True
    for a in a_list:
        if a%4!=0:
            flg=False
            break
    if flg:
        print("Yes")
    else:
        print("No")
elif H%2==1 and W%2==0:
    w=W//2
    count=0
    flg=True
    for a in a_list:
        if a%4==1 or a%4==3:
            flg=False
            break
        elif a%4==2:
            count+=1
        if count>w:
            flg=False
            break
    if flg:
        print("Yes")
    else:
        print("No")
elif H%2==0 and W%2==1:
    h=H//2
    count=0
    flg=True
    for a in a_list:
        if a%4==1 or a%4==3:
            flg=False
            break
        elif a%4==2:
            count+=1
        if count>h:
            flg=False
            break
    if flg:
        print("Yes")
    else:
        print("No")
else:
    h=H//2
    w=W//2
    count1=0
    count2=0
    flg=True
    for a in a_list:
        if a%4==1 or a%4==3:
            count1+=1
        elif a%4==2:
            count2+=1
        if count2>h+w or count1>1:
            flg=False
            break
    if flg:
        print("Yes")
    else:
        print("No")

Solution (Python):

from collections import Counter
h,w = map(int, input().split())
al = []
for _ in range(h):
    al += list(input())

c = Counter(al)

if h%2==1 and w%2==1:
    for k in c.keys():
        if c[k]%2==1:
            c[k] -= 1
            break

g4 = (h//2)*(w//2)*4
for k in c.keys():
    while c[k]>=4 and g4>0:
        c[k] -= 4
        g4 -= 4
if g4>0:
    print("No")
    exit()

g2 = (h%2)*(w//2)*2 + (w%2)*(h//2)*2
for k in c.keys():
    while c[k]>=2 and g2>0:
        c[k] -= 2
        g2 -= 2
if g2>0:
    print("No")
    exit()

for k in c.keys():
    if c[k]>0:
        print("No")
        exit()
print("Yes")

Solution (Python):
H,W=map(int,input().split())
A=[input() for _ in range(H)]
from collections import defaultdict
d=defaultdict(int)
for a in A:
  for j in a:
    
    d[j]+=1

four=0
two=0
one=0

for i in  range(26):
  c=chr(ord("a")+i)
  if d[c]>=4:
    four+=d[c]//4 
    d[c]%=4
  if d[c]>=2:
    two+=d[c]//2
    d[c]%=2
  if d[c]>=1:
    one+=d[c]
    d[c]-=1

if four<(H//2)*(W//2):    
  print("No")
  exit(0)
four-=(H//2)*(W//2)
two+=four*2

if H%2==1:
  if two < W//2:
    print("No")
    exit()
  two-=W//2
if W%2==1:
  if two <H//2:
    print("No")
    exit()
  two-=H//2

print("Yes")

Solution (Python):
t,_,s=open(0).read().partition('\n')
h,w=map(int,t.split())
d=[h%2&w%2,w%2*h//2+h%2*w//2,0,h//2*(w//2)]
for i in map(s.count,set(s)-{'\n'}):
  for j in(3,1,0):
    while d[j]and i>j:
      i-=j+1
      d[j]-=1
print('YNeos'[any(d)::2])

Solution (Python):
t,_,s=open(0).read().partition('\n')
h,w=map(int,t.split())
d=[h%2&w%2,w%2*h//2+h%2*w//2,0,h//2*(w//2)]
for i in map(s.count,set(s)-{'\n'}):
  for j in(3,1,0):
    while d[j]and i>j:
      i-=j+1
      d[j]-=1
print('YNeos'[sum(d)>0::2])

Solution (Python):
t,_,s=open(0).read().partition('\n')
h,w=map(int,t.split())
a,b,c,d=h//2,h%2,w//2,w%2
l=[b&d,d*a+b*c,0,a*c]
for i in map(s.count,set(s)-{'\n'}):
  for j in(3,1,0):
    while l[j]and i>j:
      i-=j+1
      l[j]-=1
print('YNeos'[sum(l)>0::2])

Solution (Python):
t,_,s=open(0).read().partition('\n')
h,w=map(int,t.split())
d=[h%2and w%2,w%2*h//2+h%2*w//2,0,h//2*(w//2)]
for i in map(s.count,set(s)-{'\n'}):
  for j in(3,1,0):
    while d[j]and i>j:
      i-=j+1
      d[j]-=1
print('YNeos'[sum(d)>0::2])

Solution (Python):
t,_,s=open(0).read().partition('\n')
h,w=map(int,t.split())
a,b=h//2*(w//2),h%2and w%2
d=[b,(h*w-a*4-b)//2,0,a]
for i in map(s.count,set(s)-{'\n'}):
  for j in(3,1,0):
    while d[j]and i>j:
      i-=j+1
      d[j]-=1
print('YNeos'[sum(d)>0::2])

Solution (Python):
t,_,s=open(0).read().partition('\n')
h,w=map(int,t.split())
d={}
d[4]=a=h//2*(w//2)
d[1]=b=h%2and w%2
d[2]=(h*w-a*4-b)//2
for i in map(s.count,set(s)-{'\n'}):
  for j in(4,2,1):
    while d[j]and i>=j:
      i-=j
      d[j]-=1
print('YNeos'[sum(d.values())>0::2])

Solution (Python):
t,_,s=open(0).read().partition('\n')
h,w=map(int,t.split())
d={}
d[4]=a=h//2*(w//2)
d[1]=b=h%2and w%2
d[2]=(h*w-a*4-b)//2
for i in map(s.count,set(s)-{'\n'}):
  for j in(4,2,1):
    while d[j]and i>=j:
      i-=j
      d[j]-=1
print('YNeos'[any(t for t in d.values())::2])

Solution (Python):
t,_,s=open(0).read().partition('\n')
h,w=map(int,t.split())
d={}
d[3]=h//2*(w//2)
d[0]=h%2and w%2
d[1]=(h*w-d[3]*4-d[0])//2
for i in set(s)-{'\n'}:
  i=s.count(i)
  for j in[3,1,0]:
    while d[j]and i>j:
      i-=j+1
      d[j]-=1
print('YNeos'[any(t for t in d.values())::2])

Solution (Python):
t,_,s=open(0).read().partition('\n')
h,w=map(int,t.split())
a=h//2*(w//2)
c=h%2and w%2
b=(h*w-a*4-c)//2
for i in set(s)-{'\n'}:
  i=s.count(i)
  while i>3and a:
    i-=4
    a-=1
  while i>1and b:
    i-=2
    b-=1
  if i and c:
    i-=1
    c-=1
print('YNeos'[any(t for t in(a,b,c))::2])

Solution (Python):
t,_,s=open(0).read().partition('\n')
h,w=map(int,t.split())
a=h//2*(w//2)
c=h%2and w%2
b=(h*w-a*4-c)//2
for i in set(s.replace('\n','')):
  i=s.count(i)
  while i>3and a:
    i-=4
    a-=1
  while i>1and b:
    i-=2
    b-=1
  if i and c:
    i-=1
    c-=1
print('YNeos'[any(t for t in(a,b,c))::2])

Solution (Python):
t,_,s=open(0).read().partition('\n')
h,w=map(int,t.split())
a=h//2*(w//2)
c=h%2and w%2
b=(h*w-a*4-c)//2
l=[]
for i in set(s.replace('\n','')):
    l.append(s.count(i))
for i in l:
    if i>3:
        while i>3and a:
            i-=4
            a-=1
    if i>1:
        while i>1and b:
            i-=2
            b-=1
    if i and c:
        i-=1
        c-=1
if all(not t for t in(a,b,c)):
    print('Yes')
else:
    print('No')

Solution (Python):
t,_,s=open(0).read().partition('\n')
h,w=map(int,t.split())
a=b=c=0
if h%2and w%2:
    a=h//2*(w//2)
    c=1
    b=(h*w-a*4-c)//2
elif h%2or w%2:
    a=h//2*(w//2)
    b=(h*w-a*4)//2
else:
    a=h*w//4
l=[]
for i in set(s.replace('\n','')):
    l.append(s.count(i))
for i in l:
    if i>3:
        while i>3and a:
            i-=4
            a-=1
    if i>1:
        while i>1and b:
            i-=2
            b-=1
    if i and c:
        i-=1
        c-=1
if all(not t for t in(a,b,c)):
    print('Yes')
else:
    print('No')

Solution (Python):
t,_,s=open(0).read().partition('\n')
h,w=map(int,t.split())
a=b=c=0
if h%2and w%2:
    a=h//2*(w//2)
    c=1
    b=(h*w-a*4-c)//2
elif h%2or w%2:
    a=h//2*(w//2)
    b=(h*w-a*4)//2
else:
    a=h*w//4
l=[]
for i in set(s.replace('\n','')):
    l.append(s.count(i))
for i in l:
    if i>3:
        while i>3and a:
            i-=4
            a-=1
    if i>1:
        while i>1and b:
            i-=2
            b-=1
    if i and c:
        i-=1
        c-=1
if all(not t for t in(a,b,c)):
    print('Yes')
else:
    print('No')

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

d = Counter(s).most_common()
one = 0
two = 0
if h % 2:
    if w % 2:
        for _, num in d:
            if num % 4 == 1 or num % 4 == 3:
                one += 1
                if one > 1:
                    print("No")
                    exit()
                if num % 4 == 3:
                    two += 1
                    if two > h//2 + w//2:
                        print("No")
                        exit()
            if num % 4 == 2:
                two += 1
                if two > h//2 + w//2:
                    print("No")
                    exit()
    else:
        for _, num in d:
            if num % 4:
                if num % 4 == 2:
                    two += 1
                    if two > w//2:
                        print("No")
                        exit()
                else:
                    print("No")
                    exit()
else:
    if w % 2:
        for _, num in d:
            if num % 4:
                if num % 4 == 2:
                    two += 1
                    if two > h//2:
                        print("No")
                        exit()
                else:
                    print("No")
                    exit()
    else:
        for _, num in d:
            if num % 4:
                print("No")
                exit()
print("Yes")

Solution (Python):

import collections
h, w = map(int, input().split())
a = []
for i in range(h):
    a.append(input())


palinmoji = ""
for i in range(h):
    palinmoji += a[i]

palinli = collections.Counter(palinmoji)

if h % 2 == 0 and w % 2 == 0:
    for i in palinli:
        if palinli[i] % 4 != 0:
            print("No")
            exit()
    print("Yes")
elif h % 2 == 0 and w % 2 != 0:
    cnt = 0
    for i in palinli:
        if palinli[i] % 4 != 0:
            if palinli[i] % 2 != 0:
                print("No")
                exit()
            if palinli[i] % 2 == 0:
                cnt += 1
            if cnt == h // 2 + 1:
                print("No")
                exit()
    print("Yes")
elif h % 2 != 0 and w % 2 == 0:
    cnt = 0
    for i in palinli:
        if palinli[i] % 4 != 0:
            if palinli[i] % 2 != 0:
                print("No")
                exit()
            if palinli[i] % 2 == 0:
                cnt += 1
            if cnt == w // 2 + 1:
                print("No")
                exit()
    print("Yes")
elif h % 2 != 0 and w % 2 != 0:
    cnt = 0
    onecnt = 0
    for i in palinli:
        if palinli[i] % 4 != 0:
            if palinli[i] % 2 != 0:
                onecnt += 1
                if (palinli[i] - 1) % 4 != 0 and onecnt == 1:
                    cnt += 1
                    pass
                elif onecnt == 2:
                    print("No")
                    exit()
            if palinli[i] % 2 == 0:
                cnt += 1
    if cnt >= h // 2 + w // 2 + 1:
        print("No")
        exit()
    print("Yes")

Solution (Python):
from collections import defaultdict, deque
H, W = map(int, input().split())



Counts = defaultdict(int)
for i in range(H):
    A = input()
    for a in A:
        Counts[a] += 1
Counts = deque(sorted(Counts.values()))



mod4 = [c % 4 for c in Counts]
for i in range(len(mod4)):
    if mod4[i] == 3:
        mod4[i] = 1
        mod4.append(2)


if (H % 2 == 0) and (W % 2 == 0):
    print('No' if any(mod4) else 'Yes')


elif (H % 2 == 1) and (W % 2 == 0):
    if (mod4.count(2) <= W // 2) and (set(mod4) == {0, 2}):
        print('Yes')
    else:
        print('No')


elif (H % 2 == 0) and (W % 2 == 1):
    if (mod4.count(2) <= H // 2) and (set(mod4) == {0, 2}):
        print('Yes')
    else:
        print('No')


else:
    if (mod4.count(2) <= (H // 2) + (W // 2)) and (mod4.count(1) == 1):
        print('Yes')
    else:
        print('No')

Solution (Python):
H, W = [int(_) for _ in input().split()]
memo = {}
for _ in range(H):
    for _ in input():
        memo[_] = memo.get(_, 0) + 1
count = [0] * 4
for k, v in memo.items():
    count[v % 4] += 1
ans = 'No'
if H * W % 2:
    if count[1] + count[3] == 1 and 1 + 2 * count[2] <= H + W - 1:
        ans = 'Yes'
elif H % 2:
    if count[1] == count[3] == 0 and 2 * count[2] <= W and (
            W - 2 * count[2]) % 4 == 0:
        ans = 'Yes'
elif W % 2:
    if count[1] == count[3] == 0 and 2 * count[2] <= H and (
            H - 2 * count[2]) % 4 == 0:
        ans = 'Yes'
else:
    if count[1] == count[2] == count[3] == 0:
        ans = 'Yes'
print(ans)

Solution (Python):
from collections import Counter

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

ng = False
if H % 2 == 0 and W % 2 == 0:
	for value in c.values():
		if value % 4 != 0:
			ng = True

elif W % 2 == 0:
	two = 0
	for value in c.values():
		if value % 4 != 0:
			if value % 2 != 0:
				ng = True
			else:
				two += 1
	if two > W // 2:
		ng = True

elif H % 2 == 0:
	two = 0
	for value in c.values():
		if value % 4 != 0:
			if value % 2 != 0:
				ng = True
			else:
				two += 1
	if two > H // 2:
		ng = True

else:
	two = 0
	one = 0
	three = 0
	for value in c.values():
		if value % 4 != 0:
			if value % 2 != 0:
				if value % 4 == 1:
					one += 1
				else:
					three += 1
			else:
				two += 1
	if (one+three) > 1:
		ng = True
	elif one:
		if two > H // 2 + W // 2:
			ng = True
	elif three:
		if two+1 > H // 2 + W // 2:
			ng = True

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

Solution (Python):
H,W=map(int,input().split())
A=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
L=[0]*26

for j in range(H):
    a=list(input())
    for k in range(W):
        for l in range(26):
            if a[k]==A[l]:
                L[l]+=1
                
for x in range(26):
    L[x]=L[x]%4
                
if H*W%2==1:
    if L.count(1)+L.count(3)==1 and L.count(2)+L.count(3)<=(H+W-2)//2:
        print("Yes")
    else:
        print("No")
elif H%2==1:
    if L.count(1)+L.count(3)==0 and L.count(2)<=W//2:
        print("Yes")
    else:
        print("No")
elif W%2==1:
    if L.count(1)+L.count(3)==0 and L.count(2)<=H//2:
        print("Yes")
    else:
        print("No")
else:
    if sum(L)==0:
        print("Yes")
    else:
        print("No")

Solution (Python):
import collections
def inpl(): return [int(i) for i in input().split()]

H, W = inpl()
a = collections.Counter(''.join([input() for _ in range(H)]))
nd2, nd4 = 0, 0 
for i in a.values():
    if i%2:
        nd2 += 1
        i -= 1
    if i%4:
        nd4 += 1
ans = 'No'
if H%2 and W%2:
    if nd2 == 1 and (H+W-2)//2 >= nd4:
        ans = 'Yes'
elif H%2:
    if not nd2 and W//2 >= nd4:
        ans = 'Yes'
elif W%2:
    if not nd2 and H//2 >= nd4:
        ans = 'Yes'
else:
    if not nd2 and not nd4:
        ans = 'Yes'
print(ans)

Solution (Python):
from collections import defaultdict
H,W=map(int,input().split())
c=defaultdict(int)
for i in range(H):
  s=input()
  for j in range(W):
    c[s[j]]+=1

if H%2==0 and W%2==0:
  for v in c.values():
    if v%4!=0:
      print("No")
      exit()
elif H%2==0 or W%2==0:
  k=0
  for v in c.values():
    if v%2!=0:
      print("No")
      exit()
    else:
      k+=v//4
  if k<(H//2)*(W//2):
    print("No")
    exit()
else:
  k=0
  f=0
  for v in c.values():
    if v%2!=0:
      if f==0:
        k+=v//4
        f=1
      else:
        print("No")
        exit()
    else:
      k+=v//4
  if k<(H//2)*(W//2):
    print("No")
    exit()
  
print("Yes")

Solution (Python):
from collections import defaultdict
H, W = map(int, input().split())
A = [list(input()) for i in range(H)]

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

Mod4 = [0, 0, 0, 0]
for d in D:
    Mod4[D[d] % 4] += 1

if H%2 == W%2 == 0:
    if Mod4[1] == Mod4[2] == Mod4[3] == 0: print("Yes")
    else: print("No")
elif H%2 == 0:
    if Mod4[2] <= H//2 and Mod4[1] == Mod4[3] == 0: print("Yes")
    else: print("No")
elif W%2 == 0:
    if Mod4[2] <= W//2 and Mod4[1] == Mod4[3] == 0: print("Yes")
    else: print("No")
else:
    if Mod4[1] == 1 and Mod4[3] == 0 and Mod4[2] <= (H+W-1)//2: print("Yes")
    elif Mod4[1] == 0 and Mod4[3] == 1 and Mod4[2] <= (H+W-3)//2: print("Yes")
    else: print("No")

Solution (Python):
H,W=map(int,input().split())
a=[list(input()) for i in range(H)]
c=[0 for i in range(26)]
x=0
for i in range(H):
    for j in range(W):
        c[ord(a[i][j])-97]+=1
y=[0,0,0,0]
for i in range(26):
    y[c[i]%4]+=1
if H%2==0 and W%2==0:
    if y[1]+y[2]+y[3]==0:
        print("Yes")
    else:
        print("No")
elif (H-W)%2==1:
    if y[1]+y[3]==0:
        X=H if H%2==0 else W
        if y[2]>X//2:
            print("No")
        else:
            print("Yes")
    else:
        print("No")
else:
    if y[1]+y[3]==1:
        P=y[3]+y[2]
        if P>(W+H-2)//2:
            print("No")
        else:
            print("Yes")
    else:
        print("No")

Solution (Python):
from collections import Counter as c
d=c()
h,w=map(int,input().split())
for _ in range(h):
  d+=c(input())

def solve():
  global h,w
  if h%2==0 and w%2==0:
    return False if any(map(lambda x:x%4,d.values())) else True

  e=c()
  for i in d.values():e[i%4]+=1

  if h%2 and w%2:
    if e[3] or e[1]!=1 or e[2]>(h-1)/2+(w-1)/2:return False
    return True

  if w%2:h,w=w,h
  if (e[1] or e[3]) or e[2]>w/2:return False
  return True

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

Solution (Python):
ai = lambda: list(map(int,input().split()))

h,w = ai()
m = ''
for _ in range(h):
    m += input()

from collections import Counter
k = list(Counter(m).values())

c1 = 0
c2 = 0
for kk in k:
    if kk % 2:
        c1 += 1
        kk -= 1
    if kk % 4:
        c2 += 1

ans = 0
if h&1 and w&1:
    if c1 <= 1 and c2 <= h//2 + w/2:
        ans = 1
elif h&1:
    if c1 <= 0 and c2 <= w//2:
        ans = 1
elif w&1:
    if c1 <= 0 and c2 <= h//2:
        ans = 1
else:
    if c1 <= 0 and c2 <= 0:
        ans = 1

if ans:
    print('Yes')
else:
    print('No')

Solution (Python):
import sys


ans = 'No'
h, w = [int(_) for _ in input().split()]
s = ''
for i in range(h):
    s += input()

dict = {}
for i in range(len(s)):
    if s[i] in dict.keys():
        dict[s[i]] += 1
    else:
        dict[s[i]] = 1

list = list(dict.values())

if h % 2 != 0 and w % 2 != 0:
    for i in range(len(list)):
        if list[i] % 2 != 0:
            list[i] -= 1
            break

for i in list:
    if i % 2 != 0:
        print('No')
        sys.exit()

c = 0
if h % 2 == 1:
    if w % 2 == 0:
        c += w / 2
    else:
        c += (w - 1) / 2
if w % 2 == 1:
    if h % 2 == 0:
        c += h / 2
    else:
        c += (h - 1) / 2

p = (h // 2) * (w // 2)
for j in range(p):
    for i in range(len(list)):
        if list[i] >= 4:
            list[i] = list[i] % 4
            break

k = 0
for i in list:
    k += i / 2

if k == c:
    ans = 'Yes'

print(ans)

Solution (Python):
from collections import Counter

H, W = map(int,input().split())
A = ""
for _ in range(H): A += input()
C_A = Counter(A)
g1 = (H*W)%2
g2 = (H%2)*(W//2) + (W%2)*(H//2)
g4 = (H//2)*(W//2)
g1_est = 0; g2_est = 0; g4_est = 0;

for n in C_A.values():
    g4_est += n//4
    g2_est += (n%4)//2
    g1_est += n%2
if g4_est>=g4:
    g2_est += 2*(g4_est - g4)
    if g2==g2_est and g1==g1_est:
        print("Yes")
        exit()
print("No")

Solution (Python):
from collections import Counter

H, W = map(int,input().split())
A = ""
for _ in range(H): A += input()

a_count = Counter(A)
sym4 = [0, 0]
sym2 = [0, 0]
sym1 = [0, 0]
sym4[0] = (H//2) * (W//2)
sym2[0] = (H%2) * (W//2) + (H//2) * (W%2)
sym1[0] = (H%2) * (W%2)

for i in a_count.values():
    sym4[1] += i // 4
    sym2[1] += (i % 4) // 2
    sym1[1] += i % 2

if sym4[1] >= sym4[0]:
    sym2[1] += 2 * (sym4[1] - sym4[0])
    if sym2[1] == sym2[0]:
        print('Yes')
        exit()

print('No')

Solution (Python):
def no():
    print("No")
    exit()
H, W = map(int, input().split())
L = [0]*26
for i in range(H):
    for a in input():
        L[ord(a)-97] += 1
t4 = (H//2)*(W//2)
t2 = (H//2)*(W%2)+(H%2)*(W//2)
t1 = (H%2)*(W%2)

for i, n in enumerate(L):
    q, m = divmod(n, 2)
    L[i] = q
    if m==1:
        t1 -= 1
if t1 != 0:
    no()
for i, n in enumerate(L):
    q, m = divmod(n, 2)
    L[i] = q
    if m==1:
        t2 -= 1
if t2 < 0 or t2%2 != 0:
    no()
t4 += t2//2

print("Yes")

Solution (Python):

from sys import stdin
from collections import Counter

in_strings = lambda: stdin.readline()[:-1] 
in_int = lambda: int(stdin.readline()) 
in_intlist = lambda: list(map(int, stdin.readline().split())) 


H, W = in_intlist()
a_list = []
for _ in range(H):
    s = in_strings()
    a_list.extend(list(s))

a_count = Counter(a_list)
sym4 = [0, 0]
sym2 = [0, 0]
sym1 = [0, 0]
sym4[0] = (H//2) * (W//2) 
sym2[0] = (H%2) * (W//2) + (H//2) * (W%2)
sym1[0] = (H%2) * (W%2)

for i in a_count.values():
    sym4[1] += i // 4
    sym2[1] += (i % 4) // 2
    sym1[1] += i % 2

if sym4[1] >= sym4[0]:
    sym2[1] += 2 * (sym4[1] - sym4[0])
    if sym2[1] == sym2[0]:
        print('Yes')
        exit()

print('No')

Solution (Python):
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

h,w = li()

cnt = Counter([])
for _ in range(h):
    tmp = lc()
    for c in tmp:
        cnt[c] += 1

exist = True

if h%2 == 0 and w%2 == 0:
    for key,value in cnt.items():
        if value%4 != 0:
            exist = False
            break
        
elif h%2 == 1 and w%2 == 1:
    odd = 0
    mod4_2 = 0
    for key,value in cnt.items():
        if value % 2 == 1:
            odd += 1
        elif value % 4 == 2:
            mod4_2 += 1
            
    if odd > 1:
        exist = False
    elif mod4_2 > (h+w-2)//2:
        exist = False
        
else:
    odmax = 0
    if h%2 == 0:
        odmax = h//2
    else:
        odmax = w//2
        
    
    mod4_2 = 0
    for key, value in cnt.items():
        if value%2 != 0:
            exist = False
            break
        elif value%4 == 2:
            mod4_2 +=1
            
    if mod4_2 > odmax:
        exist = False
        
        
if exist:
    print("Yes")
else:
    print("No")