Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)
def main():
    n = int(input())
    h = [int(x) for x in input().split()]
    memo = [None for i in range(n)]

    # def rec(n):
    #     if memo[n-1] == None:
    #         if n <= 1:
    #             memo[n-1] = 0
    #         elif n == 2:
    #             memo[n-1] = abs(h[1]-h[0])
    #         else:
    #             d1 = rec(n-2)+abs(h[n-1]-h[n-3])
    #             d2 = rec(n-1)+abs(h[n-1]-h[n-2])
    #             memo[n-1] = min(d1,d2)
    #     return memo[n-1]
        
    # print(rec(n))

    def f(n):
        if memo[n-1] == None:
          if n <= 1:
              memo[n-1] = 0
          elif n == 2:
              memo[n-1] = abs(h[1]-h[0])
          else:
              d1 = f(n-1) + abs(h[n-1]-h[n-2])
              d2 = f(n-2) + abs(h[n-1]-h[n-3])
              memo[n-1] = min(d1,d2)
        return memo[n-1]

    print(f(n))


if __name__ == "__main__":
    main()


Fixed submission:
import sys
sys.setrecursionlimit(10**5)
def main():
    n = int(input())
    h = [int(x) for x in input().split()]
    memo = [None for i in range(n)]

    def rec(n):
        if memo[n-1] == None:
            if n <= 1:
                memo[n-1] = 0
            elif n == 2:
                memo[n-1] = abs(h[1]-h[0])
            else:
                d1 = rec(n-2)+abs(h[n-1]-h[n-3])
                d2 = rec(n-1)+abs(h[n-1]-h[n-2])
                memo[n-1] = min(d1,d2)
        return memo[n-1]
        
    print(rec(n))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)
def main():
    n = int(input())
    h = [int(x) for x in input().split()]
    memo = [None for i in range(n)]

    # def rec(n):
    #     if memo[n-1] == None:
    #         if n <= 1:
    #             memo[n-1] = 0
    #         elif n == 2:
    #             memo[n-1] = abs(h[1]-h[0])
    #         else:
    #             d1 = rec(n-2)+abs(h[n-1]-h[n-3])
    #             d2 = rec(n-1)+abs(h[n-1]-h[n-2])
    #             memo[n-1] = min(d1,d2)
    #     return memo[n-1]
        
    # print(rec(n))

    def f(n):
        if memo[n-1] == None:
          if n <= 1:
              memo[0] = 0
          elif n == 2:
              memo[1] = abs(h[1]-h[0])
          else:
              d1 = f(n-1) + abs(h[n-1]-h[n-2])
              d2 = f(n-2) + abs(h[n-1]-h[n-3])
              memo[n-1] = min(d1,d2)
        return memo[n-1]

    print(f(n))


if __name__ == "__main__":
    main()


Fixed submission:
import sys
sys.setrecursionlimit(10**5)
def main():
    n = int(input())
    h = [int(x) for x in input().split()]
    memo = [None for i in range(n)]

    def rec(n):
        if memo[n-1] == None:
            if n <= 1:
                memo[n-1] = 0
            elif n == 2:
                memo[n-1] = abs(h[1]-h[0])
            else:
                d1 = rec(n-2)+abs(h[n-1]-h[n-3])
                d2 = rec(n-1)+abs(h[n-1]-h[n-2])
                memo[n-1] = min(d1,d2)
        return memo[n-1]
        
    print(rec(n))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)
def main():
    n = int(input())
    h = [int(x) for x in input().split()]
    memo = [None for i in range(n)]

    # def rec(n):
    #     if memo[n-1] == None:
    #         if n <= 1:
    #             memo[n-1] = 0
    #         elif n == 2:
    #             memo[n-1] = abs(h[1]-h[0])
    #         else:
    #             d1 = rec(n-2)+abs(h[n-1]-h[n-3])
    #             d2 = rec(n-1)+abs(h[n-1]-h[n-2])
    #             memo[n-1] = min(d1,d2)
    #     return memo[n-1]
        
    # print(rec(n))

    def f(n, h):
        if memo[n-1] == None:
          if n <= 1:
              memo[0] = 0
          elif n == 2:
              memo[1] = abs(h[1]-h[0])
          else:
              d1 = abs(h[n-1]-h[n-2]) + f(n-1,h)
              d2 = abs(h[n-1]-h[n-3]) + f(n-2,h)
              memo[n-1] = min(d1,d2)
        return memo[n-1]

    print(f(n,h))


if __name__ == "__main__":
    main()

