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:
H,W = list(map(int,input().strip().split(' ')))
A=[str(input().strip()) for i in range(H)]

import collections
flg = 1
flg1 = 0
S = [[s for s in a] for a in A]
for s in S:
    c = collections.Counter(s)
    if len(c.keys()) != 1:
        for i in c.values():
            if i % 2 != 0:
                flg1 = flg1 + 1
                if W % 2 == 0 and flg1 >= 1:
                    flg = 0
                    break
                elif W % 2 != 0 and flg1 >= 2:
                    flg = 0
                    break

flg2 = 0
if flg == 1:    
    S_t = [list(x) for x in zip(*S)]
    for s in S_t:
        c = collections.Counter(s)
        if len(c.keys()) != 1:
            for i in c.values():
                if i % 2 != 0:
                    flg2 = flg2 + 1
                    if H % 2 == 0 and flg2 >= 1:
                        flg = 0
                        break
                    elif H % 2 != 0 and flg2 >= 2:
                        print("wow!")
                        flg = 0
                        break

if flg == 1:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
H,W = list(map(int,input().strip().split(' ')))
A=[str(input().strip()) for i in range(H)]

import collections
flg = 1
flg1 = 0
S = [[s for s in a] for a in A]
for s in S:
    c = collections.Counter(s)
    if len(c.keys()) != 1:
        for i in c.values():
            if i % 2 != 0:
                flg1 = flg1 + 1
                if W % 2 == 0 and flg1 >= 1:
                    flg = 0
                    break
                elif W % 2 != 0 and flg1 >= 2:
                    flg = 0
                    break

if flg == 1:    
    S_t = [list(x) for x in zip(*S)]
    for s in S_t:
        c = collections.Counter(s)
        if len(c.keys()) != 1:
            for i in c.values():
                if i % 2 != 0:
                    flg1 = flg1 + 1
                    if H % 2 == 0 and flg1 >= 1:
                        flg = 0
                        break
                    elif H % 2 != 0 and flg1 >= 2:
                        flg = 0
                        break

if flg == 1:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
H,W = list(map(int,input().strip().split(' ')))
A=[str(input().strip()) for i in range(H)]

import collections
flg = 1
flg1 = 0
S = [[s for s in a] for a in A]
for s in S:
    c = collections.Counter(s)
    for i in c.values():
        if i % 2 != 0 and len(c.keys()) != 1:
            flg1 = flg1 + 1
            if W % 2 == 0 and flg1 >= 1:
                flg = 0
                break
            elif W % 2 != 0 and flg1 >= 2:
                flg = 0
                break

if flg == 1:    
    S_t = [list(x) for x in zip(*S)]
    for s in S_t:
        c = collections.Counter(s)
        for i in c.values():
            if i % 2 != 0 and len(c.keys()) != 1:
                flg1 = flg1 + 1
                if H % 2 == 0 and flg1 >= 1:
                    flg = 0
                    break
                elif H % 2 != 0 and flg1 >= 2:
                    flg = 0
                    break

if flg == 1:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
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

print(cnt)
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")

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
A = []
for i in range(H):
    A.extend(list(input()))
A.sort()
a = [0, 0, 0]
if H % 2 != 0 and W % 2 != 0:
    a[0] = 1
    a[1] = int(H / 2) + int(W / 2)
    a[2] = int((H * W - a[0] - a[1]) / 4)
elif H % 2 != 0:
    a[0] = 0
    a[1] = int(W / 2)
    a[2] = int((H * W - a[0] - a[1]) / 4)
elif W % 2 != 0:
    a[0] = 0
    a[1] = int(H / 2)
    a[2] = int((H * W - a[0] - a[1]) / 4)
else:
    a[0] = 0
    a[1] = 0
    a[2] = int(H * W / 4)
