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

Fixed submission:
from collections import Counter
n = int(input())
if n == 1:
  print(1)
else:
  XY = tuple(tuple(map(int, input().split())) for _ in range(n))
  L = []
  for i in range(n-1):
    for j in range(i+1, n):
      x1, y1 = XY[i]
      x2, y2 = XY[j]
      L.append((x1-x2, y1-y2))
      L.append((x2-x1, y2-y1))
  C = Counter(L)
  ans = n - C.most_common()[0][1]
  print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
XY = tuple(tuple(map(int, input().split())) for _ in range(n))
L = []
for i in range(n-1):
  for j in range(i+1, n):
    x1, y1 = XY[i]
    x2, y2 = XY[j]
    L.append((x1-x2, y1-y2))
    L.append((x2-x1, y2-y1))
C = Counter(L)
ans = n - C.most_common()[0][1]
print(ans)
Problem p03008 (python)

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

n = int(input())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
def f(n):
  dp = list(range(n+1))
  for a, b in zip(A, B):
    for i in range(n+1):
      if i-a >= 0:
        dp[i] = max(dp[i], dp[i-a]+b)
  return max(dp)
m = f(n)
A, B = B, A
ans = f(m)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n = int(input())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
def f(n):
  dp = list(range(n+1))
  for a, b in zip(A, B):
    if b <= a:
      continue
    for i in range(n+1):
      if i-a >= 0:
        dp[i] = max(dp[i], dp[i-a]+b)
  return max(dp[n])
m = f(n)
A, B = B, A
ans = f(m)
print(ans)
Problem p03029 (python)

