Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np
l, a, b, m = map(int, input().split())
# l = 107
# a = 10000000000007  # 10**13 + 7
# b = 1000000000000007  # 10**15 + 7
# m = 998244353

s_max = a + b * (l - 1)
ten_pow = [1]
while ten_pow[-1] <= s_max:
    ten_pow.append(ten_pow[-1] * 10)
D_MAX = len(ten_pow)
d = [0] * D_MAX
for i in range(D_MAX):
    if ten_pow[i] >= a:
        d[i] = (ten_pow[i] - a) // b
        if (ten_pow[i] - a) % b == 0:
            d[i] -= 1
d[-1] = l - 1
cd = [d[i + 1] - d[i] for i in range(len(d) - 1)]
# print(ten_pow)
# print(d)
# print(cd)

y = np.array([a, a + b, 1]).T % m
for i in range(len(cd)):
    x = np.array([[ten_pow[i + 1], 1, 0], [0, 1, b], [0, 0, 1]])
    x %= m
    # print(x)
    # print('y', y)
    k = cd[i]
    while k > 0:
        if k & 1:
            y = (x @ y) % m
            # print('y', y)
        x = (x @ x) % m
        k = k >> 1

ans = y[0]
print(ans)


Fixed submission:
import numpy as np
l, a, b, m = map(int, input().split())
# l = 107
# a = 10000000000007  # 10**13 + 7
# b = 1000000000000007  # 10**15 + 7
# m = 998244353

s_max = a + b * (l - 1)

# ten_pow[i] = 10**i
ten_pow = [1]
while ten_pow[-1] <= s_max:
    ten_pow.append(ten_pow[-1] * 10)

