Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
x = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
a.reverse()

b.sort()
b.reverse()

c.sort()
c.reverse()

l = []

for i in range(x[0]):
    for j in range(x[1]):
        for k in range(x[2]):
            l.append(a[i]+b[j]+c[k])

l.sort()
l.reverse()

for i in range(x[3]):
    print(l[i])

Fixed submission:
x,y,z,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

d = []
for xx in a:
    for yy in b:
        d.append(xx+yy)
d.sort()
d.reverse()


e = []
if len(d)>3000:
    for i in range(3000):
        for zz in c:
            e.append(d[i]+zz)
else:
    for xy in d:
        for zz in c:
            e.append(xy+zz)
e.sort()
e.reverse()

for i in range(k):
    print(e[i])
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

a,b,q = map(int,input().split())
s = [-10**11] + [int(input()) for i in range(a)] + [10**11]
t = [-10**11] + [int(input()) for i in range(b)] + [10**11]



for i in range(q):
    x = int(input())
    xs = bisect.bisect_right(s,x)
    xt = bisect.bisect_right(t,x)
    ss = [x-s[xs-1],s[xs]-x]
    tt = [x-t[xt-1],t[xt]-x]
    print(min(max(ss[0],tt[0]), max(ss[1],tt[1]), ss[0]*2+tt[1], ss[1]*2+tt[0], tt[0]*2+ss[1], tt[1]*2+ss[0]))


Fixed submission:
import bisect

a,b,q = map(int,input().split())
s = [-10**11] + [int(input()) for i in range(a)] + [10**11]
t = [-10**11] + [int(input()) for i in range(b)] + [10**11]



for i in range(q):
    x = int(input())
    xs = bisect.bisect_right(s,x)
    xt = bisect.bisect_right(t,x)
    ss = [x-s[xs-1],s[xs]-x]
    tt = [x-t[xt-1],t[xt]-x]
    print(min(max(ss[0],tt[0]), max(ss[1],tt[1]), ss[0]*2+tt[1], ss[1]*2+tt[0], tt[0]*2+ss[1], tt[1]*2+ss[0]))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

inf = float('inf')


a,b,q = map(int,input().split())
s = [-inf] + [int(input()) for i in range(a)] + [inf]
t = [-inf] + [int(input()) for i in range(b)] + [inf]



for i in range(q):
    x = int(input())
    xs = bisect.bisect_right(s,x)
    xt = bisect.bisect_right(t,x)
    ss = [x-s[xs-1],s[xs]-x]
    tt = [x-t[xt-1],t[xt]-x]
    print(min(max(ss[0],tt[0]), max(ss[1],tt[1]), ss[0]*2+tt[1], ss[1]*2+tt[0], tt[0]*2+ss[1], tt[1]*2+ss[0]))


Fixed submission:
import bisect

a,b,q = map(int,input().split())
s = [-10**11] + [int(input()) for i in range(a)] + [10**11]
t = [-10**11] + [int(input()) for i in range(b)] + [10**11]



for i in range(q):
    x = int(input())
    xs = bisect.bisect_right(s,x)
    xt = bisect.bisect_right(t,x)
    ss = [x-s[xs-1],s[xs]-x]
    tt = [x-t[xt-1],t[xt]-x]
    print(min(max(ss[0],tt[0]), max(ss[1],tt[1]), ss[0]*2+tt[1], ss[1]*2+tt[0], tt[0]*2+ss[1], tt[1]*2+ss[0]))
Buggy python submission (verdict: Runtime Error):
s = input()

ans = 'keyence'

for i in range(len(s)):
    if s[i]==ans[0]:
        ans=ans[1:]
if ans=='':
    print('YES')
else:
    print('NO')

Fixed submission:
s = input()

for i in range(len(s)):
    for j in range(i,len(s)):
        if s[:i]+s[j:]=='keyence':
            print('YES')
            exit()
print('NO')
Buggy python submission (verdict: Runtime Error):
s = input()

if s[0]=="W":
    l = [1]
else:
    l = [0,1]

for i in range(1,len(s)):
    if s[i]==s[i-1]:
        l[-1]+=1
    else:
        l.append(1)

rightw = sum(l[2::2])

ans = 0

