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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split(" "))

count_dict = {}

for i in range(h):
    x = input()
    for alph in x:
        if alph in count_dict.keys():
            count_dict[alph] += 1
        else:
            count_dict[alph] = 1


if (h % 2 == 0) and (w % 2 == 0):
    isAllQuat = True
    for alph in count_dict.keys():
        isAllQuat = isAllQuat and (count_dict[alph] % 4 == 0)
    rtn = isAllQuat
elif (h % 2 != 0) and (w % 2 == 0):
    for alph in count_dict.keys():
        count_dict[alph] = count_dict[alph] % 4

    isAllEven = True
    for alph in count_dict.keys():
        isAllEven = isAllEven and (count_dict[alph] % 2 == 0)

    rtn = isAllEven
elif (h % 2 == 0) and (w % 2 != 0):
    for alph in count_dict.keys():
        count_dict[alph] = count_dict[alph] % 4

    isAllEven = True
    for alph in count_dict.keys():
        isAllEven = isAllEven and (count_dict[alph] % 2 == 0)

    rtn = isAllEven
else:
    # num_odd = 0
    # for alph in count_dict.keys():
    #     a = count_dict[alph] % 4
    #
    #     if a % 2 != 0:
    #         num_odd += 1
    # rtn = (num_odd == 1)

    num_quat = 0
    num_odd = 0
    num_even = 0
    for alph in count_dict.keys():
        if count_dict[alph] >= 4:
            num_quat += int(count_dict[alph]/4)

            count_dict[alph] = (count_dict[alph] % 4)
            if (count_dict[alph] % 2 != 0):
                num_odd += 1
            else:
                num_even += 1

    rtn = (num_quat == (w*h - w - h + 1)/4) or (num_odd == 0) or (num_even == 0.5*(w+h)-1)

if rtn:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, raw_input().split())
d = {}
for i in range(h):
    ai = raw_input()
    for j in ai:
        if j in d:
            d[j] += 1
        else:
            d[j] = 1

once = 0
two = 0
ONCE_LIMIT = 0
if w % 2 == 1 and h % 2 == 1:
    ONCE_LIMIT = 1
    TWO_LIMIT = (w-1)/2 + (h-1)/2
elif w % 2 == 1:
    TWO_LIMIT = h/2
elif h % 2 == 1:
    TWO_LIMIT = w/2
else:
    TWO_LIMIT = 0
for v in d.values():
    if v % 2 == 1 and once == ONCE_LIMIT:
        print 'No'
        exit()
    if v%4 == 2 and two == TWO_LIMIT:
        print 'No'
        exit()
    if v%4 == 2:
        two += 1
    if v % 2 == 1:
        once += 1
print 'YES'

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split(" "))

count_dict = {}

for i in range(h):
    x = input()
    for alph in x:
        if alph in count_dict.keys():
            count_dict[alph] += 1
        else:
            count_dict[alph] = 1


if (h % 2 == 0) and (w % 2 == 0):
    isAllQuat = True
    for alph in count_dict.keys():
        isAllQuat = isAllQuat and (count_dict[alph] % 4 == 0)
    rtn = isAllQuat
elif (h % 2 != 0) and (w % 2 == 0):
    for alph in count_dict.keys():
        count_dict[alph] = count_dict[alph] % 4

    isAllEven = True
    for alph in count_dict.keys():
        isAllEven = isAllEven and (count_dict[alph] % 2 == 0)

    rtn = isAllEven
elif (h % 2 == 0) and (w % 2 != 0):
    for alph in count_dict.keys():
        count_dict[alph] = count_dict[alph] % 4

    isAllEven = True
    for alph in count_dict.keys():
        isAllEven = isAllEven and (count_dict[alph] % 2 == 0)

    rtn = isAllEven
else:
    # num_odd = 0
    # for alph in count_dict.keys():
    #     a = count_dict[alph] % 4
    #
    #     if a % 2 != 0:
    #         num_odd += 1
    # rtn = (num_odd == 1)

    num_quat = 0
    num_odd = 0
    for alph in count_dict.keys():
        if count_dict[alph] >= 4:
            num_quat += int(count_dict[alph]/4)

            count_dict[alph] = (count_dict[alph] % 4)
            if (count_dict[alph] % 2 != 0):
                num_odd += 1

    rtn = (num_quat == (w*h - w - h + 1)/4) or (num_odd == 0)

