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

Fixed submission:
def xor_gauss_jordan(A):
    """掃き出し法でジョルダン標準形を求める"""
    cnt_row = len(A)
    cnt_col = len(bin(max(A))[2::])
 
    rank = 0
    for col in range(cnt_col):
        # ピボットを探す
        pivot = -1
        for row in range(rank, cnt_row):
            if A[row] & 2**(cnt_col - col - 1):
                pivot = row
                break
 
        #  ピボットがない場合は次の列に
        if pivot == -1:
            continue
 
        # 行をスワップする
        A[pivot], A[rank] = A[rank], A[pivot]
 
        # ピボットのある列の値がすべて0になるように掃き出す
        A_rank = A[rank]
        for row in range(cnt_row):
            if row != rank and A[row] & 2**(cnt_col - col - 1):
                A[row] ^= A[rank]
        rank += 1
 
    return A


t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    s = input()

    hand = [0]
    flag = False

    for i in range(n)[::-1]:
        val = a[i]
        if s[i] == "1":
            # 手持ちでvalを作れるか確認する
            hand.sort(reverse=True)
            for num in hand:
                if val.bit_length() == num.bit_length():
                    val ^= num
            if val != 0:
                flag = True
        else:
            # valを手持ちに加える
            hand.append(val)
            # 手持ちは基底で管理するので掃き出し法を行う
            hand = xor_gauss_jordan(hand)


    if flag:
        print(1)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
def xor_gauss_jordan(A):
    """掃き出し法でジョルダン標準形を求める"""
    cnt_row = len(A)
    cnt_col = len(bin(max(A))[2::])
 
    rank = 0
    for col in range(cnt_col):
        # ピボットを探す
        pivot = -1
        for row in range(rank, cnt_row):
            if A[row] & 2**(cnt_col - col - 1):
                pivot = row
                break
 
        #  ピボットがない場合は次の列に
        if pivot == -1:
            continue
 
        # 行をスワップする
        A[pivot], A[rank] = A[rank], A[pivot]
 
        # ピボットのある列の値がすべて0になるように掃き出す
        A_rank = A[rank]
        for row in range(cnt_row):
            if row != rank and A[row] & 2**(cnt_col - col - 1):
                A[row] ^= A[rank]
        rank += 1
 
    return A


t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    s = input()

    hand = [0]
    flag = False

    for i in range(n)[::-1]:
        val = a[i]
        if s[i] == "1":
            # 手持ちでvalを作れるか確認する
            hand.sort(reverse=True)
            for num in memo_0:
                if val & num == num:
                    val -= num
            if val != 0:
                flag = True
        else:
            # valを手持ちに加える
            hand.append(val)
            # 手持ちは基底で管理するので掃き出し法を行う
            hand = xor_gauss_jordan(memo_0)


    if flag:
        print(1)
    else:
        print(0)
Problem p02702 (python)

Fixed submission:
s = input()
MOD = 2019

dp = [0] * MOD
dq = [0] * MOD
ans = 0

for i in range(len(s)):
    tmp = int(s[i])
    if i % 2 == 0:
        for val in range(MOD):
            dp[((val * 10) + tmp) % MOD] += dq[val]
            dq[val] = 0
        dp[tmp] += 1
        ans += dp[0]

    else:
        for val in range(MOD):
            dq[((val * 10) + tmp) % MOD] += dp[val]
            dp[val] = 0
        dq[tmp] += 1
        ans += dq[0] 
    
print(ans)

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

s = input()
MOD = 2019

dp = [0] * ((MOD) * (len(s) + 1))
# dp = [[0] * (MOD) for i in range(len(s) + 1)]

dp[0] = 0
for i in range(len(s)):
    tmp = int(s[i])
    dp[(i + 1) * MOD + tmp] += 1
    for val in range(MOD):
        dp[(i + 1) * MOD + (val * 10 + tmp) % MOD] += dp[i * MOD + val]

ans = 0
for i in range(len(s) + 1):
    ans += dp[i * MOD]
    
print(ans)
Problem p02745 (python)

Fixed submission:
MAX_N = 2000
a = [ord(char) for char in input()]
b = [ord(char) for char in input()]
c = [ord(char) for char in input()]


len_a = len(a)
len_b = len(b)
len_c = len(c)

a = a + [63] * (MAX_N - len_a + 10)
b = b + [63] * (MAX_N - len_b + 10)
c = c + [63] * (MAX_N - len_c + 10)

