Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math

A, B = map(int,input().split())

def soinsu(test):
    list_sosu = []
    x = 0
    while x==0:
        for i in range(2,test+1):
            if i > math.sqrt(test):
                list_sosu.append(test)
                x = 1
                break
            elif test % i == 0:
                test = int(test/i)
                if test == 1:
                    x = 1
                list_sosu.append(i)
                break
    return set(list_sosu)

if A == 1 or B == 1:
    print(1)
    
else:
    print(len(soinsu(A)&soinsu(B))+1)

Fixed submission:
# coding: utf-8
# Your code here!
N = int(input())
 
if N%2 == 0:
     print(0.5)
else:
    print(1-int(N/2)/N)
Buggy python submission (verdict: Time Limit Exceeded):
import math

A, B = map(int,input().split())

def soinsu(test):
    list_sosu = []
    x = 0
    while x==0:
        for i in range(2,test+1):
            if test % i == 0:
                test = int(test/i)
                if test == 1:
                    x = 1
                list_sosu.append(i)
                break
    return set(list_sosu)

if A == 1 or B == 1:
    print(1)
    
else:
    print(len(soinsu(A)&soinsu(B))+1)

Fixed submission:
import math

A, B = map(int,input().split())

def soinsu(test):
    list_sosu = []
    x = 0
    while x==0:
        for i in range(2,test+1):
            if i > int(math.sqrt(test)):
                list_sosu.append(test)
                x = 1
                break
            elif test % i == 0:
                test = int(test/i)
                if test == 1:
                    x = 1
                list_sosu.append(i)
                break
    return set(list_sosu)

if A == 1 or B == 1:
    print(1)
    
else:
    print(len(soinsu(A)&soinsu(B))+1)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

N, M = map(int,input().split())
hen = [list(map(int,input().split())) for i in range(M)]
S, T = map(int,input().split())
hen2 = []
for i in range(N):
    a = []
    for j in hen:
        if j[0]==i+1:
            a.append(j[1])
    hen2.append(a)

queue = [[S,0]]
check = []
dist = [0]

while True:
    if queue == []:
        print(-1)
        break
    Now = queue.pop(0)
    ndist = dist.pop(0)
    if Now == [T,0]:
        print(int(ndist/3))
        break
    
    check.append(Now)
    for i in hen2[Now[0]-1]:
        if [i,(Now[1]+1)%3] not in check:
            queue.append([i,(Now[1]+1)%3])
            dist.append(ndist+1)
            

Fixed submission:
S = input()

S = list(S)
S.sort()
if S[0] == S[1] and S[2] == S[3]:
    if S[1]!=S[2]:
        print("Yes")
    else:
        print("No")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import math
N,K = map(int,input().split())
mod = 1000000007

for j in range(K):
    i = j+1
    x = math.factorial(K-1)//(math.factorial(K-i)*math.factorial(i-1))
    y = math.factorial(N-K+1)//(math.factorial(N-K+1-i)*math.factorial(i))
    ans = x*y
    ans = int(ans%mod)
    print(ans)
    

Fixed submission:
import math
N,K = map(int,input().split())
mod = 1000000007

for j in range(K):
    i = j+1
    p = N-K+1-i
    if p <0:
        p = 0
    x = math.factorial(K-1)//(math.factorial(K-i)*math.factorial(i-1))
    y = math.factorial(N-K+1)//(math.factorial(p)*math.factorial(i))
    ans = x*y
    ans = int(ans%mod)
    print(ans)

Buggy python submission (verdict: Runtime Error):
import math
N,K = map(int,input().split())
mod = 1000000007

for j in range(K):
    i = j+1
    x = math.factorial(K-1)/math.factorial(K-i)//math.factorial(i-1)
    y = math.factorial(N-K+1)/math.factorial(N-K+1-i)//math.factorial(i)
    ans = int(x*y)
    ans = ans%mod
    print(ans)
    

Fixed submission:
import math
N,K = map(int,input().split())
mod = 1000000007

for j in range(K):
    i = j+1
    p = N-K+1-i
    if p <0:
        p = 0
    x = math.factorial(K-1)//(math.factorial(K-i)*math.factorial(i-1))
    y = math.factorial(N-K+1)//(math.factorial(p)*math.factorial(i))
    ans = x*y
    ans = int(ans%mod)
    print(ans)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

N,K=map(int,input().split())

if K=1:
    print(0)
else:
    print(N-K)
    

Fixed submission:
# coding: utf-8
# Your code here!

