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=map(int,input().split())
s=[list(input()) for _ in range(H)]
D={}

for h in range(H):
    for w in range(W):
        if s[h][w] in D:
            D[s[h][w]]+=1
        else:
            D[s[h][w]]=1

odd=0
semi=0
for d in D:
    if D[d]%4==1:
        odd+=1
    elif D[d]%4==2:
        semi+=1
    elif D[d]%4==3:
        odd+=1
        semi+=1

if H%2==0 and W%2==0:
    if odd==semi==0:
        print("Yes")
    else:
        print("No")
elif H%2==1 and W%2==1:
    if odd>1 or semi>(H-1)+(W-1):
        print("No")
    else:
        print("Yes")
else:
    if H%2==1:
        if odd>0 or semi>W-1:
            print("No")
        else:
            print("Yes")
    else:
        if odd>0 or semi>H-1:
            print("No")
        else:
            print("Yes")

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
s=[list(input()) for _ in range(H)]
D={}

for h in range(H):
    for w in range(W):
        if s[h][w] in D:
            D[s[h][w]]+=1
        else:
            D[s[h][w]]=1

odd=0
semi=0
for d in D:
    if D[d]%4==1:
        odd+=1
    elif D[d]%4==2:
        semi+=1
    elif D[d]%4==3:
        odd+=1
        semi+=1

if H%2==0 and W%2==0:
    if odd==semi==0:
        print("Yes")
    else:
        print("No")
elif H%2==1 and W%2==1:
    if odd>1 or semi>(H-1)+(W-1):
        print("No")
    else:
        print("Yes")
else:
    if H%2==1:
        if odd>1 or semi>W-1:
            print("No")
        else:
            print("Yes")
    else:
        if odd>0 or semi>H-1:
            print("No")
        else:
            print("Yes")

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
s=[list(input()) for _ in range(H)]
D={}

for h in range(H):
    for w in range(W):
        if s[h][w] in D:
            D[s[h][w]]+=1
        else:
            D[s[h][w]]=1

odd=0
semi=0
for d in D:
    if D[d]%4==1:
        odd+=1
    elif D[d]%4==2:
        semi+=1
    elif D[d]%4==3:
        odd+=1
        semi+=1

if H%2==0 and W%2==0:
    if odd==semi==0:
        print("Yes")
    else:
        print("No")
elif H%2==1 and W%2==1:
    if odd>1 or semi>(H-1)+(W-1):
        print("No")
    else:
        print("Yes")
else:
    if H%2==1:
        if odd>1 or semi>W-1:
            print("No")
        else:
            print("Yes")
    else:
        if odd>1 or semi>H-1:
            print("No")
        else:
            print("Yes")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

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

c4,c2 = 0,0
for k in d.keys():
    c4 += d[k]//4
    c2 += (d[k]%4)//2

if H%2 + W%2 == 0:
    if c4 == H*W//4:
        print("Yes")
    else:
        print("No")
elif H%2 + W%2 == 1:
    if H%2 == 1:
        if c4 != (H-1)*W//4:
            print("No")
        else:
            c4 -= (H-1)*W//4
            c2 += c4*2
            if c2 == W//2:
                print("Yes")
            else:
                print("No")
    if W%2 == 1:
        if c4 != H*(W-1)//4:
            print("No")
        else:
            c4 -= H*(W-1)//4
            c2 += c4*2
            if c2 == H//2:
                print("Yes")
            else:
                print("No")
else:
    if c4 != (H-1)*(W-1)//4:
        print("No")
    else:
        c4 -= (H-1)*(W-1)//4
        c2 += c4*2
        if c2 == (H-1)//2+(W-1)//2:
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
S=[input() for i in range(H)]
X=[0]*26
for i in range(H):
  for j in range(W):
    X[ord(S[i][j])-ord('a')]+=1
for i in range(26):
  X[i]&=1
if sum(X)>(W&H&1):
  print('No')
else:
  print('Yes')

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
a = [list(input()) for i in range(h)]
d_al = dict()
for ai in a:
    for aij in ai:
        if aij in d_al:
            d_al[aij] += 1
        else:
            d_al[aij] = 1
od = 0
a2 = 0
for i in d_al.values():
    if i % 2 == 1:
        od += 1
    elif i % 4 == 2:
        a2 += 1
if h % 2 == 1 and w % 2 == 1:
    if od == 1 and a2 <= (h + w - 1) // 2:
        print('Yes')
    else:
        print('No')
