Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):

n, y = map(int, input().split())

flg = False

# iは10000円札の枚数、jは5000円札の枚数、kは1000円札の枚数
for i in range(n + 1):
    for j in range(n + 1 - i):
        for k in range(n + 1 - i - j):
            if 10000 * i + 5000 * j + 1000 * k == y and i + j + k == n and not flg:
                flg = True
                print(i, j, k)
                break
        else:
            continue
        break
    else:
        continue
    break

if not flg:
    print(-1, -1, -1)


Fixed submission:

n, y = map(int, input().split())

flg = False

# iは10000円札の枚数、jは5000円札の枚数、kは1000円札の枚数
for i in range(n + 1):
    for j in range(n + 1 - i):
        k = (y - 10000 * i - 5000 * j) // 1000
        if i + j + k == n and not flg:
            flg = True
            print(i, j, k)
            break
    else:
        continue
    break

if not flg:
    print(-1, -1, -1)

Buggy python submission (verdict: Time Limit Exceeded):

n, y = map(int, input().split())

flg = False

# iは10000円札の枚数、jは5000円札の枚数、kは1000円札の枚数
for i in range(n + 1):
    for j in range(n + 1 - i):
        for k in range(n + 1 - i - j):
            if 10000 * i + 5000 * j + 1000 * k == y and i + j + k == n and not flg:
                flg = True
                print(i, j, k)
        else:
            continue
        break
    else:
        continue
    break

if not flg:
    print(-1, -1, -1)


Fixed submission:

n, y = map(int, input().split())

flg = False

# iは10000円札の枚数、jは5000円札の枚数、kは1000円札の枚数
for i in range(n + 1):
    for j in range(n + 1 - i):
        k = (y - 10000 * i - 5000 * j) // 1000
        if i + j + k == n and not flg:
            flg = True
            print(i, j, k)
            break
    else:
        continue
    break

if not flg:
    print(-1, -1, -1)

Buggy python submission (verdict: Time Limit Exceeded):

n, y = map(int, input().split())

flg = False

# iは10000円札の枚数、jは5000円札の枚数、kは1000円札の枚数
for i in range(n + 1):
    for j in range(n + 1 - i):
        for k in range(n + 1 - i - j):
            if 10000 * i + 5000 * j + 1000 * k == y and i + j + k == n and not flg:
                flg = True
                print(i, j, k)

if not flg:
    print(-1, -1, -1)


Fixed submission:

n, y = map(int, input().split())

flg = False

# iは10000円札の枚数、jは5000円札の枚数、kは1000円札の枚数
for i in range(n + 1):
    for j in range(n + 1 - i):
        k = (y - 10000 * i - 5000 * j) // 1000
        if i + j + k == n and not flg:
            flg = True
            print(i, j, k)
            break
    else:
        continue
    break

if not flg:
    print(-1, -1, -1)
Buggy python submission (verdict: Time Limit Exceeded):

n = int(input())


def func(times):
    power = 1
    divide_num = 10 ** 9 + 7

    for i in range(times):
        power *= (i + 1)

    print(power % divide_num)


func(times=n)


Fixed submission:

n = int(input())


def func(times):
    power = 1
    divide_num = 10 ** 9 + 7

    for i in range(times):
        power *= (i + 1)
        power %= divide_num

    print(power)


func(times=n)
Buggy python submission (verdict: Time Limit Exceeded):

s = input()

words = ['dream', 'dreamer', 'erase', 'eraser']

while len(s) > 0:
    for word in words:
        s = s[::-1]
        word = word[::-1]
        flg = False

        if s.startswith(word):
            s = s.replace(word, '', 1)
            s = s[::-1]
            flg = True
            break

        s = s[::-1]

    if not flg:
        break

if len(s) == 0:
    print('YES')
else:
    print('NO')


Fixed submission:

s = input()

words = ['dream', 'dreamer', 'erase', 'eraser']

while len(s) > 0:
    for word in words:
        flg = False

        if s.endswith(word):
            s = s[:(len(s) - len(word))]
            flg = True
            break

    if not flg:
        break

if len(s) == 0:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
import sys

N = int(sys.stdin.readline())

S = sys.stdin.readline()

set = [0]*N
for i in range(N):
    counter = 0
    counter = S[0:i].count("W") + S[i:N].count("E")
    set[i] = counter

print(min(set))

Fixed submission:
import sys

N = int(sys.stdin.readline())
S = sys.stdin.readline()

