ZhenlongDai/ACPR huggingface dataset:
Problem: p03854
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
s = input()

s = s[::-1]
lis = ['dream', 'dreamer', 'erase', 'eraser']
nlis = []
for i in lis:
    nlis.append(i[::-1])

flag = 0
for _ in range(10**5+1):
    for j in nlis:
        if s.startswith(j):
            s = s.replace(j, '')
        else:
            break
    
    if s == '':
        flag = 1
        break


if flag:
    print('YES')
else:
    print('NO')

Failing test case input:
dreameraser

Expected output:
YES

Actual output:
NO


Fixed submission (verdict: Accepted):
s = input()

s = s[::-1]
lis = ['dreamer', 'dream', 'eraser', 'erase']
nlis = []
for i in lis:
    nlis.append(i[::-1])


for i in range(10**5 + 1):
    for j in nlis:
        if s.startswith(j):
            s = s[len(j):]


if s == '':
    print('YES')
else:
    print('NO')

Problem: p03854
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
s = input()
i = 0
while s[i:5] != '':
    if s[i:5] == 'dream':
        if s[i+5:i+10] == 'dream':
            i += 5
        elif s[i+5:i+10] == 'erase':
            i += 5
        elif s[i+5:i+7] == 'er':
            i += 7
        else:
            print('No')
            sys.exit(0)
    elif s[i:5] == 'erase':
        if s[i+5:i+10] == 'dream':
            i += 5
        elif s[i+5:i+10] == 'erase':
            i += 5
        elif s[i+5:i+6] == 'r':
            i += 6
        else:
            print('No')
            sys.exit(0)
    else:
        print('No')
        sys.exit(0)

print('Yes')

Failing test case input:
eq`sedream

Expected output:
NO


Actual output:
No


Fixed submission (verdict: Accepted):
import sys
s = input()
i = 0
while s[i:i+5] != '':
    if s[i:i+5] == 'dream':
        if s[i+5:i+10] == 'dream':
            i += 5
        elif s[i+5:i+10] == 'erase':
            i += 5
        elif s[i+5:i+7] == 'er':
            i += 7
        else:
            i += 5
    elif s[i:i+5] == 'erase':
        if s[i+5:i+10] == 'dream':
            i += 5
        elif s[i+5:i+10] == 'erase':
            i += 5
        elif s[i+5:i+6] == 'r':
            i += 6
        else:
            i += 5
    else:
        print('NO')
        sys.exit(0)
print('YES')

Problem: p03854
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import re
S = input()
Snew = S[::-1]
print(Snew)
if re.sub('^maerd|remaerd|resare|esare$',"",Snew) == "":
    print("Yes")
else:
    print("No")

Failing test case input:
maerdesare

Expected output:
NO


Actual output:
erasedream
No


Fixed submission (verdict: Accepted):
import re
S = input()
Snew = S[::-1]
result = re.sub('maerd|remaerd|resare|esare',"",Snew)
if  result == "":
    print("YES")
else: 
    print("NO")
Problem: p03854
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()

def calc(s):
    if s == "":
        return print("Yes")
    if s.find("dreameraser") != -1:
        s = s.replace("dreameraser", "")
        return calc(s)
    elif s.find("dreamerase") != -1:
        s = s.replace("dreamerase", "")
        return calc(s)        
    elif s.find("dreamer") != -1:
        s = s.replace("dreamer", "")
        return calc(s)
    elif s.find("dream") != -1:
        s = s.replace("dream", "")
        return calc(s)
    elif s.find("eraser") != -1:
        s = s.replace("eraser", "")
        return calc(s)
    elif s.find("erase") != -1:
        s = s.replace("erase", "")
        return calc(s)
    return print("No")

calc(s)

Failing test case input:
reqem`erc

Expected output:
NO


Actual output:
No


Fixed submission (verdict: Accepted):
s = input()

def calc(s):
    if s == "":
        return print("YES")
    if s.find("dreameraser") != -1:
        s = s.replace("dreameraser", "")
        return calc(s)
    elif s.find("dreamerase") != -1:
        s = s.replace("dreamerase", "")
        return calc(s)        
    elif s.find("dreamer") != -1:
        s = s.replace("dreamer", "")
        return calc(s)
    elif s.find("dream") != -1:
        s = s.replace("dream", "")
        return calc(s)
    elif s.find("eraser") != -1:
        s = s.replace("eraser", "")
        return calc(s)
    elif s.find("erase") != -1:
        s = s.replace("erase", "")
        return calc(s)
    return print("NO")

calc(s)

Problem: p03854
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()[::-1]
words = ['maerd', 'remaerd', 'esare', 'resare']
flag = 0
for _ in range(25000):
    if flag==4:
        break
    else:
        flag=0
    for word in words:
        l = len(word)
        if s[0:l] == word:
            s = s[l:]
        else:
            flag+=1
if flag==4:
    print('No')
else:
    print('Yes')


