Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, M, Q = map(int, input().split())

A = []
B = []
C = []
D = []

for i in range(Q):
    a, b, c, d = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)
    D.append(d)


def dfs(nums):

    if len(nums) == N + 1:
        score = 0
        for j in range(Q):
            if nums[B[j]] - nums[A[j]] == C[j]:
                score += D[j]
        return score

    max_score = 0
    for i in range(nums[-1], M+1):
        new_nums = nums + [i]
        max_score = max(max_score, dfs(new_nums))

    return max_score

nums[1]
res = dfs(nums)
print(res)

Fixed submission:
N, M, Q = map(int, input().split())
 
A = []
B = []
C = []
D = []
 
for i in range(Q):
    a, b, c, d = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)
    D.append(d)
 
 
def dfs(nums):
 
    if len(nums) == N + 1:
        score = 0
        for j in range(Q):
            if nums[B[j]] - nums[A[j]] == C[j]:
                score += D[j]
        return score
 
    max_score = 0
    for i in range(nums[-1], M+1):
        new_nums = nums + [i]
        max_score = max(max_score, dfs(new_nums))
 
    return max_score
 
nums = [1]
res = dfs(nums)
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, N = map(int, input().split())

max_r = 0
for i in range(B):
  if i <= N:
    max_r = max(max_r, i/B)

res = int(max_r * A)
print(res)

Fixed submission:
A, B, N = map(int, input().split())

max_d = min(B - 1, N)
max_r = max_d / B

res = int(max_r * A)
print(res)
Buggy python submission (verdict: Runtime Error):
S = input()
leng = len(S)

count = [0] * 2019
count[0] = 1

for i in range(leng):
    remainder = int(S[i:]) % 2019
    count[remainder] += 1

res = 0
for cnt in count:
    res += cnt * (cnt - 1) // 2
    
print(res)


Fixed submission:
S, W = map(int, input().split())

if W >= S:
  print('unsafe')
else:
  print('safe')
Buggy python submission (verdict: Runtime Error):
N = input()

for char in N:
  if char = '7':
    print('Yes')

print('No')

Fixed submission:
N = input()

flag = False

for char in N:
  if char == '7':
    print('Yes')
    flag = True
    break

if flag == False:   
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd

def gcd3(a, b, c):
  return gcd(gcd(a, b), c)

K = int(input())

res = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      res += gcd3(a, b, c)
      
print(res)

Fixed submission:
from math import gcd

def gcd3(a, b, c):
  return gcd(gcd(a, b), c)

K = int(input())

res = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      res += gcd3(a, b, c)
      
print(res)
Buggy python submission (verdict: Runtime Error):
N, X, Y = map(int, input().split())

counts = [0] * N
for i in range(1, N):
    for j in range(i+1, N+1):
        # i -> x 直接
        d1 = abs(j-i)
        # i -> X -> Y -> j
        d2 = abs(i-X) + abs(Y-j) + 1

        d = min(d1, d2, d3)
        counts[d] += 1


for i in range(1, N):
    print(counts[i])

Fixed submission:
N, X, Y = map(int, input().split())


counts = [0] * N
for i in range(1, N):
    for j in range(i+1, N+1):
        # i -> x 直接
        d1 = abs(j-i)
        # i -> X -> Y -> j
        d2 = abs(i-X) + abs(Y-j) + 1

        d = min(d1, d2)
        counts[d] += 1


for i in range(1, N):
    print(counts[i])
Buggy python submission (verdict: Runtime Error):
import sys

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

S = []
C = []
for m in range(M):
  s, c = map(int, input().split())
  S.append(s)
  C.append(c)

for i in range(10**N):
  tes = str(i)
  flag = True
  if len(tes) < N:
    flag = False
  for s, c in zip(S, C):
    if tes[s-1] != str(c):
      flag = False
  if flag:
    print(tes)
    sys.exit()


print(-1)


Fixed submission:
import sys
N, M = map(int, input().split())

A = [-1] * N

for i in range(M):
  s, c = map(int, input().split())
  if A[s-1] != c and A[s-1] != -1:
    print(-1)
    sys.exit()
  else:
    A[s-1] = c
  
