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

Fixed submission:
n = int(input())
h = [int(i) for i in input().split()]

# dpの最小値を変更する関数
def chmin(a, b):
    if a > b:
        return b
    else:
        return a
    
# 無限大の値
f_inf = float('inf')

# DP テーブルを初期化　(最小化問題なので INF に初期化)
dp = [f_inf] * (10**5+10)

# 初期条件
dp[0] = 0

# 足場 i-1 から足場 i へ移動する。コストは|h[i]−h[i-1]|
# 足場 i-2 から足場 i へと移動する コストは |h[i]−h[i-2]|
for i in range(1, n):
    dp[i] = chmin(dp[i], dp[i - 1] + abs(h[i] - h[i-1]))
    # 一番目の足場では一つ前しか存在しない
    if i > 1:
        dp[i] = chmin(dp[i], dp[i - 2] + abs(h[i] - h[i -2]))

print(dp[n-1])

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

n = int(input())
h = [int(i) for i in input().split()]

# 無限大の値
f_inf = float('inf')

# メモ用のDP テーブルを初期化　(最小化問題なので INF に初期化)
dp = [f_inf] * (10**5+10)

# dpの最小値を変更する関数
def chmin(a, b):
    if a > b:
        return b
    else:
        return a

# メモ化再帰の関数
def rec(i):
    # DPの値が更新されている場合はその値を返す
    if dp[i] <  f_inf:
        return dp[i]
    
    # 再帰の終了条件。足場0のコストは0
    if i == 0:
        return 0
    
    # i-1, i-2　を再帰
    res = f_inf
    # i-1 から来た場合
    res = chmin(res, rec(i-1) + abs(h[i] - h[i-1]))
    # i-2 から来た場合
    if i > 1:
        res = chmin(res, rec(i-2) + abs(h[i] - h[i-2]))
    
    # 結果をメモする
    dp[i] = res
    return res

ans = rec(n-1)
print(ans)

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

n = int(input())
h = [int(i) for i in input().split()]

# 無限大の値
f_inf = float('inf')

# メモ用のDP テーブルを初期化　(最小化問題なので INF に初期化)
dp = [f_inf] * (10**5+10)

# dpの最小値を変更する関数
def chmin(a, b):
    if a > b:
        return b
    else:
        return a

@lru_cache(None)
# メモ化再帰の関数
def rec(i):
    # # DPの値が更新されている場合はその値を返す
    # if dp[i] <  f_inf:
    #     return dp[i]
    
    # 再帰の終了条件。足場0のコストは0
    if i == 0:
        return 0
    
    # i-1, i-2　を再帰
    res = f_inf
    # i-1 から来た場合
    res = chmin(res, rec(i-1) + abs(h[i] - h[i-1]))
    # i-2 から来た場合
    if i > 1:
        res = chmin(res, rec(i-2) + abs(h[i] - h[i-2]))
    
    # # 結果をメモする
    # dp[i] = res
    return res

ans = rec(n-1)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
h = [int(i) for i in input().split()]

# 無限大の値
f_inf = float('inf')

# メモ用のDP テーブルを初期化　(最小化問題なので INF に初期化)
dp = [f_inf] * (10**5+10)

# dpの最小値を変更する関数
def chmin(a, b):
    if a > b:
        return b
    else:
        return a

# メモ化再帰の関数
def rec(i):
    # DPの値が更新されている場合はその値を返す
    if dp[i] <  f_inf:
        return dp[i]
    
    # 再帰の終了条件。足場0のコストは0
    if i == 0:
        return 0
    
    # i-1, i-2　を再帰
    res = f_inf
    # i-1 から来た場合
    res = chmin(res, rec(i-1) + abs(h[i] - h[i-1]))
    # i-2 から来た場合
    if i > 1:
        res = chmin(res, rec(i-2) + abs(h[i] - h[i-2]))
    
    # 結果をメモする
    dp[i] = res
    return res

ans = rec(n-1)
print(ans)
Problem p03165 (python)

Fixed submission:
import sys

# input処理を高速化する
input = sys.stdin.readline

# 入力
S = input()
T = input()

def chmax(a, b):
    if a >= b:
        return a
    else:
        return b


