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:
# -*- coding: utf-8 -*-

import sys
from collections import Counter

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

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

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as de
p=de(int)
h,w=map(int,input().split())
for i in range(h):
    a=list(input())
    for j in range(w):
        p[ord(a[j])-ord("a")]+=1
c=0
d=0
for i in p.values():
    c+=i%2
    d+=i//2
if w%2==1:
    if h-c>=0 and (h-c)%2==0:
        print("Yes")
    else:
        print("No")
else:
    if c!=0:
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

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


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

    max_count = 0
    odd_count = 0
    even_count = 0
    for s in dic:
        max_count = max(max_count, dic[s])
        if dic[s] % 2 == 0:
            even_count += 1
        else:
            odd_count += 1
    if (H * W) % 2 == 0:
        if odd_count == 0 and max_count >= 1 * (4 if min(H, W) > 1 else 1) :
            print "Yes"
        else:
            print "No"
    else:
        if odd_count == 1 and max_count >= 1 * (4 if min(H, W) > 1 else 1):
            print "Yes"
        else:
            print "No"


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
h,w = map(int, input().split())
al = []
for _ in range(h):
    al += list(input())

c = Counter(al)

if h==1 or w==1:
    res = "Yes"
    one = []
    for k in c.keys():
        if c[k]%2==0:
            pass
        elif c[k]%2==1:
            one.append(k)
        else:
            res = "No"
            break
    if res=="Yes" and len(one)>1:
        res = "No"
elif h%2==0 and w%2==0:
    res = "Yes"
    for k in c.keys():
        if c[k]%4!=0:
            res = "No"
            break
elif h%2==1 and w%2==1:
    res = "Yes"
    one = []
    two = []
    for k in c.keys():
        if c[k]%4==0:
            pass
        elif c[k]%4==1:
            one.append(k)
        elif c[k]%4==2:
            two.append(k)
        elif c[k]%4==3:
            one.append(k)
            two.append(k)
    if res=="Yes":
        if len(one)!=1:
            res = "No"

else:
    res = "Yes"
    for k in c.keys():
        if c[k]%2!=0:
            res = "No"
            break

print(res)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
h,w = map(int, input().split())
al = []
for _ in range(h):
    al += list(input())

c = Counter(al)

if h==1 or w==1:
    res = "Yes"
    one = []
    for k in c.keys():
        if c[k]%2==0:
            pass
        elif c[k]%2==1:
            one.append(k)
        else:
            res = "No"
            break
    if res=="Yes" and len(one)>1:
        res = "No"
elif h%2==0 and w%2==0:
    res = "Yes"
    for k in c.keys():
        if c[k]%4!=0:
            res = "No"
            break
elif h%2==1 and w%2==1:
    res = "Yes"
    one = []
    for k in c.keys():
        if c[k]%4==0:
            pass
        elif c[k]%4==1:
            one.append(k)
        else:
            res = "No"
            break
    if res=="Yes" and len(one)!=1:
        res = "No"
else:
    res = "Yes"
    for k in c.keys():
        if c[k]%2!=0:
            res = "No"
            break

print(res)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
h,w = map(int, input().split())
al = []
for _ in range(h):
    al += list(input())

c = Counter(al)

if h==1 or w==1:
    res = "Yes"
    one = []
    for k in c.keys():
        if c[k]%2==0:
            pass
        elif c[k]%2==1:
            one.append(k)
        else:
            res = "No"
            break
    if res=="Yes" and len(one)!=1:
        res = "No"
elif h%2==0 and w%2==0:
    res = "Yes"
    for k in c.keys():
        if c[k]%4!=0:
            res = "No"
            break
elif h%2==1 and w%2==1:
    res = "Yes"
    one = []
    for k in c.keys():
        if c[k]%4==0:
            pass
        elif c[k]%4==1:
            one.append(k)
        else:
            res = "No"
            break
    if res=="Yes" and len(one)!=1:
        res = "No"
else:
    res = "Yes"
    for k in c.keys():
        if c[k]%2!=0:
            res = "No"
            break

print(res)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
h,w = map(int, input().split())
al = []
for _ in range(h):
    al += list(input())

c = Counter(al)