if N >= 2 and A[0] == 0:
  print(-1)
  sys.exit()

res = 0

for i in range(N):
  if A[i] == -1:
    if i == 0 and N >= 2:
      A[i] = 1
    else:
      A[i] = 0
  res += A[i] * 10 ** (N-i-1)

print(res)

Buggy python submission (verdict: Runtime Error):
import sys

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

S = []
C = []
for m in range(M):
  s, c = map(int, input().split())
  S.append(s)
  C.append(c)

for i in range(10**(N-1)-1, 10**N):
  tes = str(i)
  flag = True
  for s, c in zip(S, C):
    if tes[s-1] != str(c):
      flag = False
  if flag:
    print(tes)
    sys.exit()

print(-1)

Fixed submission:
import sys
N, M = map(int, input().split())

A = [-1] * N

for i in range(M):
  s, c = map(int, input().split())
  if A[s-1] != c and A[s-1] != -1:
    print(-1)
    sys.exit()
  else:
    A[s-1] = c
  
if N >= 2 and A[0] == 0:
  print(-1)
  sys.exit()

res = 0

for i in range(N):
  if A[i] == -1:
    if i == 0 and N >= 2:
      A[i] = 1
    else:
      A[i] = 0
  res += A[i] * 10 ** (N-i-1)

print(res)
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
MOD = 10**9 + 7

res = 0

def comb(n, k):
    """nCkを計算する関数"""
    fact = [1] * (n+1)
    for i in range(1, n+1):
        fact[i] = fact[i-1] * i % MOD

    # k!と(n-k)!の逆元はそれぞれ、(k!) ** (MOD-2), (n-k)!**(MOD-2)
    res = fact[n] * pow(fact[k], -1, MOD) * pow(fact[n-k], -1, MOD)
    return res % MOD


for i in range(n):
    if i != a and i != b:
        res += comb(n, i)

print(res)

Fixed submission:
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

MOD = 10**9 + 7
# 二項展開より 2**n - 1 - nCa - nCb を MOD 10**9 + 7 で求めればよい


def combination(n, a):
    # nCk = n! / k! (n-k)! のうち、 n!/(n-k)! を計算する
    res = 1
    div = 1
    for i in range(a):
        res *= n-i
        res %= MOD
        div *= a - i
        div %= MOD

    # print(f'n {n}, a {a}, res {res}, div {div}')
    res = (res * pow(div, MOD-2, MOD)) % MOD
    return res


count = (pow(2, n, MOD) - 1 - combination(n, a) - combination(n, b)) % MOD
print(count)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
P = list(map(int, input().split()))

S = []
sum_ = 0
for i, p in enumerate(P):
  sum_ += p
  S.append(sum_)


max_sum = 0
for i in range(N-K+1):
  max_sum = max(max_sum, S[i+K] - S[i])

res = (max_sum + K) / 2

print(res)

Fixed submission:
N, K = map(int, input().split())
P = tuple(map(int, input().split()))
P2 = P[K:]

max_sum = 0
sum_ = sum(P[:K])

for p, q in zip(P, P2):
  max_sum = max(max_sum, sum_)
  sum_ += q - p
  
max_sum = max(max_sum, sum_)
          
res = (max_sum + K)/ 2
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
P = tuple(map(int, input().split()))

max_sum = 0
for i in range(N-K+1):
  max_sum = max(max_sum, sum(P[i:i+K]))
          
res = (max_sum + K)/ 2
print(res)

Fixed submission:
N, K = map(int, input().split())
P = tuple(map(int, input().split()))
P2 = P[K:]

max_sum = 0
sum_ = sum(P[:K])

for p, q in zip(P, P2):
  max_sum = max(max_sum, sum_)
  sum_ += q - p
  
max_sum = max(max_sum, sum_)
          
res = (max_sum + K)/ 2
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
P = tuple(map(int, input().split()))

max_sum = 0
for i in range(N-K+1):
  max_sum = max(max_sum, sum(P[i:i+K]))
          
res = (max_sum + K)/ 2
print(res)

Fixed submission:
N, K = map(int, input().split())
P = tuple(map(int, input().split()))
P2 = P[K:]

