Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
from fractions import gcd
 
def number_calc(A,B,x):
  	if A%x == 0:
      left = A//x
    else:
      left = A//x + 1
    right = B//x
    res = max(right-left+1,0)
    return res
 
A,B,C,D = map(int,input().split())
 
ans = B-A+1
ans -=number_calc(A,B,C)
ans -=number_calc(A,B,D)
lcm = (C*D)//gcd(C,D)
ans +=number_calc(A,B,lcm)
 
print(ans)

Fixed submission:
import math
from fractions import gcd


A,B,C,D = map(int,input().split())
lcm = C//gcd(C,D)*D
ans = B - B//C - B//D + B//lcm
a = A-1
ans -= a - a//C - a//D + a//lcm 

print(ans)

Buggy python submission (verdict: Runtime Error):
import math
from fractions import gcd


A,B,C,D = map(int,input().split())
lcm = C//math.gcd(C,D)*D
ans = B - B//C - B//D + B//lcm
a = A-1
ans -= a - a//C - a//D + a//lcm 

print(ans)


Fixed submission:
import math
from fractions import gcd


A,B,C,D = map(int,input().split())
lcm = C//gcd(C,D)*D
ans = B - B//C - B//D + B//lcm
a = A-1
ans -= a - a//C - a//D + a//lcm 

print(ans)

Buggy python submission (verdict: Runtime Error):
import math
from fractions import gcd

def number_calc(A,B,x):
    left = math.ceil(A/x)
    right = math.floor(B/x)
    res = max(right-left+1,0)
    return res

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

ans = B-A+1
ans -=number_calc(A,B,C)
ans -=number_calc(A,B,D)
ans +=number_calc(A,B,(C*D)/math.gcd(C,D))

print(ans)



Fixed submission:
import math
from fractions import gcd


A,B,C,D = map(int,input().split())
lcm = C//gcd(C,D)*D
ans = B - B//C - B//D + B//lcm
a = A-1
ans -= a - a//C - a//D + a//lcm 

print(ans)

Buggy python submission (verdict: Runtime Error):
import math
def number_calc(A,B,x):
    left = math.ceil(A/x)
    right = math.floor(B/x)
    return (right - left + 1)

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

ans = B-A+1
ans -=number_calc(A,B,C)
ans -=number_calc(A,B,D)
ans +=number_calc(A,B,(C*D)/math.gcd(C,D))

print(ans)



Fixed submission:
import math
from fractions import gcd


A,B,C,D = map(int,input().split())
lcm = C//gcd(C,D)*D
ans = B - B//C - B//D + B//lcm
a = A-1
ans -= a - a//C - a//D + a//lcm 

print(ans)

Buggy python submission (verdict: Runtime Error):
import math
A,B,C,D = map(int,input().split())


def number(A,B,x):
    left = math.ceil(A/x)
    right = math.floor(B/x)
    return (right - left + 1)
    
ans = B-A+1
ans -=number(A,B,C)
ans -=number(A,B,D)
ans +=number(A,B,(C*D)/math.gcd(C,D))

print(ans)



Fixed submission:
import math
from fractions import gcd


A,B,C,D = map(int,input().split())
lcm = C//gcd(C,D)*D
ans = B - B//C - B//D + B//lcm
a = A-1
ans -= a - a//C - a//D + a//lcm 

print(ans)

Buggy python submission (verdict: Runtime Error):
import math
A,B,C,D = map(int,input().split())


def number(A,B,x):
    left = math.ceil(A/x)
    right = math.floor(B/x)
    return right - left + 1
    
    
    
    
