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

Fixed submission:
n, a, b = map(int, input().split())
s = n // (a + b)
t = n % (a + b)
print(s * a + min(t, a))

Buggy submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
s = ""
while len(s) < n:
  s += "b" * a + "r" * b
print(s[:n].count("b"))

Buggy submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
s = ""
whlie len(s) < n:
  s += "b" * a + "r" * b
print(s[:n+1].count("b"))
Problem p02759 (python)

Fixed submission:
n = int(input())
print((n // 2) + (n % 2) )

Buggy submission (verdict: Runtime Error):
n = input()
print((n // 2) + (n % 2))
Problem p02771 (python)

Fixed submission:
print("Yes" if len(set(input().split())) == 2 else "No")

Buggy submission (verdict: Runtime Error):
print "Yes" if len(set(input().split())) == 2 else "No"
Problem p02829 (python)

Fixed submission:
a = int(input())
b = int(input())
c = 6 - a - b
print(c)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
n = [1, 2, 3].remove(a).remove(b)
print(n[0])
Problem p02836 (python)

Fixed submission:
s = input()
t = 0
for i in range(len(s)):
  if s[i] != s[::-1][i]:
    t += 1
print(t//2)

Buggy submission (verdict: Runtime Error):
s = input()
t = 0
for i in range(len(s)):
  if s[i] != s[::-1][i]:
    t += 1
ptint(t//2)

Buggy submission (verdict: Runtime Error):
s = input()
t = 0
for i in range(len(s)):
  if s[i] != s[::-1][i]:
    t += 1
ptint(t)
Problem p02916 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = sum(map(int, input().split()))
c = list(map(int, input().split()))
s = 0
for i in range(n-1):
  if a[i+1] - a[i] == 1:
    s += c[a[i] - 1]
print(b + s)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = map(int, input().split())
b = sum(map(int, input().split()))
c = map(int, input().split())
s = 0
for i in range(n-1):
  if a[i+1] - a[i] == 1:
    s += c[a[i] - 1]
print(b + s)
Problem p02933 (python)

Fixed submission:
a = int(input())
b = input()
print("red" if a < 3200 else b)

Buggy submission (verdict: Runtime Error):
a, s = input().split()
print(s if int(a) < 3200 else "red")
Problem p03012 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
s = []
for i in range(1, n):
  s.append(abs(sum(a[:i]) - sum(a[i:])))
print(min(s))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
s = []
for i in range(1, n):
  s.append(abs(a[:i] - a[i:]))
print(min(s))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
s = []
for i in range(1, n):
  s.append(abs(a[:i] - a[i:]))
print(max(s))
Problem p03075 (python)

Fixed submission:
a = []
for i in range(5):
  a.append(int(input()))
a.sort()
j = int(input())
k = a[4] - a[0]
if k <= j:
  print("Yay!")
else:
  print(":(")

Buggy submission (verdict: Runtime Error):
a = []
for i in range(5):
  a.append(int(input()))
a.sort()
j = int(input)
k = a[4] - a[0]
if k <= j:
  print("Yay!")
else:
  print(":(")
Problem p03631 (python)

Fixed submission:
a = input()
print("Yes" if a == a[::-1] else "No")

Buggy submission (verdict: Runtime Error):
print("Yes" if input() == reversed((input()) else "No")
Problem p03774 (python)

Fixed submission:
n, m = map(int, input().split())
p = [list(map(int, input().split())) for i in range(n + m)]
for a, b in p[:n]:
  x = [abs(a - c) + abs(b - d) for c, d in p[n:]]
  print(x.index(min(x)) + 1)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = [input().split() for i in range(n)]
c = []
for i in range(n):
  for j in range(m):
    b = input().split()
    c.append(abs(a[i][0] - b[0]) + abs(a[i][1] - b[1]))
  print(c.index(min(c)))
Problem p03775 (python)

Fixed submission:
n = int(input())
for i in range(int(n**0.5), 0, -1):
  if n % i == 0:
    print(len(str(n//i)))
    break

Buggy submission (verdict: Runtime Error):
n = int(input())
s = []
for i in range(1, n//2 + 1):
  if n % i == 0:
    a = max(len(str(i)), len(str(n//i)))
    s.append(a)
print(min(s))

Buggy submission (verdict: Runtime Error):
n = int(input())
s = 0
for i in range(1, n//2 + 1):
  if n % i == 0:
    s.append(max(len(str(i)), len(str(n//i))))
print(min(s))
Problem p03803 (python)

Fixed submission:
a, b = map(int, input().split())
if a == 1:
  a = 14
if b == 1:
  b = 14
if a > b:
  print("Alice")
elif a < b:
  print("Bob")
else:
  print("Draw")

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
for i in a:
  for j in b:
    if j not in i:
      print("No")
      exit()
print("Yes")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split()
if a == b:
  print("Draw")
elif a == 1 or a > b >= 2:
    print("Alice")
elif b == 1 or b > a >= 2:
    print("Bob")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split()
if a == b:
  print("Draw")
elif a == 1 or (a > b >= 2):
    print("Alice")
else:
    print("Bob")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split()
if a == b:
  print("Draw")
elif a == 1 or a > b >= 2:
    print("Alice")
else:
    print("Bob")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split()
if a == b:
  print("Draw")
elif a == 1 or a > b:
    print("Alice")
else:
    print("Bob")
Problem p04005 (python)

Fixed submission:
s = sorted(list(map(int, input().split())))
a = s.pop(-1)
b = a // 2
c = a - (a//2)
d = s[0] * s[1]
print(abs(d * b - d * c))

Buggy submission (verdict: Runtime Error):
s = sorted(list(map(int, input().split())))
a = s.pop(-1)
b,c = a // 2, a - (a//2)
d = s[0] * a[1]
print(abs(d * b - d * c))
Problem p02627 (python)

Fixed submission:
s=input()
if s.isupper()==True:
    print("A")
else:
    print("a")

Buggy submission (verdict: Runtime Error):
n=int(input())
i=1
a=0
m=n
while n-26**i>0:
    n=n-26**i
    i+=1
    a+=n**i #桁数
a #最小
ans=""
b=0
l=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for j in range(i):
    b=m%26
    m=m//26
    if b==0:
      m=m-1
    ans=l[b-1]+ans
print(ans)
Problem p02688 (python)

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

grid = []
for i in range(2*k):
    array = list(map(int, input().split()))
    grid.append(array)

l = []
for j in range (k):
    l.append(grid[0+2*j+1])

lis = list(itertools.chain.from_iterable(l))

count = 0
for m in range(n):
    if m+1 in lis:
        count = count +1
print(n - count)

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

grid = []
for i in range(2*k):
    array = list(map(int, input().strip().split()))
    grid.append(array)
for j in range (k):
    l.append(grid[0+2*j+1])
lis = list(itertools.chain.from_iterable(l))
count = 0
for m in range(n):
    if m+1 in lis:
        count = count +1
print(n - count)
Problem p02785 (python)

Fixed submission:
import sys
n,k = map(int,input().split())
l = list(map(int,input().split()))
if n <= k:
    print("0")
    sys.exit()
l = sorted(l,reverse = True)
hissatu = 0
for i in range(k):
    hissatu += l[i]
total = 0
for j in l:
    total += j
print(total-hissatu)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
l = list(map(int,input().split()))
if n <= k:
    print("0")
    sys.exit()
l = sorted(l,reverse = True)
for i in range(k):
    l.remove(l[0])
d = dict.fromkeys(l)
a = 0
for j in d.keys():
    a += j
print(a)

Buggy submission (verdict: Runtime Error):
import sys
n,k = map(int,input().split())
l = list(map(int,input().split()))
if n <= k:
    print("0")
    sys.exit()
l = sorted(l,reverse = True)
for i in range(k):
    l.remove(l[i])
a = 0
for j in l:
    a += j
print(a)
Problem p02831 (python)

Fixed submission:
a,b = map(int,input().split())
from fractions import gcd
c = gcd(a,b)
answer = a*b/c
print(int(answer))

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
from fractions import gcd
c = math.gcd(a,b)
answer = a*b/c
print(int(answer))

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
from math import gcd
c = math.gcd(a,b)
answer = a*b/c
print(int(answer))

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
import math
c = math.gcd(a,b)
answer = a*b/c
print(int(answer))
Problem p02989 (python)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
l.sort()
a=int(n/2)
s=l[a-1]
t=l[a]
if s==t:
  print("0")
else:
  ans=t-s
  print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
l=list(map(int,input().split()))
l.sort()
a=n/2
s=l.index(a-1)
t=l.index(a)
if s==t:
  print("0")
else:
  ans=t-s
  print(ans)
Problem p02859 (python)

Fixed submission:
# -*- coding:utf-8 -*-

def solve():
    r = int(input())
    print(r*r)


if __name__ == "__main__":
    solve()

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

def solve():
    r = input()
    print(r*r)

if __name__ == "__main__":
    solve()
Problem p02891 (python)

Fixed submission:
# -*- coding:utf-8 -*-

def is_onaji(S):
    pre_moji = S[0]
    for i in range(1, len(S)):
        if S[i] == pre_moji:
            pre_moji = S[i]
            continue
        else:
            return False
    return True


def solve():
    S = input()
    K = int(input())
    N = len(S)

    if N == 1:
        print(K//2)
        return

    # 1回目
    base1 = 0
    pre_moji = S[0]
    for i in range(1, N):
        if S[i] == pre_moji:
            base1 += 1
            pre_moji = "?"
        else:
            pre_moji = S[i]

    if K == 1:
        print(base1)
        return

    # 2回目
    base2 = 0
    for i in range(0, N):
        if S[i] == pre_moji:
            base2 += 1
            pre_moji = "?"
        else:
            pre_moji = S[i]

    if K == 2:
        print(base1+base2)
        return

    # 3回目
    base3 = 0
    for i in range(0, N):
        if S[i] == pre_moji:
            base3 += 1
            pre_moji = "?"
        else:
            pre_moji = S[i]

    if K == 3:
        print(base1+base2+base3)
        return

    if base1 == base2 and base2 == base3:
        print(base1*K)
    elif base1 != base2 and base2 == base3:
        print(base1 + base2*(K-1))
    else:
        # base1とbase2が交互にくる
        print(base1*((K+1)//2) + base2*(K//2))


if __name__ == "__main__":
    solve()

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

def is_onaji(S):
    pre_moji = S[0]
    for i in range(1, len(S)):
        if S[i] == pre_moji:
            pre_moji = S[i]
            continue
        else:
            return False
    return True


def solve():
    S = input()
    K = int(input())
    N = len(S)

    if N == 1:
        print(K//2)
        return

    # 1回目
    base1 = 0
    pre_moji = S[0]
    for i in range(1, N):
        if S[i] == pre_moji:
            base1 += 1
            pre_moji = "?"
        else:
            pre_moji = S[i]

    if K == 1:
        print(base1)
        return

    # 2回目
    base2 = 0
    for i in range(0, N):
        if S[i] = pre_moji:
            base2 += 1
            pre_moji = "?"
        else:
            pre_moji = S[i]

    if K == 2:
        print(base1+base2)

    # 3回目
    base3 = 0
    for i in range(0, N):
        if S[i] = pre_moji:
            base3 += 1
            pre_moji = "?"
        else:
            pre_moji = S[i]

    if K == 3:
        print(base1+base2+base3)

    if base1 == base2 and base2 == base3:
        print(base1*K)
    elif base1 != base2 and base2 == base3:
        print(base1 + base2*(K-1))
    else:
        # base1とbase2が交互にくる
        print(base1*((K+1)//2) + base2*(K//2))


if __name__ == "__main__":
    solve()
Problem p03045 (python)

Fixed submission:
# -*- coding:utf-8 -*-

class UnionFindVerSize():
    def __init__(self, N):
        """ N個のノードのUnion-Find木を作成する """
        # 親の番号を格納する。自分が親だった場合は、自分の番号になり、それがそのグループの番号になる
        self._parent = [n for n in range(0, N)]
        # グループのサイズ（個数）
        self._size = [1] * N

    def find_root(self, x):
        """ xの木の根(xがどのグループか)を求める """
        if self._parent[x] == x: return x
        self._parent[x] = self.find_root(self._parent[x]) # 縮約
        return self._parent[x]

    def unite(self, x, y):
        """ xとyの属する集合を併合する """
        gx = self.find_root(x)
        gy = self.find_root(y)
        if gx == gy: return

        # 小さい方を大きい方に併合させる（木の偏りが減るので）
        if self._size[gx] < self._size[gy]:
            self._parent[gx] = gy
            self._size[gy] += self._size[gx]
        else:
            self._parent[gy] = gx
            self._size[gx] += self._size[gy]

    def get_size(self, x):
        """ xが属するグループのサイズ（個数）を返す """
        return self._size(self.find_root(x))

    def is_same_group(self, x, y):
        """ xとyが同じ集合に属するか否か """
        return self.find_root(x) == self.find_root(y)


def solve():
    """戦略
    □ □ □ □ □ □ □ □ □ □ □ □ □ □ □
    |_| |_| |_|     |_| | |_|_|_|
                    |___|
     1   2   3  4 5   6      7   

    上みたいなものを考えたらわかるが、答えはグループの数(=7)。

    Union-Findを使えばよい。

    """
    N, M = list(map(int, input().split()))
    X, Y, Z = [], [], []
    uf = UnionFindVerSize(N)
    for i in range(M):
        x, y, z = list(map(int, input().split()))
        x, y = x-1, y-1
        uf.unite(x, y)
    
    # 答えは、(グループの数) 
    ans = 0
    for i in range(N):
        if uf.find_root(i) == i:
            ans += 1
    
    print(ans)


if __name__ == "__main__":
    solve()

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

class UnionFind():
    def __init__(self, N):
        """ N個のノードのUnion-Find木を作成する """
        # 親の番号を格納する。自分が親だった場合は、自分の番号になり、それがそのグループの番号になる
        self.parent = [n for n in range(0, N)]
        # グループの深さ
        self.size = [1] * N

    def find(self, x):
        """ 木の根(どのグループか)を求める """
        if self.parent[x] == x: return x
        self.parent[x] = self.find(self.parent[x]) # 縮約
        return self.parent[x]

    def unite(self, x, y):
        """ xとyの属する集合を併合する """
        gx = self.find(x)
        gy = self.find(y)
        if gx == gy: return

        # 小さい方を大きい方に併合させる（木の偏りが減るので）
        if self.size[gx] < self.size[gy]:
            self.parent[gx] = gy
            self.size[gy] += self.size[gx]
        else:
            self.parent[gy] = gx
            self.size[gx] += self.size[gy]

    def is_same_group(self, x, y):
        """ xとyが同じ集合に属するか否か """
        return self.find(x) == self.find(y)


def solve():
    N, M = list(map(int, input().split()))
    X, Y, Z = [], [], []
    uf = UnionFind(N)
    for i in range(M):
        x, y, z = list(map(int, input().split()))
        x, y = x-1, y-1
        uf.unite(x, y)
    
    # 答えは、(グループの数) 
    ans = 0
    for i in range(N):
        if uf[i].find(i) == i:
            ans += 1
    
    print(ans)


if __name__ == "__main__":
    solve()
Problem p03127 (python)

Fixed submission:
def gcd(a, b):
    """ 最大公約数。aはbより大きいこと """
    if b == 0:
        return a
    else:
        return gcd(b, a%b)


def solve():
    N = int(input())
    A = [int(x) for x in input().split(" ")]

    A.sort(reverse=True)
    ans = A[0]
    for i in range(1, N):
        ans = gcd(ans, A[i])

    print(ans)


if __name__ == "__main__":
    solve()

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

def solve():
    N = input()
    A = list(map(int, input().split()))

    # Aの要素を使って、1以上の作成可能な最も小さい値を作る。それが答え。
    # というか最大公約数が答え。

    ans = A[0]
    for i in range(1, N):
        ans = fractions.gcd(ans, A[i])
    print(ans)

if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
import math

def solve():
    N = int(input())
    A = [int(x) for x in input().split(" ")]

    d = 10**9
    for i in range(1, N):
        d = min(math.gcd(A[0], A[i]), d)

    print(d)


if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
import math

def solve():
    N = int(input())
    A = [int(x) for x in input().split(" ")]

    d = 10**9
    for i in range(1, N):
        d = min(math.gcd(A[0], A[1]), d)

    print(d)


if __name__ == "__main__":
    solve()
Problem p03252 (python)

Fixed submission:
# -*- coding:utf-8 -*-

def calc(S, T):
    # 差を計算する
    ans = 0
    for i in range(len(S)):
        if S[i] != T[i]:
            ans += 1
    return ans


def solve():
    s = input()
    S = [moji for moji in s]
    T = input()

    # 文字の置き換えをして、差が減ってなかったら無理？
    
    diff = calc(S, T)
    if diff == 0:
        print("Yes")
        return
    pre_diff = diff

    while True:
        # c1, c2を決める
        for i in range(len(S)):
            if S[i] != T[i]:
                c1 = S[i]
                c2 = T[i]
                break
        
        # 文字を置き換える
        for i in range(len(S)):
            if S[i] == c1:
                S[i] = c2
            elif S[i] == c2:
                S[i] = c1
        
        # 差を計算する
        diff = calc(S, T)
        if diff == 0:
            break
        elif diff < pre_diff:
            pre_diff = diff
            continue
        else:
            print("No")
            return
    print("Yes")





if __name__ == "__main__":
    solve()

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

def calc(S, T):
    # 差を計算する
    ans = 0
    for i in range(len(S)):
        if S[i] != T[i]:
            ans += 1
    return ans


def solve():
    s = input()
    S = [moji for moji in s]
    T = input()

    # 文字の置き換えをして、差が減ってなかったら無理？
    pre_diff = calc(S, T)
    while True:
        for i in range(len(S)):
            if S[i] != T[i]:
                c1 = S[i]
                c2 = T[i]
                break
        
        for i in range(len(S)):
            if S[i] == c1:
                S[i] = c2
            elif S[i] == c2:
                S[i] = c1
        
        # 差を計算する
        diff = calc(S, T)
        if diff == 0:
            break
        elif diff < pre_diff:
            pre_diff = diff
            continue
        else:
            print("No")
            return
    print("Yes")





if __name__ == "__main__":
    solve()
Problem p03804 (python)

Fixed submission:
# -*- coding:utf-8 -*-

def solve():
    N, M = list(map(int, input().split()))
    A = []
    B = []

    for i in range(N):
        A.append(list(input()))
    for i in range(M):
        B.append(list(input()))
    
    # 左上から順に走査する
    for i in range(N-M+1):
        for j in range(N-M+1):
            if A[i][j] == B[0][0]:
                is_contained = True
                for k in range(0, M):
                    for l in range(0, M):
                        if A[i+k][j+l] != B[k][l]:
                            is_contained = False
                            break
                    if not is_contained: break
                if is_contained:
                    print("Yes")
                    return
    print("No")


if __name__ == "__main__":
    solve()

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

def solve():
    N, M = list(map(int, input().split()))
    A = []
    B = []

    for i in range(N):
        A.append(list(input()))
    for i in range(M):
        B.append(list(input()))
    
    # 左上から順に走査する
    for i in range(N-M+1):
        for j in range(N-M+1):
            if A[i][j] == B[0][0]:
                is_contained = True
                for k in range(i, i+M):
                    for l in range(j, j+M):
                        if A[k][l] != B[k][l]:
                            is_contained = False
                            break
                    if not is_contained: break
                if is_contained:
                    print("Yes")
                    return
    print("No")


if __name__ == "__main__":
    solve()
Problem p02699 (python)

Fixed submission:
s, w = map(int, input().split(" "))
print(["safe", "unsafe"][s <= w])

Buggy submission (verdict: Runtime Error):
s, w = map(int, input().split(" "))
print(["safe", "unsafe"][s <= w])

Buggy submission (verdict: Runtime Error):
s, w = map(int, input().strip().split(" "))
print(["safe", "unsafe"][s < w])
Problem p02689 (python)

Fixed submission:
n, m= map(int, input().split())
high = list(map(int, input().split()))
ans = [1]*n

for i in range(m):
    a, b = map(int, input().split())
    if high[a-1] > high[b-1]:
        ans[b-1] = 0
    elif high[a-1] < high[b-1]:
        ans[a-1] = 0
    else:
        ans[a-1] = 0
        ans[b-1] = 0
print(sum(ans))

Buggy submission (verdict: Runtime Error):
n, m= map(int, input().split())
high = list(map(int, input().split()))
ans = [0]*n
 
for i in range(m):
    a =list(map(int, input().split()))
    if high[a[0]-1] > high[a[1]-1]:
        if ans[a[0]-1] == 0:
            ans[a[0]-1] = 1
        ans[a[1]-1] = -1
    elif high[a[0]]-1 < high[a[1]-1]:
        if ans[a[1]-1] == 0:
            ans[a[1]-1] = 1
        ans[a[0]-1] = -1
    else:
        ans[a[1]-1] = -1
        ans[a[0]-1] = -1
print(ans.count(0) + ans.count(1))

Buggy submission (verdict: Runtime Error):
n, m= map(int, input().split())
high = list(map(int, input().split()))
ans = [0]*n

for i in range(m):
    a =list(map(int, input().split()))
    if high[a[0]]-1 > high[a[1]-1]:
        if ans[a[0]-1] == 0:
            ans[a[0]-1] = 1
        ans[a[1]-1] = -1
    elif high[a[0]]-1 < high[a[1]-1]:
        if ans[a[1]-1] == 0:
            ans[a[1]-1] = 1
        ans[a[0]-1] = -1
    else:
        ans[a[1]-1] = -1
        ans[a[0]-1] = -1
print(ans.count(0) + ans.count(1))
Problem p02623 (python)

Fixed submission:
# 再帰は深くなりすぎる
N, M, K = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
accum_A, accum_B = [0] * (len(A)+1), [0] * (len(B)+1)
for i in range(len(A)):
    accum_A[i+1] = accum_A[i] + A[i]
for i in range(len(B)):
    accum_B[i+1] = accum_B[i] + B[i]

ans = 0
i, j = len(A), 0
while i >= 0 and j <= len(B) :
    if accum_A[i] + accum_B[j] > K:
        i -= 1
    else:
        ans = max(ans, i+j)
        j += 1

print(ans)

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

A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

# dp[i][j] = Aをi冊、Bをj冊読んだ時のcost、costがkを超えない範囲で i + jの最大値を求める
# dp[0][0] = 0

# dp = [[0] * (M+1) for _ in range(N+1)]

# どうやって増やしていけばいいんだ ??
# recursionかな
ans = 0
def recur(i, j, cost):
    global ans
    if cost > K:
        return
    ans = max(ans, i + j)
    # dp[i][j] = cost

    if i + 1 < len(A):
        recur(i+1, j, cost+A[i+1])
    if j + 1 < len(B):
        recur(i, j+1, cost+B[j+1])
    return

recur(0, 0, 0)
print(ans)

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

A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

# dp[i][j] = Aをi冊、Bをj冊読んだ時のcost、costがkを超えない範囲で i + jの最大値を求める
# dp[0][0] = 0

dp = [[0] * (M+1) for _ in range(N+1)]

# どうやって増やしていけばいいんだ ??
# recursionかな
ans = 0
def recur(i, j, cost):
    global ans
    if cost > K:
        return
    ans = max(ans, i + j)
    dp[i][j] = cost

    if i + 1 < len(A):
        recur(i+1, j, dp[i][j]+A[i+1])
    if j + 1 < len(B):
        recur(i, j+1, dp[i][j]+B[j+1])
    return

recur(0, 0, 0)
print(ans)