if h==1 or w==1:
    res = "YES"
    one = []
    for k in c.keys():
        if c[k]%2==0:
            pass
        elif c[k]%2==1:
            one.append(k)
        else:
            res = "NO"
            break
    if res=="YES" and len(one)!=1:
        res = "NO"
elif h%2==0 and w%2==0:
    res = "YES"
    for k in c.keys():
        if c[k]%4!=0:
            res = "NO"
            break
elif h%2==1 and w%2==1:
    res = "YES"
    one = []
    for k in c.keys():
        if c[k]%4==0:
            pass
        elif c[k]%4==1:
            one.append(k)
        else:
            res = "NO"
            break
    if res=="YES" and len(one)!=1:
        res = "NO"
else:
    res = "YES"
    for k in c.keys():
        if c[k]%2!=0:
            res = "NO"
            break

print(res)

Submission status: Wrong Answer

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

four=0
two=0
one=0

for i in  range(26):
  c=chr(ord("a")+i)
  if d[c]>=4:
    four+=d[c]//4 
    d[c]%=4
  if d[c]>=2:
    two+=d[c]//2
    d[c]%=2
  if d[c]>=1:
    one+=d[c]
    d[c]-=1
    
if four<=(H//2)*(W//2):    
  print("No")
  exit(0)
four-=(H//2)*(W//2)
two+=four*2

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

print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


# 各文字の出現回数を数えて降順ソート
Counts = defaultdict(int)
for i in range(H):
    A = input()
    for a in A:
        Counts[a] += 1
Counts = deque(sorted(Counts.values()))


# クリアすべきパターン
Need = [1] * (H % 2) * (W % 2) + \
       [2] * (H // 2) * (W % 2) + \
       [2] * (H % 2) * (W // 2) + \
       [4] * (H // 2) * (W // 2)


# パターンをクリアできるかシミュレーション
while Counts:
    if Counts[-1] >= Need[-1]:
        X = Counts.pop() - Need.pop()
        if X != 0:
            Counts.appendleft(X)
    else:
        print('No')
        break
else:
    print('Yes')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
import numpy as np
from collections import Counter 
h,w=map(int, input().split())
a=np.array([list(input()) for i in range(h)])
ans='Yes'
for i in range(h):
    c=Counter(a[i,:])
    if [i%2 for i in list(c.values())].count(1)>1:ans='No'
for i in range(w):
    c=Counter(a.T[i,:])
    if [i%2 for i in list(c.values())].count(1)>1:ans='No'
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
from collections import Counter

h,w=map(int, input().split())
a=np.array([list(input()) for i in range(h)])
ans='Yes'
for i in range(h):
    c=Counter(a[i,:])
    if list(c.values()).count(1)>1:ans='No'
for i in range(w):
    c=Counter(a.T[i,:])
    if list(c.values()).count(1)>1:ans='No'
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
ai = lambda: list(map(int,input().split()))
ai_ = lambda: [int(x)-1 for x in input().split()]

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

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

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

if h&1 and w&1:
    if c1 <= 1 and c2 <= 2:
        print('Yes')
    else:
        print('No')
elif h&1 or w&1:
    if c1 <= 0 and c2 <= 1:
        print('Yes')
    else:
        print('No')
else:
    if c1 <= 0 and c2 <= 0:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

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

h,w = ai()
m = []
for _ in range(h):
    m += input().split()

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

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

if h&1 and w&1:
    if c1 <= 1 and c2 <= 2:
        print('Yes')
    else:
        print('No')
elif h&1 or w&1:
    if c1 <= 0 and c2 <= 1:
        print('Yes')
    else:
        print('No')
else:
    if c1 <= 0 and c2 <= 0:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
import sys


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

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

list = list(dict.values())

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

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

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

for i in range(len(list)):
    list[i] = list[i] % 4

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

if k == c:
    ans = 'Yes'

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

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

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

print('No')

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

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

if flg == 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 += list(input())
b = list(set(a))
c = []
count = h*w
for p in b:
    count -= (a.count(p) - a.count(p)%4)
    if a.count(p)%4:
        c.append((p, a.count(p)%4))
fin = []
for t in c:
    if t[1] == 2:
        count -= 2
    else:
        fin.append(t)

if h%2 and w%2:
    if len(fin) == 1 and fin[0][1] == count:
        print("Yes")
        exit()
else:
    if fin == [] and count == 0:
        print("Yes")
        exit()
print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
a = []
for i in range(h):
    a += list(input())
b = list(set(a))
c = []
count = h*w
for p in b:
    count -= a.count(p) - a.count(p)%4
    for _ in range(a.count(p)%4):
        c.append(p)
fin = []
for p in list(set(c)):
    if c.count(p) == 2:
        count -= 2
    else:
        for _ in range(c.count(p)):
            fin.append(p)
if h%2 == 1 and w%2 == 1:
    if len(set(fin)) == 1 and count == len(fin):
        print("Yes")
        exit()
else:
    if fin == [] and count == 0:
        print("Yes")
        exit()
print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
a = []
for i in range(h):
    a += list(input())
b = list(set(a))
c = []
count = h*w
for p in b:
    count -= (a.count(p)//4)*4
    for _ in range(a.count(p)%4):
        c.append(p)
fin = []
for p in list(set(c)):
    if c.count(p) == 2:
        count -= 2
    else:
        for _ in range(c.count(p)):
            fin.append(p)
if h%2 == 1 and w%2 == 1:
    if len(set(fin)) == 1 and count == len(fin):
        print("Yes")
        exit()
else:
    if fin == [] and count == 0:
        print("Yes")
        exit()
print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
a = []
for i in range(h):
    a += list(input())
b = list(set(a))
c = []
count = h*w
for p in b:
    count -= (a.count(p)//4)*4
    for _ in range(a.count(p)%4):
        c.append(p)
fin = []
for p in list(set(c)):
    if c.count(p) == 2:
        count -= 2
    else:
        for _ in range(c.count(p)):
            fin.append(p)
if h%2 and w%2:
    if len(set(fin)) == 1 and count == len(fin):
        print("Yes")
        exit()
else:
    if fin == [] and count == 0:
        print("Yes")
        exit()
print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
a = []
for i in range(h):
    a += list(input())
b = list(set(a))
c = []
count = h*w
for p in b:
    count -= (a.count(p)//4)*4
    for _ in range(a.count(p)%4):
        c.append(p)
fin = []
for p in list(set(c)):
    if c.count(p) == 2:
        count -= 2
    else:
        fin.append(p)
if h%2 and w%2:
    if len(set(fin)) == 1 and count == len(fin):
        print("Yes")
        exit()
else:
    if fin == [] and count == 0:
        print("Yes")
        exit()
print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
a = []
for i in range(h):
    a += list(input())
b = list(set(a))
c = []
count = h*w
for p in b:
    count -= (a.count(p)//4)*4
    for _ in range(a.count(p)%4):
        c.append(p)
if h % 2 == 0 and w % 2 == 0:
    if c == []:
        print("Yes")
        exit()
elif h % 2 == 0 and w % 2 == 1:
    if count % 2 == 0 and len(c) == count and len(set(c)) == count//2:
        print("Yes")
        exit()
elif h % 2 == 1 and w % 2 == 0:
    if count % 2 == 0 and len(c) == count and len(set(c)) == count//2:
        print("Yes")
        exit()
elif h % 2 == 1 and w % 2 == 1:
    if count % 2 and len(c) == count and (len(set(c)) == count//2 or len(set(c)) == count//2 + 1):
        print("Yes")
        exit()
print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
a = []
for i in range(h):
    a += list(input())
b = list(set(a))
c = []
for p in b:
    for _ in range(a.count(p)%4):
        c.append(p)
if h % 2 == 0 and w % 2 == 0:
    if c == []:
        print("Yes")
        exit()
elif h % 2 == 0 and w % 2 == 1:
    if len(c) == h and len(set(c)) == h//2:
        print("Yes")
        exit()
elif h % 2 == 1 and w % 2 == 0:
    if len(c) == w and len(set(c)) == w//2:
        print("Yes")
        exit()
elif h % 2 == 1 and w % 2 == 1:
    if len(c) == w + h - 1 and (len(set(c)) == w//2 + h//2 or len(set(c)) == w//2 + h//2 + 1):
        print("Yes")
        exit()
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
S = [[s for s in a] for a in A]
for s in S:
    c = collections.Counter(s)
    flg1 = 0
    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)
        flg2 = 0
        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:
                        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

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

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:
                        flg = 0
                        break

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