INF = float("inf")

n = int(eval(input()))

z = []

m = [[0] * (n + 1) for _ in range(n + 1)]

for i in range(1, n + 1):

    a, b = list(map(int, input().split()))

    z.append(a)

z.append(b)

for l in range(1, n):

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

        j = i + l

        m[i][j] = INF

        for k in range(i, j):

            m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + z[i - 1] * z[k] * z[j])

print((m[1][n]))



import sys

INF = float("inf")

n = int(eval(input()))

m = [[0] * (n + 1) for _ in range(n + 1)]

li = [list(map(int, a.split())) for a in sys.stdin]

z = (li[0][0], ) + list(zip(*li))[1]

for l in range(1, n):

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

        j = i + l

        m[i][j] = INF

        for k in range(i, j):

            m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + z[i - 1] * z[k] * z[j])

print((m[1][n]))



INF = float("inf")
n = int(eval(input()))
z = []
m = [[0] * (n + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
    a, b = list(map(int, input().split()))
    z.append(a)
z.append(b)
for l in range(1, n):
    for i in range(1, n - l + 1):
        j = i + l
        m[i][j] = INF
        for k in range(i, j):
            m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + z[i - 1] * z[k] * z[j])
print((m[1][n]))

import sys

INF = float("inf")
n = int(eval(input()))
m = [[0] * (n + 1) for _ in range(n + 1)]
li = [list(map(int, a.split())) for a in sys.stdin]
z = (li[0][0],) + list(zip(*li))[1]
for l in range(1, n):
    for i in range(1, n - l + 1):
        j = i + l
        m[i][j] = INF
        for k in range(i, j):
            m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + z[i - 1] * z[k] * z[j])
print((m[1][n]))

+import sys + -z = [] -for i in range(1, n + 1): -    a, b = list(map(int, input().split())) -    z.append(a) -z.append(b) +li = [list(map(int, a.split())) for a in sys.stdin] +z = (li[0][0],) + list(zip(*li))[1]