elif h % 2 == 1:
    if od == 0 and a2 <= w // 2:
        print('Yes')
    else:
        print('No')
elif w % 2 == 1:
    if od == 0 and a2 <= h // 1:
        print('Yes')
    else:
        print('No')
else:
    if od == 0 and a2 == 0:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

lst=[0]*26
for i in range(h):
    for j in range(w):
        lst[ord(a[i][j])-ord("a")]-=1

# print(lst)

heapq.heapify(lst)
dic=defaultdict(int)
if h%2==0:
    if w%2==0:
        dic[4]=h*w//4
    else:
        dic[4]=(w-1)*h//4
        dic[2]=h//2
else:
    if w%2==0:
        dic[4]=(h-1)*w//4
        dic[2]=w//2
    else:
        dic[4]=(h-1)*(w-1)
        dic[2]=h//2+w//2
        dic[1]=1
# print(dic)
# print(lst)
for i in range(dic[4]):
    tmp=-heapq.heappop(lst)
    if tmp>=4:
        tmp-=4
        heapq.heappush(lst,-tmp)
    else:
        print("No")
        quit()

for i in range(dic[2]):
    tmp=-heapq.heappop(lst)
    if tmp>=2:
        tmp-=2
        heapq.heappush(lst,-tmp)
    else:
        print("No")
        quit()
for i in range(dic[1]):
    tmp=-heapq.heappop(lst)
    if tmp>=1:
        tmp-=1
        heapq.heappush(lst,-tmp)
    else:
        print("No")
        quit()
# print(lst)
print("Yes")

Submission status: Wrong Answer

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

lst=[0]*26
for i in range(h):
    for j in range(w):
        lst[ord(a[i][j])-ord("a")]-=1

print(lst)

heapq.heapify(lst)
dic=defaultdict(int)
if h%2==0:
    if w%2==0:
        dic[4]=h*w//4
    else:
        dic[4]=(w-1)*h//4
        dic[2]=h//2
else:
    if w%2==0:
        dic[4]=(h-1)*w//4
        dic[2]=w//2
    else:
        dic[4]=(h-1)*(w-1)
        dic[2]=h//2+w//2
        dic[1]=1
# print(dic)
# print(lst)
for i in range(dic[4]):
    tmp=-heapq.heappop(lst)
    if tmp>=4:
        tmp-=4
        heapq.heappush(lst,-tmp)
    else:
        print("No")
        quit()

for i in range(dic[2]):
    tmp=-heapq.heappop(lst)
    if tmp>=2:
        tmp-=2
        heapq.heappush(lst,-tmp)
    else:
        print("No")
        quit()
for i in range(dic[1]):
    tmp=-heapq.heappop(lst)
    if tmp>=1:
        tmp-=1
        heapq.heappush(lst,-tmp)
    else:
        print("No")
        quit()
# print(lst)
print("Yes")

Submission status: Wrong Answer

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

cnt = defaultdict(int)
for _ in range(h):
    for a in input():
        cnt[a] += 1

