Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sympy
url = "https://atcoder.jp//contests/abc057/tasks/abc057_c"

def main():
    n = int(input())
    ans = 10000000000000000
    ns = sympy.divisors(n)
    for i in range(0, (len(ns)//2) + 1):
        tmp = max(len(str(ns[i])), len(str(ns[len(ns)-i-1])))
        ans = tmp if tmp < ans else ans
    if len(ns) % 2 != 0:
            tmp = len(str(ns[len(ns) // 2]))
            ans = tmp if tmp < ans else ans
    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:

url = "https://atcoder.jp//contests/abc057/tasks/abc057_c"
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


def main():
    n = int(input())
    ans = 10000000000000000
    ns = make_divisors(n)
    for i in range(0, (len(ns)//2) + 1):
        tmp = max(len(str(ns[i])), len(str(ns[len(ns)-i-1])))
        ans = tmp if tmp < ans else ans
    if len(ns) % 2 != 0:
            tmp = len(str(ns[len(ns) // 2]))
            ans = tmp if tmp < ans else ans
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    ans = 1
    mod = 10**9 + 7
    for i in range(1,n+1):
        ans *= i
    print(ans%mod)

if __name__ == '__main__':
    main()


Fixed submission:
import math

def main():
    n = int(input())
    mod = 10**9 + 7
    print(math.factorial(n)%mod)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):

def main():
    s, c = list(map(int, input().split()))
    count = 0
    while True:
        if c < 2 or (s < 1 and c < 4):
            break
        if s > 1:
            s -= 1
            c -= 2
        else:
            c -= 4
        count += 1
    print(count)


if __name__ == '__main__':
    main()

Fixed submission:
def main():
    s, c = list(map(int, input().split()))
    count = 0
    if s <= c//2:
        count = s
    else:
        print(c//2)
        exit()
    c -= s*2
    print(count+c//4)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
def main():
    k,s = list(map(int, input().split()))
    count = 0
    for x,y,z in itertools.product(range(0, k+1),range(0, k+1),range(0, k+1)):
        count += 1 if x+y+z == s else 0
    print(count)


if __name__ == '__main__':
    main()

Fixed submission:
import itertools
url = "https://atcoder.jp//contests/abc057/tasks/abc057_a"

def main():
    k, s = list(map(int, input().split()))
    count = 0
    for x, y in itertools.product(range(k+1), range(k+1)):
        z = s - x - y
        if 0 <= z <= k:
            count += 1
    print(count)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import math
def main():
    n = int(input())
    As = list(map(int, input().split(' ')))
    ind_lis = {}
    idx = n - 1
    while idx >= 0:
        ind_lis[idx] = 0
        idx -= 2
    for a in As:
        ind_lis[a] += 1
        if a == 0 and ind_lis[a] > 1:
            print(0)
            exit()
        elif ind_lis[a] > 2:
            print(0)
            exit()
    print(2**(n//2)%(10**9 + 7))



if __name__ == '__main__':
    main()

Fixed submission:
import math

def fail():
    print(0)
    exit()

def main():
    n = int(input())
    As = list(map(int, input().split(' ')))
    ind_lis = {}
    idx = n - 1
    while idx >= 0:
        ind_lis[idx] = 0
        idx -= 2
    for a in As:
        if a not in ind_lis:
            fail()
        ind_lis[a] += 1
        if a == 0 and ind_lis[a] > 1:
            fail()
        elif ind_lis[a] > 2:
            fail()
    print(2**(n//2)%(10**9 + 7))



if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):

url = "https://atcoder.jp//contests/abc049/tasks/abc049_b"

def main():
    h, w = list(map(int, input().split()))
    ss = [input() for _ in range(h)]
    for s in ss:
        print(s)
        print(s)

if __name__ == '__main__':
    main()


Fixed submission:

url = "https://atcoder.jp//contests/abc049/tasks/arc065_a"

def main():
    words = ['dream','dreamer', 'erase', 'eraser']
    s = input()
    rs = s[::-1]
    while rs != '':
        tmp = len(rs)
        for word in words:
            if len(word) > len(rs):
                continue
            rs = rs[0:len(word)].replace(word[::-1], '') + rs[len(word):]
        if tmp == len(rs):
            print('NO')
            exit()
    print('YES')

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):

def main():
    t = input().split()
    dis = list(map(int, input().split()))
    like = []
    for i in range(0,10):
        if i not in dis:
            like.append(i)
    ans = []
    digit = False
    for i in range(len(t[0])):
        if digit:
            break
        ans.append(-1)
        for j, v in enumerate(like):
            if int(t[0][i]) == v:
                ans[-1] = j
                break
            elif int(t[0][i]) < v:
                ans[-1] = j
                for m in range(i + 1, len(t[0])):
                    ans.append(0)
                digit = True
                break

    ind = 0
    ans_s = []
    for i in reversed(ans):
        if i == -1:
            ind += 1
            ans_s.append(0)
        elif ind > 0:
            if i == len(like) - 1:
                ans_s.append(0)
            else:
                ans_s.append(i + ind)
                ind = 0
        else:
            ans_s.append(i)
    print(ans_s)
    if ind > 0:
        ans_s.append(-1)
    ans_s.reverse()
    if len(ans_s) == 1 and int(t[0][0]) > like[ans_s[0]]:
        ans_s.append(0)
    for i in range(0, len(ans_s)):
        ans_s[i] = str(like[ans_s[i]])
    print(''.join(ans_s))


if __name__ == '__main__':
    main()




Fixed submission:
url = "https://atcoder.jp/contests/abc043/tasks/abc043_a"

def main():

    a = int(input())
    ans = 0
    for i in range(1, a + 1):
        ans += i
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
l = sorted([int(x) for x in input().split()])

print(sum(l[:k]))

Fixed submission:
print('a' if input().islower() else 'A')
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input())
l = sorted([int(x) for x in input().split()])

print(sum(l[:k]))

Fixed submission:
n, k = map(int, input().split())
l = sorted([int(x) for x in input().split()])

print(sum(l[:k]))
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
import operator
input()

result = reduce(operator.mul, [int(x) for x in input().split()], 1)
if result > 10 ** 18:
  print(-1)
else:
  print(result)

Fixed submission:
input()

result = 1
a = [int(x) for x in input().split()]
if 0 in a:
  print(0)
  exit()

for x in a:
  if result > 10 ** 18:
    print(-1)
    exit()
  result *= x
  
if result > 10 ** 18:
  print(-1)
else:
  print(result)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
p = [int(x) for x in input().split()]

l = 0
r = k

result = 0.0
m = 0
pp = []
while r != len(p)+1:
  tmp_pp = p[l:r]
  s = sum(tmp_pp)
  l += 1
  r += 1
  if s <= m:
    continue
  m = s
  pp = tmp_pp

for pi in pp:
  result += pi / 2 + 1 / 2
print(result)

Fixed submission:
from itertools import accumulate
n, k = map(int, input().split())
p = list(map(int, input().split()))

pp = [0] + list(accumulate(p))

m = 0
for i in range(n - k + 1):
  m = max(m,pp[i + k] - pp[i])
print((m+k)/2)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
p = [int(x) for x in input().split()]

l = 0
r = k

result = 0.0
m = 0
while r != len(p)+1:
  pp = p[l:r]
  l += 1
  r += 1
  s = sum(pp)
  if s <= m:
    continue
  m = s
  this_res = 0.0
  # 期待値の計算
  for pi in pp:
    this_res += pi / 2 + 1/2
  result = max(result, this_res)

print(result)

Fixed submission:
from itertools import accumulate
n, k = map(int, input().split())
p = list(map(int, input().split()))

pp = [0] + list(accumulate(p))

m = 0
for i in range(n - k + 1):
  m = max(m,pp[i + k] - pp[i])
print((m+k)/2)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
p = [int(x) for x in input().split()]

l = 0
r = k

result = 0.0
while r != len(p)+1:
  this_res = 0.0
  for pi in p[l:r]:
    this_res += pi / 2 + 1/2
  result = max(result, this_res)
  l += 1
  r += 1

print(result)

Fixed submission:
from itertools import accumulate
n, k = map(int, input().split())
p = list(map(int, input().split()))

pp = [0] + list(accumulate(p))

m = 0
for i in range(n - k + 1):
  m = max(m,pp[i + k] - pp[i])
print((m+k)/2)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
p = [int(x) for x in input().split()]

l = 0
r = k

result = 0.0
while r != len(p)+1:
  this_res = 0.0
  # 期待値の計算
  for pi in p[l:r]:
    this_res += pi / 2 + 1/2
  result = max(result, this_res)
  l += 1
  r += 1

print(result)

Fixed submission:
from itertools import accumulate
n, k = map(int, input().split())
p = list(map(int, input().split()))

pp = [0] + list(accumulate(p))

m = 0
for i in range(n - k + 1):
  m = max(m,pp[i + k] - pp[i])
print((m+k)/2)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
p = [int(x) for x in input().split()]

l = 0
r = k

result = 0.0
while r != len(p)+1:
  this_res = 0.0
  for pi in p[l:r]:
    this_res += sum(map(lambda a : 1/pi * a, [x for x in range(1, pi+1)]))
  result = max(result, this_res)
  l += 1
  r += 1

print(result)

Fixed submission:
from itertools import accumulate
n, k = map(int, input().split())
p = list(map(int, input().split()))

pp = [0] + list(accumulate(p))

m = 0
for i in range(n - k + 1):
  m = max(m,pp[i + k] - pp[i])
print((m+k)/2)
Buggy python submission (verdict: Runtime Error):
h, n = map(int, input().split())
dp = [10 ** 9] * (h+1)
dp[0] = 0

for ni in range(n):
  a, b = map(int, input().split())
  for hi in range(h):
    nj = min(j+a, h)
    dp[nj] = min(dp[nj], dp[j] + b)

print(dp[h])

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

count = 0
while True:
    h -= a
    count += 1
    if h <= 0:
        break
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = [int(x) for x in input().split()]

bits = 0

result = 0
for x in p:
  if x == 1:
    bits |= 1 << x - 1
    result += 1
    continue
  
  lower_bits = '1' * (x - 1)
  
  if (bits & int(lower_bits, 2)) > 0:
    bits |= 1 << x - 1
    continue
    
  result += 1
  bits |= 1 << x - 1

print(result)

Fixed submission:
iterate = int(input())
p = [int(x) for x in input().split()]

result_sum = 0
prev_min = 10  ** 9
for i in range(iterate):
  if p[i] <= prev_min:
    	result_sum += 1
  prev_min = min(prev_min, p[i])

print(result_sum)
Buggy python submission (verdict: Runtime Error):
a


Fixed submission:
print(chr(ord(input())+1))
Buggy python submission (verdict: Runtime Error):
r = int(input())
g = int(input())

print(int(g * 2 - r))

Fixed submission:
# history :: {int : (int, bool)}
n, m = [int(x) for x in input().split()]
history = { i+1 : [0, False] for i in range(n)}

for _ in range(m):
  pi, result = input().split()
  translated_pi = int(pi)
  if result == 'WA' and not history[translated_pi][1]:
    history[translated_pi][0] += 1
  else:
    history[translated_pi][1] = True

ac_count = 0
penalty_count = 0
for result in history.values():
  if result[1]:
    ac_count += 1
    penalty_count += result[0]

print("{} {}".format(ac_count, penalty_count))
Buggy python submission (verdict: Runtime Error):
input()
s1, s2 = input().split()
for idx in range(len(s)):
  print(s1[idx],end='')
  print(s2[idx],end='')
  
print()

Fixed submission:
input()
s1, s2 = input().split()
for idx in range(len(s2)):
  print(s1[idx],end='')
  print(s2[idx],end='')
  
print()
Buggy python submission (verdict: Runtime Error):
s = input()
rev_s = reverse(s)

count = 0
for i in range(len(s)):
  if s[i] != rev_s[i]:
    count += 1
    
print(count)

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

cnt = 0
for i in range(len(S)//2):
    if S[i] != Sinv[i]:
        S[i] = Sinv[i]
        cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = set(filter(lambda x : n % x == 0 and n / x < 10, [x for x in range(1, 10)])

print("Yes" if len(s) == 0 in s else "No")

Fixed submission:
s = {x*y for x in range(1, 10) for y in range(1, 10)}

print("Yes" if int(input()) in s else "No")
Buggy python submission (verdict: Runtime Error):
for i in range(0, n, 2):
  if s[i] == 'L':
    f = False

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

f = True

for i in range(0, n, 2):
  if s[i] == 'L':
    f = False

for i in range(1, n, 2):
  if s[i] == 'R':
    f = False
    
print("Yes" if f else "No")
Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]
sc = {i : k for i in range(1, n+1)}
sc[0] = 0

for s in a:
  for i in range(1, n+1):
    if i == s:
      continue
    
    sc[i] -= 1

del sc[0]
for s in sc.values():
  print("Yes" if s > 0 else "No")

Fixed submission:
n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]
sc = {i : 0 for i in range(1, n+1)}
sc[0] = 0

for s in a:
  sc[s] += 1

del sc[0]
for s in sc.values():
  print("Yes" if (k-q+s)>0 else "No")
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()))

m = max(a)

print(sum(b) + c[m - 1])

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ttl = sum(b)
for i in range(n-1):
    if a[i]+1 == a[i+1]:
        ttl += c[a[i]-1]
print(ttl)
Buggy python submission (verdict: Runtime Error):
n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]
sc = {i : k for i in range(1, n+1)}
sc[0] = 0

for s in a:
  for i in range(1, n+1):
    if i == s:
      continue
    
    sc[i] -= 1

del sc[0]
for s in sc.values():
  print("Yes" if s > 0 else "No")

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

h.reverse()
ans = 0
temp = 0
for i in range(n-1):
    if h[i+1] >= h[i]:
        temp += 1
    else:
        ans = max(temp, ans)
        temp = 0

ans = max(temp, ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = map(int, input().split())

count = 0
for i in range(n-1):
  if s[i] > s[i+1]:
    count += 1

print("YES" if count < 3 else "NO")

Fixed submission:
n=int(input())
s=list(map(int,input().split()))
ans=0
p=sorted(s)
for i in range(n):
    if s[i]!=p[i]:
        ans+=1
print("NO" if ans>2 else "YES")

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

count = 0
for i in range(n-1):
  if int(s[i]) > int(s[i+1]):
    count += 1

print("YES" if count < 3 else "NO")

Fixed submission:
n=int(input())
s=list(map(int,input().split()))
ans=0
p=sorted(s)
for i in range(n):
    if s[i]!=p[i]:
        ans+=1
print("NO" if ans>2 else "YES")
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = sorted(list(map(int, input().split())))
print(a[n/2] - a[n/2-1])

Fixed submission:
n = int(input())
a = sorted(list(map(int, input().split())))
print(a[n//2] - a[n//2-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
stairs = [i for i in range(1, n+1)]
a = []
for _ in range(m):
  a.append(int(input()))

dp = [0] * (n + 1)
dp[0] = 1


for i in range(1, n+1):
  if i in a:
    continue
  dp[i] = dp[i] + dp[i-1]
  if i > 1:
    dp[i] = dp[i] + dp[i-2]

print(dp[n] % 1000000007)

Fixed submission:
n, m = map(int, input().split())
stairs = [i for i in range(1, n+1)]
a = [0 for _ in range(m)]
for i in range(m):
  a[i] = int(input())
a = set(a)
  
dp = [0] * (n + 1)
dp[0] = 1

for i in range(1, n+1):
  if i in a:
    continue
  dp[i] = dp[i] + dp[i-1]
  if i > 1:
    dp[i] = dp[i] + dp[i-2]

print(dp[n] % 1000000007)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
left = 0 # 制約における最小を超える値
right = 10 ** 6 # 制約における最大を超える値
for _ in range(m):
  l, r = map(int, input().split())
  left = max(left, l)
  right = min(right, r)
    right = r

print(r-l+1 if l <= r else 0)

Fixed submission:
n, m = map(int, input().split())
left = 0 # 制約における最小を超える値
right = 10 ** 6 # 制約における最大を超える値
for _ in range(m):
  l, r = map(int, input().split())
  left = max(left, l)
  right = min(right, r)

print(right-left+1 if left <= right else 0)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
for i in range(m):
  b, c = map(int, input().split())
  change_number = len(list(filter(lambda x : x < c, a)))
  change_number = change_number if change_number <= b else b
  a = ([c] * change_number) + a[change_number:]
  a.sort()

print(sum(a))

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
cb_list = []
for i in range(m):
  b, c = map(int, input().split())
  cb_list.append((c, b))

cb_list.sort(key=lambda x: x[0], reverse=True)

elim_count = 0
for i in range(m):
  c,b = cb_list[i]
  a.extend([c] * b)
  if len(a) >= 2*n:
    break

a.sort(reverse=True)
print(sum(a[:n]))
Buggy python submission (verdict: Runtime Error):
from collections import deque
n = int(input())
# 最終的に出力する色
colors = [-1] * n
# 重み付き無向グラフ
conns = [set() for _ in [0] * n] 

for x in range(1, n):
  v1, v2, dis = map(int, input().split())
  # (接続ノード, 重み) を加える
  conns[v1-1].add((v2-1, dis))
  conns[v2-1].add((v1-1, dis))

# BFSの為に根ノードを初期化. (基準ノード, 距離)
q = deque([(0, 0)])
# BFS開始
while q:
  v, dis, past = q.popleft()
  
  # 奇数なら1で,偶数なら0で塗る
  colors[v] = dis&1
  
  # 基準ノードから生える各エッジに対し
  for edge, w in conns[v]:
    
    # 根からここまでの距離を足しつつ,新しく探索先を追加.
    q.append((edge, dis + w))

print('\n'.join(map(str, colors)))

Fixed submission:
n, k = map(int, input().split())
total_prob = 0
for i in range(1, n+1):
  dice_count = 0
  while (i << dice_count) < k:
    dice_count += 1
  
  total_prob += (1 / n) * (0.5 ** dice_count)
  
print(round(total_prob, 12))
Buggy python submission (verdict: Runtime Error):
n = int(input())
# 最終的に出力する色
colors = [-1] * n
# 重み付き無向グラフ
conns = [set() for _ in [0] * n] 

for x in range(1, n):
  v1, v2, dis = map(int, input().split())
  # (接続ノード, 重み) を加える
  conns[v1-1].add((v2-1, dis))
  conns[v2-1].add((v1-1, dis))
  
def dfs(now: int, prev: int,  color: int):
  # 頂点に色を塗る
  colors[now] = color
  # 頂点から生える各エッジに対し
  for edge, w in conns[now]:
    # 親と一緒 -> 無視
    if edge == prev:
      continue
    # 偶数なら同色,奇数なら異色で塗る
    dfs(edge, now, 1-color) if w&1 else dfs(edge, now, color)

# 適当に根ノードを決め,グラフ彩色開始
dfs(0, -1, 1)

print('\n'.join(map(str, colors)))

Fixed submission:
from collections import deque
n = int(input())
# 最終的に出力する色
colors = [-1] * n
# 重み付き無向グラフ
conns = [set() for _ in [0] * n] 

for x in range(1, n):
  v1, v2, dis = map(int, input().split())
  # (接続ノード, 重み) を加える
  conns[v1-1].add((v2-1, dis))
  conns[v2-1].add((v1-1, dis))

# BFSの為に根ノードを初期化. (基準ノード, 距離, 過去のノード)
q = deque([(0, 0, -1)])
# BFS開始
while q:
  v, dis, past = q.popleft()
  
  # 奇数なら1で,偶数なら0で塗る
  colors[v] = dis&1
  
  # 基準ノードから生える各エッジに対し
  for edge, w in conns[v]:
    
    # エッジが既に調べたものなら飛ばす
    if edge == past:
      continue
    # 根からここまでの距離を足しつつ,新しく探索先を追加.
    q.append((edge, dis + w, v))

print('\n'.join(map(str, colors)))

Buggy python submission (verdict: Runtime Error):
from collections import deque
n = int(input())
# 最終的に出力する色
colors = [-1] * n
# 重み付き無向グラフ
conns = [set() for _ in [0] * n] 

for x in range(1, n):
  v1, v2, dis = map(int, input().split())
  # (接続ノード, 重み) を加える
  conns[v1-1].add((v2-1, dis))
  conns[v2-1].add((v1-1, dis))

# BFSの為に根ノードを初期化. (基準ノード, 距離)
q = deque([(0, 0)])
# BFS開始
while q:
  v, dis, past = q.popleft()
  
  # 奇数なら1で,偶数なら0で塗る
  colors[v] = dis&1
  
  # 基準ノードから生える各エッジに対し
  for edge, w in conns[v]:
    
    # 根からここまでの距離を足しつつ,新しく探索先を追加.
    q.append((edge, dis + w))

print('\n'.join(map(str, colors)))

Fixed submission:
from collections import deque
n = int(input())
# 最終的に出力する色
colors = [-1] * n
# 重み付き無向グラフ
conns = [set() for _ in [0] * n] 

for x in range(1, n):
  v1, v2, dis = map(int, input().split())
  # (接続ノード, 重み) を加える
  conns[v1-1].add((v2-1, dis))
  conns[v2-1].add((v1-1, dis))

# BFSの為に根ノードを初期化. (基準ノード, 距離, 過去のノード)
q = deque([(0, 0, -1)])
# BFS開始
while q:
  v, dis, past = q.popleft()
  
  # 奇数なら1で,偶数なら0で塗る
  colors[v] = dis&1
  
  # 基準ノードから生える各エッジに対し
  for edge, w in conns[v]:
    
    # エッジが既に調べたものなら飛ばす
    if edge == past:
      continue
    # 根からここまでの距離を足しつつ,新しく探索先を追加.
    q.append((edge, dis + w, v))

print('\n'.join(map(str, colors)))
Buggy python submission (verdict: Time Limit Exceeded):
n, k= map(int, input().split())
h = list(map(int, input().split()))
h = [0] + h

dp = [10 ** 9] * (n+1)
dp[1] = 0

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

print(dp[n])

Fixed submission:
n, k= map(int, input().split())
h = list(map(int, input().split()))
h = [0] + h

dp = [10 ** 9] * (n+1)
dp[1] = 0

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

print(dp[n])
Buggy python submission (verdict: Runtime Error):
N = int(input())
m, *P = sorted([int(input()) for x in range(N)], reverse=True)

"""
m = P[N-1]
P = P[:N-1]
"""

print(sum(P) + m // 2)

Fixed submission:
d = int(input())
print("Christmas " + "Eve " * (5 - d%20))
Buggy python submission (verdict: Runtime Error):
n, t = map(int, input.split())

max_cost = 10 ** 9

for _ in range(n):
  c, tt = map(int, input().split())
  if tt <= t:
    max_cost = max(max_cost, c)
    
print(max_cost)

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

if ans==10000:
  print("TLE")
else:
  print(ans)
Buggy python submission (verdict: Runtime Error):
def f(c):
  if c == "1":
    return "9"
  elif c == "9":
    return 1
  else:
    return c
  
print(''.join(list(map(f, input()))))

Fixed submission:
f = lambda c : "1" if c == "9" else "9"
  
print(''.join(list(map(f, input()))))
Buggy python submission (verdict: Runtime Error):
N = int(input())
m = dict()

prev = input()
m[prev] = True
flg = True

for _ in range(N - 1):
  s = input()
  flg = all(flg, s not in m, prev[len(prev) - 1] == s[0])
  m[s] = True
  prev = s

print("Yes" if flg else "No")

Fixed submission:
N = int(input())
m = dict()

prev = input()
m[prev] = True
flg = True

for _ in range(N - 1):
  s = input()
  flg = flg and s not in m
  flg = flg and prev[len(prev) - 1] == s[0]
  m[s] = True
  prev = s

print("Yes" if flg else "No")