Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = (int)(input())
l = (list)(map(int, input().split()))

max_l = max(l) if max(l) >= 0 else 0
min_l = min(l) if min(l) <= 0 else 0

l_sort = sorted(l)

for i in range(n):
    if l[i] == min(l):
        cost = max(l)*2 + (lambda -x*2: x if x <= 0 else 0)(l_sort[1])
    elif l[i] == max(l):
        cost = -min(l)*2 + (lambda x*2: x if x >= 0 else 0)(l_sort[n-2])
    else:
        cost = -min_l*2 + max_l*2
    print(cost)


Fixed submission:
n = int(input())
a = [int(i) for i in ("0 "+input()+" 0").split()]
ans = sum(abs(a[i+1]-a[i]) for i in range(n+1))
for i in range(n):
    print(ans-abs(a[i+1]-a[i])-abs(a[i+2]-a[i+1])+abs(a[i+2]-a[i]))
Buggy python submission (verdict: Runtime Error):
from collections import Counter
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)

B = int(input())
Lb = [input() for _ in range(B)]
R = int(input())
Lr = [input() for _ in range(R)]

Cb = Counter(Lb)
Cr = Counter(Lr)

cand = []
for i, v in Cb.items():
    cand.append(v-Cr[i])
ans = max(list(filter(lambda x: x > 0, cand)))
print(ans)


Fixed submission:
from collections import Counter

N = Counter([input() for _ in range(int(input()))])
M = Counter([input() for _ in range(int(input()))])
print(max(0, max(N[key]-M[key] for key in N.keys())))

Buggy python submission (verdict: Runtime Error):
from collections import Counter
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)

B = int(input())
Lb = [input() for _ in range(B)]
R = int(input())
Lr = [input() for _ in range(R)]

Cb = Counter(Lb)
Cr = Counter(Lr)

cand = []
for i, v in Cb.items():
    cand.append([v-Cr[i]])
ans = sum(list(filter(lambda x: x > 0, cand)))
print(ans)


Fixed submission:
from collections import Counter

N = Counter([input() for _ in range(int(input()))])
M = Counter([input() for _ in range(int(input()))])
print(max(0, max(N[key]-M[key] for key in N.keys())))
Buggy python submission (verdict: Runtime Error):
n=int(input())
t ,a=list(map(int, input().split()))
h = list(map(int,input().split(' ')))

min=100000000000000
min_index=n+1
for i in range(len(h)):
  v = abs(t - h[i]*0.006)
  if v < min:
    min=v
    min_index=i
print(min_index+1)


Fixed submission:
n = int(input())
cards = (list)(map(int, input().split()))

cards = sorted(cards, reverse=True)

print(2*sum(cards[0::2]) - sum(cards))

Buggy python submission (verdict: Runtime Error):
n=int(input())
t ,a=list(map(int, input().split()))
h = list(map(int,input().split(' ')))

min=100000000000000
min_index=n+1
for i in range(n):
  v = abs(t - h[i]*0.006)
  if v < min:
    min=v
    min_index=i
print(min_index+1)


Fixed submission:
n = int(input())
cards = (list)(map(int, input().split()))

cards = sorted(cards, reverse=True)

print(2*sum(cards[0::2]) - sum(cards))
Buggy python submission (verdict: Runtime Error):
grid = []
for _ in range(3):
    grid.append((list)(map(int, input().split())))

for i in range(3):
    j = (i+1) % 3
    diff1 = grid[i][0] - grid[j][0]
    diff2 = grid[i][1] - grid[j][1]

    if diff1 != diff2 or diff2 != diff3:
        print("No")
        exit()

print("Yes")


Fixed submission:
grid = []
for _ in range(3):
    grid.append((list)(map(int, input().split())))

for i in range(3):
    j = (i+1) % 3
    diff1 = grid[i][0] - grid[j][0]
    diff2 = grid[i][1] - grid[j][1]
    diff3 = grid[i][2] - grid[j][2]

    if diff1 != diff2 or diff2 != diff3 or diff1 != diff3:
        print("No")
        exit()

