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

Fixed submission:
s = input()
a = list("abcdefghijklmnopqrstuvwxyz")
if s == "zyxwvutsrqponmlkjihgfedcba":
     print(-1)
elif len(s) != 26:
    nokori = set(a) - set(s)
    nokori = sorted(nokori, key=a.index)
    print(s + nokori[0])
else:
    for i in range(1, 27):
        if list(s)[-i] > list(s)[-(i + 1)]:
            break
    T = sorted(list(s)[-i:])
    #print(T)
    for t in T:
        if t > list(s)[-(i + 1)]:
            break
    print("".join(list(s)[:-(i + 1)]) + t)

Buggy submission (verdict: Runtime Error):
s = input()
a = list("abcdefghijklmnopqrstuvwxyz")
elif len(s) != 26:
    nokori = set(a) - set(s)
    nokori = sorted(nokori, key=a.index)
    print(s + nokori[0])
else:
    for i in range(2, 27):
        if s[-i] <= s[-i + 1]:
            break
    if i == 26:
        print(-1)
    else:
        s_ = sorted(s[-i + 1:])
        for j in s_:
            if j > s[-i]:
                break
        print(s[:-i] + j)

Buggy submission (verdict: Runtime Error):
s = input()
a = list("abcdefghijklmnopqrstuvwxyz")
if len(s) != 26:
    nokori = set(a) - set(s)
    nokori = sorted(nokori, key=a.index)
    print(s + nokori[0])
else:
    for i in range(2, 27):
        if s[-i] <= s[1 - i]:
            break
    for k in range(1, 27):
        if s[-k] > s[-k - 1]:
            break
    #print(i, k)
    if i == 26:
        print(-1)
    else:
        s_ = sorted(s[-i + 1:])
        for j in s_:
            if j > s[-i]:
                break
        #print(s[:-i] + j)

        T = sorted(s[-k:])
        for t in T:
            if t > s[-k - 1]:
                break
        print("".join(list(s)[:-k - 1]) + t)
        #print(s_, T)

Buggy submission (verdict: Runtime Error):
s = input()
a = list("abcdefghijklmnopqrstuvwxyz")
if len(s) != 26:
    nokori = set(a) - set(s)
    nokori = sorted(nokori, key=a.index)
    print(s + nokori[0])
else:
    for i in range(2, 27):
        if s[-i] <= s[1 - i]:
            break
    for k in range(1, 27):
        if s[-k] > s[-k - 1]:
            break
    #print(i, k)
    if i == 26:
        print(-1)
    else:
        s_ = sorted(s[-i + 1:])
        for j in s_:
            if j > s[-i]:
                break
        #print(s[:-i] + j)

        T = sorted(s[-k:])
        for t in T:
            if t > s[-k - 1]:
                break
        print(s[:-k - 1] + t)
        #print(s_, T)
Problem p03556 (python)

Fixed submission:
n = int(input())
i = 1
while n >= i * i:
    i += 1
print((i - 1) * (i - 1))

Buggy submission (verdict: Runtime Error):
n = int(input())
for i in range(1, n):
    if n < i ** 2:
        break
print((i - 1) ** 2)
Problem p03565 (python)

Fixed submission:
sd = input()
t = input()
for i in range(len(sd) - len(t), -1, -1):
    t_kamo = sd[i:i + len(t)]
    for j in range(len(t) + 1):
        if j == len(t):
            s = sd[:i].replace("?", "a") + t + sd[i + len(t):].replace("?", "a")
            print(s)
            exit()
        if t_kamo[j] == "?":
            continue
        elif t_kamo[j] != t[j]:
            break
print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
sd = input()
t = input()
n = len(sd)
m = len(t)
ss = []
for i in range(n - m + 1):
    flag = True
    s = ""
    for j in range(m):
        if sd[i + j] == "?" or sd[i + j] == t[j]:
            continue
        else:
            flag = False
    if flag:
        k = 0
        for j in range(n):
            if j < i or j > i + m:
                if sd[j] == "?":
                    s += "a"
                else:
                    s += sd[j]
            else:
                if sd[j] == "?":
                    s += t[k]
                else:
                    s += sd[j]
                k += 1
        ss.append(s)
