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: Runtime Error

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
	print(2/0)
	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: Runtime Error

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:
	print(2/0)
	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: Runtime Error

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
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: Runtime Error

Solution code:
from collections import defaultdict
d = defaultdict(int)

h,w = map(int,input().split())

for hh in range(h):
  s = list(input())
  for ss in s:
    d[ss]+=1

dv  = list(d.values())
d2 = [i for i in dv if i%2 == 0 and i%4 !=0]
d2_2 = [i for i in d2 if i == 2]
d4 = [i for i in dv if i%4 == 0]
d2_e = [i for i in d2 if i != 2]
d_odd  = [i for i in list(d.values()) if i%2 == 1]


if h%2==0:
  if w%2==0:
    if len(dv)==len(d4):
      ans = "Yes"
    else:
      ans = "No"
else:
  if w%2==0:
    if len(d_odd)==0 and len(d2_2)<=1 and all(list(map(lambda x:x%(h*2)==0,d2_e))):
      ans = "Yes"
    else:
      ans = "No"
  else:
    ans = "Yes" if len(dv)==len(d4) else "No"
print(ans)

Submission status: Runtime Error

Solution code:
n, m, k = map(int, input().split())

# if n*m%2 == 0:
#     if k%2 == 0 and k >= min(n, m):
#         ans = 1
#     else:
#         ans = 0
# else:
#     ans = 1

# if ans:
#     print("Yes")
# else:
#     print("No")

n,m,K=map(int,input().split());print("YNeos"[all(k*m-K+l*n-k*l*2for k in range(n+1)for l in range(m+1))::2])

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
a,l=[list(input())for i in range(h)],[0]*26
for i in a:
 for j in i:l[ord(j)-97]+=1