max_sum = 0
sum_ = sum(P[:K])

for p, q in zip(P, P2):
  max_sum = max(max_sum, sum_)
  sum_ += q - p
  
max_sum = max(max_sum, sum_)
          
res = (max_sum + K)/ 2
print(res)
Buggy python submission (verdict: Runtime Error):
from collections import deque

H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

dir = [(-1, 0), (1, 0), (0, -1), (0, 1)]

dist = [[-1] * W for _ in range(H)]

def BFS(y, x):
  """(y, x)からはじめて、道のマスをBFSで最短距離を探す"""
  que = deque()
  que.append((y, x))
  dist[y][x] = 0
  max_dist = 0
  while que:
    sy, sx = que.popleft()  # popleft?
    for dy, dx in dir:
      ny = sy + dy
      nx = sx + dx
      if 0 <= ny < H and 0 <= nx < W and S[ny][nx] != "#" and dist[ny][nx] == -1:
        que.append((ny, nx))
        dist[ny][nx] = dist[sy][sx] + 1
        max_dist = max(max_dist, dist[ny][nx])
  
  return max_dist

max_dist = 0
for sy in range(H):
  for sx in range(W):
    if S[sy][sx] != "#":
      dist = [[-1] * W for _ in range(H)]
      max_dist = max(max_dist, BFS(sy, sx))
      
print(max_dist)

Fixed submission:
C = input()
D = chr(ord(C)+1)

print(D)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7

N = int(input())
A = list(map(int, input().split()))
B = [bin(a) for a in A]

maxA = max(A)
mask = 1

count = 0
i = 0
while maxA >> i:
    zeros = sum([1 for a in A if (mask * 2**i) & a == 0]) % MOD
    ones = (len(A) - zeros) % MOD
    count += zeros * ones * ((2**i) % MOD)
    count %= MOD
    i += 1

print(count)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7

N = int(input())
A = list(map(int, input().split()))
B = [bin(a) for a in A]

maxA = max(A)
mask = 1

count = 0
i = 0
while maxA >> i:
    zeros = sum([1 for a in A if (mask * 2**i) & a == 0]) % MOD
    ones = (len(A) - zeros) % MOD
    count += zeros * ones * ((2**i) % MOD)
    count %= MOD
    i += 1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7

N = int(input())
A = list(map(int, input().split()))
B = [bin(a) for a in A]

maxA = max(A)
mask = 1

count = 0
i = 0
while maxA >> i:  # ここが違う
    zeros = sum([1 for a in A if (mask * 2**i) & a == 0])
    ones = len(A) - zeros
    count += zeros * ones * 2**i
    count %= MOD
    i += 1

print(count)


Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7

N = int(input())
A = list(map(int, input().split()))
B = [bin(a) for a in A]

maxA = max(A)
mask = 1

count = 0
i = 0
while maxA >> i:
    zeros = sum([1 for a in A if (mask * 2**i) & a == 0]) % MOD
    ones = (len(A) - zeros) % MOD
    count += zeros * ones * ((2**i) % MOD)
    count %= MOD
    i += 1

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

X, Y = map(int, input().split())
mod = 10 ** 9 + 7

if (2 * X - Y) % 3 != 0:
    # 整数解がない場合
    print(0)
    sys.exit()


m = (2 * X - Y) // 3
n = (2 * Y - X) // 3

u = m + n
fact = [1] * (u+1)

for i in range(1, u+1):
    fact[i] = (fact[i-1] * i) % mod

fact_inv1 = pow(fact[n], mod-2, mod)
fact_inv2 = pow(fact[m], mod-2, mod)

res = (((fact[u] * fact_inv1) % mod) * fact_inv2) % mod

print(res)

Fixed submission:
import sys

X, Y = map(int, input().split())
mod = 10 ** 9 + 7

# if (2 * X - Y) % 3 != 0 or (2 * Y - X) % 3 != 0:
if (X + Y) % 3 != 0:
    # 整数解がない場合
    print(0)
    sys.exit()


m = (2 * X - Y) // 3
n = (2 * Y - X) // 3

if m < 0 or n < 0:
    print(0)
    sys.exit()