if rtn:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split(" "))

count_dict = {}

for i in range(h):
    x = input()
    for alph in x:
        if alph in count_dict.keys():
            count_dict[alph] += 1
        else:
            count_dict[alph] = 1


if (h % 2 == 0) and (w % 2 == 0):
    isAllQuat = True
    for alph in count_dict.keys():
        isAllQuat = isAllQuat and (count_dict[alph] % 4 == 0)
    rtn = isAllQuat
elif (h % 2 != 0) and (w % 2 == 0):
    for alph in count_dict.keys():
        count_dict[alph] = count_dict[alph] % 4

    isAllEven = True
    for alph in count_dict.keys():
        isAllEven = isAllEven and (count_dict[alph] % 2 == 0)

    rtn = isAllEven
elif (h % 2 == 0) and (w % 2 != 0):
    for alph in count_dict.keys():
        count_dict[alph] = count_dict[alph] % 4

    isAllEven = True
    for alph in count_dict.keys():
        isAllEven = isAllEven and (count_dict[alph] % 2 == 0)

    rtn = isAllEven
else:
    # num_odd = 0
    # for alph in count_dict.keys():
    #     a = count_dict[alph] % 4
    #
    #     if a % 2 != 0:
    #         num_odd += 1
    # rtn = (num_odd == 1)

    num_quat = 0
    num_odd = 0
    for alph in count_dict.keys():
        if count_dict[alph] >= 4:
            num_quat += int(count_dict[alph]/4)

            count_dict[alph] = (count_dict[alph] % 4)
            if (count_dict[alph] % 2 != 0):
                num_odd += 1

    rtn = (num_quat == (w*h - w - h + 1)/4) and (num_odd == 0)

if rtn:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, raw_input().split())
d = {}
for i in range(h):
    ai = raw_input()
    for j in ai:
        if j in d:
            d[j] += 1
        else:
            d[j] = 1

once = 0
if h == 1 and w == 1:
    print 'Yes'
else:
    two = 0
    ONCE_LIMIT = 0
    if w % 2 == 1 and h % 2 == 1:
        ONCE_LIMIT = 1
        TWO_LIMIT = (w-1)/2 + (h-1)/2
    elif w % 2 == 1:
        TWO_LIMIT = h/2
    elif h % 2 == 1:
        TWO_LIMIT = w/2
    else:
        TWO_LIMIT = 0
    for v in d.values():
        if v % 2 == 1 and once == ONCE_LIMIT:
            print 'No'
            exit()
        if v%4 == 2 and two == TWO_LIMIT:
            print 'No'
            exit()
        if v%4 == 2:
            two += 1
        if v % 2 == 1:
            once += 1
    print 'YES'

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split(" "))

count_dict = {}

for i in range(h):
    x = input()
    for alph in x:
        if alph in count_dict.keys():
            count_dict[alph] += 1
        else:
            count_dict[alph] = 1


if (h % 2 == 0) and (w % 2 == 0):
    isAllQuat = True
    for alph in count_dict.keys():
        isAllQuat = isAllQuat and (count_dict[alph] % 4 == 0)
    rtn = isAllQuat
elif (h % 2 != 0) and (w % 2 == 0):
    for alph in count_dict.keys():
        count_dict[alph] = count_dict[alph] % 4

    isAllEven = True
    for alph in count_dict.keys():
        isAllEven = isAllEven and (count_dict[alph] % 2 == 0)

    rtn = isAllEven
elif (h % 2 == 0) and (w % 2 != 0):
    for alph in count_dict.keys():
        count_dict[alph] = count_dict[alph] % 4

    isAllEven = True
    for alph in count_dict.keys():
        isAllEven = isAllEven and (count_dict[alph] % 2 == 0)

    rtn = isAllEven
