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

Fixed submission:
N = int(input())
act = [list(map(int,input().split())) for _ in range(N)]
dp = [[0]*3 for _ in range(N+1)]

for i in range(N):
  dp[i+1][0] = max(dp[i][1], dp[i][2]) + act[i][0]
  dp[i+1][1] = max(dp[i][0], dp[i][2]) + act[i][1]
  dp[i+1][2] = max(dp[i][0], dp[i][1]) + act[i][2]
  
print(max(dp[N]))

Buggy submission (verdict: Runtime Error):
N = int(input())
act = [list(map(int,input().split())) for _ in range(N)]
dp = [[0]*3 for _ in range(N+1)]

for i in range(1,N+1):
  dp[i+1][0] = max(dp[i][1], dp[i][2]) + act[i][0]
  dp[i+1][1] = max(dp[i][0], dp[i][2]) + act[i][1]
  dp[i+1][2] = max(dp[i][0], dp[i][1]) + act[i][2]
  
print(max(dp[N]))

Buggy submission (verdict: Runtime Error):
N = int(input())
act = [tuple(map(int,input().split())) for _ in range(N)]
dp = [[0]*3 for _ in range(N+1)]

for i in range(1,N+1):
  dp[i+1][0] = max(dp[i][1], dp[i][2]) + act[i][0]
  dp[i+1][1] = max(dp[i][0], dp[i][2]) + act[i][1]
  dp[i+1][2] = max(dp[i][0], dp[i][1]) + act[i][2]
  
print(max(dp[N]))

Buggy submission (verdict: Runtime Error):
N = int(input())
act = [tuple(map(int,input().split())) for _ in range(N)]
dp = [[0]*N for _ in range(N+1)]

for i in range(1,N+1):
  for j in range(3):
    for k in range(3):
      if j != k:
        dp[i][j] = max(dp[i][j], dp[i-1][k] + act[i-1][j])

print(max(dp[N]))

Buggy submission (verdict: Runtime Error):
N = int(input())
act = [tuple(map(int,input().split())) for _ in range(N)]
dp = [[0]*N for _ in range(N+1)]

for i in range(1,N+1):
  for j in range(3):
    for k in range(3):
      if j != k:
        dp[i][j] = max(dp[i][j], dp[i-1][k] + act[i-1][j])

print(max(dp[N]))

Buggy submission (verdict: Runtime Error):
N = int(input())
act = [tuple(map(int,input().split())) for _ in range(N)]
dp = [[0]*N for _ in range(N+1)]

for i in range(1,N+1):
  for j in range(3):
    for k in range(3):
      if j != k:
        dp[i][j] = max(dp[i][j], dp[i-1][k] + act[i-1][j])

print(max(dp[N]))
Problem p03164 (python)

Fixed submission:
N, W = map(int, input().split())
w = []
v = []
for _ in range(N):
  wi, vi = map(int, input().split())
  w.append(wi)
  v.append(vi)
dp = [[float('inf')]*(max(v)*N+1) for _ in range(N+1)]
dp[0][0] = 0

for i in range(N):
  for sum_v in range(max(v)*N+1):
    if v[i] - sum_v > 0:
      dp[i+1][sum_v] = dp[i][sum_v]
    else:
      dp[i+1][sum_v] = min(dp[i][sum_v], dp[i][sum_v - v[i]] + w[i])

ans = 0
for sum_v in range(max(v)*N+1):
  if dp[N][sum_v] <= W:
    ans = sum_v
print(ans)

Buggy submission (verdict: Runtime Error):
N, W = map(int, input().split())
w = []
v = []
for _ in range(N):
  wi, vi = map(int, input().split())
  w.append(wi)
  v.append(vi)
dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(N):
  for sum_w in range(W+1):
    if sum_w-w[i] >= 0:
      dp[i+1][sum_w] = max(dp[i][sum_w], dp[i][sum_w-w[i]]+v[i])
    else:
      dp[i+1][sum_w] = dp[i][sum_w]

