Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03339 (python)

Fixed submission:
def sum_list(l1, l2):
  for i in range(len(l1)):
    l1[i] += l2[i]

  return l1


n = (int)(input())
s = input()
l_e = [0 for _ in range(n+1)]
l_w = [0 for _ in range(n+1)]

for i in range(n):
  if s[i] == 'W':
    l_e[i] += 1
  l_e[i+1] = l_e[i]

for i in reversed(range(n)):
  if s[i] == 'E':
    l_w[i] += 1
  l_w[i-1] = l_w[i]

l_e = l_e[:-1]
l_w = l_w[:n]


#print("E", l_e)
#print("W", l_w)

print(min(sum_list(l_e, l_w))-1)

Buggy submission (verdict: Runtime Error):
n = (int)(input())
s = (input())

l = len(s)
ans = l
for i in range(l):
  l_we = s[0:i] if(i >= 0)else None
  l_ea = s[i+1:l] if(i+1 <= l) else None
  print(l_we)
  print(l_ea)
  tmp = 0
  tmp += l_we.count('W')
  tmp += l_ea.count('E')
  ans = min(ans, tmp)
print(ans)
Problem p03377 (python)

Fixed submission:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
A, B, X = map(int, input().split())

ans = "YES"
if A+B < X:
    ans = "NO"
elif A > X:
    ans = "NO"
print(ans)

Buggy submission (verdict: Runtime Error):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
A, B, X = map(int, input().split())

ans = "YES"
if A+B < X:
    ans = "NO"
elif:
    A > X:
        ans = "NO"
print(ans)
Problem p03378 (python)

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

N, M, X = map(int, input().split())
a = list(map(int, input().split()))
l = [0]*(N+1)
for i in a:
    l[i] += 1
print(min(sum(l[0:X]), sum(l[X+1: N+1])))

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

N, M, X = map(int, input().split())
a = list(map(int, input().split()))
l = [0]*(N+1)
for i in a:
    l[i] += 1
print(min[sum(l[0:X]), sum(l[X+1: N+1])])
Problem p03393 (python)

Fixed submission:
s = input()

alp = [0]*26
a_int = ord('a')

ans = -1
cand = []
if len(s) == 26:
    for i in reversed(range(1, 26)):
        if s[i] < s[i-1]:
            cand.append(s[i])
            continue
        else:
            cand.append(s[i])
            cand = sorted(cand, reverse=True)
            c = min(list(filter(lambda x: x > s[i-1], cand)))
            ans = s[0:i-1]+c
            break

else:
    for c in s:
        alp[ord(c)-a_int] = 1

    for i in range(26):
        if alp[i] == 0:
            ans = s+chr(i+a_int)
            break
print(ans)

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

alp = [0]*26
a_int = ord('a')

ans = -1
cand = []
if len(s) == 26:
    for i in reversed(range(1, 26)):
        if s[i] < s[i-1]:
            cand.append(s[i])
            continue
        else:
            cand = sorted(cand)
            print(cand)
            ans = s[0:i-1]+cand[0]
            break

else:
    for c in s:
        alp[ord(c)-a_int] = 1

    for i in range(26):
        if alp[i] == 0:
            ans = s+chr(i+a_int)
            break
print(ans)

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

alp = [0]*26
a_int = ord('a')

if s == "zyxwvutsrqponmlkjihgfedcba":
    ans = -1
else:
    for c in s:
        alp[ord(c)-a_int] = 1

    for i in range(26):
        if alp[i] == 0:
            ans = s+chr(i+a_int)
            break
print(ans)
Problem p03394 (python)

Fixed submission:
N = int(input())

if N==2:
    print(3,5)
    exit()
if N==3:
    print(2,5,63)
    exit()
if N==4:
    print(2,5,20,63)
    exit()

if N==5:
    print(2,5,20,30,63)
    exit()

S=set()
i=2
while len(S)<N:
    if i%2==0 or i%3==0:
        S.add(i)
    i+=1

i+=1
r=sum(S)

if r%6==0:
    pass