ans = B-A+1
ans -=number(A,B,C)
ans -=number(A,B,D)
ans +=number(A,B,(C*D)//math.gcd(C,D))

print(ans)



Fixed submission:
import math
from fractions import gcd


A,B,C,D = map(int,input().split())
lcm = C//gcd(C,D)*D
ans = B - B//C - B//D + B//lcm
a = A-1
ans -= a - a//C - a//D + a//lcm 

print(ans)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
a = [int(input()) for _ in range(M)]
mod = 10 **9 + 7

import sys
for i in range(M-1):
    flag = a[i+1]-a[i]
    if flag == 1:
        print(0)
        sys.exit()
        
        
dp = [0] * (N+10)
dp[1] = 1
dp[2] = 1
dp[3] = 2
for i in range(3,N+5):
    dp[i+1] = dp[i] + dp[i-1]
    dp[i+1] %= mod
ans = 1
for i in range(M+1):
    if i == 0:
        number = a[i]
    elif i == M:
        number = N - a[i-1]
    else:
        number = a[i]-a[i-1] - 1
    number = max(1,number)
    ans *= dp[number]
    ans %= mod
print(ans)
    

Fixed submission:
N,M = map(int,input().split())
a = [int(input()) for _ in range(M)]
MOD = 10 **9 + 7

import sys
for i in range(M-1):
    flag = a[i+1]-a[i]
    if flag == 1:
        print(0)
        sys.exit()
        
        
dp = [0] * (N+10)
dp[1] = 1
dp[2] = 1
for i in range(1,N+5):
    dp[i+2] = dp[i+1] + dp[i]
    dp[i+2] %= MOD
    
if M == 0:
    print(dp[N+1])
    sys.exit()
ans = 1
for i in range(M+1):
    if i == 0:
        number = a[i]
    elif i == M:
        number = N - a[i-1]
    else:
        number = a[i]-a[i-1] - 1
    number = max(1,number)
    ans *= dp[number]
    ans %= MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]


left = [[0]*W for _ in range(H)]
right = [[0]*W for _ in range(H)]
top = [[0]*W for _ in range(H)]
bottom = [[0]*W for _ in range(H)]

for j in range(W):
    cnt = 0
    for i in range(H):
        if S[i][j] == '#':
            cnt = 0
        else:
            cnt += 1
            top[i][j] = cnt
            
for j in range(W):
    cnt = 0
    for i in reversed(range(H)):
        if S[i][j] == '#':
            cnt = 0
        else:
            cnt += 1
            bottom[i][j] = cnt
            
for i in range(H):
    cnt = 0
    for j in range(W):
        if S[i][j] == '#':
            cnt = 0
        else:
            cnt += 1
            left[i][j] = cnt
            
for i in range(H):
    cnt = 0
    for j in reversed(range(W)):
        if S[i][j] == '#':
            cnt = 0
        else:
            cnt += 1
            right[i][j] = cnt
                        
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans,left[i][j]+right[i][j]+top[i][j]+bottom[i][j]-3)
        
print(ans)

            

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


left = [[0]*W for _ in range(H)]
right = [[0]*W for _ in range(H)]
top = [[0]*W for _ in range(H)]
bottom = [[0]*W for _ in range(H)]

for j in range(W):
    cnt = 0
    for i in range(H):
        if S[i][j] == '#':
            cnt = 0
        else:
            cnt += 1
            top[i][j] = cnt
            
for j in range(W):
    cnt = 0
    for i in reversed(range(H)):
        if S[i][j] == '#':
            cnt = 0
        else:
            cnt += 1
            bottom[i][j] = cnt
            
for i in range(H):
    cnt = 0
    for j in range(W):
        if S[i][j] == '#':
            cnt = 0
        else:
            cnt += 1
            left[i][j] = cnt
            
for i in range(H):
    cnt = 0
    for j in reversed(range(W)):
        if S[i][j] == '#':
            cnt = 0
        else:
            cnt += 1
            right[i][j] = cnt
                        
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans,left[i][j]+right[i][j]+top[i][j]+bottom[i][j]-3)
        
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int((input()))
ab = [list(map(int,input().split())) for _ in range(N-1)]
c = list(map(int,input().split()))
c.sort(reverse = True)

al = [[] for _ in range(N+1)]
for a,b in ab:
    al[a].append(b)


d = [0] * (N)
d[ab[0][0]-1] = c[0]
cnt = 1
child = al[ab[0][0]]
ans = 0

while cnt < N:
    pi = int(child.pop())
    d[pi-1] = (c[cnt])
    ans += c[cnt]
    if al[pi]:
        child = child + al[pi]
    cnt += 1
    
print(ans)
print(' '.join(map(str,d)))
    
    
    
    

Fixed submission:
N = int((input()))
ab = [list(map(int,input().split())) for _ in range(N-1)]
c = list(map(int,input().split()))
c.sort(reverse = True)