ab = [True] * (2 * MAX_N + 10)
ba = [True] * (2 * MAX_N + 10)
bc = [True] * (2 * MAX_N + 10)
cb = [True] * (2 * MAX_N + 10)
ca = [True] * (2 * MAX_N + 10)
ac = [True] * (2 * MAX_N + 10)


for length in range(MAX_N + 1):
    for i in range(MAX_N + 1):
        if i + length > MAX_N:
            break

        if a[i + length] != b[i] and a[i + length] != 63 and b[i] != 63:
            ab[length] = False
        if b[i + length] != a[i] and b[i + length] != 63 and a[i] != 63:
            ba[length] = False

        if b[i + length] != c[i] and b[i + length] != 63 and c[i] != 63:
            bc[length] = False
        if c[i + length] != b[i] and c[i + length] != 63 and b[i] != 63:
            cb[length] = False

        if c[i + length] != a[i] and c[i + length] != 63 and a[i] != 63:
            ca[length] = False
        if a[i + length] != c[i] and a[i + length] != 63 and c[i] != 63:
            ac[length] = False


ans = MAX_N * 6
for len1 in range(MAX_N + 1):
    for len2 in range(MAX_N + 1):
        if ab[len1] and bc[len2] and ac[len1 + len2]:
            tmp = max(len_a, len_b + len1, len_c + len1 + len2)
            ans = min(ans, tmp)
        if ba[len1] and ac[len2] and bc[len1 + len2]:
            tmp = max(len_b, len_a + len1, len_c + len1 + len2)
            ans = min(ans, tmp)

for len1 in range(MAX_N + 1):
    for len2 in range(MAX_N + 1):
        if bc[len1] and ca[len2] and ba[len1 + len2]:
            tmp = max(len_b, len_c + len1, len_a + len1 + len2)
            ans = min(ans, tmp)
        if cb[len1] and ba[len2] and ca[len1 + len2]:
            tmp = max(len_c, len_b + len1, len_a + len1 + len2)
            ans = min(ans, tmp)

for len1 in range(MAX_N + 1):
    for len2 in range(MAX_N + 1):
        if ca[len1] and ab[len2] and cb[len1 + len2]:
            tmp = max(len_c, len_a + len1, len_b + len1 + len2)
            ans = min(ans, tmp)
        if ac[len1] and cb[len2] and ab[len1 + len2]:
            tmp = max(len_a, len_c + len1, len_b + len1 + len2)
            ans = min(ans, tmp)

print(ans)

Buggy submission (verdict: Runtime Error):
def solve(li):
    if len(li) == n:
        ans.append(li)
        return
    tmp = max(li)
    for i in range(1, tmp + 2):
        solve(li + [i])

ans = []
n = int(input())
solve([1])
res = []
alph = "abcdefghijklmnopq"

for ptn in ans:
    for i in range(n):
        ptn[i] = alph[ptn[i] - 1]
    res.append("".join(ptn))
res = sorted(res)
for i in res:
    print(i)
Problem p02780 (python)

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

ans = [0] * n
for i in range(n):
    ans[i] = (p[i] + 1) / 2

ruiseki = [0] * (n + 1)
for i in range(n):
    ruiseki[i + 1] = ruiseki[i] + ans[i]
    
res = 0
for i in range(n):
    if k+i > n:
        break
    res = max(res, ruiseki[k + i] - ruiseki[i])
print(res)

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

ans = [0] * n
ans = 0
for i in range(n):
    ans[i] = (p[i] + 1) / 2

ruiseki = [0] * (n + 1)
for i in range(n):
    ruiseki[i + 1] = ruiseki[i] + ans[i]
    
res = 0
for i in range(n):
    if k+i > n:
        break
    res = max(res, ruiseki[k + i] - ruiseki[i])
print(res)

Buggy submission (verdict: Runtime Error):
5 3
1 2 2 4 5
Problem p02840 (python)

Fixed submission:
from operator import itemgetter


n, x, d = map(int, input().split())

a = [0] * n
for i in range(n - 1):
    a[i + 1] = a[i] + 1

ruiseki1 = [0] * (n + 1)
ruiseki2 = [0] * (n + 1)

for i in range(n):
    ruiseki1[i + 1] += ruiseki1[i] + a[i] 
for i in range(n):
    ruiseki2[i + 1] += ruiseki2[i] + a[n - i - 1] 

if d == 0 and x == 0:
    print(1)
    exit()
elif d == 0:
    print(n + 1)
    exit()
    
memo = {}