if ss:
    print(sorted(ss)[0])
else:
    print("UNRESTORABLE")
Problem p03569 (python)

Fixed submission:
s = input()

i = 0
j = len(s) - 1
ans = 0
while i != j:
    if abs(i - j) == 1:
        if s[i] == s[j]:
            break
    if s[i] != s[j]:
        if s[i] != "x" and s[j] != "x":
            print(-1)
            exit()
        elif s[i] != "x":
            j -= 1
        else:
            i += 1
        ans += 1
    else:
        i += 1
        j -= 1

print(ans)

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

i = 0
j = len(s) - 1
ans = 0
while i != j:
    if s[i] != s[j]:
        if s[i] != "x" and s[j] != "x":
            print(-1)
            exit()
        elif s[i] != "x":
            j -= 1
        else:
            i += 1
        ans += 1
    else:
        i += 1
        j -= 1

print(ans)
Problem p03578 (python)

Fixed submission:
import collections

n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
dc = collections.Counter(d)
tc = collections.Counter(t)
for i in tc:
    if tc[i] > dc[i]:
        print("NO")
        exit()
print("YES")

Buggy submission (verdict: Runtime Error):
n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
t_ = set(t)
for i in range(len(t_)):
  if t.count(t_[i]) > d.count(t_[i]):
    print("NO")
    exit()
print("YES")