# d[i] = (s_j <= 10**i - 1 なるjの数)
D_MAX = len(ten_pow)
d = [0] * D_MAX
for i in range(D_MAX):
    if ten_pow[i] >= a:
        d[i] = max((ten_pow[i] - 1 - a) // b, 0)
d[-1] = l - 1

# cd[i] = ((i+1)桁のsの要素数(s_0を除く))
cd = [d[i + 1] - d[i] for i in range(len(d) - 1)]
# print(ten_pow)
# print(d)
# print(cd)

y = np.array([a, a + b, 1]).T % m
for i in range(len(cd)):
    x = np.array([[ten_pow[i + 1] % m, 1, 0], [0, 1, b], [0, 0, 1]])
    x %= m
    # print(x)
    # print('y', y)
    k = cd[i]
    while k > 0:
        if k & 1:
            y = np.dot(x, y) % m
            # print('y', y)
        x = np.dot(x, x) % m
        k = k >> 1

ans = y[0] % m
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
r, g, b, n = map(int, input().split())

ans = 0
for i in range(n // r + 1):
    for j in range(n // g + 1):
        m = r * i + g * j
        if m <= n and (n - m) % b == 0:
            ans += 1

print(ans)


Fixed submission:
r, g, b, n = map(int, input().split())

ans = 0
for i in range(n // r + 1):
    for j in range(n // g + 1):
        m = r * i + g * j
        if m <= n and (n - m) % b == 0:
            ans += 1
        elif m > n:
            break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h, w = map(int, input().split())
a = ['#' * (w+2)] + ['#' + input() + '#' for i in range(h)] + ['#' * (w+2)]
for i in range(h+2):
    a[i] = list(a[i])

d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
x = []
for i in range(1, h+1):
    for j in range(1, w+1):
        if a[i][j] == '#':
            x.append((i, j))

ans = 0
while x:
    y = []
    for i, j in x:
        for di, dj in d:
            if a[i+di][j+dj] == '.':
                a[i+di][j+dj] = '#'
                y.append((i+di, j+dj))
    x = y.copy()
    ans += 1
    # for i in range(h+2):
    #     print("".join(a[i]))
    # print()

ans -= 1
print(ans)


Fixed submission:
from collections import deque
h, w = map(int, input().split())
a = ['#' * (w+2)] + ['#' + input() + '#' for i in range(h)] + ['#' * (w+2)]
for i in range(h+2):
    a[i] = list(a[i])

d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
x = []
for i in range(1, h+1):
    for j in range(1, w+1):
        if a[i][j] == '#':
            x.append((i, j))

ans = 0
while x:
    y = []
    for i, j in x:
        for di, dj in d:
            if a[i+di][j+dj] == '.':
                a[i+di][j+dj] = '#'
                y.append((i+di, j+dj))
    x = y
    ans += 1
    # for i in range(h+2):
    #     print("".join(a[i]))
    # print()

ans -= 1
print(ans)
Buggy python submission (verdict: Runtime Error):
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 i in range(x):
    for j in range(y):
        d.append(a[i] + b[j])
d.sort(reverse=True)

e = []
for i in range(k):
    for j in range(z):
        e.append(d[i] + c[j])
e.sort(reverse=True)

for i in range(k):
    print(e[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 i in range(x):
    for j in range(y):
        d.append(a[i] + b[j])
d.sort(reverse=True)

e = []
for i in range(min(len(d), k)):
    for j in range(z):
        e.append(d[i] + c[j])
e.sort(reverse=True)

for i in range(k):
    print(e[i])

Buggy python submission (verdict: Runtime Error):
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 i in range(x):
    for j in range(y):
        d.append(a[i] + b[j])
d.sort(reverse=True)

e = []
for i in range(k):
    for j in range(z):
        e.append(d[i] + c[j])
e.sort(reverse=True)

for i in range(k):
    print(e[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 i in range(x):
    for j in range(y):
        d.append(a[i] + b[j])
d.sort(reverse=True)

e = []
for i in range(min(len(d), k)):
    for j in range(z):
        e.append(d[i] + c[j])
e.sort(reverse=True)

for i in range(k):
    print(e[i])
Buggy python submission (verdict: Runtime Error):
print('YES' if set(map(int, input().split())) == set(1, 9, 7, 4) else 'NO')


Fixed submission:
print('YES' if set(list(map(int,
                            input().split()))) == set([1, 9, 7, 4]) else 'NO')
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = [input() for _ in range(h)]

is_used = [[False] * w for _ in range(h)]

di = [+1, 0, -1, 0]
dj = [0, +1, 0, -1]


def dfs(i, j):
    if s[i][j] == '#':
        cnt_w, cnt_b = 0, 1
    else:
        cnt_w, cnt_b = 1, 0

    for k in range(4):
        ni = i + di[k]
        nj = j + dj[k]
        if ni < 0 or ni >= h or nj < 0 or nj >= w:
            continue
        if is_used[ni][nj]:
            continue
        if s[i][j] == s[ni][nj]:
            continue

        is_used[ni][nj] = True
        cw, cb = dfs(ni, nj)
        cnt_w += cw
        cnt_b += cb
    return (cnt_w, cnt_b)


ans = 0
for i in range(h):
    for j in range(w):
        if not is_used[i][j]:
            is_used[i][j] = True
            cnt_w, cnt_b = dfs(i, j)
            ans += cnt_w * cnt_b

print(ans)


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

h, w = map(int, input().split())
s = [input() for _ in range(h)]

is_used = [[False] * w for _ in range(h)]

di = [+1, 0, -1, 0]
dj = [0, +1, 0, -1]


def dfs(i, j):
    if s[i][j] == '#':
        cnt_w, cnt_b = 0, 1
    else:
        cnt_w, cnt_b = 1, 0

    for k in range(4):
        ni = i + di[k]
        nj = j + dj[k]
        if ni < 0 or ni >= h or nj < 0 or nj >= w:
            continue
        if is_used[ni][nj]:
            continue
        if s[i][j] == s[ni][nj]:
            continue

        is_used[ni][nj] = True
        cw, cb = dfs(ni, nj)
        cnt_w += cw
        cnt_b += cb
    return (cnt_w, cnt_b)


ans = 0
for i in range(h):
    for j in range(w):
        if not is_used[i][j]:
            is_used[i][j] = True
            cnt_w, cnt_b = dfs(i, j)
            ans += cnt_w * cnt_b

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = tuple(map(int, input().split()))

INF = 10**10
dp = [INF] * n
dp[0] = 0
# dp[i] = (足場iにたどり着いた時点でのコストの最小値)

for i in range(n):
    for j in range(i + 1, min(i + k + 1, n)):
        if dp[j] > dp[i] + abs(h[j] - h[i]):
            dp[j] = dp[i] + abs(h[j] - h[i])

print(dp[n - 1])


Fixed submission:
n, k = map(int, input().split())
h = tuple(map(int, input().split()))

INF = float('inf')
dp = [INF] * n
dp[0] = 0
# dp[i] = (足場iにたどり着いた時点でのコストの最小値)

for i in range(n):
    for j in range(i + 1, min(i + k + 1, n)):
        dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]))

print(dp[n - 1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = tuple(map(int, input().split()))

INF = float('inf')
dp = [INF] * n
dp[0] = 0
# dp[i] = (足場iにたどり着いた時点でのコストの最小値)

for i in range(n):
    for j in range(i + 1, min(i + k + 1, n)):
        if dp[j] > dp[i] + abs(h[j] - h[i]):
            dp[j] = dp[i] + abs(h[j] - h[i])

print(dp[n - 1])


Fixed submission:
n, k = map(int, input().split())
h = tuple(map(int, input().split()))

INF = float('inf')
dp = [INF] * n
dp[0] = 0
# dp[i] = (足場iにたどり着いた時点でのコストの最小値)

for i in range(n):
    for j in range(i + 1, min(i + k + 1, n)):
        dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]))

print(dp[n - 1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = tuple(map(int, input().split()))

INF = float('inf')
dp = [INF] * n
dp[0] = 0
# dp[i] = (足場iにたどり着いた時点でのコストの最小値)

for i in range(n):
    for j in range(i + 1, min(i + k + 1, n)):
        dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]))

print(dp[n - 1])


Fixed submission:
n, k = map(int, input().split())
h = tuple(map(int, input().split()))

INF = float('inf')
dp = [INF] * n
dp[0] = 0
# dp[i] = (足場iにたどり着いた時点でのコストの最小値)

for i in range(n):
    for j in range(i + 1, min(i + k + 1, n)):
        dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]))

print(dp[n - 1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = tuple(map(int, input().split()))

INF = float('inf')
dp = [INF] * n
dp[0] = 0
# dp[i] = (足場iにたどり着いた時点でのコストの最小値)

for i in range(n):
    for j in range(i + 1, min(i + k + 1, n)):
        dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]))