right = S[1:].count("E")
left = 0
ans = [0]*N
ans[0] = right + left
for i in range(1, N):
    if S[i] == "E":
        right = right - 1
    if S[i-1] == "W":
        left = left + 1
    ans[i] = right+left

print(min(ans))
Buggy python submission (verdict: Runtime Error):
import sys

a = sys.stdin.readline().split(' ')
data = sys.stdin.readlines()

S = int(a[0])
H = int(a[1])

dx = [0,1,0,-1]
dy = [1,0,-1,0]

ans = 'Yes'
if S == 1 and H == 1:
    continue
else:
    for i in range(S):
        for j in range(H):
            if data[i][j] == '.':
                continue
            else:
                for k in range(4):
                    x = j + dx[k]
                    y = i + dy[k]
                    if x < 0 or y < 0 or x >= H or y >= S:
                        continue
                    else:
                        if data[y][x] == "#":
                            ans = 'Yes'
                            break
                        else:
                            ans = 'No'
                            continue

print(ans)



Fixed submission:
import sys

a = sys.stdin.readline().split(' ')
data = sys.stdin.readlines()

S = int(a[0])
H = int(a[1])

dx = [0,1,0,-1]
dy = [1,0,-1,0]

for i in range(S):
    for j in range(H):
        count = 0
        if data[i][j] == '#':
            for k in range(4):
                x = j + dx[k]
                y = i + dy[k]
                if x < 0 or y < 0 or x >= H or y >= S:
                    continue
                else:
                    if data[y][x] == "#":
                        count = count+1
            if count == 0:
                print('No')
                sys.exit()


print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
import sys

num = sys.stdin.readline().split(' ')
K = int(num[0])
S = int(num[1])

counter = 0
for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            if i+j+k == S:
                counter += 1
            else:
                continue

print(counter)

Fixed submission:
import sys

num = sys.stdin.readline().split(' ')
K = int(num[0])
S = int(num[1])

counter = 0
for i in range(K+1):
    for j in range(K+1):
        if 0 <= S-i-j <= K:
            counter += 1
        else:
            continue

print(counter)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = map(int, input().split())
counter = 0

# xが２で何回割れるかの関数
def how_much_time_divisible(x):
    ans = 0　
    while x % 2 == 0:
        x /= 2
        ans += 1
    return ans

# リストaの要素すべてに対して、2で何回割れるかの値に置き換えたい（ｂがその置き換わったリストである）
b = map(how_much_time_divisible, a)
# bの要素で最も小さいものが答えである
print(min(b))


Fixed submission:
n = int(input())
a = map(int, input().split())
counter = 0

# xが２で何回割れるかの関数
def how_much_time_divisible(x):
    ans = 0
    
    while x % 2 == 0:
        x /= 2
        ans += 1
    return ans

# リストaの要素すべてに対して、2で何回割れるかの値に置き換えたい（ｂがその置き換わったリストである）
b = map(how_much_time_divisible, a)
# bの要素で最も小さいものが答えである
print(min(b))
Buggy python submission (verdict: Runtime Error):
a, b, x = map(int, input().split())

def f(n):
    if n = -1:
        return 0
    return n // x

print(f(b)-f(a-1))

Fixed submission:
a, b, x = map(int, input().split())

def f(n):
    if n == -1:
        return 0
    return n // x + 1

print(f(b)-f(a-1))

Buggy python submission (verdict: Time Limit Exceeded):
a, b, x = map(int, input().split())

counter = 0
for i in range(a, b+1):
    if i % x == 0:
        counter += 1
print(counter)


Fixed submission:
a, b, x = map(int, input().split())

def f(n):
    if n == -1:
        return 0
    return n // x + 1

print(f(b)-f(a-1))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())

H=list(str(input()))


m = 0 
for i in range(N):
    c = 0
    for s in range(N):
        if i > s and H[s] == 'W':
            c += 1
        
        if i < s and H[s] == 'E':
            c += 1
    
    if m == 0 or m >c:
        m = c
        


print(m)

Fixed submission:
from itertools import accumulate

N=int(input())
s=str(input())


a = accumulate(c=='W' for c in 'X'+s[:-1])
b = reversed(list(accumulate(c=='E' for c in 'X'+s[-1:0:-1])))
print(min(x + y for x, y in zip(a, b)))
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())