Buggy submission (verdict: Runtime Error):
n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
t_ = set(t)
for i in range(len(t_):
  if t.count(t_[i]) > d.count(t_[i]):
    print("NO")
    exit()
print("YES")
Problem p03601 (python)

Fixed submission:
a, b, c, d, e, f = map(int, input().split())
x = set()
y = set()
for A in range(0, f + 1, 100 * a):
    for B in range(0, f + 1, 100 * b):
        if A + B > f:
            break
        if A + B:
            x.add(A + B)
for C in range(0, f + 1, c):
    for D in range(0, f + 1, d):
        if C + D > f:
            break
        y.add(C + D)
ans = 0
w = 100 * a
s = 0
for X in x:
    for Y in y:
        if X + Y <= f and 100 * Y / X <= e:
                if ans < Y / (X + Y):
                    ans = Y / (X + Y)
                    w = X
                    s = Y
print(w + s, s)

Buggy submission (verdict: Runtime Error):
a, b, c, d, e, f = map(int, input().split())
x = set()
y = set()
for A in range(0, f + 1, 100 * a):
    for B in range(0, f + 1, 100 * b):
        if A + B > f:
            break
        if A + B:
            x.add(A + B)
for C in range(0, f + 1, c):
    for D in range(0, f + 1, d):
        if C + D > f:
            break
        y.add(C + D)
ans = 0
for X in x:
    for Y in y:
        if X + Y <= f and 100 * Y / X <= e:
                if ans < Y / (X + Y):
                    ans = Y / (X + Y)
                    w = X
                    s = Y
print(w + s, s)

Buggy submission (verdict: Runtime Error):
a, b, c, d, e, f = map(int, input().split())
x = set()
y = set()
for A in range(0, f + 1, 100 * a):
    for B in range(0, f + 1, 100 * b):
        if A + B:
            x.add(A + B)
for C in range(0, f + 1, c):
    for D in range(0, f + 1, d):
        y.add(C + D)
ans = 0
for X in x:
    for Y in y:
        if X + Y <= f and 100 * Y / X <= e:
                if ans < Y / (X + Y):
                    ans = Y / (X + Y)
                    w = X
                    s = Y
print(w + s, s)
Problem p03624 (python)

Fixed submission:
s = set(input())
a = "abcdefghijklmnopqrstuvwxyz"
for i in s:
  a = a.replace(i, "")
if a:
  print(a[0])
else:
  print("None")

Buggy submission (verdict: Runtime Error):
s = set(input())
a = "abcdefghijklmnopqrstuvwxyz"
for i in s:
  a = a.replace(i, "")
print(a[0])
Problem p03687 (python)

Fixed submission:
s_ = input()
answ = float("inf")
for i in s_:
    s = s_
    ans = 0
    while len(set(s)) != 1:
        a = ""
        for j in range(len(s) - 1):
            if s[j] == i or s[j + 1] == i:
                a += i
            else:
                a += s[j]
        ans += 1
        s = a
    answ = min(answ, ans)
print(answ)

Buggy submission (verdict: Runtime Error):
import collections

s = input()
c = collections.Counter(s).most_common()
m = c[0][1]
maxi = 0
if m == 1:
    print(len(s) // 2)
else:
    for k in c:
        if k[1] == m and k[0] != s[0]:
            index = [i for i, x in enumerate(s) if x == k[0]]
            sa = [index[i + 1] - index[i] for i in range(m - 1)]
            if maxi < min(sa):
                use = k
                maxi = min(sa)
    ans = 0
    while len(set(s)) != 1:
        a = ""
        for i in range(len(s) - 1):
            if s[i] == use[0] or s[i + 1] == use[0]:
                a += use[0]
            else:
                a += s[i]
        ans += 1
        s = a
    print(ans)
Problem p03697 (python)

Fixed submission:
a, b = map(int, input().split())
if a + b >= 10:
  print("error")
else:
  print(a + b)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().splt())
if a + b >= 10:
  print("error")
else:
  print(a + b)
Problem p03732 (python)

Fixed submission:
N, W = map(int, input().split())
w = []
v = []
for i in range(N):
    wi, vi = map(int, input().split())
    w.append(wi)
    v.append(vi)
ww = [w[0], w[0]+1, w[0]+2, w[0]+3]
d = {}
for i in range(4):
    d[ww[i]] = []
for i in range(N):
    d[w[i]].append(v[i])
for i in range(4):
    d[ww[i]] = sorted(d[ww[i]], reverse=True)
    
ans = 0
for i in range(N+1):
    if len(d[ww[0]]) < i:
        # print('break i: {}'.format(i))
        break
    for j in range(N+1):
        if i + j > N or len(d[ww[1]]) < j:
            # print('break i, j: {}, {}'.format(i, j))
            break
        for k in range(N+1):
            if i + j + k > N or len(d[ww[2]]) < k:
                # print('break i, j, k: {}, {}, {}'.format(i, j, k))
                break
            for l in range(N+1):
                # print(ww[0] * i + ww[1] * j + ww[2] * k + ww[3] * l)

                if i + j + k + l > N or\
                        len(d[ww[3]]) < l or\
                        ww[0] * i + ww[1] * j +\
                        ww[2] * k + ww[3] * l > W:
                    # print('break i, j, k: {}, {}, {}, {}'.format(i, j, k, l))
                    break

                av = sum([d[ww[0]][p] for p in range(i)])
                bv = sum([d[ww[1]][p] for p in range(j)])
                cv = sum([d[ww[2]][p] for p in range(k)])
                dv = sum([d[ww[3]][p] for p in range(l)])
                ans = max(ans, av+bv+cv+dv)
print(ans)

Buggy submission (verdict: Runtime Error):
n, W = map(int, input().split())
w = []
v = []
for i in range(n):
    w_, v_ = map(int, input().split())
    w.append(w_)
    v.append(v_)

if sum(w) <= W:
    print(sum(v))
else:
    dp = [[0] * (W + 1) for i in range(n + 1)]  # DP テーブル

    for i in range(n - 1, -1, -1):
        for j in range(w[0], W + 1):
            if j < w[i]:
                dp[i][j] = dp[i + 1][j]
            else:
                dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i])

    print(dp[0][W])