elif r%6==2:
    S.remove(8)
    while len(S)<N:
        if i%6==0:
            S.add(i)
            break
        i+=1
elif r%6==3:
    S.remove(9)
    while len(S)<N:
        if i%6==0:
            S.add(i)
            break
        i+=1
elif r%6==5:
    S.remove(9)
    while len(S)<N:
        if i%6==4:
            S.add(i)
            break
        i+=1

assert len(S)==N,len(S)
print(" ".join(map(str,S)))

Buggy submission (verdict: Runtime Error):
N = int(input())

if N==2:
    print(3,5)
    exit()
if N==3:
    print(2,5,63)
    exit()
if N==4:
    print(2,5,20,63)
    exit()

if N==5:
    print(2,5,20,30,63)

S=set()
i=2
while len(S)<N:
    if i%2==0 or i%3==0:
        S.add(i)
    i+=1

i+=1
r=sum(S)

if r%6==0:
    pass
elif r%6==2:
    S.remove(8)
    while len(S)<N:
        if i%6==0:
            S.add(i)
            break
        i+=1
elif r%6==3:
    S.remove(9)
    while len(S)<N:
        if i%6==0:
            S.add(i)
            break
        i+=1
elif r%6==5:
    S.remove(9)
    while len(S)<N:
        if i%6==4:
            S.add(i)
            break
        i+=1

assert len(S)==N,len(S)
print(" ".join(map(str,S)))

Buggy submission (verdict: Runtime Error):
N = int(input())

if N==2:
    print(3,5)
    exit()
if N==3:
    print(2,5,63)
    exit()
if N==4:
    print(2,5,20,63)
    exit()

S=set()
i=2
while len(S)<N:
    if i%2==0 or i%3==0:
        S.add(i)
    i+=1

i+=1
r=sum(S)

if r%6==0:
    pass
elif r%6==2:
    S.remove(8)
    while len(S)<N:
        if i%6==0:
            S.add(i)
            break
        i+=1
elif r%6==3:
    S.remove(9)
    while len(S)<N:
        if i%6==0:
            S.add(i)
            break
        i+=1
elif r%6==5:
    S.remove(9)
    while len(S)<N:
        if i%6==4:
            S.add(i)
            break
        i+=1

assert len(S)==N,len(S)
print(" ".join(map(str,S)))

Buggy submission (verdict: Runtime Error):
N = int(input())

S=set()
i=2
while len(S)<=N:
    if i%2==0 or i%3==0:
        S.add(i)
    i+=1

r=sum(S)%6

if r%6==0:
    pass
elif r%2==0:
    S.remove(8)
    while len(S)<=N:
        if i%6==0:
            S.add(i)
            break
        i+=1
elif r%3==0:
    S.remove(9)
    while len(S)<=N:
        if i%6==0:
            S.add(i)
            break
        i+=1
elif r%5==0:
    S.remove(9)
    while len(S)<=N:
        if i%6==4:
            S.add(i)
            break
        i+=1




print(" ".join(map(str,S)))
Problem p03401 (python)

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 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)
Problem p03408 (python)

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

Buggy 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)
Problem p03434 (python)

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

Buggy 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)
Problem p03435 (python)

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 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")
Problem p03456 (python)

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

Buggy 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)
Problem p03482 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

s = input()

K = float('inf')
if all(c == '0' for c in s):
    K = len(s)
elif all(c == '1' for c in s):
    K = len(s)
else:
    for k in range(1, len(s)):
        if s[k] != s[k-1]:
            K = min(K, max(k, len(s)-k))
        else:
            continue

print(K)

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

s = input()

K = []
for k in range(1, len(s)):
    if s[k] != s[k-1]:
        K.append(max(len(s)-k, k))
    else:
        continue

ans = 0
if min(K) == 0:
    if all(v == "1" for v in s):
        ans = len(s)
else:
    ans = min(K)
print(ans)

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

s = input()

K = []
for k in range(1, len(s)):
    if s[k] != s[k-1]:
        K.append(max(len(s)-k, k))
    else:
        continue

ans = 0
if min(K) == 0:
    if all(v == "1" for v in s):
        ans = len(K)