print(math.factorial(n) % (10**9+7)

Fixed submission:
import math
n = int(input())

print(math.factorial(n) % (10**9+7))

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

p=1
for i in range(1, n+1):
    p = i*(p % (10**9 + 7)) 

print(p

Fixed submission:
import math
n = int(input())

print(math.factorial(n) % (10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
 
p=1
for i in range(1, n+1):
    p = p*i  
 
print(p % (10**9 + 7))

Fixed submission:
import math
n = int(input())

print(math.factorial(n) % (10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
 
p=1
for i in range(1, n+1):
    p = p*i  
 
print(p % (10**9 + 7))

Fixed submission:
import math
n = int(input())

print(math.factorial(n) % (10**9+7))

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

p=1
for i in range(1, n+1):
    p = p*i  

print(p % (10**9 + 7)

Fixed submission:
import math
n = int(input())

print(math.factorial(n) % (10**9+7))

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

p=1
for i in range(1, n+1):
    p = p*i  

print(p % (10**9 + 7)

Fixed submission:
import math
n = int(input())

print(math.factorial(n) % (10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
result = 3*10**5
for i in range(0, N):
    count = 0
    for index, s in enumerate(S):
        if index == i:
            continue
        if index < i and s == "W":
            count += 1
        if index > i and s == "E":
            count += 1

    if result > count:
        result = count
print(result)

Fixed submission:
N = int(input())
S = input()
ws = [0]*N
w_c = 0
for i in range(0, N):
    if S[i] == "W":
        w_c += 1
    ws[i] += w_c
es = [0]*N
e_c = 0
for i in reversed(range(0, N)):
    if S[i] == "E":
        e_c += 1
    es[i] += e_c
res = 3*10**5
for i in range(0, N):
    if i - 1 == 0:
        if es[0] < res:
            res = es[1]
        continue
    if i + 1 == N:
        if ws[i] < res:
            res = ws[i-1]
        continue
    t = ws[i-1] + es[i+1]
    if t < res:
        res = t
print(res)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
if (a*b)%2 == 1:
  print "Odd"
else:
  print "Even"

Fixed submission:
a, b = map(int, input().split())
if (a*b)%2 == 1:
  print ("Odd")
else:
  print ("Even")
Buggy python submission (verdict: Runtime Error):
N = int(input())
routes = [(0,0,0)]
append = routes.append
for _ in range(0, N):
    t, x, y = map(int, input().split())
    append((t, x, y))
for i in range(1, N+2):
    bt, bx, by = routes[i-1]
    t, x, y = routes[i]
    ct = t - bt
    # xだけで考える。yとxは独立させて考えて問題ない。両方が成立しなければ成立しないため。
    cx = x - bx
    cy = y - by
    if cx > ct or cy > ct:
        print ("No")
        exit()
    if (cx+cy) % 2 != ct % 2:
        print ("No")
        exit()
print ("Yes")

Fixed submission:
N = int(input())
routes = [(0,0,0)]
append = routes.append
for _ in range(0, N):
    t, x, y = map(int, input().split())
    append((t, x, y))
for i in range(1, N+1):
    bt, bx, by = routes[i-1]
    t, x, y = routes[i]
    ct = t - bt
    # xだけで考える。yとxは独立させて考えて問題ない。両方が成立しなければ成立しないため。
    cx = abs(x - bx)
    cy = abs(y - by)
    if cx > ct or cy > ct:
        print ("No")
        exit()
    if (cx+cy) % 2 != ct % 2:
        print ("No")
        exit()
print ("Yes")
Buggy python submission (verdict: Runtime Error):
import sys
N, Y = map(int, input().split())
for a in range(N+1):
    for b in range(N+1):
        c = N - a - b
        if c < 0:
            continue
        if (10000*a + 5000*b + 1000*c) == Y:
            print(str(a)+" "+str(b)+" "+sstr(c))
            sys.exit()
print("-1 -1 -1")

Fixed submission:
N, Y = map(int, input().split())
result = [-1, -1, -1]
for a in range(0, N+1):
    for b in range(0, N+1):
        c = N-a-b
        if c < 0:
            continue
        if Y == (10000*a + 5000*b + 1000*c):
            result[0] = a
            result[1] = b
            result[2] = c
print (" ".join(map(str, result)))

Buggy python submission (verdict: Runtime Error):
import sys
N, Y = map(int, input().split())
for a in range(N+1):
    for b in range(N+1):
        c = N - a - c
        if c < 0:
            continue
        if 10000*a + 5000*b + 1000*c == Y:
            print(str(a)+" "+str(b)+" "+sstr(c))
            sys.exit()
print("-1 -1 -1")

Fixed submission:
N, Y = map(int, input().split())
result = [-1, -1, -1]
for a in range(0, N+1):
    for b in range(0, N+1):
        c = N-a-b
        if c < 0:
            continue
        if Y == (10000*a + 5000*b + 1000*c):
            result[0] = a
            result[1] = b
            result[2] = c
print (" ".join(map(str, result)))

Buggy python submission (verdict: Runtime Error):
N, Y = map(int, input().split())
result = [-1, -1, -1]
for a in range(0, N):
    for b in range(0, N):
        c = N-(a+b)
        if 10000*a + 5000*b + 1000*c:
            result[0] = a
            result[1] = b
            result[2] = c
print (" ".join(result))

Fixed submission:
N, Y = map(int, input().split())
result = [-1, -1, -1]
for a in range(0, N+1):
    for b in range(0, N+1):
        c = N-a-b
        if c < 0:
            continue
        if Y == (10000*a + 5000*b + 1000*c):
            result[0] = a
            result[1] = b
            result[2] = c
print (" ".join(map(str, result)))
Buggy python submission (verdict: Runtime Error):
total = 0
for i in range(0, N):
    t = sum(map(int, list(str(i))))
    if A <= t <= B:
        total += t
print (total)

Fixed submission:
N, A, B = map(int, input().split())
total = 0
for n in range(1, N+1):
    tmp = n
    t = 0
    while n > 0:
        t += n%10
        n = n // 10
    if A <= t and t <= B:
        total += tmp
print (total)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
args = map(int, input().split())
count = len(set(args))
balls = {}
for ball in count:
    balls[ball] = 0

for i in args:
    balls[i] += 1
if count <= K:
    print (0)
else:
    print (sum(sorted(balls.values())[0:max(count-K, 0)]))


Fixed submission:
N, K = map(int, input().split())
args = list(map(int, input().split()))
ballset = set(args)
balls = {}
for ball in ballset:
    balls[ball] = 0
for i in args:
    balls[i] += 1
count = len(ballset)
if count <= K:
    print (0)
else:
    print (sum(sorted(balls.values())[0:max(count-K, 0)]))

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
args = map(int, input().split())
count = len(set(args))
balls = {}
for ball in count:
    balls[ball] = 0

for i in args:
    balls[i] += 1
if count <= K:
    print (0)
else:
    print (sum(sorted(balls.values())[0:max(count-K, 0)]))


Fixed submission:
N, K = map(int, input().split())
args = list(map(int, input().split()))
ballset = set(args)
balls = {}
for ball in ballset:
    balls[ball] = 0
for i in args:
    balls[i] += 1
count = len(ballset)
if count <= K:
    print (0)
else:
    print (sum(sorted(balls.values())[0:max(count-K, 0)]))
Buggy python submission (verdict: Runtime Error):
import sys
A,B,C,D = map(int, input().split())
if A+B+C+D==7:
    print("A+B+C+D=7")
    sys.exit()
if A-B+C+D==7:
    print("A-B+C+D=7")
    sys.exit()
if A+B-C+D==7:
    print("A+B-C+D=7")
    sys.exit()
if A+B+C-D==7:
    print("A+B+C-D=7")
    sys.exit()
if A-B-C+D==7:
    print("A-B-C+D=7")
    sys.exit()
if A-B+C-D==7:
    print("A-B+C-D=7")
    sys.exit()
if A-B-C+D==7:
    print("A-B-C+D=7")
    sys.exit()
if A-B-C-D==7:
    print("A-B-C-D=7")
    sys.exit()


Fixed submission:
import sys
A,B,C,D = map(int, list(input()))
if A+B+C+D==7:
    print("{}+{}+{}+{}=7".format(A,B,C,D))
    sys.exit()
if A+B-C+D==7:
    print("{}+{}-{}+{}=7".format(A,B,C,D))
    sys.exit()
if A+B+C-D==7:
    print("{}+{}+{}-{}=7".format(A,B,C,D))
    sys.exit()
if A+B-C-D==7:
    print("{}+{}-{}-{}=7".format(A,B,C,D))
    sys.exit()
if A-B+C+D==7:
    print("{}-{}+{}+{}=7".format(A,B,C,D))
    sys.exit()
if A-B-C+D==7:
    print("{}-{}-{}+{}=7".format(A,B,C,D))
    sys.exit()
if A-B+C-D==7:
    print("{}-{}+{}-{}=7".format(A,B,C,D))
    sys.exit()
if A-B-C-D==7:
    print("{}-{}-{}-{}=7".format(A,B,C,D))
    sys.exit()

Buggy python submission (verdict: Runtime Error):
import sys
A,B,C,D = map(int, input().split())
if A+B+C+D==7:
    print("A+B+C+D==7")
    sys.exit()
if A-B+C+D==7:
    print("A-B+C+D==7")
    sys.exit()
if A+B-C+D==7:
    print("A+B-C+D==7")
    sys.exit()
if A+B+C-D==7:
    print("A+B+C-D==7")
    sys.exit()

if A-B-C+D==7:
    print("A-B-C+D==7")
    sys.exit()
if A-B+C-D==7:
    print("A-B+C-D==7")
    sys.exit()
if A-B-C+D==7:
    print("A-B-C+D==7")
    sys.exit()
if A-B-C-D==7:
    print("A-B-C-D==7")
    sys.exit()


Fixed submission:
import sys
A,B,C,D = map(int, list(input()))
if A+B+C+D==7:
    print("{}+{}+{}+{}=7".format(A,B,C,D))
    sys.exit()
if A+B-C+D==7:
    print("{}+{}-{}+{}=7".format(A,B,C,D))
    sys.exit()
if A+B+C-D==7:
    print("{}+{}+{}-{}=7".format(A,B,C,D))
    sys.exit()
if A+B-C-D==7:
    print("{}+{}-{}-{}=7".format(A,B,C,D))
    sys.exit()
if A-B+C+D==7:
    print("{}-{}+{}+{}=7".format(A,B,C,D))
    sys.exit()
if A-B-C+D==7:
    print("{}-{}-{}+{}=7".format(A,B,C,D))
    sys.exit()
if A-B+C-D==7:
    print("{}-{}+{}-{}=7".format(A,B,C,D))
    sys.exit()
if A-B-C-D==7:
    print("{}-{}-{}-{}=7".format(A,B,C,D))
    sys.exit()
Buggy python submission (verdict: Runtime Error):
if int("".join(list(map(int, input().split())))) % 4 == 0:
  print('YES')
else:
  print('NO')

Fixed submission:
if int("".join(list(map(str, input().split())))) % 4 == 0:
  print('YES')
else:
  print('NO')

Buggy python submission (verdict: Runtime Error):
if int(list(map(int, input().split())).join()) % 4 == 0:
  print('YES')
else:
  print('NO')

Fixed submission:
if int("".join(list(map(str, input().split())))) % 4 == 0:
  print('YES')
else:
  print('NO')

Buggy python submission (verdict: Runtime Error):
if int(map(int, input().split()).join()) % 4 == 0:
  print('YES')
else:
  print('NO')

Fixed submission:
if int("".join(list(map(str, input().split())))) % 4 == 0:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
cities = {}
for i in range(0, N):
    cities[i] = 0
for _ in range(0, M):
    a, b = map(int, input().split())
    cities[a] += 1
    cities[b] += 1
# 都市をkeyにしたdictを作って、その内容をインクリしていく?
for i in range(0, N):
    print (cities[i])


Fixed submission:

N, M = map(int, input().split())
cities = {}
for i in range(1, N+1):
    cities[i] = 0
for _ in range(0, M):
    a, b = map(int, input().split())
    cities[a] += 1
    cities[b] += 1
# 都市をkeyにしたdictを作って、その内容をインクリしていく?
for i in range(1, N+1):
    print (cities[i])
Buggy python submission (verdict: Runtime Error):
def f(a, b):
    al = len(str(a))
    bl = len(str(b))
    if al > bl:
        return al
    return bl
N = int(input())
n = int(N**0.5)
result = 12
for i in range(1, n+1):
    for j in range(1, n+1):
        if i*j == N:
            r = f(i, j)
            if r < result:
                result = r
print result()


Fixed submission:
def f(a, b):
    al = len(str(int(a)))
    bl = len(str(int(b)))
    if al > bl:
        return al
    return bl
N = int(input())
result = len(str(N))
for a in range(1, N):
    if a*a > N:
        break
    if (N % a) != 0:
        continue
    b = N / a
    r = f(a, b)
    if r < result:
        result = r
print (result)
Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int, input().split())
count = 0
for a in range(K+1):
    for b in range(K+1):
        for c in range(K+1):
            if a+b+c == S:
                count += 1
print (count)


Fixed submission:
K, S = map(int, input().split())
count = 0
for a in range(K+1):
    for b in range(K+1):
        # **3の全探索は間に合わないため、S-a-bの値が0からKの間である組を数えれば良い。
        # for c in range(K+1):
        #     if a+b+c == S:
        c = S - a - b
        if 0<=c<=K:
            count += 1
print (count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

cnt = float('inf')
for i in range(N):
    W = S[:i].count('W')
    E = S[i + 1:].count('E')
    cnt = min(E + W, cnt)
    
print(cnt)

Fixed submission:
N = int(input())
S = input()

cnt = [[0, 0] for _ in range(N)]

if S[0] == 'W':
    cnt[0][0] = 1

if S[-1] == 'E':
    cnt[-1][1] = 1

for i in range(1, N):
    cnt[i][0] += cnt[i - 1][0]
    if S[i] == 'W':
        cnt[i][0] += 1
    
for i in range(N - 2, -1, -1):
    cnt[i][1] += cnt[i + 1][1]
    if S[i] == 'E':
        cnt[i][1] += 1

count = float('inf')
for i in range(N):
    count = min(count, cnt[i][0] + cnt[i][1])

print(count - 1)
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = []
S.append('.' * (H + 2))
S.extend(['.' + input() + '.' for _ in range(H)])
S.append('.' * (H + 2))

if ''.join(S).count('#') <= 1:
    print("Yes")
    quit()

for y in range(1, H + 1):
    for x in range(1, W + 1):
        if S[y][x] == '#' and set([S[y - 1][x], S[y + 1][x], S[y][x - 1], S[y][x + 1]]) == set('.'):
            print("No")
            quit()
print("Yes")


Fixed submission:
H, W = map(int, input().split())
S = []
S.append('.' * (W + 2))
S.extend(['.' + input() + '.' for _ in range(H)])
S.append('.' * (W + 2))

if ''.join(S).count('#') <= 1:
    print("Yes")
    quit()

for y in range(1, H + 1):
    for x in range(1, W + 1):
        if S[y][x] == '#' and set([S[y - 1][x], S[y + 1][x], S[y][x - 1], S[y][x + 1]]) == set('.'):
            print("No")
            quit()
print("Yes")

Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = []
S.append('.' * (H + 2))
S.extend(['.' + input() + '.' for _ in range(H)])
S.append('.' * (H + 2))

for y in range(1, H + 1):
    for x in range(1, W + 1):
        if S[y][x] == '#' and \
        set([S[y - 1][x], S[y + 1][x], S[y][x - 1], S[y][x + 1]]) == set('.'):
            print("No")
            quit()
print("Yes")


Fixed submission:
H, W = map(int, input().split())
S = []
S.append('.' * (W + 2))
S.extend(['.' + input() + '.' for _ in range(H)])
S.append('.' * (W + 2))

if ''.join(S).count('#') <= 1:
    print("Yes")
    quit()

for y in range(1, H + 1):
    for x in range(1, W + 1):
        if S[y][x] == '#' and set([S[y - 1][x], S[y + 1][x], S[y][x - 1], S[y][x + 1]]) == set('.'):
            print("No")
            quit()
print("Yes")

Buggy python submission (verdict: Runtime Error):
def main():
    H, W = map(int, input().split())
    S = []
    S.append('.' * (H + 2))
    S.extend(['.' + input() + '.' for _ in range(H)])
    S.append('.' * (H + 2))

    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if S[y][x] == '#' and \
            set([S[y - 1][x], S[y + 1][x], S[y][x - 1], S[y][x + 1]]) == set('.'):
                print("No")
                return
    print("Yes")

main()

Fixed submission:
H, W = map(int, input().split())
S = []
S.append('.' * (W + 2))
S.extend(['.' + input() + '.' for _ in range(H)])
S.append('.' * (W + 2))

if ''.join(S).count('#') <= 1:
    print("Yes")
    quit()

for y in range(1, H + 1):
    for x in range(1, W + 1):
        if S[y][x] == '#' and set([S[y - 1][x], S[y + 1][x], S[y][x - 1], S[y][x + 1]]) == set('.'):
            print("No")
            quit()
print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
S = input()[::-1]

words = list(map(lambda s: s[::-1], ['dreamer', 'eraser', 'erase', 'dream']))

while any([w in S for w in words]):
    for w in words:
        if S[:len(w)] == w:
            S = S[len(w):]
            break

print('YES' if len(S) == 0 else 'NO')

Fixed submission:
S = input()[::-1]

words = list(map(lambda s: s[::-1], ['dreamer', 'eraser', 'erase', 'dream']))

while True:
    for w in words:
        if S[:len(w)] == w:
            S = S[len(w):]
            break
    else:
        break

print('YES' if len(S) == 0 else 'NO')