Failing test case input:
eccrqgl`rra

Expected output:
NO


Actual output:
No


Fixed submission (verdict: Accepted):
s = input()[::-1]
words = ['maerd', 'remaerd', 'esare', 'resare']
flag = 0
for _ in range(25000):
    if flag==4 or len(s)==0:
        break
    else:
        flag=0
    for word in words:
        l = len(word)
        if s[0:l] == word:
            s = s[l:]
        else:
            flag+=1
if flag==4:
    print('NO')
else:
    print('YES')

Problem: p03854
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
s_list = ["eraser","erase","dreamer","dream"]
for i in range(4):
	s.replace(s_list[i],'')
if len(s) == 0:
	print("YES")
else:
	print("NO")

Failing test case input:
dreameraser

Expected output:
YES

Actual output:
NO


Fixed submission (verdict: Accepted):
s = input()
s_list = ["eraser","erase","dreamer","dream"]
for i in range(4):
	s = s.replace(s_list[i],"")
if len(s):
	print("NO")
else:
	print("YES")
Problem: p03854
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

if input().rstrip().replace("dream","D").replace("erase","E").replace("Der","").replace("Eer","").replace("D","").replace("E","") == "":
    print( "YES" )
else:
    print( "NO" )


Failing test case input:
dreameraser

Expected output:
YES

Actual output:
NO


Fixed submission (verdict: Accepted):
if input().rstrip().replace("dream","D").replace("erase","E").replace("Der","").replace("Er","").replace("D","").replace("E","") == "":
    print( "YES" )
else:
    print( "NO" )

Problem: p03854
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
t = ["dream","dreamer","erase","eraser"]



t_r = []
for i in range(len(t)):
    t_r.append(t[i][::-1])
    
s = input()
s_r = s[::-1]

flag = True
for i in range(len(s_r)):
    flag2 = False
    for j in t_r:
        tmp_s = s_r[i:len(j)]       
        if(tmp_s == j):
            flag2 = True
            i += len(j)
    if flag2 == False:
        flag = False
        break

if flag==True:
    print("YES")
else:
    print("NO")

Failing test case input:
dreameraser

Expected output:
YES

Actual output:
NO


Fixed submission (verdict: Accepted):
t = ["dream","dreamer","erase","eraser"]



t_r = []
for i in range(len(t)):
    t_r.append(t[i][::-1])
    
s = input()
s_r = s[::-1]


flag = True

i=0
while(i<len(s_r)):
    flag2 = False
   
    for j in range(len(t_r)):
        t = t_r[j] 
        tmp_s = s_r[i:i+len(t)]
        
        
        if(tmp_s == t):
            flag2 = True
            i += len(t)
    if flag2 == False:
        flag = False
        break

if flag==True:
    print("YES")
else:
    print("NO")

Problem: p03854
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
S = input()

S = S.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')

if S:
    print('No')
else:
    print('Yes')

Failing test case input:
bre`meqer

Expected output:
NO


Actual output:
No


Fixed submission (verdict: Accepted):
S = input()

S = S.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')

if S:
    print('NO')
else:
    print('YES')

Problem: p03854
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S=input()
W=["dream","dreamer","erase","eraser"]

ans="Yes"
while len(S)>0:
  if S.endswith(W[0]):
    S=S[:-len(W[0])]
  elif S.endswith(W[1]):
    S=S[:-len(W[1])]
  elif S.endswith(W[2]):
    S=S[:-len(W[2])]
  elif S.endswith(W[3]):
    S=S[:-len(W[3])]
  else:
    ans="No"
    break
    
print(ans)

Failing test case input:
p_eedo`btm

Expected output:
NO


Actual output:
No


Fixed submission (verdict: Accepted):
S=input()
W=["dream","dreamer","erase","eraser"]

ans="YES"
while len(S)>0:
  if S.endswith(W[0]):
    S=S[:-len(W[0])]
  elif S.endswith(W[1]):
    S=S[:-len(W[1])]
  elif S.endswith(W[2]):
    S=S[:-len(W[2])]
  elif S.endswith(W[3]):
    S=S[:-len(W[3])]
  else:
    ans="NO"
    break
    
print(ans)
Problem: p03854
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

S = input()
word = ["dream","dreamer","erase","eraser"]

S = S[::-1] 
for i in range(len(word)): word[i] = word[i][::-1] 

print(S, S[5:], S[11:] == "")

while True:
    for i in range(len(word)):
        flag2 = False
        if word[i] == S[:len(word[i])]:
            flag2 = True
            S = S[len(word[i]):]
            break
    if S == "":
        print("YES")
        break 
    elif flag2 == False:
        print("NO")
        break 





Failing test case input:
qeqdm`esc

Expected output:
NO


Actual output:
cse`mdqeq dqeq True
NO


Fixed submission (verdict: Accepted):

S = input()
word = ["dream","dreamer","erase","eraser"]

S = S[::-1] 
for i in range(len(word)): word[i] = word[i][::-1] 

while True:
    for i in range(len(word)):
        flag2 = False
        if word[i] == S[:len(word[i])]:
            flag2 = True
            S = S[len(word[i]):]
            break
    if S == "":
        print("YES")
        break 
    elif flag2 == False:
        print("NO")
        break

Problem: p03854
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

def main():
    S = input()

    S = S.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
    print('Yes' if len(S)==0 else 'No')

if __name__ == '__main__':
    main()


Failing test case input:
dte`mfqeq

Expected output:
NO


Actual output:
No


Fixed submission (verdict: Accepted):
import sys

def main():
    S = input()

    S = S.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
    print('YES' if len(S)==0 else 'NO')

if __name__ == '__main__':
    main()

Problem: p03854
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
s = s[::-1]

w = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]

current_position = 0


while current_position < len(s):
    if s[current_position] == 'm':
        current_position += 5
    
    elif s[current_position] == 'r' and s[current_position+2] == 'm':
        current_position += 7
    
    elif s[current_position] == 'r' and s[current_position+2] == 's':
        current_position += 6
    
    elif s[current_position] == 'e':
        current_position += 5
    
    else:
        break
    
if current_position == len(s):
    print('YES')

else:
    print('NO')
    