al = [[] for _ in range(N+1)]
for a,b in ab:
    al[a].append(b)
    al[b].append(a)

d = [0] * (N)
d[ab[0][0]-1] = c[0]
cnt = 1
child = al[ab[0][0]]
ans = 0
Check = [True] * (N+1)
Check[ab[0][0]] = False

while child and cnt < N:
    pi = int(child.pop())
    Check[pi] = False
    d[pi-1] = (c[cnt])
    ans += c[cnt]
    for i in al[pi]:
        if Check[i]:child.append(i)
    cnt += 1
    
print(ans)
print(' '.join(map(str,d)))
Buggy python submission (verdict: Runtime Error):
N = int(input())
uvw = [list(map(int,input().split())) for _ in range(N-1)]
#testcase = open('testcase_04','r')
#contents = testcase.read()
#N = int(contents[0][0])
#uvw = [[int(j) for j in contents[i]]for i in range(1,N)]


ans = [0] * N
adj_list = [[] for _ in range(N+1)]

for u,v,w in uvw:
    adj_list[u-1].append([v-1,w])
    adj_list[v-1].append([u-1,w])
    
memo = [True] * N
def dfs(s,cnt): 
    memo[s] = False
    if cnt % 2 == 1:
        ans[s] = 1
    nxt = adj_list[s]
    for v,w in nxt:
        if memo[v]:
            dfs(v,cnt+w)
    return
    
dfs(0,0)
for a in ans:
    print(a)
    

    


Fixed submission:
N = int(input())
uvw = [list(map(int,input().split())) for _ in range(N-1)]
import sys
sys.setrecursionlimit(10000000)
#testcase = open('testcase_04','r')
#contents = testcase.read()
#contents = contents.split("\n")
#N = int(contents[0])
#uvw = [[0,0,0] for _ in range(N-1)]
#for i in range(N-1):
#    uvw[i] = [int(j) for j in contents[i+1].split()]
        


ans = [0] * N
adj_list = [[] for _ in range(N+1)]

for u,v,w in uvw:
    adj_list[u-1].append([v-1,w])
    adj_list[v-1].append([u-1,w])
    
memo = [True] * N
def dfs(s,cnt): 
    memo[s] = False
    if cnt % 2 == 1:
        ans[s] = 1
    nxt = adj_list[s]
    for v,w in nxt:
        if memo[v]:
            dfs(v,cnt+w)
    return
    
dfs(0,0)
for a in ans:
    print(a)

Buggy python submission (verdict: Runtime Error):

N = int(input())
uvw = [list(map(int,input().split())) for _ in range(N-1)]

ans = [0] * N
adj_list = [[] for _ in range(N)]

for u,v,w in uvw:
    adj_list[u-1].append([v-1,w])
    adj_list[v-1].append([u-1,w])
    
memo = [True] * N
def dfs(s,cnt): 
    memo[s] = False
    if cnt % 2 == 1:
        ans[s] = 1
    nxt = adj_list[s]
    for v,w in nxt:
        if memo[v]:
            dfs(v,cnt+w)
    return
    
dfs(0,0)
for a in ans:
    print(a)
    

    


Fixed submission:
N = int(input())
uvw = [list(map(int,input().split())) for _ in range(N-1)]
import sys
sys.setrecursionlimit(10000000)
#testcase = open('testcase_04','r')
#contents = testcase.read()
#contents = contents.split("\n")
#N = int(contents[0])
#uvw = [[0,0,0] for _ in range(N-1)]
#for i in range(N-1):
#    uvw[i] = [int(j) for j in contents[i+1].split()]
        


ans = [0] * N
adj_list = [[] for _ in range(N+1)]

for u,v,w in uvw:
    adj_list[u-1].append([v-1,w])
    adj_list[v-1].append([u-1,w])
    
memo = [True] * N
def dfs(s,cnt): 
    memo[s] = False
    if cnt % 2 == 1:
        ans[s] = 1
    nxt = adj_list[s]
    for v,w in nxt:
        if memo[v]:
            dfs(v,cnt+w)
    return
    
dfs(0,0)
for a in ans:
    print(a)
Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N= map(int,input().split())