else:
    # num_odd = 0
    # for alph in count_dict.keys():
    #     a = count_dict[alph] % 4
    #
    #     if a % 2 != 0:
    #         num_odd += 1
    # rtn = (num_odd == 1)

    num_quat = 0
    for alph in count_dict.keys():
        if count_dict[alph] >= 4:
            num_quat += int(count_dict[alph]/4)
            
            count_dict[alph] = (count_dict[alph] % 4)
    rtn = (num_quat == (w*h - w - h + 1)/4)

if rtn:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, raw_input().split())
d = {}
for i in range(h):
    ai = raw_input()
    for j in ai:
        if j in d:
            d[j] += 1
        else:
            d[j] = 1

once = 0
if h == 1 and w == 1:
    print 'Yes'
    two = 0
    ONCE_LIMIT = 0
    if w % 2 == 1 and h % 2 == 1:
        ONCE_LIMIT = 1
        TWO_LIMIT = (w-1)/2 + (h-1)/2
    elif w % 2 == 1:
        TWO_LIMIT = h/2
    elif h % 2 == 1:
        TWO_LIMIT = w/2
    else:
        TWO_LIMIT = 0
    for v in d.values():
        if v % 2 == 1 and once == ONCE_LIMIT:
            print 'No'
            exit()
        if v%4 == 2 and two == TWO_LIMIT:
            print 'No'
            exit()
        if v%4 == 2:
            two += 1
        if v % 2 == 1:
            once += 1
    print 'YES'

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split(" "))

count_dict = {}

for i in range(h):
    x = input()
    for alph in x:
        if alph in count_dict.keys():
            count_dict[alph] += 1
        else:
            count_dict[alph] = 1


if (h % 2 == 0) and (w % 2 == 0):
    isAllQuat = True
    for alph in count_dict.keys():
        isAllQuat = isAllQuat and (count_dict[alph] % 4 == 0)
    rtn = isAllQuat
elif (h % 2 != 0) and (w % 2 == 0):
    for alph in count_dict.keys():
        count_dict[alph] = count_dict[alph] % 4

    isAllEven = True
    for alph in count_dict.keys():
        isAllEven = isAllEven and (count_dict[alph] % 2 == 0)

    rtn = isAllEven
elif (h % 2 == 0) and (w % 2 != 0):
    for alph in count_dict.keys():
        count_dict[alph] = count_dict[alph] % 4

    isAllEven = True
    for alph in count_dict.keys():
        isAllEven = isAllEven and (count_dict[alph] % 2 == 0)

    rtn = isAllEven
else:
    # num_odd = 0
    # for alph in count_dict.keys():
    #     a = count_dict[alph] % 4
    #
    #     if a % 2 != 0:
    #         num_odd += 1
    # rtn = (num_odd == 1)

    num_quat = 0
    for alph in count_dict.keys():
        if count_dict[alph] >= 4:
            count_dict[alph] = (count_dict[alph] % 4)
            num_quat += int(count_dict[alph]/4)
    rtn = (num_quat == (w*h - w - h + 1)/4)

if rtn:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split(" "))

count_dict = {}

for i in range(h):
    x = input()
    for alph in x:
        if alph in count_dict.keys():
            count_dict[alph] += 1
        else:
            count_dict[alph] = 1


if (h % 2 == 0) and (w % 2 == 0):
    isAllQuat = True
    for alph in count_dict.keys():
        isAllQuat = isAllQuat and (count_dict[alph] % 4 == 0)
    rtn = isAllQuat
elif (h % 2 != 0) and (w % 2 == 0):
    for alph in count_dict.keys():
        count_dict[alph] = count_dict[alph] % 4

    isAllEven = True
    for alph in count_dict.keys():
        isAllEven = isAllEven and (count_dict[alph] % 2 == 0)

    rtn = isAllEven
elif (h % 2 == 0) and (w % 2 != 0):
    for alph in count_dict.keys():
        count_dict[alph] = count_dict[alph] % 4

    isAllEven = True
    for alph in count_dict.keys():
        isAllEven = isAllEven and (count_dict[alph] % 2 == 0)

    rtn = isAllEven
