Problem p03160 (python)

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis = [0] * n
vis[0] = 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i-1]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[-1])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[1]=0
vis[2]=abs(arr[0]-arr[1])
def c(i):
  if i in vis:
    return vis[i]
  x = abs(arr[i-1]-arr[i-2]) + c(i-1)
  y = abs(arr[i-1]-arr[i-3]) + c(i-2)
  vis[i]=min(x, y)
  return vis[i]
c(n)
print(vis[n])

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[1]=0
vis[2]=abs(arr[0]-arr[1])
def c(i):
  if i in vis:
    #print(vis)
    return vis[i]
  x = abs(arr[i-1]-arr[i-2]) + c(i-1)
  y = abs(arr[i-1]-arr[i-3]) + c(i-2)
  vis[i]=min(x, y)
  #print(i, x, y, vis)
  return vis[i]
c(n)
print(vis[n])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[1]=0
if n < 2:
  print(0)
  exit
vis[2]=abs(arr[0]-arr[1])
if n == 2:
  print(vis[2])
  exit
def c(i):
  if i in vis:
    #print(vis)
    return vis[i]
  x = abs(arr[i-1]-arr[i-2]) + c(i-1)
  y = abs(arr[i-1]-arr[i-3]) + c(i-2)
  vis[i]=min(x, y)
  #print(i, x, y, vis)
  return vis[i]
c(n)
print(vis[n])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[1]=0
if n < 2:
  print(0)
  exit
vis[2]=abs(arr[0]-arr[1])
if n == 2:
  print(vis[2])
  exit
def c(i):
  if i in vis:
    #print(vis)
    return vis[i]
  x = abs(arr[i-1]-arr[i-2]) + c(i-1)
  y = abs(arr[i-1]-arr[i-3]) + c(i-2)
  vis[i]=min(x, y)
  #print(i, x, y, vis)
  return vis[i]
c(n)
print(vis[n-1])

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
def count(x):
    if x < 0:
      return 0
    if x in vis:
      return vis[x]
    else:
      vis[x]=min(abs(arr[x]-arr[x-1])+count(x-1),abs(arr[x]-arr[x-2])+count(x-2))
    return vis[x]
  
vis={}
vis[0] = 0
if n < 2:
  print(0)
elif n == 2:
  print(abs(arr[0]-arr[1]))
else:
    vis[1] = abs(arr[0]-arr[1])
    print(count(n-1))

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[1] = 0
if n < 2:
  print(0)
  exit
if n == 2:
  print(abs(arr[0]-arr[1]))
  exit
vis[2] = abs(arr[0]-arr[1])
def count(x):
    if x < 0:
      return 0
    if x in vis:
      return vis[x]
    else:
      vis[x]=min(abs(arr[x-1]-arr[x-2])+count(x-1),abs(arr[x-1]-arr[x-3])+count(x-2))
    return vis[x]
print(count(n))

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[1] = 0
if n < 2:
  print(0)
  exit
if n == 2:
  print(abs(arr[0]-arr[1]))
  exit
vis[2] = abs(arr[0]-arr[1])
def count(n):
    if n < 0:
      return 0
    if n in vis:
      return vis[n]
    else:
      vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n))

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
if n < 2:
  print(0)
  exit
if n == 2:
  print(min(arr[0]-arr[1]))
  exit
vis[1] = min(arr[0]-arr[1])
def count(n):
    if n < 0:
      return 0
    if n in vis:
        return vis[n]
    else:
      vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n))

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
if n < 2:
  print(0)
  return
if n == 2:
  print(min(arr[0]-arr[1]))
  return
vis[1] = min(arr[0]-arr[1])
def count(n):
    if n < 0:
      return 0
    if n in vis:
        return vis[n]
    else:
      vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n))

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
if n < 2:
  print(0)
  return
if n == 2:
  print(min(arr[0]-arr[1]))
  return
vis[1] = min(arr[0]-arr[1])
def count(n):
    if n < 0:
      return 0
    if n in vis:
        return vis[n]
    else:
      vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n))

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
if n < 2:
  print(0)
if n == 2:
  print(min(arr[0]-arr[1]))