for i in range(len(l)//2):
    ans += l[2*i+1]*rightw
    if i!=len(s)//2-1:
        rightw -= l[2*i+2]

print(ans)

Fixed submission:
s = input()

if s[0]=="W":
    l = [1]
else:
    l = [0,1]

for i in range(1,len(s)):
    if s[i]==s[i-1]:
        l[-1]+=1
    else:
        l.append(1)

rightw = sum(l[2::2])

ans = 0

for i in range(len(l)//2):
    ans += l[2*i+1]*rightw
    if i!=len(l)//2-1:
        rightw -= l[2*i+2]

print(ans)

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

if s[0]=="W":
    l = [1]
else:
    l = [0,1]

for i in range(1,len(s)):
    if s[i]==s[i-1]:
        l[-1]+=1
    else:
        l.append(1)

rightw = sum(l[2::2])

ans = 0

for i in range(len(s)//2):
    ans += l[2*i+1]*rightw
    rightw -= l[2*i+2]

print(ans)

Fixed submission:
s = input()

if s[0]=="W":
    l = [1]
else:
    l = [0,1]

for i in range(1,len(s)):
    if s[i]==s[i-1]:
        l[-1]+=1
    else:
        l.append(1)

rightw = sum(l[2::2])

ans = 0

for i in range(len(l)//2):
    ans += l[2*i+1]*rightw
    if i!=len(l)//2-1:
        rightw -= l[2*i+2]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n = int(input())
a = list(map(int,input().split()))

a.sort()

b = [0]*n
ans = 0

for i in range(n):
    if b[-i-1]==0:
        c = 2**(len(bin(a[-i-1]))-2)-a[-i-1]
        d = bisect.bisect_left(a,c)
        e = bisect.bisect_right(a,c)
        if a[d]==c:
            for j in range(d,e):
                if b[j]==0 and j!=n-i-1:
                    ans += 1
                    b[-i-1]=1
                    b[j]=1
                    break

print(ans)


Fixed submission:
import bisect

n = int(input())
aa = list(map(int,input().split()))

aa.sort()

a = [aa[0]]
b = [1]

for i in range(1,n):
    if a[-1]==aa[i]:
        b[-1]+=1
    else:
        a.append(aa[i])
        b.append(1)

ans = 0

for i in range(len(a)):
    while b[-i-1]!=0:
        c = 2**(len(bin(a[-i-1]))-2)-a[-i-1]
        d = bisect.bisect_left(a,c)
        if a[d]==c:
            if b[d]>1:
                ans += 1
                b[-i-1] -= 1
                b[d] -= 1
            elif b[d]==1 and a[d]!=a[-i-1]:
                ans += 1
                b[-i-1] -= 1
                b[d] -= 1
            else:
                break
        else:
            break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# n次元バーガーの[全段数,パティ枚数]
def burger(n):
    if n == 0:
        return [1,1]
    return [burger(n-1)[0]*2+3,burger(n-1)[1]*2+1]

# レベルn, 下からx段, 食べるパティp枚
def eat(n,x):
    if n==0:
        if x>0:
            return 1
        else:
            return 0
    if x < 1:
        return 0
    if 1 <= x <= 1+burger(n-1)[0]:
        return eat(n-1,x-1)
    if x == 2 + burger(n-1)[0]:
        return burger(n-1)[1]+1
    if x>2+burger(n-1)[0]:
        return eat(n-1,x-2-burger(n-1)[0])+burger(n-1)[1]+1

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

print(eat(n,x))

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

b = [[1,1]]

for i in range(n):
    b.append([b[-1][0]*2+3, b[-1][1]*2+1])

ans = 0
for i in range(len(b)):
    if x >= b[-1-i][0]:
        x -= b[-1-i][0]
        ans += b[-1-i][1]
        if x > 0:
            x-=1
            ans += 1
        if x>=b[-1-i][0]:
            x -= b[-1 - i][0]
            ans += b[-1 - i][1]
            break
    x-=1
    if x<=0:
        break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def shichigo(s):
    if '3' not in s:
        return False
    if '5' not in s:
        return False
    if '7' not in s:
        return False
    x = s.replace('3','').replace('5','').replace('7','')
    if x=='':
        return True
    return False


n = input()

# k = 桁数-1
k = len(n)-1

# k桁までの753数
ans = 0
for i in range(1,k+1):
    ans += 3**i - 3*2**i + 3

# nの桁の753数/3
a = 3**k - 2**(k+1) + 1

f = int(n[0])

if f<3:
    print(ans)
    exit()
elif f==3:
    for i in range(3*10**k,int(n)+1):
        if shichigo(str(i)):
            ans += 1
elif f<5:
    ans += a
elif f ==5:
    ans += a
    for i in range(5*10**k,int(n)+1):
        if shichigo(str(i)):
            ans += 1
elif f<7:
    ans += 2*a
elif f==7:
    ans += 2*a
    for i in range(7*10**k,int(n)+1):
        if shichigo(str(i)):
            ans += 1
else:
    ans += 3*a

print(ans)

Fixed submission:
def shichigo(s):
    if '3' not in s:
        return False
    if '5' not in s:
        return False
    if '7' not in s:
        return False
    x = s.replace('3','').replace('5','').replace('7','')
    if x=='':
        return True
    return False

n = input()

l = [[] for i in range(len(n))]
l[0] = ['3','5','7']
for i in range(1,len(l)):
    for j in range(len(l[i-1])):
        l[i].append('3'+l[i-1][j])
        l[i].append('5'+l[i-1][j])
        l[i].append('7'+l[i-1][j])

ans = 0
for i in range(len(l)):
    for j in range(len(l[i])):
        if int(n) >= int(l[i][j]):
            if shichigo(l[i][j]):
                ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def shichigo(s):
    if '3' not in s:
        return False
    if '5' not in s:
        return False
    if '7' not in s:
        return False
    x = s.replace('3','').replace('5','').replace('7','')
    if x=='':
        return True
    return False


n = input()

# k = 桁数-1
k = len(n)-1

# k桁までの753数
ans = 0
for i in range(1,k+1):
    ans += 3**i - 3*2**i + 3

# nの桁の753数/3
a = 3**k - 2**(k+1) + 1

f = int(n[0])

if f<3:
    print(ans)
    exit()
elif f==3:
    for i in range(3*10**k,int(n)+1):
        if shichigo(str(i)):
            ans += 1
elif f<5:
    ans += a
elif f ==5:
    ans += a
    for i in range(5*10**k,int(n)+1):
        if shichigo(str(i)):
            ans += 1
elif f<7:
    ans += 2*a
elif f==7:
    ans += 2*a
    for i in range(7*10**k,int(n)+1):
        if shichigo(str(i)):
            ans += 1
else:
    ans += 3*a

print(ans)

Fixed submission:
def shichigo(s):
    if '3' not in s:
        return False
    if '5' not in s:
        return False
    if '7' not in s:
        return False
    x = s.replace('3','').replace('5','').replace('7','')
    if x=='':
        return True
    return False

n = input()

l = [[] for i in range(len(n))]
l[0] = ['3','5','7']
for i in range(1,len(l)):
    for j in range(len(l[i-1])):
        l[i].append('3'+l[i-1][j])
        l[i].append('5'+l[i-1][j])
        l[i].append('7'+l[i-1][j])

ans = 0
for i in range(len(l)):
    for j in range(len(l[i])):
        if int(n) >= int(l[i][j]):
            if shichigo(l[i][j]):
                ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()

x = 0

for i in range(len(s)):
    if x >30:
        print('No')
        exit()
    if s[i]!=t[i]:
        a = s[i]
        b = t[i]
        for j in range(len(s)):
            if s[j] == a:
                s = s[:j] + b + s[j+1:]
            elif s[j] == b:
                s = s[:j] + a + s[j+1:]
        x += 1

if s==t:
    print('Yes')
else:
    print('No')

Fixed submission:
s = input()
t = input()

while s != '':
    if [i for i, x in enumerate(s) if x == s[0]] == [i for i, x in enumerate(t) if x == t[0]]:
        s = s.replace(s[0],'')
        t = t.replace(t[0],'')
    else:
        print('No')
        exit()

print('Yes')

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()

x = 0

for i in range(len(s)):
    if x >30:
        print('No')
        exit()
    if s[i]!=t[i]:
        a = s[i]
        b = t[i]
        for j in range(len(s)):
            if s[j] == a:
                s = s[:j] + b + s[j+1:]
            elif s[j] == b:
                s = s[:j] + a + s[j+1:]
        x += 1

if s==t:
    print('Yes')
else:
    print('No')

Fixed submission:
s = input()
t = input()

while s != '':
    if [i for i, x in enumerate(s) if x == s[0]] == [i for i, x in enumerate(t) if x == t[0]]:
        s = s.replace(s[0],'')
        t = t.replace(t[0],'')
    else:
        print('No')
        exit()

print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n,m,Q= map(int, input().split())

a = np.zeros((n+1,n+1))

for i in range(m):
    l,r = map(int,input().split())
    a[r:,:l+1] += 1

for i in range(Q):
    p,q = map(int, input().split())
    print(int(a[q][p]))

Fixed submission:
n,m,q = map(int, input().split())

a = [[0]*(n+1) for i in range(n+1)]

for i in range(m):
    l,r = map(int, input().split())
    a[l][r]+=1

b = [[0]*(n+1) for i in range(n+1)]

for i in range(1,n+1):
    for j in range(1,n+1):
        b[i][j]=b[i-1][j]+b[i][j-1]-b[i-1][j-1]+a[i][j]

for i in range(q):
    p,q = map(int, input() .split())
    ans = b[q][q]-b[p-1][q]-b[q][p-1]+b[p-1][p-1]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n,m,q = map(int, input().split())

a = np.zeros((n+1,n+1))

for i in range(m):
    l,r = map(int,input().split())
    a[r:,:l+1] += 1

for i in range(q):
    p,q = map(int, input().split())
    print(int(a[q][p]))


Fixed submission:
n,m,q = map(int, input().split())

a = [[0]*(n+1) for i in range(n+1)]

for i in range(m):
    l,r = map(int, input().split())
    a[l][r]+=1

b = [[0]*(n+1) for i in range(n+1)]

for i in range(1,n+1):
    for j in range(1,n+1):
        b[i][j]=b[i-1][j]+b[i][j-1]-b[i-1][j-1]+a[i][j]

for i in range(q):
    p,q = map(int, input() .split())
    ans = b[q][q]-b[p-1][q]-b[q][p-1]+b[p-1][p-1]
    print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))

ans = 0

l = [0]*(n+1)

for i in range(n):
    l[i+1] = (a[i]+l[i])%m

b = [0]*m

for i in range(n+1):
    b[l[i]]+=1

for i in range(m):
    if b[i] >1:
        ans += sum(range(1,b[i]))

print(ans)

Fixed submission:
from itertools import accumulate
from collections import Counter
import math


def combinations_count(n, r):
    return math.factorial(n)//(math.factorial(n-r) * math.factorial(r))

n,m = map(int,input().split())
a = list(map(int, input().split()))

a = [0]+a
b = list(accumulate(a))

for i in range(len(b)):
    b[i]%=m


c = Counter(b)

ans = 0

for x in c:
    if c[x]>1:
        ans += combinations_count(c[x],2)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))

