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

Fixed submission:
from collections import deque

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

tree = dict(zip([i for i in range(1, N+1)], [[] for _ in range(N)]))
for i in range(N-1):
  a, b = map(int, input().split())
  tree[a].append(b)
  tree[b].append(a)

counter = [0] * (N+1)
for i in range(Q):
  p, x = map(int, input().split())
  counter[p] += x

d = deque([[1, 0]])
while d:
  node, parent = d.popleft()
  counter[node] += counter[parent]
  children = tree[node]
  for child in children:
    if child == parent:
      continue
      
    d.append([child, node])
    
  
print(' '.join(map(str, counter[1:])))

Buggy submission (verdict: Runtime Error):
import numpy as np

N, Q = list(map(int, input().split()))
tree = np.eye(N)

for i in range(N-1):
  a, b = list(map(int, input().split()))
  ids = tree[:, a-1] > 0
  tree[ids, b-1] = 1
  
r = np.zeros(N)
for i in range(Q):
  p, x = list(map(int, input().split()))
  r += (tree[p-1] > 0)*x
  
r = np.array(r, dtype=int)
print(' '.join(map(str, r)))

Buggy submission (verdict: Runtime Error):
import numpy as np

N, Q = list(map(int, input().split()))
tree = np.eye(N)

for i in range(N-1):
  a, b = list(map(int, input().split()))
  ids = tree[:, a-1] > 0
  tree[ids, b-1] = 1
  
r = np.zeros(N)
for i in range(Q):
  p, x = list(map(int, input().split()))
  r += (tree[p-1] > 0)*x
  
out = str(int(r[0]))
for i in range(1, N):
  out += ' {0}'.format(int(r[i]))

print(out)

Buggy submission (verdict: Runtime Error):
def f(p, x, r, tree):
  r[p-1] += x
  children = tree[p]
  for child in children:
    r = f(child, x, r, tree)
  
  return r

N, Q = list(map(int, input().split()))
keys = [i for i in range(1, N+1)]
values = [[] for i in range(N)]
tree = dict(zip(keys, values))

for i in range(N-1):
  a, b = list(map(int, input().split()))
  if a in tree.keys():
    tree[a] += [b]
  
  else:
    tree[a] = [b]

r = [0 for i in range(N)]    
for i in range(Q):
  p, x = list(map(int, input().split()))
  r = f(p, x, r, tree)

out = str(r[0])
for i in range(1, N):
  out += ' {0}'.format(r[i])

print(out)
Problem p02947 (python)

Fixed submission:
def number(x):
  return int((1 + (1 + 8*x)**0.5) / 2)


N = int(input())
d = {}
for i in range(N):
  s = ''.join(sorted(input()))
  if s in d.keys():
    d[s] += number(d[s])
  else:
    d[s] = 0


print(sum(d.values()))

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())
S = []
for i in range(N):
  S.append(list(input()))

S = np.array(S)

s = list('abcdefghijklmnopqrstuvwxyz')

T = np.zeros([N, 26])

for i, a in enumerate(s):
  T[:, i] = np.sum(S == a, axis=1)

T3 = np.atleast_3d(T)

print(int((np.sum(np.prod(T3 == T3.T, axis=1)) - N) / 2))

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())
S = []
for i in range(N):
  S.append(list(input()))

S = np.array(S)

s = list('abcdefghijklmnopqrstuvwxyz')

T = np.zeros([N, 26])

for i, a in enumerate(s):
  T[:, i] = np.sum(S == a, axis=1)

T3 = np.atleast_3d(T)
r = np.prod(T3 == T3.T, axis=1)