u = m + n
fact = [1] * (u+1)

for i in range(1, u+1):
    fact[i] = (fact[i-1] * i) % mod

fact_inv1 = pow(fact[n], mod-2, mod)
fact_inv2 = pow(fact[m], mod-2, mod)

res = (((fact[u] * fact_inv1) % mod) * fact_inv2) % mod

print(res)
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())

count = 0
avail = 1

while avail < B:
  avail -= 1
  count += 1
  avail = +A

print(count)


Fixed submission:
S = input()
T = input()

count = 0
for s, t in zip(S, T):
  if s == t:
    count += 1
    
print(count)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
h = [int(x) for x in input().split()]

INF = float('inf')
dp = [INF for _ in range(N+10)]

# initial state
dp[0] = 0

for i in range(N):
    for j in range(1, min(K+1, len(h)-i)):
        dp[i+j] = min(dp[i] + abs(h[j+i] - h[i]), dp[i+j])

print(dp[N-1])

Fixed submission:
N = int(input())
h = [int(n) for n in input().split()]


cost = [0] * (N+1)

for i in range(N):
    if i == 0:
        cost[i] = 0
    elif i == 1:
        cost[i] = abs(h[i] - h[i-1])

    if i >= 2:
        cost[i] = min(cost[i-1] + abs(h[i] - h[i-1]), cost[i-2] + abs(h[i] - h[i-2]))

print(cost[N-1])

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
h = [int(x) for x in input().split()]

INF = float('inf')
dp = [INF for _ in range(N+K+10)]

# initial state
dp[0] = 0

for i in range(N):
    for j in range(1, min(K+1, len(h)-i)):
        dp[i+j] = min(dp[i] + abs(h[j+i] - h[i]), dp[i+j])

print(dp[N-1])

Fixed submission:
N = int(input())
h = [int(n) for n in input().split()]


cost = [0] * (N+1)

for i in range(N):
    if i == 0:
        cost[i] = 0
    elif i == 1:
        cost[i] = abs(h[i] - h[i-1])

    if i >= 2:
        cost[i] = min(cost[i-1] + abs(h[i] - h[i-1]), cost[i-2] + abs(h[i] - h[i-2]))