def lcs(s, t):
    dp = [[0 for i in range(len(T)+1)] for j in range(len(S)+1)]
    for i in range(len(S)):
        for j in range(len(T)):
            if S[i] == T[j]:
                dp[i+1][j+1] = chmax(dp[i+1][j+1], dp[i][j] + 1)
            dp[i+1][j+1] = chmax(dp[i+1][j+1], dp[i+1][j])
            dp[i+1][j+1] = chmax(dp[i+1][j+1], dp[i][j+1])

    ans = ''
    i = len(S)
    j = len(T)
    while (i>0  and j>0):
        if dp[i][j] == dp[i-1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j-1]:
            j -= 1
        else:
            ans += s[i-1] 
            i -= 1
            j -= 1
    
    print(ans[::-1])

        
lcs(S, T)

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

# input処理を高速化する
input = sys.stdin.readline

# 入力
S = input()
T = input()

def lcs(s, t):
    dp = np.zeros((len(S)+1, len(T)+1), dtype=int)

    for i in range(len(S)):
        for j in range(len(T)):
            if S[i] == T[j]:
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                dp[i+1][j+1] = np.maximum(dp[i+1][j], dp[i][j+1])
    
    ans = ''
    i = len(S)
    j = len(T)
    while (i>0  and j>0):
        if dp[i][j] == dp[i-1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j-1]:
            j -= 1
        else:
            ans += s[i-1] 
            i -= 1
            j -= 1
    
    print(ans[::-1])
Problem p03168 (python)

Fixed submission:
import sys

# input処理を高速化する
input = sys.stdin.readline

