def mcm(M):

  n = len(M)

  m = [[0 for i in range(n)] for j in range(n)]

   

  for l in range(2, n+1):

    for i in range(0, n-l+1):

      j = i + l - 1

      def cost(i, k ,j):

        return m[i][k] + m[k+1][j] + M[i][0]*M[k][1]*M[j][1]

      m[i][j] = min(cost(i, k, j) for k in range(i, j))

   

  return m[0][n-1]

 

n = eval(input())

M = []

 

for i in range(n):

  M.append(list(map(int, input().split())))

print(mcm(M))
def matrix(n):

    x = [[0 for i in range(len(n))] for j in range(len(n))]

    for l in range(2, len(n)+1):

        for i in range(0, len(n)-l+1):

            j = i + l - 1

            x[i][j] = min(x[i][k] + x[k+1][j] + X[i][0]*X[k][1]*X[j][1] for k in range(i, j))



    print(x[0][len(n)-1])



n = eval(input())

X = []



for i in range(n):

    X.append(list(map(int, input().split())))



matrix(X)
def mcm(M):
    n = len(M)
    m = [[0 for i in range(n)] for j in range(n)]
    for l in range(2, n + 1):
        for i in range(0, n - l + 1):
            j = i + l - 1

            def cost(i, k, j):
                return m[i][k] + m[k + 1][j] + M[i][0] * M[k][1] * M[j][1]

            m[i][j] = min(cost(i, k, j) for k in range(i, j))
    return m[0][n - 1]


n = eval(input())
M = []
for i in range(n):
    M.append(list(map(int, input().split())))
print(mcm(M))

def matrix(n):
    x = [[0 for i in range(len(n))] for j in range(len(n))]
    for l in range(2, len(n) + 1):
        for i in range(0, len(n) - l + 1):
            j = i + l - 1
            x[i][j] = min(
                x[i][k] + x[k + 1][j] + X[i][0] * X[k][1] * X[j][1] for k in range(i, j)
            )
    print(x[0][len(n) - 1])


n = eval(input())
X = []
for i in range(n):
    X.append(list(map(int, input().split())))
matrix(X)

-def mcm(M): -    n = len(M) -    m = [[0 for i in range(n)] for j in range(n)] -    for l in range(2, n + 1): -        for i in range(0, n - l + 1): +def matrix(n): +    x = [[0 for i in range(len(n))] for j in range(len(n))] +    for l in range(2, len(n) + 1): +        for i in range(0, len(n) - l + 1): - -            def cost(i, k, j): -                return m[i][k] + m[k + 1][j] + M[i][0] * M[k][1] * M[j][1] - -            m[i][j] = min(cost(i, k, j) for k in range(i, j)) -    return m[0][n - 1] +            x[i][j] = min( +                x[i][k] + x[k + 1][j] + X[i][0] * X[k][1] * X[j][1] for k in range(i, j) +            ) +    print(x[0][len(n) - 1]) -M = [] +X = [] -    M.append(list(map(int, input().split()))) -print(mcm(M)) +    X.append(list(map(int, input().split()))) +matrix(X)