cnt = 0
for i in range(N+1):
    for j in range(N+1):
        k = N - R*i- G*j
        if k<0 or k % B != 0 : continue
        k /= B
        cnt += 1
            
print(cnt)

Fixed submission:
R,G,B,N= map(int,input().split())

cnt = 0
for i in range(N+1):
    for j in range(N+1):
        k = N - R*i- G*j
        if k<0 or k % B != 0 : continue
        cnt += 1
            
print(cnt)
Buggy python submission (verdict: Runtime Error):
N= int(input())
S = [input() for _ in range(N)]

IB= [0] * (N)
LA = [0] * (N)
flag = True
Eflag = False
cntb= 0
cnta = 0
ans = 0
for i in range(N):
    if S[i][0] == 'B':
        IB[i] = 1
        cntb += 1
    if S[i][len(S[i])-1] == 'A' :
        LA[i] = 1
        cnta += 1
    if (IB[i] == 1 and LA[i] == 0) or (IB[i]==0 and LA[i] == 1):
        flag = False
    elif (IB[i] == 1 and LA[i] == 1):
        Eflag = True
    for j in range(len(S[i])):
        if S[i][j] == 'A' and S[i][j+1]=='B' : ans += 1
        
        
ans += min(cntb,cnta)
if Eflag and flag:    
    ans -= 1



print(ans)
    


Fixed submission:
N= int(input())
S = [input() for _ in range(N)]

IB= [0] * (N)
LA = [0] * (N)
flag = True
Eflag = False
cntb= 0
cnta = 0
ans = 0
for i in range(N):
    if S[i][0] == 'B':
        IB[i] = 1
        cntb += 1
    if S[i][len(S[i])-1] == 'A' :
        LA[i] = 1
        cnta += 1
    if (IB[i] == 1 and LA[i] == 0) or (IB[i]==0 and LA[i] == 1):
        flag = False
    elif (IB[i] == 1 and LA[i] == 1):
        Eflag = True
    for j in range(len(S[i])-1):
        if S[i][j] == 'A' and S[i][j+1]=='B' : ans += 1
        
        
ans += min(cntb,cnta)
if Eflag and flag:    
    ans -= 1



print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
S = list(S)
S2 = list(S)
ans = 0
i=0
while i < N-1:
    idx = i
    if S[i] == '#' and S[i+1] == '.':
        ans += 1
        
        i += 1
        
        for j in range(1,N):
            if idx -j < 0 or idx + 1 + j > N-1 : break

            if S[idx-j] == '#' and S[idx+1+j] == '.':
                
                ans += 1
                i += 1
            else:
                break
    i += 1

print(ans)
        
    
    

Fixed submission:
A,B,C = map(int,input().split())

if A>B:
    tmp = A
    A = B
    B = tmp
    
if C >= A and C <= B:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
S = list(S)
S2 = list(S)
ans = 0
while True:
    cnt = 0
    newS = list(S2)
    i = 0
    while i < (len(S2)-1):
        if S2[i] == '#' and S2[i+1] == '.':
            newS = newS[0:i-cnt*2] + newS[i+2 - cnt*2:]
            ans += 1
            cnt += 1
            i += 1
        i += 1
    S2 = list(newS)
    if cnt == 0:
        break

print(ans)
        
    
    

Fixed submission:
N = int(input())
S = input()

CW = 0

for s in S:
    if s == '.' : CW += 1
    
CB = 0
ans = (CB+CW)
for s in S:
    if s == '.' : CW -= 1
    if s == '#' : CB += 1
    ans = min(ans,CB+CW)
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))


C.sort()
C.reverse()
AB =[0]*(X*Y)

for i in range(X):
    for j in range(Y):
        AB[i*Y+j] =  A[i] + B[j]
        
AB.sort()
AB.reverse()
K2 = min(K,X*Y)
AB = AB[0:K2]
ABC = [0] * (K2*Z)
for i in range(K2):
    for j in range(Z):
        ABC[i*Z+j] = AB[i] + C[j]
        
ABC.sort()
ABC.reverse()
ABC = ABC[0:K]
for i in ABC:
    print(i)
        

Fixed submission:
X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))


C.sort()
C.reverse()
AB =[0]*(X*Y)