Fixed submission:
a, p = map(int, input().split())
print((3*a+p)//2)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
read = sys.stdin.read

def main():
  n, q = map(int, input().split())
  event = []
  stop = set()
  for _ in range(n):
    s, t, x = map(int, input().split())
    event.append((s-x, 1, x))
    event.append((t-x, -1, x))
  event.sort()
  event.append((float("inf"), 0, 0))
  D = list(map(int, read().split()))
  now = 0
  for t, b, x in event:
    while t > D[now]:
      if stop:
        print(min(stop))
      else:
        print(-1)
      now += 1
      if now == q:
        exit()
    if b == 1:
      stop.add(x)
    else:
      stop.remove(x)
      
if __name__ == "__main__":
  main()
Problem p03070 (python)

Fixed submission:
n = int(input())
A = tuple(int(input()) for _ in range(n))
S = sum(A)
mod = 998244353
ans = pow(3, n, mod)
cnt = 0
dp = [[0]*(S+1) for _ in range(n+1)]
dp[0][0] = 1
for i, a in enumerate(A):
  for k in range(S+1):
    if k >= a:
      dp[i+1][k] = dp[i][k]*2 + dp[i][k-a]
    else:
      dp[i+1][k] = dp[i][k]*2
    dp[i+1][k] %= mod
for k in range((S+1)//2, S+1):
  ans -= dp[n][k]*3
  ans %= mod
if S%2 == 0:
  dp = [0]*(S//2+1)
  dp[0] = 1
  for i, a in enumerate(A):
    for k in range(S//2, -1, -1):
      if k >= a:
        dp[k] += dp[k-a]
  ans += dp[S//2]*3
  ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = tuple(int(input()) for _ in range(n))
S = sum(A)
mod = 998244353
ans = pow(3, n, mod) - (pow(2, n, mod)-2)*3 - 3
cnt = 0
dp = [[[0]*(S+1) for j in range(n+2)] for i in range(n+1)]
dp[0][0][0] = 1
for i, a in enumerate(A):
  for j in range(i+2):
    for k in range(S+1):
      if k >= a and j:
        dp[i+1][j][k] = dp[i][j][k] + dp[i][j-1][k-a]
      else:
        dp[i+1][j][k] = dp[i][j][k]
for j in range(n-1):
  for k in range((S+1)//2, S+1):
    cnt += dp[n][j][k] * (pow(2, n-j, mod) - 2)
    cnt %= mod
ans -= cnt*3
ans %= mod
print(ans)
Problem p03096 (python)

Fixed submission:
import sys
read = sys.stdin.read
MOD = 10**9+7

n, *C = map(int, read().split())
dp = [0]*(n+1)
dp[0] = 1
idx = [-1]*(2*10**5+1)
for i, c in enumerate(C, 1):
  dp[i] = dp[i-1]
  if idx[c] != -1 and idx[c] < i-1:
    dp[i] += dp[idx[c]]
    dp[i] %= MOD
  idx[c] = i
print(dp[-1])

Buggy submission (verdict: Runtime Error):
import sys
read = sys.stdin.read
MOD = 10**9+7

n, *C = map(int, read().split())
dp = [0]*(n+1)
dp[0] = 1
idx = [-1]*(10**5+1)
for i, c in enumerate(C, 1):
  dp[i] = dp[i-1]
  if idx[c] != -1 and idx[c] < i-1:
    dp[i] += dp[idx[c]]
    dp[i] %= MOD
  idx[c] = i
print(dp[-1])
Problem p03110 (python)

Fixed submission:
n = int(input())
c = 0
for i in range(n):
  x, u = map(lambda x:float(x) if x.replace(".", "").isdigit() else x, input().split())
  if u == "BTC":
    x *= 380000
  c += x
print(c)

Buggy submission (verdict: Runtime Error):
n = int(input())
c = 0
for i in range(n):
  x, u = map(int, input().split())
  if u == "BTC":
    x *= 380000
  c += x
print(c)
Problem p03111 (python)

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

N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9
def dfs(cur, a, b, c):
  if cur == N:
    return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
  ret0 = dfs(cur + 1, a, b, c)
  ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
  ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
  ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
  return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit("10**7")

N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9
def dfs(cur, a, b, c):
  if cur == N:
    return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
  ret0 = dfs(cur + 1, a, b, c)
  ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
  ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
  ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
  return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit("10**7")

N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9
def dfs(cur, a, b, c):
  if cur == N:
  return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
  ret0 = dfs(cur + 1, a, b, c)
  ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
  ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
  ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
  return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))

Buggy submission (verdict: Runtime Error):
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9
def dfs(cur, a, b, c):
  if cur == N:
  return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
  ret0 = dfs(cur + 1, a, b, c)
  ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
  ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
  ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
  return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))
Problem p03148 (python)

Fixed submission:
import sys
input = sys.stdin.readline
from operator import itemgetter
import heapq
n, k = map(int, input().split())
TD = sorted([list(map(int, input().split())) for _ in range(n)], reverse=True, key=itemgetter(1))
L = [[] for _ in range(n+1)]
P = []
a = 0
cnt = 0
F = [-float("inf")]*(n+1)
for t, d in TD[:k]:
  L[t].append(d)
  if len(L[t]) == 1:
    a += 1
  cnt += d
F[a] = cnt
for i in range(1, n+1):
  while len(L[i]) > 1:
    heapq.heappush(P, L[i].pop())
now = k
for i in range(a, n):
  if len(P) == 0:
    break
  while now < n and L[TD[now][0]]:
    now += 1
  if now == n:
    break
  t, d = TD[now]
  L[t].append(d)
  F[i+1] = F[i] - heapq.heappop(P) + d
ans = 0
for i in range(a, n+1):
  ans = max(ans, F[i] + i*i)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from operator import itemgetter
import heapq
n, k = map(int, input().split())
TD = sorted([list(map(int, input().split())) for _ in range(n)], reverse=True, key=itemgetter(1))
L = [[] for _ in range(n+1)]
P = []
a = 0
cnt = 0
F = [-float("inf")]*(n+1)
for t, d in TD[:k]:
  L[t].append(d)
  if len(L[t]) == 1:
    a += 1
  cnt += d
F[a] = cnt
for i in range(1, n+1):
  while len(L[i]) > 1:
    heapq.heappush(P, L[i].pop())
now = k
for i in range(a, n):
  while now < n and L[TD[now][0]]:
    now += 1
  if now == n:
    break
  t, d = TD[now]
  L[t].append(d)
  F[i+1] = F[i] - heapq.heappop(P) + d
ans = 0
for i in range(a, n+1):
  ans = max(ans, F[i] + i*i)
print(ans)
Problem p03161 (python)

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float("inf")] * n
dp[0] = 0
for i in range(1, n):
  if i < k:
    dp[i] = min([ dp[j]+abs(h[j]-h[i]) for j in range(i) ])
  else:
    dp[i] = min( [ dp[i-j-1]+abs(h[i-j-1]-h[i]) for j in range(k) ] )
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
import sys

def main():
  n, k, *h = map(int, sys.stdin.read().split())
  dp = [float("inf")] * n
  dp[0] = 0
  for i in range(1, n):
    if i < k:
      dp[i] = min([ dpj+abs(hj-h[i]) for dpj, hj in zip(dp[:i], h[:i]) ])
    else:
      dp[i] = min( [ dpj+abs(hj-h[i]) for dpj, hj in zip(dp[i-k:k], h[i-k:k]) ] )
  print(dp[n-1])
  
if __name__ == "__main__":
  main()
Problem p03164 (python)

Fixed submission:
n, W = map(int, input().split())
wv = [ list(map(int, input().split())) for _ in range(n) ]
dp = [ [float("inf")]*(10**5+1) for _ in range(n+1) ]
dp[0][0] = 0
for i in range(n):
  w, v = wv[i]
  for j in range(10**5+1):
    if j < v:
      dp[i+1][j] = dp[i][j]
    else:
      dp[i+1][j] = min(dp[i][j], dp[i][j-v]+w)
ans = 0
for j in range(10**5+1):
  if dp[n][j] <= W:
    ans = j
print(ans)

Buggy submission (verdict: Runtime Error):
n, w = map(int, input().split())
l = [ list(map(int, input().split())) for _ in range(n) ]
dp = [ [0]*(w+1) for _ in range(n+1) ]
for i in range(1, n+1):
  for j in range(w+1):
    if j < l[i-1][0]:
      dp[i][j] = dp[i-1][j]
    else:
      dp[i][j] = max(dp[i-1][j-l[i-1][0]] + l[i-1][1], dp[i-1][j])
print(dp[n][w])
Problem p03169 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
A = tuple(map(int, input().split()))
C = [0]*3
for a in A:
  C[a-1] += 1
dp = [[[-1]*(n+1) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0] = 0
def f(i, j, k):
  if dp[i][j][k] != -1:
    return dp[i][j][k]
  res = 1
  if i:
    res += f(i-1, j, k)*(i/n)
  if j:
    res += f(i+1, j-1, k)*(j/n)
  if k:
    res += f(i, j+1, k-1)*(k/n)
  res /= (i+j+k)/n
  dp[i][j][k] = res
  return res
ans = f(C[0], C[1], C[2])
print(ans)

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

import sys
sys.setrecursionlimit(10**7)
n = int(input())

D = np.full((n+1, n+1, n+1, n+1), -1)
def dfs(a, b, c, d):
  if a == n:
    return 0
  if D[a, b, c, d] != -1:
    return D[a, b, c, d]
  rep = n
  if b != 0:
    rep += b * dfs(a+1, b-1, c, d)
  if c != 0:
    rep += c * dfs(a, b+1, c-1, d)
  if d != 0:
    rep += d * dfs(a, b, c+1, d-1)
  rep /= (n-a)
  D[a, b, c, d] = rep
  return rep

L = [0]*4
for a in map(int, input().split()):
  L[a] += 1
ans = dfs(*L)
print(ans)
Problem p03241 (python)

Fixed submission:
n, m = map(int, input().split())
for i in range(m//n, 0, -1):
  if m%i == 0:
    print(i)
    break

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
k = m//n
ans = 0
for i in range(1, int(m**0.5)+1):
  if m%i == 0:
    if i <= k:
      if i <= k:
      ans = max(ans, i)
    if m//i <= k:
      ans = max(ans, m//i)
print(ans)
Problem p03251 (python)

Fixed submission:
n, m, x, y = map(int, input().split())
X = sorted(list(map(int, input().split())))
Y = sorted(list(map(int, input().split())))
for i in range(X[-1], Y[0]):
  if x <= i < y:
    print("No War")
    exit()
print("War")

Buggy submission (verdict: Runtime Error):
n, m, x, y = map(int, input().split())
X = sorted(map(int, input().split()))
Y = sorted(map(int, input().split()))
for i in range(X[-1]:Y[0]):
  if x <= i < y:
    print("No War")
    exit()
print("War")
Problem p03316 (python)

Fixed submission:
s = input()
c = 0
for i in s:
  c += int(i)
if int(s) % c:
  print("No")
else:
  print("Yes")

Buggy submission (verdict: Runtime Error):
n = input()
k = list(map(int, list(n)))
s = sum(n)
n = int(n)
if n%k:
  print("No")
else:
  print("Yes")
Problem p03319 (python)

Fixed submission:
n, k = map(int, input().split())
print(-((1-n)//(k-1)))

Buggy submission (verdict: Runtime Error):
import math

n, k = map(int, input().split())
a = list(map(int, input().split()))
w = a.index(1)
if w<k or n-w-1<k:
  print( math.ceil((n-1)/(k-1)) )
else:
  print( math.seil((w)/(k-1)) + math.ceil((n-w-1)/(k-1)) )
Problem p03320 (python)

Fixed submission:
from fractions import Fraction
def S(n):
  res = 0
  while n:
    n, r = divmod(n, 10)
    res += r
  return res
k = int(input())
n = 1
for _ in range(k):
  print(n)
  n += 1
  m = Fraction(n, S(n))
  temp = n
  for d in range(len(str(n))+1):
    x = 10**(d+1)*(n//(10**(d+1))+1)-1
    if Fraction(x, S(x)) < m:
      m = Fraction(x, S(x))
      temp = x
  n = temp

Buggy submission (verdict: Runtime Error):
from fractions import Fraction
L = []
for i in range(1, 18):
    for j in range(1, 9*i+1):
        if (j-1)//9 >= i-1:
            temp = str(9-(-j%9)) + "9"*(i-1)
        else:
            temp = "1"
            t = j-1
            for rest in range(i-1, 0, -1):
                if t <= 9*(rest-1):
                    temp += "0"
                else:
                    temp += str(t-9*(rest-1))
                    t = 9*(rest-1)
        L.append((int(temp), j))
L.sort(reverse=True)
A = []
m = float("inf")
for l, k in L:
    if Fraction(l, k) <= m:
        A.append(l)
        m = Fraction(l, k)
k = int(input())
for i in range(k):
    print(A.pop())
Problem p03393 (python)

Fixed submission:
al = "abcdefghijklmnopqrstuvwxyz"
s = input()
if len(s)<26:
  for i in al:
    if i not in s:
      print(s+i)
      break
else:
  if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    k = []
    for i in range(25, 0, -1):
      k.append(s[i])
      if s[i-1] < s[i]:
        for j in sorted(k):
          if j > s[i-1]:
            print(s[:i-1] + j)
            exit()

Buggy submission (verdict: Runtime Error):
s = input()
if len(s)<26:
  for i in al:
    if i not in s:
      print(s+i)
      break
else:
  if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
  else:
    k = []
    for i in range(25, 0, -1):
      k.append(s[i])
      if s[i-1] < s[i]:
        for j in sorted(k):
          if j > s[i-1]:
            print(s[:i-1] + j)
            exit()
Problem p03424 (python)

Fixed submission:
n=input()
if "Y" in input():
  print("Four")
else:
  print("Three")

Buggy submission (verdict: Runtime Error):
n=input()
if "Y" in input():
  print("Four")
else:
  print("Three)
Problem p03469 (python)

Fixed submission:
s = input()
print(s[:3]+"8"+s[4:])

Buggy submission (verdict: Runtime Error):
s = input()
s[3] = "8"
print(s)
Problem p03476 (python)

Fixed submission:
q = int(input())
p = [False]*(10**5)
c = [0]*(10**5)
temp = [True]*(10**5)
temp[0] = False
temp[1] = False
for i in range(2, 10**5):
  c[i] = c[i-1]
  if temp[i]:
    temp[2*i::i] = [False]*(len(temp[i+i::i]))
    if temp[(i+1)//2] and i%2:
      c[i] += 1

for _ in range(q):
  l, r = map(int, input().split())
  print(c[r] - c[l-1])

Buggy submission (verdict: Runtime Error):
q = int(input())
p = [False]*(10**5)
c = [0]*(10**5)
temp = [True]*(N+1)
temp[0] = False
temp[1] = False
for i in range(2, 10**5):
  c[i] = c[i-1]
  if temp[i]:
    temp[2*i::i] = [False]*(len(temp[i+i::i]))
    if temp[(i+1)//2] and i%2:
      c[i] += 1

for _ in range(q):
  l, r = map(int, input().split())
  print(c[r] - c[l-1])
Problem p03477 (python)

Fixed submission:
a, b, c, d = map(int, input().split())
if a+b > c+d:
  print("Left")
elif a+b < c+d:
  print("Right")
else:
  print("Balanced")

Buggy submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
if a+b > c+d:
  print("Left")
elif a+b < c+d:
  print("Right")
wlaw:
  print("Balanced")
Problem p03543 (python)

Fixed submission:
s = input()
if s[0]==s[1]==s[2] or s[1]==s[2]==s[3]:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
s = input()
if s[0]==s[1]=s[2] or s[1]==s[2]==s[3]:
  print("Yes")
else:
  print("No")
Problem p03547 (python)

Fixed submission:
l = ["A", "B", "C", "D", "E", "F"]
a, b = map(str, input().split())
if l.index(a) < l.index(b):
  print("<")
elif l.index(a) > l.index(b):
  print(">")
else:
  print("=")

Buggy submission (verdict: Runtime Error):
l = ["A", "B", "C", "D", "E", "F"]
a, b = map(int, input().split())
if l.index(a) < l.index(b):
  print("<")
elif l.index(a) > l.index(b):
  print(">")
else:
  print("=")
Problem p03557 (python)

Fixed submission:
import bisect
from itertools import accumulate
n = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0
b_to_c = [0]*n
for i in range(n):
  b_to_c[i] = n - bisect.bisect_right(C, B[i])
Q = list(accumulate(b_to_c[::-1]))[::-1]
  
for i in A:
  t = bisect.bisect_right(B, i)
  if t < n:
    ans += Q[t]
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0
for i in A:
  for j in B[np.searchsorted(B, i, side="right"):]:
    ans += n - np.searchsorted(C, j, side="right")
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
n = int(input())
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
count = 0
for i in a:
  for j in range(bisect.bisect_right(b, i), n):
    count += n - bisect.bisect_right(c, b[j])

print(count)
Problem p03579 (python)

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

n, m = map(int, input().split())
G = [[] for _ in range(n)]
for _ in range(m):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  G[a].append(b)
  G[b].append(a)

C = [-1]*n
def is_bipartite(v, color):
  C[v] = color
  for nv in G[v]:
    if C[nv] != -1 and color == C[nv]:
      return False
    if C[nv] == -1:
      if not is_bipartite(nv, color ^ 1):
        return False
  return True

if is_bipartite(0, 0):
  b = C.count(0)
  w = n - b
  ans = b*w - m
else:
  ans = n*(n-1)//2 - m
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline

n, m = map(int, input().split())
G = [[] for _ in range(n)]
for _ in range(m):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  G[a].append(b)
  G[b].append(a)

C = [-1]*n
def is_bipartite(v, color):
  C[v] = color
  for nv in G[v]:
    if C[nv] != -1 and color == C[nv]:
      return False
    if C[nv] == -1:
      if not is_bipartite(nv, color ^ 1):
        return False
  return True

if is_bipartite(0, 0):
  b = C.count(0)
  w = n - b
  ans = b*w - m
else:
  ans = n*(n-1)//2 - m
print(ans)
Problem p03599 (python)

Fixed submission:
A, B, C, D, E, F = map(int, input().split())
Swater, sugar, percent = 100*A, 0, 0
for k in range(F//(100*A) + 1):
  for l in range(F//(100*B) + 1):
    if k == 0 and l == 0:
      continue
    M = k*A + l*B
    if 100 * M > F:
      continue
    for x in range(M*E//C + 1):
      for y in range(M*E//D + 1):
        S = C*x + D*y
        if 100*M+S > F:
          continue
        if S > M*E:
          continue
        t = 100*S / (100*M+S)
        if t > percent:
          percent = t
          Swater = 100*M+S
          sugar = S
print(Swater, sugar)

Buggy submission (verdict: Runtime Error):
A, B, C, D, E, F = map(int, input().split())
Swater, sugar, percent = 0, 0, 0
for k in range(F//(100*A) + 1):
  for l in range(F//(100*B) + 1):
    if k == 0 and l == 0:
      continue
    M = k*A + l*B
    if 100 * M > F:
      continue
    for x in range(M*E//C + 1):
      for y in range(M*E//D + 1):
        S = C*x + D*y
        if 100*M+S > F:
          continue
        if S > M*E:
          continue
        t = 100*S / (100*M+S)
        if t > percent:
          percent = t
          Swater = 100*M+S
          suger = S
print(Swater, suger)
Problem p03603 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n = int(input())
P = list(map(int, input().split()))
T = [[] for _ in range(n)]
for i, p in enumerate(P, 1):
  T[p-1].append(i)
X = list(map(int, input().split()))
D = [[-1]*n for _ in range(2)]
def dfs(color, v):
  if D[color][v] != -1:
    return D[color][v]
  l = len(T[v])
  x = X[v]
  dp = [[float("inf")]*(x+1) for _ in range(l+1)]
  dp[0][0] = 0
  for i, nv in enumerate(T[v]):
    for j in range(x+1):
      if j >= X[nv]:
        dp[i+1][j] = min(dp[i+1][j], dp[i][j-X[nv]]+dfs(color, nv))
      if j >= dfs(color^1, nv):
        dp[i+1][j] = min(dp[i+1][j], dp[i][j-dfs(color^1, nv)]+X[nv])
  res = min(dp[l])
  D[color][v] = res
  return res
ans = dfs(0, 0)
if ans == float("inf"):
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

INF = 2**30
n = int(input())
P = list(map(int, input().split()))
T = [[] for _ in range(n)]
for i, p in enumerate(P, 1):
  T[p-1].append(i)
X = list(map(int, input().split()))
D = [-1]*n
def dfs(v):
  if D[v] != -1:
    return D[v]
  l = len(T[v])
  x = X[v]
  dp = [INF]*(x+1)
  dp[0] = 0
  for nv in T[v]:
    k = [INF]*(x+1)
    for j in range(x+1):
      if j >= X[nv]:
        k[j] = min(k[j], dp[j-X[nv]]+dfs(nv))
      if j >= dfs(nv):
        k[j] = min(k[j], dp[j-dfs(nv)]+X[nv])
    dp = k.copy()
  res = min(dp)
  D[v] = res
  return res
ans = dfs(0)
if ans == INF:
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

INF = 2**30
n = int(input())
P = list(map(int, input().split()))
T = [[] for _ in range(n)]
for i, p in enumerate(P, 1):
  T[p-1].append(i)
X = list(map(int, input().split()))
D = [-1]*n
def dfs(v):
  if D[v] != -1:
    return D[v]
  l = len(T[v])
  x = X[v]
  dp = [INF]*(x+1)
  dp[0] = 0
  for i, nv in enumerate(T[v]):
    k = [INF]*(x+1)
    for j in range(x+1):
      if j >= X[nv]:
        k[j] = min(k[j], dp[j-X[nv]]+dfs(nv))
      if j >= dfs(nv):
        k[j] = min(k[j], dp[j-dfs(nv)]+X[nv])
    dp = k.copy()
  res = min(dp)
  D[v] = res
  return res
ans = dfs(0)
if ans == INF:
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")
Problem p03605 (python)

Fixed submission:
if "9" in input():
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
if 9 in input():
  print("Yes")
else:
  print("No")
Problem p03616 (python)

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

x = int(input())
k = int(input())
R = [(_r, i%2) for i, _r in enumerate(map(int, input().split()))]
n = int(input())
TA = [list(map(int, input().split())) for _ in range(n)]
T, A = zip(*TA)
L = [None]*n
b = 0
for i, t in enumerate(T, 1):
  R.append((t, -i))
R.sort()
dx = 1
l, r, p, q = 0, x, 0, x
for _r, i in R:
  d = _r-b
  b = _r
  if dx == 1:
    if d <= p:
      p -= d
      q -= d
    elif d < q:
      q -= d
      l = r-q
      p = 0
    else:
      l = 0
      r = 0
      p = 0
      q = 0
  else:
    if d <= x-q:
      p += d
      q += d
    elif d < x-p:
      p += d
      r = l+(x-p)
      q = x
    else:
      l = x
      r = x
      p = x
      q = x
  if i >= 0:
    dx = i
  else:
    a = A[-i-1]
    if a < l:
      res = p
    elif a <= r:
      res = (a-l)+p
    else:
      res = q
    L[-i-1] = res
print(*L, sep="\n")

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

x = int(input())
k = int(input())
R = [(_r, i%2) for i, _r in enumerate(map(int, input().split()))]
n = int(input())
TA = [list(map(int, input().split())) for _ in range(n)]
T, A = zip(*TA)
L = [None]*n
b = 0
for i, t in enumerate(T, 1):
  R.append((t, -i))
R.sort()
dx = 1
l, r, p, q = 0, x, 0, x
for _r, i in R:
  d = _r-b
  b = _r
  if dx == 1:
    if d <= p:
      p -= d
      q -= d
    elif d < q:
      q -= d
      l = r-q
      p = 0
    else:
      l = 0
      r = 0
      p = 0
      q = 0
  else:
    if d <= x-q:
      p += d
      q += d
    elif d < x-p:
      p += d
      r = l+(x-p)
      q = x
    else:
      l = x
      r = x
      p = x
      q = x
  if i >= 0:
    dx = i
  else:
    a = A[-i-1]
    if a < l:
      res = p
    elif a <= r:
      res = (a-l)+p
    else:
      res = q
    L[-i-1] = res
print(*L, sep="\n")