Problem:


Score : 400 points

Problem Statement

We have an H-by-W matrix.
Let a_{ij} be the element at the i-th row from the top and j-th column from the left.
In this matrix, each a_{ij} is a lowercase English letter.

Snuke is creating another H-by-W matrix, A', by freely rearranging the elements in A.
Here, he wants to satisfy the following condition:

Every row and column in A' can be read as a palindrome.

Determine whether he can create a matrix satisfying the condition.

Note

A palindrome is a string that reads the same forward and backward.
For example, a, aa, abba and abcba are all palindromes, while ab, abab and abcda are not.

Constraints

1 ≤ H, W ≤ 100

a_{ij} is a lowercase English letter.

Input

Input is given from Standard Input in the following format:

H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW}

Output

If Snuke can create a matrix satisfying the condition, print Yes; otherwise, print No.

Sample Input 1

3 4
aabb
aabb
aacc

Sample Output 1

Yes

For example, the following matrix satisfies the condition.

abba
acca
abba

Sample Input 2

2 2
aa
bb

Sample Output 2

No

It is not possible to create a matrix satisfying the condition, no matter how we rearrange the elements in A.

Sample Input 3

5 1
t
w
e
e
t

Sample Output 3

Yes

For example, the following matrix satisfies the condition.

t
e
w
e
t

Sample Input 4

2 5
abxba
abyba

Sample Output 4

No

Sample Input 5

1 1
z

Sample Output 5

Yes



Sample input:
3 4
aabb
aabb
aacc


Sample output:
Yes

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = ""
cnt = [0] * 26
for _ in range(h):
    s += input().strip()

for i in range(len(s)):
    cnt[ord(s[i]) - ord("a")] += 1
c4=0
c2=0
c1=0
if h&1 == 1:
    c2 += w // 2
if w&1 == 1:
    c2 += h // 2
if (h&1 == 1) and (w&1 == 1):
    c1 = 1