for i in range(3):
    j = (i+1) % 3
    diff1 = grid[0][i] - grid[0][j]
    diff2 = grid[1][i] - grid[1][j]
    diff3 = grid[2][i] - grid[2][j]

    if diff1 != diff2 or diff2 != diff3 or diff1 != diff3:
        print("No")
        exit()

print("Yes")
Buggy python submission (verdict: Runtime Error):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

a, b = input().split()
n = int(a+b)
ans = "No"
i = 0
while i*i <= n:
    if n % (i*i) == 0:
        ans = "Yes"
    i += 1
print(ans)


Fixed submission:
from math import sqrt
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

a, b = input().split()
n = int(a+b)
if int(sqrt(n)) == sqrt(n):
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

a, b = input().split()
n = int(a+b)
ans = "No"
i = 0
while i*i <= n:
    if n % (i*i) == 0:
        ans = "Yes"
print(ans)


Fixed submission:
from math import sqrt
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

a, b = input().split()
n = int(a+b)
if int(sqrt(n)) == sqrt(n):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

K = int(input())
L = list(map(int, input().split()))

maxr = 2
minr = 2
r = 0
for n in reversed(L):
    if any(x % n == 0 for x in range(minr, maxr+1)):
        # if minr//n <= maxr//n:
        minr = ceil(minr/n)*n
        maxr = (maxr)//n*n+n-1
    else:
        n = -1
        break

if n == -1:
    print(n)
else:
    print(int(minr), maxr)


Fixed submission:
from math import ceil
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

K = int(input())
L = list(map(int, input().split()))