print(dp[N][W])
Problem p03752 (python)

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

ans = float('inf')
for bit in range(1<<(n-1)):
  cand = [0]*(n-1)
  for i in range(n-1):
    if bit & 1<<i: cand[i] = 1
  if cand.count(1) != k-1: continue
  cost = 0
  mx = a[0]
  for i in range(1, n):
    if cand[i-1]:
      if a[i] <= mx:
        cost += mx-a[i]+1
        mx += 1
    mx = max(mx, a[i])
  ans = min(ans, cost)
print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))

ans = float('inf')
for bit in range(1<<(n-1)):
  cand = [0]*(n-1)
  for i in range(n-1):
    if bit & 1<<i: cand[i] = 1
  if cand.count(1) != k-1: continue
  cost = 0
  mx = a[0]
  for i in range(1, n):
    if cand[i-1]:
      if a[i] <= mx:
        cost += mx-a[i]+1
        mx += 1
    mx = max(mx, a[j])
  ans = min(ans, cost)
print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))

ans = float('inf')
for bit in range(1<<(n-1)):
  cost = 0
  cand = [0]*(n-1)
  for i in range(n-1):
    if bit & 1<<i: cand[i] = 1
  if cand.count(1) != k-1: continue
  mx = a[0]
  for i in range(1, n):
    if cand[i-1]:
      if a[i] <= mx:
        cost += prev-a[i]+1
        ms += 1
    mx = max(mx, a[j])
  ans = min(ans, cost)
print(ans)
Problem p03471 (python)

Fixed submission:
n, total = map(int, input().split(" "))

x = -1
y = -1
z = -1

for x_tmp in range(0, n + 1):
    for y_tmp in range(0, (n - x_tmp) + 1):
        z_tmp = n - (x_tmp + y_tmp) if n >= (x_tmp + y_tmp) else 0
        if total == (x_tmp * 10000 + y_tmp * 5000 + z_tmp * 1000):
            x, y, z = x_tmp, y_tmp, z_tmp

print(x, y, z, sep = " ")

Buggy submission (verdict: Runtime Error):
n, total = map(int, input().split(" "))

x = -1
y = -1
z = -1

num_max_10k = total // 10000
num_max_5k = total // 5000
num_max_1k = total // 1000

for num_10k in range (num_max_10k + 1):
    for num_5k in range(num_max_5k + 1):
        if (num_10k + num_5k >= n):
            num_1k = 0
        else:
            num_1k = n - (num_10k + num_5k)

        #print(num_10k, num_5k, num_1k, sep=" ")
        if (total == (sum_10k * 10000 + sum_5k * 5000 + sum_1k * 1000)
            and n == (num_10k + num_5k + num_1k)):
            x, y, z = num_10k, num_5k, num_1k

print(x, y, z, sep=" ")
Problem p03574 (python)

Fixed submission:
def replace(s, r, c):
    for row in range(r - 1, r + 2):
        for column in range(c - 1, c + 2):
            if row < 0 or len(s) <= row:
                continue

            if column < 0 or len(s[row]) <= column:
                continue

            value = s[row][column]
            if value != "#":
                value += 1
                s[row][column] = value


h, w = map(int, input().split(" "))
s = []
for _ in range(h):
    row = input()
    tmp = []
    for i in range(w):
        tmp.append(row[i] if row[i] == "#" else 0)
    s.append(tmp)

for row in range(h):
    for column in range(w):
        if s[row][column] == "#":
            replace(s, row, column)

for row in range(h):
    res = ""
    for column in range(w):
        res += str(s[row][column])
    print(res)

Buggy submission (verdict: Runtime Error):
def replace(s, r, c):
    for row in range(r - 1, r + 2):
        for column in range(c - 1, c + 2):
            value = s[row][column]
            if value != "#":
                value = value + 1 if value != "." else 1
                s[row][column] = value