for i in range(X):
    for j in range(Y):
        AB[i*Y+j] =  A[i] + B[j]
        
AB.sort()
AB.reverse()
K2 = min(K,X*Y)
AB = AB[0:K2]
ABC = [0] * (K2*Z)
for i in range(K2):
    for j in range(Z):
        ABC[i*Z+j] = AB[i] + C[j]
        
ABC.sort()
ABC.reverse()
ABC = ABC[0:K]
for i in ABC:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
N,Q = map(int,input().split())
S = input()

l = [0] * Q
r = [0] * Q
for i in range(Q):
    l[i],r[i] = map(int,input().split())


for i in range(Q):
    ans = 0
    subseq = S[l[i]-1:r[i]]
    for j in range(len(subseq)-1):
        if (subseq[j] == 'A')and(subseq[j+1] == 'C'):
            ans += 1
    print(ans)

Fixed submission:
N,Q = map(int,input().split())
S = input()

l = [0] * Q
r = [0] * Q
for i in range(Q):
    l[i],r[i] = map(int,input().split())

ans = [0] * N


for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
        ans[i+1] = ans[i] + 1
    else:
        ans[i+1] = ans[i]
        
for j in range(Q):
    print(ans[r[j]-1]-ans[l[j]-1])
Buggy python submission (verdict: Runtime Error):
N = int(input())

modd = 1000_000_007
dp = [[[[0 for k in range(4)] for i in range(4) ]for j in range(4) ]for n in range(N+1)]

dp[0][3][3][3] = 1


for L in range(N):
    for i in range(4):
        
        for j in range(4):
        
            for k in range(4):
                if (dp[L][i][j][k]==0): continue
                for a in range(4):
                    if (a == 2 and i == 1 and j == 0):    continue
                    if (a == 2 and i == 0 and j == 1):    continue
                    if (a == 1 and i == 2 and j == 0):    continue
                    if (a == 2 and i == 1 and k == 0):    continue
                    if (a == 2 and j == 1 and k == 0):    continue
                    
                    dp[L+1][a][i][j] += dp[L][i][j][k]
                    dp[L+1][a][i][j] %= modd
  
ans = 0         
for i in range(4):
    for j in range(4):
        for k in range(4):
            ans += dp[N][i][j][k]
            ans %= modd
print(ans)
                

Fixed submission:
N = int(input())

modd = 1000000007
dp = [[[[0 for k in range(4)] for i in range(4) ]for j in range(4) ]for n in range(N+1)]

dp[0][3][3][3] = 1


for L in range(N):
    for i in range(4):
        
        for j in range(4):
        
            for k in range(4):
                if (dp[L][i][j][k]==0): continue
                for a in range(4):
                    if (a == 2 and i == 1 and j == 0):    continue
                    if (a == 2 and i == 0 and j == 1):    continue
                    if (a == 1 and i == 2 and j == 0):    continue
                    if (a == 2 and i == 1 and k == 0):    continue
                    if (a == 2 and j == 1 and k == 0):    continue
                    
                    dp[L+1][a][i][j] += dp[L][i][j][k]
                    dp[L+1][a][i][j] %= modd
  
ans = 0         
for i in range(4):
    for j in range(4):
        for k in range(4):
            ans += dp[N][i][j][k]
            ans %= modd
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A,B = map(int,input().split())

ans = A
for i in range(B-A):
    ans = ans ^ (A+i+1)
    
print(ans)

Fixed submission:
A,B = map(int,input().split())
keta = 0
tmp = B
twos = []
base = 1
while tmp > 0:
    tmp /= 2
    keta += 1
    base *= 2
    twos.append(base)

def func(n):
    if n%2 == 0:
        tmp = (n-1)//2
        ans = tmp%2 ^ n
    else:
        tmp = (n-1)//2 
        ans = tmp%2
    return ans
    
print(func(B)^func(A-1))
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = [list(map(int,input.split())) for _ in range(N)]

like = [0] * M

for i in range(N):
    for j in range(A[i][0]):
        like[A[i][j+1]] += 1
        
cnt = 0
for i in range(M):
    if like[i] == M:
        cnt += 1

print(cnt)

Fixed submission:
N,M = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(N)]
like = [0] * M

