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:
from sys import stdin
n,m = map(int,stdin.readline().split())
di = {}
for _ in xrange(n):
    a = stdin.readline().strip()
    for i in a:
        di[i] = di.get(i,0) + 1
ev = 0
od = 0
for i in di:
    if di[i]%4==2:
        ev+=1
    elif di[i]%4==3:
        od+=1
        ev+=1
    elif di[i]%4==1:
        od+=1
ans = 'Yes'
ma = max(n/2, m/2)
if od>1:
    ans = 'No'
elif (n*m)%2==0 and od>0:
    ans = 'No'
else:
    if n%2==0 and m%2==0:
        if ev > 0:
            ans = 'No'
    elif n%2==0:
        if ev > ma:
            ans = 'No'
    elif m%2==0:
        if ev > ma:
            ans = 'No'
    else:
        if ev > (n/2) + (m/2):
            ans = 'No'
print ans

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !

H , W  = input().split()
H = int(H)
W = int(W)
OK = False

st = ""
for n in range(H):
    st += input()
    
counter = {}
for c in st:
    if not c in counter:
        counter[c] = 1
    else:
        counter[c] += 1

#H,Wが偶数の時
if (H % 2 == 0) & (W % 2 == 0) :
    for i in counter.keys():
        if not (counter[i] % 4 == 0) : 
            #一度でも4の倍数でなかったらだめ
            OK = False
            break
        OK = True
elif (H % 2 != 0) & (W % 2 != 0) :
    #一個の奴が必ず一つある -> 奇数が必ず一つある
    kisuuCounter = 0
    for i in counter.keys():
        if counter[i] % 2 == 1 : 
            kisuuCounter += 1
            kisuu = i
    
    if kisuuCounter == 1 : 
        counter[kisuu] -= 1
        twoPair = (W + H - 2) / 2
        q = {i : (counter[i] % 4) / 2 for i in counter.keys()}
        p = {i: (counter[i] - 2*q[i]) / 4 for i in counter.keys() }
        
        x = twoPair - sum(q.values())
        if (x % 2 == 0) & (x <= 2 * sum(p.values())) : 
            OK = True
else :
    kisuuCounter = 0
    for i in counter.keys():
        if counter[i] % 2 == 1 : 
            kisuuCounter += 1
            kisuu = i
    
    if kisuuCounter == 0 :
        if H % 2 == 0 : 
            twoPair = H / 2
        else : 
            twoPair = W / 2
        
        q = {i : (counter[i] % 4) / 2 for i in counter.keys()}
        p = {i: (counter[i] - 2*q[i]) / 4 for i in counter.keys() }
        x = twoPair - sum(q.values())
        if (x % 2 == 0) & (x <= 2 * sum(p.values())) : 
            OK = True
        
if OK : print("Yes")
else : print("No")

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import Counter
H,W = map(int, input().split())

a = [
    input()
    for _ in range(H)
]

tmp = []
for aa in a:
    for c in aa:
        tmp.append(c)


cc = Counter(tmp)

if (int(math.ceil(H/2.0)) + int(math.ceil(W/2.0)) - 1 - len(cc.keys())) >= 0:
    one = 0
    for _, a in cc.items():
        if a == 1:
            one += 1

    if one > 1:
        print('No')
    else:
        print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from sys import stdin
n,m = map(int,stdin.readline().split())
di = {}
for _ in xrange(n):
    a = stdin.readline().strip()
    for i in a:
        di[i] = di.get(i,0) + 1
ev = 0
od = 0
for i in di:
    if di[i]%4==2:
        ev+=1
    elif di[i]%4==3:
        od+=1
        ev+=1
    elif di[i]%4==1:
        od+=1
ans = 'Yes'
if od>1:
    ans = 'No'
elif (n*m)%2==0 and od>0:
    ans = 'No'
else:
    if n%2==0 and m%2==0:
        if ev > 0:
            ans = 'No'
    elif n%2==0:
        if ev > m/2:
            ans = 'No'
    elif m%2==0:
        if ev > n/2:
            ans = 'No'
    else:
        if ev > (n/2) + (m/2):
            ans = 'No'
print ans

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import Counter
H,W = map(int, input().split())

a = [
    input()
    for _ in range(H)
]