ans = 0

for i in range(len(a)):
    a[i] %= m

x = 0

for i in range(n):
    for j in range(n-i):
        x += a[i+j]
        x %= m
        if x == 0:
            ans += 1
    x = 0

print(ans)


Fixed submission:
from itertools import accumulate
from collections import Counter
import math


def combinations_count(n, r):
    return math.factorial(n)//(math.factorial(n-r) * math.factorial(r))

n,m = map(int,input().split())
a = list(map(int, input().split()))

a = [0]+a
b = list(accumulate(a))

for i in range(len(b)):
    b[i]%=m


c = Counter(b)

ans = 0

for x in c:
    if c[x]>1:
        ans += combinations_count(c[x],2)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))

ans = 0

x = 0

for i in range(n):
    for j in range(n-i):
        x += a[i+j]
        x %= m
        if x == 0:
            ans +=1
    x = 0

print(ans)

Fixed submission:
from itertools import accumulate
from collections import Counter
import math


def combinations_count(n, r):
    return math.factorial(n)//(math.factorial(n-r) * math.factorial(r))

n,m = map(int,input().split())
a = list(map(int, input().split()))

a = [0]+a
b = list(accumulate(a))

for i in range(len(b)):
    b[i]%=m


c = Counter(b)

ans = 0

for x in c:
    if c[x]>1:
        ans += combinations_count(c[x],2)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))