c = 1
cnt = [0, 0, 0]
for i in range(1, H * W):
    if A[i] == A[i - 1]:
        c += 1
    else:
        if c == 1:
            cnt[0] += 1
        elif c == 2:
            cnt[1] += 1
        elif c == 3:
            cnt[0] += 1
            cnt[1] += 1
        elif c == 4:
            cnt[2] += 1
        elif c > 4:
            cnt[2] += int(c / 4)
            c %= 4
            if c == 3:
                cnt[0] += 1
                cnt[1] += 1
            if c == 2:
                cnt[1] += 1
            if c == 1:
                cnt[0] += 1
        c = 1
        
if c == 1:
    cnt[0] += 1
elif c == 2:
    cnt[1] += 1
elif c == 3:
    cnt[0] += 1
    cnt[1] += 1
elif c == 4:
    cnt[2] += 1
elif c > 4:
    cnt[2] += int(c / 4)
    c %= 4
    if c == 3:
        cnt[0] += 1
        cnt[1] += 1
    if c == 2:
        cnt[1] += 1
    if c == 1:
        cnt[0] += 1

ans = 1
if a[2] > cnt[2]:
    ans = -1
cnt[2] -= a[2]
cnt[1] += cnt[2] * 2
if a[1] > cnt[1]:
    ans = -1
cnt[1] -= a[1]
cnt[0] += cnt[1] * 2
if cnt[0] != a[0]:
    ans = -1
if ans == 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
A = []
for i in range(H):
    A.extend(list(input()))
A.sort()
a = [0, 0, 0]
if H % 2 != 0 and W % 2 != 0:
    a[0] = 1
    a[1] = int(H / 2) + int(W / 2)
    a[2] = int((H * W - a[0] - a[1]) / 4)
elif H % 2 != 0:
    a[0] = 0
    a[1] = int(W / 2)
    a[2] = int((H * W - a[0] - a[1]) / 4)
elif W % 2 != 0:
    a[0] = 0
    a[1] = int(H / 2)
    a[2] = int((H * W - a[0] - a[1]) / 4)
else:
    a[0] = 0
    a[1] = 0
    a[2] = int(H * W / 4)
c = 1
cnt = [0, 0, 0]
for i in range(1, H * W):
    if A[i] == A[i - 1]:
        c += 1
    else:
        if c == 1:
            cnt[0] += 1
        elif c == 2:
            cnt[1] += 1
        elif c == 3:
            cnt[0] += 1
            cnt[1] += 1
        elif c == 4:
            cnt[2] += 1
        elif c > 4:
            cnt[2] += int(c / 4)
            c %= 4
            if c == 3:
                cnt[0] += 1
                cnt[1] += 1
            if c == 2:
                cnt[1] += 1
        c = 1
        
if c == 1:
    cnt[0] += 1
elif c == 2:
    cnt[1] += 1
elif c == 3:
    cnt[0] += 1
    cnt[1] += 1
elif c == 4:
    cnt[2] += 1
elif c > 4:
    cnt[2] += int(c / 4)
    c %= 4
    if c == 3:
        cnt[0] += 1
        cnt[1] += 1
    if c == 2:
        cnt[1] += 1

ans = 1

if a[2] > cnt[2]:
    ans = -1
cnt[2] -= a[2]
cnt[1] += cnt[2] * 2
if a[1] > cnt[1]:
    ans = -1
cnt[1] -= a[1]
cnt[0] += cnt[1] * 2
if cnt[0] != a[0]:
    ans = -1

if ans == 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
A = []
for i in range(H):
    A.extend(list(input()))
A.sort()
a = [0, 0, 0]
if H % 2 != 0 and W % 2 != 0:
    a[0] = 1
    a[1] = int(H / 2) + int(W / 2)
    a[2] = int((H * W - a[0] - a[1]) / 4)
elif H % 2 != 0:
    a[0] = 0
    a[1] = int(W / 2)
    a[2] = int((H * W - a[0] - a[1]) / 4)
elif W % 2 != 0:
    a[0] = 0
    a[1] = int(H / 2)
    a[2] = int((H * W - a[0] - a[1]) / 4)