print(dp[n - 1])


Fixed submission:
n, k = map(int, input().split())
h = tuple(map(int, input().split()))

INF = float('inf')
dp = [INF] * n
dp[0] = 0
# dp[i] = (足場iにたどり着いた時点でのコストの最小値)

for i in range(n):
    for j in range(i + 1, min(i + k + 1, n)):
        dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]))

print(dp[n - 1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n, w = map(int, input().split())
items = [tuple(map(int, input().split())) for _ in range(n)]

dp = [[0] * (w + 1) for _ in range(n + 1)]

for i, (wi, vi) in enumerate(items):
    for j in range(w + 1):
        if j >= wi:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - wi] + vi)
        else:
            dp[i + 1][j] = dp[i][j]

print(dp[n][w])


Fixed submission:
import sys
input = sys.stdin.readline

n, w = map(int, input().split())
items = [tuple(map(int, input().split())) for _ in range(n)]

dp = [[0] * (w + 1) for _ in range(n + 1)]

for i, (wi, vi) in enumerate(items):
    for j in range(w + 1):
        if j >= wi:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - wi] + vi)
        else:
            dp[i + 1][j] = dp[i][j]

print(dp[n][w])

Buggy python submission (verdict: Time Limit Exceeded):
n, w = map(int, input().split())
items = [tuple(map(int, input().split())) for _ in range(n)]

dp = [[0] * (w + 1) for _ in range(n + 1)]

for i, (wi, vi) in enumerate(items):
    for j in range(w + 1):
        if j >= wi:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - wi] + vi)
        else:
            dp[i + 1][j] = dp[i][j]

print(dp[n][w])


Fixed submission:
import sys
input = sys.stdin.readline

n, w = map(int, input().split())
items = [tuple(map(int, input().split())) for _ in range(n)]

dp = [[0] * (w + 1) for _ in range(n + 1)]

for i, (wi, vi) in enumerate(items):
    for j in range(w + 1):
        if j >= wi:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - wi] + vi)
        else:
            dp[i + 1][j] = dp[i][j]

print(dp[n][w])
Buggy python submission (verdict: Runtime Error):
#include <cstdio>
#include <vector>
using namespace std;

vector<int> divisor(int m) {
    vector<int> divs;
    for (int i = 1; i*i <= m; i++) {
        if (m % i == 0) {
            divs.push_back(i);
            if (m != i*i) {
                divs.push_back(m / i);
            }
        }
    }
    sort(divs.begin(), divs.end());

    return divs;
}