Buggy submission (verdict: Runtime Error):
n, W = map(int, input().split())
w = []
v = []
for i in range(n):
    w_, v_ = map(int, input().split())
    w.append(w_)
    v.append(v_)

dp = [[0] * (W + 1) for i in range(n + 1)]  # DP テーブル

for i in range(n - 1, -1, -1):
    for j in range(w[0], W + 1):
        if j < w[i]:
            dp[i][j] = dp[i + 1][j]
        else:
            dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i])

print(dp[0][W])
Problem p03763 (python)

Fixed submission:
import collections

n = int(input())
s = [input() for i in range(n)]
if n == 1:
    print("".join(sorted(s[0])))
else:
    c = []
    for i in s:
        c.append(collections.Counter(i))
    a = c[0] & c[1]
    for i in range(2, n):
        a &= c[i]
    ans = []
    a = a.most_common()
    for i in a:
        for j in range(i[1]):
            ans.append(i[0])
    print("".join(sorted(ans)))

Buggy submission (verdict: Runtime Error):
import collections

n = int(input())
s = [input() for i in range(n)]
c = []
for i in s:
    c.append(collections.Counter(i))
a = c[0] & c[1]
for i in range(2, n):
    a &= c[i]
ans = []
a = a.most_common()
for i in a:
    for j in range(i[1]):
        ans.append(i[0])
print("".join(sorted(ans)))
Problem p03777 (python)

Fixed submission:
a, b = input().split()
if a == "H":
  if b == "H":
    print("H")
  else:
    print("D")
else:
  if b == "H":
    print("D")
  else:
    print("H")

Buggy submission (verdict: Runtime Error):
x = int(input())
a = 0
for i in range(1, 10 ** 9):
    if a >= x:
        print(i - 1)
        break
    a += i
Problem p03838 (python)

Fixed submission:
x, y = map(int, input().split())
res = float("inf")
if x <= y:  # xx
    res = min(res, y - x)
if -x <= y:  # ox
    res = min(res, y + x + 1)
if x <= -y:  # xo
    res = min(res, -y - x + 1)
if -x <= -y:  # oo
    res = min(res, -y + x + 2)
print(res)

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

x, y = map(int, input().split())
if abs(x) == abs(y):
    print(1)
elif np.sign(x) == np.sign():
    if x < y:
        print(y - x)
    else:
        print(x - y + 2)
else:
    print(x + y + 1)
Problem p03844 (python)

Fixed submission:
a, op, b = input().split()
if op == "+":
  print(int(a) + int(b))
else:
  print(int(a) - int(b))

Buggy submission (verdict: Runtime Error):
n = int(input())
t = list(map(int, input().split()))
m = int(input())
s = sum(t)
for i in range(m):
  p, x = map(int, input().split())
  print(s - t[p - 1] + x)
Problem p03852 (python)

Fixed submission:
c = input()
vowel = ["a", "e", "i", "o", "u"]
if c in vowel:
  print("vowel")
else:
  print("consonant")

Buggy submission (verdict: Runtime Error):
c = input()
vowel = ["a", "e", "i", "o", "u"]
if vowel.find(c) == -1:
  print("consonant")
else:
  print("vowel")
Problem p03957 (python)

Fixed submission:
s = input()
if "C" in s:
    if "F" in s[s.index("C"):]:
        print("Yes")
        exit()
print("No")

Buggy submission (verdict: Runtime Error):
s = input()
if "F" in s[s.index("C"):]:
    print("Yes")
else:
    print("No")
Problem p03964 (python)

Fixed submission:
def ceil(x, y):
    if x % y == 0:
        return x // y
    else:
        return x // y + 1

n = int(input())
t = a = 1
for i in range(n):
    T, A = map(int, input().split())
    n = max(ceil(t, T), ceil(a, A))
    t = n * T
    a = n * A
print(t + a)