else:
    a[0] = 0
    a[1] = 0
    a[2] = int(H * W / 4)
c = 1
cnt = [0, 0, 0]
for i in range(1, H * W):
    if A[i] == A[i - 1]:
        c += 1
    else:
        if c == 1:
            cnt[0] += 1
        elif c == 2:
            cnt[1] += 1
        elif c == 3:
            cnt[0] += 1
            cnt[1] += 1
        elif c == 4:
            cnt[2] += 1
        elif c > 4:
            cnt[2] += int(c / 4)
            c %= 4
            if c == 3:
                cnt[0] += 1
                cnt[1] += 1
            if c == 2:
                cnt[1] += 1
        c = 1
        
if c == 1:
    cnt[0] += 1
elif c == 2:
    cnt[1] += 1
elif c == 3:
    cnt[0] += 1
    cnt[1] += 1
elif c == 4:
    cnt[2] += 1
elif c > 4:
    cnt[2] += int(c / 4)
    c %= 4
    if c == 3:
        cnt[0] += 1
        cnt[1] += 1
    if c == 2:
        cnt[1] += 1

if a == cnt:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
A = []
for i in range(H):
    A.extend(list(input()))
A.sort()
print(A)
a = [0, 0, 0]
if H % 2 != 0 and W % 2 != 0:
    a[0] = 1
    a[1] = int(H / 2) + int(W / 2)
    a[2] = int((H * W - a[0] - a[1]) / 4)
elif H % 2 != 0:
    a[0] = 0
    a[1] = int(W / 2)
    a[2] = int((H * W - a[0] - a[1]) / 4)
elif W % 2 != 0:
    a[0] = 0
    a[1] = int(H / 2)
    a[2] = int((H * W - a[0] - a[1]) / 4)
else:
    a[0] = 0
    a[1] = 0
    a[2] = int(H * W / 4)
c = 1
cnt = [0, 0, 0]
for i in range(1, H * W):
    if A[i] == A[i - 1]:
        c += 1
    else:
        if c == 1:
            cnt[0] += 1
        elif c == 2:
            cnt[1] += 1
        elif c == 3:
            cnt[0] += 1
            cnt[1] += 1
        elif c == 4:
            cnt[2] += 1
        elif c > 4:
            cnt[2] += int(c / 4)
            c %= 4
            if c == 3:
                cnt[0] += 1
                cnt[1] += 1
            if c == 2:
                cnt[1] += 1
        c = 1
        
if c == 1:
    cnt[0] += 1
elif c == 2:
    cnt[1] += 1
elif c == 3:
    cnt[0] += 1
    cnt[1] += 1
elif c == 4:
    cnt[2] += 1
elif c > 4:
    cnt[2] += int(c / 4)
    c %= 4
    if c == 3:
        cnt[0] += 1
        cnt[1] += 1
    if c == 2:
        cnt[1] += 1

if a == cnt:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
h,w = map(int, sys.stdin.readline().split())
a = [[[c] for c in l.strip()] for l in sys.stdin]
from itertools import chain
a = list(chain.from_iterable(a))
a = list(chain.from_iterable(a))
import collections
c = collections.Counter(a)
counts,values = zip(*c.most_common())
if (h %2 == 0 and w %2 == 0):
    for i in values:
        if i %4 != 0:
            print("No")
            break
    else:
        print("Yes")
elif (h%2 == 1 and w %2 == 1):
    yu = (w-1 + h-1)/2
    iko = 1
    for i in values:
        if i %4 == 0:
            continue
        elif i %2 == 0:
            yu -= 1
            if yu < 0:
                print("No")
                break
        elif i %4 == 1:
            iko -= 1
            if iko < 0:
                print('No')
                break
        else:
            iko-= 1
            yu-=1
            if iko < 0:
                print('No')
                break
            if yu < 0:
                print("No")
                break
    else:
        print('Yes')