print(cost[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = [int(x) for x in input().split()]

INF = float('inf')
dp = [INF for _ in range(N+K+10)]

# initial state
dp[0] = 0

for i in range(N):
  lim = min(len(h)-i, K+1)
  for j in range(1, lim):
        dp[i+j] = min(dp[i] + abs(h[j+i] - h[i]), dp[i+j])

print(dp[N-1])

Fixed submission:
N, K = map(int, input().split())
h = [int(x) for x in input().split()]

INF = float('inf')
dp = [INF for _ in range(N+K+10)]

# initial state
dp[0] = 0

for i in range(N):
    for j in range(1, min(K+1, len(h)-i)):
        dp[i+j] = min(dp[i] + abs(h[j+i] - h[i]), dp[i+j])

print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = [int(x) for x in input().split()]

INF = float('inf')
dp = [INF for _ in range(N+10)]

# initial state
dp[0] = 0

for i in range(N):
    for j in range(1, min(K+1, len(h)-i)):
        dp[i+j] = min(dp[i] + abs(h[j+i] - h[i]), dp[i+j])

print(dp[N-1])

Fixed submission:
N, K = map(int, input().split())
h = [int(x) for x in input().split()]

INF = float('inf')
dp = [INF for _ in range(N+K+10)]

# initial state
dp[0] = 0

for i in range(N):
    for j in range(1, min(K+1, len(h)-i)):
        dp[i+j] = min(dp[i] + abs(h[j+i] - h[i]), dp[i+j])

print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = [int(x) for x in input().split()]

INF = float('inf')
dp = [INF for _ in range(N+K+10)]

# initial state
dp[0] = 0

for i in range(N):
    for j in range(1, min(K+1, len(h)-i)):
        dp[i+j] = min(dp[i] + abs(h[j+i] - h[i]), dp[i+j])

print(dp[N-1])

Fixed submission:
N, K = map(int, input().split())
h = [int(x) for x in input().split()]

INF = float('inf')
dp = [INF for _ in range(N+K+10)]

# initial state
dp[0] = 0

for i in range(N):
    for j in range(1, min(K+1, len(h)-i)):
        dp[i+j] = min(dp[i] + abs(h[j+i] - h[i]), dp[i+j])

print(dp[N-1])

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
h = [int(x) for x in input().split()]

assert len(h) == N, print(f'length of steps {len(h)} doesn\'t equal to {K}')

# list dp retains information for the minimum costs
# if dp[i] = n, it means n is the minimum cost to get to i step
# if dp[i] = INF, it means the minimum cost has not been evaluated yet
INF = float('inf')
dp = [INF for _ in range(N+K+10)]

# initial state
dp[0] = 0

for i in range(N):
    for j in range(1, min(K+1, len(h)-i)):
        dp[i+j] = min(dp[i] + abs(h[j+i] - h[i]), dp[i+j])
        
print(dp[N-1])

Fixed submission:
N, K = map(int, input().split())
h = [int(x) for x in input().split()]

INF = float('inf')
dp = [INF for _ in range(N+K+10)]

# initial state
dp[0] = 0

for i in range(N):
    for j in range(1, min(K+1, len(h)-i)):
        dp[i+j] = min(dp[i] + abs(h[j+i] - h[i]), dp[i+j])

print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
from math import sqrt


def is_prime(n):
    if n < 2:
        return False
    i = 2
    while i <= sqrt(n):
        if n % i == 0:
            return False
        else:
            i += 1
    return True


Q = int(input())

for i in range(Q):
    l, r = map(int, input().split())
    count = 0
    for j in range(l, r+1, 2):
        count += is_prime(j) * is_prime((j+1)//2)
    print(count)

Fixed submission:
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

Q = int(input())

L = []
R = []
for i in range(Q):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)


def primes(max_r):
    is_prime = [True] * (max_r + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(max_r**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, max_r + 1, i):
            is_prime[j] = False
    return [i for i in range(max_r + 1) if is_prime[i] and is_prime[(i+1)//2]]


max_r = max(R)
ps = primes(max_r)

S = [0]
for i in range(1, max_r+1):
    if i in ps:
        S.append(S[i-1]+1)
    else:
        S.append(S[i-1])


for i in range(Q):
    print(S[R[i]] - S[L[i]-1])
Buggy python submission (verdict: Runtime Error):
N, A, B = map(int, input())

if N * A <= B:
  print(N*A)
else:
  print(B)

Fixed submission:
N, A, B = map(int, input().split())

if N * A <= B:
  print(N*A)
else:
  print(B)

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

def digitsum(a):
  x = 0
  while a > 0:
    x += a % 10
    a /= 10
  return x

if N % digitsum(N) == 0:
  print('Yes')
else:
  print('No')


Fixed submission:
N, A, B = map(int, input().split())

if N * A <= B:
  print(N*A)
else:
  print(B)
Buggy python submission (verdict: Runtime Error):
input(N)

def digitsum(a):
  x = 0
  while a > 0:
    x += a % 10
    a /= 10
  
  return x

if N % digitsum(N) == 0:
  print('Yes')
else:
  print('No')

Fixed submission:
N = int(input())

def digitsum(a):
  sum_ = 0
  while a > 0:
    sum_ += int(a)%10
    a /= 10
  return sum_

if N % digitsum(N) == 0:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left, bisect_right

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

A.sort()
C.sort()

count = 0
for b in B:
    upper = bisect_left(A, b)  # returns number of elements which satisfy a < b
    lower = bisect_right(C, b)
    count += upper * (len(C) - lower)

print(count)

Fixed submission:
import sys

C1 = input()
C2 = input()[::-1]


for i in range(len(C1)):
  if C1 != C2:
    print("NO")
    sys.exit()

print("YES")
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
C.sort()

count = 0
for b in B:
    upper = bisect_left(A, b)  # returns number of elements which satisfy a < b
    lower = bisect_right(C, b)
    count += upper * (len(C) - lower)

print(count)

Fixed submission:
from bisect import bisect_left, bisect_right

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

A.sort()
C.sort()

count = 0
for b in B:
    upper = bisect_left(A, b)  # returns number of elements which satisfy a < b
    lower = bisect_right(C, b)
    count += upper * (len(C) - lower)

print(count)
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())

S = [list(input()) for _ in range(H)]
dydx = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]

def check(h, w):
  count = 0
  for dy, dx in dydx:
    if 0 <= h + dy < H and 0 <= w + dx < W and S[h+dy][w+dx] == '#':
      count += 1
  return count
      
  

for h in range(H):
  for w in range(W):
    if S[h][w] == '.':
      S[h][w] = check(h, w)
  print("".join(S[h])
      
      

Fixed submission:
H, W = map(int, input().split())

S = [list(input()) for _ in range(H)]
dydx = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]


def check(h, w):
  count = 0
  for dy, dx in dydx:
    if 0 <= h + dy < H and 0 <= w + dx < W and S[h+dy][w+dx] == '#':
      count += 1
  return count

for h in range(H):
  for w in range(W):
    if S[h][w] == '.':
      S[h][w] = str(check(h, w))
  res = "".join(S[h])
  print(res)
Buggy python submission (verdict: Runtime Error):
S = dict()

S['a'] = input()[::-1]
S['b'] = input()[::-1]
S['c'] = input()[::-1]

player = 'a'

while S[player]:
  player = S[player].pop()

  
res = player.upper()
print(res)
  

Fixed submission:
A = input()
B = input()
C = input()

x = A[0]

def turn(A, B, C, x):
  if x == 'a':
    if len(A) == 0:
      print('A')
      return
    else:
      y = A[0]
      A = A[1:]
      
  if x == 'b':
    if len(B) == 0:
      print('B')
      return
    else:
      y = B[0]
      B = B[1:]
  
  if x == 'c':
    if len(C) == 0:
      print('C')
      return
    else:
      y = C[0]
      C = C[1:]
  
  return turn(A, B, C, y)

turn(A, B, C, x)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
DP = [[0 for _ in range(N)] for _ in range(K+1)]
for i in range(N):
    DP[0][i] = A[i]

for i in range(1, K+1,1):
    for j in range(N):
        pl, mi = min(j + DP[i-1][j], N-1), max(j - DP[i-1][j], 0)
        for k in range(mi, pl+1, 1):
            DP[i][k] += 1

print(" ".join(map(str, DP[K])))

Fixed submission:
import sys
N, K = map(int, input().split())
if K > 42:
    print(" ".join(map(str, [N] * N)))
    sys.exit()
A = [int(i) for i in input().split()]
DP = [[0 for _ in range(N)] for _ in range(K+1)]
for i in range(N):
    DP[0][i] = A[i]

for i in range(1, K+1,1):
    B = [0] * N
    for j in range(N):
        pl, mi = min(j + DP[i-1][j], N-1), max(j - DP[i-1][j], 0)
        B[mi] += 1
        if pl + 1 < N:
            B[pl + 1] -= 1
    for j in range(1, N):
        B[j] += B[j-1]
    DP[i] = B
print(" ".join(map(str, DP[K])))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
# N = (2 ** 16) * (3 ** 16)
ans = 0
t = []
primeList = [2]
maxNumber = 2 * 10 ** 5
for x in range(3, maxNumber):
    for y in primeList:
        if x % y == 0:
            break
    else:
        primeList.append(x)  # 割り切れるものがなければリストに追加

for i in primeList:
    for x in range(1, 40):
        y = i ** x
        if N // y == N / y:
            ans += 1
            N = N // y
        else:
            break

if N > 10 ** 5:
    ans += 1
print(ans)


Fixed submission:
N = int(input())
ans = 0
for i in range(2, 10 ** 6 + 1):
    for x in range(1, 40):
        y = i ** x
        if N // y == N / y:
            ans += 1
            N = N // y
        else:
            while N // i == N / i:
                N = N // i
            break


if N > 10 ** 6:
    ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
T = input()
ans = ""
for i in T:
    if i == "?" or i == "D":
        ans += "D"
    else:
        ans += i
print(ans)

Fixed submission:
T = input()
T = T.replace("?", "D")
print(T)