Failing test case input:
er`sedream

Expected output:
NO


Actual output:
YES


Fixed submission (verdict: Accepted):
s = input()
s = s[::-1]

w = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]

current_position = 0


while current_position <= len(s):
    if s[current_position:current_position+5] == w[0]:
        current_position += 5
    
    elif s[current_position:current_position+7] == w[1]:
        current_position += 7
    
    elif s[current_position:current_position+6] == w[3]:
        current_position += 6
    
    elif s[current_position:current_position+5] == w[2]:
        current_position += 5
    
    else:
        break
    
if current_position == len(s):
    print('YES')
else:
	print('NO')
Problem: p03854
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
S = list(S)
s = ''.join(list(reversed(S)))
def main(s):
  s = s.strip('esare' 'maerd' 'resare''remaerd')
  return s
if main(s) == '':
  print('YES')
elif main(s) != '':
  print('NO')


Failing test case input:
resaremaerd

Expected output:
NO


Actual output:
YES


Fixed submission (verdict: Accepted):
S = input()
S = list(S)
s = ''.join(list(reversed(S)))
def main(s):
  l = ["resare", "esare","remaerd", "maerd"]
  for i in l:
    s = s.replace(i, '')
  return s
if main(s) == '':
  print('YES')
elif main(s) != '':
  print('NO')

Problem: p03854
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input().replace("dream","").replace("dreamer","").replace("erase","").replace("eraser","")
if s:
  print("NO")
else:
  print("YES")

Failing test case input:
dreameraser

Expected output:
YES

Actual output:
NO


Fixed submission (verdict: Accepted):
s = input().replace('eraser','').replace('erase','').replace('dreamer','').replace('dream','')
if s:
    print('NO')
else:
    print('YES')

Problem: p03854
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
t = ''
while s:
    a = ''
    for i in ['dream', 'dreamer', 'erase', 'eraser']:
        if s.startswith(i) : a = i
    if a == '' : print('NO');exit()
    s = s[len(a):]
print('YES')

Failing test case input:
dreameraser

Expected output:
YES

Actual output:
NO


Fixed submission (verdict: Accepted):
s = input()
t = ''
while s:
    a = ''
    for i in ['eraser', 'erase', 'dreamer', 'dream']:
        if s.endswith(i) : a = i; break
    if a == '' : print('NO');exit()
    s = s[:-len(a)]
print('YES')

Problem: p03854
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if s:
	print("No")
else:
	print("Yes")


Failing test case input:
arr`egqccrl

Expected output:
NO


Actual output:
No


Fixed submission (verdict: Accepted):
s = input().replace("eraser","").replace("erase","").replace("dreamer","").replace("dream","")
if s:
    print("NO")
else:
    print("YES")

Problem: p03854
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
word=input()

wordList=["dream","dreamer","erase","eraser"]



while 1:
  if word[len(word)-5:]==wordList[0]:
    word=word[:len(word)-5]
  elif word[len(word)-7:]==wordList[1]:
    word=word[:len(word)-7]
  elif word[len(word)-5:]==wordList[2]:
    word=word[:len(word)-5]
  elif word[len(word)-7:]==wordList[3]:
    word=word[:len(word)-7]
  else:
    print("false")
    break
  if word=="":
    print("true")
    break

Failing test case input:
dreamerer

Expected output:
NO

Actual output:
false


Fixed submission (verdict: Accepted):
word=input()

wordList=["dream","dreamer","erase","eraser"]



while 1:
  if word[len(word)-5:]==wordList[0]:
    word=word[:len(word)-5]
  elif word[len(word)-7:]==wordList[1]:
    word=word[:len(word)-7]
  elif word[len(word)-5:]==wordList[2]:
    word=word[:len(word)-5]
  elif word[len(word)-6:]==wordList[3]:
    word=word[:len(word)-6]
  else:
    print("NO")
    break
  if word=="":
    print("YES")
    break
Problem: p03854
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()

result = "NO"

while True:
    if S[-5:-1] == "dream":
        if len(S) == 5:
            result = "YES"
            break
        S.rstrip("dream")
    elif S[-5:-1] == "erase":
        if len(S) == 5:
            result = "YES"
            break
        S.rstrip("erase")
    elif S[-6:-1] == "eraser":
        if len(S) == 6:
            result = "YES"
            break
        S.rstrip("eraser")
    elif S[-7:-1] == "dreamer":
        if len(S) == 7:
            result = "YES"
            break
        S.rstrip("dreamer")
    else:
        break

print(result)

Failing test case input:
dreameraser

Expected output:
YES

Actual output:
NO


Fixed submission (verdict: Accepted):
S = input()

result = "NO"

while True:
    if S[-5:] == "dream":
        if len(S) == 5:
            result = "YES"
            break
        S = S[:-5]
    elif S[-5:] == "erase":
        if len(S) == 5:
            result = "YES"
            break
        S = S[:-5]
    elif S[-6:] == "eraser":
        if len(S) == 6:
            result = "YES"
            break
        S = S[:-6]
    elif S[-7:] == "dreamer":
        if len(S) == 7:
            result = "YES"
            break
        S = S[:-7]
    else:
        break

print(result)

Problem: p03854
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):


S=input()
T=[]

l=-1
while l>=-len(S):
    if S[l]=="r":
        if l-2<-len(S):
            print("NO");break
        elif S[l-2]=="s":
            T+="eraser"[::-1]
            l-=6
        else:
            T+="dreamer"[::-1]
            l-=7
    elif S[l]=="e":
        T+="erase"[::-1]
        l-=5
    elif S[l]=="m":
        T+="dream"[::-1]
        l-=5
    else:
        print("NO");break
        
if S=="".join(T[::-1]):
    print("YES")


Failing test case input:
er`sedream

Expected output:
NO


Actual output:

Fixed submission (verdict: Accepted):
S=input()
T=[]

l=-1
while l-2>=-len(S):
    k=S[l:l-3:-1]
    if k=="mae":
        T+="dream"[::-1]
        l-=5
    elif k=="rem":
        T+="dreamer"[::-1]
        l-=7
    elif k=="esa":
        T+="erase"[::-1]
        l-=5
    elif k=="res":
        T+="eraser"[::-1]
        l-=6
    else:
        break
if S=="".join(T[::-1]):
    print("YES")
else:
    print("NO")
Problem: p03854
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
q = [0]
flag = False
while len(s) > 0:
    if s[0:5] in ['dream','erase'] and flag == False:
        q.append(s[0:5])
        s = s[5:]
        flag = False
    elif s[0:6] == 'eraser':
        q.append(s[0:6])
        s = s[6:]
        flag = False
    elif s[0:7] == 'dreamer':
        q.append(s[0:7])
        s = s[7:]
        flag = False
    elif q[-1] in ['dream','erase']:
        s = q[-1] + s
        q.pop()
        flag = True
    else:
        print('NO')
        exit()

print('Yes')


Failing test case input:
dreameraser

Expected output:
YES

Actual output:
Yes


Fixed submission (verdict: Accepted):
s = input()
q = [0]
flag = False
while len(s) > 0:
    if s[0:5] in ['dream','erase'] and flag == False:
        q.append(s[0:5])
        s = s[5:]
        flag = False
    elif s[0:6] == 'eraser':
        q.append(s[0:6])
        s = s[6:]
        flag = False
    elif s[0:7] == 'dreamer':
        q.append(s[0:7])
        s = s[7:]
        flag = False
    elif q[-1] in ['dream','erase']:
        s = q[-1] + s
        q.pop()
        flag = True
    else:
        print('NO')
        exit()

print('YES')

Problem: p03854
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()


S = S.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')

if S is '':
    print('YES')
else:
    print('NO')
print(S)

Failing test case input:
`tbmodee_p