else:
    # num_odd = 0
    # for alph in count_dict.keys():
    #     a = count_dict[alph] % 4
    #
    #     if a % 2 != 0:
    #         num_odd += 1
    # rtn = (num_odd == 1)

    num_quat = 0
    for alph in count_dict.keys():
        if count_dict[alph] >= 4:
            count_dict[alph] = (count_dict[alph] % 4)
            num_quat += int(count_dict[alph]/4)
    rtn = (num_quat == (w + h - 2)/2 )

if rtn:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, raw_input().split())
d = {}
for i in range(h):
    ai = raw_input()
    for j in ai:
        if j in d:
            d[j] += 1
        else:
            d[j] = 1

once = 0
if h == 1 and w == 1:
    print 'Yes'
elif h == 1 or w == 1:
    for v in d.values():
        if v % 2 == 1 and once == 1:
            print 'No'
            exit()
        if v % 2 == 1:
            once = 1
    print 'Yes'
else:
    two = 0
    ONCE_LIMIT = 0
    if w % 2 == 1 and h % 2 == 1:
        ONCE_LIMIT = 1
        TWO_LIMIT = (w-1)/2 + (h-1)/2
    elif w % 2 == 1:
        TWO_LIMIT = h/2
    elif h % 2 == 1:
        TWO_LIMIT = w/2
    else:
        TWO_LIMIT = 0
    for v in d.values():
        if v % 2 == 1 and once == ONCE_LIMIT:
            print 'No'
            exit()
        if v%4 == 2 and two == TWO_LIMIT:
            print 'No'
            exit()
        if v%4 == 2:
            two += 1
        if v % 2 == 1:
            once += 1
    print 'YES'

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split(" "))

count_dict = {}

for i in range(h):
    x = input()
    for alph in x:
        if alph in count_dict.keys():
            count_dict[alph] += 1
        else:
            count_dict[alph] = 1


if (h % 2 == 0) and (w % 2 == 0):
    isAllQuat = True
    for alph in count_dict.keys():
        isAllQuat = isAllQuat and (count_dict[alph] % 4 == 0)
    rtn = isAllQuat
elif (h % 2 != 0) and (w % 2 == 0):
    for alph in count_dict.keys():
        count_dict[alph] = count_dict[alph] % 4

    isAllEven = True
    for alph in count_dict.keys():
        isAllEven = isAllEven and (count_dict[alph] % 2 == 0)

    rtn = isAllEven
elif (h % 2 == 0) and (w % 2 != 0):
    for alph in count_dict.keys():
        count_dict[alph] = count_dict[alph] % 4

    isAllEven = True
    for alph in count_dict.keys():
        isAllEven = isAllEven and (count_dict[alph] % 2 == 0)

    rtn = isAllEven
else:
    num_odd = 0
    for alph in count_dict.keys():
        a = count_dict[alph] % 4

        if a % 2 != 0:
            num_odd += 1
    rtn = (num_odd == 1)

if rtn:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter
H, W = list(map(int, input().split()))
cnt = Counter()
for i in range(H):
    ls = list(map(str, input().split()))
    for j in ls:
        A = Counter(j)
        cnt += A

ki = 0
gu = 0
f = 0
cnto = 0
for i, j in cnt.most_common():
    cnto += 1
    if (j % 2) != 0:
        ki += 1
    elif (j % 2) == 0:
        gu += 1
    elif (j %4) == 0:
        f += 1
oth = cnto - f


if H == 1 and W == 1:
    print('Yes')
elif (H == 1 or W == 1) and ki == 1:
    print('Yes')
elif oth == 0 and H%2 == 0 and W%2 == 0:
    print('Yes')
elif H%2 != 0 and W%2 == 0 and gu == int(H/2):
    print('Yes')
elif H%2 == 0 and W%2 != 0 and gu == int(W/2):
    print('Yes')
elif H%2 != 0 and W%2 != 0 and gu == int(W/2) + int(H/2):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split(" "))

count_dict = {}

for i in range(h):
    x = input()
    for alph in x:
        if alph in count_dict.keys():
            count_dict[alph] += 1
        else:
            count_dict[alph] = 1