vis[1] = min(arr[0]-arr[1])
def count(n):
    if n < 0:
      return 0
    if n in vis:
        return vis[n]
    else:
      vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n-1))

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
if n < 2:
  print(0)
if n == 2:
  print(min(arr[0]-arr[1]))
vis[1] = min(arr[0]-arr[1])
def count(n):
  	if n < 0:
      return 0
    if n in vis:
        return vis[n]
    else:
      vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n-1))

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
if n < 2:
  print(0)
if n == 2:
  print(min(arr[0]-arr[1]))
vis[1] = min(arr[0]-arr[1])
def count(n):
  	if n < 0:
      return 0
    if n in vis:
        return vis[n]
    else:
      vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n-1))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
if n < 2:
  print(0)
if n == 2:
  print(min(arr[0]-arr[1]))
vis[1] = min(arr[0]-arr[1])
def count(n):
  	if n < 0:
      return 0
    if n in vis:
        return vis[n]
    else:
      vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
if n < 2:
  print(0)
if n == 2:
  print(min(arr[0]-arr[1]))
vis[1] = min(arr[0]-arr[1])
def count(n):
    if n in vis or n < 0:
        return vis[n]
    else:
      vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
if n < 2:
  return 0
if n == 2:
  return min(arr[0]-arr[1])
vis[1] = min(arr[0]-arr[1])
def count(n):
    if n in vis or n < 0:
        return vis[n]
    else:
      vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
vis={}
def count(n):
    if n in vis:
        return vis[n]
    if n<2:
        return 0
    else:
      vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n))

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis[0] = 0
if n < 2:
  print(vis[0])
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i-1]-arr[i-2]) + vis[i-1]
    step_2 = abs(arr[i-1]-arr[i-3]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[i])

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis[0] = 0
if n < 2:
  print(vis[0])
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i-1]-arr[i-2]) + vis[i-1]
    step_2 = abs(arr[i-1]-arr[i-3]) + vis[i-2]
    vis[i] = min(step_1, step_2)
print(vis[i-1])

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis[0] = 0
if n < 2:
  print(vis[0])
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i-1]-arr[i-2]) + vis[i-1]
    step_2 = abs(arr[i-1]-arr[i-3]) + vis[i-2]
    vis[i] = min(step_1, step_2)
   
print(vis[i])

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis[0] = 0
if n < 2:
  return 0
vis[1] = abs(arr[0]-arr[1])
for i in range(2, n):
    step_1 = abs(arr[i-1]-arr[i-2]) + vis[i-1]
    step_2 = abs(arr[i-1]-arr[i-3]) + vis[i-2]
    vis[i] = min(step_1, step_2)
   
print(vis[i])

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis={}
vis[0] = 0
vis[1] = 0
if n > 1:
  vis[2] = abs(arr[0]-arr[1])
if n == 2:
  print(vis[2])
for i in range(2, n+1):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-1]
    vis[i+1] = min(step_1, step_2)
   
print(vis[i])

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis={}
vis[0] = 0
vis[1] = 0
if n > 1:
  vis[2] = abs(arr[0]-arr[1])
if n == 2:
  print(vis[2])
for i in range(2, n+1):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-1]
    vis[i+1] = min(step_1, step_2)
   
print(vis[i+1])

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis={}
vis[0] = 0
vis[1] = 0
if n > 1:
  vis[2] = abs(arr[0]-arr[1])
if n == 2:
  print(vis[2])
for i in range(2, n+1):
    step_1 = abs(arr[i]-arr[i-1]) + vis[i]
    step_2 = abs(arr[i]-arr[i-2]) + vis[i-1]
    vis[i+1] = min(step_1, step_2)
   
print(vis[n])

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis={}
vis[0] = 0
vis[1] = 0
if n > 1:
  vis[2] = abs(arr[0]-arr[1])
if n == 2:
  print(vis[2])
for i in range(3, n):
    step_1 = abs(arr[i-1]-arr[i-2]) + vis[i-1]
    step_2 = abs(arr[i-1]-arr[i-3]) + vis[i-2]
    vis[i] = min(step_1, step_2)
   
print(vis[i])

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis={}
vis[0] = 0
vis[1] = 0
if n > 1:
  vis[2] = abs(arr[0]-arr[1])
if n == 2:
  print(vis[2])