else:
    ans = min(K)
print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
l=[]

p=s[0]
seq=1

for c in s[1:]:
  if c==p:
    seq+=1
  else:
    l.append(seq)
    seq=1
    p=c
ans=float("inf")

d1=min([a+b for a,b in zip(l[0::2],l[1::2])])
d2=min([a+b for a, b in zip(l[1::2],l[2::2])])
print(min(d1,d2))

Buggy submission (verdict: Runtime Error):
s=input()
l=[]

p=s[0]
seq=1

for c in s[1:]
  if c==p:
    seq+=1
  else:
    l.append(seq)
    seq=1
    p=c
ans=float("inf")

d1=min([a+b for a,b in zip(l[0::2],l[1::2])])
d2=min([a+b for a, b in zip(l[1::2],l[2::2])])
print(min(d1,d2))

Buggy submission (verdict: Runtime Error):
s=input()
l=[]

p=s[0]
seq=1

for c in s[1:]
  if c==p:
    seq+=1
  else:
    l.append(seq)
    seq=1
    prev=c
ans=float("inf")

d1=min([a+b for a,b in zip(l[0::2],l[1::2])])
d2=min([a+b for a, b in zip(l[1::2],l[2::2])])
print(min(d1,d2))
Problem p03486 (python)

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 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")
Problem p03502 (python)

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 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")
Problem p03533 (python)

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

Buggy 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)

Buggy 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)

Buggy 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)
Problem p03574 (python)

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 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])))
Problem p03575 (python)

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 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)
Problem p03583 (python)

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 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()

Buggy 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)
Problem p03592 (python)

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 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")

Buggy 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")
Problem p03593 (python)

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

Buggy 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)
Problem p03599 (python)

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


def concentrate(water, sugar):
    if water+sugar == 0:
        return 0
    else:
        return sugar/(water+sugar)


A, B, C, D, E, F = map(int, input().split())
A *= 100
B *= 100
water_list = []
sugar_list = []

max_cont = E/(E+100)

max_water = F//B+1
for i in range(max_water):
    remain = F - B*i
    if remain < 0:
        break
    else:
        j = remain//A
        for k in range(j+1):
            water_list.append(A*k+B*i)

max_sugar = F//D+1
for i in range(max_sugar):
    tmp = D*i
    remain = F - tmp
    if remain < 0:
        break
    else:
        j = remain//C
        for k in range(j+1):
            sugar_list.append(D*i+C*k)

water_list = sorted(set(water_list))
sugar_list = sorted(set(sugar_list))

max_tmp = 0
ans = [0, 0]
for water in water_list:
    for sugar in sugar_list:
        if water+sugar > F:
            break
        else:
            conc = concentrate(water, sugar)
            if conc > max_cont:
                break
            else:
                if max_tmp <= conc:
                    max_tmp = conc
                    ans = [water, sugar]
print(sum(ans), ans[1])

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


def concentrate(water, sugar):
    if water+sugar == 0:
        return 0
    else:
        return sugar/(water+sugar)


A, B, C, D, E, F = map(int, input().split())
A *= 100
B *= 100
water_list = []
sugar_list = []

max_cont = E/(E+100)

max_water = F//B+1
for i in range(max_water):
    remain = F - B*i
    if remain < 0:
        break
    else:
        j = remain//A
        for k in range(j+1):
            water_list.append(A*k+B*i)

max_sugar = F//D
for i in range(max_sugar):
    tmp = D*i
    remain = F - tmp
    if remain < 0:
        break
    else:
        j = remain//C
        for k in range(j+1):
            sugar_list.append(D*i+C*k)

water_list = sorted(set(water_list))
sugar_list = sorted(set(sugar_list))
print(water_list)

max_tmp = 0
ans = []
for water in water_list:
    for sugar in sugar_list:
        if water+sugar > F:
            break
        else:
            conc = concentrate(water, sugar)
            if conc > max_cont:
                break
            else:
                if max_tmp < conc:
                    max_tmp = conc
                    ans = [water, sugar]
print(sum(ans), ans[1])