o,t,f=(h//2)*(w//2),(h//2)*(w%2)+(w//2)*(h%2),(h%2)*(w%2)
for i in l:
 while o and i>3:o-=1;i-=4
 while t and i>1:t-=1i-=2
 f-=i
print("Yes"if o==t==f==0else"No")

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
A = [list(input()) for _ in range(H)]
C = {chr(i):0 for i in range(97,123)}
for i in range(H):
    for j in range(W):
        C[A[i][j]] += 1
if H%2==0 and W%2==0:
    flag = 0
    for a in C:
        if C[a]%4!=0:
            flag = 1
            break
elif H%2==0 and W%2==1 or H%2==1 and W%2==0:
    flag = 0
    for a in C:
        if (C[a]%4)%2!=0:
            flag = 1
        break
else:
    flag = 0
    cnt = 0
    for a in C:
        if C[a]%2==1:
            cnt += 1
    if cnt!=1:
        flag = 1
if flag==0:
    Print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
from collections import Counter

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

arr = sum(arr, [])

c = Counter(arr)
c = list(c.values())

if h % 2 == 0 and w % 2 == 0:
    ans = all([x % 4 == 0 for x in c])  # 全て4個セットならOK

elif h % 2 == 1 and w % 2 == 1:
    even = (h + w) // 2 - 1  # 2個セットを許容できる個数
    odd_cnt = len([x for x in c if x % 2 == 1])
    if odd_cnt != 1:
        print("No")
        sys.exit()
    odd = sum([x for x in c if x % 2 == 1])
    if odd % 4 == 3:
        even -= 1
    c.remove(odd)
    # 2個セットが許容数以下か
    ans = True if sum([x % 4 == 2 for x in c]) <= even else False
    ans &= all([x % 4 == 0 for x in c if x % 4 != 2])  # 残り全て4個セットか

else:
    even = h // 2 if h % 2 == 0 else w // 2  # 2個セットを許容できる個数
    # 2個セットが許容数以下か
    ans = True if sum([x % 4 == 2 for x in c]) <= even else False
    ans &= all([x % 4 == 0 for x in c if x % 4 != 2])  # 残り全て4個セットか

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

Submission status: Runtime Error

Solution code:
h,w,k=map(int,input().split())
ans="No"
for i in range(h+1):
  for j in range(w+1):
    if i*j+(h-i)*(w-j) == k:
      ans="Yes"
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter, defaultdict
H, W = map(int, input().split(' '))
d = defaultdict(int)
for i in range(H):
    for k, v in Counter(input()).items():
        d[k] += v
if H % 2 == 0 and W % 2 == 0:
    for i in d.values():
        if i % 4 != 0:
            print('No')
            exit()
    print('Yes')
elif H % 2 == 0 or W % 2 == 0:
    cnt = H//2 if not H % 2 else W//2
    for i in d.values():
        if i % 4 == 0:
            continue
        elif i % 2 == 0:
            cnt -= 1
            if cnt >= 0:
                continue
        print('No')
        exit()
    print('Yes')
else:
    raise TypeError
    odd = 1
    cnt = H+W-1
    for i in d.values():
        if i % 2 != 0 and odd:
            odd -=1
            continue
        elif i % 4 == 0:
            continue
        elif i % 2 == 0 and cnt:
            cnt -= 1
            continue
        else:
            print('No')
            exit()
    print('Yes')

Submission status: Runtime Error

Solution code:
from collections import Counter, defaultdict
H, W = map(int, input().split(' '))
d = defaultdict(int)
for i in range(H):
    for k, v in Counter(input()).items():
        d[k] += v
if H % 2 == 0 and W % 2 == 0:
    for i in d.values():
        if i % 4 != 0:
            print('No')
            exit()
    print('Yes')
elif H % 2 == 0 or W % 2 == 0:
    raise TypeError
    cnt = H//2 if not H % 2 else W//2
    for i in d.values():
        if i % 4 == 0:
            continue
        elif i % 2 == 0:
            cnt -= 1
            if cnt >= 0:
                continue
        print('No')
        exit()
    print('Yes')
else:
    raise TypeError
    odd = 1
    cnt = H+W-1
    for i in d.values():
        if i % 2 != 0 and odd:
            odd -=1
            continue
        elif i % 4 == 0:
            continue
        elif i % 2 == 0 and cnt:
            cnt -= 1
            continue
        else:
            print('No')
            exit()
    print('Yes')

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    h,w=map(int,input().split())
    s=""
    for _ in range(h):
        s+=input()
    sc=list(Counter(s).values())
    #print(sc)
    if h%2==1 and w%2==1:
        for i,scc in enumerate(sc):
            if scc%2==1:
                sc[i]-=1
                break
        else:
            print("No")
            sys.exit()
    #print(sc)
    cunt_2=0
    if h%2==1:cunt_2+=w//2
    if w%2==1:cunt_2+=h//2
    for i,scc in enumerate(sc):
        if cunt_2==0:break
        if scc%4==2:
            sc[i]-=2
            cunt_2-=1
    else:
        if cunt_2%2==1:
            print("No")
            sys.exit()
        else:
            for i,scc in enumerate(sc):
                if cunt_2==0:break
                if scc>0 and scc%4==0:
                    sc[i]-=4
                    cunt_4-=2  
            else:
                print("No")
                sys.exit()
    #print(sc)
    cunt_4=(h//2)*(w//2)
    for i,scc in enumerate(sc):
        if cunt_4>0 and scc>0 and scc%4==0:
            sc[i]-=4
            cunt_4-=1
    #print(sc)
    print("Yes" if all(scc==0 for scc in sc) else "No")

        

if __name__=='__main__':
    main()

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
a={}
for i in range(26):
  a[chr(i+97)]=0
for i in range(h):
  s=input()
  for j in s:
    a[j]+=1
if h==1 and w==1:print("Yes")
elif h==1 or w==1:
  cnt=0
  for i in a.values():
    if i%2==1:cnt+=1
  if cnt!=1:print("No")
  else:print("Yes")
elif h%2==0 and w%2==0:
  for i in a.values():
    if i%4!=0:print("No");exit()
  print("Yes")
elif h%2==1 and w%2==0:
  cnt=0
  for i in a.values():
    if i%4==1 or i%4==3:
      print("No");exit()
    if i%4==2:cnt+=1
  if cnt>w//2:
    print("No")
  else:print("Yes")
elif h%2==0 and w%2==1:
  cnt=0
  for i in a.values():
    if i%4==1 or i%4==3:
      print("No");exit()
    if i%4==2:cnt+=1
  if cnt>h//2:
    print("No")
  else:print("Yes")
else:
  cnt3=0;cnt2=0;cnt1=0
  for i in a.values():
    if i%4==1:cnt1+=1
    elif i%4==2:cnt2+=1
    elif i%4==3:cnt3+=1
  rem=1-cnt1
  elif cnt1+cnt3!=1:print("No")
  elif cnt2+cnt3>h+w-2:print("No")
  else:
    print("Yes")

Submission status: Runtime Error

Solution code:
def solve():
    inputs = open(0).readlines()
    h, w = map(int, inputs[0].split())
    *A, = map(lambda x: x.strip(), inputs[1:])
    B = []
    for S in A:
        C = [0] * 26
        for c in S:
            C[ord(c)-ord('a')] += 1
        B.append(C)
    
    if w % 2 == 0:
        if all(all(x % 2 == 0 for x in b) for b in B):
            C = []
        else:
            return 'No'
    else:
        C = [[i for i, x in enumerate(b) if x % 2 != 0] for b in B]
        if all(len(c) == 1 for c in C):
            B = [[x if x % 2 == 0 else x-1 for x in b] for b in B]
            C = Counter([c[0] for c in C]).values()
        else:
            return 'No'
    C
    D = Counter(map(tuple, B)).values()
    if h % 2 == 0:
        if all(c % 2 == 0 for c in C) and all(d % 2 == 0 for d in D):
            return 'Yes'
    else:
        if sum(c % 2 for c in C) <= 1 and sum(d % 2 for d in D) <= 1:
            return 'Yes'
    return 'No'

print(solve())

Submission status: Runtime Error

Solution code:
import collections
H,W = list(map(int , input().split()))
D = []
for j in range(H):
    x=list(input())
    D.extend(x)
s = len((set(D)))
c = collections.Counter(D)
Q = []

for i in range(s):
    Q.append(c.most_common()[i][1])
if s == 1:
    print("Yes")
else:
    if ((H*W)%2 == 1):
        seigen = (H//2+1)*(W//2 +1)
        q = 0
        m = 0
        mm = (N-(H//2)*(W//2)*4)//2+1
        for k in range(s):
            q += (Q[k] % 2)
            if (Q[k] % 4)!= 0:
                m += 1
        if (q == 1)and(s<=seigen)and (m <= mm):
            print("Yes")
        else:
            print("No")
    elif ((H%2) == 0)and((W %2) ==0):
        q = 0
        for k in range(s):
            q += (Q[k] % 4)
        if ((s % 2) == 0)and(q == 0):
            print("Yes")
        else:
            print("No")

    else:
        q = 0
        e = 0
        if ((H%2) == 1):
            seigen = (H//2+1)*W
            seigen2 = (H//2+1)
        elif ((W%2) == 1):
            seigen = (W//2+1)*H
            seigen2 = (W//2+1)
        for k in range(s):
            q += (Q[k] % 2)
            if (Q[k] % 4)!= 0:
                e += 1
        if (q == 0)and(s<=seigen)and(e<=seigen2):
            print("Yes")
        else:
            print("No")

Submission status: Runtime Error

Solution code:
import collections
H,W = list(map(int , input().split()))
D = []
for j in range(H):
    x=list(input())
    D.extend(x)
s = len((set(D)))
c = collections.Counter(D)
Q = []

for i in range(s):
    Q.append(c.most_common()[i][1])
if ((H*W)%2 == 1):
    seigen = (H//2+1)*(W//2 +1)
    q = 0
    for k in range(s):
        q += (Q[k] % 2)
    if (q == 1)and(s<=seigen):
        print("Yes")
    else:
        print("No")
elif ((H%2) == 0)and((W %2) ==0):
    q = 0
    for k in range(s):
        q += (Q[k] % 4)
    if ((s % 2) == 0)and(q == 0):
        print("Yes")
    else:
        print("No")

else:
    q = 0
        
    if ((H%2) == 1):
        seigen = (H//2+1)*W
    elif ((W%2) == 1):
        seigen = (W//2+1)*H
    for k in range(s):
        q += (Q[k] % 2)
    if (q == 0)and(s<=seigen):
        #print("Yes")
    else:
        #print("No")

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    def main():

        H,W=map(int,input().split())
        grid=[[_ for _ in input()] for _ in range(H)]
        for g in grid:
            gg=Counter(g)
            cnt=0
            for i in gg.values():
                if i%2==1:
                    cnt+=1
            if not ((cnt==1 and W%2==1) or (cnt==0 and W%2==0)):
                return 'No'

        grid=zip(*grid)
        W=H
        for g in grid:
            gg=Counter(g)
            cnt=0
            for i in gg.values():
                if i%2==1:
                    cnt+=1
            if not ((cnt==1 and W%2==1) or (cnt==0 and W%2==0)):
                return 'No'
        return 'Yes'
    print(main())







resolve()

Submission status: Runtime Error

Solution code:
from collections import Counter
H, W = map(int, input().split())
D = []
for _ in range(H):
    D.extend(list([v for v in input()]))
C = Counter(D)
L = list([v for i, v in C.most_common()])

if H == 1 and W == 1:
    ans = "Yes"
elif H == 1 or W == 1:
    if sum([1 if v % 2 == 1 else 0 for v in L]) == 1:
        ans = "Yes"
    else:
        ans = "No"
elif H % 2 == 1 and W % 2 == 1:
    if sum(v % 2 for v in L) == 1 and (sum(1 if v % 4 == 0 else 0 for v in L) == len(L)-1 or (sum(1 if v % 4 == 0 else 0 for v in L)) == len(L)-2):
        ans = "Yes"
    else:
        ans = "No"
elif H % 2 == 0 and W % 2 == 0:
    if all(v % 4 == 0 for v in L):
        ans = "Yes"
    else:
        ans = "No"
else:
    assert 1 == 2
    if sum(v % 2 for v in L) == 0 and (sum(1 if v % 4 == 0 else 0 for v in L) == len(L)-1 or (sum(1 if v % 4 == 0 else 0 for v in L)) == len(L)-2):
        ans = "Yes"
    else:
        ans = "No"
print(ans)

# 1.2.4.

Submission status: Runtime Error

Solution code:
from collections import Counter
H, W = map(int, input().split())
D = []
for _ in range(H):
    D.extend(list([v for v in input()]))
C = Counter(D)
L = list([v for i, v in C.most_common()])
# print(C)
if H == 1 and W == 1:
    ans = "Yes"
elif H == 1 or W == 1:
    if sum([1 if v % 2 == 1 else 0 for v in L]) == 1:
        ans = "Yes"
    else:
        ans = "No"
elif H % 2 == 1 and W % 2 == 1:
    if sum(v % 2 for v in L) == 1 and (sum(1 if v % 4 == 0 else 0 for v in L) == len(L)-1 or (sum(1 if v % 4 == 0 else 0 for v in L)) == len(L)-2):
        ans = "Yes"
    else:
        ans = "No"
elif H % 2 == 0 and W % 2 == 0:
    assert 1 == 2
    ans = "Un"
else:
    if sum(v % 2 for v in L) == 0 and (sum(1 if v % 4 == 0 else 0 for v in L) == len(L)-1 or (sum(1 if v % 4 == 0 else 0 for v in L)) == len(L)-2):
        ans = "Yes"
    else:
        ans = "No"
print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    h, w = LI()
    a = SR(h)
    d = defaultdict(int)
    for i in range(h):
        for j in range(w):
            d[s[i][j]] += 1
    four = 0
    for i in d.values():
        if i & 1:
            print("No")
            return
        four |= i & 4 and not i & 3
    if four:
        print("Yes")
    else:
        print("No")
        

    return


#main
if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import collections
h, w = map(int,input().split())
a = []
for i in range(h):
    a.append(list(input()))

tmp = []
for i in range(h):
    for j in a[i]:
        tmp.append(j)
#print(tmp)
c = collections.Counter(tmp)
tmp2 = list(set(tmp))
four = 0
two = 0
odd = 0
for i in tmp2:
    if c[i] % 4 == 0:
        four += 1
    elif c[i] % 2 == 0:
        two += 1
    else:
        odd += 1

if h % 2 == 1 and w % 2 == 1:
    if odd == 1 and (two == 2 or two == 0):
        ans = "Yes"
    else:
        ans == "No"
elif h % 2 == 0 and w % 2 == 0:
    if two == 0 and odd == 0:
        ans = "Yes"
    else:
        ans = "No"
elif h % 2 == 0 and w % 2 == 1:
    if odd == 0 and two <= h // 2:
        ans = "Yes"
    else:
        ans = "No"
elif h % 2 == 1 and w % 2 == 0:
    if odd == 0 and two <= w // 2:
        ans = "Yes"
    else:
        ans = "No"
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import collections
h, w = map(int,input().split())
a = []
for i in range(h):
    a.append(list(input()))

tmp = []
for i in range(h):
    for j in a[i]:
        tmp.append(j)
#print(tmp)
c = collections.Counter(tmp)
tmp2 = list(set(tmp))
four = 0
two = 0
odd = 0
for i in tmp2:
    if c[i] % 4 == 0:
        four += 1
    elif c[i] % 2 == 0:
        two += 1
    else:
        odd += 1

if h % 2 == 1 and w % 2 == 1:
    if odd == 1 and (two == 2 or two == 0):
        ans = "Yes"
    else:
        ans == "No"
elif h % 2 == 0 and w % 2 == 0:
    if two == 0 and odd == 0:
        ans = "Yes"
    else:
        ans = "No"
else:
    if (odd == 0 and two == 0) or (two == 2 and odd == 0):
        ans = "Yes"
    else:
        ans = "No"
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import collections
h, w = map(int,input().split())
a = []
for i in range(h):
    a.append(list(input()))

tmp = []
for i in range(h):
    for j in a[i]:
        tmp.append(j)
#print(tmp)
c = collections.Counter(tmp)
tmp2 = set(tmp)
four = 0
two = 0
odd = 0
for i in tmp2:
    if c[i] % 4 == 0:
        four += 1
    elif c[i] % 2 == 0:
        two += 1
    else:
        odd += 1

if h % 2 == 1 and w % 2 == 1:
    if odd == 1 and (two == 2 or two == 0):
        ans = "Yes"
    else:
        ans == "No"
elif h % 2 == 0 and w % 2 == 0:
    if two == 0 and odd == 0:
        ans = "Yes"
    else:
        ans = "No"
else:
    if (odd == 0 and two == 0) or (two == 2 and odd == 0):
        ans = "Yes"
    else:
        ans = "No"
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import collections
h, w = map(int,input().split())
a = []
for i in range(h):
    a.append(list(input()))

tmp = []
for i in range(h):
    for j in a[i]:
        tmp.append(j)
#print(tmp)
c = collections.Counter(tmp)
tmp2 = set(tmp)
odd = 0
for i in tmp2:
    if c[i] % 2 == 1:
        odd += 1

if h % 2 == 1 and w % 2 == 1:
    if odd == 1:
        ans = "Yes"
    else:
        ans == "No"
elif h % 2 == 0 and w % 2 == 0:
    if (h > 2 or w > 2) and odd == 0:
        ans = "Yes"
    else:
        ans = "No"
else:
    if odd == 0:
        ans = "Yes"
    else:
        ans = "No"
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter

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

raw = ""
for i in range(H):
    raw = raw + input()
#words = Counter(list(raw))

print(words)
if H*W % 2 == 1:
    flag = 0
    two_sum = (H-1) + (W-1)
elif H%2 == 1:
    flag = 1
    two_sum = W
elif W%2 == 1:
    flag = 1
    two_sum = H
else:
    flag = 1
    two_sum = 0

for value in words.values():
    if value % 2 == 1:
        flag += 1
    if flag > 1:
        print("No")
        break

if flag < 2 and two_sum > -1:
    for key, value in words.items():
        N_key = value
        while N_key > 0:
            if 1 < N_key < 4:
                N_key -= 2
                two_sum -= 2
            else:
                N_key -= 4

if flag < 2 and two_sum > -1:
    print("Yes")
elif two_sum < 0:
    print("No")

Submission status: Runtime Error

Solution code:
al = [chr(ord('a') + i) for i in range(26)]

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

cnt = [0] * 26
for h in range(H):
    for w in range(W):
        cnt[al.index(A[h][w])] += 1
cnt = [i for i in cnt if i != 0]
cnt.sort(reverse=True)

if H == 1 or W == 1:
    count = (H*W) // 2
    while count > 0:
        count -= 1
        cnt[0] -= 2
        cnt.sort(reverse=True)
    cnt = [i for i in cnt if i != 0]
    if cnt[0] == 1 and len(cnt) == 1:
        ans = "Yes"
    else:
        ans = "No"
else:
    if H % 2 == 1 and W % 2 == 1:
        count = (H//2) * (W//2)
        while count > 0:
            count -= 1
            cnt[0] -= 4
            cnt.sort(reverse=True)
        cnt = [i for i in cnt if i != 0]
        count = (H//2) + (W//2)
        while count > 0:
            count -= 1
            cnt[0] -= 2
            cnt.sort(reverse=True)
        cnt = [i for i in cnt if i != 0]
        if cnt[0] == 1 and len(cnt) == 1:
            ans = "Yes"
        else:
            ans = "No"
    elif H % 2 == 0 and W % 2 == 0:
        count = (H//2) * (W//2)
        while count > 0:
            count -= 1
            cnt[0] -= 4
            cnt.sort(reverse=True)
        cnt = list(set(cnt))
        if cnt[0] == 0 and len(cnt) == 1:
            ans = "Yes"
        else:
            ans = "No"
    else:
        count = (H//2) * (W//2)
        while count > 0:
            count -= 1
            cnt[0] -= 4
            cnt.sort(reverse=True)
        cnt = [i for i in cnt if i != 0]
        cnt.sort(reverse=True)
        count = (H%2) * (W//2) + (H//2) * (W%2)
        while count > 0:
            count -= 1
            cnt[0] -= 2
            cnt.sort(reverse=True)
        cnt =list(set(cnt))
        if cnt[0] == 0 and len(cnt) == 1:
            ans = "Yes"
        else:
            ans = "No"
print(ans)

Submission status: Runtime Error

Solution code:
al = [chr(ord('a') + i) for i in range(26)]

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

cnt = [0] * 26
for h in range(H):
    for w in range(W):
        cnt[al.index(A[h][w])] += 1
cnt = [i for i in cnt if i != 0]
cnt.sort(reverse=True)

if H == 1 or W == 1:
    count = (H*W) // 2
    while count > 0:
        count -= 1
        cnt[0] -= 2
        cnt.sort(reverse=True)
    cnt = [i for i in cnt if i != 0]
    if cnt[0] == 1 and len(cnt) == 1:
        ans = "Yes"
    else:
        ans = "No"
else:
    if H % 2 == 1 and W % 2 == 1:
        count = (H//2) * (W//2)
        while count > 0:
            count -= 1
            cnt[0] -= 4
            cnt.sort(reverse=True)
        cnt = [i for i in cnt if i != 0]
        count = (H//2) + (W//2)
        while count > 0:
            count -= 1
            cnt[0] -= 2
            cnt.sort(reverse=True)
        cnt = [i for i in cnt if i != 0]
        if cnt[0] == 1 and len(cnt) == 1:
            ans = "Yes"
        else:
            ans = "No"
    elif H % 2 == 0 and W % 2 == 0:
        count = (H//2) * (W//2)
        while count > 0:
            count -= 1
            cnt[0] -= 4
            cnt.sort(reverse=True)
        cnt = list(set(cnt))
        if cnt[0] == 0 and len(cnt) == 1:
            ans = "Yes"
        else:
            ans = "No"
    else:
        count = (H//2) * (W//2)
        while count > 0:
            count -= 1
            cnt[0] -= 4
            cnt.sort(reverse=True)
        cnt = [i for i in cnt if i != 0]
        count = (H%2) * (W//2) + (H//2) * (W%2)
        while count > 0:
            count -= 1
            cnt[0] -= 2
            cnt.sort(reverse=True)
        cnt =list(set(cnt))
        if cnt[0] == 0 and len(cnt) == 1:
            ans = "Yes"
        else:
            ans = "No"
print(ans)

Submission status: Runtime Error

Solution code:
al = [chr(ord('a') + i) for i in range(26)]

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

cnt = [0] * 26
for h in range(H):
    for w in range(W):
        cnt[al.index(A[h][w])] += 1
if H == 1 or W == 1:
    check = 0
    for i in range(26):
        if cnt[i] % 2 == 1:
            check += 1
    if check == 1:
        ans = "Yes"
    else:
        ans = "No"
else:
    cnt = [i for i in cnt if i != 0]
    cnt.sort(reverse=True)
    if H % 2 == 1 and W % 2 == 1:
        count = H//2 * W//2
        while count > 0:
            count -= 1
            cnt[0] -= 4
            cnt.sort(reverse=True)
        cnt = [i for i in cnt if i != 0]
        count = H//2 + W//2
        while count > 0:
            count -= 1
            cnt[0] -= 2
            cnt.sort(revese=True)
        cnt = [i for i in cnt if i != 0]
        if cnt[0] == 1 and len(cnt) == 1:
            ans = "Yes"
        else:
            ans = "No"
    elif H % 2 == 0 and W % 2 == 0:
        count = H//2 * W//2
        while count > 0:
            count -= 1
            cnt[0] -= 4
            cnt.sort(reverse=True)
        cnt = list(set(cnt))
        if cnt[0] == 0 and len(cnt) == 1:
            ans = "Yes"
        else:
            ans = "No"
    else:
        count = H//2 * W//2
        while count > 0:
            count -= 1
            cnt[0] -= 4
            cnt.sort(reverse=True)
        cnt = [i for i in cnt if i != 0]
        count = (H%2) * (W//2) + (H//2) * (W%2)
        while count > 0:
            count -= 1
            cnt[0] -= 2
            cnt.sort(reverse=True)
        cnt =list(set(cnt))
        if cnt[0] == 0 and len(cnt) == 1:
            ans = "Yes"
        else:
            ans = "No"
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
import string
import heapq
h,w = map(int,stdin.readline().rstrip().split())
s = ""
for i in range(h):
    s += stdin.readline().rstrip()
task_4 = (h//2)*(w//2)
task_2 = (h%2)*(h//2)+(w%2)*(w//2)
task_1 = (h%2)*(w%2)
alpha = string.ascii_lowercase
li = [-s.count(i) for i in alpha if s.count(i) != 0]
heapq.heapify(li)
for i in range(task_4):
    if li[0] <= -4:
        k = heapq.heappop(li)
        if k+4 == 0:
            continue
        else:
            heapq.heappush(li,k+4)
    else:
        print("No")
        exit()
for i in range(task_2):
    if li[0] <= -2:
        k = heapq.heappop(li)
        if k+2 == 0:
            continue
        else:
            heapq.heappush(li,k+2)
    else:
        print("No")
        exit()
for i in range(task_1):
    if li[0] <= -1:
        k = heapq.heappop(li)
        if k+1 == 0:
            continue
        else:
            heapq.heappush(li,k+1)
    else:
        print("No")
        exit()
print("Yes")

Submission status: Runtime Error

Solution code:
from collections import Counter 

a,b = map(int,input().split())
l = ''
for i in range(a):
    t = input()
    l+=t

c = Counter(list(l))
# print(c)
dp = [0,0,0]
for i in c:
    if c[i]%2 ==1:
        dp[0] +=1
    elif c[i]%4 == 0:
        dp[2] += 1
    elif c[i]%2 == 0:
        dp[1] += 1
# print(dp)
ans = 'No'
if a%2 ==1 and b%2 ==1:
    A = 1
    B = (a+b-2)//2
A = 0
elif  a%2 ==0 and b%2 ==0:
    B= 0
elif a%2 ==0 and b%2 ==1:
    B = a//2
else:
    B= b//2
if A >= dp[0] and B >= dp[1]:
    ans = 'Yes'
print(ans)

Submission status: Runtime Error

Solution code:
h, w = map(int. input().split())
d = {}
for i in h:
  for c in input():
    if c in d:
      d[c] += 1
    else:
      d[c] = 1
m = ((w + 1)// 2) * ((h + 1) // 2)
ans = "Yes"
if len(d.keys()) > m:
  ans = "No"
oc = 0
for key in d:
  oc += d[key] % 2
if oc > 1:
  ans = "No"
print(ans)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
#n,mの偶奇で場合分け
#n,mがともに偶数の時は全部４の倍数個なきゃダメ
#n,mの片方のみ奇数の時は、例えばnが奇数の時は個数が偶数だが４の倍数でない組みがm//2組みまで許される
#n,mがともに奇数の時は個数が偶数だが４の倍数でない組みが(n+m)//2組み許され、ただ一つ奇数が必要
l=[]
for i in range(n):
  l.append(list(input()))
from collections import defaultdict
d=defaultdict(int)
for i in range(n):
  for j in range(m):
    d[l[i][j]]+=1
b=True
count2=0
count1=0
for i in d:
  if d[i]%4==0:
    pass
  elif d[i]%2==0:
    count2+=1
  else:
    if count1!=0:
      b=False
    else:
      count1=1
      index=d[i]
if not b:#奇数個あるのが２組以上
  print("No")
else:
  if n%2==0 and m%2==0:
    if count2>0 or count1>0:
      print("No")
    else:
      print("Yes")
  if n%2==0 and m%2==1:
    if count1>0 or count2>n//2:
      print("No")
    else:
      print("Yes")
  if n%2==1 and m%2==0:
    if count1>0 or count2>m//2:
      print("No")
    else:
      print("Yes")
  else:
    if (index-1)%4==2:
      count2+=1
    if count2>(n+m-2)//2:
      print("No")
    else:
      print("Yes")

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
a={}
for i in range(26):
  a[chr(i+97)]=0
for i in range(h):
  s=input()
  for j in s:
    a[j]+=1
if h%2==0 and w%2==0:
  for i in a.values():
    if i%4!=0:print("No");exit()
  print("Yes")
elif h%2==1 and w%2==0:
  cnt=0
  for i in a.values():
    if i%4!=2:cnt+=1
  if cnt>w//2:
    print("No")
  else:print("Yes")
elif h%2==0 and w%2==1:
   cnt=0
  for i in a.values():
    if i%4!=2:cnt+=1
  if cnt>h//2:
    print("No")
  else:print("Yes")
else:
  cnt2=0;cnt1=0
  for i in a.values():
    if i%4==1:cnt1+=1
    elif i%4==2:cnt2+=1
  if cnt1!=1:print("No")
  elif 2*cnt2>h+w-2:print("No")
  else:
    print("Yes")