ans = 0

for i in range(n):
    for j in range(i,n):
        if sum(a[i:j+1])%m == 0:
            ans +=1

print(ans)

Fixed submission:
from itertools import accumulate
from collections import Counter
import math


def combinations_count(n, r):
    return math.factorial(n)//(math.factorial(n-r) * math.factorial(r))

n,m = map(int,input().split())
a = list(map(int, input().split()))

a = [0]+a
b = list(accumulate(a))

for i in range(len(b)):
    b[i]%=m


c = Counter(b)

ans = 0

for x in c:
    if c[x]>1:
        ans += combinations_count(c[x],2)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

d,g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]

a = [i for i in range(d)]

b = itertools.permutations(a,d)

ans = float('inf')

for x in b:
    c = 0
    e = 0
    flag = False
    for i in x:
        for j in range(pc[i][0]):
            c += 1
            e += 100*(i+1)
            if e>=g:
                flag = True
                break
        if flag:
            break
        e += pc[i][1]
        if e >= g:
            flag = True
        if flag:
            break
    ans = min(ans, c)

print(ans)



Fixed submission:
import itertools
import math

d,g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]

a = [i for i in range(d)]

b = itertools.permutations(a,d)

ans = float('inf')

for x in b:
    c = 0
    e = 0
    flag = False
    for i in x:
        if e+100*(i+1)*pc[i][0]<=g:
            c += pc[i][0]
            e+=100*(i+1)*pc[i][0]+pc[i][1]
            if e >= g:
                break
        else:
            c += math.ceil((g-e)/(100*(i+1)))
            break
    ans = min(ans, c)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter

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