Fixed submission:
import sys
sys.setrecursionlimit(10**5)
def main():
    n = int(input())
    h = [int(x) for x in input().split()]
    memo = [None for i in range(n)]

    def rec(n):
        if memo[n-1] == None:
            if n <= 1:
                memo[n-1] = 0
            elif n == 2:
                memo[n-1] = abs(h[1]-h[0])
            else:
                d1 = rec(n-2)+abs(h[n-1]-h[n-3])
                d2 = rec(n-1)+abs(h[n-1]-h[n-2])
                memo[n-1] = min(d1,d2)
        return memo[n-1]
        
    print(rec(n))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)
def main():
    n = int(input())
    h = [int(x) for x in input().split()]
    memo = [None for i in range(n)]

    # def rec(n):
    #     if memo[n-1] == None:
    #         if n <= 1:
    #             memo[n-1] = 0
    #         elif n == 2:
    #             memo[n-1] = abs(h[1]-h[0])
    #         else:
    #             d1 = rec(n-2)+abs(h[n-1]-h[n-3])
    #             d2 = rec(n-1)+abs(h[n-1]-h[n-2])
    #             memo[n-1] = min(d1,d2)
    #     return memo[n-1]
        
    # print(rec(n))

    def f(n):
        if memo[n-1] != None:
            return memo[n-1]
        if n <= 1:
            memo[0] = 0
            return 0
        elif n == 2:
            memo[1] = abs(h[1]-h[0])
            return memo[1]
        else:
            d1 = abs(h[n-1]-h[n-2]) + f(n-1)
            d2 = abs(h[n-1]-h[n-3]) + f(n-2)
            memo[n-1] = min(d1,d2)
            return memo[n-1]

    print(f(n))


if __name__ == "__main__":
    main()

Fixed submission:
import sys
sys.setrecursionlimit(10**5)
def main():
    n = int(input())
    h = [int(x) for x in input().split()]
    memo = [None for i in range(n)]

    def rec(n):
        if memo[n-1] == None:
            if n <= 1:
                memo[n-1] = 0
            elif n == 2:
                memo[n-1] = abs(h[1]-h[0])
            else:
                d1 = rec(n-2)+abs(h[n-1]-h[n-3])
                d2 = rec(n-1)+abs(h[n-1]-h[n-2])
                memo[n-1] = min(d1,d2)
        return memo[n-1]
        
    print(rec(n))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)
def main():
    n = int(input())
    h = [int(x) for x in input().split()]
    memo = [None for i in range(n)]

    # def rec(n):
    #     if memo[n-1] == None:
    #         if n <= 1:
    #             memo[n-1] = 0
    #         elif n == 2:
    #             memo[n-1] = abs(h[1]-h[0])
    #         else:
    #             d1 = rec(n-2)+abs(h[n-1]-h[n-3])
    #             d2 = rec(n-1)+abs(h[n-1]-h[n-2])
    #             memo[n-1] = min(d1,d2)
    #     return memo[n-1]
        
    # print(rec(n))

    def f(n, h):
        if memo[n-1] != None:
            return memo[n-1]
        if n <= 1:
            memo[0] = 0
            return 0
        elif n == 2:
            memo[1] = abs(h[1]-h[0])
            return memo[1]
        else:
            d1 = abs(h[n-1]-h[n-2]) + f(n-1,h)
            d2 = abs(h[n-1]-h[n-3]) + f(n-2,h)
            memo[n-1] = min(d1,d2)
            return memo[n-1]

    print(f(n,h))


if __name__ == "__main__":
    main()

Fixed submission:
import sys
sys.setrecursionlimit(10**5)
def main():
    n = int(input())
    h = [int(x) for x in input().split()]
    memo = [None for i in range(n)]

    def rec(n):
        if memo[n-1] == None:
            if n <= 1:
                memo[n-1] = 0
            elif n == 2:
                memo[n-1] = abs(h[1]-h[0])
            else:
                d1 = rec(n-2)+abs(h[n-1]-h[n-3])
                d2 = rec(n-1)+abs(h[n-1]-h[n-2])
                memo[n-1] = min(d1,d2)
        return memo[n-1]
        
    print(rec(n))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)
def main():
    n = int(input())
    h = [int(x) for x in input().split()]
    history = [None for i in range(n)]

    def f(n, h):
        if history[n-1] != None:
            return history[n-1]
        if n <= 1:
            history[0] = 0
            return 0
        elif n == 2:
            history[1] = abs(h[1]-h[0])
            return history[1]
        else:
            d1 = abs(h[n-1]-h[n-2]) + f(n-1,h)
            d2 = abs(h[n-1]-h[n-3]) + f(n-2,h)
            history[n-1] = min(d1,d2)
            return history[n-1]
    print(f(n,h))