quartet = (h//2) * (w//2)
doublet = (h % 2)*(w//2)+(w % 2)*(h//2)
singlet = 1 if h & 1 and w & 1 else 0

for k, v in cnt.items():
    if v < 4:
        continue
    quartet -= v//4
    cnt[k] = v % 4

for k, v in cnt.items():
    if v < 2:
        continue
    doublet -= v//2
    cnt[k] = v % 2

singlet -= sum(v for v in cnt.values())
if singlet == doublet == quartet == 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

H, W = map(int, input().split())
four, two, any = 0, 0, 0
if H % 2:
    if W % 2:
        two = H // 2 + W // 2
        any = 1
    else:
        two = W // 2
else:
    if W % 2:
        two = H // 2
four = (H * W - two * 2 - any) // 4
print(four, two, any)
s = ''
for _ in range(H):
    s += str(input())
c = Counter(s)
d = {'four': 0, 'two': 0}
for v in c.values():
    d['four'] += v // 4
    v -= 4 * (v // 4)
    d['two'] += v // 2
if d['four'] >= four:
    d['two'] += (d['four'] - four) * 2
    if d['two'] == two:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

H, W = map(int, input().split())
four, two, any = 0, 0, 0
if H % 2:
    if W % 2:
        two = H // 2 + W // 2
        any = 1
    else:
        two = W // 2
else:
    if W % 2:
        two = H // 2
four = (H * W - two - any) // 4
s = ''
for _ in range(H):
    s += str(input())
c = Counter(s)
d = {'four': 0, 'two': 0, 'any': 0}
for v in c.values():
    d['four'] += v // 4
    v -= 4 * (v // 4)
    d['two'] += v // 2
    v -= 2 * (v // 2)
    d['any'] += v
if d['four'] >= four:
    d['two'] += (d['four'] - four) * 2
    if d['two'] == two:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter
import math
h, w = map(int, input().split())
data = ''
for _ in range(h):
    a = input()
    data += a
cnt = Counter(data)
data_list = list(cnt.values())
cnt_list = []
for hh in range(math.ceil(h / 2)):
    for ww in range(math.ceil(w / 2)):
        if (hh == math.floor(h / 2)) & (ww == math.floor(w / 2)):
            cnt_list.append(1)
        elif (hh == math.floor(h / 2)) | (ww == math.floor(w / 2)):
            cnt_list.append(2)
        else:
            cnt_list.append(4)
cnt_count = Counter(cnt_list)
ans = 'Yes'

cnt_4 = 0
while cnt_4 < cnt_count[4]:
    for c in range(len(data_list)):
        if ((data_list[c]) >= 4) & (data_list[c] > 0):
            data_list[c] -= 4
            cnt_4 += 1
        if cnt_4 == cnt_count[4]:
            break
    if cnt_4 == cnt_count[4]:
        ans = 'Yes'
        break
    if len([d for d in data_list if d >= 4]) == 0:
        ans = 'No'
        break

cnt_2 = 0
while cnt_2 < cnt_count[2]:
    for c in range(len(data_list)):
        if ((data_list[c] >= 2) & (data_list[c] > 0)):
            data_list[c] -= 2
            cnt_2 += 1
        if cnt_2 == cnt_count[2]:
            break
    if cnt_4 == cnt_count[4]:
        ans = 'Yes'
        break
    if len([d for d in data_list if d >= 2]) == 0:
        ans = 'No'
        break
    
cnt_1 = 0
while cnt_1 < cnt_count[1]:
    for c in range(len(data_list)):
        if (data_list[c] > 0):
            data_list[c] -= 1
            cnt_1 += 1
        if cnt_1 == cnt_count[1]:
            break
    if cnt_4 == cnt_count[4]:
        ans = 'Yes'
        break
    if len([d for d in data_list if d >= 1]) == 0:
        ans = 'No'
        break

if (sum(data_list) == 0) & (ans != 'No'):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter
import math
h, w = map(int, input().split())
data = ''
for _ in range(h):
    a = input()
    data += a
cnt = Counter(data)
data_list = list(cnt.values())
cnt_list = []
for hh in range(math.ceil(h / 2)):
    for ww in range(math.ceil(w / 2)):
        if (hh == math.floor(h / 2)) & (ww == math.floor(w / 2)):
            cnt_list.append(1)
        elif (hh == math.floor(h / 2)) | (ww == math.floor(w / 2)):
            cnt_list.append(2)
        else:
            cnt_list.append(4)
cnt_count = Counter(cnt_list)

cnt_4 = 0
while cnt_4 < cnt_count[4]:
    for c in range(len(data_list)):
        if ((data_list[c]) >= 4) & (data_list[c] > 0):
            data_list[c] -= 4
            cnt_4 += 1
        if cnt_4 == cnt_count[4]:
            break
    if sum([d for d in data_list if d >= 4]) <= 0:
        print('No')
        exit()

cnt_2 = 0
while cnt_2 < cnt_count[2]:
    for c in range(len(data_list)):
        if ((data_list[c] >= 2) & (data_list[c] > 0)):
            data_list[c] -= 2
            cnt_2 += 1
        if cnt_2 == cnt_count[2]:
            break
    if sum([d for d in data_list if d >= 2]) <= 0:
        print('No')
        exit()
    
cnt_1 = 0
while cnt_1 < cnt_count[1]:
    for c in range(len(data_list)):
        if (data_list[c] > 0):
            data_list[c] -= 1
            cnt_1 += 1
        if cnt_1 == cnt_count[1]:
            break
    if sum([d for d in data_list if d >= 1]) <= 0:
        print('No')
        exit()

if sum(data_list) == 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter
import math
h, w = map(int, input().split())
data = ''
for _ in range(h):
    a = input()
    data += a
cnt = Counter(data)
data_list = list(cnt.values())
cnt_list = []
for hh in range(math.ceil(h / 2)):
    for ww in range(math.ceil(w / 2)):
        if (hh == math.floor(h / 2)) & (ww == math.floor(w / 2)):
            cnt_list.append(1)
        elif (hh == math.floor(h / 2)) | (ww == math.floor(w / 2)):
            cnt_list.append(2)
        else:
            cnt_list.append(4)
cnt_count = Counter(cnt_list)

for i in range(cnt_count[4]):
    for c in range(len(data_list)):
        if ((data_list[c] % 4) == 0) & (data_list[c] > 0):
            data_list[c] -= 4
            break

for i in range(cnt_count[2]):
    for c in range(len(data_list)):
        if ((data_list[c] % 4) == 2) & (data_list[c] > 0):
            data_list[c] -= 2
            break            
            
for i in range(cnt_count[1]):
    for c in range(len(data_list)):
        if (data_list[c] % 4) % 2 == 1:
            data_list[c] -= 1
            break


if sum(data_list) == 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter
import math
h, w = map(int, input().split())
data = ''
for _ in range(h):
    a = input()
    data += a
cnt = Counter(data)
data_list = list(cnt.values())
cnt_list = []
for hh in range(math.ceil(h / 2)):
    for ww in range(math.ceil(w / 2)):
        if (hh == math.floor(h / 2)) & (ww == math.floor(w / 2)):
            cnt_list.append(1)
        elif (hh == math.floor(h / 2)) | (ww == math.floor(w / 2)):
            cnt_list.append(2)
        else:
            cnt_list.append(4)

cnt_count = Counter(cnt_list)
for i in range(cnt_count[1]):
    for c in range(len(data_list)):
        if (data_list[c] % 4) % 2 == 1:
            data_list[c] -= 1
            break

for i in range(cnt_count[2]):
    for c in range(len(data_list)):
        if ((data_list[c] % 4) == 2) & (data_list[c] > 0):
            data_list[c] -= 2
            break

for i in range(cnt_count[4]):
    for c in range(len(data_list)):
        if ((data_list[c] % 4) == 0) & (data_list[c] > 0):
            data_list[c] -= 4
            break
if sum(data_list) == 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

cnt = defaultdict(int)
for i in range(h):
    for j in range(w):
        cnt[a[i][j]] += 1

if h % 2 == 0 and w % 2 == 0:
    for k, v in cnt.items():
        if v % 4 != 0:
            print("No")
            exit()
    print("Yes")

if h % 2 == 1 and w % 2 == 0:
    res = 0
    for k, v in cnt.items():
        if v % 2 != 0:
            print("No")
            exit()
        if v // 2 == 1 or v // 2 == h: res += 1
    if res == w // 2:
        print("Yes")
    else:
        print("No")

if h % 2 == 0 and w % 2 == 1:
    res = 0
    for k, v in cnt.items():
        if v % 2 != 0:
            print("No")
            exit()
        if v // 2 == 1 or v // 2 == w: res += 1
    if res == h // 2:
        print("Yes")
    else:
        print("No")

if h % 2 == 1 and w % 2 == 1:
    res = []
    for k, v in cnt.items():
        res.append(v)
    res.sort()
    if res[0] == 1 and sum(res[1:]) % 2 == 0:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter
import numpy as np
H, W = map(int, input().split())
A = []
for _ in range(H):
    A.append(list(input()))
A = np.array(A)
# print('A', A)


def is_kaibun(s):
    s = ''.join(s)
    return s == s[::-1]


def is_kaibun2(s):
    c = Counter(s)
    values = np.array(list(c.values()))
    if np.count_nonzero(values % 2 != 0) >= 2:
        return False
    if len(s) % 2 == 1:
        return np.count_nonzero(values % 2 != 0) == 1
    else:
        return np.count_nonzero(values % 2 != 0) == 0


_H = [is_kaibun2(A[i, :]) for i in range(H)]
_W = [is_kaibun2(A[:, i]) for i in range(W)]
# print('_H', _H)
# print('_W', _W)

ans = 'Yes' if np.all(_H) & np.all(_W) else 'No'
# print(ans)
print('Yes')

# 9
# 12
# 15
# 18
# 21
# 24

Submission status: Wrong Answer

Solution code:
from collections import Counter
import numpy as np
H, W = map(int, input().split())
A = []
for _ in range(H):
    A.append(list(input()))
A = np.array(A)
# print('A', A)


def is_kaibun(s):
    s = ''.join(s)
    return s == s[::-1]


def is_kaibun2(s):
    c = Counter(s)
    values = np.array(list(c.values()))
    if np.count_nonzero(values % 2 != 0) >= 2:
        return False
    if len(s) % 2 == 1:
        return np.count_nonzero(values % 2 != 0) == 1
    else:
        return np.count_nonzero(values % 2 != 0) == 0


_H = [is_kaibun2(A[i, :]) for i in range(H)]
_W = [is_kaibun2(A[:, i]) for i in range(W)]
# print('_H', _H)
# print('_W', _W)

ans = 'Yes' if np.all(_H) & np.all(_W) else 'No'
# print(ans)
print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter
import numpy as np
H, W = map(int, input().split())
A = []
for _ in range(H):
    A.append(list(input()))
A = np.array(A)
# print('A', A)


def is_kaibun(s):
    s = ''.join(s)
    return s == s[::-1]


def is_kaibun2(s):
    c = Counter(s)
    values = np.array(list(c.values()))
    if np.count_nonzero(values % 2 != 0) >= 2:
        return False
    if len(s) % 2 == 1:
        return np.count_nonzero(values % 2 != 0) == 1
    else:
        return np.count_nonzero(values % 2 != 0) == 0


_H = [is_kaibun2(A[i, :]) for i in range(H)]
_W = [is_kaibun2(A[:, i]) for i in range(W)]
# print('_H', _H)
# print('_W', _W)

ans = 'Yes' if np.all(_H) & np.all(_W) else 'No'
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

h,w = map(int,input().split())
l = []
for _ in range(h):
    a = input().split()
    l.append(a)

l = itertools.chain.from_iterable(l)
l = set(l)
l = list(l)
l_len = len(l)

r = 0
if h >= w:
    h = h
    r = w
else:
    r = h
    h = w

j = 0
if h%2 != 0:
    j += h//2+1
else:
    j += h//2

if r > 2:
    j += r-(r//2)


if j >= l_len:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

lis = [0] * 26
for i in range(H):
    for j in range(W):
        lis[ord(a[i][j]) - ord('a')] += 1

one = 0
two = 0
for i in lis:
    if i % 4 == 2:
        two += 1
    elif i % 4 == 1:
        one += 1
    elif i % 4 == 3:
        two += 1
        one += 1
ans = 'Yes'
if H % 2 == 0 and W % 2 == 0:
    if two > 0 or one > 0:
        ans = 'No'
elif H % 2 == 0 and W % 2 == 1:
    if one > 0 or two > H//2:
        ans = 'No'
elif H % 2 == 1 and W % 2 == 0:
    if one > 0 or two > W//2:
        ans = 'No'
else:
    if one != 1 and two > (H-1 + W-1)//2:
        ans = 'No'
print(ans)

Submission status: Wrong Answer

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

lis = [0] * 26
for i in range(H):
    for j in range(W):
        lis[ord(a[i][j]) - ord('a')] += 1

one = 0
two = 0
for i in lis:
    if i % 4 == 2:
        two += 1
    elif i % 4 == 1:
        one += 1
    elif i % 4 == 3:
        two += 1
        one += 1
ans = 'Yes'
if H % 2 == 0 and W % 2 == 0:
    if two > 0 or one > 0:
        ans = 'No'
elif H % 2 == 0 and W % 2 == 1:
    if one > 0 or two > W-1:
        ans = 'No'
elif H % 2 == 1 and W % 2 == 0:
    if one > 0 or two > H-1:
        ans = 'No'
else:
    if one != 1 and two > (H-1 + W-1)//2:
        ans = 'No'
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter as co
n,m=map(int,input().split())
l=co("".join([input()for i in range(n)])).values()
if n%2 and m%2:
    print("Yes"if(n+m)//2-1==len(tuple(1 for j in l if j%4==2))and len(tuple(1 for j in l if j%2))==1 else "No")
elif (n+m)%2:
    k=(n,m)[n%2]
    print("Yes"if k//2==len(tuple(1 for j in l if j%4==2))else"No")
else:print("No"if len(tuple(1 for j in l if j%4))else "Yes")

Submission status: Wrong Answer

Solution code:
from collections import Counter
H,W=map(int,input().split())
a=[list(input()) for _ in range(H)]

tmp=[]
for j in a:
  for k in j:
    tmp.append(k)
d=dict(Counter(tmp))
#print(d)

odd=0
even_4=0
even_2=0
even_4_sum=0
odd_list=[]

for char in d:
    if d[char]%2==1:
        odd +=1
        odd_list.append(char)
    else:
        if d[char]%2==0:
            k= d[char]//4
            even_4 += k
            even_4_sum += k*4
            even_2 += (d[char]-4*k)//2
#print(odd,even_4,even_2)


ans="Yes"
if H==1 or W==1:
    m = max(H,W)
    if m%2==1:
        if odd !=1:
            ans="No"
    else:
        if odd >= 1:
            ans="No"
    
else:
    if H%2==0 and W%2==0:
        if odd>0 or even_2>0:
            ans="No"
    elif H%2==1 and W%2==1:
        if odd !=1:
            ans="No"
        else:
            s=d[odd_list[0]]
            u = s//4
            v = (s-u)//2  # s=4*u+2*v+1
            #print(even_4_sum)

            if even_4_sum< (H-1)*(W-1):
                ans="No"
            #else:
            #    even_4_amari = even_4_sum- (H-1)*(W-1)
            #    must_4_maxi = 4*(min(H,W)//2)
            #    print(even_4_amari, must_4_maxi)
            #    #must_4_mini = 4*(min(H,W)//2)
            #    if even_4_amari > must_4_maxi:
            #        ans="No"
                
    else:
        if odd >=1:
            ans="No"
        else:
            gu = H if H%2==0 else W
            if 2*even_2>gu:
                ans="No"

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
H,W=map(int,input().split())
a=[list(input()) for _ in range(H)]

tmp=[]
for j in a:
  for k in j:
    tmp.append(k)
d=dict(Counter(tmp))
#print(d)

odd=0
even_4=0
even_2=0
even_4_sum=0
odd_list=[]

for char in d:
    if d[char]%2==1:
        odd +=1
        odd_list.append(char)
    else:
        if d[char]%4==0:
            even_4 += 1
            even_4_sum += d[char]
        else:
            even_2 += 1
#print(odd,even_4,even_2)


ans="Yes"
if H==1 or W==1:
    m = max(H,W)
    if m%2==1:
        if odd !=1:
            ans="No"
    else:
        if odd >= 1:
            ans="No"
    
else:
    if H%2==0 and W%2==0:
        if odd>0 or even_2>0:
            ans="No"
    elif H%2==1 and W%2==1:
        if odd !=1:
            ans="No"
        else:
            s=d[odd_list[0]]
            u = s//4
            v = (s-u)//2  # s=4*u+2*v+1
            dw=abs(H-W)
            #print(even_4_sum)

            if even_4_sum< (H-1)*(W-1):
                ans="No"
            else:
                even_4_amari = even_4_sum- (H-1)*(W-1)
                must_4_maxi = 4*(min(H,W)//2)
                #must_4_mini = 4*(min(H,W)//2)
                if even_4_amari > must_4_maxi:
                    ans="No"
                
    else:
        if odd >=1:
            ans="No"
        else:
            gu = H if H%2==0 else W
            if 2*even_2>gu:
                ans="No"

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
H,W=map(int,input().split())
a=[list(input()) for _ in range(H)]

tmp=[]
for j in a:
  for k in j:
    tmp.append(k)
d=dict(Counter(tmp))
#print(d)

odd=0
even_4=0
even_2=0
even_4_sum=0
odd_list=[]

for char in d:
    if d[char]%2==1:
        odd +=1
        odd_list.append(char)
    else:
        if d[char]%4==0:
            even_4 += 1
            even_4_sum += d[char]
        else:
            even_2 += 1
#print(odd,even_4,even_2)


ans="Yes"
if H==1 or W==1:
    m = max(H,W)
    if m%2==1:
        if odd !=1:
            ans="No"
    else:
        if odd >= 1:
            ans="No"
    
else:
    if H%2==0 and W%2==0:
        if odd>0 or even_2>0:
            ans="No"
    elif H%2==1 and W%2==1:
        if odd !=1:
            ans="No"
        else:
            s=d[odd_list[0]]
            u = s//4
            v = (s-u)//2  # s=4*u+2*v+1
            dw=abs(H-W)
            #print(even_4_sum)

            if even_4_sum< (H-1)*(W-1):
                ans="No"
            else:
                even_4_amari = even_4_sum- (H-1)*(W-1)
                must_4 = 4*(min(H,W)//2)
                if even_4_amari > must_4:
                    ans="No"
                else:
                    if even_4_amari + 4*u < must_4:
                        ans="No"
                
    else:
        if odd >=1:
            ans="No"
        else:
            gu = H if H%2==0 else W
            if 2*even_2>gu:
                ans="No"

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
H,W=map(int,input().split())
a=[list(input()) for _ in range(H)]

tmp=[]
for j in a:
  for k in j:
    tmp.append(k)
d=dict(Counter(tmp))
#print(d)

odd=0
even_4=0
even_2=0
even_4_sum=0
odd_list=[]

for char in d:
    if d[char]%2==1:
        odd +=1
        odd_list.append(char)
    else:
        if d[char]%4==0:
            even_4 += 1
            even_4_sum += d[char]
        else:
            even_2 += 1
#print(odd,even_4,even_2)


ans="Yes"
if H==1 or W==1:
    m = max(H,W)
    if m%2==1:
        if odd !=1:
            ans="No"
    else:
        if odd >= 1:
            ans="No"
    
else:
    if H%2==0 and W%2==0:
        if odd>0 or even_2>0:
            ans="No"
    elif H%2==1 and W%2==1:
        if odd !=1:
            ans="No"
        else:
            s=d[odd_list[0]]
            u = s//4
            v = (s-u)//2  # s=4*u+2*v+1
            dw=abs(H-W)
            #print(even_4_sum)

            if even_4_sum< (H-1)*(W-1):
                ans="No"
            else:
                even_4_amari = even_4_sum- (H-1)*(W-1)
                #print(even_4_amari+4*u)
                #print(4*min(H,W)//2)
                if even_4_amari+4*u!=4*(min(H,W)//2):
                    ans="No"               
                
    else:
        if odd >=1:
            ans="No"
        else:
            gu = H if H%2==0 else W
            if 2*even_2>gu:
                ans="No"

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
H,W=map(int,input().split())
a=[list(input()) for _ in range(H)]

tmp=[]
for j in a:
  for k in j:
    tmp.append(k)
d=dict(Counter(tmp))
#print(d)

odd=0
even_4=0
even_2=0
odd_list=[]

for char in d:
    if d[char]%2==1:
        odd +=1
        odd_list.append(char)
    else:
        if d[char]%4==0:
            even_4 += 1
        else:
            even_2 += 1
#print(odd,even_4,even_2)


ans="Yes"
if H==1 or W==1:
    m = max(H,W)
    if m%2==1:
        if odd !=1:
            ans="No"
    else:
        if odd >= 1:
            ans="No"
    
else:
    if H%2==0 and W%2==0:
        if odd>0 or even_2>0:
            ans="No"
    elif H%2==1 and W%2==1:
        if odd !=1:
            ans="No"
        else:
            s=d[odd_list[0]]
            u = s//4
            v = (s-u)//2
            dw=abs(H-W)
            
            if 2*v+2*even_2 !=dw:
                ans="No"
    else:
        if odd >=1:
            ans="No"
        else:
            gu = H if H%2==0 else W
            if 2*even_2>gu:
                ans="No"

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
H,W=map(int,input().split())
a=[list(input()) for _ in range(H)]

tmp=[]
for j in a:
  for k in j:
    tmp.append(k)
d=dict(Counter(tmp))
#print(d)

odd=0
even_4=0
even_2=0
odd_list=[]

for char in d:
    if d[char]%2==1:
        odd +=1
        odd_list.append(char)
    else:
        if d[char]%4==0:
            even_4 += 1
        else:
            even_2 += 1
#print(odd,even_4,even_2)


ans="Yes"
if H==1 or W==1:
    m = max(H,W)
    if m%2==1:
        if odd !=1:
            ans="No"
    else:
        if odd >= 1:
            ans="No"
    
else:
    if H%2==0 and W%2==0:
        if odd>0 or even_2>0:
            ans="No"
    elif H%2==1 and W%2==1:
        if odd !=1:
            ans="No"
        else:
            s=d[odd_list[0]]
            u = s//4
            v = (s-u)//2
            dw=abs(H-W)
            
            if 2*v+2*even_2 >dw:
                ans="No"
    else:
        if odd >=1:
            ans="No"
        else:
            gu = H if H%2==0 else W
            if 2*even_2>gu:
                ans="No"

print(ans)