N,K=map(int,input().split())

if K==1:
    print(0)
else:
    print(N-K)
Buggy python submission (verdict: Runtime Error):
N=int(input()) 
A=int(input()) 
B=int(input()) 
C=int(input()) 
D=int(input()) 
E=int(input())

x = [A,B,C,D,E] 
pace = min(x) 
y = int(N/pace)
if pace = 1:
    print(y+4)
else:
    print(y+5)

Fixed submission:
N=int(input()) 
A=int(input()) 
B=int(input()) 
C=int(input()) 
D=int(input()) 
E=int(input())

x = [A,B,C,D,E] 
pace = min(x) 
y = int(N/pace)
if pace == 1:
    print(y+4)
else:
    print(y+5)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = [int(s) for s in input().split()]
A = []
for _ in range(M):
    A.append(int(input()))

counts = [0] * (N + 1)
for i in range(N + 1):
    if i == 0:
        counts[i] = 1
    elif i == 1:
        if i not in A:
            counts[i] = 1
    else:
        for j in [i - 2, i - 1]:
            if j not in A and i not in A:
                counts[i] += counts[j]
                counts[i] %= 1000000007

print(counts[N])


Fixed submission:
N, M = [int(s) for s in input().split()]
A = []
for _ in range(M):
    A.append(int(input()))
A = set(A)

counts = [0] * (N + 1)
for i in range(N + 1):
    if i == 0:
        counts[i] = 1
    elif i == 1:
        if i not in A:
            counts[i] = 1
    else:
        if i not in A:
            for j in [i - 2, i - 1]:
                if j not in A:
                    counts[i] += counts[j]
                    counts[i] %= 1000000007

print(counts[N])
Buggy python submission (verdict: Time Limit Exceeded):
L = input()
n = 1

for i, s in enumerate(L[::-1]):
    if s == '1':
        n = n * 2 + 3 ** i
        n %= 10 ** 9 + 7

print(n)


Fixed submission:
import sys
sys.setrecursionlimit(10000)

L = input()
n = 1
p = (1, 0)  # 3 ** 0 = 1
mod = 10 ** 9 + 7

for i in range(len(L)):
    if L[len(L) - 1 - i] == '1':
        k = (p[0] * (3 ** (i - p[1]))) % mod
        n = n * 2 + k
        n %= mod
        p = (k, i)

print(n)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N, K = [int(s) for s in input().split()]
V = [int(s) for s in input().split()]

que = deque([(0, [], V, 0, True, True)])  # total, negative items, deque, count, left_flag, right_flag
best = 0
while que:
    t, s, v, n, lf, rf = que.pop()
    if n >= K:
        best = max([best, t + sum(s)])
        continue
    if v:
        if lf:
            if v[0] >= 0:
                best = max([best, t + v[0] + sum(s)])
                que.append((t + v[0], s, v[1:], n + 1, lf, rf))
            else:
                que.append((t, s + [v[0]], v[1:], n + 1, lf, rf))
        if rf and len(v) > 1:
            if v[-1] >= 0:
                best = max([best, t + v[-1] + sum(s)])
                que.append((t + v[-1], s, v[:-1], n + 1, lf, rf))
            else:
                que.append((t, s + [v[-1]], v[:-1], n + 1, lf, rf))
    if s:
        s.sort()
        que.append((t, s[1:], [s[0]] + v, n + 1, False, rf))
        que.append((t, s[1:], v + [s[0]], n + 1, lf, False))
        best = max([best, t + sum(s[1:])])

print(best)

Fixed submission:
from collections import deque

N, K = [int(s) for s in input().split()]
V = [int(s) for s in input().split()]

best = 0
for a in range(min([K, N]) + 1):
    for b in range(min([K, N]) - a + 1):
        L = V[:a] + V[N - b:]
        Lp = [i for i in L if i >= 0]
        Lm = [i for i in L if i < 0]
        Lm.sort()
        s = sum(Lp + Lm[min([len(Lm), K - a - b]):])
        best = max([best, s])

print(best)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N, K = [int(s) for s in input().split()]
V = [int(s) for s in input().split()]

que = deque([(set(), V, 0)])
best = 0
while que:
    s, v, n = que.pop()
    if n >= K:
        best = max([best, sum(s)])
        continue
    if v:
        que.append((s | set([v[0]]), v[1:], n + 1))
        if len(v) > 1:
            que.append((s | set([v[-1]]), v[:-1], n + 1))
    if s:
        for i in s:
            que.append((s - set([i]), [i] + v, n + 1))
            que.append((s - set([i]), v + [i], n + 1))