for i in range(3, n):
    step_1 = abs(arr[i-1]-arr[i-2]) + vis[i-1]
    step_2 = abs(arr[i-1]-arr[i-3]) + vis[i-2]
    vis[i] = min(step_1, step_2)
   
print(vis[n])

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis={}
vis[0] = 0
vis[1] = 0
if n > 1:
  vis[2] = abs(arr[0]-arr[1])
if n == 2:
  print(vis[2])
for i in range(3, n):
    step_1 = abs(arr[i-1]-arr[i-2]) + vis[i-1]
    step_2 = abs(arr[i-1]-arr[i-3]) + vis[i-2]
    vis[i] = min(step_1, step_2)
   
print(vis[i])

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  print(0)
vis={}
vis[0] = 0
vis[1] = 0
if n > 1:
  vis[2] = abs(arr[0]-arr[1])
if n == 2:
  print(vis[2])
for i in range(3, n+1):
    step_1 = abs(arr[i-1]-arr[i-2]) + vis[i-1]
    step_2 = abs(arr[i-1]-arr[i-3]) + vis[i-2]
    vis[i] = min(step_1, step_2)
   
print(vis[i])

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
if n < 2:
  return 0
vis={}
vis[0] = 0
vis[1] = 0
if n > 1:
  vis[2] = abs(arr[0]-arr[1])
if n == 2:
  return vis[2]
for i in range(3, n+1):
    step_1 = abs(arr[i-1]-arr[i-2]) + vis[i-1]
    step_2 = abs(arr[i-1]-arr[i-3]) + vis[i-2]
    vis[i] = min(step_1, step_2)
   
print(vis[i])

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
vis[1] = 0
if n > 1:
  vis[2] = abs(arr[0]-arr[1])

for i in range(3, n+1):
    step_1 = abs(arr[i-1]-arr[i-2]) + vis[i-1]
    step_2 = abs(arr[i-1]-arr[i-3]) + vis[i-2]
    vis[i] = min(step_1, step_2)
   
print(vis[i])

Buggy submission (verdict: Runtime Error):
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
vis[1] = 0
if n > 1:
  vis[2] = abs(arr[0]-arr[1])

for i in range(3, n):
    step_1 = abs(arr[i-1]-arr[i-2]) + vis[i-1]
    step_2 = abs(arr[i-1]-arr[i-3])+vis[i-2]
    vis[n] = min(step_1, step_2)
    print(vis)
print(vis[n])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
vis={}
vis[0] = 0
vis[1] = 0
if n > 1:
  vis[2] = abs(arr[0]-arr[1])
def count(n):
  	n = n-1
  	if n in vis:
      return vis[n]
    step_1 = abs(arr[n]-arr[n-1])+count(n-1)
    step_2 = abs(arr[n]-arr[n-2])+count(n-2)
    vis[n] = min(step_1, step_2)
    return vis[n]
print(count(n))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
vis={}
def count(n):
    if n in vis:
        return vis[n]
    if n<2:
        return 0
    if n==2:
        vis[n]=abs(arr[n-1]-arr[n-2])+count(n-1)
    if n>=3:
        vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),(abs(arr[n-1]-arr[n-3])+count(n-2)))
    return vis[n]
print(count(n))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
vis={}
def count(n):
    if n in vis:
        return vis[n]
    if n<2:
        return 0
    if n==2:
        vis[n]=abs(arr[n-1]-arr[n-2])+count(n-1)
    if n>=3:
        vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
vis={}
def count(n):
    if n in vis:
        return vis[n]
    if n<2:
        return 0
    if n==2:
        vis[n]=(abs(arr[n-1]-arr[n-2])+count(n-1))
    if n>=3:
        vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n-1))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1500)
n=int(input())
arr=list(map(int,input().split()))
print(arr)
vis={}
vis[0] = 0
vis[1] = 0
def count(n):
    if n in vis:
        return vis[n]
    if n == 2:
        vis[n]=(abs(arr[n-1]-arr[n-2])+count(n-1))
    else:
        vis[n]=min(abs(arr[n-1]-arr[n-2])+count(n-1),abs(arr[n-1]-arr[n-3])+count(n-2))
    return vis[n]
print(count(n))