h, w = map(int, input().split(" "))
s = []
for _ in range(h):
    row = input()
    tmp = []
    for i in range(w):
        tmp.append(row[i])
    s.append(tmp)

for row in range(h):
    for column in range(w):
        if s[row][column] == "#":
            replace(s, row, column)

for row in range(h):
    res = ""
    for column in range(w):
        res += str(s[row][column])
    print(res)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split(" "))
s = []
for _ in range(h):
    row = input()
    tmp = []
    for i in range(w):
        tmp.append(row[i])
    s.append(tmp)

for row in range(h):
    for column in range(w):
        if s[row][column] == "#":
            replace(s, row, column)

for row in range(h):
    res = ""
    for column in range(w):
        res += str(s[row][column])
    print(res)
Problem p03680 (python)

Fixed submission:
n = int(input())
buttons = [0]
target_index = 0
for _ in range(n):
    buttons.append(int(input()))

count = 0
prev_index = 1
while count < n:
    if prev_index < 1 or len(buttons) <= prev_index:
        count = -1
        break

    next_index = buttons[prev_index]
    count += 1
    if next_index == 2:
        break
    else:
        prev_index = next_index

print(count if count < n else -1)

Buggy submission (verdict: Runtime Error):
n = int(input())
buttons = [0]
target_index = 0
for _ in range(n):
    num = int(input())
    buttons.append(num)

count = 0
next_index = 2
while count < n:
    if next_index < 1 or len(buttons) - 1 <= next_index:
        count = -1
        break

    prev_index = buttons.index(next_index)
    count += 1
    if prev_index == 1:
        break
    else:
        next_index = prev_index

print(count if count < n else -1)

Buggy submission (verdict: Runtime Error):
n = int(input())
buttons = [0]
target_index = 0
for i in range(n):
    num = int(input())
    buttons.append(num)

count = 0
next_index = 2
while count < n:
    if next_index < 1 or len(buttons) - 1 <= next_index:
        count = -1
        break

    prev_index = buttons.index(next_index)
    count += 1
    if prev_index == 1:
        break
    else:
        next_index = prev_index

print(count if count < n else -1)

Buggy submission (verdict: Runtime Error):
n = int(input())
buttons = [0]
target_index = 0
for i in range(n):
    num = int(input())
    buttons.append(num)

count = 0
next_index = 2
while count < n:
    if len(buttons) - 1 <= next_index <= 0:
        count = -1
        break

    prev_index = buttons.index(next_index)
    count += 1
    if prev_index == 1:
        break
    else:
        next_index = prev_index

print(count if count < n else -1)

Buggy submission (verdict: Runtime Error):
n = int(input())
buttons = [0]
target_index = 0
for i in range(n):
    num = int(input())
    buttons.append(num)

count = 0
next_index = 2
while count < n:
    if len(buttons) - 1 <= next_index:
        count = -1
        break

    prev_index = buttons.index(next_index)
    count += 1
    if prev_index == 1:
        break
    else:
        next_index = prev_index

print(count if count < n else -1)

Buggy submission (verdict: Runtime Error):
n = int(input())
buttons = [0]
target_index = 0
for i in range(n):
    num = int(input())
    buttons.append(num)

count = 0
next_index = 2
while count < n:
    if len(buttons) - 1 < next_index:
        count = -1
        break

    prev_index = buttons.index(next_index)
    count += 1
    if prev_index == 1:
        break
    else:
        next_index = prev_index

print(count if count < n else -1)

Buggy submission (verdict: Runtime Error):
n = int(input())
buttons = [0]
target_index = 0
for i in range(n):
    num = int(input())
    buttons.append(num)

count = 0
next_index = 2
while count < n:
    prev_index = buttons.index(next_index)
    count += 1
    if prev_index == 1:
        break
    else:
        next_index = prev_index

print(count if count < n else -1)
Problem p03730 (python)