maxr = 2
minr = 2
r = 0
for n in reversed(L):
    #print("max={}min={}".format(maxr, minr))
    if ceil(maxr//n)*n >= minr:
        # if any(x % n == 0 for x in range(minr, maxr+1)):
        # if minr//n <= maxr//n:
        minr = ceil(minr/n)*n
        maxr = (maxr)//n*n+n-1
    else:
        n = -1
        break

if n == -1:
    print(n)
else:
    print(int(minr), maxr)
Buggy python submission (verdict: Runtime Error):
S=input()
T=input()
S ="".join(sorted(S))
T="".join(sorted(T,reversed=True))
if S<=T:
  print("Yes")
else:
  print("No")

Fixed submission:
S=input()
T=input()
S ="".join(sorted(S))
T="".join(sorted(T,reverse=True))
if S<T:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = input()[:-1]
dig = 0
for c in N:
    dig += int(c)
if N % dig == 0:
    print("Yes")
else:
    print("No")


Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = input()[:-1]
dig = 0
for c in N:
    dig += int(c)
if int(N) % dig == 0:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
dig = 0
while N:
    dig += N % 10
if N % dig == 0:
    print("Yes")
else:
    print("No")


Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = input()[:-1]
dig = 0
for c in N:
    dig += int(c)
if int(N) % dig == 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N, C = list(map(int, input().split()))
prog = []
for _ in range(N):
    prog.append(list(map(int, input().split())))

ans = 0
T = 10**5
print(max([len(list(filter(lambda x:x[0] <= i <= x[1], prog)))
           for i in range(T+1)]))


Fixed submission:
from itertools import accumulate
# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, C = map(int, input().split())
TV = dict()
programs = [list(map(int, input().split())) for _ in range(N)]
last_time = max([p[1] for p in programs])
for i in range(1, C+1):
    TV[i] = [0]*(last_time*2+2)

for s, t, c in programs:
    s *= 2
    t *= 2
    TV[c][s] += 1
    TV[c][t+1] -= 1

for c in range(1, C+1):
    TV[c] = list(accumulate(TV[c]))

ans = 0
for i in range(last_time*2+1):
    tmp = 0
    for c in range(1, C+1):
        if TV[c][i] > 0:
            tmp += 1
    ans = max(ans, tmp)
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
ans="YES"
if len(s)>9:
	ans="NO"
else:
	a="KIHBR"
	kihbr=""
	for c in s:
		if c=="A":
			contine
		else:
			kihbr+=c
    if kihbr!=a:
		ans="NO"		
	if not "KIH" in s:
		ans="NO"
	if "AA" in s:
		ans="NO"
		
print(ans)	


Fixed submission:
s = input()

r = "AKIHABARA"
r2 = "KIHBR"
ans = "YES"
if not 5 <= len(s) <= len(r):
    ans = "NO"
if "AA" in s:
    ans = "NO"
if not "KIH" in s:
    ans = "NO"
else:
    rem_A = ""
    for c in s:
        if c != "A":
            rem_A += c
    if not rem_A == r2:
        ans = "NO"
print(ans)

Buggy python submission (verdict: Runtime Error):
def factiring2(N,P):
	if N==1:
		ans=P
	else:
		ans=1
		for i in range(2,int(P**0.5)+1):
			cnt=0
			while P%i==0:
				P//=i
				cnt+=1
			if cnt>=N:
				ans*=i**(cnt//N)
	return ans	

	
		

			
	


N, P = map(int, input().split())
ans=factiring2(N,P)
print(ans)



Fixed submission:
s = input()

r = "AKIHABARA"
r2 = "KIHBR"
ans = "YES"
if not 5 <= len(s) <= len(r):
    ans = "NO"
if "AA" in s:
    ans = "NO"
if not "KIH" in s:
    ans = "NO"
else:
    rem_A = ""
    for c in s:
        if c != "A":
            rem_A += c
    if not rem_A == r2:
        ans = "NO"
print(ans)

Buggy python submission (verdict: Runtime Error):
s = input()

l=['K','I','H','B','R']
i=0
ans="YES"
seq=False
for c in s:
	if i<len(l) and c=="A":
		if not seq:
			seq=True
			continue
		else:
			ans="NO"
			break
	else:
                seq=False
		if i<len(l) and c==l[i]:
			i+=1
		else:
			ans="NO"
			break
print(ans)


Fixed submission:
s = input()

r = "AKIHABARA"
r2 = "KIHBR"
ans = "YES"
if not 5 <= len(s) <= len(r):
    ans = "NO"
if "AA" in s:
    ans = "NO"
if not "KIH" in s:
    ans = "NO"
else:
    rem_A = ""
    for c in s:
        if c != "A":
            rem_A += c
    if not rem_A == r2:
        ans = "NO"
print(ans)

Buggy python submission (verdict: Runtime Error):
s = input()

l=['K','I','H','B','R']
i=0
ans="YES"
for c in s:
	if c=="A":
		continue
	else:
		if c==l[i]:
			i+=1
		else:
			ans="NO"
			break
print(ans)


Fixed submission:
s = input()

r = "AKIHABARA"
r2 = "KIHBR"
ans = "YES"
if not 5 <= len(s) <= len(r):
    ans = "NO"
if "AA" in s:
    ans = "NO"
if not "KIH" in s:
    ans = "NO"
else:
    rem_A = ""
    for c in s:
        if c != "A":
            rem_A += c
    if not rem_A == r2:
        ans = "NO"
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A = sorted(A)
B = sorted(B)
C = sorted(C)

ans = 0

for b in B:
    ans += len(list(filter(lambda x: x < b, A))) * \
        len(list(filter(lambda x: x > b, C)))

print(ans)


Fixed submission:
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A = sorted(A)
B = sorted(B)
C = sorted(C)

acc_a = [0]*N
acc_c = [0]*N

i_a = 0
i_c = N-1
for i in range(N):
    b = B[i]
    while i_a < N and A[i_a] < b:
        acc_a[i] += 1
        i_a += 1

for i in reversed(range(N)):
    b = B[i]
    while i_c >= 0 and C[i_c] > b:
        acc_c[i] += 1
        i_c -= 1

acc_a = list(accumulate(acc_a))
acc_c = list(accumulate(acc_c[::-1]))
acc_c = acc_c[::-1]

ans = 0
for a, c in zip(acc_a, acc_c):
    ans += a*c
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0

for b in B:
    ans += len(list(filter(lambda x: x < b, A))) * \
        len(list(filter(lambda x: x > b, C)))

print(ans)


Fixed submission:
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A = sorted(A)
B = sorted(B)
C = sorted(C)

acc_a = [0]*N
acc_c = [0]*N

i_a = 0
i_c = N-1
for i in range(N):
    b = B[i]
    while i_a < N and A[i_a] < b:
        acc_a[i] += 1
        i_a += 1

for i in reversed(range(N)):
    b = B[i]
    while i_c >= 0 and C[i_c] > b:
        acc_c[i] += 1
        i_c -= 1

acc_a = list(accumulate(acc_a))
acc_c = list(accumulate(acc_c[::-1]))
acc_c = acc_c[::-1]

ans = 0
for a, c in zip(acc_a, acc_c):
    ans += a*c
print(ans)
Buggy python submission (verdict: Runtime Error):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)

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

grid = [["#"]*(W+2) for _ in range(H+2)]

for i in range(1, H+1):
    s = input()
    for j, c in enumerate(s):
        grid[i][j+1] = c

cntGrid = [[0]*(W+2) for _ in range(H+2)]
for i in range(1, H+1):
    for j in range(1, W+1):
        if grid[i][j] == "#":
            cntGrid[i][j] = "#"
            d = [-1, 0, 1]
            for x in d:
                for y in d:
                    if x == 0 and y == 0:
                        continue
                    else:
                        cntGrid[i+x][j+y] += 1
for l in cntGrid[1:-1]:
    print("".join(map(str, l[1:-1])))


Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)

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