for i in range(n + 1):
    s_cnt = i
    geta = i * x
    div = geta // d
    mod = geta % d
    min_ = ruiseki1[i]
    max_ = ruiseki2[i]
    if mod not in memo:
        memo[mod] = []
    memo[mod].append((min_ + div, max_ + div + 1))

ans = 0
for i in memo:
    memo[i] = sorted(memo[i])
    r_max = -10**18
    for j in memo[i]:
        l, r = j
        if r - r_max < 0:
            continue
        ans += min(r - l, r - r_max)
        r_max = r
print(ans)

Buggy submission (verdict: Runtime Error):
from operator import itemgetter


n, x, d = map(int, input().split())

a = [0] * n
for i in range(n - 1):
    a[i + 1] = a[i] + 1

ruiseki1 = [0] * (n + 1)
ruiseki2 = [0] * (n + 1)

for i in range(n):
    ruiseki1[i + 1] += ruiseki1[i] + a[i] 
for i in range(n):
    ruiseki2[i + 1] += ruiseki2[i] + a[n - i - 1] 

if d == 0 and x == 0:
    print(tmp)
    exit()
elif d == 0:
    print(tmp)
    exit()
    
memo = {}
for i in range(n + 1):
    s_cnt = i
    geta = i * x
    div = geta // d
    mod = geta % d
    min_ = ruiseki1[i]
    max_ = ruiseki2[i]
    if mod not in memo:
        memo[mod] = []
    memo[mod].append((min_ + div, max_ + div + 1))

ans = 0
for i in memo:
    memo[i] = sorted(memo[i], key = itemgetter(1))
    right = -10**18
    for j in memo[i]:
        l, r = j
        ans += min(r - l, r - right)
        right = r
print(ans)
Problem p02866 (python)

Fixed submission:
n = int(input())
d = list(map(int, input().split()))
MOD = 998244353
if d[0] != 0:
    print(0)
    exit()
    
a = [0] * n
for i in range(n):
    a[d[i]] += 1

ans = 1
for i in range(n):
    if i == 0:
        if a[i] != 1:
            ans *= 0
    else:
                for _ in range(a[i]):
                    ans *= a[i-1]
                    ans %= MOD
print(ans % MOD)

Buggy submission (verdict: Runtime Error):
n = int(input())
d = list(map(int, input().split()))
MOD = 998244353

a = [0] * n
for i in range(n):
    a[d[i]] += 1

ans = 1
for i in range(n):
    if i == 0:
        if a[i] != 1:
            ans *= 0
    else:
        if a[i] > 0:
            if a[i-1] == 0:
                ans *= 0
                print(aa)
            else:
                ans *= pow(a[i-1], a[i], MOD)
                ans %= MOD
print(ans % MOD)
Problem p02867 (python)

Fixed submission:
from collections import deque
from operator import itemgetter


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

info = [(a[i], b[i]) for i in range(n)]
info = sorted(info, key = itemgetter(1))
for i in range(n):
    a[i], b[i] = info[i]

s = sorted(a)
t = sorted(b)
for i in range(n):
    if s[i] > t[i]:
        print("No")
        exit()

sorted_a = sorted(zip(a, range(len(a))))
graph = [[] for i in range(n)]
for i in range(n):
    u = i
    v = sorted_a[i][1]
    if u != v:
        graph[u].append(v)

used = [False]*n
pos = 0
used[pos] = True
q = deque([pos])
while q:
    pos = q.pop()
    for next_pos in graph[pos]:
        if used[next_pos]:
            continue
        q.append(next_pos)
        used[next_pos] = True

for i in range(n):
    if not used[i]:
        print("Yes")
        exit()

for i in range(n-1):
    if s[i+1] <= t[i]:
        print("Yes")
        exit()

print("No")

Buggy submission (verdict: Runtime Error):
from collections import deque
from operator import itemgetter


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

info = [(a[i], b[i]) for i in range(n)]
info = sorted(info, key = itemgetter(1))
for i in range(n):
    a[i], b[i] = info[i]

s = sorted(a)
t = sorted(b)
for i in range(n):
    if s[i] > t[i]:
        print("No")
        exit()

sorted_a = sorted(zip(a, range(len(a))))
graph = [[] for i in range(n)]
for i in range(n):
    u = i
    v = sorted_a[i][1]
    if u != v:
        graph[u].append(v)

used = [False]*n
pos = 0
used[pos] = True
q = deque([pos])
while q:
    pos = q.pop()
    for next_pos in graph[pos]:
        if used[next_pos]:
            continue
        q.append(next_pos)
        used[next_pos] = True