def main():
    N = int(input())
    lst_p = list(map(float, input().split()))

    # dp[i][j] := 最初の i 枚のコインを投げたときに、表が j 枚となる確率
    # 次のコインが表: dp[i+1][j+1] += dp[i][j]∗p[i]
    # 次のコインが裏: dp[i+1][j] += dp[i][j]∗(1.0−p[i])
    dp = [[0] * (N+1) for i in range(N+1)]

    # 初期条件
    dp[0][0] = 1.0

    for i in range(N):
        for j in range(N):
            dp[i+1][j+1] += dp[i][j] * lst_p[i]
            dp[i+1][j] += dp[i][j] * (1.0 - lst_p[i])
    
    ans = 0
    for i in range((N+1)//2, N+1):
        ans += dp[N][i]

    print(ans)

main()

Buggy submission (verdict: Runtime Error):
import sys

# input処理を高速化する
input = sys.stdin.readline

def main():
    N = int(input())
    p = list(map(float, input().split()))

    # dp[j] := 表が j 枚となる確率
    # dp[j] = dp[j-1]*p[i] + dp[j]*(1-p[i]) ただしdp[j]が重複していることに注意
    dp = [0.0] * (N+1)
    # 初期条件
    dp[0]= 1.0

    for i in range(N):
        p_tail = 1 - p[i]
        dp = [dp[j -1] * p[i] + dp[j] * p_tail[i] for j in range(N+1)]

        # 更新前のdpを更新に使う。
        dp_before_update = dp[:]
        for j in range(N+1):
            dp[j] = (dp_before_update[j-1] * lst_p[i]) + (dp_before_update[j] * (1 - lst_p[i]))
    
    ans = sum(dp[(N//2+1):])

    print(ans)

main()

Buggy submission (verdict: Runtime Error):
import sys

# input処理を高速化する
input = sys.stdin.readline

def main():
    N = int(input())
    lst_p = list(map(float, input().split()))

    # dp[i][j] := 最初の i 枚のコインを投げたときに、表が j 枚となる確率
    # 次のコインが表: dp[i+1][j+1] += dp[i][j]∗p[i]
    # 次のコインが裏: dp[i+1][j] += dp[i][j]∗(1.0−p[i])
    dp = [[0] * (N+1) for i in range(N+1)]

    # 初期条件
    dp[0][0] = 1.0

    for i in range(N):
        for j in range(N):
            dp[i+1][j+1] += dp[i][j] * lst_p[i]
            dp[i+1][j] += dp[i][j] * (1.0 - lst_p[i])
    
    ans = sum(dp[(N//2+1):])

    print(ans)

main()
Problem p03160 (python)

Fixed submission:
'''input
4
10 30 40 20
'''

n=int(input())
arr=list(map(int,input().split()))
dp=[0]*len(arr)
for i in range(1,n):
	dp[i]=dp[i-1]+abs(arr[i]-arr[i-1])
	if(i>1):
		a=dp[i-2]+abs(arr[i]-arr[i-2])
		dp[i]=min(dp[i],a)
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
'''input
4
10 30 40 20
'''

n=int(input())
arr=list(map(int,input().split()))
dp=[0]*len(arr)
dp[0]=0
for i in range(len(arr)):
    if(i==1):
        dp[i]=dp[i-1]+abs(arr[i]-arr[i+1])
    else:
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]))
print(dp[n-1])
Problem p03160 (python)

Fixed submission:
#!/usr/bin/env python
# coding: utf-8

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

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

print(DP[-1])

#dp = {}
#NOT_FOUND = pow(10, 4) + 1
#
#def sget(i):
#    if i in dp:
#        return dp[i]
#    return NOT_FOUND
#
#def chmin(a, b):
#    if (a > b):
#        return b
#    return a
#
#def main(N, hs):
#    dp[0] = 0
#    #for i in range(1, N):
#    #    dp[i] = chmin(sget(i), sget(i - 1) + abs(hs[i] - hs[i - 1]))
#    #    if i > 1:
#    #        dp[i] = chmin(sget(i), sget(i - 2) + abs(hs[i] - hs[i - 2]))
#    #def rec(i):
#    #    if sget(i) < NOT_FOUND:
#    #        return sget(i)
#    #    if i == 0:
#    #        return 0
#    #    res = NOT_FOUND
#    #    res = chmin(res, rec(i-1) + abs(hs[i] - hs[i-1]))
#    #    if (i > 1):
#    #        res = chmin(res, rec(i-2) + abs(hs[i] - hs[i-2]))
#    #    dp[i] = res
#    #    return dp[i]
#    #return rec(N-1)
#    return dp[N-1]
#
#
#if __name__ == '__main__':
#    #N = 4
#    #hs = [10, 30, 40, 20]
#    #N = 2
#    #hs = [10, 10]
#    #N = 6
#    #hs = [30, 10, 60, 10, 60, 50]
#    #N = 2
#    #hs = [1, 3, 2, 1]
#    N = int(input())
#    hs = list(map(int, input().split()))
#    print(main(N, hs))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
# coding: utf-8

dp = {}
NOT_FOUND = pow(10, 4) + 1

def sget(i):
    if i in dp:
        return dp[i]
    return NOT_FOUND

def chmin(a, b):
    if (a > b):
        return b
    return a

def main(N, hs):
    dp[0] = 0
    #for i in range(1, N):
    #    dp[i] = chmin(sget(i), sget(i - 1) + abs(hs[i] - hs[i - 1]))
    #    if i > 1:
    #        dp[i] = chmin(sget(i), sget(i - 2) + abs(hs[i] - hs[i - 2]))
    def rec(i):
        if sget(i) < NOT_FOUND:
            return sget(i)
        if i == 0:
            return 0
        res = NOT_FOUND
        res = chmin(res, rec(i-1) + abs(hs[i] - hs[i-1]))
        if (i > 1):
            res = chmin(res, rec(i-2) + abs(hs[i] - hs[i-2]))
        dp[i] = res
        return dp[i]
    return rec(N-1)


if __name__ == '__main__':
    #N = 4
    #hs = [10, 30, 40, 20]
    #N = 2
    #hs = [10, 10]
    #N = 6
    #hs = [30, 10, 60, 10, 60, 50]
    #N = 2
    #hs = [1, 3, 2, 1]
    N = int(input())
    hs = list(map(int, input().split(" ")))
    print(main(N, hs))
    #print(dp)
Problem p03160 (python)

Fixed submission:
n=int(input())
L=list(map(int,input().split()))
dp=[]
dp.append(0)
dp.append(abs(L[0]-L[1]))
for i in range(2, n):
    dp.append( min( dp[i-2]+abs(L[i]-L[i-2]), dp[i-1]+abs(L[i]-L[i-1]) ) )
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
def Stepenica(i,p1,p2):
    if i<len(L):
        p3=min( p1+abs(L[i]-L[i-2]), p2+abs(L[i]-L[i-1]) )
        Stepenica(i+1,p2,p3)
    else:
        print(p2)
        return
    
n=int(input())
L=list(map(int,input().split()))
Stepenica(2,0,abs(L[0]-L[1]))

Buggy submission (verdict: Runtime Error):
def Stepenica(L,i,p1,p2):
    if i<len(L):
        p3=min( p1+abs(L[i]-L[i-2]), p2+abs(L[i]-L[i-1]) )
        Stepenica(L,i+1,p2,p3)
    else:
        print(p2)
        return
    
n=int(input())
L=list(map(int,input().split()))
Stepenica(L,2,0,abs(L[0]-L[1]))
Problem p03160 (python)

Fixed submission:
import pdb
import sys

def solve(a,N):
    dp = [10**9 for x in xrange(N)]
    dp[0] = 0
    for i in xrange(N-1):
        if i+1 < N:
            dp[i+1] = min(dp[i+1],abs(a[i]-a[i+1])+dp[i])
        if i+2<N:
            dp[i+2] = min(dp[i+2],abs(a[i]-a[i+2])+dp[i])
        
    return dp[N-1]
    
if __name__=='__main__':
    N = int(raw_input())
    a = map(int,raw_input().split())
    print solve(a,N)

Buggy submission (verdict: Runtime Error):
import pdb
import sys

def solve(a,N,K):
    dp = [10**9 for x in xrange(N)]
    dp[0] = 0
    for i in xrange(N-1):
        for j in xrange(1,K+1):
            if i+j < N:
                dp[i+j] = min(dp[i+j],abs(a[i]-a[i+j])+dp[i])
            else:
                break
    return dp[N-1]
    
if __name__=='__main__':
    N,K = map(int,raw_input().split())
    a = map(int,raw_input().split())
    print solve(a,N,K)

Buggy submission (verdict: Runtime Error):
import pdb
import sys

def solve(a,N,K):
    dp = [10**9 for x in xrange(N)]
    dp[0] = 0
    for i in xrange(N-1):
        for j in xrange(1,K+1):
            if i+j < N:
                dp[i+j] = min(dp[i+j],abs(a[i]-a[i+j])+dp[i])
            else:
                break
    return dp[N-1]
    
if __name__=='__main__':
    N,K = map(int,raw_input().split())
    a = map(int,raw_input().split())
    print solve(a,N,K)

Buggy submission (verdict: Runtime Error):
import pdb
import sys

def solve(a,N,K):
    dp = [10**9 for x in xrange(N)]
    dp[0] = 0
    for i in xrange(N-1):
        for j in xrange(1,K+1):
            if i+j < N:
                dp[i+j] = min(dp[i+j],abs(a[i]-a[i+j])+dp[i])
            else:
                break
    return dp[N-1]
    
if __name__=='__main__':
    N,K = map(int,raw_input().split())
    a = map(int,raw_input().split())
    print solve(a,N,K)
Problem p03160 (python)

Fixed submission:
def jump_cost(value1, value2):
  return abs(value1 - value2)

def stone_jump(n, stones):
  cost = [float("inf")] * n
  cost[0] = 0

  for index in range(len(stones) - 1):
    cost[index + 1] = min(cost[index + 1], cost[index] + jump_cost(stones[index], stones[index + 1]))
    if index + 2 < n:
      cost[index + 2] = min(cost[index + 2], cost[index] + jump_cost(stones[index], stones[index + 2]))

  print(cost[-1])
  return cost[-1]

n = int(input())
stones = [int(i) for i in input().split()]
stone_jump(n, stones)

Buggy submission (verdict: Runtime Error):
def jump_cost(value1, value2):
  return abs(value1 - value2)

n = int(input())
stones = [int(i) for i in input().split()]
cost = [float("inf")] * n
cost[0] = 0

for index in range(len(stones) - 1):
  cost[index + 1] = min(cost[index + 1], cost[index] + jump_cost(stones[index], stones[index + 1]))
  if index + 2 < n:
    cost[index + 2] = min(cost[index + 2], cost[index] + jump_cost(stones[index], stones[index + 2]))

return cost[-1]

Buggy submission (verdict: Runtime Error):
  jumps = {}
  lowest_cost = None

  stack = []
  if n == 2:
    stack.append((0, 1, 0))
  elif n > 2:
    stack.append((0, 2, 0))
    stack.append((0, 1, 0))

  while stack:
    current_index, next_index, cost = stack.pop()
    next_path = (current_index, next_index)
    if next_path not in jumps:
      jumps[next_path] = abs(stones[current_index] - stones[next_index])

    new_cost = cost + jumps[next_path]
    if next_index + 1 == n:
      if lowest_cost is None or new_cost < lowest_cost:
        lowest_cost = new_cost
    elif next_index + 2 == n:
      stack.append((next_index, next_index + 1, new_cost))
    else:
      stack.append((next_index, next_index + 2, new_cost))
      stack.append((next_index, next_index + 1, new_cost))

  return lowest_cost
Problem p03160 (python)

Fixed submission:
n = int(input())
l = [int(i) for i in input().split(" ")]
dp = [0 for i in range(n + 1)]
dp[1] = abs(l[0] - l[1])
for i in range(2, n):
	dp[i] = min(dp[i - 1] + abs(l[i] - l[i - 1]), dp[i - 2] + abs(l[i] - l[i - 2]))
print(dp[n - 1])

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

@lru_cache(maxsize = None)

def dp(n):
	if n == 0:
		return 0
	if n == 1:
		return abs(l[0] - l[1])
	return min(dp(n - 1) + abs(l[n] - l[n - 1]), dp(n - 2) + abs(l[n] - l[n - 2]))

n = int(input())
l = [int(i) for i in input().split(" ")]

print(dp(n - 1))
Problem p03160 (python)

Fixed submission:
from functools import lru_cache
from sys import setrecursionlimit

setrecursionlimit(900010)

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

@lru_cache(maxsize=None)
def f(n):
	if n == 0: return 0
	if n == 1: return abs(a[0] - a[1])
	return min(f(n - 1) + abs(a[n - 1] - a[n]), f(n - 2) + abs(a[n - 2] - a[n]))

print(f(N - 1))

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

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

@lru_cache(maxsize=None)
def f(n):
	if n == 0: return 0
	if n == 1: return abs(a[0] - a[1])
	return min(f(n - 1) + abs(a[n - 1] - a[n]), f(n - 2) + abs(a[n - 2] - a[n]))

print(f(N - 1))
Problem p03160 (python)

Fixed submission:
INF=int(1e6)

N=int(input())
heights=[int(x) for x in input().split()]
# print('heights: ',heights)
dp=[INF]*N
# print(dp)
if(N==1):
  print(dp[0])
  exit()

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

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


# print('dp: ',dp)
print(dp[N-1])

#30->60->60->50
#30   30  30  40

Buggy submission (verdict: Runtime Error):
INF=int(1e6)

N=int(input())
heights=[int(x) for x in input().split()]
dp=[INF]*N
if(N==1):
  print(dp[0])
  exit()

dp[1]=heights[1]-heights[0]

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

    
print(dp[N])

Buggy submission (verdict: Runtime Error):
INF=int(1e6)

N=int(input())
heights=[int(x) for x in input().split()]
dp=[INF]*N
if(N==1):
  print(dp[0])
  return

dp[1]=heights[1]-heights[0]

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

    
print(dp[N])
Problem p03162 (python)

Fixed submission:
N=int(input())
inputs=[]
dp=[]
for _ in range(N):
    inputs.append([int(x) for x in input().split()])
    dp.append([0]*3)

for j in range(3):
    dp[0][j]=inputs[0][j]

for i in range(1,N):

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



print(max(dp[N-1]))

Buggy submission (verdict: Runtime Error):
N=int(input())
inputs=[]
dp=[]
for _ in range(N):
    inputs.append([int(x) for x in input().split()])
    dp.append([0]*3)

for j in range(3):
    dp[0][j]=inputs[0][j]

for i in range(1,N):

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


print(dp[N-1][N-1])
Problem p03160 (python)

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

d = [0] * n
d[1] = abs(a[0]-a[1])

for i in range(2, len(a)):
    d[i] = min(d[i-1]+abs(a[i]-a[i-1]), d[i-2]+abs(a[i]-a[i-2]))
print(d[-1])

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

d = [float("inf")] * n
d[0] = 0

for i in range(1, len(a)):
    s = max(i-k, 0)
    now=a[i] 
    d[i] = min(y + abs(now-x) for x, y in zip(a[s:i], d[s:i]))
print(d[-1])

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

d = [float("inf")] * n
d[0] = 0

for i in range(1, len(a)):
    s = max(i-k, 0)
    now = a[i]
    d[i] = min(y + abs(now-x) for x, y in zip(a[s:i], d[s:i]))
print(d[-1])
Problem p03160 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
def solve():
    N = int(input())
    cost = list(map(int, input().split()))
    memo = {}
    def helper(i):
        if i in memo:
            return memo[i]
        if i == 0:
            return 0
        # use i at i+1 or i+2
        if i - 2 >= 0:
            u1 = abs(cost[i-1] - cost[i]) + helper(i-1)
            u2 = abs(cost[i-2] - cost[i]) + helper(i-2)
            f = min(u1, u2)
        else:
            f = abs(cost[i-1] - cost[i]) + helper(i-1)
        memo[i] = f
        return f
    return helper(N-1)
print(solve())

Buggy submission (verdict: Runtime Error):
def solve():
    N = int(input())
    cost = list(map(int, input().split()))
    memo = {}
    def helper(i):
        if i in memo:
            return memo[i]
        if i == 0:
            return 0
        # use i at i+1 or i+2
        if i + 1 < N:
            f = abs(cost[i-1] - cost[i]) + helper(i-1)
        else:
            u1 = abs(cost[i-1] - cost[i]) + helper(i-1)
            u2 = abs(cost[i-2] - cost[i]) + helper(i-2)
            f = min(u1, u2)
        memo[i] = f
        return f
    return helper(N-1)
print(solve())
Problem p03294 (python)

Fixed submission:
n = int(input())
x = [int(i) for i in input().split()]
print(sum(x) - n)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = 0
x = [s += int(i) for i in input().split()]
print(s - n)
Problem p03633 (python)

Fixed submission:
import math

n = int(input())
a = []  
for i in range(n):
  a.append(int(input()))
if n == 1:
  print(a[0])
else:
  lcm = (a[0] * a[1]) // math.gcd(a[0], a[1])
  for i in range(2, n):
    lcm = (lcm * a[i]) // math.gcd(lcm, a[i])
  print(lcm)

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
a = []  
  for i in range(n):
    a.append(int(input()))
if n == 1:
  print(a[0])
else:
  lcm = (a[0] * a[1]) // math.gcd(a[0], a[1])
  for i in range(2, n):
    lcm = (lcm * a[i]) // math.gcd(lcm, a[i])
  print(lcm)

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
a = []
if n == 1:
  print(a[0])
else:
  
  for i in range(n):
    a.append(int(input()))
  lcm = (a[0] * a[1]) // math.gcd(a[0], a[1])
  for i in range(2, n):
    lcm = (lcm * a[i]) // math.gcd(lcm, a[i])
  print(lcm)

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
lcm = (a[0] * a[1]) // math.gcd(a[0], a[1])
for i in range(2, n):
  lcm = (lcm * a[i]) // math.gcd(lcm, a[i])
print(lcm)
Problem p03852 (python)

Fixed submission:
x = 'aeiou'
i = input()
if i in x:
  print("vowel")
else:
  print("consonant")

Buggy submission (verdict: Runtime Error):
x = 'aeiou'
i = input()
if i in x:
  print("vowel")
else
  print("consonant")
Problem p03262 (python)

Fixed submission:
def gcd(a,b):
    if b==0:
        return a 
    return gcd(b,a%b)
n,x = map(int,input().split())
l = [int(ele) for ele in input().split()]
l.append(x)
l.sort()
g = 0 
for i in range(1,n+1):
    g = gcd(g,l[i]-l[i-1])
print(g)

Buggy submission (verdict: Runtime Error):
from math import gcd
n,x = map(int,input().split())
l = [int(ele) for ele in input().split()]
l.append(x)
l.sort()
g = 0 
for i in range(1,n+1):
    g = gcd(g,l[i]-l[i-1])
print(g)
Problem p03633 (python)

Fixed submission:
#from math import * 
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b):
    return (a*b)//gcd(a,b)

ans=1
for _ in range(int(input())):
    ans=lcm(ans,int(input()))
print(ans)

Buggy submission (verdict: Runtime Error):
from math import * 
def lcm(a,b):
    return (a*b)//gcd(a,b)

ans=1
for _ in range(int(input())):
    ans=lcm(ans,int(input()))
print(ans)

Buggy submission (verdict: Runtime Error):
from math import * 
def lcm(a,b):
    return (a*b)//gcd(a,b)

ans=1
for _ in range(int(input())):
    ans=lcm(ans,int(input()))
print(ans)
Problem p03160 (python)

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

dp = [0]*n
for i in range(1,n):
	if i == 1:
		dp[i]=abs(a[0]-a[1])
	else:
		dp[i]=min(dp[i-1]+abs(a[i-1]-a[i]),dp[i-2]+abs(a[i-2]-a[i]))
print(dp[n-1])

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

def dp(i,n,a):
	if i==(n-1):
		return 0
	d1=1e10
	d2=1e10
	if(i+1<=n-1):
		d1=dp(i+1,n,a)+abs(a[i]-a[i+1])
	if(i+2<=n-1):
		d2=dp(i+2,n,a)+abs(a[i]-a[i+2])
	return min(d1,d2)

print(dp(0,n,a))

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

def dp(i,n,a):
	if i==(n-1):
		return 0
	elif i>n-1:
		return 1e9
	d1=1e9
	d2=1e9
	if(i+1<=n-1):
		d1=dp(i+1,n,a)+abs(a[i]-a[i+1])
	if(i+2<=n-1):
		d2=dp(i+2,n,a)+abs(a[i]-a[i+2])
	return min(d1,d2)

print(dp(0,n,a))
Problem p03166 (python)

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

n,m=map(int,input().split())
d={}
dp={}
n=[]

for _ in range(m):
	x,y=map(int,input().split())
	n.append(x)
	try:
		d[x].append(y)
	except:
		d[x]=[y]

def lp(a):
	if a in dp:
		return dp[a]
	if a not in d:
		dp[a]=1
		return 1
	ans=0
	for i in d[a]:
		ans=max(ans,1+lp(i))
	dp[a]=ans
	return ans

p=0
for i in n:
	p=max(p,lp(i))
print(p-1)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
d={}
dp={}

for _ in range(m):
	x,y=map(int,input().split())
	try:
		d[x].append(y)
	except:
		d[x]=[y]

def lp(a):
	if a in dp:
		return dp[a]
	if a not in d:
		dp[a]=1
		return 1
	ans=0
	for i in d[a]:
		ans=max(ans,1+lp(i))
	dp[a]=ans
	return ans

print(lp(x))
Problem p03167 (python)

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

h,w=map(int,input().split())
a=[]
dp={}
dp[(h-1,w-1)]=1
for i in range(h):
	a.append(list(input()))

def foo(i,j):
	if i>=h or j>=w:
		return 0
	if (i,j) in dp:
		return dp[(i,j)]
	ans=0
	if i+1<h and a[i+1][j]=='.':
		ans+=foo(i+1,j)
	if j+1<w and a[i][j+1]=='.':
		ans+=foo(i,j+1)
	dp[(i,j)]=ans%(1e9+7)
	return dp[(i,j)]

print(int(foo(0,0)))

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
a=[]
dp={}
dp[(h-1,w-1)]=1
for i in range(h):
	a.append(list(input()))

def foo(i,j):
	if i>=h or j>=w:
		return 0
	if (i,j) in dp:
		return dp[(i,j)]
	ans=0
	if i+1<h and a[i+1][j]=='.':
		ans+=foo(i+1,j)
	if j+1<w and a[i][j+1]=='.':
		ans+=foo(i,j+1)
	dp[(i,j)]=ans%(1e9+7)
	return dp[(i,j)]

print(int(foo(0,0)))