print((np.sum(r) - len(r)) // 2)
Problem p02969 (python)

Fixed submission:
a = int(input())
print(3*a*a)

Buggy submission (verdict: Runtime Error):
a = int(input())
print(3＊a＊a)
Problem p03000 (python)

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

D = [0]
for l in L:
  d = D[-1] + l
  if d <= X:
    D.append(d)
  else:
    break

print(len(D))

Buggy submission (verdict: Runtime Error):
N, X = map(int, input().split())
L = list(map(int, input().split()))

D = [0]
for l in L:
  d = D[-1] + L
  if d <= X:
    D.append(d)
  else:
    break

print(len(D))
Problem p03008 (python)

Fixed submission:
def solve(n, a, b):
  ab = [(ai, bi) for ai, bi in zip(a, b) if ai < bi]
  if len(ab) == 0:
    return n
  elif len(ab) == 1:
    a0, b0 = ab[0]
    return (n//a0)*b0 + n%a0
  elif len(ab) == 2:
    (a0, b0), (a1, b1) = ab
    if b0/a0 < b1/a1:
      a0, b0, a1, b1 = a1, b1, a0, b0
    return max(((n-a1*i)//a0)*b0 + (n-a1*i)%a0 + i*b1 for i in range(a0))
  else:
    dp = [j for j in range(n+1)]
    for ai, bi in ab:
      for j in range(ai, n+1):
        dp[j] = max(dp[j], dp[j-ai]+bi)
    return dp[-1]

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

N = solve(N, A, B)
N = solve(N, B, A)
print(N)

Buggy submission (verdict: Runtime Error):
import numpy as np

def solve(n, a, b):
  ab = [(ai, bi) for ai, bi in zip(a, b) if ai < bi]
  dp = [[j for j in range(n+1)] for i in range(len(ab)+1)]
  if len(ab) == 0:
    return n
  if len(ab) == 1:
    a0, b0 = ab[0]
    return (n//a0)*b0 + n%a0
  if len(ab) == 2:
    a0, b0 = ab[0]; a1, b1 = ab[1]
    if a0 < a1: a0, b0, a1, b1 = a1, b1, a0, b0
    t = n // a0
    return max(((n-a0*i)//a1)*b1 + (n-a0*i)%a1 + i*bi for i in range(t+1))
  else:
    dp = np.arange(n+1)
    for ai, bi in ab:
      dp[ai:] = np.maximum(dp[ai:], dp[:-ai]+bi)
    return dp[-1]

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

N = solve(N, A, B)
N = solve(N, B, A)
print(N)
Problem p03068 (python)

Fixed submission:
N = int(input())
S = input()
K = int(input())
t = S[K-1]
ans = ''
for s in S:
  if s == t:
    ans += s
  else:
    ans += '*'

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
K = input()
t = S[K-1]
ans = ''
for s in S:
  if s == t:
    ans += s
  else:
    ans += '*'

print(ans)
Problem p03128 (python)

Fixed submission:
nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
N, M = map(int, input().split())
A = list(map(int, input().split()))

# 使うマッチ棒の本数が等しい場合は大きい数だけ考えれば良い
A.sort(reverse=True)
s = set()
candidates = [] # [a, nums[a]]
for a in A:
  if nums[a] in s:
    continue
  s.add(nums[a])
  candidates.append([a, nums[a]])


dp1 = [0] * (N+1)
dp2 = [-1] * (N+1)
d = {}
for a, n in candidates:
  if n <= N:
    dp1[n] = 1
    dp2[n] = 0
    d[n] = a

for i in range(N+1):
  for a, n in candidates:
    if i >= n and dp1[i-n]:
      if dp1[i] < dp1[i-n] + 1:
        dp1[i] = dp1[i-n] + 1
        dp2[i] = i-n

ans = []
idx = N
while idx:
  next_idx = dp2[idx]
  ans.append(d[idx - next_idx])
  idx = next_idx

ans.sort(reverse=True)
print(''.join(list(map(str, ans))))

Buggy submission (verdict: Runtime Error):
nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
N, M = map(int, input().split())
A = list(map(int, input().split()))

# 使うマッチ棒の本数が等しい場合は大きい数だけ考えれば良い
A.sort(reverse=True)
s = set()
candidates = [] # [a, nums[a]]
for a in A:
  if nums[a] in s:
    continue
  s.add(nums[a])
  candidates.append([a, nums[a]])


dp = [-1] * (N+1)
dp[0] = 0
for i in range(N+1):
  for a, n in candidates:
    if i >= n and dp[i-n]>=0:
      dp[i] = max(dp[i], dp[i-n]+1)

ans = ''
idx = N
digit = dp[N]
while digit:
  for a, n in candidates:
    if dp[idx-n] == dp[idx]-1:
      ans += str(a)
      digit -= 1
      idx -= n
      break

print(int(ans))

Buggy submission (verdict: Runtime Error):
nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
N, M = map(int, input().split())
A = list(map(int, input().split()))

# 使うマッチ棒の本数が等しい場合は大きい数だけ考えれば良い
A.sort(reverse=True)
s = set()
candidates = [] # [a, nums[a]]
for a in A:
  if nums[a] in s:
    continue
  s.add(nums[a])
  candidates.append([a, nums[a]])


dp1 = [0] * (N+1)
dp2 = [-1] * (N+1)
d = {}
for a, n in candidates:
  dp1[n] = 1
  dp2[n] = 0
  d[n] = a

for i in range(N+1):
  for a, n in candidates:
    if i >= n and dp1[i-n]:
      if dp1[i] < dp1[i-n] + 1:
        dp1[i] = dp1[i-n] + 1
        dp2[i] = i-n

ans = []
idx = N
while idx:
  next_idx = dp2[idx]
  ans.append(d[idx - next_idx])
  idx = next_idx

ans.sort(reverse=True)
print(''.join(list(map(str, ans))))

Buggy submission (verdict: Runtime Error):
nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
N, M = map(int, input().split())
A = list(map(int, input().split()))

# 使うマッチ棒の本数が等しい場合は大きい数だけ考えれば良い
A.sort(reverse=True)
s = set()
candidates = [] # [a, nums[a]]
for a in A:
  if nums[a] in s:
    continue
  s.add(nums[a])
  candidates.append([a, nums[a]])

# dp[i] : ちょうどi本のマッチ棒で作ることができる最大の整数
dp = [0] * (N+1)
for a, n in candidates:
  dp[n] = a

for i in range(N+1):
  for a, n in candidates:
    if i >= n and dp[i-n]:
      temp = list(str(dp[i-n])) + [str(a)]
      temp.sort(reverse=True)
      temp = int(''.join(temp))
      dp[i] = max(dp[i], temp)

print(dp[-1])
Problem p03148 (python)

Fixed submission:
import heapq

N, K = map(int, input().split())
dt = [list(map(int, input().split()))[::-1] for i in range(N)]
dt.sort(reverse=True)

ans = 0
t_set = set()
candidates = []
for d, t in dt[:K]:
  if t in t_set:
    heapq.heappush(candidates, [d, t])
    ans += d
  else:
    t_set.add(t)
    ans += d

x = len(t_set)
ans += x**2

if len(candidates) == 0:
  print(ans)
  quit()

ans = [ans]
for d, t in dt[K:]:
  if t in t_set:
    continue
  cand_d, cand_t = heapq.heappop(candidates)
  _ans = ans[-1] - cand_d + d + (2*x+1)
  x += 1
  ans.append(_ans)
  t_set.add(t)
  if len(candidates) == 0:
    break

print(max(ans))

Buggy submission (verdict: Runtime Error):
import heapq

N, K = map(int, input().split())
dt = [list(map(int, input().split()))[::-1] for i in range(N)]
dt.sort(reverse=True)

ans = 0
t_set = set()
candidates = []
for d, t in dt[:K]:
  if t in t_set:
    heapq.heappush(candidates, [d, t])
    ans += d
  else:
    t_set.add(t)
    ans += d

x = len(t_set)
ans += x**2

ans = [ans]
for d, t in dt[K:]:
  if t in t_set:
    continue
  cand_d, cand_t = heapq.heappop(candidates)
  _ans = ans[-1] - cand_d + d + (2*x+1)
  x += 1
  ans.append(_ans)
  if len(candidates) == 0:
    break

print(max(ans))
Problem p03215 (python)

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

S = []
for l in range(0, N):
  temp = 0
  for r in range(l, N):
    temp += A[r]
    S.append(temp)

max_s = max(S)
n = max_s.bit_length()
S_temp = [S, []]
s_idx = 0
for i in range(n-1, -1, -1):
  c = 0
  for s in S_temp[s_idx]:
    if (s >> i) & 1:
      S_temp[s_idx-1].append(s)
      c += 1
  if c == K:
    ans = S_temp[s_idx-1][0]
    for _s in S_temp[s_idx-1]:
      ans &= _s
    print(ans)
    quit()
  if c > K:
    S_temp[s_idx] = []
    s_idx = not s_idx
  else:
    S_temp[s_idx-1] = []

ans = S_temp[s_idx][0]
for _s in S_temp[s_idx][:K]:
  ans &= _s

print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

S = []
for l in range(0, N):
  temp = 0
  for r in range(l, N):
    temp += A[r]
    S.append(temp)

max_s = max(S)
n = max_s.bit_length()
S_temp = [S.copy(), []]
s_idx = 0
for i in range(n-1, -1, -1):
  c = 0
  for s in S_temp[s_idx]:
    if (s >> i) & 1:
      S_temp[s_idx-1].append(s)
      c += 1
  if c == K:
    ans = S_temp[s_idx-1][0]
    for _s in S_temp[s_idx-1]:
      ans &= _s
    print(ans)
    quit()
  if c > K:
    S_temp[s_idx] = []
    s_idx = not s_idx
  else:
    S_temp[s_idx-1] = []

ans = S_temp[s_idx][0]
for _s in S_temp[s_idx][:K]:
  ans &= _s

print(ans)
Problem p03239 (python)

Fixed submission:
N, T = map(int, input().split())
ans = float('inf')
cost = float('inf')

for i in range(N):
  c, t = map(int, input().split())
  if t <= T:
    ans = min(ans, c)

if ans < float('inf'):
  print(ans)
else:
  print('TLE')

Buggy submission (verdict: Runtime Error):
N, T = map(int, input().split())
ans = 'TLE'
cost = float('inf')

for i in range(N):
  c, t = map(int, input().split())
  if t <= T:
    ans = min(ans, c)

print(ans)
Problem p03282 (python)

Fixed submission:
S = input()
K = int(input())
if S[0] != '1':
  print(S[0])
  quit()

for i, s in enumerate(S, 1):
  if s != '1':
    print(s)
    quit()
  elif i >= K:
    print(s)
    quit()

Buggy submission (verdict: Runtime Error):
S = input()
if S[0] == '1':
  print(S[1])
else:
  print(S[0])
Problem p03316 (python)

Fixed submission:
N = input()
S = 0
for n in N:
  S += int(n)

if int(N) % S:
  print('No')
else:
  print('Yes')

Buggy submission (verdict: Runtime Error):
N = input()
S = 0
for n in N:
  S += int(n)

if S % N:
  print('No')
else:
  print('Yes')
Problem p03360 (python)

Fixed submission:
ABC = sorted(map(int, input().split()))
K = int(input())
print(sum(ABC[:2] + ABC[-1:]*2**K))

Buggy submission (verdict: Runtime Error):
ABC = sorted(map(int, input().split()))
K = int(input().split())
print(sum(ABC[:2] + ABC[-1:]*2**K))
Problem p03370 (python)

Fixed submission:
N, X = map(int, input().split())
m = [int(input()) for i in range(N)]
X -= sum(m)
ans = N
ans += X // min(m)
print(ans)

Buggy submission (verdict: Runtime Error):
N, X = map(intm input().split())
m = [int(input()) for i in range(N)]
X -= sum(m)
ans = N
ans += X // min(m)
print(ans)
Problem p03401 (python)

Fixed submission:
N = int(input())
A = [0] + list(map(int, input().split()))
diff = []
for i in range(N):
  diff.append(abs(A[i]-A[i+1]))

diff.append(abs(A[-1]))

A += [0]
s = sum(diff)
for i in range(N):
  v = s - diff[i] - diff[i+1]
  v += abs(A[i] - A[i+2])
  print(v)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [0] + list(map(int, input().split()))
diff = []
for i in range(N):
  diff.append(abs(A[i]-A[i+1]))

diff.append(abs(A[-1]))a

A += [0]
s = sum(diff)
for i in range(N):
  v = s - diff[i] - diff[i+1]
  v += abs(A[i] - A[i+2])
  print(v)
Problem p03433 (python)

Fixed submission:
N = int(input()) % 500
if int(input()) >= N:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
N = int(input()) % 500
if A >= N:
  print('Yes')
else:
  print('No')
Problem p03487 (python)

Fixed submission:
from collections import Counter

N = int(input())
c = Counter(list(map(int, input().split())))
ans = 0
for k in c:
  ans += c[k] - k if k <= c[k] else c[k]

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
c = Counter(list(map(int, input())))
ans = 0
for k in c:
  ans += d[k] - k if k <= d[k] else d[k]

print(ans)
Problem p03502 (python)

Fixed submission:
N = input()
f = sum(map(int, list(N)))
if int(N) % f == 0:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
N = input()
f = sum(map(int, list(N)))
if N // f == 0:
  print('Yes')
else:
  print('No')
Problem p03504 (python)

Fixed submission:
N, C = map(int, input().split())
table = [[0]*(10**5 + 1) for i in range(C)]

st = [[] for i in range(C)]
for i in range(N):
  s, t, c = map(int, input().split())
  st[c-1].append([s, t])

st_new = [[] for i in range(C)]
for c in range(C):
  if st[c]:
    st[c].sort()
    st_new[c].append(st[c][0])
    n = len(st[c])
    for i in range(1, n):
      si, ti = st[c][i]
      sii, tii = st_new[c][-1]
      if si == tii:
        st_new[c][-1][1] = ti
      else:
        st_new[c].append([si, ti])

for c in range(C):
  for s, t in st_new[c]:
    table[c][s-1] += 1
    table[c][t] -= 1
  
for c in range(C):
  for i in range(1, 10**5+1):
    table[c][i] += table[c][i-1]

ans = 0
for i in range(10**5 + 1):
  num = 0
  for c in range(C):
    num += table[c][i]
  ans = max(ans, num)

print(ans)

Buggy submission (verdict: Runtime Error):
N, C = map(int, input().split())
table = [[0]*(10**5 + 1) for i in range(C)]

st = [[] for i in range(C)]
for i in range(N):
  s, t, c = map(int, input().split())
  st[c-1].append([s, t])

st_new = [[] for i in range(C)]
for c in range(C):
  if st[c]:
    st[c].sort()
    st_new[c].append(st[c][0])
    n = len(st[c])
    for i in range(1, n):
      si, ti = st[c][i]
      sii, tii = st_new[c][-1]
      if si == tii:
        st_new[c][i-1][1] = ti
      else:
        st_new[c].append([si, ti])

for c in range(C):
  for s, t in st_new[c]:
    table[c][s-1] += 1
    table[c][t] -= 1
  
for c in range(C):
  for i in range(1, 10**5+1):
    table[c][i] += table[c][i-1]

ans = 0
for i in range(10**5 + 1):
  num = 0
  for c in range(C):
    num += table[c][i]
  ans = max(ans, num)

print(ans)

Buggy submission (verdict: Runtime Error):
N, C = map(int, input().split())
table = [[0]*(10**5 + 1) for i in range(C)]

st = [[] for i in range(C)]
for i in range(N):
  s, t, c = map(int, input().split())
  st[c-1].append([s, t])

st_new = [[] for i in range(C)]
for c in range(C):
  if st[c]:
    st[c].sort()
    st_new[c].append(st[c][0])
    n = len(st[c])
    for i in range(1, n):
      si, ti = st[c][i]
      sii, tii = st_new[c][i-1]
      if si == tii:
        st_new[c][i-1][1] = ti
      else:
        st_new[c].append([si, ti])

for c in range(C):
  for s, t in st_new[c]:
    table[c][s-1] += 1
    table[c][t] -= 1
  
for c in range(C):
  for i in range(1, 10**5+1):
    table[c][i] += table[c][i-1]

ans = 0
for i in range(10**5 + 1):
  num = 0
  for c in range(C):
    num += table[c][i]
  ans = max(ans, num)

print(ans)
Problem p03578 (python)

Fixed submission:
from collections import defaultdict

N = int(input())
D = list(map(int, input().split()))
kind = defaultdict(int)
for d in D:
  kind[d] += 1

M = int(input())
T = list(map(int, input().split()))
for t in T:
  kind[t] -= 1
  if kind[t] < 0:
    print('NO')
    quit()

print('YES')

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

N = int(input())
D = list(map(int, input().split()))
kind = defaultdict(int)
for d in D:
  kind[d] += 1

M = int(input())
T = list(map(int, input().split()))
for t in T:
  d[t] -= 1
  if d[t] < 0:
    print('NO')
    quit()

print('YES')
Problem p03606 (python)

Fixed submission:
N = int(input())
ans = 0
for i in range(N):
  l, r = map(int, input().split())
  ans += (r - l + 1)

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input().split())
ans = 0
for i in range(N):
  l, r = map(int, input().split())
  ans += (r - l + 1)

print(ans)
Problem p03761 (python)

Fixed submission:
n = int(input())
alpha = list('abcdefghijklmnopqrstuvwxyz')
num_s = dict(zip(alpha, [50]*len(alpha)))

for i in range(n):
  S = input()
  d = dict(zip(alpha, [0]*len(alpha)))
  for s in S:
    d[s] += 1
  for s in d:
    num_s[s] = min(num_s[s], d[s])

ans = ''
for s in num_s:
  ans += s*num_s[s]

print(''.join(sorted(ans)))

Buggy submission (verdict: Runtime Error):
n = int(input())
alpha = list('abcdefghijklmnopqrstuvwxyz')
num_s = dict(zip(alpha, [50]*len(alpha)))

for i in range(n):
  S = input()
  d = dict(zip(alpha, [0]*len(alpha)))
  for s in S:
    d[s] += 1
  for s in d:
    num_s[s] = min(num_s[s], d[s])

ans = ''
for s in num_s:
  ans += s*num_s[0]

print(''.join(sorted(ans)))
Problem p03777 (python)

Fixed submission:
def another(s):
  if s == 'D':
    return 'H'
  else:
    return 'D'

a, b = input().split()
if a == 'H':
  print(b)
else:
  print(another(b))

Buggy submission (verdict: Runtime Error):
def another(s):
  if s == 'D':
    return 'H'
  else:
    return 'D'

a, b = map(int, input().split())
if a == 'H':
  print(b)
else:
  print(another(b))
Problem p03778 (python)

Fixed submission:
W, a, b = map(int, input().split())
if a <= b <= a + W or a <= b + W <= a + W:
  print(0)
  quit()

print(min(abs(a+W - b), abs(b+W - a)))

Buggy submission (verdict: Runtime Error):
W, a, b = map(int, input().split())
if a <= b <= a + W or a <= b + W <= a + W:
  prin(0)
  quit()

print(abs(a+W - b), abs(b+w - a))
Problem p03937 (python)

Fixed submission:
H, W = map(int, input().split())
A = [input() for i in range(H)]

visited = [[False]*W for i in range(H)]
visited[0][0] = True
d = [[0, 0, -1, -1]]
while d:
  x, y, px, py = d.pop()
  num = 0
  flag = False
  for dx, dy in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
    if 0<=x+dx<H and 0<=y+dy<W and [x+dx, y+dy]!=[px, py] and A[x+dx][y+dy]=='#' and not visited[x+dx][y+dy]:
      visited[x+dx][y+dy] = True
      num += 1
      d.append([x+dx, y+dy, x, y])
      if dx < 0 or dy < 0:
        flag = True
  if (num >= 2) or flag:
    print('Impossible')
    quit()

print('Possible')

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
A = [input() for i in range(H)]

visited = [[False]*W for i in range(H)]
visited[0][0] = True
d = [[0, 0], [-1, -1]]
while d:
  x, y, px, py = d.pop()
  num = 0
  flag = False
  for dx, dy in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
    if 0<=x+dx<H and 0<=y+dy<W and [x+dx, y+dy]!=[px, py] and A[x+dx][y+dy]=='#' and not visited[x+dx][y+dy]:
      visited[x+dx][y+dy] = True
      num += 1
      d.append([x+dx, y+dy, x, y])
      if dx < 0 or dy < 0:
        flag = True
  if (num >= 2) or flag:
    print('Impossible')
    quit()

print('Possible')
Problem p03952 (python)

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

if x in [1, 2*N-1]:
  print('No')
else:
  print('Yes')
  if N == 2:
    print(*range(1, 4), sep='\n')
  else:
    ans = [0] * (2*N - 1)
    s = set(range(1, 2*N))
    if x >= N:
      ans[N-2] = x - 1; s.discard(x-1)
      ans[N-1] = x; s.discard(x)
      ans[N] = x + 1; s.discard(x+1)
      ans[N+1] = x - 2; s.discard(x-2)
    else:
      ans[N-2] = x + 1; s.discard(x+1)
      ans[N-1] = x; s.discard(x)
      ans[N] = x - 1; s.discard(x-1)
      ans[N+1] = x + 2; s.discard(x+2)
    for i in range(2*N-1):
      if ans[i]:
        continue
      ans[i] = s.pop()
    print(*ans, sep='\n')

Buggy submission (verdict: Runtime Error):
N, x = map(int, input().split())

if x in [1, 2*N-1]:
  print('No')
else:
  print('Yes')
  if N == 2:
    print(*range(1, 4), sep='\n')
  else:
    ans = [0] * (2*N - 1)
    s = set(range(1, 2*N))
    if x >= N:
      ans[N-1] = x - 1; s.discard(x-1)
      ans[N] = x; s.discard(x)
      ans[N+1] = x + 1; s.discard(x+1)
      ans[N+2] = x - 2; s.discard(x-2)
    else:
      ans[N-1] = x + 1; s.discard(x+1)
      ans[N] = x; s.discard(x)
      ans[N+1] = x - 1; s.discard(x-1)
      ans[N+2] = x + 2; s.discard(x+2)
    for i in range(2*N-1):
      if ans[i]:
        continue
      ans[i] = s.pop()
    print(*ans, sep='\n')
Problem p04006 (python)

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

min_time = [a for a in A]
ans = 10**15
for t in range(N):
  time = t*x
  for i in range(N):
    j = (i - t) % N
    min_time[i] = min(min_time[i], A[j])
    time += min_time[i]
  ans = min(ans, time)

print(ans)

Buggy submission (verdict: Runtime Error):
N, x = map(int, input().split())
A = list(map(int, input().split()))

min_time = A.copy()
ans = 10**15
for t in range(N):
  time = t*x
  for i in range(N):
    j = (i - t) % N
    min_time[i] = min(min_time[i], A[j])
    time += min_time[i]
  ans = min(ans, time)

print(ans)
Problem p04019 (python)

Fixed submission:
S = input()
n = int('N' in S)
s = int('S' in S)
w = int('W' in S)
e = int('E' in S)

if n + s == 1 or w + e == 1:
  print('No')
else:
  print('Yes')

Buggy submission (verdict: Runtime Error):
S = input()
n = int('N' in S)
s = int('S' in S)
w = int('W' in W)
e = int('E' in E)

if n + s == 1 or w + e == 1:
  print('No')
else:
  print('Yes')
Problem p02662 (python)

Fixed submission:
# Import
from collections import deque
import math

# I/O
def read(): return input()
def read_int(): return int(input())
def read_array(type=int): return [type(i) for i in input().split()]
def read_tupple(type=None):
    tmp = input().split()
    if type is None: return map(int, tmp)
    assert len(tmp) == len(type)
    return [type[i](tmp[i]) for i in range(len(tmp))]

MOD = 998244353
N, S = read_tupple()
A = read_array()

dp = [[0 for j in range(S+1)] for i in range(N+1)]
dp[0][0] = 1
for i in range(N):
    for j in range(S+1):
        dp[i + 1][j] += 2 * dp[i][j]
        if j - A[i] >= 0:
            dp[i + 1][j] += dp[i][j - A[i]]
        
        while dp[i+1][j] > MOD:
            dp[i+1][j] -= MOD
        
print(dp[N][S])

Buggy submission (verdict: Runtime Error):
# Import
from collections import deque
import math

# I/O
def read(): return input()
def read_int(): return int(input())
def read_array(type=int): return [type(i) for i in input().split()]
def read_tupple(type=None):
    tmp = input().split()
    if type is None: return map(int, tmp)
    assert len(tmp) == len(type)
    return [type[i](tmp[i]) for i in range(len(tmp))]

MOD = 998244353
N, S = read_tupple()
A = read_array()

dp = [[0 for j in range(S+1)] for i in range(N+1)]
dp[0][0] = 1
for i in range(N):
    for j in range(S+1):
        dp[i + 1][j] += 2 * dp[i][j]
        if j - A[i] >= 0:
            dp[i + 1][j] += dp[i][j - A[i]]
        
        while dp[i+1][j] > MOD:
			dp[i+1][j] -= MOD
        
print(dp[N][S])