for i in range(n):
    if not used[i]:
        print("Yes")
        exit()

for i in range(n):
    if s[i+1] <= t[i]:
        print("Yes")
        exit()

print("No")
Problem p02918 (python)

Fixed submission:
n, k = map(int, input().split())
s = input()
cnt = 1
li = []
for i in range(n-1):
    if s[i] == s[i+1] and s[i] == "R":
        cnt += 1
    elif s[i] == s[i+1] and s[i] == "L":
        cnt += 1
    else:
        li.append((s[i], cnt))
        cnt = 1
if n > 1:
   li.append((s[i], cnt))
cut = len(li) - 1

print(min(n-1, n - cut - 1 + 2 * k))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = input()
cnt = 1
li = []
li2 = []
ind_R = []
ind_L = []
for i in range(n-1):
    if s[i] == s[i+1] and s[i] == "R":
        cnt += 1
    elif s[i] == s[i+1] and s[i] == "L":
        cnt += 1
    else:
        li.append((s[i], cnt))
        cnt = 1
li.append((s[i], cnt))
cut = len(li) - 1

print(min(n-1, n - cut - 1 + 2 * k))
Problem p03046 (python)

Fixed submission:
m, k= map(int, input().split())

if 2**m <= k:
    print(-1)
    exit()

if m == 1:
    if k == 0:
        print("0 0 1 1")
    if k == 1:
        print(-1)
    exit()

li = []
for i in range(2**m):
    if i != k:
        li.append(i)
li = li + [k] + list(reversed(li)) + [k]
print(" ".join(map(str, li)))

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
if n%2 == 1:
    if m
    print(-1)
    exit()
else:
    if m >= n:
        print(-1)
        exit()

list1 = [0]*n
k = 2
for j in range(1,n):
    if j == len(list1)-j:
        list1[j] = 1
        break
    list1[j] = k
    list1[len(list1)-j] = k
    k = k+1

list2 = [0]*n
for j in range(1,n):
    if j == len(list2)-j:
        list2[j] = 1
        break
    list2[j] = k
    list2[len(list2)-j] = k
    k = k+1

li = list1 + list2

for i in range(len(li)):
    if li[i] == m:
        li[i] = 1
    elif li[i] == 1:
        li[i] = m
print(li)

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
if n%2 == 0:
    print(-1)
    exit()
else:
    if m >= n:
        print(-1)
        exit()

1/0
Problem p03082 (python)

Fixed submission:
n, x = map(int, input().split())
s = list(map(int, input().split()))
MOD = 10 ** 9 + 7

s = sorted(s, reverse=True)
max_ = max(s[0], x)
dp = [[0] * (max_ + 1) for i in range(n + 1)]
dp[0][x] = 1

for i in range(n):
    for val in range(max_ + 1):
        dp[i + 1][val % s[i]] += dp[i][val]
        dp[i + 1][val % s[i]] %= MOD
        dp[i + 1][val] += dp[i][val] * (n - i - 1)
        dp[i + 1][val] %= MOD

ans = 0
for i, num in enumerate(dp[-1]):
    ans += num * i
    ans %= MOD
print(ans)

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
s = list(map(int, input().split()))
s = sorted(s)
MOD = 10**9 + 7

frac = [0]*(n+1)
frac[0] = 1
for i in range(0,n):
    frac[i+1] = (i+1) * frac[i]
    frac[i+1] %= MOD

def solve(x, cnt, visited):
    ans = 0
    flag = False
    if cnt == n:
        return x
    for i in range(n):
        if not visited[i]:
            if s[i] <= x:
                if not flag:
                    ans += (x % s[i]) * frac[n - (cnt + 1)]
                    flag = True
                else:
                    tmp_visited = visited[0:]
                    tmp_visited[i] = True
                    ans += solve(x % s[i], cnt + 1, tmp_visited) % MOD
                    ans %= MOD
            else:
                tmp_visited = visited[0:]
                tmp_cnt = 0
                for j in range(i, n):
                    if not tmp_visited[j]:
                        tmp_visited[j] = True
                        tmp_cnt += 1
                ans += solve(x, cnt + tmp_cnt, tmp_visited) * frac[tmp_cnt] % MOD
                ans %= MOD
                break
    return ans
    
    
print(solve(x, 0, visited = [False]*n) % MOD)
Problem p03096 (python)