int main() {
    int n, m;

    scanf("%d%d", &n, &m);
    vector<int> divs = divisor(m);

    for (int i = divs.size()-1; i >= 0; i--) {
        if (divs[i] * n <= m) {
            printf("%d\n", divs[i]);
            break;
        }
    }
    return 0;
}


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

p = m // n
while m % p != 0:
    p -= 1

print(p)

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

p = m // n
while m % p != 0:
    p -= 1

print(p)


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

p = m // n
while m % p != 0:
    p -= 1

print(p)
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left

n, k = map(int, input().split())
x = list(map(int, input().split()))
if 0 in x:
    x.remove(0)
    k -= 1
    n -= 1

if n == 0:
    print(0)
else:
    si = bisect_left(x, 0)

    ans = x[-1] - x[0]
    if si + k - 1 < len(x):
        ans = min(ans, x[si + k - 1])
    if si - k >= 0:
        ans = min(ans, abs(x[si - k]))

    for i in range(n):
        tmp_ans = 0
        if i < si and i + k -1 < len(x):
            tmp_ans = abs(x[i]) * 2 + x[i + k - 1]
            ans = min(ans, tmp_ans)
        elif i - k + 1 >= 0:
            tmp_ans = x[i] * 2 + abs(x[i - k + 1])
            ans = min(ans, tmp_ans)

    print(ans)


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

print(n-i+1)
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left

n, k = map(int, input().split())
x = list(map(int, input().split()))
# if 0 in x:
#     x.remove(0)
#     k -= 1
#     n -= 1
#
# if n == 0:
#     print(0)

si = bisect_left(x, 0)


ans = x[-1] - x[0]
if si + k - 1 < len(x):
    ans = min(ans, x[si + k - 1])
if si - k >= 0:
    ans = min(ans, abs(x[si - k]))

for i in range(n):
    tmp_ans = 0
    if i < si:
        tmp_ans = abs(x[i]) * 2 + x[i + k - 1]
        ans = min(ans, tmp_ans)
    elif i - k + 1 >= 0:
        tmp_ans = x[i] * 2 + abs(x[i - k + 1])
        ans = min(ans, tmp_ans)

print(ans)


Fixed submission:
from bisect import bisect_left

n, k = map(int, input().split())
x = list(map(int, input().split()))
if 0 in x:
    x.remove(0)
    k -= 1
    n -= 1

if n == 0:
    print(0)
else:
    si = bisect_left(x, 0)

    ans = (x[-1] - x[0]) * 2
    if si + k - 1 < len(x):
        ans = min(ans, x[si + k - 1])
    if si - k >= 0:
        ans = min(ans, abs(x[si - k]))

    for i in range(n):
        tmp_ans = 0
        if i < si and i + k -1 < len(x):
            tmp_ans = abs(x[i]) * 2 + x[i + k - 1]
            ans = min(ans, tmp_ans)
        elif i >= si and i - k + 1 >= 0:
            tmp_ans = x[i] * 2 + abs(x[i - k + 1])
            ans = min(ans, tmp_ans)

    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