grid = [["#"]*(W+2) for _ in range(H+2)]

for i in range(1, H+1):
    s = input()
    for j, c in enumerate(s):
        grid[i][j+1] = c

cntGrid = [[0]*(W+2) for _ in range(H+2)]
for i in range(1, H+1):
    for j in range(1, W+1):
        if grid[i][j] == "#":
            cntGrid[i][j] = "#"
            d = [-1, 0, 1]
            for x in d:
                for y in d:
                    if x == 0 and y == 0:
                        continue
                    else:
                        if not grid[i+x][j+y] == "#":
                            cntGrid[i+x][j+y] += 1
for l in cntGrid[1:-1]:
    print("".join(map(str, l[1:-1])))
Buggy python submission (verdict: Runtime Error):
from UnionFind import UnionFind

N, M = map(int, input().split())

edges = []
for _ in range(M):
    a, b = map(int, input().split())
    edges.append([a-1, b-1])

mat = [[0]*N for _ in range(N)]
for s, g in edges:
    mat[s][g] = 1
    mat[g][s] = 1

ans = 0

for i in range(M):
    uni = UnionFind(N)

    for j in range(M):
        if i != j:
            uni.union(edges[j][0], edges[j][1])

    if not all(uni.find(0) == uni.find(x) for x in range(N)):
        ans += 1
print(ans)


Fixed submission:
N, M = map(int, input().split())
edges = []
for _ in range(M):
    a, b = list(map(int, input().split()))
    edges.append([a-1, b-1])

nodes = [0]*N

mat = [[0]*N for _ in range(N)]

for s, g in edges:
    nodes[s] += 1
    nodes[g] += 1
    mat[s][g] = 1
    mat[g][s] = 1

ans = 0


def check(nodes):
    return all(n != 1 for n in nodes)


ans = 0
while not check(nodes):
    for i in range(N):
        if nodes[i] == 1:
            for j in range(N):
                if mat[i][j]:
                    mat[i][j] = 0
                    mat[j][i] = 0
                    ans += 1
                    nodes[i] -= 1
                    nodes[j] -= 1
                    break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
N, K = (list)(map(int, input().split()))
pos_x = []
pos_y = []

for _ in range(N):
    a, b = map(int, input().split())
    pos_x.append(a)
    pos_y.append(b)


def count_point(x, y):
    ret = 0
    x_min = min(x)
    x_max = max(x)
    y_min = min(y)
    y_max = max(y)
    for i in range(N):
        if x_min <= pos_x[i] <= x_max and y_min <= pos_y[i] <= y_max:
            ret += 1
    return ret


def calc_area(x, y):
    ret = (x[1]-x[0])*(y[1]-y[0])
    return (abs)(ret)


set_x = set(pos_x)
set_y = set(pos_y)


area = float('inf')
for cand_x in combinations(set_x, 2):
    for cand_y in combinations(set_y, 2):
        if count_point(cand_x, cand_y) >= K:
            area = min(area, calc_area(cand_x, cand_y))