print(best)

Fixed submission:
from collections import deque

N, K = [int(s) for s in input().split()]
V = [int(s) for s in input().split()]

best = 0
for a in range(min([K, N]) + 1):
    for b in range(min([K, N]) - a + 1):
        L = V[:a] + V[N - b:]
        Lp = [i for i in L if i >= 0]
        Lm = [i for i in L if i < 0]
        Lm.sort()
        s = sum(Lp + Lm[min([len(Lm), K - a - b]):])
        best = max([best, s])

print(best)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
S2 = [s == 'W' for s in S]

min_num = N
for i in range(N):
    min_num = min([min_num, sum(S2[:i]) + N - i - sum(S2[i + 1:]) - 1])

print(min_num)


Fixed submission:
N = int(input())
S = input()
total = [0] * (N + 1)
for i in range(N):
    if S[i] == 'W':
        total[i + 1] = total[i] + 1
    else:
        total[i + 1] = total[i]

min_num = min(total[i] + (N - i - 1) - (total[N] - total[i + 1]) for i in range(N))

print(min_num)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

min_num = N
for i in range(N):
    min_num = min([min_num, S[:i].count('W') + S[i + 1:].count('E')])

print(min_num)


Fixed submission:
N = int(input())
S = input()
total = [0] * (N + 1)
for i in range(N):
    if S[i] == 'W':
        total[i + 1] = total[i] + 1
    else:
        total[i + 1] = total[i]

min_num = min(total[i] + (N - i - 1) - (total[N] - total[i + 1]) for i in range(N))

print(min_num)
Buggy python submission (verdict: Runtime Error):
n = int(input())
t = list(str(input()))
if n%2 == 1:
    print("No")
else:
    ans = True
    a = ["" for i in range(int(n/2))]
    b = ["" for i in range(int(n/2))]
    for i in range(int(n/2)):
        a[i] = t[i]
        b[i] = t[int(n/2)+i]
    for i in range(int(n/2)):
        ans = ans and a[i] == b[i]
if ans:
    print("Yes")
else:
    print("No")

Fixed submission:
n = int(input())
t = list(str(input()))
if n%2 == 1:
    print("No")
else:
    ans = True
    a = ["" for i in range(int(n/2))]
    b = ["" for i in range(int(n/2))]
    for i in range(int(n/2)):
        a[i] = t[i]
        b[i] = t[int(n/2)+i]
    for i in range(int(n/2)):
        ans = ans and a[i] == b[i]
    if ans:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
n,x=list(map(int,input().split()))
l=list(map(int,input().split()))
i=0
p=0
while p<=x or i<n:
    p=p+l[i]
    i+=1
print(i)

Fixed submission:
n,x=list(map(int,input().split()))
l=list(map(int,input().split()))
i=0
p=0
while i<n:
    p=p+l[i]
    if p>x:
        break
    i+=1
print(i+1)

Buggy python submission (verdict: Runtime Error):
n,x=list(map(int,input().split()))
l=list(map(int,input().split()))
i=0
p=0
while p<=x:
    p=p+l[i]
    i+=1
print(i)

Fixed submission:
n,x=list(map(int,input().split()))
l=list(map(int,input().split()))
i=0
p=0
while i<n:
    p=p+l[i]
    if p>x:
        break
    i+=1
print(i+1)
Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
    if b==0:
        return max(a,b)
    else:
        if a%b == 0:
            return(b)
        else:
            return gcd(b,a%b)
n = int(input())
a = list(map(int,input().split()))
l=[0 for i in range(n+1)]
r=[0 for i in range(n+1)]

for i in range(1,n):
    l[i]=gcd(l[i-1],a[i-1])
    r[i]=gcd(r[i-1],a[n-i])
for i in range(n):
    e[i] = gcd(l[i],r[n-1-i])
print(max(e))


Fixed submission:
def gcd(a,b):
    if b==0:
        return max(a,b)
    else:
        if a%b == 0:
            return(b)
        else:
            return gcd(b,a%b)
n = int(input())
a = list(map(int,input().split()))
l=[0 for i in range(n)]
r=[0 for i in range(n)]
e=[0 for i in range(n)]
for i in range(1,n):
    l[i]=gcd(l[i-1],a[i-1])
    r[i]=gcd(r[i-1],a[n-i])
for i in range(n):
    e[i] = gcd(l[i],r[n-1-i])