else:
    if h %2 == 0:
      yu = h/2
    else:
      yu = w/2
    for i in values:
        if i %4 == 0:
            continue
        elif i %2 == 0:
            yu -= 1
            if yu < 0:
                print("No")
                break
    else:
        print('Yes')

Submission status: Wrong Answer

Solution code:
def main():
    h, w = map(int, input().split())
    a = []
    for i in range(h):
        a.append(input())

    cnt_dict = {}
    for i in range(h):
        for j in range(w):
            cnt_dict[a[i][j]] = cnt_dict.get(a[i][j], 0) + 1

    cnt_odd, cnt_even, cnt_f, max_odd = 0, 0, 0, 0
    for i in cnt_dict:
        if cnt_dict[i] % 4 == 0:
            cnt_f += 1
        if cnt_dict[i] % 2 == 0:
            cnt_even += 1
        else:
            cnt_odd += 1
            max_odd = max(max_odd, cnt_dict[i])

    if h % 2 == 0 and w % 2 == 0:
        if cnt_odd == 0 and cnt_even == cnt_f:
            print("Yes")
        else:
            print("No")
    elif h % 2 and w % 2:
        if cnt_odd == 1 and cnt_even - cnt_f <= h // 2 + w // 2 - max_odd // 2:
            print("Yes")
        else:
            print("No")
    else:
        if h % 2 == 0:
            u = h
        else:
            u = w
        if cnt_odd == 0 and cnt_even - cnt_f <= u // 2:
            print("Yes")
        else:
            print("No")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    h, w = map(int, input().split())
    a = []
    for i in range(h):
        a.append(input())

    cnt_dict = {}
    for i in range(h):
        for j in range(w):
            cnt_dict[a[i][j]] = cnt_dict.get(a[i][j], 0) + 1

    cnt_odd, cnt_even, cnt_f, max_odd = 0, 0, 0, 0
    for i in cnt_dict:
        if cnt_dict[i] % 4 == 0:
            cnt_f += 1
        if cnt_dict[i] % 2 == 0:
            cnt_even += 1
        else:
            cnt_odd += 1
            max_odd = max(max_odd, cnt_dict[i])

    if h % 2 == 0 and w % 2 == 0:
        if cnt_odd == 0 and cnt_even == cnt_f:
            print("Yes")
        else:
            print("No")
    elif h % 2 and w % 2:
        if cnt_odd == 1 and cnt_even - cnt_f <= h // 2 + w // 2 - max_odd // 2:
            print("Yes")
        else:
            print("No")
    else:
        if cnt_odd == 0 and cnt_even - cnt_f <= 2:
            print("Yes")
        else:
            print("No")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    h, w = map(int, input().split())
    a = []
    for i in range(h):
        a.append(input())

    cnt_dict = {}
    for i in range(h):
        for j in range(w):
            cnt_dict[a[i][j]] = cnt_dict.get(a[i][j], 0) + 1

    cnt_odd, cnt_even, cnt_f = 0, 0, 0
    for i in cnt_dict:
        if cnt_dict[i] % 4 == 0:
            cnt_f += 1
        if cnt_dict[i] % 2 == 0:
            cnt_even += 1
        else:
            cnt_odd += 1

    if h % 2 == 0 and w % 2 == 0:
        if cnt_odd == 0 and cnt_even - cnt_f == 0:
            print("Yes")
        else:
            print("No")
    elif h % 2 and w % 2:
        if cnt_odd == 1 and cnt_even - cnt_f <= 2:
            print("Yes")
        else:
            print("No")
    else:
        if cnt_odd == 0 and cnt_even - cnt_f <= 2:
            print("Yes")
        else:
            print("No")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
H, W = map(int, input().split())
S = []
for h in range(H):
    tmp = list(input())
    for w in tmp:
        S.append(w)