m = (n * (n + 1) // 2) // 2 + 1


class BIT1():
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (self.n + 1)
        self.data = [0] * (self.n + 1)

    def add(self, idx, x):
        # add x to idx-th element
        # idx: 1-indexed
        self.data[idx] += x
        while idx <= self.n:
            self.bit[idx] += x
            idx += (idx & (-idx))

    def sum(self, idx):
        # get sum of [1, idx]
        # idx: 1-indexed
        s = 0
        while idx:
            s += self.bit[idx]
            idx -= (idx & (-idx))
        return s


def check(x):
    # MofM が x以下である
    # x以下の要素が (n*(n+1)//2)//2 + 1 個以上ある

    s = 0
    c = [0] * (n + 1)
    for i in range(n):
        c[i + 1] = c[i]
        if a[i] <= x:
            c[i + 1] += 1
    d = [2 * c[i] - i + n + 1 for i in range(n + 1)]
    d_max = max(d)
    bit = BIT1(d_max)

    cnt = 0
    for i in range(n + 1):
        cnt += bit.sum(d[i] - 1)
        bit.add(d[i], 1)
    return cnt >= m


lb = 0  # False
ub = max(a) + 1  # True
while ub - lb > 1:
    mid = (ub + lb) // 2
    if check(mid):
        ub = mid
    else:
        lb = mid

print(ub)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
m = (n * (n + 1) // 2) // 2 + 1


class BIT1():
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (self.n + 1)
        self.data = [0] * (self.n + 1)

    def add(self, idx, x):
        # add x to idx-th element
        # idx: 1-indexed
        self.data[idx] += x
        while idx <= self.n:
            self.bit[idx] += x
            idx += (idx & (-idx))

    def sum(self, idx):
        # get sum of [1, idx]
        # idx: 1-indexed
        s = 0
        while idx:
            s += self.bit[idx]
            idx -= (idx & (-idx))
        return s


def check(x):
    # MofM が x以下である
    # x以下の要素が (n*(n+1)//2)//2 + 1 個以上ある

    s = 0
    c = [0] * (n + 1)
    for i in range(n):
        c[i + 1] = c[i]
        if a[i] <= x:
            c[i + 1] += 1
    d = [2 * c[i] - i + n + 1 for i in range(n + 1)]
    d_max = max(d)
    bit = BIT1(d_max)

    cnt = 0
    for i in range(n + 1):
        cnt += bit.sum(d[i] - 1)
        bit.add(d[i], 1)
    return cnt >= m


lb = 0  # False
ub = max(a) + 1  # True
while ub - lb > 1:
    mid = (ub + lb) // 2
    if check(mid):
        ub = mid
    else:
        lb = mid

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

for i in range(min(k, len(s))):
    if s[i] != "1":
        ans = s[i]
        break

print(ans)


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

ans = s[0]
for i in range(min(k, len(s))):
    if s[i] != '1':
        ans = s[i]
        break

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

ans = 0
for i in range(len(s)):
    if s[i] == "+":
        ans += 1ac
    else:
        ans -= 1

print(ans)


Fixed submission:
s = input()

ans = 0
for i in range(len(s)):
    if s[i] == "+":
        ans += 1
    else:
        ans -= 1

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

cand = [s[0]]
for i in range(len(s)):
    if len(cand) == n and s[i] > cand[-1]:
        continue
    for j in range(i, len(s)):
        tmp = s[i:j+1]
        #print(i,j, tmp, cand)
        if tmp in cand:
            continue
        cand += [tmp]
        #cand = sorted(cand)
        cand.sort()
        if len(cand) > n:
            cand.pop()


print(cand.pop())


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

cand = [str(s[0])]
for i in range(len(s)):
    if len(cand) == n and s[i] > cand[-1]:
        continue
    for j in range(i, len(s)):
        tmp = s[i:j+1]
        #print(i,j, tmp, cand)
        if len(cand) == n and tmp > cand[-1]:
            break
        if tmp in cand:
            continue
        cand += [tmp]
        #cand = sorted(cand)
        cand.sort()
        if len(cand) > n:
            cand.pop()


print(cand.pop())

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

cand = [str(s[0])]
for i in range(len(s)):
    if len(cand) == n and s[i] > cand[-1]:
        continue
    for j in range(i, len(s)):
        tmp = str(s[i:j+1])
        #print(i,j, tmp, cand)
        if tmp in cand:
            continue
        cand += [tmp]
        cand = sorted(cand)
        if len(cand) > n:
            cand.pop()


print(cand.pop())


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

cand = [str(s[0])]
for i in range(len(s)):
    if len(cand) == n and s[i] > cand[-1]:
        continue
    for j in range(i, len(s)):
        tmp = s[i:j+1]
        #print(i,j, tmp, cand)
        if len(cand) == n and tmp > cand[-1]:
            break
        if tmp in cand:
            continue
        cand += [tmp]
        #cand = sorted(cand)
        cand.sort()
        if len(cand) > n:
            cand.pop()


print(cand.pop())
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = ['.'*(h+2)] + ['.' + input() + '.' for i in range(h)] + ['.'*(h+2)]
d = [[1, 0], [0, 1], [-1, 0], [0, -1]]

ans = 0
for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j] == '.':
            continue
        c = 0
        for k in range(4):
            if s[i+d[k][0]][j+d[k][1]] == "#":
                c += 1
        if c == 0:
            ans = -1

if ans == -1:
    print("No")
else:
    print("Yes")


Fixed submission:
h, w = map(int, input().split())
s = ['.'*(w+2)] + ['.' + input() + '.' for i in range(h)] + ['.'*(w+2)]
d = [[1, 0], [0, 1], [-1, 0], [0, -1]]

ans = 0
for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j] == '.':
            continue
        c = 0
        for k in range(4):
            if s[i+d[k][0]][j+d[k][1]] == "#":
                c += 1
        if c == 0:
            ans = -1