if (h % 2 == 0) and (w % 2 == 0):
    isAllQuat = True
    for alph in count_dict.keys():
        isAllQuat = isAllQuat and (count_dict[alph] % 4 == 0)
    rtn = isAllQuat
elif ((h % 2 == 0) and (w % 2 != 0)) or ((h % 2 != 0) and (w % 2 == 0)):
    for alph in count_dict.keys():
        count_dict[alph] = count_dict[alph] % 4

    isAllEven = True
    for alph in count_dict.keys():
        isAllEven = isAllEven and (count_dict[alph] % 2 == 0)

    rtn = isAllEven
else:
    # num_odd = 0
    # for alph in count_dict.keys():
    #     a = count_dict[alph] % 4
    #
    #     if a % 2 != 0:
    #         num_odd += 1
    # rtn = (num_odd == 1)
    rtn = False

if rtn:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split(" "))

count_dict = {}

for i in range(h):
    x = input()
    for alph in x:
        if alph in count_dict.keys():
            count_dict[alph] += 1
        else:
            count_dict[alph] = 1


if (h % 2 == 0) and (w % 2 == 0):
    isAllQuat = True
    for alph in count_dict.keys():
        isAllQuat = isAllQuat and (count_dict[alph] % 4 == 0)
    rtn = isAllQuat
elif ((h % 2 == 0) and (w % 2 != 0)) or ((h % 2 != 0) and (w % 2 == 0)):
    for alph in count_dict.keys():
        count_dict[alph] = count_dict[alph] % 4

    isAllEven = True
    for alph in count_dict.keys():
        isAllEven = isAllEven and (count_dict[alph] % 2 == 0)

    rtn = isAllEven
else:
    # num_odd = 0
    # for alph in count_dict.keys():
    #     a = count_dict[alph] % 4
    #
    #     if a % 2 != 0:
    #         num_odd += 1
    # rtn = (num_odd == 1)
    rtn = True

if rtn:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, raw_input().split())
d = {}
for i in range(h):
    ai = raw_input()
    for j in ai:
        if j in d:
            d[j] += 1
        else:
            d[j] = 1

once = 0
if h == 1 and w == 1:
    print 'Yes'
elif h == 1 or w == 1:
    for v in d.values():
        if v % 2 == 1 and once == 1:
            print 'No'
            exit()
        if v % 2 == 1:
            once = 1
    print 'Yes'
else:
    two = 0
    if w % 2 == 1 and h % 2 == 1:
        ONCE_LIMIT = 1
        TWO_LIMIT = (w-1)/2 + (h-1)/2
    elif w % 2 == 1:
        ONCE_LIMIT = 0
        TWO_LIMIT = h/2
    elif h % 2 == 1:
        ONCE_LIMIT = 0
        TWO_LIMIT = w/2
    else:
        ONCE_LIMIT = 0
        TWO_LIMIT = 0
    for v in d.values():
        if once == ONCE_LIMIT and v % 2 == 1:
            print 'No'
            exit()
        if two == TWO_LIMIT and v%4 == 2:
            print 'No'
            exit()
        if v%4 == 2:
            two += 1
        if v % 2 == 1:
            once += 1
    print 'YES'

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split(" "))

count_dict = {}

for i in range(h):
    x = input()
    for alph in x:
        if alph in count_dict.keys():
            count_dict[alph] += 1
        else:
            count_dict[alph] = 1


if (h % 2 == 0) and (w % 2 == 0):
    isAllQuat = True
    for alph in count_dict.keys():
        isAllQuat = isAllQuat and (count_dict[alph] % 4 == 0)
    rtn = isAllQuat
elif ((h % 2 == 0) and (w % 2 != 0)) or ((h % 2 != 0) and (w % 2 == 0)):
    for alph in count_dict.keys():
        count_dict[alph] = count_dict[alph] % 4

    isAllEven = True
    for alph in count_dict.keys():
        isAllEven = isAllEven and (count_dict[alph] % 2 == 0)

    rtn = isAllEven