tmp = []
for aa in a:
    for c in aa:
        tmp.append(c)


cc = Counter(tmp)

if (int(math.ceil(H/2.0)) + int(math.ceil(W/2.0)) - 1 - len(cc.keys())) >= 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import itertools
import sys

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

a = [input() for i in range(h)]
words = list(set(itertools.chain(*a)))
at = list(itertools.chain(*a))

mods = []
for word in words:
    mod = at.count(word) % 4
    if mod:
        mods.append(mod)
    else:
        mods.append(4)

mods = list(sorted(mods))
def count_down(l, n):
    for i in range(len(l)):
        if l[i] - n >= 0:
            l[i] -= n
            if not l[i]:
                del l[i]
            return True
    return False

if h % 2 and w % 2:
    flg = False
    for i in range(w // 2 + h // 2):
        flg = count_down(mods, 2)
    if flg and count_down(mods, 1):
        print("Yes")
        sys.exit()

elif h % 2:
    flg = False
    for i in range(w // 2):
        flg = count_down(mods, 2)
    if flg:
        print("Yes")
        sys.exit()

elif w % 2:
    flg = False
    for i in range(h // 2):
        flg = count_down(mods, 2)
    if flg:
        print("Yes")
        sys.exit()

else:
    if mods.count(4) == len(mods):
        print("Yes")
        sys.exit()

print("No")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def foo():
	H, W = map(int, input().split())
	s = ""
	for _ in range(H):
		s += input()

	counter = defaultdict(int)
	for c in s:
		counter[c] += 1

	x1, x2 = H // 2, H % 2
	y1, y2 = W // 2, W % 2

	n = x1 * y1
	k = 0
	for c in counter:
		if k == n:
			break
		if counter[c] >= 4:
			k += 1
			counter[c] -= 4

	if k != n:
		print("No")
		return

	if x2 == 1:
		n = y1
		k = 0
		for c in counter:
			if k == n:
				break
			if counter[c] >= 2:
				k += 1
				counter[c] -= 2
		if k != n:
			print("No")
			return
	if y2 == 1:
		n = x1
		k = 0
		for c in counter:
			if k == n:
				break
			if counter[c] >= 2:
				k += 1
				counter[c] -= 2
		if k != n:
			print("No")
			return
	print("Yes")

foo()

Submission status: Wrong Answer

Solution code:
from sys import stdin
n,m = map(int,stdin.readline().split())
di = {}
for _ in xrange(n):
    a = stdin.readline().strip()
    for i in a:
        di[i] = di.get(i,0) + 1
ev = 0
od = 0
for i in di:
    if di[i]%4==2:
        ev+=1
    elif di[i]%4==3:
        od+=1
        ev+=1
    elif di[i]%4==1:
        od+=1
ans = 'Yes'
if od>1:
    ans = 'No'
elif (n*m)%2==0 and od>0:
    ans = 'No'
else:
    if n%2==0 and m%2==0:
        if ev > 0:
            ans = 'No'
    elif n%2==0:
        if ev > m/2:
            ans = 'No'
    elif m%2==0:
        if ev > n/2:
            ans = 'No'
    else:
        if ev > n/2 + m/2:
            ans = 'No'
print ans

Submission status: Wrong Answer

Solution code:
raw1 = input().split()
H = int(raw1[0])
W = int(raw1[1])

c = [0 for x in range(26)]

for i in range(H):
    raw = input()
    for j in range(W):
        c[ord(raw[j]) - 97] += 1

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


if c.count(3) > 0 :
    print('No')
elif W%2 == 1 and H%2 == 1 and c.count(1) == 1 and c.count(2) >= (H-1)/2 +(W-1)/2:
    print('Yes')
elif W%2 == 0 and H%2==0 and c.count(1)==0 and c.count(2) ==0:
    print('Yes')
elif W % 2 ==0 and  H % 2  == 1 and c.count(1) == 0 and c.count(2) >= W/2:
    print('Yes')
elif W % 2 ==1 and  H % 2  == 0 and c.count(1) == 0 and c.count(2) >= H/2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
#! -*- coding:utf-8 -*-
import collections
H,W = map(int,input().split())

arr = [[0]*W]*H

for i in range(H):
    arr[i] = list(input())
    
if H == 1 and W == 1:
    print('Yes')
elif H == 1 or W == 1:
    stock = []
    count = 0
    for i in range(H):
        for j in range(W):
            if arr[i][j] in stock:
                count += 1
                stock.remove(arr[i][j])
            else:
                stock.append(arr[i][j])

    if H == 1 and W%2 == 0:
        if count == W//2:
            print('Yes')
        else:
            print('No')
    elif H == 1 and W%2 == 1:
        if count == W//2:
            print('Yes')
        else:
            print('No')
    elif W == 1 and H%2 == 0:
        if count == H//2:
            print('Yes')
        else:
            print('No')
    elif W == 1 and H%2 == 1:
        if count == H//2:
            print('Yes')
        else:
            print('No')
            
else:
    li = [ y for x in arr for y in x]
    count_dict = collections.Counter(li)
    #print(count_dict)
    if H%2 == 0 and W%2 == 0:
        flag = 0
        for k,v in count_dict.items():
            if v%4 != 0:
                flag = 1

        if flag == 0:
            print('Yes')
        else:
            print('No')
    elif H%2 == 1 and W%2 == 1:
        flag1 = 0
        flag2 = 0
        flag3 = 0
        for k,v in count_dict.items():
            if v%4 != 0:
                if v % 2 == 0:
                    flag2 += 1
                elif v % 2 == 1:
                    flag3 += 1
                else:
                    flag1 = 1
        #print(flag1,flag2,flag3)
        if (flag1 == 0 and flag2 == 2 and flag3 == 1) or (flag1 == 0 and flag2 == 0 and flag3 == 1):
            print('Yes')
        else:
            print('No')

    else:
        flag1 = 0
        flag2 = 0
        for k,v in count_dict.items():
            if v%4 != 0:
                if v % 4 == 2:
                    flag2 += 1
                else:
                    flag1 = 1
        #print(flag1,flag2,flag3)
        if (flag1 == 0 and flag2 == 1):
            print('Yes')
        else:
            print('No')

Submission status: Wrong Answer

Solution code:
from sys import stdin
n,m = map(int,stdin.readline().split())
di = {}
for _ in xrange(n):
    a = stdin.readline().strip()
    for i in a:
        di[i] = di.get(i,0) + 1
ev = 0
od = 0
for i in di:
    if di[i]%4==2:
        ev+=1
    elif di[i]%4==3:
        od+=1
        ev+=1
    elif di[i]%4==1:
        od+=1
ans = 'Yes'
if od>1:
    ans = 'No'
elif (n*m)%2==0 and od>0:
    ans = 'No'
else:
    if n%2==0 and m%2==0:
        if ev > 0:
            ans = 'No'
    elif n%2==0:
        if ev > m/2:
            ans = 'No'
    elif m%2==0:
        if ev > m/2:
            ans = 'No'
    else:
        if ev > n/2 + m/2:
            ans = 'No'
print ans

Submission status: Wrong Answer

Solution code:
raw1 = input().split()
H = int(raw1[0])
W = int(raw1[1])

c = [0 for x in range(26)]

for i in range(H):
    raw = input()
    for j in range(W):
        c[ord(raw[j]) - 97] += 1

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


if c.count(3) > 0 :
    print('No')
elif W%2 == 1 and H%2 == 1 and c.count(1) == 1 and c.count(2) == (H-1)/2 +(W-1)/2:
    print('Yes')
elif W%2 == 0 and H%2==0 and c.count(1)==0 and c.count(2) ==0:
    print('Yes')
elif W % 2 ==0 and  H % 2  == 1 and c.count(1) == 0 and c.count(2) == W/2:
    print('Yes')
elif W % 2 ==1 and  H % 2  == 0 and c.count(1) == 0 and c.count(2) == H/2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
raw1 = input().split()
H = int(raw1[0])
W = int(raw1[1])

c = [0 for x in range(26)]

for i in range(H):
    raw = input()
    for j in range(W):
        c[ord(raw[j]) - 97] += 1

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


if c.count(3) > 0 :
    print('No')
elif W%2 == 1 and H%2 == 1 and c.count(1) == 1 and c.count(2) == (H-1)/2 +(W-1)/2:
    print('Yes')
elif W%2 == 0 and H%2==0 and c.count(1)==0 and c.count(2) ==0:
    print('Yes')
elif W % 2 ==0 and  H % 2  == 1 and c.count(1) == 0 and c.count(2)%2 == W/2:
    print('Yes')
elif W % 2 ==1 and  H % 2  == 0 and c.count(1) == 0 and c.count(2)%2 == H/2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def foo():
	H, W = map(int, input().split())
	s = ""
	for _ in range(H):
		s += input()

	counter = defaultdict(int)
	for c in s:
		counter[c] += 1

	x1, x2 = H // 2, H % 2
	y1, y2 = W // 2, W % 2

	n = x1 * y1
	k = 0
	for c in counter:
		if k == n:
			break
		if counter[c] >= 4:
			k += 1
			counter[c] -= 4

	if k != n:
		print("No")
		return

	if x2 == 1:
		n = x1
		k = 0
		for c in counter:
			if k == n:
				break
			if counter[c] >= 2:
				k += 1
				counter[c] -= 2
		if k != n:
			print("No")
			return
	if y2 == 1:
		n = y1
		k = 0
		for c in counter:
			if k == n:
				break
			if counter[c] >= 2:
				k += 1
				counter[c] -= 2
		if k != n:
			print("No")
			return
	print("Yes")

foo()

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())

L = [0]*26
for _ in range(H):
  for a in input():
    L[ord(a)-ord('a')] += 1

m2 = 0
m1 = 0
for n in L:
  if n%4 != 0:
    if n%2 == 0:
      m2 += 1
    else:
      m1 += 1

if H%2 == 0 and W%2==0:
  print('Yes' if m1+m2 == 0 else 'No')
elif H%2==0 or W%2==0:
  print('Yes' if m1 == 0 else 'No')
else:
  print('Yes' if m1 == 1 else 'No')

Submission status: Wrong Answer

Solution code:
raw1 = input().split()
H = int(raw1[0])
W = int(raw1[1])

c = [0 for x in range(26)]

for i in range(H):
    raw = input()
    for j in range(W):
        c[ord(raw[j]) - 97] += 1

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


if c.count(3) > 0 :
    print('No')
elif W%2 == 1 and H%2 == 1 and c.count(1) == 1 and c.count(2) == (H-1)/2 +(W-1)/2:
    print('Yes')
elif W%2 == 0 and H%2==0 and c.count(1)==0 and c.count(2) ==0:
    print('Yes')
elif W % 2 +  H % 2  == 1 and c.count(1) == 0 and c.count(2)%2 == (H-1)/2 +(W-1)/2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
raw1 = input().split()
H = int(raw1[0])
W = int(raw1[1])

c = [0 for x in range(26)]

for i in range(H):
    raw = input()
    for j in range(W):
        c[ord(raw[j]) - 97] += 1

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


if c.count(3) > 0 :
    print('No')
elif W%2 == 1 and H%2 == 1 and c.count(1) == 1 and c.count(2) == (H-1)/2 +(W-1)/2:
    print('Yes')
elif W%2 == 0 and H%2==0 and c.count(1)==0 and c.count(2) ==0:
    print('Yes')
elif W % 2 +  H % 2  == 1 and c.count(1) == 0 and c.count(2)%2 == 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter
import numpy as np
import sys

hw = input().split()
h = int(hw[0])
w = int(hw[1])

a_all = ""
for i in range(h):
    a_all += input()
    
count = Counter(a_all)

four_num = w//2 * h//2
two_num = w%2 * h//2 + h%2 * w//2
one_num = w%2 * h%2

nums = list(count.values())

nums_array = np.array(nums)

check=0

for i in range(four_num):
    if len(nums_array[nums_array>=4])>=1:
        nums_array[np.where(nums_array>=4)[0][0]] -= 4
    else:
        check = 1
        break

for i in range(two_num):
    if len(nums_array[nums_array>=2])>=1:
        nums_array[np.where(nums_array>=2)[0][0]] -= 2
    else:
        check = 1

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

Submission status: Wrong Answer

Solution code:
#Palindromic Matrix
h,w = list(map(int, input().split()))
a = []
for i in range(h):
    a.append(input())
a = "".join(a)

import collections
c = collections.Counter(a).values()
d = 0
e = 0
for ci in c:
    d+=ci//4
    e+=ci//2

#print(h//2, w//2)
#print(d,e)

if (d>=(h//2)*(w//2) and e-2*d>=(h//2)*(w%2)+(w//2)*(h%2)):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
#Palindromic Matrix
h,w = list(map(int, input().split()))
a = []
for i in range(h):
    a.append(input())
a = "".join(a)

import collections
c = collections.Counter(a).values()
d = 0
e = 0
for ci in c:
    d+=ci//4
    e+=ci//2

print(h//2, w//2)
print(d,e)

if (d>=(h//2)*(w//2) and e-2*d>=(h//2)*(w%2)+(w//2)*(h%2)):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
h,w = list(map(int,input().split()))
a = [0] * h
m = [0] * 26
if h == w == 1:
    print('Yes')
    exit()

for i in range(h):
    a[i] = list(input())
    for j in range(w):
        m[ord(a[i][j])-97] += 1
wki = w%2
hki = h%2
whan = int(w/2)
hhan = int(h/2)

m.sort()
m.reverse()

yon = int(whan * hhan)
ni =int(  (wki * hhan) + (hki * whan) )
iti = 0
if wki == 1 and hki == 1:
    iti = 1
flag = 0
for i in range(26):
    if (m[i] == 1 and iti == 0) or (m[i] == 1 and flag == 1):
        print('No')
        exit()
    if m[i] == 1 and flag == 0 and iti == 1:
        flag +=1
        m[i] -= 1
        iti -= 1

for i in range(26):
    while m[i] >=4 and yon > 0:
        m[i] -= 4
        yon -= 1
for i in range(26):
    while m[i] >= 2 and ni >0:
        m[i] -= 2
        ni -= 1


if yon == 0 and ni == 0 and iti == 0 and sum(m) == 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter
import numpy as np

hw = input().split()
h = int(hw[0])
w = int(hw[1])

a_all = ""
for i in range(h):
    a_all += input()
    
count = Counter(a_all)

four_num = w//2 * h//2
two_num = w%2 * h//2 + h%2 * w//2
one_num = w%2 * h*2

nums = list(count.values())

nums_array = np.array(nums)

check=0

for i in range(four_num):
    if len(nums_array[nums_array>=4])>=1:
        nums_array[np.where(nums_array>=4)[0][0]] -= 4
    else:
        check = 1
        break

for i in range(two_num):
    if len(nums_array[nums_array>=2])>=1:
        nums_array[np.where(nums_array>=2)[0][0]] -= 2
    else:
        check = 1

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

Submission status: Wrong Answer

Solution code:

from collections import Counter

H, W = map(int, input().split())
gyoretu = [list(input()) for i in range(H)]
S = ""
for i in range(H):
    S += "".join(gyoretu[i])


cnter = Counter(S)
item = list(cnter.values())

cnt = 0
for n in item:
    if n%2 == 1:
        cnt += 1

if (H%2 == 0) & (W%2 == 0) & (cnt>0):
    print("No")

elif (H%2 == 1) & (W%2 == 1):
    if cnt > 2:
        print("No")
    else:
        print("Yes")

elif cnt > 0:
    print("No")

elif (H==2) & (W==2):
    if len(item) > 1:
        print("No")
    else:
        print("Yes")
    
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
#Palindromic Matrix
h,w = list(map(int, input().split()))
a = []
for i in range(h):
    a.append(input())
a = "".join(a)

import collections
c = collections.Counter(a).values()
d = 0
e = 0
for ci in c:
    d+=ci//4
    e+=ci//2

print(h//2, w//2)
print(d,e)

if (d>=(h//2)*(w//2) and e-2*d>=(h//2)*(h%2)+(w//2)*(w%2)):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
raw1 = input().split()
H = int(raw1[0])
W = int(raw1[1])

c = [0 for x in range(26)]

for i in range(H):
    raw = input()
    for j in range(W):
        c[ord(raw[j]) - 97] += 1

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


if c.count(3) > 0 :
    print('No')
elif W%2 == 1 and H%2 == 1 and c.count(1) == 1 and c.count(2)%2 == 0:
    print('Yes')
elif W%2 == 0 and H%2==0 and c.count(1)==0 and c.count(2)%2==0:
    print('Yes')
elif W % 2 +  H % 2  == 1 and c.count(1)== 0 and c.count(2)%2 == 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
hoge = [int(x) for x in input().split()]
moji = ''
char = {}
only = ''
for i in range(hoge[0]):
    moji += input()
for m in moji:
    if m in char:
        char[m] += 1
    else:
        char.update({m:1})
        only += m
if hoge[0] % 2 == 1 and hoge[1] % 2 == 1:
    one = 1
    two = (hoge[0]-1)/2 + (hoge[1]-1)/2
    four = (hoge[0]-1)/2 * (hoge[1]-1)/2
elif hoge[0] % 2 == 1 and hoge[1] % 2 == 0:
    one = 0
    two = hoge[1]/2
    four = (hoge[0]-1)/2 * hoge[1]/2
elif hoge[0] % 2 == 0 and hoge[1] % 2 == 1:
    one = 0
    two = hoge[0]/2
    four = (hoge[1]-1)/2 * hoge[0]/2
else:
    one = 0
    two = 0
    four = hoge[1]/2 * hoge[0]/2

foo = 0
for c in only:
    while(char[c] > 0):
        if char[c] >= 4:
            char[c] -= 4
            four -= 1
        elif char[c] >= 2:
            char[c] -= 2
            two -= 1
        else:
            char[c] -= 1
            one -= 1
        if four < 0 or two < 0 or one < 0:
            foo = 1
            break
    if foo == 1:
        break

if foo == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
raw1 = input().split()
H = int(raw1[0])
W = int(raw1[1])

c = [0 for x in range(26)]

for i in range(H):
    raw = input()
    for j in range(W):
        c[ord(raw[j]) - 97] += 1

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


if c.count(3) > 0 :
    print('No')
elif W%2 == 1 and H%2 == 1 and c.count(1) == 1 and c.count(2)%2 == 0:
    print('Yes')
elif W%2 == 0 and H%2==0 and c.count(1)==0 and c.count(2)==0:
    print('Yes')
elif W % 2 +  H % 2  == 1 and c.count(1)== 0 and c.count(2)%2 == 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
#Palindromic Matrix
h,w = list(map(int, input().split()))
a = []
for i in range(h):
    a.append(input())
a = "".join(a)

import collections
c = collections.Counter(a).values()
d = 0
e = 0
for ci in c:
    d+=ci//4
    e+=ci//2

print(h//2, w//2)
print(d,e)

if (d>=(h//2)*(w//2) and e-2*d>=(h//2)+(w//2)):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
#Palindromic Matrix
h,w = list(map(int, input().split()))
a = []
for i in range(h):
    a.append(input())
a = "".join(a)

import collections
c = collections.Counter(a).values()
d = 0
e = 0
for ci in c:
    d+=ci//4
    e+=ci//2

print(h//2, w//2)
print(d,e)

if (d>=(h//2)*(w//2) and 2*e-4*d>=(h//2)+(w//2)):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
raw1 = input().split()
H = int(raw1[0])
W = int(raw1[1])

c = [0 for x in range(26)]

for i in range(H):
    raw = input()
    for j in range(W):
        c[ord(raw[j]) - 97] += 1

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


if c.count(3) > 0 :
    print('No')
elif W%2 == 1 and H%2 == 1 and c.count(1) == 1 and c.count(2) == 0:
    print('Yes')
elif W%2 == 0 and H%2==0 and c.count(1)==0 and c.count(2)==0:
    print('Yes')
elif W % 2 +  H % 2  == 1 and c.count(1)== 0 and c.count(2)%2 == 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
hoge = [int(x) for x in input().split()]
moji = ''
char = {}
only = ''
for i in range(hoge[0]):
    moji += input()
for m in moji:
    if m in char:
        char[m] += 1
    else:
        char.update({m:1})
        only += m
if hoge[0] % 2 == 1 and hoge[1] % 2 == 1:
    one = 1
    two = (hoge[0]-1)/2 + (hoge[1]-1)/2
    four = (hoge[0]-1)/2 * (hoge[1]-1)/2
elif hoge[0] % 2 == 1 and hoge[1] % 2 == 0:
    one = 0
    two = hoge[1]/2
    four = (hoge[0]-1)/2 * hoge[1]/2
elif hoge[0] % 2 == 0 and hoge[1] % 2 == 1:
    one = 0
    two = hoge[0]/2
    four = (hoge[1]-1)/2 * hoge[0]/2
else:
    one = 0
    two = 0
    four = hoge[1]/2 * hoge[0]/2

foo = 0
for c in only:
    if char[c] >= 4:
        char[c] -= 4
        four -= 1
    elif char[c] >= 2:
        char[c] -= 2
        two -= 1
    else:
        char[c] -= 1
        one -= 1
    if four < 0 or two < 0 or one < 0:
        print("No")
        foo = 1
        break
if foo == 0:
    print("Yes")

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())

L = [0]*26
for _ in range(H):
  for a in input():
    L[ord(a)-ord('a')] += 1

R = []
for n in L:
  if n%4 != 0:
    R.append(n%4)

if H%2 == 0 and W%2==0:
  print('Yes' if not R else 'No')
else:
  odd = 0
  for r in R:
    odd += r%2
  if H%2==1 and W%2==1:
    print('Yes' if odd == 1 else 'No')
  else:
    print('Yes' if odd == 0 else 'No')

Submission status: Wrong Answer

Solution code:
from  collections import Counter
H, W = map(int, input().split())
A = []
C = Counter()
for i in range(H):
    A.append(input())
    C += Counter(A[i])

if(H%2 == 0 and W%2 == 0):
    for l in C:
        if(C[l]%4):
            print("No")
            exit()
    print("Yes")
elif(H%2 and W%2):
    t = 0
    for l in C:
        if(C[l]%2):
            t += 1
            C[l] -= 1
    if(t != 1):
        print("No")
        exit()

    t = 0
    for l in C:
        if(C[l]%4):
            t += 1

    if((H+W-2)//2-t >= 0 and ((H+W-2)//2-t)%2 == 0):
        print("Yes")
    else:
        print("No")
else:
    t = 0
    r = H*(W%2) + W*(H%2)
    for l in C:
        if(C[l]%2):
            print("No")
            exit()
        elif(C[l]%4):
            t += 1
    if(r//2-t >= 0 and (r//2-t)%2):
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
#Palindromic Matrix
h,w = list(map(int, input().split()))
a = []
for i in range(h):
    a.append(input())
a = "".join(a)

import collections
c = collections.Counter(a).values()
d = 0
e = 0
for ci in c:
    d+=ci//4
    e+=ci//2

#print(h//2, w//2)
#print(d,e)

if (d>=(h//2)*(w//2) and e-d>=(h//2)+(w//2)):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter

H, W = map(int, input().split())
gyoretu = [list(input()) for i in range(H)]
S = ""
for i in range(H):
    S += "".join(gyoretu[i])


cnter = Counter(S)
item = list(cnter.values())

cnt = 0
for n in item:
    if n%2 == 1:
        cnt += 1

if (H%2 == 0) & (W%2 == 0) & (cnt>0):
    print("No")

elif (H%2 == 1) & (W%2 == 1):
    if cnt > 2:
        print("No")
    else:
        print("Yes")

elif cnt > 0:
    print("No")

elif (H==2) & (W==2):
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
def solver1( m , h, w):
    for k, v in m.items():
        if v%2 == 1:
            m[k] = m[k] - 1
            break
    _2kcount = (h-1)/2 + (w-1)/2
    _4kcount = ((h-1)/2) * ((w-1)/2 )
    for k, v in m.items():
        if v%4 == 2:
            _2kcount -= 1
            m[k] = m[k] - 2
        elif v%4 != 0:
            return 'No'
    if _2kcount < 0:
        return 'No'
    if _2kcount %2 != 0:
        return 'No'
    return 'Yes'
    #we don't need to care about 4k case because the total amount of material is fix.
def solver2( m, h, w):
    oddc = h if h%2 == 1 else w
    evenc = w if w%2 == 0 else h
    _2kcount = evenc
    for k, v in m.items():
        if v%4 == 2:
            _2kcount -= 1
            m[k] = m[k] - 2
        elif v%4 != 0:
            return 'No'
    if _2kcount < 0:
        return 'No'
    if _2kcount %2 != 0:
        return 'No'
    return 'Yes'

H,W = map(int, sys.stdin.readline().strip().split())

matrix = []
materials = {}
for _ in xrange(H):
    line = sys.stdin.readline().strip()
    for a in line:
        materials[a] = materials.get(a, 0) + 1

if H%2 == 0 and W%2 == 0:
    for value in materials.values():
        if value % 4 == 0:
            continue
        else:
            print 'No'
            exit(0)
    print 'Yes'
    exit(0)
if H%2 == 1 and W%2 == 1:
    print solver1(materials, H, W)
    exit(0)

print solver2(materials, H, W)
exit(0)

Submission status: Wrong Answer

Solution code:
import sys
def solver1( m , h, w):
    for k, v in m.items():
        if v%2 == 1:
            m[k] = m[k] - 1
            break
    _2kcount = (h-1)/2 + (w-1)/2
    _4kcount = ((h-1)/2) * ((w-1)/2 )
    for k, v in m.items():
        if v%4 == 2:
            _2kcount -= 1
            m[k] = m[k] - 2
        elif v%4 != 0:
            return 'No'
    if _2kcount < 0:
        return 'No'
    if _2kcount %2 != 0:
        return 'No'
    return 'Yes'
    #we don't need to care about 4k case because the total amount of material is fix.
def solver2( m, h, w):
    oddc = h if h%2 == 1 else w
    evenc = w if w%2 == 0 else h
    _2kcount = oddc
    for k, v in m.items():
        if v%4 == 2:
            _2kcount -= 1
            m[k] = m[k] - 2
        elif v%4 != 0:
            return 'No'
    if _2kcount < 0:
        return 'No'
    if _2kcount %2 != 0:
        return 'No'
    return 'Yes'

H,W = map(int, sys.stdin.readline().strip().split())

matrix = []
materials = {}
for _ in xrange(H):
    line = sys.stdin.readline().strip()
    for a in line:
        materials[a] = materials.get(a, 0) + 1

if H%2 == 0 and W%2 == 0:
    for value in materials.values():
        if value % 4 == 0:
            continue
        else:
            print 'No'
            exit(0)
    print 'Yes'
    exit(0)
if H%2 == 1 and W%2 == 1:
    print solver1(materials, H, W)
    exit(0)

print solver2(materials, H, W)
exit(0)

Submission status: Wrong Answer

Solution code:
h,w = list(map(int,input().split()))
a = [0] * h
m = [0] * 26

for i in range(h):
    a[i] = list(input())
    for j in range(w):
        m[ord(a[i][j])-97] += 1

wki = w%2
hki = h%2
whan = int(w/2)
hhan = int(h/2)

m.sort()
m.reverse()

yon = int(whan * hhan)
ni =int(  (wki * hhan) + (hki * whan) )
iti = 0
if wki == 1 and hki == 1:
    iti = 1
flag = 0
for i in range(26):
    if m[i] == 1:
        flag +=1
if flag >iti:
    print('No')
    exit()
if flag == 1 and iti:
    iti = 0

for i in range(26):
    while m[i] >=4 and yon > 0:
        m[i] -= 4
        yon -= 1
for i in range(26):
    while m[i] >= 2 and ni >0:
        m[i] -= 2
        ni -= 1


if yon == 0 and ni == 0 and iti == 0 and sum(m) == 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import division, print_function
import sys


def main():
    h, w = map(int, sys.stdin.readline().strip().split(" "))
    aa = ""
    for _ in range(h):
        aa += sys.stdin.readline().strip()
    d = {}
    for c in aa:
        if c in d:
            d[c] += 1
        else:
            d[c] = 1

    # print(d)
    fours = 0
    evens = 0
    odds = 0

    for c, count in d.items():
        fours += count // 4
        evens += (count % 4) // 2
        odds += count % 2

    # print(fours, evens, odds)
    if h % 2 == 0 and w % 2 == 0:
        print("Yes" if odds == 0 and evens == 0 else "No")
    elif h % 2 == 0 and w % 2 == 1:
        if odds != 0:
            print("No")
            return
        if 4 * fours < h * (w - 1):
            print("No")
            return
        print("Yes")
    elif h % 2 == 1 and w % 2 == 0:
        if odds != 0:
            print("No")
            return
        if 4 * fours < w * (h - 1):
            print("No")
            return
        print("Yes")
    else:
        if odds != 1:
            print("No")
            return
        if 4 * fours < (w - 1) * (h - 1):
            print("No")
        print("Yes")


if __name__ == '__main__':
    main()