Fixed submission:
n = int(input())
cc = [int(input()) for i in range(n)]
c = [cc[0]]
for i in range(1,n):
  if cc[i] != cc[i-1]:
    c.append(cc[i])

n = len(c)
dp = [0 for i in range(n)]
pos_dp = [-1 for i in range(2*10**5+1)]

dp[0] = 1
pos_dp[c[0]] = 0
     
for i in range(1,n):
  if pos_dp[c[i]]!=-1:
    dp[i] = (dp[i-1] + dp[pos_dp[c[i]]])%1000000007
  else:
    dp[i] = dp[i-1] 
  pos_dp[c[i]] = i

print(dp[n-1])

Buggy submission (verdict: Runtime Error):
import bisect
n = int(input())
c = [int(input()) for i in range(n)]
dp = [1 for i in range(n)]
dp2 = [-1 for i in range(n)]
memo = {}
ans = 0

def count(s):
  memo = {}
  res = 1
  for i in range(len(s)):
    if s[i] not in memo:
      memo[s[i]] = 1
    else:
      memo[s[i]] += 1
  for i in memo:
    res = res*((memo[i]*(memo[i]+1))//2)
  return res


dp2[c[0]] = 0
#print("dp",dp)
#print("dp2",dp2)
     
for i in range(1,n):
  
  if c[i] != c[i-1]:
    if dp2[c[i]] == -1:
      dp2[c[i]] = i
    else:
      dp[c[i]] = count(c[dp2[c[i]]:i])*dp[c[i]]
      ans += dp[c[i]]
      dp2[c[i]] = i

 # print(i,"dp",dp)
  #print(i,"dp2",dp2)
  #print(ans)   
#    for j in range(9):
#      ans += len()-1
#      bisect.bisect_left(li[i],)
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
n = int(input())
c = [int(input()) for i in range(n)]

ans = 1
li = [[] for i in range(9)]
for i in range(n):
  if not li[c[i]]:
    li[c[i]].append(i)
  else:
#    if li[c[i]] != li[c[i]][-1]

    li[c[i]].append(i)
    ans += len(li[c[i]]) - 1
#    for j in range(9):
#      ans += len()-1
#      bisect.bisect_left(li[i],)
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
n = int(input())
c = [int(input()) for i in range(n)]

ans = 1
li = [[] for i in range(9)]
for i in range(n):
  if not li[c[i]]:
    li[c[i]].append(i)
    print(i)
  else:
#    if li[c[i]] != li[c[i]][-1]

    li[c[i]].append(i)
    ans += len(li[c[i]]) - 1
#    for j in range(9):
#      ans += len()-1
#      bisect.bisect_left(li[i],)
print(ans)
Problem p03145 (python)

Fixed submission:
a,b,c= map(int,input().split())
print(a*b//2)

Buggy submission (verdict: Runtime Error):
a,b,c= (int,input().split())
print(a*b/2)
Problem p03160 (python)

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

dp = [0]*N

dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2,N):
  dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))

print(dp[N-1])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)
 
N = int(input())
h = list(map(int,input().split()))
 
N -= 1
 
def step(i):
  if i == 0:
    return 0
  elif i == 1:
    return abs(h[1]-h[0])
  elif step[i-1]+abs(h[i-1]-h[i]) <= step[i-2]+abs(h[i-2]-h[i]):
    return step(i-1) + abs(h[i-1]-h[i])
  else:
    return step(i-2) + abs(h[i-2]-h[i])
  
print(step(N))

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

N = int(input())
h = list(map(int,input().split()))

N -= 1
 
def step(i):
  if i == 0:
    return 0
  elif i == 1:
    return abs(h[1]-h[0])
  elif abs(h[i-1]-h[i]) <= abs(h[i-2]-h[i]):
    return step(i-1) + abs(h[i-1]-h[i])
  else:
    return step(i-2) + abs(h[i-2]-h[i])
  
print(step(N))

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

N -= 1

def step(i):
  if i == 0:
    return 0
  elif i == 1:
    return abs(h[1]-h[0])
  elif abs(h[i-1]-h[i]) <= abs(h[i-2]-h[i]):
    return step(i-1) + abs(h[i-1]-h[i])
  else:
    return step(i-2) + abs(h[i-2]-h[i])
  
print(step(N))

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

N -= 1

def step(i):
  if i == 0:
    return 0
  elif i == 1:
    return abs(h[1]-h[0])
  elif abs(h[i-1]-h[i]) <= abs(h[i-2]-h[i]):
    return step(i-1) + abs(h[i-1]-h[i])
  else:
    return step(i-2) + abs(h[i-2]-h[i])
  