ab = []
for i in range(m):
    a,b = map(int, input().split())
    ab.append([a-1,b-1])

ab.sort(key=itemgetter(1))

fall = [0 for i in range(n-1)]

for i in range(len(ab)):
    flag = True
    for j in range(ab[i][0],ab[i][1]):
        if fall[j]:
            flag = False
            break
    if flag:
        fall[ab[i][1]-1] = 1

print(fall.count(1))


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

l = []

for i in range(m):
    a, b = map(int, input().split())
    l.append([b, a])

l.sort()

ans = 0
x = 0

for i in range(m):
    if l[i][1] >= x:
        ans += 1
        x = l[i][0]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]

x = 0
ans = 0

while x < n:
    p = 10000000
    for y in a:
        if y[0] >= x:
            p = min(p, y[1])
    for y in a:
        if y[0] < x:
            a.remove(y)
    if p <= n:
        ans += 1
    if p == 10000000:
        break
    x = p

print(ans)

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

l = []

for i in range(m):
    a, b = map(int, input().split())
    l.append([b, a])

l.sort()

ans = 0
x = 0

for i in range(m):
    if l[i][1] >= x:
        ans += 1
        x = l[i][0]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]

x = 0
ans = 0


while x < n:
    p = 10000000
    for i in range(m):
        if a[i][0] >= x:
            p = min(p, a[i][1])
    if p <= n:
        ans +=1
    if p == 10000000:
        break
    x = p

print(ans)

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

l = []

for i in range(m):
    a, b = map(int, input().split())
    l.append([b, a])

l.sort()

ans = 0
x = 0

for i in range(m):
    if l[i][1] >= x:
        ans += 1
        x = l[i][0]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

ans = min(s[1:].count("E"), s[:-1].count("W"))

for i in range(1,n-1):
    ans = min(s[:i].count("W")+s[i+1:].count("E"), ans)

print(ans)

Fixed submission:
n = int(input())
s = input()

ans = [0]*n
ans[0] = s[1:].count("E")

for i in range(1,n):
    ans[i]=ans[i-1]
    if s[i-1]=="W":
        ans[i] += 1
    if s[i]=="E":
        ans[i] -= 1

print(min(ans))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
k = int(input())

sub = []

for i in range(len(s)):
    for j in range(i,len(s)):
        if s[i:j+1] not in sub:
            sub.append(s[i:j+1])
            sub.sort()
        if len(sub) > 5:
            sub = sub[:5]

print(sub[k-1])

Fixed submission:
s = input()
k = int(input())

sub = []

for i in range(len(s)):
    for j in range(1,6):
        if s[i:i+j] not in sub:
            sub.append(s[i:i+j])
            sub.sort()
        if len(sub) > 5:
            sub = sub[:5]

print(sub[k-1])

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

sub = []

for i in range(len(s)):
    for j in range(i,len(s)):
            sub.append(s[i:j+1])

sub2 = set(sub)
sub3 = list(sub2)

sub3.sort()

print(sub3[k-1])