for i in range(N):
    for j in range(A[i][0]):
        like[A[i][j+1]-1] += 1
        
cnt = 0
for i in range(M):
    if like[i] == N:
        cnt += 1

print(cnt)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

ans = min(A)
aset = set(A)
A = list(aset)

for i in range(N):
    for j in range(i+1,N):
        aset.add(A[i] % A[j])
        
Alist = list(aset)
Alist.sort()
for i in range(1,len(Alist)):
    ans = min(ans,Alist[i]-Alist[i-1])

print(ans)    



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

ans = 2 ** 30

def GCD(a,b):
    c = a%b
    if c  == 0:
        return b
    return (GCD(b,c))

tmp = A[0]
for a in A[1:]:
    tmp = GCD(a,tmp)
    
print(tmp)
Buggy python submission (verdict: Runtime Error):

N = int(input())
H = list(map(int,input().split()))
inf = 10**9+7
dp = [inf] * (N+10)
import numpy as np
for i,h in enumerate(H[:N-1]):
    dp[i+1] = min(dp[i+1],dp[i] + np.abs(h[i]-h[i+1]))
    if i<N-2: dp[i+2] = min(dp[i+2],dp[i] + np.abs(h[i]-h[i+2]))
    
print(dp[N-1])

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

dp = [0] * 100010

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

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

Buggy python submission (verdict: Runtime Error):

N = int(input())
H = list(map(int,input().split()))
inf = 10**9+7
dp = [inf] * (N+10)
import numpy as np
for i,h in enumerate(H[:N-1]):
    dp[i+1] = min(dp[i+1],dp[i] + np.abs(h[i]-h[i+1]))
    if i>N-2: dp[i+2] = min(dp[i+2],dp[i] + np.abs(h[i]-h[i+2]))
    
print(dp[N-1])

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

dp = [0] * 100010

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

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

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

dp = [0] * 10010

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

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

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

dp = [0] * 100010

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

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

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

dp = [0] * 1010

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

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

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

dp = [0] * 100010

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

for i in range(2,N):
    dp[i] = min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2]) 
    
print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):

N,W = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(N)]

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

for i in range(1,N+1):
    for j in range(W+1):
        
        if j < wv[i-1][0]:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j],dp[i-1][j-wv[i-1][0]] + wv[i-1][1])

print(dp[N][W])


Fixed submission:

N,W = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(N)]

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

for i in range(1,N+1):
    for j in range(W+1):
        
        if j < wv[i-1][0]:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j],dp[i-1][j-wv[i-1][0]] + wv[i-1][1])

print(dp[N][W])
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
h = [int(input()) for _ in range(N)]

h = sorted(h)
Lh = len(h)
while Lh > K:
    print(h)
    head = h[1] - h[0]
    tail = h[Lh-1]-h[Lh-2]
    if head > tail:
        h = h[1:]
    else:
        h = h[:Lh-1]
    Lh = len(h)
        
print(h[Lh-1]-h[0])


Fixed submission:
N,K = map(int,input().split())
h = [int(input()) for _ in range(N)]

h = sorted(h)
hK = h[0:K]
ans = hK[K-1]-h[0]
for i in range(N-K+1):
    ans = min(ans,h[i+K-1]-h[i])

print(ans)
Buggy python submission (verdict: Runtime Error):
S = list(input())
T = list(input())

dic = {}
sets = set()
flag = True
for s,t in S,T:
  if s in sets:
    if dic[s] != t:
      flag = False
      break
  else:
    sets.add(s)
    dic[s] = t
    
if flag:
  print('Yes')
else:
  print('No')

Fixed submission:
#from collections import Counter

S = list(input())
T = list(input())

dics = {}
dicst= {}
sets = set()
sett = set()
flag = True
for i in range(len(S)):
    s = S[i]
    t = T[i]
    if s in sets and t in sett:
        if dics[s] != t or dicst[t] != s:
            flag = False
            break
    elif s in sets and not(t in sett):
        flag = False
        break
    elif t in sett and not(s in sets):
        flag = False
        break
    else:
        sets.add(s)
        sett.add(t)
        dics[s] = t
        dicst[t] = s
    
print('Yes') if flag else print('No')