else:
    num_odd = 0
    for alph in count_dict.keys():
        a = count_dict[alph] % 4

        if a % 2 != 0:
            num_odd += 1
    rtn = (num_odd == 1)

if rtn:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, raw_input().split())
d = {}
for i in range(h):
    ai = raw_input()
    for j in ai:
        if j in d:
            d[j] += 1
        else:
            d[j] = 1

once = 0
if h == 1 and w == 1:
    print 'Yes'
elif h % 2 == 1 or w % 2 == 1:
    for v in d.values():
        if v % 2 == 1 and once == 1:
            print 'No'
            exit()
        if v % 2 == 1:
            once = 1
    print 'Yes'
else:
    two = 0
    if w % 2 == 1 and h % 2 == 1:
        ONCE_LIMIT = 1
        TWO_LIMIT = (w-1)/2 + (h-1)/2
    elif w % 2 == 1:
        ONCE_LIMIT = 0
        TWO_LIMIT = h/2
    elif h % 2 == 1:
        ONCE_LIMIT = 0
        TWO_LIMIT = w/2
    else:
        ONCE_LIMIT = 0
        TWO_LIMIT = 0
    for v in d.values():
        if once == ONCE_LIMIT and v % 2 == 1:
            print 'No'
            exit()
        if two == TWO_LIMIT and v%4 == 2:
            print 'No'
            exit()
        if v%4 == 2:
            two += 1
        if v % 2 == 1:
            once += 1
    print 'YES'

Submission status: Wrong Answer

Solution code:
h, w = map(int, raw_input().split())
d = {}
for i in range(h):
    ai = raw_input()
    for j in ai:
        if j in d:
            d[j] += 1
        else:
            d[j] = 1

once = 0
if h == 1 and w == 1:
    print 'Yes'
elif h == 1 or w == 1:
    if w % 2 == 1:
        for v in d.values():
            if v % 2 == 1 and once == 1:
                print 'No'
                exit()
            if v % 2 == 1:
                once = 1
        print 'Yes'
    else:
        for v in d.values():
            if v % 2 == 1:
                print 'No'
                exit()
        print 'Yes'
else:
    two = 0
    if w % 2 == 1 and h % 2 == 1:
        ONCE_LIMIT = 1
        TWO_LIMIT = (w-1)/2 + (h-1)/2
    elif w % 2 == 1:
        ONCE_LIMIT = 0
        TWO_LIMIT = h/2
    elif h % 2 == 1:
        ONCE_LIMIT = 0
        TWO_LIMIT = w/2
    else:
        ONCE_LIMIT = 0
        TWO_LIMIT = 0
    for v in d.values():
        if once == ONCE_LIMIT and v % 2 == 1:
            print 'No'
            exit()
        if two == TWO_LIMIT and v%4 == 2:
            print 'No'
            exit()
        if v%4 == 2:
            two += 1
        if v % 2 == 1:
            once += 1
    print 'YES'

Submission status: Wrong Answer

Solution code:
from collections import Counter
H, W = list(map(int, input().split()))
cnt = Counter()
for i in range(H):
    ls = list(map(str, input().split()))
    for j in ls:
        A = Counter(j)
        cnt += A
k = 1
if H%2 == 0 and W%2 == 0:
    k = 0
elif H%2 != 0 and W%2 == 0:
    k = W
elif H%2 == 0 and W%2 != 0:
    k = H
else:
    k = H*W

p = 0
for i, j in cnt.most_common():
    if (j % 2) != 0:
        p += 1

if p == k:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter
H, W = list(map(int, input().split()))
cnt = Counter()
for i in range(H):
    ls = list(map(str, input().split()))
    for j in ls:
        A = Counter(j)
        cnt += A
k = 1
if H%2 == 0 and W%2 == 0:
    k = 0
elif H%2 != 0 and W%2 == 0:
    k = W
elif H%2 == 0 and W%2 != 0:
    k = H
else:
    k = H*W

p = 0
for i, j in cnt.most_common():
    if (j % 2) != 1:
        p += 1

if p == k:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter
H, W = list(map(int, input().split()))
cnt = Counter()
for i in range(H):
    ls = list(map(str, input().split()))
    for j in ls:
        A = Counter(j)
        cnt += A