print(area)


Fixed submission:
from itertools import combinations
N, K = (list)(map(int, input().split()))
pos_x = []
pos_y = []

for _ in range(N):
    a, b = map(int, input().split())
    pos_x.append(a)
    pos_y.append(b)


def count_point(x, y):
    ret = 0
    x_min = min(x)
    x_max = max(x)
    y_min = min(y)
    y_max = max(y)
    for i in range(N):
        if x_min <= pos_x[i] <= x_max and y_min <= pos_y[i] <= y_max:
            ret += 1
    return ret


def calc_area(x, y):
    ret = (x[1]-x[0])*(y[1]-y[0])
    return (abs)(ret)


set_x = set(pos_x)
set_y = set(pos_y)


area = float('inf')
for cand_x in combinations(set_x, 2):
    for cand_y in combinations(set_y, 2):
        if count_point(cand_x, cand_y) >= K:
            area = min(area, calc_area(cand_x, cand_y))
print(area)
Buggy python submission (verdict: Runtime Error):
N = int(input())
for h in range(1, 3501):
    for w in range(1, 3501):
        u = 4*h*w-N*w-N*h
        d = N*h*w
        if d % u == 0:
            print(h, w, d//u)
            exit()


Fixed submission:
M = 3501
N = int(input())
for h in range(1, M):
    for w in range(1, M):
        u = 4*h*w-N*w-N*h
        d = N*h*w
        if u <= 0:
            continue
        if d % u == 0:
            print(h, w, d//u)
            exit()

Buggy python submission (verdict: Runtime Error):
MOD = 10**9+7
N = int(input())
L = list(map(lambda x: bin(int(x))[2:], input().split()))
max_len = max([len(v) for v in L])
padL = ["0"*(max_len-len(v))+v for v in L]
cnt = [0]*max_len
for i in range(max_len):
    for l in padL:
        cnt[i] += 1 if l[i] == "1" else 0

ans = 0
v = 1
for i in range(max_len):
    ans += v*cnt[max_len-1-i]*(N-cnt[max_len-i-1])
    ans %= MOD
    v *= 2

print(ans)


Fixed submission:
M = 3501
N = int(input())
for h in range(1, M):
    for w in range(1, M):
        u = 4*h*w-N*w-N*h
        d = N*h*w
        if u <= 0:
            continue
        if d % u == 0:
            print(h, w, d//u)
            exit()
Buggy python submission (verdict: Runtime Error):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W, K = map(int, input().split())
Upper = H//2 if H % 2 == 1 else H//2+1
for h in range(Upper):
    w = (K-W*h)/(H-2*h)
    if int(w) == w and 0 <= w <= W:
        print("Yes")
        exit()
print("No")


Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W, K = map(int, input().split())
for h in range(H+1):
    for w in range(W+1):
        if (W-w)*h+(H-h)*w == K:
            print("Yes")
            exit()
print("No")

Buggy python submission (verdict: Runtime Error):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W, K = map(int, input().split())
for h in range(H//2+1):
    w = (K-W*h)/(H-2*h)
    if int(w) == w and 0 <= w <= W:
        print("Yes")
        exit()
print("No")


Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W, K = map(int, input().split())
for h in range(H+1):
    for w in range(W+1):
        if (W-w)*h+(H-h)*w == K:
            print("Yes")
            exit()
print("No")
Buggy python submission (verdict: Runtime Error):
from collections import Counter
H, W = map(int, input().split())
D = []
for _ in range(H):
    D.extend(list([v for v in input()]))
C = Counter(D)
L = list([v for i, v in C.most_common()])

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

# 1.2.4.


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

g1 = sum(v % 2 for v in L)
g4 = sum(v//4 for v in L)

if g4 >= (W-(W % 2))*(H-(H % 2))//4 and g1 == H & 1 & W:
    print("Yes")
else:
    print("No")

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


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

g1 = sum(v % 2 for v in L)
g4 = sum(v//4 for v in L)

if g4 >= (W-(W % 2))*(H-(H % 2))//4 and g1 == H & 1 & W:
    print("Yes")
else:
    print("No")