Fixed submission:
a, b, c = map(int, input().split())
res = False
for i in range(a, a * b + 1, a):
    if i % b == c:
        res = True

print("YES" if res == True else "NO")

Buggy submission (verdict: Runtime Error):
import math

a, b, c = map(int, input().split())
res = False
n = abs(b * c // (b - a))
for i in range(n -1, n + 1 + 1):
    if a * i % b == c:
        res = True

print("YES" if res == True else "NO")

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
res = False
n = abs(b * c // (b - a))
for i in range(n -1, n + 1 + 1):
    if a * i % b == c:
        res = True

print("YES" if res == True else "NO")
Problem p02756 (python)

Fixed submission:
# -*- coding: utf-8 -*-
s = str(input())
q = int(input())  
st = s
sth = s
sth2 = ""
stm = ""
stm2 = ""
count = 0
flagh = 0
flagm = 0
for i in range(q):
  k = input().split()
  if(k[0] == '1'):
    count = (count + 1) % 2
  else:
    c = count - 2
    d = int(k[1]) 
    e = k[2]
    if(c + d != 0):
      sth = e + sth
      if(len(sth) > 5000 and flagh == 0):
        flagh = 1
        sth2 = sth
        sth = ""
    else:
      stm = stm + e
      if(len(stm) > 5000 and flagm == 0):
        flagm = 1
        stm2 = stm
        stm = ""
      

st = sth + sth2 + stm2 + stm
if(count == 1):
  st = st[::-1]
  
print(st)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
s = str(input())
q = int(input())  
st = s
sth = s
sth2 = ""
stm = ""
stm2 = ""
count = 0
for i in range(q):
  k = input().split()
  if(k[0] == '1'):
    count = (count + 1) % 2
  else:
    c = count - 2
    d = int(k[1]) 
    e = k[2]
    if(c + d != 0):
      sth = e + sth
      if(len(sth) > 500):
        sth2 = sth
        sth = ""
    else:
      stm = stm + e
      if(len(stm) > 500):
        stm2 = stm
        stm = ""
      

st = sth + sth2 + stm2 + stm
if(count == 1):
  st = st[::-1]
  
print(st

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
s = str(input())
q = int(input())
l = []
for i in range(q):
  qy = input().split()
  l.append(qy)
  
st = s
count = 0
for i in range(q):
  k = l[i][0]
  if(k == '1'):
    count += 1
  elif(k == '2'):
    c = count
    d = int(l[i][1])
    e = i[i][2]
    if((c + d) % 2 == 1):
      st = e + st
    elif((c + d) % 2 == 0):
      st = st + e

if(count % 2 == 1):
  st = st[::-1]
      
print(st)
Problem p02765 (python)

Fixed submission:
#coding:utf-8

n,k = map(int,input().split())

if(n < 10):
  k = k + 100 * (10 - n)
  
print("{}".format(k))

Buggy submission (verdict: Runtime Error):
#coding:utf-8

n,k = map(int,input()split())

if(n < 10):
  k = k + 100 * (10 - n)
  
print("{}".format(k))
Problem p02748 (python)

Fixed submission:
def main():
    _, _, m_num = map(int, input().split())
    a = [int(s) for s in input().split()]
    b = [int(s) for s in input().split()]

    min_price = min(a) + min(b)

    m = []
    for _ in range(m_num):
        x, y, c = map(int, input().split())
        price = a[x - 1] + b[y - 1] - c
        min_price = min(min_price, price)
    
    print(min_price)

main()

Buggy submission (verdict: Runtime Error):
def main():
    _, _, m_num = map(int, input().split())
    a = [int(s) for s in input().split()]
    b = [int(s) for s in input().split()]

    min_price = min(a) + min(b)

    m = []
    for _ in range(m_num):
        price = a[x - 1] + b[y - 1] - c
        print(x, y, c, price)
        min_price = min(min_price, price)
    
    print(min_price)

main()
Problem p03044 (python)

Fixed submission:
from collections import defaultdict, deque

def main():
    n = int(input())
    edges = defaultdict(list)

    for _ in range(n - 1):
        u, v, w = map(int, input().split())
        edges[u-1].append((v - 1, w))
        edges[v-1].append((u - 1, w))
    
    vertexes = solve(edges, n)
    for v in vertexes:
        print(v)

def solve(edges, n):
    vertexes = [None for _ in range(n)]
    vertexes[0] = 0

    q = deque()
    q.append(0)

    while q:
        u = q.popleft()

        for v, w in edges[u]:
            if vertexes[v] is not None:
                continue
            if w % 2 == 0:
                vertexes[v] = vertexes[u]
            else:
                vertexes[v] = 1 - vertexes[u]
            q.append(v)
    
    return vertexes
    
main()

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

def main():
    n = int(input())
    edges = defaultdict(list)

    for _ in range(n - 1):
        u, v, w = map(int, input().split())
        edges[u-1].append((v - 1, w))
        edges[v-1].append((u - 1, w))
    
    vertexes = [None for _ in range(n)]
    vertexes[0] = 0
    traverse(0, edges, vertexes)

    for v in vertexes:
        print(v)

def traverse(u, edges, vertexes):
    for e in edges[u]:
        v, w = e
        if vertexes[v] is not None:
            continue

        if w % 2 == 0:
            vertexes[v] = vertexes[u]
        else:
            vertexes[v] = 1 - vertexes[u]
        traverse(v, edges, vertexes)

main()
Problem p03106 (python)

Fixed submission:
def main():
    a, b, k = map(int, input().split())
    print(solve(a, b, k))

def solve(a, b, k):
    n = 0
    for i in range(100, 0, -1):
        if a % i == 0 and b % i == 0:
            n += 1
            if n == k:
                return i

main()

Buggy submission (verdict: Runtime Error):
import itertools
import math

def main():
    a, b, k = map(int, input().split())
    print(solve(a, b, k))

def solve(a, b, k):
    c = math.gcd(a, b)
    n = 0

    for i in range(c, 0, -1):
        if a % i == 0 and b % i == 0:
            n += 1
            if n == k:
                return i

main()
Problem p03239 (python)

Fixed submission:
n, limit = map(int, input().split())
x = []
for _ in range(n):
  c, t = map(int, input().split())
  x.append((c, t))

y = min((c for c, t in x if t <= limit), default=0)
if y:
  print(y)
else:
  print('TLE')

Buggy submission (verdict: Runtime Error):
n, limit = map(int, input().split())
x = []
for _ in range(n):
  c, t = map(int, input().split())
  x.append((c, t))

y = min(c for c, t in x if t <= limit)
print(y)
Problem p03240 (python)

Fixed submission:
from collections import namedtuple

Point = namedtuple('Point', ('x', 'y', 'h'))

def main():
    n = int(input())
    points = [read_point() for _ in range(n)]
    print(*solve(points))

def solve(points):
    for p in points:
        if p.h != 0:
            base = p
            break

    for x in range(0, 101 + 1):
        for y in range(0, 100 + 1):
            h = base.h + abs(base.x - x) + abs(base.y - y)
            for p in points:
                ph = max(h - abs(x - p.x) - abs(y - p.y), 0)
                if ph != p.h:
                    break
            else:
                return Point(x, y, h)

def read_point():
    x, y, h = map(int, input().split())
    return Point(x, y, h)

main()

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

Point = namedtuple('Point', ('x', 'y', 'h'))

def main():
    n = int(input())
    points = [read_point() for _ in range(n)]
    print(*solve(points))

def solve(points):
    for x in range(0, 101 + 1):
        for y in range(0, 100 + 1):
            h = points[0].h + abs(points[0].x - x) + abs(points[0].y - y)
            for p in points[1:]:
                h2 = p.h + abs(p.x - x) + abs(p.y - y)
                if (p.h > 0 and h2 != h) or h2 > h:
                    break
            else:
                return Point(x, y, h)

def read_point():
    x, y, h = map(int, input().split())
    return Point(x, y, h)

main()

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

Point = namedtuple('Point', ('x', 'y', 'h'))

def main():
    n = int(input())
    points = [read_point() for _ in range(n)]
    print(*solve(points))

def solve(points):
    for x in range(0, 101 + 1):
        for y in range(0, 100 + 1):
            h = points[0].h + abs(points[0].x - x) + abs(points[0].y - y)
            for p in points[1:]:
                h2 = p.h + abs(p.x - x) + abs(p.y - y)
                if h != h2:
                    break
            else:
                return Point(x, y, h)

def read_point():
    x, y, h = map(int, input().split())
    return Point(x, y, h)

main()
Problem p03243 (python)

Fixed submission:
n = int(input())
x = (n - 1) // 111 + 1
print(x * 111)

Buggy submission (verdict: Runtime Error):
n = input()
x = (n - 1) // 111 + 1
print(x * 111)
Problem p03408 (python)

Fixed submission:
from collections import Counter

n = int(input())
blue = Counter(input() for _ in range(n))
m = int(input())
red = Counter(input() for _ in range(m))
c = (blue - red).most_common(1)

if c:
  print(max(c[0][1], 0))
else:
  print(0)

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

n = int(input())
blue = Counter(input() for _ in range(n))
m = int(input())
red = Counter(input() for _ in range(m))
c = (blue - red).most_common(1)

print(max(c[0][1], 0))
Problem p03434 (python)

Fixed submission:
input()
c = list(map(int, input().split()))
c.sort(reverse=True)
a = sum(c[::2])
b = sum(c[1::2])
print(a - b)

Buggy submission (verdict: Runtime Error):
input()
c = list(map(int, input().split()))
c.sort(reverse=True)
a = sum(c[::2])
b = sun(c[1::2])
print(a - b)
Problem p03448 (python)

Fixed submission:
def main():
    a, b, c, x = [int(input()) for _ in range(4)]
    coins = ((500, a), (100, b), (50, c))

    print(solve(coins, x))

def solve(coins, x):
    if len(coins) == 1:
        if coins[0][0] * coins[0][1] >= x and x % coins[0][0] == 0:
            return 1
        else:
            return 0

    t = 0
    for i in range(coins[0][1] + 1):
        r = x - coins[0][0] * i
        if r >= 0:
            t += solve(coins[1:], r)

    return t

main()

Buggy submission (verdict: Runtime Error):
def main():
    a, b, c, x = [int(input()) for _ in range(4)]
    coins = ((500, a), (100, b), (50, c))

    print(solve(coins, x))

def solve(coins, x):
    if len(coins) == 1:
        if coins[0][0] * coins[0][1] >= x and x % coins[0][1] == 0:
            return 1
        else:
            return 0

    t = 0
    for i in range(coins[0][1] + 1):
        r = x - coins[0][0] * i
        if r >= 0:
            t += solve(coins[1:], r)

    return t

main()
Problem p03474 (python)

Fixed submission:
def isdigit(s):
  return all(c in '0123456789' for c in s)

def check(s, a, b):
  if len(s) != a + b + 1:
    return False
  
  if not isdigit(s[:a]):
    return False
  
  if s[a] != '-':
    return False
  
  if not isdigit(s[-b:]):
    return False
  
  return True
  
a, b = map(int, input().split())
s = input()
if check(s, a, b):
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
def issigit(s):
  return all(c in '0123456789' for c in s)

def check(s, a, b):
  if len(s) != a + b + 1:
    return False
  
  if not isdigit(s[:a]):
    return False
  
  if s[a] != '-':
    return False
  
  if not isdigit(s[-b:]):
    return False
  
  return True
  
a, b = map(int, input().split())
s = input()
if check(s, a, b):
  print('Yes')
else:
  print('No')