print(step(N))
Problem p03161 (python)

Fixed submission:
N,K = map(int,input().split())
h = list(map(int,input().split()))
 
dp = [100000000000]*N
 
dp[0] = 0
dp[1] = abs(h[1]-h[0])
 
for i in range(2,N):
  for num in range(K):
    if num+1<=i:
      A = dp[i-num-1]+abs(h[i]-h[i-num-1])
      if dp[i] >= A:
        dp[i] = A
 
print(dp[N-1])

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

dp = [0]*n
dp[0]=0

for i in range(1,k):
  dp[i]=min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,i+1)])

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


print(dp[n-1])
Problem p03163 (python)

Fixed submission:
n,w = map(int,input().split())
info = [[0,0]]+[list(map(int,input().split())) for i in range(n)]

## dp[i][j]:i番目までのアイテムを重さjのナップサックに詰めるときの最大価値
dp = [[0]*(w+1) for i in range(n+1)]
for i in range(n+1):
  for j in range(w+1):
    if j-info[i][0]>=0:
      dp[i][j] = max(dp[i-1][j],dp[i-1][j-info[i][0]]+info[i][1])
    else:
      dp[i][j] = dp[i-1][j]

print(dp[n][w])

Buggy submission (verdict: Runtime Error):
n,w = map(int,input().split())
info = [[0,0]]+[list(map(int,input().split())) for i in range(n)]
v = 0
for i in range(n+1):
  v += info[i][1]
n = n+1
## dp[i][j]:i番目までのアイテムを詰めたときに総価値jになるときの最小重さ
dp = [[float("inf")]*(v) for i in range(n)]

for i in range(n):
  dp[i][0] = 0

for i in range(1,n):
  for j in range(1,v):
    if j-info[i][1]>=0:
      dp[i][j] = min(dp[i-1][j],dp[i-1][j-info[i][1]]+info[i][0])
    else:
      dp[i][j] = dp[i-1][j]

for j in range(v):
  if dp[n-1][j] <= w:
    ans = j
print(ans)
Problem p03166 (python)

Fixed submission:
import sys


input = sys.stdin.readline
sys.setrecursionlimit(200000)

n, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]
tree = [[] for i in range(n)]
start_point = [True] * n
for i in range(m):
    tree[info[i][0] - 1].append(info[i][1] - 1)
    start_point[info[i][1] - 1] = False
     
dp = [-1]*n

def dfs(pos):
    if dp[pos] !=-1:
        return dp[pos]
    if not tree[pos]:
        dp[pos] = 0
        return 0
    ans = 0
    for i in tree[pos]:
        ans = max(ans, dfs(i) + 1)
    dp[pos] = ans
    return ans

for i in range(n):
    dfs(i)
print(max(dp))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]
tree = [[] for i in range(n)]
start_point = [True] * n
for i in range(m):
    tree[info[i][0] - 1].append(info[i][1] - 1)
    start_point[info[i][1] - 1] = False
     
dp = [0]*n

def dfs(pos):
    for i in tree[pos]:
        if dp[i] < dp[pos] + 1:
            dp[i] = dp[pos] + 1
            dfs(i)

for i in range(len(start_point)):
    if start_point[i]:
        dfs(i)
print(max(dp))
Problem p03167 (python)

Fixed submission:
H,W = map(int,input().split())
a = [list(input()) for i in range(H)]

dp=[[0]*(W) for i in range(H)]

flagH = 0
flagW = 0

for i in range(H):
  if a[i][0]=="." and flagH==0:
    dp[i][0]=1
  else:
    dp[i][0]=0
    flagH=1

for j in range(W):
  if a[0][j]=="." and flagW==0:
    dp[0][j]=1
  else:
    dp[0][j]=0
    flagW=1

for i in range(1,H):
  for j in range(1,W):
    if a[i][j]==".":
      dp[i][j]=dp[i-1][j]+dp[i][j-1]

print(dp[H-1][W-1]%1000000007)

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())
a = [list(input()) for i in range(H)]

dp=[[0]*(W) for i in range(H)]

for i in range(H):
  if a[i][0]==".":
    dp[i][0]=1

for j in range(W):
  if a[0][i]==".":
    dp[0][i]=1

for i in range(1,H):
  for j in range(1,W):
    if a[i][j]==".":
      dp[i][j]=dp[i-1][j]+dp[i][j-1]

print(dp[H-1][W-1])