print(max(e))

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a):
    b = sorted(a)
    c = [0 for i in range(len(b))]
    for i in range(len(b)):
        if b[i]%b[0]==0:
            c[i]=b[0]
        else:
            c[i]=b[i]%b[0]
    d=sorted(c)
    if d[0]==d[-1]:
        return d[0]
    else:
        return gcd(c)
n = int(input())
a = list(map(int,input().split()))
e = [0 for i in range(n)]
for i in range(n):
    e[i] = gcd(a[:i]+a[i+1:])
print(max(e))


Fixed submission:
def gcd(a,b):
    if b==0:
        return max(a,b)
    else:
        if a%b == 0:
            return(b)
        else:
            return gcd(b,a%b)
n = int(input())
a = list(map(int,input().split()))
l=[0 for i in range(n)]
r=[0 for i in range(n)]
e=[0 for i in range(n)]
for i in range(1,n):
    l[i]=gcd(l[i-1],a[i-1])
    r[i]=gcd(r[i-1],a[n-i])
for i in range(n):
    e[i] = gcd(l[i],r[n-1-i])
print(max(e))
Buggy python submission (verdict: Runtime Error):
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define MOD 1000000007
#define endl "\n"
#define sz(a) (int)((a).size())
#define all(x) (x).begin(), (x).end()
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define OTP(s) cout<<s<<endl;
#define FOR(i,j,k,l) for(int i=j;i<k;i+=l)
#define REP(i,j) FOR(i,0,j,1)
inline ll add(ll a, ll b){a += b; if(a >= MOD)a -= MOD; return a;}
inline ll sub(ll a, ll b){a -= b; if(a < 0)a += MOD; return a;}
inline ll mul(ll a, ll b){return (ll)((ll) a * b %MOD);}
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

ll min(ll a,ll b)
{
    return a>b?b:a;
}
ll max(ll a,ll b)
{
    return a>b?a:b;
}

ll n;
double q[3000][3000];
double p[10000];
int main()
{
    IOS
    cin>>n;
    REP(i,n)
    {
        cin>>p[i+1];
    }
    double prod=1;

    q[0][0]=1;
    FOR(i,1,n+1,1)
    {
        prod*=0;
        q[0][i]=prod;
    }
    prod=1;
    REP(i,n)
    {
        prod*=p[i+1];
        q[i+1][0] = prod;
    }
    FOR(i,1,n+1,1)
    {
        FOR(j,1,i+1,1)
        {
            q[i][j] = p[i]*q[i-1][j] + (1-p[i])*q[i-1][j-1];
        }
    }
    // REP(i,n+1)
    // {
    //     REP(j,n+1)
    //     {
    //         cout<<q[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    double ans = 0;
    REP(i,(n-1)/2+1)
    {
        ans+=q[n][i];
    }
    cout<<fixed<<setprecision(12)<<ans<<endl;
}

Fixed submission:
n = int(input())
p = list(map(float, input().split()))
q=[]
q.append([1])
for i in range(n):
    q[0].append(0)
prod = 1.0
for i in range(1,n+1):
    prod*=p[i-1]
    q.append([prod])

for i in range(1,n+1):
    for j in range(1,n+1):
        try:
            q[i].append(p[i-1]*q[i-1][j] + (1-p[i-1])*q[i-1][j-1])
        except:
            print(i)
            print(j)
        #print(q)