c4 += (h//2) * (w//2)

for i in range(26):
    while cnt[i] %4 == 1 or cnt[i] %4 == 3:
        cnt[i] -= 1
        c1 -= 1
for i in range(26):
    while cnt[i] % 4 == 2:
        cnt[i] -= 2
        c2 -= 1
for i in range(26):
    while cnt[i] >= 1:
        cnt[i] -= 4
        c4 -= 1

#print((c1,c2,c4))
if c1==0 and c2==0 and c4==0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = ""
cnt = [0] * 26
for _ in range(h):
    s += input().strip()

for i in range(len(s)):
    cnt[ord(s[i]) - ord("a")] += 1
c4=0
c2=0
c1=0
if h&1 == 1:
    c2 += w // 2
if w&1 == 1:
    c2 += h // 2
if (h&1 == 1) and (w&1 == 1):
    c1 += 1
c4 += (h//2) * (w//2)

for i in range(26):
    while cnt[i] >= 4:
        cnt[i] -= 4
        c4 -= 1
for i in range(26):
    while cnt[i] >= 2:
        cnt[i] -= 2
        c2 -= 1
for i in range(26):
    while cnt[i] >= 1:
        cnt[i] -= 1
        c1 -= 1

#print((c1,c2,c4))
if c1==0 and c2==0 and c4==0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = ""
cnt = [0] * 26
for _ in range(h):
    s += input().strip()

for i in range(len(s)):
    cnt[ord(s[i]) - ord("a")] += 1
c4=0
c2=0
c1=0
if h&1 == 1:
    c2 += w // 2
if w&1 == 1:
    c2 += h // 2
if h&1 == 1 and w&1 == 1:
    c1 += 1
c4 += (h//2) * (w//2)
#print((c1,c2,c4))

for i in range(26):
    while cnt[i] >= 4:
        cnt[i] -= 4
        c4 -= 1
for i in range(26):
    while cnt[i] >= 2:
        cnt[i] -= 2
        c2 -= 1
for i in range(26):
    while cnt[i] >= 1:
        cnt[i] -= 1
        c1 -= 1

#print((c1,c2,c4))
if c1==c2==c4==0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

c = Counter()
for h in range(H):
    ch = Counter(a[h])
    c += ch

# W, H が1のときは例外として扱う
# W, H が偶数: すべて4の倍数
# W が偶数, H が奇数: 基本4の倍数、2の倍数でいいのが W//2 種類
# W が奇数、 H が偶数: 基本4の倍数、2の倍数が許されるのは真ん中の列の H//2 種類だけ
# W, H が奇数: 基本4の倍数、2の倍数でいいのが H//2 種類、 1種類は奇数で ok

def length_n_multiple(n):
    return len([v for v in c.values() if v%n == 0])

case = [W%2, H%2]

if [W, H] == [1, 1]:
    print("Yes")
elif W == 1 or H == 1:
    if length_n_multiple(2) >= len(c)-1:
        print("Yes")
    else:
        print("No")
elif case == [0, 0]:
    if length_n_multiple(4) == len(c):
        print("Yes")
    else:
        print("No")
elif case == [0, 1]:
    if length_n_multiple(2) == len(c) and length_n_multiple(4) >= W//2-1:
        print("Yes")
    else:
        print("No")
elif case == [1, 0]:
    if length_n_multiple(2) == len(c) and length_n_multiple(4) >= H//2-1:
        print("Yes")
    else:
        print("No")
else:
    if length_n_multiple(2) >= len(c)-1 and length_n_multiple(4) >= H//2:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

c = Counter()
for h in range(H):
    ch = Counter(a[h])
    c += ch

print(c)

# W, H が1のときは例外として扱う
# W, H が偶数: すべて4の倍数
# W が偶数, H が奇数: 基本4の倍数、2の倍数でいいのが W//2 種類
# W が奇数、 H が偶数: 基本4の倍数、2の倍数が許されるのは真ん中の列の H//2 種類だけ
# W, H が奇数: 基本4の倍数、2の倍数でいいのが H//2 種類、 1種類は奇数で ok

def length_n_multiple(n):
    return len([v for v in c.values() if v%n == 0])

case = [W%2, H%2]

if [W, H] == [1, 1]:
    print("Yes")
elif W == 1 or H == 1:
    if length_n_multiple(2) >= len(c)-1:
        print("Yes")
    else:
        print("No")
elif case == [0, 0]:
    if length_n_multiple(4) == len(c):
        print("Yes")
    else:
        print("No")
elif case == [0, 1]:
    if length_n_multiple(2) == len(c) and length_n_multiple(4) >= W//2-1:
        print("Yes")
    else:
        print("No")
elif case == [1, 0]:
    if length_n_multiple(2) == len(c) and length_n_multiple(4) >= H//2-1:
        print("Yes")
    else:
        print("No")
else:
    if length_n_multiple(2) >= len(c)-1 and length_n_multiple(4) >= H//2:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

c = Counter()
for h in range(H):
    ch = Counter(a[h])
    c += ch

# W, H が偶数: すべて4の倍数
# W が偶数, H が奇数: 基本4の倍数、2の倍数でいいのが W//2 種類
# W が奇数、 H が偶数: 基本4の倍数、2の倍数が許されるのは真ん中の列の H//2 種類だけ
# W, H が奇数: 基本4の倍数、2の倍数でいいのが H//2 種類、 1種類は奇数で ok

def length_n_multiple(n):
    return len([v for v in c.values() if v%n == 0])

case = [W%2, H%2]

if case == [0, 0]:
    if length_n_multiple(4) == len(c):
        print("Yes")
    else:
        print("No")
elif case == [0, 1]:
    if length_n_multiple(2) == len(c) and length_n_multiple(4) >= W//2-1:
        print("Yes")
    else:
        print("No")
elif case == [1, 0]:
    if length_n_multiple(2) == len(c) and length_n_multiple(4) >= H//2-1:
        print("Yes")
    else:
        print("No")
else:
    if length_n_multiple(2) >= len(c)-1 and length_n_multiple(4) >= H//2:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

c = Counter()
for h in range(H):
    ch = Counter(a[h])
    c += ch

print(c)

# W, H が偶数: すべて4の倍数
# W が偶数, H が奇数: 基本4の倍数、2の倍数でいいのが W//2 種類
# W が奇数、 H が偶数: 基本4の倍数、2の倍数が許されるのは真ん中の列の H//2 種類だけ
# W, H が奇数: 基本4の倍数、2の倍数でいいのが H//2 種類、 1種類は奇数で ok

def length_n_multiple(n):
    return len([v for v in c.values() if v%n == 0])

case = [W%2, H%2]

if case == [0, 0]:
    if length_n_multiple(4) == len(c):
        print("Yes")
    else:
        print("No")
elif case == [0, 1]:
    if length_n_multiple(2) == len(c) and length_n_multiple(4) >= W//2-1:
        print("Yes")
    else:
        print("No")
elif case == [1, 0]:
    if length_n_multiple(2) == len(c) and length_n_multiple(4) >= H//2-1:
        print("Yes")
    else:
        print("No")
else:
    if length_n_multiple(2) >= len(c)-1 and length_n_multiple(4) >= H//2:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

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

c = Counter()
for h in range(H):
    ch = Counter(a[h])
    c += ch

# W, H が偶数: すべて4の倍数
# W が偶数, H が奇数: 基本4の倍数、2の倍数でいいのが W//2 種類
# W が奇数、 H が偶数: 基本4の倍数、2の倍数が許されるのは真ん中の列の H//2 種類だけ
# W, H が奇数: 基本4の倍数、2の倍数でいいのが H//2 種類、 1種類は奇数で ok


def length_n_multiple(n):
    return len([v for v in c.values() if v%n == 0])

case = [W%2, H%2]

if case == [0, 0]:
    if length_n_multiple(4) == len(c):
        print("Yes")
    else:
        print("No")
elif case == [0, 1]:
    if length_n_multiple(2) == len(c) and length_n_multiple(4) >= W//2:
        print("Yes")
    else:
        print("No")
elif case == [1, 0]:
    if length_n_multiple(2) == len(c) and length_n_multiple(4) >= H//2:
        print("Yes")
    else:
        print("No")
else:
    if length_n_multiple(2) >= len(c)-1 and length_n_multiple(4) >= H//2:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

h,w=MI()
lis=[]
for i in range(h):
    lis+=list(SI())
c=Counter(lis)
count1,count2=0,0
if h%2==0 and w%2==0:
    for x in c.keys():
        if c[x]%4!=0:
            print("No")
            sys.exit()
    print("Yes")
    
if h%2==0 and w%2==1:
    for x in c.keys():
        if c[x]%4==2:
            count2+=1
        elif c[x]%2==1:
            count1+=1
    if count2>1 or count1>0:
        print("No")
    else:
        print("Yes")
if w%2==0 and h%2==1:
    for x in c.keys():
        if c[x]%4==2:
            count2+=1
        elif c[x]%2==1:
            count1+=1
    #print(count1,count2)
    if count2>1 or count1>0:
        print("No")
    else:
        print("Yes")
if w%2==1 and h%2==1:
    for x in c.keys():
        if c[x]%4==2:
            count2+=1
        elif c[x]%2==1:
            count1+=1
    #print(count1,count2)
    if count1>1 or count2>2:
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

h,w=MI()
lis=[]
for i in range(h):
    lis+=list(SI())
c=Counter(lis)
count1,count2=0,0
if h%2==0 and w%2==0:
    for x in c.keys():
        if c[x]%4!=0:
            print("No")
            sys.exit()
    print("Yes")
    
if h%2==0 and w%2==1:
    for x in c.keys():
        if c[x]%4==2:
            count2+=1
        elif c[x]%2==1:
            count1+=1
    if count2>h//2 or count1>0:
        print("No")
    else:
        print("Yes")
if w%2==0 and h%2==1:
    for x in c.keys():
        if c[x]%4==2:
            count2+=1
        elif c[x]%2==1:
            count1+=1
    #print(count1,count2)
    if count2>w//2 or count1>0:
        print("No")
    else:
        print("Yes")
if w%2==1 and h%2==1:
    for x in c.keys():
        if c[x]%4==2:
            count2+=1
        elif c[x]%2==1:
            count1+=1
    #print(count1,count2)
    if count1>1 or count2>max(h,w)//2:
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
A = [list(input()) for i in range(H)]
B = []
for i in range(H):
    for j in range(W):
        a = A[i][j]
        c = 0
        for b in B:
            if a in b:
                b[1] += 1
                c = 1
        if c == 0:
            B.append([a, 1])
ans = 'Yes'
if H % 2 == 0 and W % 2 == 0:
    for b in B:
        if b[1] % 4 != 0:
            ans = 'No'
            break
elif H % 2 == 1 and W % 2 == 1:
    c = 0
    d = 0
    for b in B:
        if b[1] % 4 != 0:
            if b[1] % 2 == 0:
                if d < H // 2 + W // 2:
                    d += 1
                else:
                    ans = 'No'
                    break
            elif c == 0:
                c = 1
            else:
                ans = 'No'
                break
else:
    if H % 2 == 1:
        C = H
    else:
        C = W
    c = 0
    for b in B:
        if b[1] % 4 != 0:
            if b[1] % 2 == 0:
                if c < C // 2:
                    c += 1
                else:
                    ans = 'No'
                    break
            else:
                ans = 'No'
                break
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

h,w=MI()
lis=[]
for i in range(h):
    lis+=list(SI())
c=Counter(lis)
count1,count2=0,0
if h%2==0 and w%2==0:
    for x in c.keys():
        if c[x]%4!=0:
            print("No")
            sys.exit()
if h%2==0 and w%2==1:
    for x in c.keys():
        if c[x]%4==2:
            count2+=1
        elif c[x]%2==1:
            count1+=1
    if count2>h//2 or count1>0:
        print("No")
    else:
        print("Yes")
if w%2==0 and h%2==1:
    for x in c.keys():
        if c[x]%4==2:
            count2+=1
        elif c[x]%2==1:
            count1+=1
    #print(count1,count2)
    if count2>w//2 or count1>0:
        print("No")
    else:
        print("Yes")
if w%2==1 and h%2==1:
    for x in c.keys():
        if c[x]%4==2:
            count2+=1
        elif c[x]%2==1:
            count1+=1
    #print(count1,count2)
    if count1>1 or count2>max(h,w)//2:
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
A = [list(input()) for i in range(H)]
B = []
for i in range(H):
    for j in range(W):
        a = A[i][j]
        c = 0
        for b in B:
            if a in b:
                b[1] += 1
                c = 1
        if c == 0:
            B.append([a, 1])
ans = 'Yes'
if H % 2 == 0 and W % 2 == 0:
    for b in B:
        if b[1] % 4 != 0:
            ans = 'No'
            break
elif H % 2 == 1 and W % 2 == 1:
    c = 0
    d = 0
    for b in B:
        if b[1] % 4 != 0:
            if b[1] % 2 == 0:
                if d < H // 2 + W // 2:
                    d += 1
                else:
                    ans = 'No'
                    break
            elif c == 0:
                c = 1
            else:
                ans = 'No'
                break
else:
    for b in B:
        if b[1] % 2 != 0:
            ans = 'No'
            break
print(ans)

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
h,w = readInts()
S = ""
for i in range(h):
    S += input()
LIST = Counter(S)
#print(LIST)
if h%2 == 0 and w%2 == 0:
    for k,v in LIST.items():
        if v%4:
            print('No')
            exit()
elif (h%2 == 0 and w%2) or (h%2 and w%2 == 0):
    two = 0
    for k,v in LIST.items():
        if v%2 or v%4 == 3:
            print('No')
            exit()
        if v%4 == 2:
            two += 1
    if h%2 == 0:
        if two > h//2:
            print('No')
            exit()
    else:
        if two > w//2:
            print('No')
            exit()
else:
    odd = 0
    two = 0
    for k,v in LIST.items():
        if v%4 == 1:
            odd += 1
        if v%4 == 2:
            two += 1
    if odd == 0:
        print('No')
        exit()
    if two > ((h-1)//2 + (w-1)//2):
        print('No')
        exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
h,w = readInts()
S = ""
for i in range(h):
    S += input()
LIST = Counter(S)
#print(LIST)
if h%2 == 0 and w%2 == 0:
    for k,v in LIST.items():
        if v%4:
            print('No')
            exit()
elif (h%2 == 0 and w%2) or (h%2 and w%2 == 0):
    two = 0
    for k,v in LIST.items():
        if v%2 or v%4:
            print('No')
            exit()
        if v%4 == 2:
            two += 1
    if h%2 == 0:
        if two > h//2:
            print('No')
            exit()
    else:
        if two > w//2:
            print('No')
            exit()
else:
    odd = 0
    two = 0
    for k,v in LIST.items():
        if v%4 == 1:
            odd += 1
        if v%4 == 2:
            two += 1
    if odd == 0:
        print('No')
        exit()
    if two > ((h-1)//2 + (w-1)//2):
        print('No')
        exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
from collections import Counter
def check():
  H, W = map(int, input().split())
  S = [input() for _ in range(H)]
  s = ''.join(S)
  c = Counter(s)
  d = Counter(c.values())
  two = 0
  one = 0
  for k,v in d.items():
    if k%4==2 or k%4==3:
      two += 2
    if k%2==1:
      one += 1
  if H%2==0 and W%2==0:
    if two>0 or one>0:
        return 'No'
  elif H%2==1 and W%2==1:
    if two>(H+W-2) or one>1:
      return 'No'
  elif H%2==1:
    if two>W or one>0:
      return 'No'
  elif W%2==1:
    if two>H or one>0:
      return 'No'
  return 'Yes'
print(check())

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
h,w = readInts()
S = ""
for i in range(h):
    S += input()
LIST = Counter(S)
#print(LIST)
if h%2 == 0 and w%2 == 0:
    for k,v in LIST.items():
        if v%4:
            print('No')
            exit()
elif (h%2 == 0 and w%2) or (h%2 and w%2 == 0):
    two = 0
    for k,v in LIST.items():
        if v%2:
            print('No')
            exit()
        if v%4 == 2:
            two += 1
    if h%2 == 0:
        if two > h//2:
            print('No')
            exit()
    else:
        if two > w//2:
            print('No')
            exit()
else:
    odd = 0
    two = 0
    for k,v in LIST.items():
        if v%4 == 1:
            odd += 1
        if v%4 == 2:
            two += 1
    if odd == 0:
        print('No')
        exit()
    if two > ((h-1)//2 + (w-1)//2):
        print('No')
        exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
A = [list(input()) for i in range(H)]
B = []
for i in range(H):
    for j in range(W):
        a = A[i][j]
        c = 0
        for b in B:
            if a in b:
                b[1] += 1
                c = 1
        if c == 0:
            B.append([a, 1])
ans = 'Yes'
if H % 2 == 0 and W % 2 == 0:
    for b in B:
        if b[1] % 4 != 0:
            ans = 'No'
            break
elif H % 2 == 1 and W % 2 == 1:
    c = 0
    for b in B:
        if b[1] % 2 != 0:
            if c == 0:
                c = 1
            else:
                ans = 'No'
                break
else:
    for b in B:
        if b[1] % 2 != 0:
            ans = 'No'
            break
print(ans)

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
h,w = readInts()
S = ""
for i in range(h):
    S += input()
LIST = Counter(S)
#print(LIST)
if h%2 == 0 and w%2 == 0:
    for k,v in LIST.items():
        if v%4:
            print('No')
            exit()
elif (h%2 == 0 and w%2) or (h%2 and w%2 == 0):
    two = 0
    odd = 0
    for k,v in LIST.items():
        if v%4:
            if v%2:
                print('No')
                exit()
            else:
                two += 1
        if two >= 4:
            print('No')
            exit()
else:
    odd = 0
    for k,v in LIST.items():
        if v%2:
            odd += 1
        if odd >= 2:
            print('No')
            exit()
    if not odd:
        print('No')
        exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
h,w = readInts()
S = ""
for i in range(h):
    S += input()
LIST = Counter(S)
#print(LIST)
if h%2 == 0 and w%2 == 0:
    for k,v in LIST.items():
        if v%4:
            print('No')
            exit()
elif (h%2 == 0 and w%2) or (h%2 and w%2 == 0):
    two = 0
    odd = 0
    for k,v in LIST.items():
        if v%4:
            if v%2:
                odd += 1
            else:
                two += 1
        if two >= 4:
            print('No')
            exit()
        if odd >= 2:
            print('No')
            exit()
    if not odd:
        print('No')
        exit()
else:
    odd = 0
    for k,v in LIST.items():
        if v%2:
            odd += 1
        if odd >= 2:
            print('No')
            exit()
    if not odd:
        print('No')
        exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
h,w = readInts()
S = ""
for i in range(h):
    S += input()
LIST = Counter(S)
#print(LIST)
if h%2 == 0 and w%2 == 0:
    for k,v in LIST.items():
        if v%4:
            print('No')
            exit()
elif (h%2 == 0 and w%2) or (h%2 and w%2 == 0):
    two = 0
    odd = 0
    for k,v in LIST.items():
        if v%4:
            if v%2:
                odd += 1
            else:
                two += 1
        if two >= 4:
            print('No')
            exit()
        if odd >= 2:
            print('No')
            exit()
else:
    odd = 0
    for k,v in LIST.items():
        if v%2:
            odd += 1
        if odd >= 2:
            print('No')
            exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
h,w = readInts()
S = ""
for i in range(h):
    S += input()
LIST = Counter(S)
#print(LIST)
if h%2 == 0 and w%2 == 0:
    for k,v in LIST.items():
        if v%4:
            print('No')
            exit()
elif (h%2 == 0 and w%2) or (h%2 and w%2 == 0):
    two = 0
    for k,v in LIST.items():
        if v%4:
            if v%2:
                print('No')
                exit()
            else:
                two += 1
        if two >= 3:
            print('No')
            exit()
else:
    odd = 0
    for k,v in LIST.items():
        if v%2:
            odd += 1
        if odd >= 2:
            print('No')
            exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

dic = Counter(A)

if H == 1 and W == 1:
    print('Yes')
elif H == 1 or W == 1:
    p = max(H, W)
    v_list = dic.values()
    if p % 2 == 0:
        if all(v%2==0 for v in v_list):
            print('Yes')
        else:
            print('No')
    else:
        cnt = [v for v in v_list if v % 2 == 1]
        if len(cnt) == 1:
            print('Yes')
        else:
            print('No')
else:
    if H % 2 == 1 and W % 2 == 1:
        v_list = dic.values()
        cnt4, cnt = 0, 0
        for v in v_list:
            cnt4 += v // 4
            if v % 2 == 1:
                cnt += 1
        if cnt4 >= (H//2 + W//2) and cnt == 1:
            print('Yes')
        else:
            print('No')
    elif H % 2 == 1 or W % 2 == 1:
        v_list = dic.values()
        cnt4, cnt = 0, 0
        for v in v_list:
            cnt4 += v // 4
            if v % 2 == 1:
                cnt += 1
        if cnt4 >= (H//2 + W//2 - 1) and cnt == 0:
            print('Yes')
        else:
            print('No')
    else:
        v_list = dic.values()
        cnt4, cnt = 0, 0
        for v in v_list:
            cnt4 += v // 4
            if v % 2 == 1:
                cnt += 1
        if cnt4 >= (H//2 + W//2) and cnt == 0:
            print('Yes')
        else:
            print('No')

Submission status: Wrong Answer

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

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

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

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