Fixed submission:
s = input()
k = int(input())

sub = []

for i in range(len(s)):
    for j in range(1,6):
        if s[i:i+j] not in sub:
            sub.append(s[i:i+j])
            sub.sort()
        if len(sub) > 5:
            sub = sub[:5]

print(sub[k-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
k = int(input())

sub = []

for i in range(len(s)):
    for j in range(i,len(s)):
        if s[i:j+1] not in sub:
            sub.append(s[i:j+1])

sub.sort()

print(sub[k-1])

Fixed submission:
s = input()
k = int(input())

sub = []

for i in range(len(s)):
    for j in range(1,6):
        if s[i:i+j] not in sub:
            sub.append(s[i:i+j])
            sub.sort()
        if len(sub) > 5:
            sub = sub[:5]

print(sub[k-1])
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())

s = [input() for i in range(h)]

for i in range(1,h-1):
    for j in range(1, w-1):
        if s[i][j]=="#" and s[i+1][j]=="." and s[i][j+1]=="." and s[i-1][j]=="." and s[i][j-1]==".":
            print("No")
            exit()

for j in range(1,w-1):
    if s[0][j] == "#" and s[1][j] == "." and s[0][j + 1] == "." and s[0][j - 1] == ".":
        print("No")
        exit()
    if s[h-1][j] == "#" and s[h-2][j] == "." and s[h-1][j + 1] == "." and s[h-1][j - 1] == ".":
        print("No")
        exit()


for i in range(1,h-1):
    if s[i][0] == "#" and s[i + 1][0] == "." and s[i][1] == "." and s[i - 1][0] == ".":
        print("No")
        exit()
    if s[i][w-1] == "#" and s[i + 1][w-1] == "." and s[i][w-2] == "." and s[i - 1][w-1] == ".":
        print("No")
        exit()

if s[0][0]=="#" and s[1][0]=="." and s[0][1]==".":
    print("No")
    exit()

if s[h-1][0]=="#" and s[h-1][1]=="." and s[h-2][0]==".":
    print("No")
    exit()

if s[0][w-1]=="#" and s[1][w-1]=="." and s[0][w-2]==".":
    print("No")
    exit()

if s[h-1][w-1]=="#" and s[h-1][w-2]=="." and s[h-2][s-1]==".":
    print("No")
    exit()

print("Yes")

Fixed submission:
h, w = map(int, input().split())

s = [input() for i in range(h)]

for i in range(1,h-1):
    for j in range(1, w-1):
        if s[i][j]=="#" and s[i+1][j]=="." and s[i][j+1]=="." and s[i-1][j]=="." and s[i][j-1]==".":
            print("No")
            exit()

for j in range(1,w-1):
    if s[0][j] == "#" and s[1][j] == "." and s[0][j + 1] == "." and s[0][j - 1] == ".":
        print("No")
        exit()
    if s[h-1][j] == "#" and s[h-2][j] == "." and s[h-1][j + 1] == "." and s[h-1][j - 1] == ".":
        print("No")
        exit()


for i in range(1,h-1):
    if s[i][0] == "#" and s[i + 1][0] == "." and s[i][1] == "." and s[i - 1][0] == ".":
        print("No")
        exit()
    if s[i][w-1] == "#" and s[i + 1][w-1] == "." and s[i][w-2] == "." and s[i - 1][w-1] == ".":
        print("No")
        exit()

if s[0][0]=="#" and s[1][0]=="." and s[0][1]==".":
    print("No")
    exit()

if s[h-1][0]=="#" and s[h-1][1]=="." and s[h-2][0]==".":
    print("No")
    exit()

if s[0][w-1]=="#" and s[1][w-1]=="." and s[0][w-2]==".":
    print("No")
    exit()

if s[h-1][w-1]=="#" and s[h-1][w-2]=="." and s[h-2][w-1]==".":
    print("No")
    exit()

print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
import statistics

n = int(input())
x = list(map(int, input().split()))

print(statistics.median(x[1:]))

for i in range(1,n-1):
    print(statistics.median(x[0:i]+x[i+1:]))

print(statistics.median(x[0:n-1]))


Fixed submission:
import statistics

n = int(input())
x = list(map(int, input().split()))

high = statistics.median_high(x)
low = statistics.median_low(x)

for i in range(n):
    if x[i]<= low:
        print(high)
    else:
        print(low)