if ans == -1:
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
a.sort()

def comb(n, k):
    ans = 1
    for i in range(k):
        ans = ans * (n - i) // (i + 1)
    return ans


i = bisect_left(a, a[-1]/2)
ans = comb(a[-1], a[i])
if i > 0:
    if ans > comb(a[-1], a[i-1]):
        print(a[-1], a[i])
    else:
        print(a[-1], a[i-1])
else:
    print(a[-1], a[i])


Fixed submission:
from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
a.sort()

def comb(n, k):
    ans = 1
    for i in range(k):
        ans = ans * (n - i) // (i + 1)
    return ans


i = bisect_left(a, a[-1]/2)
if i > 0:
    if abs(a[-1]/2 - a[i]) < abs(a[-1]/2 - a[i-1]):
        print(a[-1], a[i])
    else:
        print(a[-1], a[i-1])
else:
    print(a[-1], a[i])
Buggy python submission (verdict: Runtime Error):
n = int(input())

print(m // 3)


Fixed submission:
n = int(input())

print(n // 3)
Buggy python submission (verdict: Runtime Error):
import gc
n, k = map(int, input().split())
k2 = k * 2
b = [[0] * (k * 3) for _ in range(k * 3)]
for i in range(n):
    x, y, c = input().split()
    x = int(x) % k2
    y = int(y) % k2
    if c == 'W':
        x = (x + k) % k2

    b[x][y] += 1
    if x < k:
        b[x + k2][y] += 1
    if y < k:
        b[x][y + k2] += 1
    if x < k and y < k:
        b[x + k2][y + k2] += 1

b_cs = [[0] * (k * 3 + 2) for _ in range(k * 3 + 2)]
for i in range(k * 3 + 1):
    for j in range(k * 3 + 1):
        b_cs[i + 1][j +
                    1] = b_cs[i + 1][j] + b_cs[i][j + 1] - b_cs[i][j] + b[i][j]


def func_b(x, y):
    return b_cs[x + k][y + k] - b_cs[x + k][y] - b_cs[x][y + k] + b_cs[x][y]


# print('black')
# print(*b, sep='\n')
# print(*b_cs, sep='\n')

ans = 0
for i in range(k + 1):
    for j in range(k + 1):
        cand = 0
        cand += func_b(i, j)
        cand += func_b(i + k, j + k)
        # print(i, j, cand)
        ans = max(ans, cand)

print(ans)


Fixed submission:
import gc
n, k = map(int, input().split())
k2 = k * 2
b = [[0] * (k * 3) for _ in range(k * 3)]
for i in range(n):
    x, y, c = input().split()
    x = int(x) % k2
    y = int(y) % k2
    if c == 'W':
        x = (x + k) % k2

    b[x][y] += 1
    if x < k:
        b[x + k2][y] += 1
    if y < k:
        b[x][y + k2] += 1
    if x < k and y < k:
        b[x + k2][y + k2] += 1

b_cs = [[0] * (k * 3 + 1) for _ in range(k * 3 + 1)]
for i in range(k * 3):
    for j in range(k * 3):
        b_cs[i + 1][j +
                    1] = b_cs[i + 1][j] + b_cs[i][j + 1] - b_cs[i][j] + b[i][j]


def func_b(x, y):
    return b_cs[x + k][y + k] - b_cs[x + k][y] - b_cs[x][y + k] + b_cs[x][y]


# print('black')
# print(*b, sep='\n')
# print(*b_cs, sep='\n')

ans = 0
for i in range(k):
    for j in range(k):
        cand = 0
        cand += func_b(i, j)
        cand += func_b(i + k, j + k)
        # print(i, j, cand)
        ans = max(ans, cand)

        cand = 0
        cand += func_b(i + k, j)
        cand += func_b(i, j + k)
        # print(i, j, cand)
        ans = max(ans, cand)

print(ans)