if __name__ == "__main__":
    main()

Fixed submission:
import sys
sys.setrecursionlimit(10**5)
def main():
    n = int(input())
    h = [int(x) for x in input().split()]
    memo = [None for i in range(n)]

    def rec(n):
        if memo[n-1] == None:
            if n <= 1:
                memo[n-1] = 0
            elif n == 2:
                memo[n-1] = abs(h[1]-h[0])
            else:
                d1 = rec(n-2)+abs(h[n-1]-h[n-3])
                d2 = rec(n-1)+abs(h[n-1]-h[n-2])
                memo[n-1] = min(d1,d2)
        return memo[n-1]
        
    print(rec(n))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    h = [int(x) for x in input().split()]
    history = [None for i in range(n)]

    def f(n, h):
        if history[n-1] != None:
            return history[n-1]
        if n <= 1:
            history[0] = 0
            return 0
        elif n == 2:
            history[1] = abs(h[1]-h[0])
            return history[1]
        else:
            d1 = abs(h[n-1]-h[n-2]) + f(n-1,h)
            d2 = abs(h[n-1]-h[n-3]) + f(n-2,h)
            history[n-1] = min(d1,d2)
            return history[n-1]
    print(f(n,h))


if __name__ == "__main__":
    main()

Fixed submission:
import sys
sys.setrecursionlimit(10**5)
def main():
    n = int(input())
    h = [int(x) for x in input().split()]
    memo = [None for i in range(n)]

    def rec(n):
        if memo[n-1] == None:
            if n <= 1:
                memo[n-1] = 0
            elif n == 2:
                memo[n-1] = abs(h[1]-h[0])
            else:
                d1 = rec(n-2)+abs(h[n-1]-h[n-3])
                d2 = rec(n-1)+abs(h[n-1]-h[n-2])
                memo[n-1] = min(d1,d2)
        return memo[n-1]
        
    print(rec(n))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    h = [int(x) for x in input().split()]
    history = [None for i in range(n)]
    print(f(n,h))

def f(n, h):
    if history[n-1] != None:
        return history[n-1]
    if n <= 1:
      	history[0] = 0
        return 0
    elif n == 2:
      	history[1] = abs(h[1]-h[0])
        return history[1]
    else:
        d1 = abs(h[n-1]-h[n-2]) + f(n-1,h)
        d2 = abs(h[n-1]-h[n-3]) + f(n-2,h)
        history[n-1] = min(d1,d2)
        return history[n-1]

if __name__ == "__main__":
    main()

Fixed submission:
import sys
sys.setrecursionlimit(10**5)
def main():
    n = int(input())
    h = [int(x) for x in input().split()]
    memo = [None for i in range(n)]

    def rec(n):
        if memo[n-1] == None:
            if n <= 1:
                memo[n-1] = 0
            elif n == 2:
                memo[n-1] = abs(h[1]-h[0])
            else:
                d1 = rec(n-2)+abs(h[n-1]-h[n-3])
                d2 = rec(n-1)+abs(h[n-1]-h[n-2])
                memo[n-1] = min(d1,d2)
        return memo[n-1]
        
    print(rec(n))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    h = [int(x) for x in input().split()]
    print(f(n,h))

def f(n, h):
    if n <= 1:
        return 0
    elif n == 2:
        return abs(h[1] - h[0])
    else:
        d1 = abs(h[n-1]-h[n-2]) + f(n-1,h)
        d2 = abs(h[n-1]-h[n-3]) + f(n-2,h)
        return min(d1,d2)

if __name__ == "__main__":
    main()

Fixed submission:
import sys
sys.setrecursionlimit(10**5)
def main():
    n = int(input())
    h = [int(x) for x in input().split()]
    memo = [None for i in range(n)]

    def rec(n):
        if memo[n-1] == None:
            if n <= 1:
                memo[n-1] = 0
            elif n == 2:
                memo[n-1] = abs(h[1]-h[0])
            else:
                d1 = rec(n-2)+abs(h[n-1]-h[n-3])
                d2 = rec(n-1)+abs(h[n-1]-h[n-2])
                memo[n-1] = min(d1,d2)
        return memo[n-1]
        
    print(rec(n))

if __name__ == "__main__":
    main()