Buggy submission (verdict: Runtime Error):
def ceil(x, y):
    if x % y == 0:
        return x // y
    else:
        return x // y + 1

n = int(input())
t = a = 1
for i in range(n):
    T, A = map(int, input().split())
    n = max(ceil(t / T), ceil(a / A))
    t = n * T
    a = n * A
print(t + a)
Problem p04048 (python)

Fixed submission:
def solve(s, a, b):
    if a % b == 0:
        return s + ((a // b) * 2 - 1) * b
    if b % a == 0:
        return s + ((b // a) * 2 - 1) * a
    elif a > b:
        s += (a // b) * 2 * b
        return solve(s, a % b, b)
    else:
        s += (b // a) * 2 * a
        return solve(s, a, b % a)

n, x = map(int, input().split())
print(solve(n, n - x, x))

Buggy submission (verdict: Runtime Error):
def solve(s, a, b):
    if a % b == 0:
        return s + ((a // b) * 2 - 1) * b
    if b % a == 0:
        return s + ((b // a) * 2 - 1) * a
    if a == b:
        return s + a
    elif a > b:
        return solve(s + b * 2, a - b, b)
    else:
        return solve(s + a * 2, a, b - a)

n, x = map(int, input().split())
print(solve(n, n - x, x))

Buggy submission (verdict: Runtime Error):
def solve(s, a, b):
    if a == 1:
        return s + b * 2 - 1
    if b == 1:
        return s + a * 2 - 1
    if a == b:
        return s + a
    elif a > b:
        return solve(s + b * 2, a - b, b)
    else:
        return solve(s + a * 2, a, b - a)

n, x = map(int, input().split())
print(solve(n, n - x, x))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000000)

def solve(s, a, b):
    if a == b:
        return s + a
    elif a > b:
        return solve(s + b * 2, a - b, b)
    else:
        return solve(s + a * 2, a, b - a)


n, x = map(int, input().split())
print(solve(0, n - x, x) + n)

Buggy submission (verdict: Runtime Error):
def solve(s, a, b):
    if a == b:
        return s + a
    elif a > b:
        return solve(s + b * 2, a - b, b)
    else:
        return solve(s + a * 2, a, b - a)


n, x = map(int, input().split())
print(solve(0, n - x, x) + n)
Problem p02714 (python)

Fixed submission:
from collections import Counter


N = int(input())
S = input()

# 等間隔に並んでいる
count = 0

for start in range(N):
  offset = 1
  while True: 
      middle = start + offset
      end = middle + offset

      if end >= N:
          break

      s = {S[start], S[middle], S[end]}

      if len(s) == 3:
          count += 1

      offset += 1

c = Counter(S)

if len(c) != 3:
  print(0)
else:  
  x, y, z = c.values()
  print(x * y * z - count)

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


N = int(input())
S = input()

# 等間隔に並んでいる
count = 0

for start in range(N):
  offset = 1
  while True: 
      middle = start + offset
      end = middle + offset

      if end >= N:
          break

      s = {S[start], S[middle], S[end]}

      if len(s) == 3:
          count += 1

      offset += 1


x, y, z = Counter(S).values()

print(x * y * z - count)
Problem p03044 (python)

Fixed submission:
import sys
from collections import namedtuple


sys.setrecursionlimit(10**5)

Edge = namedtuple('Edge', 'to cost')

N = int(input())

# index と頂点の番号を合わせたいのでサイズを N + 1 に
colors = [0] * (N + 1)
vertexes = [[] for _ in range(N + 1)]

for _ in range(N - 1):
  u, v, w = map(int, input().split())
  # 無向グラフなので双方向にリンクする
  vertexes[u].append(Edge(v, w))
  vertexes[v].append(Edge(u, w))


def dfs(id, color):
  colors[id] = color
  for edge in vertexes[id]:
    if edge.cost % 2 != 0:
      if colors[edge.to] == color:
        return False
      if colors[edge.to] == 0 and not dfs(edge.to, -color):
        return False
    elif colors[edge.to] == 0:
      dfs(edge.to, color)
  return True

if dfs(1, 1):
  for color in colors[1:]:
    print(1 if color == 1 else 0)

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

Edge = namedtuple('Edge', 'to cost')

N = int(input())

# index と頂点の番号を合わせたいのでサイズを N + 1 に
colors = [0] * (N + 1)
vertexes = [[] for _ in range(N + 1)]

for _ in range(N - 1):
  u, v, w = map(int, input().split())
  # 無向グラフなので双方向にリンクする
  vertexes[u].append(Edge(v, w))
  vertexes[v].append(Edge(u, w))


def dfs(id, color):
  colors[id] = color
  for edge in vertexes[id]:
    if edge.cost % 2 != 0:
      if colors[edge.to] == color:
        return False
      if colors[edge.to] == 0 and not dfs(edge.to, -color):
        return False
    elif colors[edge.to] == 0:
      dfs(edge.to, color)
  return True

if dfs(1, 1):
  for color in colors[1:]:
    print(1 if color == 1 else 0)
Problem p03049 (python)

Fixed submission:
N = int(input())

ends_with_A = 0
starts_with_B = 0
both = 0

count = 0

for _ in range(N):
  s = input()
  count += s.count('AB')
  if s.endswith('A') and s.startswith('B'):
    both += 1
  elif s.endswith('A'):
    ends_with_A += 1
  elif s.startswith('B'):
    starts_with_B += 1

# 結合した文字が AXXXXXX or XXXXXXXB となるとき     
if ends_with_A + starts_with_B > 0:
  print(count + both + min(ends_with_A, starts_with_B))
else:  
  print(count + max(both - 1, 0) + min(ends_with_A, starts_with_B))

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

ends_with_A = 0
starts_with_B = 0
both = 0

count = 0

for _ in range(N):
  s = input()
  count += s.count('AB')
  if s.endswith('A') and s.startswith('B'):
    both += 1
  elif s.endswith('A'):
    ends_with_A += 1
  elif s.startswith('B'):
    starts_with_B += 1

if ends_with_A or starts_with_B:
  print(count + both + min(ends_with_A, starts_with_B))
else:  
  print(max(count + both + min(ends_with_A, starts_with_B) - 1), 0)
Problem p03087 (python)

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

cumulatives = [0] * (N + 1)

for i in range(N):
  if i == 0:
    cumulatives[1] = 0
  elif S[i - 1] == 'A' and S[i] == 'C':
    cumulatives[i + 1] = cumulatives[i] + 1
  else:
    cumulatives[i + 1] = cumulatives[i]
        
for _ in range(Q):
  l, r = map(lambda x: int(x) - 1, input().split())
  if l > 0 and S[l - 1] == 'A' and S[l] == 'C':
    # 右も閉区間なので+1
    print(cumulatives[r + 1] - cumulatives[l] - 1)
  else:
    print(cumulatives[r + 1] - cumulatives[l])

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

cumulatives = [0] * (N + 1)

for i in range(N):
  # 右隣にCが来るAの数を数える
  if S[i:i + 2] == 'AC':
    cumulatives[i + 1] = cumulatives[i] + 1
  else:
    cumulatives[i + 1] = cumulatives[i]

for i in range(Q):  
  l, r = map(lambda x: int(x) - 1, input().split())  # index 合わせる
  # 右隣の文字がCでない場合は条件を満たさないので右端を1左にずらす（開区間と考える）
  print(cumulatives[r] - cumulatives[l])
Problem p03160 (python)

Fixed submission:
import sys
from functools import lru_cache

sys.setrecursionlimit(10**6)

INF = sys.maxsize

N = int(input().strip())
h = [int(x) for x in input().split()]

@lru_cache()
def solve(i):
  if i >= N - 1:
    return 0
  return min(    
    solve(i + 1) + abs(h[i] - h[i + 1]) if i + 1 < N else INF,
    solve(i + 2) + abs(h[i] - h[i + 2]) if i + 2 < N else INF
  )
  
print(solve(0))

Buggy submission (verdict: Runtime Error):
import sys
from functools import lru_cache

INF = sys.maxsize

N = int(input().strip())
h = [int(x) for x in input().split()]

@lru_cache()
def solve(i):
  if i >= N - 1:
    return 0
  return min(    
    solve(i + 1) + abs(h[i] - h[i + 1]) if i + 1 < N else INF,
    solve(i + 2) + abs(h[i] - h[i + 2]) if i + 2 < N else INF
  )
  

print(solve(0))

Buggy submission (verdict: Runtime Error):
import sys
from functools import lru_cache

INF = sys.maxsize

N = int(input().strip())
h = [int(x) for x in input().split()]

@lru_cache(maxsize = 100000)
def solve(i):
  if i >= N - 1:
    return 0
  return min(    
    solve(i + 1) + abs(h[i] - h[i + 1]) if i + 1 < N else INF,
    solve(i + 2) + abs(h[i] - h[i + 2]) if i + 2 < N else INF
  )
  

print(solve(0))
Problem p03380 (python)

Fixed submission:
N = int(input())
numbers = [int(x) for x in input().split()]

numbers.sort()

n = numbers.pop()
r = min(numbers, key=lambda x: abs(x - n / 2))  # N

print(n, r)

Buggy submission (verdict: Runtime Error):
N = int(input())
numbers = [int(x) for x in input().split()]

numbers.sort()

# 最大値
n = numbers.pop()

# nCk を k < n の範囲で事前に計算する
memo = [0] * (n + 1)

# nC1 = n
memo[1] = n

for i in range(2, n):
  # memo[i] = memo[i - 1] * (n - i + 1) // i
  memo[i] = 2

max_value = 0
max_at = 0

for i in numbers:
  if max_value < memo[i]:
    max_value = memo[i]
    max_at = i

print(n, max_at)

Buggy submission (verdict: Runtime Error):
N = int(input())
numbers = [int(x) for x in input().split()]

numbers.sort()

# 最大値
n = numbers.pop()

# nCk を k < n の範囲で事前に計算する
memo = [0] * (n + 1)

# nC1 = n
memo[1] = n

for i in range(2, n):
  memo[i] = memo[i - 1] * (n - i + 1) // i

max_value = 0
max_at = 0

for i in numbers:
  if max_value < memo[i]:
    max_value = memo[i]
    max_at = i

print(n, max_at)

Buggy submission (verdict: Runtime Error):
N = int(input())
numbers = [int(x) for x in input().split()]

numbers.sort()

# 最大値
n = numbers.pop()

# nCk を k < n の範囲で事前に計算する
memo = [0] * n

# nC1 = n
memo[1] = n

for i in range(2, n):
  memo[i] = memo[i - 1] * (n - i + 1) // i

max_value = 0
max_at = 0

for i in numbers:
  if max_value < memo[i]:
    max_value = memo[i]
    max_at = i
          
print(n, max_at)
Problem p03473 (python)

Fixed submission:
x = int(input())

print(48 - x)

Buggy submission (verdict: Runtime Error):
from bisect import bisect, bisect_left


size = 10 ** 5 + 1

is_prime = [True] * size
is_prime[0] = is_prime[1] = False

# √size まで
for i in range(2, 317):
  j = 2 * i
  while j < size:
    is_prime[j] = False
    j += i

like_numbers = [
  i 
  for i, x in enumerate(is_prime)
  if x and (i + 1) % 2 == 0 and is_prime[(i + 1) // 2]
]

Q = int(input())

for _ in range(Q):
  l, r = map(int, input().split())
  if l == r:
    print(1 if l in like_numbers else 0)
  else:
    print(bisect(like_numbers, r) - bisect_left(like_numbers, l))