Expected output:
NO


Actual output:
NO
`tbmodee_p


Fixed submission (verdict: Accepted):
S = input()


S = S.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')

if S is '':
    print('YES')
else:
    print('NO')
Problem: p03160
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def min_cost():
    
    len_costs = input()
    costs = input().split(' ')
    costs = list(map(int, costs))
    dp = [None for i in range(len(costs))]
    dp[0] = 0
    dp[1] = abs(costs[1] - costs[0])
    for i in range(2, len(costs)):
        dp[i] = min(abs(costs[i] - costs[i - 1]), abs(costs[i] - costs[i - 2]))
        dp[i] += dp[i - 1] if abs(costs[i] - costs[i - 1]) < abs(costs[i] - costs[i - 2]) else dp[i - 2]
    print(dp[-1])
    return dp[-1]

min_cost()





Failing test case input:
4
8 146 105 28

Expected output:
174


Actual output:
256


Fixed submission (verdict: Accepted):
def min_cost():
    
    len_costs = input()
    costs = input().split(' ')
    costs = list(map(int, costs))
    dp = [float('inf') for i in range(len(costs))]
    dp[0] = 0
    for i in range(len(costs)):
        for j in [i + 1, i + 2]:
            if j < len(costs):
                dp[j] = min(dp[j], dp[i] + abs(costs[i] - costs[j]))
    print(dp[-1])
    return dp[-1]

min_cost()

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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(n-2):
  dp[i+2]=min(dp[i]+abs(h[i+2]-h[i]),dp[i+1]+abs(h[i+2]-h[i]))
print(dp[n-1])


Failing test case input:
4
2 77 45 13

Expected output:
75


Actual output:
107


Fixed submission (verdict: Accepted):
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(n-2):
  dp[i+2]=min(dp[i]+abs(h[i+2]-h[i]),dp[i+1]+abs(h[i+2]-h[i+1]))
print(dp[n-1])

Problem: p03160
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
lst=list(map(int,input().split()))
dp=[0 for i in range(n)]
dp[1]=abs(lst[0]-lst[1])
for i in range(2,len(lst)):
  dp[i]=min(dp[i-1]+lst[i-1],dp[i-2]+lst[i-2])
print(dp[n-1])

Failing test case input:
4
8 146 162 28

Expected output:
256


Actual output:
170


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

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

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

res = [0]*n

for i in range(n):
  if i == 1:
    res[1] = abs(h[0] - h[1])
  temp1 = abs(h[i] - h[i-2])
  temp2 = abs(h[i] - h[i-1])
  
  res[i] = min(res[i-2] + temp1, res[i-1] + temp2)
  
print(res[n-1])

Failing test case input:
4
2 91 71 13

Expected output:
127


Actual output:
138


Fixed submission (verdict: Accepted):
import math
 
n = int(input())
h = list(map(int, input().split()))
 
res = [0]*n
 
for i in range(1, n):
  if i == 1:
    res[1] = abs(h[0] - h[1])
  else:
    temp1 = abs(h[i] - h[i-2])
    temp2 = abs(h[i] - h[i-1])
    
    res[i] = min(res[i-2] + temp1, res[i-1] + temp2)
  
print(res[n-1])
Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
h=list(map(int,input().split()))
DP=[0,abs(h[0]-h[1])]
for i in range(n-2):
    DP+=[min(h[-1]+abs(h[i]-h[i+1]),h[-2]+abs(h[i]-h[i+2]))]
print(DP[-1])

Failing test case input:
4
0 0 2 -92

Expected output:
92


Actual output:
-90


Fixed submission (verdict: Accepted):
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[-1]+abs(h[i+1]-h[i+2]),DP[-2]+abs(h[i]-h[i+2]))]
print(DP[-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
h = [int(i) for i in input().split()]
dp = [float("inf")]*N

dp[0] = 0

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

print(dp[-1])

Failing test case input:
6
3 0 1 45 52 26

Expected output:
65


Actual output:
19


Fixed submission (verdict: Accepted):
N = int(input())
h = [int(i) for i in input().split()]
dp = [float("inf")]*N

dp[0] = 0

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

print(dp[-1])

Problem: p03160
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
lis = list(map(int,input().split(' ')))
def sol(lis):
    if len(lis)<=2:
        return abs(lis[0]-lis[1])
    costs = [0,abs(lis[0]-lis[1])]
    for i in range(2,len(lis)):
        x = abs(lis[i]-lis[i-1])
        y = abs(lis[i]-lis[i-2])
        if x<y:
            costs.append(x+costs[-1])
        else:
            costs.append(y+costs[-2])
    return costs[-1]
print(sol(lis))

Failing test case input:
4
2 77 54 37

Expected output:
69


Actual output:
115


Fixed submission (verdict: Accepted):
def sol(lis):
    if len(lis)<=2:
        return abs(lis[0]-lis[1])
    costs = [0,abs(lis[0]-lis[1])]
    for i in range(2,len(lis)):
        x = abs(lis[i]-lis[i-1])
        y = abs(lis[i]-lis[i-2])
        costs.append(min(x+costs[-1],y+costs[-2]))
    return costs[-1]
input()
lis = list(map(int,input().split(' ')))
print(sol(lis))

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
h=[0]+list(map(int,input().split()))
dp=[0]*(2*n)
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-1]+abs(h[i]-h[i-2]))
print(dp[n-1])

Failing test case input:
4
-1 -1 -2 24

Expected output:
25


Actual output:
1


Fixed submission (verdict: Accepted):
n=int(input())
h=list(map(int,input().split()))
dp=[0,abs(h[1]-h[0])]+[99999999]*102000
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])
Problem: p03160
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

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


         
table = [0]*N
flag = [[False]*N]

for i in range(N-1):
    if i == 0:
        table[i+1] = table[i] + abs(H[i]-H[i+1])
    elif i <= N-3:
        table[i+2] = min(
            table[i] + abs(H[i]-H[i+2]),
            table[i+1] + abs(H[i+1] - H[i+2])
        )
    else: 
        table[i+1] = table[i] + abs(H[i]-H[i+1])
    print(table)

print(table[-1])

Failing test case input:
6
30 10 60 10 60 57

Expected output:
33


Actual output:
[0, 20, 0, 0, 0, 0]
[0, 20, 0, 20, 0, 0]
[0, 20, 0, 20, 0, 0]
[0, 20, 0, 20, 0, 3]
[0, 20, 0, 20, 0, 3]
3


Fixed submission (verdict: Accepted):

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


         
table = [0]*N
flag = [[False]*N]

for i in range(1, N):

    if i == 1:
        table[i] = table[i-1] + abs(H[i-1]-H[i])
    else:
        table[i] = min(
            table[i-2] + abs(H[i-2]-H[i]),
            table[i-1] + abs(H[i-1] - H[i])
        )


print(table[-1])

Problem: p03160
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
cost_list = [ int(v) for v in input().split() ]
if n == 1:
	ans = 0
elif n == 2:
	ans = abs(cost_list[0]-cost_list[1])
else:
	ans_list =  [0, abs(cost_list[0]-cost_list[1])] + [ 10**9+1 for i in range(n-2) ]
	for i in range(2,n):
		ans_list[i] = min(ans_list[i-2]+abs(cost_list[i-2]-cost_list[i]),ans_list[i-1]+abs(cost_list[i-1]-cost_list[i])) 
	print(ans_list[-1])


Failing test case input:
2
33 10

Expected output:
23


Actual output:

Fixed submission (verdict: Accepted):
n = int(input())
cost_list = [ int(v) for v in input().split() ]
if n == 1:
	ans = 0
elif n == 2:
	ans = abs(cost_list[0]-cost_list[1])
else:
	ans_list =  [0, abs(cost_list[0]-cost_list[1])] + [ 10**9+1 for i in range(n-2) ]
	for i in range(2,n):
		ans_list[i] = min(ans_list[i-2]+abs(cost_list[i-2]-cost_list[i]),ans_list[i-1]+abs(cost_list[i-1]-cost_list[i])) 
	ans = ans_list[-1]

print(ans)

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
stage = list(map(int, input().split(" ")))

INF = float('inf')
DP = [INF for i in range(N)]

for i in range(N):
    if i == 1:
        DP[i] = abs(stage[i] - stage[i-1])
    elif i == 2:
        DP[i] = min(abs(stage[i] - stage[i-1]), abs(stage[i] - stage[i-2]))
    else:
        DP[i] = min(DP[i-1] + abs(stage[i] - stage[i-1]), DP[i-2] + abs(stage[i] - stage[i-2]))

print(DP[N-1])

Failing test case input:
4
2 77 54 13

Expected output:
93


Actual output:
64


Fixed submission (verdict: Accepted):
N = int(input())
stage = list(map(int, input().split(" ")))

INF = float('inf')
DP = [INF for i in range(N)]

for i in range(N):
    if i == 1:
        DP[i] = abs(stage[i] - stage[i-1])
    elif i == 2:
        DP[i] = min(abs(stage[i] - stage[i-2]), DP[i-1] + abs(stage[i] - stage[i-2]))
    else:
        DP[i] = min(DP[i-1] + abs(stage[i] - stage[i-1]), DP[i-2] + abs(stage[i] - stage[i-2]))

print(DP[N-1])
Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
h = list(map(int,input().split()))
c = [0]*n
c[1]=abs(h[1]-h[0])
for i in range(1,n):
    c[i]=min(c[i-2]+abs(h[i]-h[i-2]),c[i-1]+abs(h[i]-h[i-1]))
print(c[n-1])

Failing test case input:
6
30 12 60 17 60 9

Expected output:
31


Actual output:
16


Fixed submission (verdict: Accepted):
n = int(input())
h = list(map(int,input().split()))
c = [0]*n
c[1]=abs(h[1]-h[0])
for i in range(2,n):
    c[i]=min(c[i-2]+abs(h[i]-h[i-2]),c[i-1]+abs(h[i]-h[i-1]))
print(c[n-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a = [int(x) for x in input().split()]
def dp(N,a):
    F = [0]*(len(a)+1)
    F[0]=0
    F[1]=0
    F[2]=abs(a[1]-a[0])
    if N == 1: return F[0]
    elif N == 2: return F[1]
    
    for n in range(2,N+1):
        F[n] = min(F[n-1] + abs(a[n-1]-a[n-2]),F[n-2]+abs(a[n-1]-a[n-3]))
    print(F)
    return F[-1] 
print(dp(N,a))

Failing test case input:
2
-2 255

Expected output:
257


Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
a = [int(x) for x in input().split()]
def dp(N,a):
    F = [0]*(len(a))
    F[0]=0
    F[1]=abs(a[1]-a[0])
    if N == 1: return F[0]
    elif N == 2: return F[1]
    for n in range(2,N):
        F[n] = min(F[n-1] + abs(a[n]-a[n-1]),F[n-2]+abs(a[n]-a[n-2]))
    return F[-1] 
print(dp(N,a))

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
h = list(map(int,input().split()))
dp = [0] * N
for i in range(1, N):
    if i == 1:
        dp[i] = abs(h[1] - h[0])
    else:
        dp[i] = min(abs(h[i] - h[i-1]), abs(h[i] - h[i-2]))
print(dp[N-1])


Failing test case input:
4
43 11 -2 2

Expected output:
41


Actual output:
4


Fixed submission (verdict: Accepted):
N = int(input())
h = list(map(int,input().split()))
dp = [0] * N
for i in range(1, N):
    if i == 1:
        dp[i] = abs(h[1] - h[0])
    else:
        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])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
l=list(map(int,input().split()))
m=[0,abs(l[1]-l[0])]
if n==2:
    print(m[1])
else:
    p1=abs(l[2]-l[0])
    p2=abs(m[1]+l[2]-l[1])
    m.append(min(p1,p2))
    for i in range(3,n):
        p1=m[i-2]+abs(l[i]-l[i-2])
        p2=m[i-1]+abs(l[i]-l[i-1])
        m.append(min(p1,p2))
    print(abs(m[-1]))

Failing test case input:
4
29 7 0 2

Expected output:
27


Actual output:
17


Fixed submission (verdict: Accepted):
n=int(input())
l=list(map(int,input().split()))
m=[0,abs(l[1]-l[0])]
if n==2:
    print(m[1])
else:
    p1=abs(l[2]-l[0])
    p2=m[1]+abs(l[2]-l[1])
    m.append(min(p1,p2))
    for i in range(3,n):
        p1=m[i-2]+abs(l[i]-l[i-2])
        p2=m[i-1]+abs(l[i]-l[i-1])
        m.append(min(p1,p2))
    print(abs(m[-1]))
Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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):
    a = dp[i-1] + abs(h[i]-h[i-1])
    b = dp[i-2] + abs(h[i]-h[i-2])
    dp[i] = min(a,b)

print(dp)
print(dp[n-1])

Failing test case input:
2
112 1

Expected output:
111


Actual output:
[0, 111]
111


Fixed submission (verdict: Accepted):
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):
    a = dp[i-1] + abs(h[i]-h[i-1])
    b = dp[i-2] + abs(h[i]-h[i-2])
    dp[i] = min(a,b)


print(dp[n-1])

Problem: p03160
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def aFrog(N,h):
    dp = [0 for i in range(10)]
    dp[0] = 0
    dp[1] = abs(h[1]-h[0])
    print(dp)
    for i in range(2,N):
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
    return dp[N-1]

Failing test case input:
4
0 -1 2 -156

Expected output:
156


Actual output:

Fixed submission (verdict: Accepted):
N = int(input())
h = list(map(int, input().split()))
    
inf = 10**9
dp = [0] + [inf]*N
    
for i in range(1,N):
    if i == 1:
        dp[1] = abs(h[1]-h[0])
    else:
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
    
print(dp[N-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
arr = [int(i) for i in input().split()]
dp = [0 for i in range(n)]
print(dp)
for i in range(1,n):
    op1 = abs(arr[i]-arr[i-1]) + dp[i-1]
    op2 = abs(arr[i]-arr[i-2]) + dp[i-2] if i != 1 else float("inf")
    dp[i] = min(op1,op2)
print(dp[n-1])

Failing test case input:
4
1 0 0 -101

Expected output:
102


Actual output:
[0, 0, 0, 0]
102


Fixed submission (verdict: Accepted):
n = int(input())
arr = [int(i) for i in input().split()]
dp = [0 for i in range(n)]
for i in range(1,n):
    op1 = abs(arr[i]-arr[i-1]) + dp[i-1]
    op2 = abs(arr[i]-arr[i-2]) + dp[i-2] if i != 1 else float("inf")
    dp[i] = min(op1,op2)
print(dp[n-1])

Problem: p03160
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
H = list(map(int, input().split()))
dp = [float('inf')] * N
dp[0] = 0
for i in range(1, N):
    dp[i] = min(dp[i-1] + abs(H[i]-H[i-1]), dp[i-2] + abs(H[i]-H[i-2])
                ) if i >= 2 else dp[i-1] + abs(H[i] - H[i-1])
print(*dp)
print(dp[N-1])


Failing test case input:
4
30 283 0 7

Expected output:
37


Actual output:
0 253 30 37
37


Fixed submission (verdict: Accepted):
N = int(input())
H = list(map(int, input().split()))
dp = [float('inf')] * N
dp[0] = 0
for i in range(1, N):
    dp[i] = min(dp[i-1] + abs(H[i]-H[i-1]), dp[i-2] + abs(H[i]-H[i-2])
                ) if i >= 2 else dp[i-1] + abs(H[i] - H[i-1])

print(dp[N-1])
Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
h = [int(s) for s in input().split()]

dp = [0] * n
dp[0],dp[1] = 0,abs(dp[1]-dp[0])

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

Failing test case input:
4
4 91 105 28

Expected output:
150


Actual output:
63


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

dp = [0] * n
dp[0],dp[1] = 0,abs(h[1]-h[0])

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

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
h = list(map(int, input().split()))
dp = [ 10**10 for _ in range(n)]
dp[0] = 0
dp[1] = dp[0] + abs(h[1] - h[0])
if(n > 2):
  for i in range(2, n):
    dp[i] = min([dp[i-1] + abs(h[i] - h[i - 1]), dp[i-2] + abs(h[i] - h[i - 2])])
    print(i, dp[i-1] + abs(h[i] - h[i - 1]), dp[i-2] + abs(h[i] - h[i - 2]))
print(dp[-1])

Failing test case input:
4
1 0 2 -77

Expected output:
78


Actual output:
2 3 1
3 80 78
78


Fixed submission (verdict: Accepted):
n = int(input())
h = list(map(int, input().split()))
dp = [ 10**10 for _ in range(n)]
dp[0] = 0
dp[1] = dp[0] + abs(h[1] - h[0])
if(n > 2):
  for i in range(2, n):
    dp[i] = min([dp[i-1] + abs(h[i] - h[i - 1]), dp[i-2] + abs(h[i] - h[i - 2])])
print(dp[-1])

Problem: p03160
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
h = list(map(int,input().split()))
A = [float('inf')] * (N)
A[0] = 0

for i in range(N-2):
    p = A[i] + abs(h[i+1] - h[i])
    q = A[i] + abs(h[i+2] - h[i])
    if  p < A[i+1]:
        A[i+1] = p
    if q < A[i+2]:
        A[i+2] = q
print(A[N-1])

Failing test case input:
6
30 10 60 10 60 50

Expected output:
40

Actual output:
60


Fixed submission (verdict: Accepted):
N = int(input())
h = list(map(int,input().split()))
A = [float('inf')] * (N)
A[0] = 0
A[1] = abs(h[1]-h[0])

if N > 2:
    for i in range(2,N):
        p = A[i-1] + abs(h[i-1] - h[i])
        q = A[i-2] + abs(h[i-2] - h[i])
        if  p < A[i]:
            A[i] = p
        if q < A[i]:
            A[i] = q
    print(A[N-1])

else:
    print(abs(h[1]-h[0]))

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n = ni()
h = na()

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

Failing test case input:
6
30 10 35 18 154 1

Expected output:
39


Actual output:
[0, 20, 5, 22, 124, 39]


Fixed submission (verdict: Accepted):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n = ni()
h = na()

dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
count = 1
for i in range(2,n):
  dp[i] = min(abs(h[i-1]-h[i])+dp[i-1], abs(h[i-2]-h[i])+dp[i-2])
print(dp[-1])
Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


N=int(input())
li=list(map(int,input().split()))
kekka=[0]*N
cost=0
kekka[0]=li[0]


for i in range(1,N):
    if i ==1:
        kekka[i]=abs(li[1]-li[0])
    else:
        a=abs(li[i-2]-li[i])
        b=abs(li[i-1]-li[i])
        if a>b:
            kekka[i]=b+kekka[i-1]
        else:
            kekka[i]=a+kekka[i-2]


print(kekka[-1]-kekka[i])

Failing test case input:
2
47 -1

Expected output:
48


Actual output:
0


Fixed submission (verdict: Accepted):
N=int(input())
li=list(map(int,input().split()))
kekka=[0]*N


for i in range(1,N):
    if i==1:
        kekka[i]=abs(li[i]-li[i-1])
    else:
        a=abs(li[i]-li[i-1])+kekka[i-1]
        b=abs(li[i]-li[i-2])+kekka[i-2]
        kekka[i]=min(a,b)
print(kekka[-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin,stdout


n = int(stdin.readline())
dp = [0 for i in range(n)]
a  = list(map(int,stdin.readline().split()))
dp[1] = a[1] - a[0]
for i in range(2,n):
  if(abs(a[i] - a[i-1]) < abs(a[i] - a[i-2])):
    dp[i] = dp[i-1] + a[i] - a[i-1]
  else:
    dp[i] = dp[i-2] + a[i] - a[i-2]
print(dp[-1])

Failing test case input:
6
2 0 26 92 65 14

Expected output:
114


Actual output:
12


Fixed submission (verdict: Accepted):
from sys import stdin,stdout


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

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


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

h.insert(0,0)




c=[0, 0]

for i in range(2,n+1):
    
    
    ck = min(c[i-1]+abs(h[i]-h[i-1]),c[i-2]+abs(h[i]-h[i-2]))
    c.append(ck)
print(c[n])

Failing test case input:
4
29 7 0 1

Expected output:
28


Actual output:
13


Fixed submission (verdict: Accepted):


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

h.insert(0,0)




c=[0, 0]
c2 = abs(h[2]-h[1])
c.append(c2)

for i in range(3,n+1):
    
    
    ck = min(c[i-1]+abs(h[i]-h[i-1]),c[i-2]+abs(h[i]-h[i-2]))
    c.append(ck)
print(c[n])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

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

Failing test case input:
4
34 11 -4 0

Expected output:
34


Actual output:
[0, 0, 0, 0]
[0, -23, 0, 0]
[0, -23, -8, 0]
[0, -23, -8, -12]
-12


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

dp = [0]*n
for i in range(n):
    if i >= 2:
        dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]))
    elif i == 1:
        dp[i] = abs(a[i]-a[i-1])
print(dp[-1])
Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

N = int(input())
h = list(map(int,input().split()))
dp = [10000000000000] * N
dp[0] = 0

def dpf():
    for i in range(1,N):
        x = abs( h[i] - h[i-1] ) + dp[i-1]
        y = abs( h[i] - h[i-2] ) + dp[i-2]
        if x >=y:
            dp[i] = y
        else:
            dp[i] = x

def solve():
    dpf()
    print(dp)
    print(dp[N-1])

if __name__ == "__main__":
    solve()


Failing test case input:
4
29 7 0 2

Expected output:
27


Actual output:
[0, 22, 29, 27]
27


Fixed submission (verdict: Accepted):

N = int(input())
h = list(map(int,input().split()))
dp = [10000000000000] * N
dp[0] = 0

def dpf():
    for i in range(1,N):
        x = abs( h[i] - h[i-1] ) + dp[i-1]
        y = abs( h[i] - h[i-2] ) + dp[i-2]
        if x >=y:
            dp[i] = y
        else:
            dp[i] = x

def solve():
    dpf()
    print(dp[N-1])

if __name__ == "__main__":
    solve()

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
l=list(map(int,input().split()))
dp=[0 for i in range(n)]

dp[1]=l[1]-l[0]
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])


Failing test case input:
6
2 -2 1 4 65 18

Expected output:
18


Actual output:
16


Fixed submission (verdict: Accepted):
n=int(input())
l=list(map(int,input().split()))
dp=[0 for i in range(n)]

dp[1]=abs(l[1]-l[0])
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])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
h = list(map(int,input().split()))
cost = [100000]*N

cost[0] = 0
for i in range(N-1): 
  num = cost[i] + abs(h[i+1]-h[i])
  if cost[i+1] > num:
    cost[i+1] = num
  if i > 0:
    num2 = cost[i-1] + abs(h[i]-h[i-2])
    if cost[i+1] > num2:
      cost[i+1] =  num2
      
print(cost[N-1])

Failing test case input:
4
4 91 105 14

Expected output:
164


Actual output:
168


Fixed submission (verdict: Accepted):
N = int(input())
h = list(map(int,input().split()))
cost = [float('inf')]*N

cost[0] = 0
for i in range(N-1): 
  num = cost[i] + abs(h[i+1]-h[i])
  if cost[i+1] > num:
    cost[i+1] = num
  if i > 0:
    num2 = cost[i-1] + abs(h[i+1]-h[i-1])
    if cost[i+1] > num2:
      cost[i+1] =  num2
      
print(cost[N-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
h = [0] + list(map(int, input().split())) 

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

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

print(dp[N])

Failing test case input:
2
12 -1

Expected output:
13


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
h = [0] + list(map(int, input().split())) 

dp = [None for _ in range(N+1)] 
dp[1] = 0 
dp[2] = abs(h[2]-h[1])

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

print(dp[N])
Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))

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


Failing test case input:
4
17 11 1 24

Expected output:
19


Actual output:
16


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

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

Problem: p03160
Buggy submission (Python (3.8.2), verdict: Wrong Answer):




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

dp = list()


dp.append(0)
dp.append(dp[0] + abs(h[1] - h[0]))

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


print(dp)

Failing test case input:
2
44 1

Expected output:
43


Actual output:
[0, 43]


Fixed submission (verdict: Accepted):




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

dp = list()


dp.append(0)
dp.append(dp[0] + abs(h[1] - h[0]))

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


print(dp[N-1])

Problem: p03160
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from sys import stdin


def solve():
    n = int(input())
    A = [int(i) for i in stdin.readline().split()]
    if n == 2: return abs(A[0] - A[1])
    curr = 0
    p2, p1 = A[0], abs(A[0] - A[1])
    for i in range(2, len(A)):
        
        curr += min(abs(A[i] - A[i-1]), abs(A[i] - A[i-2]))
        p2 = p1
        p1 = curr
    return curr

print(solve())

Failing test case input:
4
2 91 71 13

Expected output:
127


Actual output:
78


Fixed submission (verdict: Accepted):
from sys import stdin


def solve():
    n = int(input())
    A = [int(i) for i in stdin.readline().split()]
    if n == 2: return abs(A[0] - A[1])
    curr = 0
    p2, p1 = 0, abs(A[0] - A[1])
    for i in range(2, len(A)):
        
        
        prev2 = abs(A[i] - A[i-2]) + p2
        prev = abs(A[i] - A[i-1]) + p1
        if prev > prev2: curr = prev2
        else: curr = prev
        p2 = p1
        p1 = curr
    return curr

print(solve())

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
h = list(map(int,input().split()))


dp = [99999999]*n

dp[0]=0
dp[1]=h[1]-h[0]

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

Failing test case input:
6
3 0 1 92 52 14

Expected output:
91


Actual output:
87


Fixed submission (verdict: Accepted):
n = int(input())
h = list(map(int,input().split()))


dp = [99999999]*n

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

for i in range(2,n):
  dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
  
print(dp[n-1])
Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

N = int(input())
dp = [0 for _ in range(N)]
h = list(map(int, input().split()))
for i in range(2, N):
    dp[i] = min(dp[i-2] + abs(h[i-2] - h[i]), dp[i-1] + abs(h[i-1] - h[i]))
print(dp[N-1])

Failing test case input:
4
2 77 54 23

Expected output:
83


Actual output:
54


Fixed submission (verdict: Accepted):

N = int(input())
dp = [0 for _ in range(N)]
h = list(map(int, input().split()))
dp[1] = dp[0] + abs(h[0] - h[1])
for i in range(2, N):
    dp[i] = min(dp[i-2] + abs(h[i-2] - h[i]), dp[i-1] + abs(h[i-1] - h[i]))
print(dp[N-1])

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
h = list(map(int,input().split()))
print(h)

dp = []

for i in range(N):
	dp.append(float("inf"))

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

print(dp[-1])

Failing test case input:
4
0 0 -1 -101

Expected output:
101


Actual output:
[0, 0, -1, -101]
101


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

dp = []

for i in range(N):
	dp.append(float("inf"))

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

print(dp[-1])

Problem: p03160
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
hs = list(map(int, input().split()))

costs1 = 0
costs2 = abs(hs[1] - hs[0])
for i in range(2, N):
  costs1, costs2 = min(costs1 + abs(hs[i] - hs[i - 2]), costs2 + abs(hs[i] - hs[i - 1])), costs1
  
print(costs2)


Failing test case input:
4
2 77 45 13

Expected output:
75


Actual output:
43


Fixed submission (verdict: Accepted):
N = int(input())
hs = list(map(int, input().split()))

costs1 = 0
costs2 = abs(hs[1] - hs[0])
for i in range(2, N):
  costs1, costs2 = costs2, min(costs1 + abs(hs[i] - hs[i - 2]), costs2 + abs(hs[i] - hs[i - 1])),
  
print(costs2)

Problem: p03160
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
h = [int(e) for e in input().split()]

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

for i in range(2,n):
    dp.append(min(abs(h[i]-h[i-2]),(abs(h[i]-h[i-1])+abs(h[i-1]-h[i-2]))))

print(dp[-1])

Failing test case input:
6
0 0 1 45 52 10

Expected output:
80


Actual output:
35


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

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

for i in range(2,n):
    dp.append(min(dp[-1]+abs(h[i]-h[i-1]),dp[-2]+abs(h[i]-h[i-2])))

print(dp[-1])