k = 1
if H%2 == 0 and W%2 == 0:
    k = 0
elif H%2 != 0 and W%2 == 0:
    k = W
elif H%2 == 0 and W%2 != 0:
    k = H
else:
    k = H*W

p = 0
for i, j in cnt.most_common():
    if (j % 2) != 1:
        p += 1

if p == k:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
from collections import Counter
H, W = list(map(int, input().split()))
cnt = Counter()
for i in range(H):
    ls = list(map(str, input().split()))
    for j in ls:
        A = Counter(j)
        cnt += A
k = 1
if H%2 == 0 and W%2 == 0:
    k = 0
elif H%2 != 0 and W%2 == 0:
    k = W
elif H%2 == 0 and W%2 != 0:
    k = H
else:
    k = H*W

p = 0
for i, j in cnt.most_common():
    if (j % 2) != 1:
        p += 1

if p >= k:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter()
for i in range(H):
    c += Counter(list(input()))
cl = sorted(list(c.values()),reverse=True)

if H%2 == 0 and W%2 == 0:
    a = [4]*(H*W//4)
elif H%2 == 0 and W%2 == 1:
    a = [4]*((H-1)*W//4)
    a.extend([2]*(H//2))
elif H%2 == 1 and W%2 == 0:
    a = [4]*(H*(W-1)//4)
    a.extend([2]*(W//2))
elif H%2 == 1 and W%2 == 1:
    a = [4]*((H*W-H-W+1)//4)
    a.extend([2]*((H+W-2)//2))
    a.append(1)
a = sorted(a)
if len(cl) > len(a):
    print("No")
    exit()
else:
    for b in a:
        for i,c in enumerate(cl):
            if b == 1 and c%4 == 1:
                cl[i] -= b
                break
            if b == 2 and c%4 == 2:
                cl[i] -= b
                break
            if b == 4 and c%4 == 0 and c >= 4:
                cl[i] -= b
                break            
            if i == len(cl)-1:
                print("No")
                exit()
if sum(cl) == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter()
for i in range(H):
    c += Counter(list(input()))
cl = sorted(list(c.values()),reverse=True)

if H%2 == 0 and W%2 == 0:
    a = [4]*(H*W//4)
elif H%2 == 0 and W%2 == 1:
    a = [4]*((H-1)*W//4)
    a.extend([2]*(H//2))
elif H%2 == 1 and W%2 == 0:
    a = [4]*(H*(W-1)//4)
    a.extend([2]*(W//2))
elif H%2 == 1 and W%2 == 1:
    a = [4]*((H*W-H-W+1)//4)
    a.extend([2]*((H+W-2)//2))
    a.append(1)
a = sorted(a)
if len(cl) > len(a):
    print("No")
    exit()
else:
    for b in a:
        for i,c in enumerate(cl):
            if b == 1 and c%4 == 1:
                cl[i] -= b
                break
            if b == 2 and c%4 == 2:
                cl[i] -= b
                break
            if b == 4 and c%4 == 0:
                cl[i] -= b
                break            
            if i == len(cl)-1:
                print("No")
                exit()
if sum(cl) == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter()
for i in range(H):
    c += Counter(list(input()))
cl = sorted(list(c.values()),reverse=True)

if H%2 == 0 and W%2 == 0:
    a = [4]*(H*W//4)
elif H%2 == 0 and W%2 == 1:
    a = [4]*((H-1)*W//4)
    a.extend([2]*(H//2))
elif H%2 == 1 and W%2 == 0:
    a = [4]*(H*(W-1)//4)
    a.extend([2]*(W//2))
elif H%2 == 1 and W%2 == 1:
    a = [4]*((H*W-H-W+1)//4)
    a.extend([2]*((H+W-2)//2))
    a.append(1)

if len(cl) > len(a):
    print("No")
    exit()
else:
    for a in a:
        for i,c in enumerate(cl):
            if c - a >= 0:
                cl[i] -= a
                break
            if i == len(cl)-1:
                print("No")
                exit()
print("Yes")