S = Counter(S)
square = (H // 2) * (W // 2)
line = (H // 2) * (W % 2 == 1) + (W // 2) * (H % 2 == 1)

if H % 2 == 1 and W % 2 == 1:
    for key, value in S.items():
        if value % 2 == 1:
            S[key] -= 1
            break

for key, value in S.items():
    if value >= 4:
        while value >= 4:
            square -= 1
            value -= 4
            S[key] -= 4

for key, value in S.items():
    if value >= 2:
        while value >= 2:
            line -= 1
            value -= 2
            S[key] -= 2

print("Yes" if square == 0 and line == 0 else "No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

# count = {}
count_all = len(a)
count_4 = 0
count_2 = 0
count_1 = 0

for s in "abcdefghijklmnopqrstuvwxyz":
    # count[s] = a.count(s)
    c = a.count(s)
    count_4 += c//4
    c = c%4
    count_2 += c//2
    c = c%2
    count_1 += c

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

if W%2 == 0 and H%2 == 0:
    if count_4 < W*H//4:
        print("No")
    else:
        print("Yes")
elif W%2 == 0 and H%2 == 1:
    if count_4 < W*(H-1)//4:
        print(count_4, W*(H-1)//4)
        print("No")
    elif 2*(count_4 - W*(H-1)//4) + count_2 < W//2:
        print("No")
    else:
        print("Yes")
else:
    if count_4 < (W-1)*(H-1)//4:
        print("No")
    elif 2*(count_4 - (W-1)*(H-1)//4) + count_2 < (W+H-2)//2:
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

# count = {}
count_all = len(a)
count_4 = 0
count_2 = 0
count_1 = 0

for s in "abcdefghijklmnopqrstuvwxyz":
    # count[s] = a.count(s)
    c = a.count(s)
    count_4 += c//4
    c = c%4
    count_2 += c//2
    c = c%2
    count_1 += c

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

if W%2 == 0 and H%2 == 0:
    if count_4 == count_all:
        print("Yes")
    else:
        print("No")
elif W%2 == 0 and H%2 == 1:
    if count_4 < W*(H-1)//4:
        print(count_4, W*(H-1)//4)
        print("No")
    elif 2*(count_4 - W*(H-1)//4) + count_2 < W//2:
        print("No")
    else:
        print("Yes")
else:
    if count_4 < (W-1)*(H-1)//4:
        print("No")
    elif 2*(count_4 - (W-1)*(H-1)//4) + count_2 < (W+H-2)//2:
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
from collections import Counter
h,w = (int(i) for i in input().split())
a = [input() for i in range(h)]
s,num,f = "",0,[0,0,0,0]
for i in a: s+=i
c = Counter(s).most_common()
for i in c: f[i[1]%4]+=1
if h==1 or w==1:
	if f[1]+f[3]==len(s)%2: print("Yes")
	else: print("No")
elif h%2==w%2==0:
	if f[0]==len(s): print("Yes")
	else: print("No")
elif h%2==w%2==1:
	x = (h+w-2)//2
	if f[1]+f[3]!=1: print("No")
	elif f[1]==1:
		if f[2]>x or f[2]%2!=x%2: print("No")
		else: print("Yes")
	else:
		if f[2]+1>x or (f[2]+1)%2!=x%2: print("No")
		else: print("No")
else:
	if h%2==0: h,w=w,h
	x = w//2
	if f[1]+f[3]!=0: print("No")
	elif f[2]>x or f[2]%2!=x%2: print("No")
	else: print("Yes")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import random

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

A = []
for i in range(H):
    for c in list(input()):
        A.append(c)

dict = {}
for a in A:
    if a in dict:
        dict[a] += 1
    else:
        dict[a] = 1


if H % 2 == 1 and W % 2 == 1:
    g1 = 1
    g2 = int(H/2) + int(W/2)
    g3 = int(H/2) * int(W/2)
else:
    g1 = 0
    if H % 2 == 0 and W % 2 == 0:
        g2 = 0
    else:
        if H % 2 == 0:
            g2 = int(H/2)
        else:
            g2 = int(W/2)
    g3 = int((H * W - g2 * 2) / 4)

for _ in range(g1):
    stack = []
    for c in dict:
        if dict[c] % 2 == 1:
            stack.append(c)
    if len(stack) > 1:
        x = stack.pop(random.randint(0, len(stack)-1))
        dict[x] -= 1
    elif len(stack) == 1:
        dict[stack[0]] -= 1
    else:
        pass


for _ in range(g2):
    stack = []
    for c in dict:
        if dict[c] % 4 == 2:
            stack.append(c)
    if len(stack) > 1:
        x = stack.pop(random.randint(0, len(stack)-1))
        dict[x] -= 2
    elif len(stack) == 1:
        dict[stack[0]] -= 2
    else:
        pass


for _ in range(g3):
    stack = []
    for c in dict:
        if dict[c] % 4 == 0 and dict[c] != 0:
            stack.append(c)
    if len(stack) > 1:
        x = stack.pop(random.randint(0, len(stack)-1))
        dict[x] -= 4
    elif len(stack) == 1:
        dict[stack[0]] -= 4
    else:
        pass

count = 0
for c in dict:
    if dict[c] != 0:
        count += 1
if count == 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

char_to_cnt = Counter()
for h in range(H):
    for w in range(W):
        char_to_cnt.update(A[h][w])

if H % 2 != 0 and W % 2 != 0:
    g1 = 1
    g2 = H // 2 + W // 2
    g4 = (H // 2) * (W // 2)
else:
    g1 = 0
    if H % 2 == 0 and W % 2 == 0:
        g2 = 0
    else:
        if H % 2 == 0:
            g2 = H // 2
        else:
            g2 = W // 2
    g4 = (H * W - g1 - g2 * 2) // 4

for _ in range(g1):
    for char in char_to_cnt.keys():
        cnt = char_to_cnt[char]
        if cnt % 4 == 1 or cnt % 4 == 3:
            char_to_cnt[char] -= 1
            break

for _ in range(g2):
    for char in char_to_cnt.keys():
        cnt = char_to_cnt[char]
        if cnt % 4 == 2:
            char_to_cnt[char] -= 2
            break

for _ in range(g4):
    for char in char_to_cnt.keys():
        cnt = char_to_cnt[char]
        if cnt != 0 and cnt % 4 == 0:
            char_to_cnt[char] -= 4
            break

for _, cnt in char_to_cnt.items():
    if cnt != 0:
        print("No")
        exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

char_to_cnt = Counter()
for h in range(H):
    for w in range(W):
        char_to_cnt.update(A[h][w])

if H % 2 != 0 and W % 2 != 0:
    g1 = 1
    g2 = H // 2 + W // 2
    g4 = (H // 2) * (W // 2)
else:
    g1 = 0
    if H % 2 == 0 and W % 2 == 0:
        g2 = 0
    else:
        if H % 2 == 0:
            g2 = H // 2
        else:
            g2 = W // 2
    g4 = (H * W - g1 - g2 * 2) // 4

for _ in range(g1):
    flg = False
    for char in char_to_cnt.keys():
        cnt = char_to_cnt[char]
        if cnt % 4 == 1 or cnt % 4 == 3:
            char_to_cnt[char] -= 1
            flg = True
            break

    if not flg:
        print("No")
        exit()

for _ in range(g2):
    flg = False
    for char in char_to_cnt.keys():
        cnt = char_to_cnt[char]
        if cnt % 4 == 2:
            char_to_cnt[char] -= 2
            flg = True
            break

    if not flg:
        print("No")
        exit()

for _ in range(g4):
    flg = False
    for char in char_to_cnt.keys():
        cnt = char_to_cnt[char]
        if cnt != 0 and cnt % 4 == 0:
            char_to_cnt[char] -= 4
            flg = True
            break

    if not flg:
        print("No")
        exit()

for _, cnt in char_to_cnt.items():
    if cnt != 0:
        print("No")
        exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

char_to_cnt = Counter()
for h in range(H):
    for w in range(W):
        char_to_cnt.update(A[h][w])

if H % 2 != 0 and W % 2 != 0:
    g1 = 1
    g2 = H // 2 + W // 2
    g4 = (H // 2) * (W // 2)
else:
    g1 = 0
    if H % 2 == 0 and W % 2 == 0:
        g2 = 0
    else:
        g2 = 2
    g4 = (H * W - g1 - g2 * 2) // 4

for _ in range(g1):
    flg = False
    for char in char_to_cnt.keys():
        cnt = char_to_cnt[char]
        if cnt % 4 == 1 or cnt % 4 == 3:
            char_to_cnt[char] -= 1
            flg = True
            break

    if not flg:
        print("No")
        exit()

for _ in range(g2):
    flg = False
    for char in char_to_cnt.keys():
        cnt = char_to_cnt[char]
        if cnt % 4 == 2:
            char_to_cnt[char] -= 2
            flg = True
            break

    if not flg:
        print("No")
        exit()

for _ in range(g4):
    flg = False
    for char in char_to_cnt.keys():
        cnt = char_to_cnt[char]
        if cnt != 0 and cnt % 4 == 0:
            char_to_cnt[char] -= 4
            flg = True
            break

    if not flg:
        print("No")
        exit()

for _, cnt in char_to_cnt.items():
    if cnt != 0:
        print("No")
        exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

char_to_cnt = Counter()
for h in range(H):
    for w in range(W):
        char_to_cnt.update(A[h][w])

if H % 2 != 0 and W % 2 != 0:
    g1 = 1
    g2 = H // 2 + W // 2
    g4 = (H // 2) * (W // 2)
else:
    g1 = 0
    if H % 2 == 0 and W % 2 == 0:
        g2 = 0
    else:
        g2 = 2
    g4 = (H * W - g1 - g2 * 2) // 4

for _ in range(g1):
    flg = False
    for char in char_to_cnt.keys():
        cnt = char_to_cnt[char]
        if cnt % 4 == 1 or cnt % 4 == 3:
            char_to_cnt[char] -= 1
            flg = True
            break

    if not flg:
        print("No")
        exit()

for _ in range(g2):
    flg = False
    for char in char_to_cnt.keys():
        cnt = char_to_cnt[char]
        if cnt % 4 == 2:
            char_to_cnt[char] -= 2
            flg = True
            break

    if not flg:
        print("No")
        exit()

for _ in range(g4):
    flg = False
    for char in char_to_cnt.keys():
        cnt = char_to_cnt[char]
        if cnt != 0 and cnt % 4 == 0:
            char_to_cnt[char] -= 4
            flg = True
            break

    if not flg:
        print("No")
        exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
# coding: utf-8
h,w=map(int,input().split())
dic={}
for i in range(h):
    for c in input():
        if c in dic:
            dic[c]=(dic[c]+1)%4
        else:
            dic[c]=1
d=list(dic.values())
if h%2 and w%2:
    if d.count(1)+d.count(3)==1 and d.count(2)<=h//2+w//2:
        print('Yes')
    else:
        print('No')
elif (h%2 and not w%2) or (w%2 and not h%2):
    if not (d.count(1)+d.count(3)>0):
        if h%2:
            if d.count(2)<=w//2 :#and d.count(2)%2==(w//2)%2:
                print('Yes')
        elif w%2:
            if d.count(2)<=h//2 :#and d.count(2)%2==(h//2)%2:
                print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    if sum(d)==0:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
# coding: utf-8
h,w=map(int,input().split())
dic={}
for i in range(h):
    for c in input():
        if c in dic:
            dic[c]=(dic[c]+1)%4
        else:
            dic[c]=1
d=list(dic.values())
if h%2 and w%2:
    if d.count(1)+d.count(3)==1 and d.count(2)<=h//2+w//2:
        print('Yes')
    else:
        print('No')
elif (h%2 and not w%2) or (w%2 and not h%2):
    if not (d.count(1)+d.count(3)>0):
        if h%2:
            if d.count(2)<=w//2 :#and d.count(2)%2==(w//2)%2:
                print('Yes')
        elif w%2:
            if d.count(2)<=h//2 :#and d.count(2)%2==(h//2)%2:
                print('Yes')
    else:
        print('No')
else:
    if sum(d)==0:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
# coding: utf-8
h,w=map(int,input().split())
dic={}
for i in range(h):
    for c in input():
        if c in dic:
            dic[c]=(dic[c]+1)%4
        else:
            dic[c]=1
d=list(dic.values())
if h%2 and w%2:
    if d.count(1)+d.count(3)==1 and d.count(2)<=h//2+w//2:
        print('Yes')
    else:
        print('No')
elif (h%2 and not w%2) or (w%2 and not h%2):
    if not (d.count(1)+d.count(3)>0):
        if h%2:
            if d.count(2)<=w//2 and d.count(2)%2==(w//2)%2:
                print('Yes')
        elif w%2:
            if d.count(2)<=h//2 and d.count(2)%2==(h//2)%2:
                print('Yes')
    else:
        print('No')
else:
    if sum(d)==0:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
# coding: utf-8
h,w=map(int,input().split())
dic={}
for i in range(h):
    for c in input():
        if c in dic:
            dic[c]=(dic[c]+1)%4
        else:
            dic[c]=1
d=list(dic.values())
if h%2 and w%2:
    if d.count(1)+d.count(3)==1 and d.count(2)<=h//2+w//2 and (h//2+w//2)%2!=d.count(2)%2:
        print('Yes')
    else:
        print('No')
elif (h%2 and not w%2) or (w%2 and not h%2):
    if not (d.count(1)+d.count(3)>0):
        if h%2:
            if d.count(2)<=w//2 and d.count(2)%2==(w//2)%2:
                print('Yes')
        elif w%2:
            if d.count(2)<=h//2 and d.count(2)%2==(h//2)%2:
                print('Yes')
    else:
        print('No')
else:
    if sum(d)==0:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
# coding: utf-8
h,w=map(int,input().split())
dic={}
for i in range(h):
    for c in input():
        if c in dic:
            dic[c]=(dic[c]+1)%4
        else:
            dic[c]=1
d=list(dic.values())
if h%2 and w%2:
    if d.count(1)+d.count(3)==1 and (h//2+w//2)%2<=d.count(2)<=h//2+w//2 and (h//2+w//2)%2==d.count(2)%2:
        print('Yes')
    else:
        print('No')
elif (h%2 and not w%2) or (w%2 and not h%2):
    if not (d.count(1)+d.count(3)>0):
        if h%2:
            if d.count(2)<=w//2 and d.count(2)%2==(w//2)%2:
                print('Yes')
        elif w%2:
            if d.count(2)<=h//2 and d.count(2)%2==(h//2)%2:
                print('Yes')
    else:
        print('No')
else:
    if sum(d)==0:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
# coding: utf-8
h,w=map(int,input().split())
dic={}
for i in range(h):
    for c in input():
        if c in dic:
            dic[c]=(dic[c]+1)%4
        else:
            dic[c]=1
d=list(dic.values())
if h%2 and w%2:
    if d.count(1)+d.count(3)==1 and d.count(2)<=h//2+w//2 and (h//2+w//2)%2==d.count(2)%2:
        print('Yes')
    else:
        print('No')
elif (h%2 and not w%2) or (w%2 and not h%2):
    if not (d.count(1)+d.count(3)>0):
        if h%2:
            if d.count(2)<=w//2 and d.count(2)%2==(w//2)%2:
                print('Yes')
        elif w%2:
            if d.count(2)<=h//2 and d.count(2)%2==(h//2)%2:
                print('Yes')
    else:
        print('No')
else:
    if sum(d)==0:
        print('Yes')
    else:
        print('No')