ans = 0.0
for i in range(0,(n-1)//2+1):
    ans+=q[n][i]
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
a,b=map(int,input().split())
print(a*b//math.gcd(a,b))

Fixed submission:
from fractions import gcd
a,b=map(int,input().split())
print(a*b//gcd(a,b))
Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
    if b==0: return a
    return gcd(b,a%b)

n=int(input())
x=[*map(int,input().split())]
a=x[0]
for i in range(1,n):
    a=gcd(a,x[i])
print(a)

Fixed submission:
def gcd(a,b):
    if b==0: return a
    return gcd(b,a%b)

n=int(input())
x=list(map(int,input().split()))
a=x[0]
for i in range(1,n):
    a=gcd(a,x[i])
print(a)

Buggy python submission (verdict: Runtime Error):
import math
n=int(input())
x=[*map(int,input().split())]
a=x[0]
for i in range(1,n):
    a=math.gcd(a,x[i])
print(a)

Fixed submission:
def gcd(a,b):
    if b==0: return a
    return gcd(b,a%b)

n=int(input())
x=list(map(int,input().split()))
a=x[0]
for i in range(1,n):
    a=gcd(a,x[i])
print(a)
Buggy python submission (verdict: Runtime Error):
import numpy as np


n = int(input())
p = [float(x) for x in input().split()]
dp = np.zeros((n+1,n+1))
dp[0][1] =  p[0]
dp[0][0] = 1-p[0]
for i  in range(n):
    if i<=0:
        continue
    dp[i][0] = dp[i-1][0]*(1-p[i])
    for j in range(i+1):
        dp[i][j+1] = dp[i-1][j]*p[i]
        dp[i][j+1] += dp[i-1][j+1]*(1-p[i])

k = int(n/2)+1
ans = 0
#print(dp)
for j in range(k, n+1):
    ans += dp[n-1][j]
print(ans)

Fixed submission:
n = int(input())
p = [float(x) for x in input().split()]
dp = []
for i in range(n+1):
    tp = []
    for j in range(n+1):
        tp.append(0)
    dp.append(tp)
dp[0][1] =  p[0]
dp[0][0] = 1-p[0]
for i  in range(n):
    if i<=0:
        continue
    dp[i][0] = dp[i-1][0]*(1-p[i])
    for j in range(i+1):
        dp[i][j+1] = dp[i-1][j]*p[i]
        dp[i][j+1] += dp[i-1][j+1]*(1-p[i])

k = int(n/2)+1
ans = 0
#print(dp)
for j in range(k, n+1):
    ans += dp[n-1][j]
print(ans)
Buggy python submission (verdict: Runtime Error):
def candy():
   n=int(input())
    a=0
    for i in range (0,n)
       a=a+1
    print(a)
    
candy(10)
       

Fixed submission:
def candy():
  n=int(input())
  a=0
  for i in range (1,n+1):
    a=a+i

  print(a)
    

candy()
Buggy python submission (verdict: Runtime Error):
def key():
    a=input()
    b=input()
    c=input()
    d=input()
    key=[a,b,c,d]
    if key[0]=='b':
        print('')
    elif key[0]=='0':
        print('0')
    else:
        print('1')
    if key[1]=='b':
        key.pop()
    elif key[1]=='0':
        print('0')
    else:
        print('1')
    if key[2]=='b':
        key.pop()
    elif key[2]=='0':
        print('0')
    else:
        print('1')
    if key[3]=='b':
        key.pop()
    elif key[3]=='0':
        print('0')
    else:
        print('1')

key()


Fixed submission:
def key():
    a=input()
    b=''
    for i in range(0,len(a)):
        if a[i]=='0':
            b+='0'
        elif a[i]=='1':
            b+='1'
        elif a[i]=='B':
            if len(b)==0:
                continue
            else:
                b=b[0:-1]
    print(b)

key()

Buggy python submission (verdict: Runtime Error):
def sig():
    key=[input()]   q
    a=key[0]
    if a =='0':
       key.append('0')
    elif a=='1':
       key.append('1')
    else:
       key.append('')
    for i in key:
        b=key[i]
        if b =='0':
           key.append('0')
        elif b=='1':   
           key.append('1')
        else:
            key.pop(i-1)

    print(key)

sig()


Fixed submission:
def key():
    a=input()
    b=''
    for i in range(0,len(a)):
        if a[i]=='0':
            b+='0'
        elif a[i]=='1':
            b+='1'
        elif a[i]=='B':
            if len(b)==0:
                continue
            else:
                b=b[0:-1]
    print(b)

key()
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = map(int,raw_input().split())

amax = (max(a))
amin = (min(a))

res = abs(amax-amin)
print (res) 

Fixed submission:
N = int(input())

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

amax = (max(a))
amin = (min(a))

res = abs(amax-amin)
print (res)

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = map(int,raw_input().split())

amax = (max(a))
amin = (min(a))

res = abs(amax-amin)
print res 

Fixed submission:
N = int(input())

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

amax = (max(a))
amin = (min(a))

res = abs(amax-amin)
print (res)
Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
    while a:
        a, b = b % a, a
    return b

A, B = map(int, input().split())
print(A // GCD(A, B) * B)

Fixed submission:
def GCD(a, b):
    while a:
        a, b = b % a, a
    return b


def main():
    A, B = map(int, input().split())
    print(A // GCD(A, B) * B)


main()
Buggy python submission (verdict: Runtime Error):
def ch_min(a, b):
    if (a > b):
        a = b
    return a


if __name__ == "__main__":
    N = int(input())
    h = list(map(int, input().split()))
    INF = 10 ** 10
    dp = [INF] * 100010
    dp[0] = 0
    for i in range(N):
        dp[i + 1] = ch_min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]))
        dp[i + 2] = ch_min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]))
    print(dp[N - 1])


