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



Sample input:
3 4
aabb
aabb
aacc


Sample output:
Yes

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def f(n):
    a,b,c = 0,0,0
    a = n//4
    r = n%4
    b = r//2
    c = r%2
    return (a,b,c)

h,w = map(int,input().split())
a = defaultdict(lambda:0)
for _ in range(h):
    for i in input():
        a[i] += 1
need = []
need.append((h//2)*(w//2))
need.append((h%2)*(w//2)+(w%2)*(h//2))
need.append((h%2)*(w%2))
data = [0]*3
for i in a.values():
    j,k,l = f(i)
    data[0] += j
    data[1] += k
    data[2] += l
print(data,need)
if data[0] >= need[0]:
    data[1] += (data[0]-need[0])*2
    if data[1] == need[1] and data[2] == need[2]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def f(n):
    a,b,c = 0,0,0
    a = n//4
    r = n%4
    b = r//2
    c = r%2
    return (a,b,c)

h,w = map(int,input().split())
a = defaultdict(lambda:0)
for _ in range(h):
    for i in input():
        a[i] += 1
need = []
need.append((h//2)*(w//2))
need.append((h%2)*(w//2)+(w%2)*(h//2))
need.append((h%2)*(w%2))
data = [0]*3
for i in a.values():
    j,k,l = f(i)
    data[0] += j
    data[1] += k
    data[2] += l
if data[0] >= need[0]:
    data[1] += (data[0]-need[0])//2
    if data[1] == need[1] and data[2] == need[2]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
cnt=[0]*26
for i in range(h):
	a=input()
	for j in range(w):
		cnt[ord(a[j])-ord("a")]+=1
if h%2==1 and w%2==1:
	f=0
	for i in range(26):
		if cnt[i]%2==1:
			cnt[i]-=1
			break
	four=0
	for i in range(26):
		if cnt[i]>=4:
			four+=cnt[i]//4*4
		elif cnt[i]%2==1:
			f=-1
			break
	if four>=h*w-(h//2+w//2)*2-1 and f==0:
		f=1
	else:
		f=0
elif h%2==0 and w%2==0:
	f=1
	for i in range(26):
		if cnt[i]%4!=0:
			f=0
			break
else:
	if h%2==0:
		h,w=w,h
	four=0;f=0
	for i in range(26):
		if cnt[i]>=4:
			four+=cnt[i]//4*4
		elif cnt[i]%2==1:
			f=-1
			break
	if four>=h*w-w and f==0:
		f=1
	else:
		f=0
print("Yes" if f else "No")

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
cnt=[0]*26
for i in range(h):
	a=input()
	for j in range(w):
		cnt[ord(a[j])-ord("a")]+=1
if h%2==1 and w%2==1:
	f=0
	for i in range(26):
		if cnt[i]%2==1:
			cnt[i]-=1
			break
	four=0
	for i in range(26):
		if cnt[i]>=4:
			four+=cnt[i]//4*4
		elif cnt[i]%2==1:
			f=-1
			break
	if four>=h*w-(h//2+w//2)*2-1 and f==0:
		f=1
	else:
		f=0
elif h%2==0 and w%2==0:
	f=1
	for i in range(26):
		if cnt[i]%4!=0:
			f=0
			break
else:
	if h%2==0:
		h,w=w,h
	four=0;f=0
	for i in range(26):
		if cnt[i]>=4:
			four+=cnt[i]//4*4
	if four>=h*w-w:
		f=1
	else:
		f=0
print("Yes" if f else "No")

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
cnt=[0]*26
for i in range(h):
	a=input()
	for j in range(w):
		cnt[ord(a[j])-ord("a")]+=1
if h%2==1 and w%2==1:
	f=0
	for i in range(26):
		if cnt[i]%2==1:
			cnt[i]-=1
			break
	four=0
	for i in range(26):
		if cnt[i]>=4:
			four+=cnt[i]//4*4
		elif cnt[i]%2==1:
			f=-1
			break
	if four>=h*w-(h//2+w//2)*2-1 and f==0:
		f=1
	else:
		f=0
elif h%2==0 and w%2==0:
	f=1
	for i in range(26):
		if cnt[i]%4!=0:
			f=0
			break
else:
	if h%2==0:
		h,w=w,h
	four=0;f=0
	for i in range(26):
		if cnt[i]>=4:
			four+=cnt[i]//4*4
		elif cnt[i]%2==1:
			f=-1
			break
	if four>=h*w-w//2*2 and f==0:
		f=1
	else:
		f=0
print("Yes" if f else "No")

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
cnt=[0]*26
for i in range(h):
	a=input()
	for j in range(w):
		cnt[ord(a[j])-ord("a")]+=1
cnt.sort(reverse=True)
now=0
for i in range(h//2+w//2):
	if cnt[now]>=4:
		cnt[now]-=4
	else:
		now+=1
	if now==26:
		break
cnt.sort(reverse=True)
if h%2==1 and w%2==1:
	if cnt[:3] in ([2,2,1],[3,2,0],[1,0,0]):
		print("Yes")
	else:
		print("No")
elif h%2==0 and w%2==0:
	if cnt[0]==0:
		print("Yes")
	else:
		print("No")
else:
	if cnt[0]==cnt[1]==2 or cnt[0]==0:
		print("Yes")
	else:
		print("No")

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
cnt=[0]*26
for i in range(h):
	a=input()
	for j in range(w):
		cnt[ord(a[j])-ord("a")]+=1
cnt.sort(reverse=True)
now=0
for i in range(h//2+w//2):
	if cnt[now]>=4:
		cnt[now]-=4
	else:
		now+=1
	if now==26:
		break
cnt.sort(reverse=True)
if h%2==1 and w%2==1:
	if cnt[:3] in ([2,2,1],[4,1],[3,2],[1,0,0]):
		print("Yes")
	else:
		print("No")
elif h%2==0 and w%2==0:
	if cnt[0]==0:
		print("Yes")
	else:
		print("No")
else:
	if cnt[0]==cnt[1]==2 or cnt[0]==4:
		print("Yes")
	else:
		print("No")

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
cnt=[0]*26
for i in range(h):
	a=input()
	for j in range(w):
		cnt[ord(a[j])-ord("a")]+=1
cnt.sort(reverse=True)
now=0
for i in range(h//2+w//2):
	if cnt[now]>=4:
		cnt[now]-=4
	else:
		now+=1
	if now==26:
		break
cnt.sort(reverse=True)
if h%2==1 and w%2==1:
	if cnt[:3]==[2,2,1] or h==w==1:
		print("Yes")
	else:
		print("No")
elif h%2==0 and w%2==0:
	if cnt[0]==0:
		print("Yes")
	else:
		print("No")
else:
	if cnt[0]==cnt[1]==2:
		print("Yes")
	else:
		print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter
 
h, w = map(int, input().split())
a = Counter(''.join(input() for _ in range(h)))
 
center = h * w % 2 
side = (h//2) * (w%2) + (w//2) * (h%2)
corner = (h//2) * (w//2)

for _ in range(center):
    for i in a:
        if a[i] % 2 == 1:
            a[i] -= 1
            break
for _ in range(side):
    for j in a:
        if a[j] % 4 == 2:
            a[j] -= 2
            break
for _ in range(corner):
    for k in a:
        if a[k]!=0 and a[k] % 4 == 0:
            a[k] -= 4
            break
            
#print('Yes' if sum(a[i] for i in a) == 0 else 'No')
print("Yes" if all(list(map(lambda x:x==0,a.values()))) else "No")

Submission status: Wrong Answer

Solution code:
from collections import Counter
 
h, w = map(int, input().split())
a = Counter(''.join(input() for _ in range(h)))
 
center = h * w % 2 
side = (h//2) * (w%2) + (w//2) * (h%2)
corner = (h//2) * (w//2)

for _ in range(center):
    for i in a:
        if a[i] % 2 == 1:
            a[i] -= 1
            break
for _ in range(side):
    for j in a:
        if a[j] % 4 == 2:
            a[j] -= 2
            break
for _ in range(corner):
    for k in a:
        if a[k]!=0 and a[k] % 4 == 0:
            a[k] -= 4
            break
            
print('Yes' if sum(a[i] for i in a) == 0 else 'No')

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

H, W = map(int, readline().split())
A = [readline().decode().rstrip() for _ in range(H)]

dicts = defaultdict(int)
for a in A:
    for c in a:
        dicts[c] += 1

g1 = H * W % 2
g2 = (H // 2) * (W % 2) + (W // 2) * (H % 2)
g4 = (H // 2) * (W // 2)

for _ in range(g1):
    for k, v in dicts.items():
        if (v % 4 == 1) | (v % 4 == 3):
            dicts[k] -= 1

for _ in range(g2):
    for k, v in dicts.items():
        if v % 4 == 2:
            dicts[k] -= 2
"""for _ in range(g4):
    for k, v in dicts.items():
        if (v % 4 == 0) & (v != 0):
            dicts[k] -= 4
"""
for k, v in dicts.items():
    if v % 4 != 0:
        print('No')
        sys.exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

H, W = map(int, readline().split())
A = [readline().decode().rstrip() for _ in range(H)]

dicts = defaultdict(int)
for a in A:
    for c in a:
        dicts[c] += 1

g1 = H * W % 2
g2 = (H // 2) * (W % 2) + (W // 2) * (H % 2)
g4 = (H // 2) * (W // 2)

for i in range(g1):
    for k, v in dicts.items():
        if (v % 4 == 1) | (v % 4 == 3):
            dicts[k] -= 1

for i in range(g2):
    for k, v in dicts.items():
        if v % 4 == 2:
            dicts[k] -= 2

for i in range(g4):
    for k, v in dicts.items():
        if (v % 4 == 0) & (v != 0):
            dicts[k] -= 4

for k, v in dicts.items():
    if v != 0:
        print('No')
        sys.exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

H, W = map(int, readline().split())
A = [readline().decode().rstrip() for _ in range(H)]

dicts = defaultdict(int)
for a in A:
    for c in a:
        dicts[c] += 1
if H % 2 == W % 2 == 1:

    g1 = 1
    g2 = (H // 2) + (W // 2)
    g4 = (H // 2) * (W // 2)
else:
    H_ = H
    W_ = W
    if H % 2 == 0:
        H_ = H // 2 - 1
    if W % 2 == 0:
        W_ = W // 2 - 1

    g1 = 0
    g2 = H_ + W_
    g4 = H // 2 * W // 2

for i in range(g1):
    for k, v in dicts.items():
        if (v % 4 == 1) | (v % 4 == 3):
            dicts[k] -= 1

for i in range(g2):
    for k, v in dicts.items():
        if v % 4 == 2:
            dicts[k] -= 2

for i in range(g4):
    for k, v in dicts.items():
        if (v % 4 == 0) & (v != 0):
            dicts[k] -= 4

for k, v in dicts.items():
    if v != 0:
        print('No')
        sys.exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
cd = dict()
for _ in range(h):
    for s in input():
        cd.setdefault(s, 0)
        cd[s] += 1
if h%2 == 0 and w%2 == 0:
    # 両方偶数
    c1 = 0
    c2 = 0
    c4 = h*w//4
elif h%2 == 0 or w%2 == 0:
    # どちらか偶数
    c1 = 0
    c2 = w//2
    c4 = h*w -c2
else:
    # 両方奇数
    c1 = 1
    c2 = (h-1)//2 + (w-1)//2
    c4 = h*w - c1 - c2

ans = 'Yes'
for k, v in cd.items():
    v4, r4 = divmod(v, 4)
    v2, v1 = divmod(r4, 2)
    if c4 > 0:
        c4 -= v4
        if c4 < 0:
            c2 -= 2*c4
    c2 -= v2
    c1 -= v1
    if c2 < 0 or c1 < 0:
        ans = 'No'
        break
print(ans)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
cd = dict()
for _ in range(h):
    for s in input():
        cd.setdefault(s, 0)
        cd[s] += 1
if h%2 == 0 and w%2 == 0:
    # 両方偶数
    c1 = 0
    c2 = 0
    c4 = h*w//4
elif h%2 == 0 or w%2 == 0:
    # どちらか偶数
    c1 = 0
    c2 = w//2
    c4 = h*w -c2
else:
    # 両方奇数
    c1 = 1
    c2 = (h-1)//2 + (w-1)//2
    c4 = h*w - c1 - c2

ans = 'Yes'
for k, v in cd.items():
    v4, r4 = divmod(v, 4)
    v2, v1 = divmod(r4, 2)
    c4 -= v4
    c2 -= v2
    c1 -= v1
    if c4 < 0 or c2 < 0 or c1 < 0:
        ans = 'No'
        break
print(ans)

Submission status: Wrong Answer

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

ans = "Yes"
odd = 0
cnt = 0

for i in range(26):
    if alpha[i]%2 != 0:
        odd += 1
        alpha[i] -= 1
    if alpha[i]%4 != 0: cnt += 1
    
if odd > 1: ans = "No"
elif h%2 == 1 and w%2 == 1:
    if cnt > h//2+w//2: ans = "No"
elif h%2 == 1:
    if cnt > h//2: ans = "No"
elif w%2 == 1:
    if cnt > w//2: ans = "No"
else:
    if cnt > 0: ans = "No"
print(ans)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
A = [input() for _ in range(h)]

# hが奇数なら, 1個偶数 他奇数
# hが偶数なら, 全て偶数

# 横に見る
from collections import Counter
ans = True
if w%2 == 1:
    for i in range(h):
        ca = Counter(A[i])
        odd_cnt = 0
        for k, v in ca.items():
            if v%2 == 1:
                if odd_cnt == 1:
                    ans = False
                    break
                else:
                    odd_cnt += 1
        if not ans:
            break
else:
    for i in range(h):
        ca = Counter(A[i])
        for k, v in ca.items():
            if v%2 == 1:
                ans = False
                break
        if not ans:
            break

if not ans:
    print('No')
    exit(0)

# 縦に見る
if h%2 == 1:
    for j in range(w):
        d = dict()
        for i in range(h):
            a = A[i][j]
            d.setdefault(a, 0)
            d[a] += 1

        odd_cnt = 0
        for k, v in d.items():
            if v%2 == 1:
                if odd_cnt == 1:
                    ans = False
                    break
                else:
                    odd_cnt += 1
            if not ans:
                break
else:
    for j in range(w):
        d = dict()
        for i in range(h):
            a = A[i][j]
            d.setdefault(a, 0)
            d[a] += 1

        for k, v in d.items():
            if v%2 == 1:
                ans = False
                break
        if not ans:
            break

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

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
a = [input() for x in range(h)]
mp = {}
for i in range(h):
    for j in range(w):
        try:
            mp[a[i][j]] += 1
        except KeyError:
            mp[a[i][j]] = 1

if h % 2 == 1 and w % 2 == 1:
    isok = False
    for t in mp:
        if mp[t] % 4 == 1 or mp[t] % 4 == 3:
            mp[t] -= 1
            isok = True
            break
    if not isok:
        print('No')
        exit()

if h // 2 > 0 and w // 2 > 0:
    while h > 1:
        h -= 2
        while w > 1:
            w -= 2
            ok = False
            for t in mp:
                if mp[t] // 4 > 0:
                    mp[t] -= 4
                    ok = True
                    break
            if not ok:
                print('No')
                exit()

if h > 0 or w > 0:
    for t in mp:
        if mp[t] % 2 == 1:
            print('No')
            exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
a = [input() for x in range(h)]
mp = {}
for i in range(h):
    for j in range(w):
        try:
            mp[a[i][j]] += 1
        except KeyError:
            mp[a[i][j]] = 1
while h >= 2:
    h -= 2
    while w >= 2:
        w -= 2
        ok = False
        for t in mp:
            if mp[t] >= 4:
                mp[t] -= 4
                ok = True
                break
        if not ok:
            print('No')
            exit()
odd_cnt = 0
if h > 0 or w > 0:
    for t in mp:
        if mp[t] % 2 == 1:
            odd_cnt += 1
if odd_cnt > 1:
    print('No')
    exit()
else:
    print('Yes')
    exit()

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
a = [input(_) for _ in range(h)]
mp = {}
for i in range(h):
    for j in range(w):
        try:
            mp[a[i][j]] += 1
        except KeyError:
            mp[a[i][j]] = 1
while h >= 2:
    h -= 2
    while w >= 2:
        w -= 2
        ok = False
        for t in mp:
            if mp[t] >= 4:
                mp[t] -= 4
                ok = True
                break
        if not ok:
            print('No')
            exit()
odd_cnt = 0
if h > 0 or w > 0:
    for t in mp:
        if mp[t] % 2 == 1:
            odd_cnt += 1
if odd_cnt > 1:
    print('No')
    exit()
else:
    print('Yes')
    exit()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    H, W = map(int, input().split())
    a = ''
    for _ in range(H):
        s = input()
        a += s
    
    nums1 = 0
    nums2 = 0
    if (H&1)^(W&1):
        nums2 -= 1
    for l in Counter(a).values():
        if l % 2 == 1:
            nums1 += 1
        if l > 1 and l % 4 != 0:
            nums2 += 1

    if nums1 > H*W % 2 or nums2 > (H%2) * ((W-1)//2) + (W%2) * ((H-1)//2):
        print('No')
    else:
        print('Yes')

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    H, W = map(int, input().split())
    a = ''
    for _ in range(H):
        s = input()
        a += s
    
    nums1 = 0
    nums2 = 0
    for l in Counter(a).values():
        if l % 2 == 1:
            nums1 += 1
        if l == 2 or l == 3:
            nums2 += 1

    if nums1 > (H%2) * (W%2) or nums2 > (H%2) * ((W-1)//2) + (W%2) * ((H-1)//2):
        print('No')
    else:
        print('Yes')

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    H, W = map(int, input().split())
    a = ''
    for _ in range(H):
        s = input()
        a += s
    
    nums1 = 0
    nums2 = 0
    for l in list(Counter(a).values()):
        if l % 2 == 1:
            nums1 += 1
        if l == 2 or l == 3:
            nums2 += 1

    if nums1 > (H%2) * (W%2) or nums2 > (H%2) * (W-1)//2 + (W%2) * (H-1)//2:
        print('No')
    else:
        print('Yes')

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    H, W = map(int, input().split())
    a = ''
    for _ in range(H):
        s = input()
        a += s
    
    l = list(Counter(a).values())
    nums1 = l.count(1)# 1つしかない
    nums2 = l.count(2)# 2つしかない
    if nums1 > (H%2) * (W%2) or nums2 > (H%2) * (W-1)//2 + (W%2) * (H-1)//2:
        print('No')
    else:
        print('Yes')

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

h, w = map(int, input().split())
a = Counter(''.join(input() for _ in range(h)))

center = h * w % 2
side = (h // 2) * (w % 2) + (w // 2) * (h % 2)

cnt = 0
for i in a:
    if a[i] % 2 == 1:
        a[i] -= 1
        cnt += 1
if cnt != center:
    print('No')
    exit()

cnt = 0
for i in a:
    if a[i] % 4 == 2:
        a[i] -= 2
        cnt += 1
if cnt != side:
    print('No')
    exit()

print('Yes' if sum(a[i] % 4 for i in a) == 0 else 'No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

h, w = map(int, input().split())
a = Counter(''.join(input() for _ in range(h)))

center = h * w % 2
side = (h // 2) * (w % 2) + (w // 2) * (h % 2)

cnt = 0
for i in a:
    if a[i] % 2 == 1:
        a[i] -= 1
        cnt += 1
if cnt != center:
    print('No')
    exit()

print('Yes' if sum(a[i] % 4==2 for i in a) == side else 'No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

h, w = map(int, input().split())
a = Counter(''.join(input() for _ in range(h)))

center = h * w % 2
side = (h // 2) * (w % 2) + (w // 2) * (h % 2)

cnt = 0
for i in a:
    if cnt == center:
        break
    if a[i] % 2 == 1:
        a[i] -= 1
        cnt += 1

print('Yes' if sum(a[i] % 4 == 2 for i in a) == side else 'No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

h, w = map(int, input().split())
a = Counter(''.join(input() for _ in range(h)))

center = h * w % 2
side = (h // 2) * (w % 2) + (w // 2) * (h % 2)
corner = (h // 2) * (w // 2)

cnt = 0
for i in a:
    if a[i] % 2 == 1:
        a[i] -= 1
        cnt += 1
    if cnt == center:
        break

cnt = 0
for i in a:
    if a[i] % 4 == 2:
        a[i] -= 2
        cnt += 1
    if cnt == side:
        break

print('Yes' if sum(a[i] % 4 for i in a) == 0 else 'No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

h, w = map(int, input().split())
a = Counter(''.join(input() for _ in range(h)))

center = h * w % 2
side = (h // 2) * (w % 2) + (w // 2) * (h % 2)
corner = (h // 2) * (w // 2)

for i in range(center):
    for i in a:
        if a[i] % 2 == 1:
            a[i] -= 1
            break
for i in range(side):
    for i in a:
        if a[i] % 4 == 2:
            a[i] -= 2
            break
for i in range(corner):
    for i in a:
        if a[i] % 4 == 0 and a[i] > 0:
            a[i] -= 4
            break

print('Yes' if sum(a[i] for i in a) == 0 else 'No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

h, w = map(int, input().split())
a = Counter(input() for _ in range(h))

cnt_h = 0
for i in a:
    cnt_w = 0
    for j in range(26):
        cnt_w += i.count(chr(97 + j)) % 2
    cnt_h += a[i] % 2
    if cnt_w > 1:
        print('No')
        break
else:
    print('Yes') #if cnt_h < 2 else 'No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

h, w = map(int, input().split())
a = Counter(input() for _ in range(h))

cnt_h = 0
for i in a:
    cnt_w = 0
    for j in range(26):
        cnt_w += i.count(chr(97 + j)) % 2
    cnt_h += a[i] % 2
    if cnt_w > 1:
        print('No')
        break
else:
    print('Yes' if cnt_h < 2 else 'No')

Submission status: Wrong Answer

Solution code:
print('Yes')

Submission status: Wrong Answer

Solution code:
from collections import Counter

h, w = map(int, input().split())
a = Counter(input() for _ in range(h))

cnt_h = 0
for i in a:
    cnt_w = 0
    for j in range(26):
        cnt_w += i.count(chr(97 + j)) % 2
    cnt_h += a[i] % 2
    if cnt_h > 1 or cnt_w > 1:
        print('No')
        break
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    H, W = map(int, input().split())
    all_c = Counter([])
    for _ in range(H):
        line = list(input())
        line_c = Counter(line)
        all_c += line_c
    
    if H % 2 == 0 and W % 2 == 0:
        if all(val%4 == 0 for val in all_c.values()):
            print("Yes")
        else:
            print("No")

    elif H % 2 ^ W % 2:
        flag = all(val%2 == 0 for val in all_c.values())
        two_count = sum(val%4 == 2 for val in all_c.values())

        if H % 2 == 0:
            threshould = H//2
        else:
            threshould = W//2

        if flag and two_count <= threshould:
            print("Yes")
        else:
            print("No")

    elif H % 2 == 1 and W % 2 == 1:
        one2_count = sum(val%2 == 1 for val in all_c.values())
        
        one4_count = sum(val%4 == 1 and val > 1 for val in all_c.values())
        two_count = sum(val%4 == 2 for val in all_c.values())

        threshould = H//2 + W//2
        if one2_count == 1 and one4_count + two_count <= threshould:
            print("Yes")
        else:
            print("No")

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

h, w = (int(x) for x in input().split())
A = []
for _ in range(h):
    A += list(input())

B = [0, 0, 0]
if h % 2 == 0 and w % 2 == 0:
    B[2] += h * w
elif h % 2 == 0 and w % 2 == 1:
    B[2] += h * (w - 1)
    B[1] += h
elif h % 2 == 1 and w % 2 == 0:
    B[2] += w * (h - 1)
    B[1] += w
else:
    B[2] += (w - 1) * (h - 1)
    B[1] += w + h - 2
    B[0] += 1

for key, value in Counter(A).most_common():
    while value >= 1 and B[0] > 0:
        B[0] -= 1
        value -= 1
    while value >= 4 and B[2] > 0:
        B[2] -= 1
        value -= 4
    while value >= 2 and B[1] > 0:
        B[1] -= 1
        value -= 2

    if value != 0:
        print("No")
        exit()
else:
    print("Yes")
    exit()

Submission status: Wrong Answer

Solution code:
from collections import Counter

h, w = (int(x) for x in input().split())
A = []
for _ in range(h):
    A += list(input())

B = [0, 0, 0]
if h % 2 == 0 and w % 2 == 0:
    B[2] += h * w
elif h % 2 == 0 and w % 2 == 1:
    B[2] += h * (w - 1)
    B[1] += h
elif h % 2 == 1 and w % 2 == 0:
    B[2] += w * (h - 1)
    B[1] += w
else:
    B[2] += (w - 1) * (h - 1)
    B[1] += w + h - 2
    B[0] += 1

i = 0
for key, value in Counter(A).most_common():
    while value >= 4 and B[2] > 0:
        B[2] -= 1
        value -= 4
    while value >= 2 and B[1] > 0:
        B[1] -= 1
        value -= 2
    while value >= 1 and B[0] > 0:
        B[0] -= 1
        value -= 1
    if value != 0:
        print("No")
        exit()
else:
    print("Yes")
    exit()

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
a=[0]*h
book={}
for _ in range(h):
    a=input()
    for i in a:
        if i in book:
            book[i]+=1
        else:
            book[i]=1


if h%2==0 and w%2==0:
    for i in book:
        if book[i]%4!=0:
            print("No")
            exit()

elif h%2==1 and w%2==1:
    cnt=0
    odd=0
    for i in book:
        if book[i]%2==1:
            odd+=1
            if odd==2:
                print("No")
                exit()
        cnt+=book[i]//4
    if odd==0:
        print("No")
    else:
        if cnt>=(h-1)*(w-1)//4:
            print("Yes")
        else:
            print("No")
else:
    cnt=0
    for i in book:
        if book[i]%2==1:
            print("No")
            exit()
        cnt+=book[i]//4
    if h%2==1:
        if cnt>=(h-1)*w//4:
            print("Yes")
        else:
            print("No")
    else:
        if cnt>=(w-1)*h//4:
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = ""
cnt = [0] * 26
for _ in range(h):
    s = input()
    for i in range(len(s)):
        cnt[ord(s[i]) - ord("a")] += 1
#print(cnt)
c4=0
c2=0
c1=0
if h&1 == 1:
    c2 += w // 2
if w&1 == 1:
    c2 += h // 2
if (h&1 == 1) and (w&1 == 1):
    c1 = 1
c4 += (h//2) * (w//2)
#print(c1,c2,c4)

for i in range(26):
    while cnt[i] >= 4:
        cnt[i] -= 4
        c4 -= 1
for i in range(26):
    while cnt[i] % 4 == 2:
        cnt[i] -= 2
        c2 -= 1
for i in range(26):
    while cnt[i] % 4 == 1 or cnt[i] % 4 == 3:
        cnt[i] -= 1
        c1 -= 1

#print(c1,c2,c4)
if c1==0 and c2==0 and c4==0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = ""
cnt = [0] * 26
for _ in range(h):
    s = input()
    for i in range(len(s)):
        cnt[ord(s[i]) - ord("a")] += 1
c4=0
c2=0
c1=0
if h&1 == 1:
    c2 += w // 2
if w&1 == 1:
    c2 += h // 2
if (h&1 == 1) and (w&1 == 1):
    c1 = 1
c4 += (h//2) * (w//2)
#print(c1,c2,c4)

for i in range(26):
    while cnt[i] % 4 == 1 or cnt[i] % 4 == 3:
        cnt[i] -= 1
        c1 -= 1
for i in range(26):
    while cnt[i] %4 == 0 and cnt[i] > 0:
        cnt[i] -= 4
        c4 -= 1
for i in range(26):
    while cnt[i] % 4 == 2:
        cnt[i] -= 2
        c2 -= 1

if c1==0 and c2==0 and c4==0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = ""
cnt = [0] * 26
for _ in range(h):
    s = input()
    for i in range(len(s)):
        cnt[ord(s[i]) - ord("a")] += 1
c4=0
c2=0
c1=0
if h&1 == 1:
    c2 += w // 2
if w&1 == 1:
    c2 += h // 2
if (h&1 == 1) and (w&1 == 1):
    c1 = 1
c4 += (h//2) * (w//2)
#print(c1,c2,c4)

for i in range(26):
    while cnt[i] %4 == 0 and cnt[i] > 0:
        cnt[i] -= 4
        c4 -= 1
for i in range(26):
    while cnt[i] % 4 == 2:
        cnt[i] -= 2
        c2 -= 1
for i in range(26):
    while cnt[i] % 4 == 1 or cnt[i] % 4 == 3:
        cnt[i] -= 1
        c1 -= 1

if c1==0 and c2==0 and c4==0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = ""
cnt = [0] * 26
for _ in range(h):
    s = input()
    for i in range(len(s)):
        cnt[ord(s[i]) - ord("a")] += 1
c4=0
c2=0
c1=0
if h&1 == 1:
    c2 += w // 2
if w&1 == 1:
    c2 += h // 2
if (h&1 == 1) and (w&1 == 1):
    c1 = 1
c4 += (h//2) * (w//2)
#print(c1,c2,c4)

for i in range(26):
    while cnt[i] %4 == 0 and cnt[i] > 0:
        cnt[i] -= 4
        c4 -= 1
    while cnt[i] % 4 == 2:
        cnt[i] -= 2
        c2 -= 1
    while cnt[i] % 4 == 1 or cnt[i] % 4 == 3:
        cnt[i] -= 1
        c1 -= 1

if c1==0 and c2==0 and c4==0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = ""
cnt = [0] * 26
for _ in range(h):
    s += input().strip()

for i in range(len(s)):
    cnt[ord(s[i]) - ord("a")] += 1
c4=0
c2=0
c1=0
if h&1 == 1:
    c2 += w // 2
if w&1 == 1:
    c2 += h // 2
if (h&1 == 1) and (w&1 == 1):
    c1 = 1
c4 += (h//2) * (w//2)

for i in range(26):
    while cnt[i] %4 == 1 or cnt[i] %4 == 3:
        cnt[i] -= 1
        c1 -= 1
    while cnt[i] % 4 == 2:
        cnt[i] -= 2
        c2 -= 1
    while cnt[i] %4 == 0 and cnt[i] > 0:
        cnt[i] -= 4
        c4 -= 1

if c1==0 and c2==0 and c4==0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = ""
cnt = [0] * 26
for _ in range(h):
    s += input().strip()

for i in range(len(s)):
    cnt[ord(s[i]) - ord("a")] += 1
c4=0
c2=0
c1=0
if h&1 == 1:
    c2 += w // 2
if w&1 == 1:
    c2 += h // 2
if (h&1 == 1) and (w&1 == 1):
    c1 = 1
c4 += (h//2) * (w//2)

for i in range(26):
    while cnt[i] %4 == 1 or cnt[i] %4 == 3:
        cnt[i] -= 1
        c1 -= 1
    while cnt[i] % 4 == 2:
        cnt[i] -= 2
        c2 -= 1
    while cnt[i] >= 1:
        cnt[i] -= 4
        c4 -= 1

#print((c1,c2,c4))
if c1==0 and c2==0 and c4==0:
    print("Yes")
else:
    print("No")