Buggy python submission (verdict: Runtime Error):
def solve():
    a = raw_input()
    n = len(a)
    cost = [[0 for i in range(n)] for j in range(n)]
 
    for length in range(2, n+1):
        for i in range(0, n-length+1):
            k = i+length-1
            def f(i,j,k):
                return cost[i][j-1]+cost[j][k]+M[i][0]*M[j-1][1]*M[k][1]
            cost[i][k] = min([f(i,j,k) for j in range(i+1,k+1)])
    return cost[0][n-1]
 
n = raw_input()
M = []
for i in range(n):
    M.append(map(int, raw_input().split()))
     
print solve(M)

Fixed submission:
def solve(a):
 n = len(a)
 cost = [[0 for i in range(n)] for j in range(n)]
 for length in range(2, n+1):
  for i in range(0, n-length+1):
   k = i+length-1
   def f(i,j,k):
    return cost[i][j-1]+cost[j][k]+M[i][0]*M[j-1][1]*M[k][1]
   cost[i][k] = min([f(i,j,k) for j in range(i+1,k+1)])
 return cost[0][n-1]
n = input()
M = []
for i in range(n):
 M.append(map(int, raw_input().split()))
print solve(M)

Buggy python submission (verdict: Runtime Error):
def solve():
    a = raw_input()
    n = len(a)
    cost = [[0 for i in range(n)] for j in range(n)]
 
    for length in range(2, n+1):
        for i in range(0, n-length+1):
            k = i+length-1
            def f(i,j,k):
                return cost[i][j-1]+cost[j][k]+M[i][0]*M[j-1][1]*M[k][1]
            cost[i][k] = min([f(i,j,k) for j in range(i+1,k+1)])
    return cost[0][n-1]
 
n = input()
M = []
for i in range(n):
    M.append(map(int, raw_input().split()))
     
print solve(M)

Fixed submission:
def solve(a):
 n = len(a)
 cost = [[0 for i in range(n)] for j in range(n)]
 for length in range(2, n+1):
  for i in range(0, n-length+1):
   k = i+length-1
   def f(i,j,k):
    return cost[i][j-1]+cost[j][k]+M[i][0]*M[j-1][1]*M[k][1]
   cost[i][k] = min([f(i,j,k) for j in range(i+1,k+1)])
 return cost[0][n-1]
n = input()
M = []
for i in range(n):
 M.append(map(int, raw_input().split()))
print solve(M)

Buggy python submission (verdict: Runtime Error):
def solve():
    a = raw_input()
    n = len(a)
    cost = [[0 for i in range(n)] for j in range(n)]
 
    for length in range(2, n+1):
        for i in range(0, n-length+1):
            k = i+length-1
            def f(i,j,k):
                return cost[i][j-1]+cost[j][k]+M[i][0]*M[j-1][1]*M[k][1]
            cost[i][k] = min([f(i,j,k) for j in range(i+1,k+1)])
    return cost[0][n-1]
 
n = input()
M = []
for i in range(n):
    M.append(map(int, raw_input().split()))
     
print solve()

Fixed submission:
def solve(a):
 n = len(a)
 cost = [[0 for i in range(n)] for j in range(n)]
 for length in range(2, n+1):
  for i in range(0, n-length+1):
   k = i+length-1
   def f(i,j,k):
    return cost[i][j-1]+cost[j][k]+M[i][0]*M[j-1][1]*M[k][1]
   cost[i][k] = min([f(i,j,k) for j in range(i+1,k+1)])
 return cost[0][n-1]
n = input()
M = []
for i in range(n):
 M.append(map(int, raw_input().split()))
print solve(M)

Buggy python submission (verdict: Runtime Error):
def solve(a):
    n = len(a)
    cost = [[0 for i in range(n)] for j in range(n)]
 
    for length in range(2, n+1):
        for i in range(0, n-length+1):
            k = i+length-1
            def f(i,j,k):
                return cost[i][j-1]+cost[j][k]+M[i][0]*M[j-1][1]*M[k][1]
            cost[i][k] = min([f(i,j,k) for j in range(i+1,k+1)])
    return cost[0][n-1]
 
n = raw_input()
M = []
for i in range(n):
    M.append(map(int, raw_input().split()))
print solve(M)

Fixed submission:
def solve(a):
 n = len(a)
 cost = [[0 for i in range(n)] for j in range(n)]
 for length in range(2, n+1):
  for i in range(0, n-length+1):
   k = i+length-1
   def f(i,j,k):
    return cost[i][j-1]+cost[j][k]+M[i][0]*M[j-1][1]*M[k][1]
   cost[i][k] = min([f(i,j,k) for j in range(i+1,k+1)])
 return cost[0][n-1]
n = input()
M = []
for i in range(n):
 M.append(map(int, raw_input().split()))
print solve(M)