Fixed submission:
def ch_min(a, b):
    if (a > b):
        a = b
    return a


if __name__ == "__main__":
    N = int(input())
    h = list(map(int, input().split()))
    INF = 10 ** 10
    dp = [INF] * 100010
    dp[0] = 0
    for i in range(1, N):
        dp[i] = ch_min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
        if (i > 1):
            dp[i] = ch_min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))
    print(dp[N - 1])
Buggy python submission (verdict: Time Limit Exceeded):
def ch_min(a, b):
    if (a > b):
        a = b
    return a


if __name__ == "__main__":
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    INF = 10 ** 10
    dp = [INF] * (10 ** 5 + 10)
    dp[0] = 0
    for i in range(N):
        for k in range(1, K + 1):
            if (i - k >= 0):
                dp[i] = ch_min(dp[i], dp[i - k] + abs(h[i] - h[i - k]))
    print(dp[N - 1])


Fixed submission:
import numpy as np
N, K = map(int, input().split())
H = np.array(list(map(int, input().split())) + [0] * (K + 2), np.int32)
INF = 10 ** 9
dp = np.array([INF] * (N + K + 2), np.int32)
dp[0] = 0

for i in range(N):
    dp[i + 1:i + K + 1] = np.minimum(dp[i + 1:i + K + 1],
                                     dp[i] + np.abs(H[i + 1:i + K + 1] - H[i]))
print(dp[N - 1])

Buggy python submission (verdict: Runtime Error):
def ch_min(a, b):
    if (a > b):
        a = b
    return a


if __name__ == "__main__":
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    print(f'h = {h}')
    INF = 10 ** 10
    dp = [INF] * (10 ** 5 + 10)
    dp[0] = 0
    for i in range(N):
        for k in range(1, K + 1):
            if (i - k >= 0):
                dp[i] = ch_min(dp[i], dp[i - k] + abs(h[i] - h[i - k]))
    print(dp[N - 1])


Fixed submission:
import numpy as np
N, K = map(int, input().split())
H = np.array(list(map(int, input().split())) + [0] * (K + 2), np.int32)
INF = 10 ** 9
dp = np.array([INF] * (N + K + 2), np.int32)
dp[0] = 0

for i in range(N):
    dp[i + 1:i + K + 1] = np.minimum(dp[i + 1:i + K + 1],
                                     dp[i] + np.abs(H[i + 1:i + K + 1] - H[i]))
print(dp[N - 1])
Buggy python submission (verdict: Runtime Error):
import sys
inputs = list(map(int, sys.stdin))
N = inputs[0]
a = inputs[1:N]
isFound = False
ai = 1
for i in range(1, N + 1):
    ai = a[ai - 1]
#    print(f'a{i} = {ai}')
    if (ai == 2):
        isFound = True
        print(i)
        break
if (isFound is False):
    print(-1)


Fixed submission:
N = int(input())
a = [int(input()) for i in range(N)]
isFound = False
ai = 1
for i in range(1, N + 1):
    ai = a[ai - 1]
#    print(f'a{i} = {ai}')
    if (ai == 2):
        isFound = True
        print(i)
        break
if (isFound is False):
    print(-1)

Buggy python submission (verdict: Runtime Error):
import sys
Input = list(map(int, sys.stdin))
N = Input[0]
a = Input[1:N]
isFound = False
ai = 1
for i in range(1, N + 1):
    ai = a[ai - 1]
#    print(f'a{i} = {ai}')
    if (ai == 2):
        isFound = True
        print(i)
        break
if (isFound is False):
    print(-1)


Fixed submission:
N = int(input())
a = [int(input()) for i in range(N)]
isFound = False
ai = 1
for i in range(1, N + 1):
    ai = a[ai - 1]
#    print(f'a{i} = {ai}')
    if (ai == 2):
        isFound = True
        print(i)
        break
if (isFound is False):
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = 1
for i in range(N):
    ans = ans * (i + 1)
print(ans % (10**9 + 7))

Fixed submission:
N = int(input())
ans = 1
for i in range(2, N + 1):
    ans = (ans * i) % (10**9 + 7)
print(ans)
Buggy python submission (verdict: Runtime Error):
N, K input().split()
print(K * (K - 1) ** (N - 1))

Fixed submission:
N, K = map(int, input().split())
print(K * (K - 1) ** (N - 1))